Marc Balmer found a 25-year-old bug in the BSD *dir libraries. Marc says that if you write a directory that spans two blocks, delete the first directory entry in the second block, then seekdir to the second entry in the second block (using a saved value from telldir), you'll be placed at the third entry instead. And he generously provides you
(
Read more... )
Comments 9
Note that case-insensitive HFS sorts case-insensitively, while case-sensitive HFS should sort case-sensitively.
That said: I don't think it's kosher to do arithmetic on the values returned by telldir, the way you are.
Reply
Reply
Reply
I notice that, on Linux tmpfs, the position for the file named “26” is 4. Make of that what you will.
Reply
Linux/XFS: 26, except when 26 has been deleted, in which case 27.
Linux/tmpfs: 26, except {26..28} where it's 25.
NetBSD/{FFS,LFS,MFS}: 27, except {27,28} where it's 26.
NetBSD/FFS/NFS/Linux: as above.
MacOSX/HFS+: 27, except {3..9,27,28} where it's 26. Not so odd after all, if you think about it.
Also, I somehow failed to know about zsh brace expansion until now. I might owe you a beverage or baked good.
Reply
Reply
The issue of what a position within a directory actually means seems to be entirely handwaved.
Reply
I realize now that I am not reproducing this on FreeBSD 6.2:
% ./youcantelladirbutyoucanttellitmuch.pl 25
26
Reply
Anyway, I don't think 26 is the magic number. At least on NetBSD, each __getdents30 call (i.e., getdirentries) is done with a 4kB buffer, of which only 464 bytes are needed for your test case. A little checking shows that the 202nd file is the first in the second batch. On my system, anyway.
Reply
Leave a comment