File System Hints
Posted: Tue Dec 30, 2003 1:54 am
This one is not meant as a question and answer thread, but as a thread where hints and tricks about File system implementation can be put. my examples and indications refer to the ext2 fs.
Here comes my first and very obvious one - 'thou' I stumbled over it - it took me three days to get the clue (*wham*):
You need your floppy/hard disk driver to be able to read consecutive/adjacent sectors and deliver them to a supplied buffer. You pass it the start block and the number of blocks and a location where to put the data, and then have it set off and do the rest.
The second one: It is not so obvious for one who is not used to reading file system spec's and has trouble with this block/sector thing - f. ex. floppy: The super block is always located at Block 1. On the floppy, it starts at sector 2. You read 2 adjacent sectors, so in the end, you have 1024 bytes for the superblock.
The block adjacent to the superblock is the group descriptor block. It is block 2, starts at sector 4 ... you know the rest already.
From this one you can see: you have to multiply the logical block number with the sectors_per_block constant you can calculate from several values in the superblock.
in the group descriptors you find the location of: block allocation bitmap, inode allocation bitmap and start of the inode table per group (several consecutive blocks: you can calculate how many by: total amount of inodes in file system/inodes per block)
that's it for now. It will be continued.
Here comes my first and very obvious one - 'thou' I stumbled over it - it took me three days to get the clue (*wham*):
You need your floppy/hard disk driver to be able to read consecutive/adjacent sectors and deliver them to a supplied buffer. You pass it the start block and the number of blocks and a location where to put the data, and then have it set off and do the rest.
The second one: It is not so obvious for one who is not used to reading file system spec's and has trouble with this block/sector thing - f. ex. floppy: The super block is always located at Block 1. On the floppy, it starts at sector 2. You read 2 adjacent sectors, so in the end, you have 1024 bytes for the superblock.
The block adjacent to the superblock is the group descriptor block. It is block 2, starts at sector 4 ... you know the rest already.
From this one you can see: you have to multiply the logical block number with the sectors_per_block constant you can calculate from several values in the superblock.
in the group descriptors you find the location of: block allocation bitmap, inode allocation bitmap and start of the inode table per group (several consecutive blocks: you can calculate how many by: total amount of inodes in file system/inodes per block)
that's it for now. It will be continued.