Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Jun 2011 19:28:36 -0400 (EDT)
From:      Rick Macklem <rmacklem@uoguelph.ca>
To:        mdf@FreeBSD.org
Cc:        freebsd-hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Check for 0 ino_t in readdir(3)
Message-ID:  <1936865111.251439.1307489316675.JavaMail.root@erie.cs.uoguelph.ca>
In-Reply-To: <BANLkTik%2BNZ=63fjO2me25Mo3H6JELQCuFA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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