4

I'm reading "The Unix Programming Environment". Its discussion of directories makes frequent use of the od command to get an octal dump of a directories' contents. But at some since 1984, usage of od on a directory has been disabled on the MacBook (returns 'is a directory'). It seems it has also been disabled for directories on linux.

Any alternative commands I could use?

2 Answers 2

3

The OS X kernel prohibits read(2) operations on directories, so you'll never be able to use user-space tools to read directory entries directly.

If you want to read directory entries from user space, you'll need to open the underlying block device directly, read its superblocks, find the root inode, read the entries to find the next directory in the chain recursively to find the directory you're interested in, and then you can read the directory entries. You will, in essence, write a user-space filesystem driver to do this task.

There was a lot that was clever with the old Unix systems, but this was definitely an awkward part -- the only way to create directories in those days was via the mkdir(1) command, which was setuid-root, because creating directories had to be done via the mknod(2) system call. So programs would routinely call system("mkdir /path/to/foo"); chdir("/path/to/foo"); in order to create a new directory.

0

According to http://www.unix.com/unix-advanced-expert-users/35034-using-od-directory.html this is a limitation of gnu od command, and there is a "problem" with it on FreeBSD's version as well (Which I think is what Darwin is based on.)

It may be filesystem dependent, from what the site says. It also said that this works on directories when used on Solaris.

Basically it looks like the instructions are dependent on what version of UNIX you're using. No known workaround that I can find for getting this to work on a directory.

1
  • I believe sb008 misdiagnosed the cause of the error message; the Linux kernel refuses read(2) operations on directories, so even if he recompiled his Solaris-provided od(1) on Linux, it'd still give the same error message. The OS X kernel also prohibits read(2) operations on directories, so no matter which od(1) you use, it'll never be able to use read(2) to get the data from a directory.
    – sarnold
    Oct 2, 2011 at 23:32

Not the answer you're looking for? Browse other questions tagged .