歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 淺談Linux的inode

淺談Linux的inode

日期:2017/2/28 15:52:15   编辑:Linux教程
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刪除文件慢的原因 http://www.linuxidc.com/Linux/2012-05/59492.htm)也簡單研究過它。

因為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
Copyright © Linux教程網 All Rights Reserved