From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 5 20:42:20 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F0A2C106567A for ; Fri, 5 Sep 2008 20:42:20 +0000 (UTC) (envelope-from is@rambler-co.ru) Received: from relay0.rambler.ru (relay0.rambler.ru [81.19.66.187]) by mx1.freebsd.org (Postfix) with ESMTP id A513D8FC2B for ; Fri, 5 Sep 2008 20:42:20 +0000 (UTC) (envelope-from is@rambler-co.ru) Received: from localhost (is1.park.rambler.ru [81.19.64.121]) by relay0.rambler.ru (Postfix) with ESMTP id 978A05CCC; Sat, 6 Sep 2008 00:42:18 +0400 (MSD) Date: Sat, 6 Sep 2008 00:40:14 +0400 From: Igor Sysoev To: Kostik Belousov Message-ID: <20080905204014.GB71993@rambler-co.ru> References: <20080905184032.GA71993@rambler-co.ru> <20080905194845.GV2038@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20080905194845.GV2038@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.13 (2006-08-11) Cc: freebsd-hackers@freebsd.org Subject: Re: opendir()/closedir() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Sep 2008 20:42:21 -0000 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/