linux - Why is the kernel using the default block driver instead of my driver's code? -


I wrote a block driver program that creates a dummy block device ( sbd0 ). I registered all device operations for that block device: (see include / linux / blkdev.h in the 2.6.32 kernel source)

  static structure block_device_operations sbd_ops = {.owner = THIS_MODULE, .open = sbd_open, .octl = sbd_ioctl, .getgeo = sbd_getgeo, .locked_ioctl = sbd_locked_ioctl, .compat_ioctl = sbd_compat_ioctl, .direct_access = sbd_direct_access, .media_changed = sbd_media_changed, .revalidate_disk = sbd_revalidate_disk};   

I compiled the driver program, I put the module and created the / dev / sbd0 . Now I want to test my driver code. So I wrote an application below.

  fd = open ("/ dev / sbd0", O_RDONLY); Retvl = IOCLL (FD, BLKBSZ, and Blocks); Trying to get the logical block size   

Output is: 4096

I'm surprised: I did not have the For ioctl has not implemented BLKBSZGET . This did not implement my sbd_ioctl , instead it used the default driver and gave me results. It has been executed for open , off calls sbd_open and sbd_close (which I have applied). And then I tried:

  retval = ioctl (fd, hdio_getGEO, and geoinfo);   

has implemented this sbd_getgeo but I thought it would call sbd_ioctl .

These are my questions:

  1. I implemented a driver and made a device. If I do any work on that device, then he has to invite my driver's application. But how does it use some of my driver's actions and some default driver functions?
  2. ioctl (fd, hdio_getGEO, ..) did not invoke. .ctl call , but it has been applied to .getgeo . How is this possible?

    ioctl sending is handled blkdev_ioctl By the function, which will process directly on some ioctls without calling a specific routine of your driver.

    for HDIO_GETGEO , it calls your driver getgeo function directly (3.13.6 from kernel, much later than 2.6.32 Change does not appear):

      [...] / * * First we need to set startect, driver * wants to override it. * / Mameset (and ground, 0, size (ground)); Geo.start = get_start_sect (bdev); Rate = disk-> FPS-> Getgeo (BDV, and Geo);  block_size (bdev)) , which for  BLKBSZGET  and [...]   

    simply bdev- & gt; Bd_block_size .

    You will find the blkdev_ioctl in the block / ioctl.c if you need to know what happens to other ioctls.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -