[haiku-development] Re: Handling device sizes in devfs

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 09 Dec 2012 19:06:39 +0100

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

> That would be the one to use, however, it's from Be times already, and
> is only size_t in size, so it cannot really be used for it anymore.

Ok. Maybe we can make it look at the size of the given buffer to decide 
wether it's size_t or something bigger. (relying on older drivers to fail if 
called with a mismatched size...). Or maybe we need another ioctl. Or maybe 
B_GET_GEOMETRY is ok for now.

> 
> > 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.
> 
> Indeed, this method won't work generally. Hence the method used by devfs
> to only report the size for the devices it knows about. Disk devices
> could all support them.

I'm not really happy with the current solution because it moves too much 
knowledge inside devfs. We want the device to tell the information by itself.

> > 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 ?
> 
> While /dev/console is a special case, it's generally not advisable to
> open all devices to get that information.

I understand that. The question still apply however (out of the context), is 
clearing the screen to white on open()ing /dev/console the right thing to do ?

Doing things like cat /dev/console, touch /dev/console, etc. have quite 
unexpected results. Moving the clear to the first write would avoid that.
Another solution is checking for the flags given to open(). Checking for 
O_WRONLY | O_TRUNC seems to make sense.

> > 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.
> 
> See above. The one publishing the device should maintain its meta data,
> not the open device instance.

Ok. So, what should I do ? Add a fSize field to BaseDevice.cpp and let 
subclasses set it, and just return its value on stat ?

-- 
Adrien.

Other related posts: