浅谈Linux的inode


linux中inode是个什么概念呢?简单的说inode是一个不能重复的标号一样,每个文件或目录对应一个inode值,那个inode包含哪些部分,有什么作用呢?这里拿ext3文件系统的inode数据结构来说:
struct ext3_inode {
 __u16 i_mode;    /* File mode */
 __u16 i_uid;     /* Low 16 bits of Owner Uid */
 __u32 i_size;    /* 文件大小,单位是 byte */
 __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 计数 */
 __u32 i_flags;                /* File flags */
 __u32 l_i_reserved1;          /* 可以忽略 */
 __u32 i_block[EXT3_N_BLOCKS]; /* 一组 block 指针 ,指向数据文件在磁盘上的指针*/
 __u32 i_generation;           /* 可以忽略 */
 __u32 i_file_acl;             /* 可以忽略 */
 __u32 i_dir_acl;              /* 可以忽略 */
 __u32 i_faddr;                /* 可以忽略 */
 __u8  l_i_frag;               /* 可以忽略 */
 __u8  l_i_fsize;              /* 可以忽略 */
 __u16 i_pad1;                 /* 可以忽略 */
 __u16 l_i_uid_high;           /* 可以忽略 */
 __u16 l_i_gid_high;           /* 可以忽略 */
 __u32 l_i_reserved2;          /* 可以忽略 */
};
之前在(浅析ext3删除文件慢的原因 )也简单研究过它。

因为inode主要是占用磁盘空间的,那么今天就讨论一下inode分配与占用磁盘问题,之前听人说xfs文件系统inode占用的磁盘空间达到了相当多G,当然这是因为他的文件系统本来就是用来存放小文件的,所以导致inode占用的空间也很大。

在你为一个硬盘或是分区建好文件系统以后,文件系统已经确定了这块硬盘或是分区最后能有多少inode被分配,这些inode能占用多大的空间。查看一个硬盘或分区的文件系统信息,可以通过dumpe2fs -h device_name 来查看,比如我的系统中一个分区/dev/sda8 (ext3)
$ dumpe2fs -h /dev/sda8

dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:   home
Last mounted on:          <not available>
Filesystem UUID:          78a58693-dc1a-43c0-9eaf-6c0807626c14
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file
Filesystem flags:         signed_directory_hash 
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              16318464
Block count:              65241965
Reserved block count:     652419
Free blocks:              58319070
Free inodes:              16135620
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      1008
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Filesystem created:       Fri Oct 14 16:13:01 2011
Last mount time:          Wed Feb 29 16:29:51 2012
Last write time:          Wed Feb 29 16:29:51 2012
Mount count:              5
Maximum mount count:      -1
Last checked:             Fri Oct 14 16:13:01 2011
Check interval:           0 (<none>)
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:          256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
First orphan inode:       8437776
Default directory hash:   half_md4
Directory Hash Seed:      0eddc0e6-7fa9-4226-8534-59b633b5e88b
Journal backup:           inode blocks
Journal features:         journal_incompat_revoke
日志大小:             128M
Journal length:           32768
Journal sequence:         0x006cea77
Journal start:            3735
  • 1
  • 2
  • 下一页

相关内容