The following
works in Minix but it doesn't work under Ubuntu or Suse. Why?
Is the tool different or it's because of the different filesystem?
Minix uses its own filesystem called MINIX file system but nowadays, the most major Linux distribution use the Extended file system.
What happens on a real unix system?
In Unix Programming Environment by Kernighan and Pike there is an example with this. Is it still valid?
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
I sympathize. I often used that to illustrate the content of directories in class. When we switched from Solaris to Linux, we encountered the same problem as you describe.
I don't know what the reasoning was behind that design decision -- it doesn't sound very free, does it ... cheers, drl
PS it still works in Solaris 10, you can see ., .. and t1:
I don't think that we are being fair to Linux here. Linux is designed to be very flexible in handling filesystems. No one, even root, can open a directory and read it. Instead a semi-secret system call is used to enable readdir to function. This means that the structure of a directory is known only to the kernel and it is using the FileSystem Switch to handle each filesystem type. As a result, filesystems that do not employ the unix directory structure can be supported. Consider FAT32, it has a very alien directory structure but it works well under Linux. Also file system developers are free to try new directory concepts. Linux actually gained quite a bit by prohibiting user-level directory reads.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi, myle.
My glib and petulant reply aside, I used od -bc <directory> to illustrate the structure of a directory. It was useful in discussing the idea of the inode.
Perderabo is right, there would probably be no way to do exactly the same with other filesystems, and readdir is POSIX compliant.
I don't recall what I did as a substitute, but it's possible that I wrote a short perl script to emulate what od had done for us in Solaris. There are readdir and stat functions in perl, and, even if you had to use c, it could still be done in a small program (helpful books by Stevens and Rochkind come to mind). If you are interested in showing the inode number, you probably know that an easy way is to use the "-i" option in ls -- it's just not quite as direct as using od.
We will often find inconsistencies like this. On a philosophical note, work, life, and the universe are good at providing problems and puzzles like this, big and small -- solving them helps us to keep our brains "plastic" (as in the presentation on the brain currently shown during the PBS fund-drive in the US).