function prototype of fdrop() and fdrop_locked() in kern_descrip.c

David Schultz das at FreeBSD.ORG
Mon Feb 28 13:39:29 GMT 2005


On Sat, Feb 26, 2005, Yan Yu wrote:
> HI, all,
>   I have a Q on the input parameter of fdrop() and fdrop_locked() in
> kern/kern_descrip.c.
> 
> i am curious about the design choice of their input parameter.
> currently, it is defined as
> ----------------------------------------
> A) fdrop( struct file *, struct thread *)
> ----------------------------------------
> I added some field in the file descriptor table, and need to do some
> bookkeeping whenever a file descriptor is freed. It would be much easier
> for me if fdrop() is defined as
> ---------------------------------
> B) fdrop( int fd, struct thread *)
> ---------------------------------
> then i could just instrument the fdrop function as opposed to change every
> place that calls the fdrop() function. btw, there are more than 100 places
> that calls fdrop():(

There isn't a one-to-one mapping between file structures and
userland file descriptors.  After dup(2) is called, for instance,
there are two numbers that both map to the same struct file.
David Malone gave some other good examples.  You will probably
want to rethink your design to take this into account.

Note that you could instrument the places where syscalls look up
userland file descriptors in the fd table if you need to refer to
the descriptor number.  Just be aware that the number you get
won't necessarily correspond to a unique struct file.  There are
at least two places where this mapping is done: fget_locked() and
getvnode().  I think patches to combine them would be gladly
accepted.  ;-)


More information about the freebsd-hackers mailing list