[En-Nut-Discussion] Get file size vomVIRTUALDEVICE

Harald Kipp harald.kipp at egnite.de
Sun Jul 25 17:41:14 CEST 2004



> >
> > Fortunately ioctl() may able to tell, wether the first
> > parameter points to a device or file. nf_next isn't
> > used yet, so we can redefine it as a magic and set it
> > to a value, that can't be a pointer. dev_next will
> > always contain a real pointer, including the NULL pointer.
>Good idea. I think that can be the next approach, but need some time to
>think about it...
>
>BTW, replacing the first parameter of ioctl from NUTDEVICE to NUTFILE cannot
>work, because we have some situations (mainly in dev_init), where we don't
>have a valid NUTFILE, but just the NUTDEVICE. If ioctl is called in
>dev_init, we only can use the NUTDEVICE. Surely, we can create a dummy
>NUTFILE with nf_dev member correctly initialized, but that becomes more and
>more ugly.


I do not know how we got here, but looks like I've
been here before. :-) Yes, now I remember the problems
of Michael, when he tried to implement the file
functions.

ioctl is defined as

   extern int _ioctl(int fd, int cmd, void *buffer);

ioctl then retrieves the pointer to the device and passes it
to the device specific ioctl routine. The file information
is lost.

As an alternative ioctl may pass the handle fd itself and the
device specific function may do the conversation

   NUTFILE *fp = (NUTFILE *) fd;

If fp->nf_magic is equal (void *)-1, then

   NUTDEVICE *dev = fp->nf_dev;

Otherwise

   NUTDEVICE *dev = (NUTDEVICE *)fp;

One may ask now, if it looks comprehensible to perform
ioctls on files? My feel for the English language is not
that good to answer this question.

Another option is to add a new function

   extern int fcntl(int fd, int cmd, ...);

to be used on files, which would make use of a new
NUTDEVICE member dev_fcntl, which may replace dev_size.

This makes sense to me, 2u2? ;)

Harald




More information about the En-Nut-Discussion mailing list