Final Year Project:
Using Linux Filesystems Under Windows
Chris Bryden
BEng. Electronics and Software Engineering
School of Computer Science
University of Birmingham
41
5.13 Layer 1: The ReadGroupDesc and GetGroupDesc Functions
The ReadGroupDesc function simply reads the filesystem group
descriptors from disk into a memory buffer. It is called once when the filesystem
is mounted.
The GetGroupDesc function is used to retrieve a specified group
descriptor from the memory buffer filled by ReadGroupDesc. It simply calculates
the offset within the buffer of the required group descriptor, identified by the
variable uGroup, and copies the descriptor form the buffer to the memory
location pointed to by GroupDesc. The group descriptor structure, defined in
ext2_fs.h is assigned a type, GROUPDESC.
Please see section 3.3.3 for details of the group descriptor structure.
5.14 Layer 1: The GetInode Function
This function is used to read a specified inode form the disk into the Inode
structure passed to the function. The inode is specified by passing its inode
number to the function. The inode structure, defined in ext2_fs.h, is given a type:
INODE. For more details on the structure of the inode, see section 3.3.5.
The first task that this function has to perform is that of calculating which
block group the requested inode is in. This is achieved by dividing the inode
number by the number of inodes in each group. The integer part of this result
gives the group in which the inode is located. The group descriptor for this group
is then read by calling the GetGroupDesc function.
Next, the block address of the block containing the inode has to be
calculated so that the disk read can be performed. This is done by the code
shown below
Firstly the number of inodes per block, ulInodesPerBlk, is calculated.
Then, as each group only contains a portion of the inode table, the offset within
the inode table for this group, ulInodeOffset, has to be calculated. This offset is
measured in inodes. To calculate it, the total number of inodes contained within
groups previous to this one is determined and then subtracted from the inode
number of the requested inode. Finally, to determine the block address of the
block containing the inode, the group descriptor value, bg_inode_table is used.
This gives the block address of the beginning of the portion of the inode table
//Calculate block number
ulBlkSize = 1024 << SuperBlock.s_log_block_size;
ulInodesPerBlk = ulBlkSize / sizeof(INODE);
ulInodeOffset = ulInodeNum - (ulGroup * SuperBlock.s_inodes_per_group);
ulBlock = GroupDesc.bg_inode_table + floor((double)ulInodeOffset /
(double)ulInodesPerBlk);