I was wondering why od(1) used to work in UNIX but doesn't work in GNU/Linux. There is a nice answer on serverfault. The next question is, are you aware of any tools that can emulate od behavior to support dumping directory data in GNU/Linux?
Asked
Active
Viewed 340 times
1 Answers
6
Linux doesn't let you do a plain read(dir_name, buffer, sizeof(buffer) - it always returns -1 and puts EISDIR in errno. This is probably rational, as not all filesystems have directories as files. The commonly-used reiserfs does not, for example.
You can use the open() system call from a C program to get a file descriptor of a directory, but things like readdir(3) (from libc) call getdents(2) to actually retrieve directory entries. There's probably code in each filesystem implementation to create struct linux_dirent from whatever (a file, a database, an on-disk B-tree) that filesystem uses to store directory entries.