Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Sep 2008 00:40:14 +0400
From:      Igor Sysoev <is@rambler-co.ru>
To:        Kostik Belousov <kostikbel@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: opendir()/closedir()
Message-ID:  <20080905204014.GB71993@rambler-co.ru>
In-Reply-To: <20080905194845.GV2038@deviant.kiev.zoral.com.ua>
References:  <20080905184032.GA71993@rambler-co.ru> <20080905194845.GV2038@deviant.kiev.zoral.com.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Sep 05, 2008 at 10:48:45PM +0300, Kostik Belousov wrote:

> 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.

BTW, OpenBSD does not worry about tapes :), they use open()/fstat() from
the very start.  And closedir() does not lseek() since OpenBSD 4.0.


-- 
Igor Sysoev
http://sysoev.ru/en/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080905204014.GB71993>