Search code examples
linux-kernellinux-device-driverdevice-driver

Getting device dev_t from struct bio


I have been playing around block device i/o methods by trying to override make_request_fn of any given block device by changing the function pointer to make_request_fn inside struct queue. I have one doubt though, when my own new make_request_fn gets called, the struct block_device inside struct bio has a dev_t with a minor always set to 0 no matter what device it is. Is there any way to find out which minor device in particular will the bio is going to serve? Because I need to figure out which cached original make_request_fn to call before I end my function.


Solution

  • It was because of the partitions. I did not know that all partitions will share the same make_request_fn. I figured out which partition the bio belongs to by noting down the start and end sector numbers for each partition and mapping the bi_sector inside struct bio with this.