struct dirent - difference between getdents(2) manpage and definition in /usr/src/sys/dirent.h

Joerg Sonnenberger joerg at britannica.bec.de
Wed Jul 26 04:00:49 PDT 2006


On Wed, Jul 26, 2006 at 02:55:00PM +0530, Karthik Subramanian wrote:
> I was fooling around a little with getdents (yes, I know that I
> shouldn't be using getdents!) and found that the getdents manpage
> happened to say this about struct dirent:

Yeah, you shouldn't :-)

> The data in the buffer is a series of dirent structures each containing
>     the following entries:
> 
>           u_int32_t d_fileno;
>           u_int16_t d_reclen;
>           u_int8_t  d_type;
>           u_int8_t  d_namlen;
>           char    d_name[MAXNAMELEN + 1]; /* see below */
> 
>     The d_fileno entry is a number which is unique for each distinct file in
>     the filesystem.  Files that are linked by hard links (see link(2)) have
>     the same d_fileno.  The d_reclen entry is the length, in bytes, of the
>     directory record.

Yeah, this is outdated. I'm seriously thinking about just eliminiating
this. Hm. We even have a partly outdated comment on sys/dirent.h...

> It looks like this def is missing d_reclen, whereas the getdents
> manpage mentions it - or am I missing something here?

d_reclen doesn't exist anymore, since it was superfluous from the very
beginning. It was abused by some filesystems to save logic, but since
the 64bit ino_t need to convert the output anyway, it was just easier to
merge it into a commmon helper function.

Joerg





More information about the Users mailing list