inode = which block

hiho,

i would like to show my apprentices the auto-defrag/perform mechanism from UFS. new FS, creating new directories, each directory get its own cylinder on the disk. hmm....
they want proofs.....
*embarrassing*
i couldn't remember how to look on which block the inode is linked....
so, please help me to keep my credibility :wink: (or perhabs my hono *hehe*)

thx pressy

I doubt that anyone walks around with those formulas in their head. But all of the macros are in /usr/include/sys/fs/ufs_*.h and you can get the raw data by using "fstyp -v".

what do you mean auto-defrag? as far as i know there is no defraging. if you mean how ufs allocates full block for largefiles first then allocates fragments for small files (i believe anything less then 2gb) first. but ufs does not have a defrag that i know about. you can specifiy what fragment size you want when createing the new fs bu the default is 1kb. each block can be devided into 1,2,4, or 8 fragments.

you might be able to use fstyp -v to figure out which cylinder your inode is on. do find out the inode you can use ls -i.

it wouldnt make much sense if each dir got a whole cylinder because each dir eats up an inode what if you have less inodes then you have cylinders?

Fragmentation in the context of this thread means a file that is scattered over the whole disk so that reading sequentially would be slow. This tends to not happen with the Berkeley filesystem because the file will be kept in one ccylinder group if possible.

There are only a few cylinder groups and each cg would have many inodes.

The allocation policy of the Berkeley filesystem reduces fragmentation enough that no de-fragging is needed.

Part of this policy days that a new directory goes to the least full cg. If you build a filesystem with, say 10 cg's, the root directory will be in cg 0. Now create exactly 9 more directories and each directory should be in a cylinder groups of it's own. This leads to stupid filesystem tricks like positioning a file exactly in the center cg for performance.

Getting the block of an inode is tricky but getting the cg is trivial. You divide the inode number by the inodes-per-cg and ignore the remainder.

use the fsdb (filesystem debugger) .. Use with care :slight_smile:

create a file..

ls -i filename
get inode
say its 3211
fsdb /dev/rdsk/slice_file_is_on
in fsdb use :

0t3211:ino
/(where 3211 is the inode nr of the file)
.?ino
(this will print inode info and the block its pointing to....)
db#0 BLOCKNR
db#1 BLOCKNR

To verify use (will only work on textfiles :slight_smile: )
BLOCKNR:bl
.,50/c
(this will print first 50 chars from block)

to quit the fsdb type
:quit

have fun :slight_smile:

/Peter