tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

UFS dirent d_reclen



Hello,

I'm having trouble understanding the value of d_reclen
for a dirent returne to me by readdir(2).  For
example:

mkdir dir
touch dir/f

If I now opendir(2) 'dir' and ask it to print info
about the dirents:

while ((dirp = readdir(dp)) != NULL) {
	printf("%s: %d\n", dirp->d_name, dirp->d_reclen);
}

I get the following output:

.: 16
..: 16
f: 16


The struct dirent is defined as

	ino_t    d_fileno;
	uint16_t d_reclen;
	uint16_t d_namlen;
	uint8_t  d_type;
	char     d_name[MAXNAMLEN + 1];

Inspection of the directory itself via hexdump:

$ hexdump -C <dir
00000000  c0 25 00 00 0c 00 04 01  2e 00 00 00 02 00 00 00  |.%..............|
00000010  0c 00 04 02 2e 2e 00 00  c1 25 00 00 e8 01 08 01  |.........%......|
00000020  66 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |f...............|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
$ 

'c0 25 00 00' is the inode number of the dir itself,
"."; 0c 00 hex = 12 dec is the reclen of ".", so the
next entry begins at offset 12.

'02 00 00 00' is the inode number of ".."; 0c 00 hex =
12 dec is the reclent of "..", so the next entry
begins at offset 24.

'c1 25 00 00' is the inode number of "f", the last
entry in this directory.  It's reclen is 'e8 01' hex,
488 dec, as it's the last entry in the directory.

So I'd have expected dirp->d_reclen to give me '12',
'12', and '488', instead of '16', '16', '16'.

What am I getting wrong here?

-Jan


Home | Main Index | Thread Index | Old Index