ext2文件系统结构体组成

The Second Extended File System(ext2)文件系统是Linux系统中的标准文件系统,是通过对Minix的文件系统进行扩展而得到的,其存取文件的性能极好。

在ext2文件系统中,文件由inode(包含有文件的所有信息)进行唯一标识。一个文件可能对应多个文件名,只有在所有文件名都被删除后,该文件才会被删除。此外,同一文件在磁盘中存放和被打开时所对应的inode是不同的,并由内核负责同步。

ext2文件系统采用三级间接块来存储数据块指针,并以块(block,默认为1KB)为单位分配空间。其磁盘分配策略是尽可能将逻辑相邻的文件分配到磁盘上物理相邻的块中,并尽可能将碎片分配给尽量少的文件,以从全局上提高性能。ext2文件系统将同一目录下的文件(包括目录)尽可能的放在同一个块组中,但目录则分布在各个块组中以实现负载均衡。在扩展文件时,会尽量一次性扩展8个连续块给文件(以预留空间的形式实现)。

一、磁盘组织

在ext2系统中,所有元数据结构的大小均基于“块”,而不是“扇区”。块的大小随文件系统的大小而有所不同。而一定数量的块又组成一个块组,每个块组的起始部分有多种多样的描述该块组各种属性的元数据结构。ext2系统中对各个结构的定义都包含在源代码的include/linux/ext2_fs.h文件中。

1、超级块

每个ext2文件系统都必须包含一个超级块,其中存储了该文件系统的大量基本信息,包括块的大小、每块组中包含的块数等。同时,系统会对超级块进行备份,备份被存放在块组的第一个块中。超级块的起始位置为其所在分区的第1024个字节,占用1KB的空间,其结构如下:

structext2_super_block{

__le32s_inodes_count;//文件系统中inode的总数

__le32s_blocks_count;//文件系统中块的总数

__le32s_r_blocks_count;//保留块的总数

__le32s_free_blocks_count;//未使用的块的总数(包括保留块)

__le32s_free_inodes_count;//未使用的inode的总数

__le32s_first_data_block;//块ID,在小于1KB的文件系统中为0,大于1KB的文件系统中为1

__le32s_log_block_size;//用以计算块的大小(1024算术左移该值即为块大小)

__le32s_log_frag_size;//用以计算段大小(为正则1024算术左移该值,否则右移)

__le32s_blocks_per_group;//每个块组中块的总数

__le32s_frags_per_group;//每个块组中段的总数

__le32s_inodes_per_group;//每个块组中inode的总数

__le32s_mtime;//POSIX中定义的文件系统装载时间

__le32s_wtime;//POSIX中定义的文件系统最近被写入的时间

__le16s_mnt_count;//最近一次完整校验后被装载的次数

__le16s_max_mnt_count;//在进行完整校验前还能被装载的次数

__le16s_magic;//文件系统标志,ext2中为0xEF53

__le16s_state;//文件系统的状态

__le16s_errors;//文件系统发生错误时驱动程序应该执行的操作

__le16s_minor_rev_level;//局部修订级别

__le32s_lastcheck;//POSIX中定义的文件系统最近一次检查的时间

__le32s_checkinterval;//POSIX中定义的文件系统最近检查的最大时间间隔

__le32s_creator_os;//生成该文件系统的操作系统

__le32s_rev_level;//修订级别

__le16s_def_resuid;//报留块的默认用户ID

__le16s_def_resgid;//保留块的默认组ID

//仅用于使用动态inode大小的修订版(EXT2_DYNAMIC_REV)

__le32s_first_ino;//标准文件的第一个可用inode的索引(非动态为11)

__le16s_inode_size;//inode结构的大小(非动态为128)

__le16s_block_group_nr;//保存此超级块的块组号

__le32s_feature_compat;//兼容特性掩码

__le32s_feature_incompat;//不兼容特性掩码

__le32s_feature_ro_compat;//只读特性掩码

__u8s_uuid[16];//卷ID,应尽可能使每个文件系统的格式唯一

chars_volume_name[16];//卷名(只能为ISO-Latin-1字符集,以'\0'结束)

chars_last_mounted[64];//最近被安装的目录

__le32s_algorithm_usage_bitmap;//文件系统采用的压缩算法

//仅在EXT2_COMPAT_PREALLOC标志被设置时有效

__u8s_prealloc_blocks;//预分配的块数

__u8s_prealloc_dir_blocks;//给目录预分配的块数

__u16s_padding1;

//仅在EXT3_FEATURE_COMPAT_HAS_JOURNAL标志被设置时有效,用以支持日志

__u8s_journal_uuid[16];//日志超级块的卷ID

__u32s_journal_inum;//日志文件的inode数目

__u32s_journal_dev;//日志文件的设备数

__u32s_last_orphan;//要删除的inode列表的起始位置

__u32s_hash_seed[4];//HTREE散列种子

__u8s_def_hash_version;//默认使用的散列函数

__u8s_reserved_char_pad;

__u16s_reserved_word_pad;

__le32s_default_mount_opts;

__le32s_first_meta_bg;//块组的第一个元块

__u32s_reserved[190];

};

2、块组描述符

一个块组描述符用以描述一个块组的属性。块组描述符组由若干块组描述符组成,描述了文件系统中所有块组的属性,存放于超级块所在块的下一个块中。一个块组描述符的结构如下:

structext2_group_desc

{

__le32bg_block_bitmap;//块位图所在的第一个块的块ID

__le32bg_inode_bitmap;//inode位图所在的第一个块的块ID

__le32bg_inode_table;//inode表所在的第一个块的块ID

__le16bg_free_blocks_count;//块组中未使用的块数

__le16bg_free_inodes_count;//块组中未使用的inode数

__le16bg_used_dirs_count;//块组分配的目录的inode数

__le16bg_pad;

__le32bg_reserved[3];

};

3、块位图与inode位图

块位图和inode位图的每一位分别指出块组中对应的那个块或inode是否被使用。

4、inode表

inode表用于跟踪定位每个文件,包括位置、大小等(但不包括文件名),一个块组只有一个inode表。一个inode的结构如下:

structext2_inode{

__le16i_mode;//文件格式和访问权限

__le16i_uid;//文件所有者ID的低16位

__le32i_size;//文件字节数

__le32i_atime;//文件上次被访问的时间

__le32i_ctime;//文件创建时间

__le32i_mtime;//文件被修改的时间

__le32i_dtime;//文件被删除的时间(如果存在则为0)

__le16i_gid;//文件所有组ID的低16位

__le16i_links_count;//此inode被连接的次数

__le32i_blocks;//文件已使用和保留的总块数(以512B为单位)

__le32i_flags;//此inode访问数据时ext2的实现方式

union{

struct{

__le32l_i_reserved1;//保留

}linux1;

struct{

__le32h_i_translator;//“翻译者”标签

}hurd1;

struct{

__le32m_i_reserved1;//保留

}masix1;

}osd1;//操作系统相关数据

__le32i_block[EXT2_N_BLOCKS];//定位存储文件的块的数组,前12个为块号,第13个为一级间接块号,第14个为二级间接块号,第15个为三级间接块号

__le32i_generation;//用于NFS的文件版本

__le32i_file_acl;//包含扩展属性的块号,老版本中为0

__le32i_dir_acl;//表示文件的“HighSize”,老版本中为0

__le32i_faddr;//文件最后一个段的地址

union{

struct{

__u8l_i_frag;//段号

__u8l_i_fsize;//段大小

__u16i_pad1;

__le16l_i_uid_high;//文件所有者ID的高16位

__le16l_i_gid_high;//文件所有组ID的高16位

__u32l_i_reserved2;

}linux2;

struct{

__u8h_i_frag;//段号

__u8h_i_fsize;//段大小

__le16h_i_mode_high;

__le16h_i_uid_high;//文件所有者ID的高16位

__le16h_i_gid_high;//文件所有组ID的高16位

__le32h_i_author;

}hurd2;

struct{

__u8m_i_frag;//段号

__u8m_i_fsize;//段大小

__u16m_pad1;

__u32m_i_reserved2[2];

}masix2;

}osd2;//操作系统相关数据

};

5、数据块

数据块中存放文件的内容,包括目录表、扩展属性、符号链接等。

二、目录结构

在ext2文件系统中,目录是作为文件存储的。根目录总是在inode表的第二项,而其子目录则在根目录文件的内容中定义。目录项在include/linux/ext2_fs.h文件中定义,其结构如下:

structext2_dir_entry_2{

__le32inode;//文件入口的inode号,0表示该项未使用

__le16rec_len;//目录项长度

__u8name_len;//文件名包含的字符数

__u8file_type;//文件类型

charname[255];//文件名

};

三、文件扩展属性

文件的属性大多数是位于该文件的inode结构中的标准属性,也还包含其他一些扩展属性(于系统中所有的inode相关,通常用于增加额外的功能),在fs/ext2/xattr.h文件中定义。

inode的i_file_acl字段中保存扩展属性的块的块号。属性头部项位于属性块的起始位置,其后为属性入口项,而属性值可以根据属性入口项找到所在位置。

1、属性头部项

structext2_xattr_header{

__le32h_magic;//标识码,为0xEA020000

__le32h_refcount;//属性块被链接的数目

__le32h_blocks;//用于扩展属性的块数

__le32h_hash;//所有属性的哈希值

__u32h_reserved[4];

};

2、属性入口项

structext2_xattr_entry{

__u8e_name_len;//属性名长度

__u8e_name_index;//属性名索引

__le16e_value_offs;//属性值在值块中的偏移量

__le32e_value_block;//保存值的块的块号

__le32e_value_size;//属性值长度

__le32e_hash;//属性名和值的哈希值

chare_name[0];//属性名

};

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/27624/showart_234187.html

/*

*linux/include/linux/ext2_fs.h

*

*Copyright(C)1992,1993,1994,1995

*RemyCard([email protected])

*LaboratoireMASI-InstitutBlaisePascal

*UniversitePierreetMarieCurie(ParisVI)

*

*from

*

*linux/include/linux/minix_fs.h

*

*Copyright(C)1991,1992LinusTorvalds

*/

#ifndef_LINUX_EXT2_FS_H

#define_LINUX_EXT2_FS_H

#include<linux/types.h>

#include<linux/magic.h>

#include<linux/fs.h>

/*

*Thesecondextendedfilesystemconstants/structures

*/

/*

*DefineEXT2FS_DEBUGtoproducedebugmessages

*/

#undefEXT2FS_DEBUG

/*

*DefineEXT2_RESERVATIONtoreservedatablocksforexpandingfiles

*/

#defineEXT2_DEFAULT_RESERVE_BLOCKS8

/*maxwindowsize:1024(directblocks)+3([t,d]indirectblocks)*/

#defineEXT2_MAX_RESERVE_BLOCKS1027

#defineEXT2_RESERVE_WINDOW_NOT_ALLOCATED0

/*

*Thesecondextendedfilesystemversion

*/

#defineEXT2FS_DATE"95/08/09"

#defineEXT2FS_VERSION"0.5b"

/*

*Debugcode

*/

#ifdefEXT2FS_DEBUG

#defineext2_debug(f,a...){\

printk("EXT2-fsDEBUG(%s,%d):%s:",\

__FILE__,__LINE__,__func__);\

printk(f,##a);\

}

#else

#defineext2_debug(f,a...)/**/

#endif

/*

*Specialinodenumbers

*/

#defineEXT2_BAD_INO1/*Badblocksinode*/

#defineEXT2_ROOT_INO2/*Rootinode*/

#defineEXT2_BOOT_LOADER_INO5/*Bootloaderinode*/

#defineEXT2_UNDEL_DIR_INO6/*Undeletedirectoryinode*/

/*Firstnon-reservedinodeforoldext2filesystems*/

#defineEXT2_GOOD_OLD_FIRST_INO11

/*Assumethatusermodeprogramsarepassinginanext2fssuperblock,not

*akernelstructsuper_block.Thiswillallowustocallthefeature-test

*macrosfromuserland.*/

#defineEXT2_SB(sb)(sb)

/*

*Maximalcountoflinkstoafile

*/

#defineEXT2_LINK_MAX32000

/*

*Macro-instructionsusedtomanageseveralblocksizes

*/

#defineEXT2_MIN_BLOCK_SIZE1024

#defineEXT2_MAX_BLOCK_SIZE4096

#defineEXT2_MIN_BLOCK_LOG_SIZE10

#defineEXT2_BLOCK_SIZE(s)(EXT2_MIN_BLOCK_SIZE<<(s)->s_log_block_size)

#defineEXT2_ADDR_PER_BLOCK(s)(EXT2_BLOCK_SIZE(s)/sizeof(__u32))

#defineEXT2_BLOCK_SIZE_BITS(s)((s)->s_log_block_size+10)

#defineEXT2_INODE_SIZE(s)(((s)->s_rev_level==EXT2_GOOD_OLD_REV)?\

EXT2_GOOD_OLD_INODE_SIZE:\

(s)->s_inode_size)

#defineEXT2_FIRST_INO(s)(((s)->s_rev_level==EXT2_GOOD_OLD_REV)?\

EXT2_GOOD_OLD_FIRST_INO:\

(s)->s_first_ino)

/*

*Macro-instructionsusedtomanagefragments

*/

#defineEXT2_MIN_FRAG_SIZE1024

#defineEXT2_MAX_FRAG_SIZE4096

#defineEXT2_MIN_FRAG_LOG_SIZE10

#defineEXT2_FRAG_SIZE(s)(EXT2_MIN_FRAG_SIZE<<(s)->s_log_frag_size)

#defineEXT2_FRAGS_PER_BLOCK(s)(EXT2_BLOCK_SIZE(s)/EXT2_FRAG_SIZE(s))

/*

*Structureofablocksgroupdescriptor

*/

structext2_group_desc

{

__le32bg_block_bitmap;/*Blocksbitmapblock*/

__le32bg_inode_bitmap;/*Inodesbitmapblock*/

__le32bg_inode_table;/*Inodestableblock*/

__le16bg_free_blocks_count;/*Freeblockscount*/

__le16bg_free_inodes_count;/*Freeinodescount*/

__le16bg_used_dirs_count;/*Directoriescount*/

__le16bg_pad;

__le32bg_reserved[3];

};

/*

*Macro-instructionsusedtomanagegroupdescriptors

*/

#defineEXT2_BLOCKS_PER_GROUP(s)((s)->s_blocks_per_group)

#defineEXT2_DESC_PER_BLOCK(s)(EXT2_BLOCK_SIZE(s)/sizeof(structext2_group_desc))

#defineEXT2_INODES_PER_GROUP(s)((s)->s_inodes_per_group)

/*

*Constantsrelativetothedatablocks

*/

#defineEXT2_NDIR_BLOCKS12

#defineEXT2_IND_BLOCKEXT2_NDIR_BLOCKS

#defineEXT2_DIND_BLOCK(EXT2_IND_BLOCK+1)

#defineEXT2_TIND_BLOCK(EXT2_DIND_BLOCK+1)

#defineEXT2_N_BLOCKS(EXT2_TIND_BLOCK+1)

/*

*Inodeflags(GETFLAGS/SETFLAGS)

*/

#defineEXT2_SECRM_FLFS_SECRM_FL/*Securedeletion*/

#defineEXT2_UNRM_FLFS_UNRM_FL/*Undelete*/

#defineEXT2_COMPR_FLFS_COMPR_FL/*Compressfile*/

#defineEXT2_SYNC_FLFS_SYNC_FL/*Synchronousupdates*/

#defineEXT2_IMMUTABLE_FLFS_IMMUTABLE_FL/*Immutablefile*/

#defineEXT2_APPEND_FLFS_APPEND_FL/*writestofilemayonlyappend*/

#defineEXT2_NODUMP_FLFS_NODUMP_FL/*donotdumpfile*/

#defineEXT2_NOATIME_FLFS_NOATIME_FL/*donotupdateatime*/

/*Reservedforcompressionusage...*/

#defineEXT2_DIRTY_FLFS_DIRTY_FL

#defineEXT2_COMPRBLK_FLFS_COMPRBLK_FL/*Oneormorecompressedclusters*/

#defineEXT2_NOCOMP_FLFS_NOCOMP_FL/*Don'tcompress*/

#defineEXT2_ECOMPR_FLFS_ECOMPR_FL/*Compressionerror*/

/*Endcompressionflags---maybenotallused*/

#defineEXT2_BTREE_FLFS_BTREE_FL/*btreeformatdir*/

#defineEXT2_INDEX_FLFS_INDEX_FL/*hash-indexeddirectory*/

#defineEXT2_IMAGIC_FLFS_IMAGIC_FL/*AFSdirectory*/

#defineEXT2_JOURNAL_DATA_FLFS_JOURNAL_DATA_FL/*Reservedforext3*/

#defineEXT2_NOTAIL_FLFS_NOTAIL_FL/*filetailshouldnotbemerged*/

#defineEXT2_DIRSYNC_FLFS_DIRSYNC_FL/*dirsyncbehaviour(directoriesonly)*/

#defineEXT2_TOPDIR_FLFS_TOPDIR_FL/*Topofdirectoryhierarchies*/

#defineEXT2_RESERVED_FLFS_RESERVED_FL/*reservedforext2lib*/

#defineEXT2_FL_USER_VISIBLEFS_FL_USER_VISIBLE/*Uservisibleflags*/

#defineEXT2_FL_USER_MODIFIABLEFS_FL_USER_MODIFIABLE/*Usermodifiableflags*/

/*Flagsthatshouldbeinheritedbynewinodesfromtheirparent.*/

#defineEXT2_FL_INHERITED(EXT2_SECRM_FL|EXT2_UNRM_FL|EXT2_COMPR_FL|\

EXT2_SYNC_FL|EXT2_IMMUTABLE_FL|EXT2_APPEND_FL|\

EXT2_NODUMP_FL|EXT2_NOATIME_FL|EXT2_COMPRBLK_FL|\

EXT2_NOCOMP_FL|EXT2_JOURNAL_DATA_FL|\

EXT2_NOTAIL_FL|EXT2_DIRSYNC_FL)

/*Flagsthatareappropriateforregularfiles(allbutdir-specificones).*/

#defineEXT2_REG_FLMASK(~(EXT2_DIRSYNC_FL|EXT2_TOPDIR_FL))

/*Flagsthatareappropriatefornon-directories/regularfiles.*/

#defineEXT2_OTHER_FLMASK(EXT2_NODUMP_FL|EXT2_NOATIME_FL)

/*Maskoutflagsthatareinappropriateforthegiventypeofinode.*/

static__inline____u32ext2_mask_flags(umode_tmode,__u32flags)

{

if(S_ISDIR(mode))

returnflags;

elseif(S_ISREG(mode))

returnflags&EXT2_REG_FLMASK;

else

returnflags&EXT2_OTHER_FLMASK;

}

/*

*ioctlcommands

*/

#defineEXT2_IOC_GETFLAGSFS_IOC_GETFLAGS

#defineEXT2_IOC_SETFLAGSFS_IOC_SETFLAGS

#defineEXT2_IOC_GETVERSIONFS_IOC_GETVERSION

#defineEXT2_IOC_SETVERSIONFS_IOC_SETVERSION

#defineEXT2_IOC_GETRSVSZ_IOR('f',5,long)

#defineEXT2_IOC_SETRSVSZ_IOW('f',6,long)

/*

*ioctlcommandsin32bitemulation

*/

#defineEXT2_IOC32_GETFLAGSFS_IOC32_GETFLAGS

#defineEXT2_IOC32_SETFLAGSFS_IOC32_SETFLAGS

#defineEXT2_IOC32_GETVERSIONFS_IOC32_GETVERSION

#defineEXT2_IOC32_SETVERSIONFS_IOC32_SETVERSION

/*

*Structureofaninodeonthedisk

*/

structext2_inode{

__le16i_mode;/*Filemode*/

__le16i_uid;/*Low16bitsofOwnerUid*/

__le32i_size;/*Sizeinbytes*/

__le32i_atime;/*Accesstime*/

__le32i_ctime;/*Creationtime*/

__le32i_mtime;/*Modificationtime*/

__le32i_dtime;/*DeletionTime*/

__le16i_gid;/*Low16bitsofGroupId*/

__le16i_links_count;/*Linkscount*/

__le32i_blocks;/*Blockscount*/

__le32i_flags;/*Fileflags*/

union{

struct{

__le32l_i_reserved1;

}linux1;

struct{

__le32h_i_translator;

}hurd1;

struct{

__le32m_i_reserved1;

}masix1;

}osd1;/*OSdependent1*/

__le32i_block[EXT2_N_BLOCKS];/*Pointerstoblocks*/

__le32i_generation;/*Fileversion(forNFS)*/

__le32i_file_acl;/*FileACL*/

__le32i_dir_acl;/*DirectoryACL*/

__le32i_faddr;/*Fragmentaddress*/

union{

struct{

__u8l_i_frag;/*Fragmentnumber*/

__u8l_i_fsize;/*Fragmentsize*/

__u16i_pad1;

__le16l_i_uid_high;/*these2fields*/

__le16l_i_gid_high;/*werereserved2[0]*/

__u32l_i_reserved2;

}linux2;

struct{

__u8h_i_frag;/*Fragmentnumber*/

__u8h_i_fsize;/*Fragmentsize*/

__le16h_i_mode_high;

__le16h_i_uid_high;

__le16h_i_gid_high;

__le32h_i_author;

}hurd2;

struct{

__u8m_i_frag;/*Fragmentnumber*/

__u8m_i_fsize;/*Fragmentsize*/

__u16m_pad1;

__u32m_i_reserved2[2];

}masix2;

}osd2;/*OSdependent2*/

};

#definei_size_highi_dir_acl

#ifdefined(__KERNEL__)||defined(__linux__)

#definei_reserved1osd1.linux1.l_i_reserved1

#definei_fragosd2.linux2.l_i_frag

#definei_fsizeosd2.linux2.l_i_fsize

#definei_uid_lowi_uid

#definei_gid_lowi_gid

#definei_uid_highosd2.linux2.l_i_uid_high

#definei_gid_highosd2.linux2.l_i_gid_high

#definei_reserved2osd2.linux2.l_i_reserved2

#endif

#ifdef__hurd__

#definei_translatorosd1.hurd1.h_i_translator

#definei_fragosd2.hurd2.h_i_frag

#definei_fsizeosd2.hurd2.h_i_fsize

#definei_uid_highosd2.hurd2.h_i_uid_high

#definei_gid_highosd2.hurd2.h_i_gid_high

#definei_authorosd2.hurd2.h_i_author

#endif

#ifdef__masix__

#definei_reserved1osd1.masix1.m_i_reserved1

#definei_fragosd2.masix2.m_i_frag

#definei_fsizeosd2.masix2.m_i_fsize

#definei_reserved2osd2.masix2.m_i_reserved2

#endif

/*

*Filesystemstates

*/

#defineEXT2_VALID_FS0x0001/*Unmountedcleanly*/

#defineEXT2_ERROR_FS0x0002/*Errorsdetected*/

/*

*Mountflags

*/

#defineEXT2_MOUNT_CHECK0x000001/*Domount-timechecks*/

#defineEXT2_MOUNT_OLDALLOC0x000002/*Don'tusethenewOrlovallocator*/

#defineEXT2_MOUNT_GRPID0x000004/*Createfileswithdirectory'sgroup*/

#defineEXT2_MOUNT_DEBUG0x000008/*Somedebuggingmessages*/

#defineEXT2_MOUNT_ERRORS_CONT0x000010/*Continueonerrors*/

#defineEXT2_MOUNT_ERRORS_RO0x000020/*Remountfsroonerrors*/

#defineEXT2_MOUNT_ERRORS_PANIC0x000040/*Paniconerrors*/

#defineEXT2_MOUNT_MINIX_DF0x000080/*MimicstheMinixstatfs*/

#defineEXT2_MOUNT_NOBH0x000100/*Nobuffer_heads*/

#defineEXT2_MOUNT_NO_UID320x000200/*Disable32-bitUIDs*/

#defineEXT2_MOUNT_XATTR_USER0x004000/*Extendeduserattributes*/

#defineEXT2_MOUNT_POSIX_ACL0x008000/*POSIXAccessControlLists*/

#defineEXT2_MOUNT_XIP0x010000/*Executeinplace*/

#defineEXT2_MOUNT_USRQUOTA0x020000/*userquota*/

#defineEXT2_MOUNT_GRPQUOTA0x040000/*groupquota*/

#defineEXT2_MOUNT_RESERVATION0x080000/*Preallocation*/

#defineclear_opt(o,opt)o&=~EXT2_MOUNT_##opt

#defineset_opt(o,opt)o|=EXT2_MOUNT_##opt

#definetest_opt(sb,opt)(EXT2_SB(sb)->s_mount_opt&\

EXT2_MOUNT_##opt)

/*

*Maximalmountcountsbetweentwofilesystemchecks

*/

#defineEXT2_DFL_MAX_MNT_COUNT20/*Allow20mounts*/

#defineEXT2_DFL_CHECKINTERVAL0/*Don'tuseintervalcheck*/

/*

*Behaviourwhendetectingerrors

*/

#defineEXT2_ERRORS_CONTINUE1/*Continueexecution*/

#defineEXT2_ERRORS_RO2/*Remountfsread-only*/

#defineEXT2_ERRORS_PANIC3/*Panic*/

#defineEXT2_ERRORS_DEFAULTEXT2_ERRORS_CONTINUE

/*

*Structureofthesuperblock

*/

structext2_super_block{

__le32s_inodes_count;/*Inodescount*/

__le32s_blocks_count;/*Blockscount*/

__le32s_r_blocks_count;/*Reservedblockscount*/

__le32s_free_blocks_count;/*Freeblockscount*/

__le32s_free_inodes_count;/*Freeinodescount*/

__le32s_first_data_block;/*FirstDataBlock*/

__le32s_log_block_size;/*Blocksize*/

__le32s_log_frag_size;/*Fragmentsize*/

__le32s_blocks_per_group;/*#Blockspergroup*/

__le32s_frags_per_group;/*#Fragmentspergroup*/

__le32s_inodes_per_group;/*#Inodespergroup*/

__le32s_mtime;/*Mounttime*/

__le32s_wtime;/*Writetime*/

__le16s_mnt_count;/*Mountcount*/

__le16s_max_mnt_count;/*Maximalmountcount*/

__le16s_magic;/*Magicsignature*/

__le16s_state;/*Filesystemstate*/

__le16s_errors;/*Behaviourwhendetectingerrors*/

__le16s_minor_rev_level;/*minorrevisionlevel*/

__le32s_lastcheck;/*timeoflastcheck*/

__le32s_checkinterval;/*max.timebetweenchecks*/

__le32s_creator_os;/*OS*/

__le32s_rev_level;/*Revisionlevel*/

__le16s_def_resuid;/*Defaultuidforreservedblocks*/

__le16s_def_resgid;/*Defaultgidforreservedblocks*/

/*

*ThesefieldsareforEXT2_DYNAMIC_REVsuperblocksonly.

*

*Note:thedifferencebetweenthecompatiblefeaturesetand

*theincompatiblefeaturesetisthatifthereisabitset

*intheincompatiblefeaturesetthatthekerneldoesn't

*knowabout,itshouldrefusetomountthefilesystem.

*

*e2fsck'srequirementsaremorestrict;ifitdoesn'tknow

*aboutafeatureineitherthecompatibleorincompatible

*featureset,itmustabortandnottrytomeddlewith

*thingsitdoesn'tunderstand...

*/

__le32s_first_ino;/*Firstnon-reservedinode*/

__le16s_inode_size;/*sizeofinodestructure*/

__le16s_block_group_nr;/*blockgroup#ofthissuperblock*/

__le32s_feature_compat;/*compatiblefeatureset*/

__le32s_feature_incompat;/*incompatiblefeatureset*/

__le32s_feature_ro_compat;/*readonly-compatiblefeatureset*/

__u8s_uuid[16];/*128-bituuidforvolume*/

chars_volume_name[16];/*volumename*/

chars_last_mounted[64];/*directorywherelastmounted*/

__le32s_algorithm_usage_bitmap;/*Forcompression*/

/*

*Performancehints.Directorypreallocationshouldonly

*happeniftheEXT2_COMPAT_PREALLOCflagison.

*/

__u8s_prealloc_blocks;/*Nrofblockstotrytopreallocate*/

__u8s_prealloc_dir_blocks;/*Nrtopreallocatefordirs*/

__u16s_padding1;

/*

*JournalingsupportvalidifEXT3_FEATURE_COMPAT_HAS_JOURNALset.

*/

__u8s_journal_uuid[16];/*uuidofjournalsuperblock*/

__u32s_journal_inum;/*inodenumberofjournalfile*/

__u32s_journal_dev;/*devicenumberofjournalfile*/

__u32s_last_orphan;/*startoflistofinodestodelete*/

__u32s_hash_seed[4];/*HTREEhashseed*/

__u8s_def_hash_version;/*Defaulthashversiontouse*/

__u8s_reserved_char_pad;

__u16s_reserved_word_pad;

__le32s_default_mount_opts;

__le32s_first_meta_bg;/*Firstmetablockblockgroup*/

__u32s_reserved[190];/*Paddingtotheendoftheblock*/

};

/*

*Codesforoperatingsystems

*/

#defineEXT2_OS_LINUX0

#defineEXT2_OS_HURD1

#defineEXT2_OS_MASIX2

#defineEXT2_OS_FREEBSD3

#defineEXT2_OS_LITES4

/*

*Revisionlevels

*/

#defineEXT2_GOOD_OLD_REV0/*Thegoodold(original)format*/

#defineEXT2_DYNAMIC_REV1/*V2formatw/dynamicinodesizes*/

#defineEXT2_CURRENT_REVEXT2_GOOD_OLD_REV

#defineEXT2_MAX_SUPP_REVEXT2_DYNAMIC_REV

#defineEXT2_GOOD_OLD_INODE_SIZE128

/*

*Featuresetdefinitions

*/

#defineEXT2_HAS_COMPAT_FEATURE(sb,mask)\

(EXT2_SB(sb)->s_es->s_feature_compat&cpu_to_le32(mask))

#defineEXT2_HAS_RO_COMPAT_FEATURE(sb,mask)\

(EXT2_SB(sb)->s_es->s_feature_ro_compat&cpu_to_le32(mask))

#defineEXT2_HAS_INCOMPAT_FEATURE(sb,mask)\

(EXT2_SB(sb)->s_es->s_feature_incompat&cpu_to_le32(mask))

#defineEXT2_SET_COMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_compat|=cpu_to_le32(mask)

#defineEXT2_SET_RO_COMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_ro_compat|=cpu_to_le32(mask)

#defineEXT2_SET_INCOMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_incompat|=cpu_to_le32(mask)

#defineEXT2_CLEAR_COMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_compat&=~cpu_to_le32(mask)

#defineEXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_ro_compat&=~cpu_to_le32(mask)

#defineEXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)\

EXT2_SB(sb)->s_es->s_feature_incompat&=~cpu_to_le32(mask)

#defineEXT2_FEATURE_COMPAT_DIR_PREALLOC0x0001

#defineEXT2_FEATURE_COMPAT_IMAGIC_INODES0x0002

#defineEXT3_FEATURE_COMPAT_HAS_JOURNAL0x0004

#defineEXT2_FEATURE_COMPAT_EXT_ATTR0x0008

#defineEXT2_FEATURE_COMPAT_RESIZE_INO0x0010

#defineEXT2_FEATURE_COMPAT_DIR_INDEX0x0020

#defineEXT2_FEATURE_COMPAT_ANY0xffffffff

#defineEXT2_FEATURE_RO_COMPAT_SPARSE_SUPER0x0001

#defineEXT2_FEATURE_RO_COMPAT_LARGE_FILE0x0002

#defineEXT2_FEATURE_RO_COMPAT_BTREE_DIR0x0004

#defineEXT2_FEATURE_RO_COMPAT_ANY0xffffffff

#defineEXT2_FEATURE_INCOMPAT_COMPRESSION0x0001

#defineEXT2_FEATURE_INCOMPAT_FILETYPE0x0002

#defineEXT3_FEATURE_INCOMPAT_RECOVER0x0004

#defineEXT3_FEATURE_INCOMPAT_JOURNAL_DEV0x0008

#defineEXT2_FEATURE_INCOMPAT_META_BG0x0010

#defineEXT2_FEATURE_INCOMPAT_ANY0xffffffff

#defineEXT2_FEATURE_COMPAT_SUPPEXT2_FEATURE_COMPAT_EXT_ATTR

#defineEXT2_FEATURE_INCOMPAT_SUPP(EXT2_FEATURE_INCOMPAT_FILETYPE|\

EXT2_FEATURE_INCOMPAT_META_BG)

#defineEXT2_FEATURE_RO_COMPAT_SUPP(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\

EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\

EXT2_FEATURE_RO_COMPAT_BTREE_DIR)

#defineEXT2_FEATURE_RO_COMPAT_UNSUPPORTED~EXT2_FEATURE_RO_COMPAT_SUPP

#defineEXT2_FEATURE_INCOMPAT_UNSUPPORTED~EXT2_FEATURE_INCOMPAT_SUPP

/*

*Defaultvaluesforuserand/orgroupusingreservedblocks

*/

#defineEXT2_DEF_RESUID0

#defineEXT2_DEF_RESGID0

/*

*Defaultmountoptions

*/

#defineEXT2_DEFM_DEBUG0x0001

#defineEXT2_DEFM_BSDGROUPS0x0002

#defineEXT2_DEFM_XATTR_USER0x0004

#defineEXT2_DEFM_ACL0x0008

#defineEXT2_DEFM_UID160x0010

/*Notusedbyext2,butreservedforusebyext3*/

#defineEXT3_DEFM_JMODE0x0060

#defineEXT3_DEFM_JMODE_DATA0x0020

#defineEXT3_DEFM_JMODE_ORDERED0x0040

#defineEXT3_DEFM_JMODE_WBACK0x0060

/*

*Structureofadirectoryentry

*/

#defineEXT2_NAME_LEN255

structext2_dir_entry{

__le32inode;/*Inodenumber*/

__le16rec_len;/*Directoryentrylength*/

__le16name_len;/*Namelength*/

charname[EXT2_NAME_LEN];/*Filename*/

};

/*

*Thenewversionofthedirectoryentry.SinceEXT2structuresare

*storedinintelbyteorder,andthename_lenfieldcouldneverbe

*biggerthan255chars,it'ssafetoreclaimtheextrabyteforthe

*file_typefield.

*/

structext2_dir_entry_2{

__le32inode;/*Inodenumber*/

__le16rec_len;/*Directoryentrylength*/

__u8name_len;/*Namelength*/

__u8file_type;

charname[EXT2_NAME_LEN];/*Filename*/

};

/*

*Ext2directoryfiletypes.Onlythelow3bitsareused.The

*otherbitsarereservedfornow.

*/

enum{

EXT2_FT_UNKNOWN=0,

EXT2_FT_REG_FILE=1,

EXT2_FT_DIR=2,

EXT2_FT_CHRDEV=3,

EXT2_FT_BLKDEV=4,

EXT2_FT_FIFO=5,

EXT2_FT_SOCK=6,

EXT2_FT_SYMLINK=7,

EXT2_FT_MAX

};

/*

*EXT2_DIR_PADdefinesthedirectoryentriesboundaries

*

*NOTE:Itmustbeamultipleof4

*/

#defineEXT2_DIR_PAD4

#defineEXT2_DIR_ROUND(EXT2_DIR_PAD-1)

#defineEXT2_DIR_REC_LEN(name_len)(((name_len)+8+EXT2_DIR_ROUND)&\

~EXT2_DIR_ROUND)

#defineEXT2_MAX_REC_LEN((1<<16)-1)

#endif/*_LINUX_EXT2_FS_H*/

相关推荐