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

2016-04-03 02:14:57 +08:00
 liuxu

今天在复习《鸟哥的私房菜-基础学习篇》,看到 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 <tytso@mit.edu>
Date:   Sat Oct 17 16:15:18 2015 -0400

    ext4: reserve code points for the project quota feature
    
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>

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/

2913 次点击
所在节点    Linux
3 条回复
pynix
2016-04-03 04:04:51 +08:00
貌似向后兼容的。
Joming
2016-04-03 09:38:59 +08:00
inode 看成 Linode 的举手。
liuxu
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);
...

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/268209

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX