V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
liuxu
V2EX  ›  Linux

ext4 文件系统的 inode 是 256 字节,核心结构是 160 字节

  •  1
     
  •   liuxu ·
    liuquanhao · 2016-04-03 02:14:57 +08:00 · 2906 次点击
    这是一个创建于 2961 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天在复习《鸟哥的私房菜-基础学习篇》,看到 inode 大小为 128bytes ,想看下这 128 字节里面到底是什么样的。于是我查了下 google ,发现 ext2/3 是 128 字节, ext4 是 256 字节了。

    官方介绍: https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Size

    它说 ext4 的 inode 结构最后面新加了 28 字节( i_extra_isize = 28 ),是 156 字节 (在 2013 年),然后我查了下 ext4_inode 的代码:

    https://gist.github.com/liuxu0315/9687560faab54bff77b06e91a93ab5dc

    以为我眼花了,算了好几遍,怎么算都是 32 字节, ext4 的 inode 结构应该是 160 字节才对。我一想,可能是官方 wiki 太老了, ext4 的代码在 2013 年之后改动过,于是我到 github 上 clone 了 linux 源码,用 git log 一查,果然被改过。

        $ git clone https://github.com/torvalds/linux.git
        $ cd linux
        $ git log -L 753,761:fs/ext4/ext4.h
    

    输出:

    commit 8b4953e13f4c5d9a3c869f5fca7d51e1700e7db0
    Author: Theodore Ts'o <[email protected]>
    Date:   Sat Oct 17 16:15:18 2015 -0400
    
        ext4: reserve code points for the project quota feature
        
        Signed-off-by: Theodore Ts'o <[email protected]>
    
    diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
    --- a/fs/ext4/ext4.h
    +++ b/fs/ext4/ext4.h
    @@ -687,8 +690,9 @@
            __le16  i_extra_isize;
            __le16  i_checksum_hi;  /* crc32c(uuid+inum+inode) BE */
            __le32  i_ctime_extra;  /* extra Change time      (nsec << 2 | epoch) */
            __le32  i_mtime_extra;  /* extra Modification time(nsec << 2 | epoch) */
            __le32  i_atime_extra;  /* extra Access time      (nsec << 2 | epoch) */
            __le32  i_crtime;       /* File Creation time */
            __le32  i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
            __le32  i_version_hi;   /* high 32 bits for 64-bit version */
    +       __le32  i_projid;       /* Project ID */
    

    可以看见在 2015 年 10 月的时候加了“__le32 i_projid; /* Project ID */”,所以比 2013 年的 ext4_inode 多了 4 字节,为 160 字节。

    顺便贴上我的 blog ,只谈技术。 我是个新手,有对我文笔有建议的希望能直接指出,谢谢。

    http://www.cnblogs.com/liuxuzzz/

    3 条回复    2016-04-03 11:50:58 +08:00
    pynix
        1
    pynix  
       2016-04-03 04:04:51 +08:00
    貌似向后兼容的。
    Joming
        2
    Joming  
       2016-04-03 09:38:59 +08:00
    inode 看成 Linode 的举手。
    liuxu
        3
    liuxu  
    OP
       2016-04-03 11:50:58 +08:00
    @pynix 对的

    #define EXT4_GOOD_OLD_INODE_SIZE 128
    ...
    #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
    ...
    /* s 一般是 super_block */
    #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
    EXT4_GOOD_OLD_INODE_SIZE : \
    (s)->s_inode_size)


    /*s_inode_size :
    sbi 是 ext4_sb_info , sb=superblock
    */

    if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
    sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
    sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
    } else {
    sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
    sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
    ...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2979 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:17 · PVG 23:17 · LAX 08:17 · JFK 11:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.