Final Year Project:
Using Linux Filesystems Under Windows
Chris Bryden
BEng. Electronics and Software Engineering
School of Computer Science
University of Birmingham
16
3.3.5 Inodes
An inode uniquely describes a file or directory. Its main purpose is to hold
the locations of th4e actual data blocks making up the file. The inodes are stored
one after another in the inode table, a section of which is stored in each group.
When allocating blocks for a particular file, the kernel will generally allocate
blocks from the same group that contains the inode for the file, as performance
is enhanced by having the inode and the blocks it points to located nearby on the
disk. A number is used to individually address each inode, starting at 0 for the
first inode and its value simply following on from one group to the next, through
all the groups in the filesystem. The group containing a particular inode can then
be quickly determined by simply knowing how many inodes are contained in
each group (this is a fixed number, recorded in the superblock).
The structure of an inode on disk is shown below, taken from ext2_fs.h:
·
=i_mode - The type of file (character, block, link, etc.) and access rights to the
file. This field is best described by representing it as an octal number. Since it
is a 16 bit number, there will be 6 octal digits. The rightmost four digits are
bitwise fields:
The last three digits (Octal digits 0,1 and 2) are the file permissions, in the
form rwxrwxrwx. Digit 2 refers to the user, digit 1 to the group and digit 2
to everyone else.
/*
* Structure of an inode on the disk
*/
struct ext2_inode {
unsigned short i_mode;
unsigned short i_uid;
unsigned long i_size;
unsigned long i_atime;
unsigned long i_ctime;
unsigned long i_mtime;
unsigned long i_dtime;
unsigned short i_gid;
unsigned short i_links_count;
unsigned long i_blocks;
unsigned long i_flags;
unsigned long l_i_reserved1;
unsigned long i_block[EXT2_N_BLOCKS];
unsigned long i_version;
unsigned long i_file_acl;
unsigned long i_dir_acl;
unsigned long i_faddr;
unsigned char l_i_frag;
unsigned char l_i_fsize;
unsigned short i_pad1;
unsigned long l_i_reserved2[2];
};