文章随机晒最新文章关照最多的

jiayi Rss

file system in linux kernel

| Posted in APUE, kernel |

4

File system

Super
Block
Group
Descriptors
Block
Group 1
Block
Group 2

Block
Group N

Block
Bitmap
Inode
Bitmap
Inode
Table
Data
Blocks

From the figuires above we get:

Every block group is associated with a group descriptor. All of the group descriptors are congregated following the Super Block tightly.

In the group descriptor,there is a pointer points to the refered block group’s block bitmap.Every bit in the block bitmap indicates a block.0 represents the block has been written;1 represents the block is free.The size of block bitmap is just the same as a block.So if  we assume a block is S bytes.The block bitmap can record S*8 blocks.We get that a block group is 8*S*S bytes at most.

There is another pointer in the group descriptor pointing to the inode bitmap.This inode bitmap owns the same size of a block too.Every bit in it refers to a i-node.The i-node laying on the hard disk refers to the file on the file system.The file types are as the follow:

File type

   

regular file

 

 

directory

   

symbolic link

   

character special

   

block special

   

socket

   

FIFO

   

Another important pointer in descriptor points to the I-node table.The I-node table is larger than a block.It gathers all the i-nodes in the block group.

The structure of Supper Block

struct ext3_super_block {
/*00*/ __u32 s_inodes_count;      /* inodes count */
       __u32 s_blocks_count;      /* blocks count */
       __u32 s_r_blocks_count;    /* reserve blocks count */
       __u32 s_free_blocks_count; /* free blocks count */
/*10*/ __u32 s_free_inodes_count; /* free inodes count */
       __u32 s_first_data_block;  /* firest data block */
       __u32 s_log_block_size;    /* size of a block */
       __s32 s_log_frag_size;     /* Ignore */
/*20*/ __u32 s_blocks_per_group;  /* number of blocks per block group */
       __u32 s_frags_per_group;   /* Ignore */
       __u32 s_inodes_per_group;  /* number of inodes per block group */
       __u32 s_mtime;             /* Mount time */
/*30*/ __u32 s_wtime;             /* Write time */
       __u16 s_mnt_count;         /* Mount count */
       __s16 s_max_mnt_count;     /* Maximal mount count */
       __u16 s_magic;             /* Magic label */
       __u16 s_state;             /* File system state */
       __u16 s_errors;            /* Behaviour when detecting errors */
       __u16 s_minor_rev_level;   /* minor revision level */
/*40*/ __u32 s_lastcheck;         /* time of last check */
       __u32 s_checkinterval;     /* max. time between checks */
       __u32 s_creator_os;        /* Ignore */
       __u32 s_rev_level;         /* Revision level */
/*50*/ __u16 s_def_resuid;        /* Default uid for reserved blocks */
       __u16 s_def_resgid;        /* Default gid for reserved blocks */
       __u32 s_first_ino;         /* First non-reserved inode */
       __u16 s_inode_size;        /* size of inode structure */
       __u16 s_block_group_nr;    /* block group # of this superblock */
       __u32 s_feature_compat;    /* compatible feature set */
/*60*/ __u32 s_feature_incompat;  /* incompatible feature set */
       __u32 s_feature_ro_compat; /* readonly-compatible feature set */
/*68*/ __u8  s_uuid[16];          /* 128-bit uuid for volume */
/*78*/ char  s_volume_name[16];   /* volume name */
/*88*/ char  s_last_mounted[64];  /* directory where last mounted */
/*C8*/ __u32 s_algorithm_usage_bitmap; /* Ignore */
       __u8  s_prealloc_blocks;        /* Ignore */
       __u8  s_prealloc_dir_blocks;    /* Ignore */
       __u16 s_padding1;               /* Ignore */
/*D0*/ __u8  s_journal_uuid[16]; /* uuid of journal superblock */
/*E0*/ __u32 s_journal_inum;     /* log file's inode number */
       __u32 s_journal_dev;      /* log file's device number */
       __u32 s_last_orphan;      /* start of list of inodes to delete */
/*EC*/ __u32 s_reserved[197];    /* Ignore */
};

The structure of group descriptor

struct ext3_group_desc
{
 __u32 bg_block_bitmap;      /* block pointer points to block bitmap */
 __u32 bg_inode_bitmap;      /* block pointer points to inode bitmap */
 __u32 bg_inode_table;       /* block pointer points to inodes table */
 __u16 bg_free_blocks_count; /* free blocks count */
 __u16 bg_free_inodes_count; /* free inodes count */
 __u16 bg_used_dirs_count;   /* number of direcotries */
 __u16 bg_pad;               /* Ignore */
 __u32 bg_reserved[3];       /* Ignore */
};

The structure of I-node

struct ext3_inode {
 __u16 i_mode;    /* File mode */
 __u16 i_uid;     /* Low 16 bits of Owner Uid */
 __u32 i_size;    /* size of file,byte unit */
 __u32 i_atime;   /* Access time */
 __u32 i_ctime;   /* Creation time */
 __u32 i_mtime;   /* Modification time */
 __u32 i_dtime;   /* Deletion Time */
 __u16 i_gid;     /* Low 16 bits of Group Id */
 __u16 i_links_count;          /* Links count */
 __u32 i_blocks;               /* blocks count */
 __u32 i_flags;                /* File flags */
 __u32 l_i_reserved1;          /* Ignore */
 __u32 i_block[EXT3_N_BLOCKS]; /* array of block pointers */
 __u32 i_generation;           /* Ignore */
 __u32 i_file_acl;             /* Ignore */
 __u32 i_dir_acl;              /* Ignore */
 __u32 i_faddr;                /* Ignore */
 __u8  l_i_frag;               /* Ignore */
 __u8  l_i_fsize;              /* Ignore */
 __u16 i_pad1;                 /* Ignore */
 __u16 l_i_uid_high;           /* Ignore */
 __u16 l_i_gid_high;           /* Ignore */
 __u32 l_i_reserved2;          /* Ignore */
};


I-node points to directory blocks

From the figuire above we get:

The structure of directory are allocated out of the i-node array (i-node table). It is allocated in the data blocks with the ordinary data together.
Ordinary file i-node points to the ordinary data block. Direcotery i-node points to the direcotery blocks.

Directory block points to the associated i-node


From the figuire above we get:

Directories are structured in a hierarchical tree. Each directory can contain files and subdirectories.
Directories are implemented as a special type of files. Actually, a directory is a file containing a list of entries. Each entry contains an inode number and a file name. When a process uses a pathname, the kernel code searchs in the directories to find the corresponding inode number. After the name has been converted to an inode number, the inode is loaded into memory and is used by subsequent requests.

Comments (4)

虽然没看懂,还是要留一笔~

绝对的天书…

你个人觉得应该选哪个文件系统好?JFS?

Linux 推荐 reiserfs
当然,Solaris的ZFS是极品~ license的问题没有移植到Linux上…

Write a comment

You must be logged in to post a comment.