From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 7 23:28:37 2011 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 EF7461065672 for ; Tue, 7 Jun 2011 23:28:37 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from esa-annu.mail.uoguelph.ca (esa-annu.mail.uoguelph.ca [131.104.91.36]) by mx1.freebsd.org (Postfix) with ESMTP id 9D5FB8FC14 for ; Tue, 7 Jun 2011 23:28:37 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwGACuz7k2DaFvO/2dsb2JhbABThEqTNI8itmOQfYErg2yBCgSRE4dZiA0 X-IronPort-AV: E=Sophos;i="4.65,335,1304308800"; d="scan'208";a="123249306" Received: from erie.cs.uoguelph.ca (HELO zcs3.mail.uoguelph.ca) ([131.104.91.206]) by esa-annu-pri.mail.uoguelph.ca with ESMTP; 07 Jun 2011 19:28:36 -0400 Received: from zcs3.mail.uoguelph.ca (localhost.localdomain [127.0.0.1]) by zcs3.mail.uoguelph.ca (Postfix) with ESMTP id B3EBDB3F20; Tue, 7 Jun 2011 19:28:36 -0400 (EDT) Date: Tue, 7 Jun 2011 19:28:36 -0400 (EDT) From: Rick Macklem To: mdf@FreeBSD.org Message-ID: <1936865111.251439.1307489316675.JavaMail.root@erie.cs.uoguelph.ca> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [172.17.91.201] X-Mailer: Zimbra 6.0.10_GA_2692 (ZimbraWebClient - IE7 (Win)/6.0.10_GA_2692) Cc: freebsd-hackers Subject: Re: Check for 0 ino_t in readdir(3) 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: Tue, 07 Jun 2011 23:28:38 -0000 mdf wrote: > There is a check in the function implementing readdir(3) for a zero > inode number: > > struct dirent * > _readdir_unlocked(dirp, skip) > DIR *dirp; > int skip; > { > /* ... */ > if (dp->d_ino == 0 && skip) > continue; > /* ... */ > } > > "skip" is 1 except for when coming from _seekdir(3). > > I don't recall any requirement that a filesystem not use an inode > numbered 0, though for obvious reasons it's a poor choice for a file's > inode. So... is this code in libc incorrect? Or is there > documentation that 0 cannot be a valid inode number for a filesystem? > Well, my recollection (if I'm incorrect, please correct me:-) is that, for real BSD directories (the ones generated by UFS/FFS, which everything else is expected to emulate), the d_ino field is set to 0 when the first entry in a directory block is unlink'd. This is because directory entries are not permitted to straddle blocks, so the first entry can not be subsumed by the last dirent in the previous block. In other words, when d_ino == 0, the dirent is free. rick