opendir()/closedir()

Kostik Belousov kostikbel at gmail.com
Fri Sep 5 19:48:52 UTC 2008


On Fri, Sep 05, 2008 at 10:40:32PM +0400, Igor Sysoev wrote:
> Looking at opendir()/readdir()/closedir() sequence via ktrace,
> I've seen supposedly useless lseek() syscall just before close().
> It's called from closedir():
> 
>         _seekdir(dirp, dirp->dd_rewind);        /* free seekdir storage */
> 
> It seems that free()ing libc seekdir storage should be done without
> calling lseek().
> 
> Other strange place for me is stat() before open() in opendir()
> 
>         /*
>          * stat() before _open() because opening of special files may be
>          * harmful.  _fstat() after open because the file may have changed.
>          */
> 
> What is the case when opening special file may be harmful ?

For instance, tape may be rewinded.

The whole opendir/seekdir/telldir probably should be synced with OpenBSD
version, at least due to SINGLEUSE. I made this conclusion when I merged
the OpenBSD fix for seekdir several months ago. But I also decided then
that I am not a volunteer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20080905/be1eff45/attachment.pgp


More information about the freebsd-hackers mailing list