[haiku-development] Handling device sizes in devfs

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 09 Dec 2012 18:04:20 +0100

Hello devs,

I'm trying to solve a TODO in our devfs implementation.
Currently only disk partitions are given a size by it.

I'd like to get the size of the complete disk reported as well when looking 
at the "raw" device for the disk. There is disabled code in devfs.cpp that 
suggests doing it by using B_GET_GEOMETRY ioctl, but this is specific to 
storage devices. We may want other devices to also have a size (for 
example, this is useful for device mmap()ing support).

What I'm trying is using the B_GET_DEVICE_SIZE ioctl to get the size 
instead.

Question 1: I'm not sure I'm right there. Is this the right one to use ?


To use an ioctl, I must have a device cookie. I get one by opening the 
device using devfs_open. When I'm done I close it with devfs_close. 
However, this has side effects on some of our devices. So far, I've noticed 
that opening /dev/console will clear the framebuffer to white.

Question 2: Am I allowed to open a device from the devfs_read_stat method ?
Question 3: I don't think open() should have any side effect on the device 
like this. Should console be fixed to clear the screen later, maybe at the 
first write operation ?
Question 4: I fear that opening the device to stat it has a performance 
impact (when you do ls -l /dev, all devices are opened then closed). Am I 
right to worry about this ?
Question 5: is there a better way to do ? Obviously, trying to call
device->Control() directly with a NULL cookie leads to KDL, at least for 
some devices.

Thanks,
-- 
Adrien.



Other related posts: