*BSD News Article 18805


Return to BSD News archive

Xref: sserve comp.unix.wizards:30158 comp.unix.bsd:12320 comp.unix.questions:36925
Newsgroups: comp.unix.wizards,comp.unix.bsd,comp.unix.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!darwin.sura.net!news.dfn.de!tubsibr!thuerman
From: thuerman@ibr.cs.tu-bs.de (Urs Thuermann)
Subject: Re: Revised od/BSD filesystem question
Message-ID: <1993Jul23.231712.2754@ibr.cs.tu-bs.de>
Sender: postnntp@ibr.cs.tu-bs.de (Mr. Nntp Inews Entry)
Organization: TU Braunschweig, Informatik (Bueltenweg), Germany
References: <22pd95$ke0@agate.berkeley.edu>
Date: Fri, 23 Jul 1993 23:17:12 GMT
Lines: 40

scott@soda.berkeley.edu (Scott Silvey) writes:

>... od -cdw12 ~

> 0000000   \0  \0 016  \0  \0  \f  \0 001   .  \0  \0  \0
>            00000   03584   00012   00001   11776   00000
>          |______|_______|

>Looking at the lower 2 bytes of the inode data (016 \0) we get the following:

>          [ 0*8^5 + 1*8^4 + 6*8^3 ] + [ 0 + 0 + 0 ] = 7168  decimal
>                                                    (3584*2)

This is wrong:  Read the first 4 byte in the first line as
	0 * 256^3 + 0 * 256^2 + (1*8^1 + 6) * 256^1 + 0 * 256^0 = 3584
or in the second line
	0 * 65536^1 + 3584 * 65536^0 = 3584
This is the inode number of the directory '.' (your home directory ~).

>[...] and what
>happens when an inode entry is 3 or 4 bytes long?

inodes are always 4 bytes long. 
Each directory contains a sequence of entries where each entry has the
following form:
	<inode> <total_length> <name_length> <name> <padding>
The first 3 items are 4 bytes each and give the inode number of the file
or directory referred to by <name>, the length of this entry, and the
length of <name> in bytes. <padding> is a number of bytes to make the entry
<total_length> bytes long.
There is no information like file length, access and mod. times, etc in
the directory, like in msdos systems.  Information like this is contained
in the inode.

Usually you don't have to (and shouldn't) deal with directories at this
level, since this makes your programs harder to port to other (file)-systems.
Use opendir/readdir/... instead.

Hope this helps.
Urs