Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.