od -cb .


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users od -cb .
# 1  
Old 03-09-2008
od -cb .

The following
Code:
od -cb .

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?
# 2  
Old 03-09-2008
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 Smilie ... cheers, drl

PS it still works in Solaris 10, you can see ., .. and t1:
Code:
$ od -bc d1
0000000 040 001 000 000 014 000 001 000 056 000 000 000 035 001 000 000
             001  \0  \0  \f  \0 001  \0   .  \0  \0  \0 035 001  \0  \0
0000020 014 000 002 000 056 056 000 000 041 001 000 000 350 001 002 000
          \f  \0 002  \0   .   .  \0  \0   ! 001  \0  \0 350 001 002  \0
0000040 164 061 000 000 000 000 000 000 000 000 000 000 000 000 000 000
           t   1  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
          \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0001000

# 3  
Old 03-09-2008
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.
# 4  
Old 03-09-2008
Hi.

I think Linux (design) is not being fair to me.

I wasn't expecting any particular structure other than the customary everything in Unix is a file stream of bytes. I'd figure out the rest.

Abstraction is fine, but I don't want an OS protecting me from myself. It may not make sense to the OS, but who's in charge?

It also works as expected in FreeBSD 6.2-RELEASE-p1 ... cheers, drl
# 5  
Old 03-14-2008
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).

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question