ext2/3/4的inode结构说明
系统环境:Ubuntu15.10/ext4
今天在复习《鸟哥的私房菜-基础学习篇》,看到inode大小为128bytes,想看下这128字节里面到底是什么样的。
于是我查了下google,发现ext2/3是128字节,ext4是256字节,以下是ext2/ext4对应的结构。
ext2.h/ext2_inode:
/*
295 * Structure of an inode on the disk
296 */
struct ext2_inode {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
__le32 i_size; /* Size in bytes */
__le32 i_atime; /* Access time */
__le32 i_ctime; /* Creation time */
__le32 i_mtime; /* Modification time */
__le32 i_dtime; /* Deletion Time */
__le16 i_gid; /* Low 16 bits of Group Id */
__le16 i_links_count; /* Links count */
__le32 i_blocks; /* Blocks count */
__le32 i_flags; /* File flags */
union {
struct {
__le32 l_i_reserved1;
} linux1;
struct {
__le32 h_i_translator;
} hurd1;
struct {
__le32 m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
__le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__le32 i_generation; /* File version (for NFS) */
__le32 i_file_acl; /* File ACL */
__le32 i_dir_acl; /* Directory ACL */
__le32 i_faddr; /* Fragment address */
union {
struct {
__u8 l_i_frag; /* Fragment number */
__u8 l_i_fsize; /* Fragment size */
__u16 i_pad1;
__le16 l_i_uid_high; /* these 2 fields */
__le16 l_i_gid_high; /* were reserved2[0] */
__u32 l_i_reserved2;
} linux2;
struct {
__u8 h_i_frag; /* Fragment number */
__u8 h_i_fsize; /* Fragment size */
__le16 h_i_mode_high;
__le16 h_i_uid_high;
__le16 h_i_gid_high;
__le32 h_i_author;
} hurd2;
struct {
__u8 m_i_frag; /* Fragment number */
__u8 m_i_fsize; /* Fragment size */
__u16 m_pad1;
__u32 m_i_reserved2[];
} masix2;
} osd2; /* OS dependent 2 */
};
ext4.h/ext4_inode:
/*
689 * Structure of an inode on the disk
690 */
struct ext4_inode {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
__le32 i_size_lo; /* Size in bytes */
__le32 i_atime; /* Access time */
__le32 i_ctime; /* Inode Change time */
__le32 i_mtime; /* Modification time */
__le32 i_dtime; /* Deletion Time */
__le16 i_gid; /* Low 16 bits of Group Id */
__le16 i_links_count; /* Links count */
__le32 i_blocks_lo; /* Blocks count */
__le32 i_flags; /* File flags */
union {
struct {
__le32 l_i_version;
} linux1;
struct {
__u32 h_i_translator;
} hurd1;
struct {
__u32 m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
__le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
__le32 i_generation; /* File version (for NFS) */
__le32 i_file_acl_lo; /* File ACL */
__le32 i_size_high;
__le32 i_obso_faddr; /* Obsoleted fragment address */
union {
struct {
__le16 l_i_blocks_high; /* were l_i_reserved1 */
__le16 l_i_file_acl_high;
__le16 l_i_uid_high; /* these 2 fields */
__le16 l_i_gid_high; /* were reserved2[0] */
__le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
__le16 l_i_reserved;
} linux2;
struct {
__le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
__u16 h_i_mode_high;
__u16 h_i_uid_high;
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
struct {
__le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
__le16 m_i_file_acl_high;
__u32 m_i_reserved2[];
} masix2;
} osd2; /* OS dependent 2 */
741 __le16 i_extra_isize;
742 __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */
743 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
744 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
745 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
746 __le32 i_crtime; /* File Creation time */
747 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
748 __le32 i_version_hi; /* high 32 bits for 64-bit version */
749 __le32 i_projid; /* Project ID */
};
可以看见ext4_inode仅仅是最下面多了一点。
以下是官方介绍:
Inode Size In ext2 and ext3, the inode structure size was fixed at bytes (EXT2_GOOD_OLD_INODE_SIZE) and each inode had a disk record size of bytes.
Starting with ext4, it is possible to allocate a larger on-disk inode at format time for all inodes in the filesystem to provide space beyond
the end of the original ext2 inode. The on-disk inode record size is recorded in the superblock as s_inode_size. The number of bytes actually
used by struct ext4_inode beyond the original -byte ext2 inode is recorded in the i_extra_isize field for each inode, which allows struct
ext4_inode to grow for a new kernel without having to upgrade all of the on-disk inodes. Access to fields beyond EXT2_GOOD_OLD_INODE_SIZE should
be verified to be within i_extra_isize. By default, ext4 inode records are bytes, and (as of October ) the inode structure is bytes
(i_extra_isize = ). The extra space between the end of the inode structure and the end of the inode record can be used to store extended
attributes. Each inode record can be as large as the filesystem block size, though this is not terribly efficient.
官方说2013年8月,i_extra_isize是28字节,ext4_inode是156字节(128+28)。但我今天贴的ext4_inode代码,后面的i_extra_isize部分应该
是32字节(i_extra_isize + i_checksum_hi + 4 * 7),所以ext4_inode应该是160字节(128+32)。
为了确定,我去github克隆了linus的linux源码。
$ git clone https://github.com/torvalds/linux.git
$ cd linux
$ git log -L ,:fs/ext4/ext4.h
753到761就是i_extra_isize下面的几行,可以自己查看一位置。
结果log输出:
commit 8b4953e13f4c5d9a3c869f5fca7d51e1700e7db0
Author: Theodore Ts'o <tytso@mit.edu>
Date: Sat Oct :: - 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
@@ -, +, @@
__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 */ commit e615391896064eb5a0c760d086b8e1c6ecfffeab
Author: Darrick J. Wong <djwong@us.ibm.com>
Date: Sun Apr :: - ext4: change on-disk layout to support extended metadata checksumming Define flags and change structure definitions to allow checksumming of
ext4 metadata. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
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
@@ -, +, @@
__le16 i_extra_isize;
- __le16 i_pad1;
+ __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 */ commit 3dcf54515aa4981a647ad74859199032965193a5
Author: Christoph Hellwig <hch@lst.de>
Date: Tue Apr :: - ext4: move headers out of include/linux Move ext4 headers out of include/linux. This is just the trivial move,
there's some more thing that could be done later. Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
--- /dev/null
+++ b/fs/ext4/ext4.h
@@ -, +, @@
+ __le16 i_extra_isize;
+ __le16 i_pad1;
+ __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 */
这下就清楚了,可以看见,2015年10月17号有一次提交,加了一行“__le32 i_projid; /* Project ID */”,所以多了4字节,之前2012年和2008年的代码确实都是28字节。
回到正题,linux的ext4文件系统的inode是256字节,ext4_inode却只有160字节,那160到255字节有啥用呢,它们可以用来存放其它属性,如ACL,SELinux的属性。
I think by default current versions of mkfs.ext2// default to byte inode size (see /etc/mke2fs.conf). This IIRC enables nanosecond
timestamps with ext4, and as you say, more extended attributes fit within the inode. Such extended attributes are, for instance, ACL's,
SELinux labels, some Samba specific labels. Bigger inodes of course waste a little bit of space, and as you make them bigger you get into diminishing returns territory pretty quickly.
The default bytes is probably a perfectly good compromise for most situations.
参考:
ext2.h:http://lxr.free-electrons.com/source/fs/ext2/ext2.h#L297
ext4.h:http://lxr.free-electrons.com/source/fs/ext4/ext4.h#L688
ext4的inode介绍:https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Size
ext4扩展部分使用介绍:http://serverfault.com/questions/143691/linux-why-change-inode-size
linux源码github地址:https://github.com/torvalds/linux
ext2/3/4的inode结构说明的更多相关文章
- inode结构体成员详解
概述:inode译成中文就是索引节点,它用来存放档案及目录的基本信息,包含时间.档名.使用者及群组等.inode分为内存中的inode和文件系统中的inode,为了避免混淆,我们称前者为VFS ino ...
- 深入浅出理解linux inode结构
一.inode是什么? 参考文档:http://tech.diannaodian.com/dw/lin/2012/0112/154629.html 做Android底层驱动或者嵌入式Linux的程序猿 ...
- 深入浅出理解linux inode结构【转】
本文转载自:https://blog.csdn.net/fantasyhujian/article/details/9151615 一.inode是什么? 参考文档:http://tech.diann ...
- linux inode 结构
inode 结构由内核在内部用来表示文件. 因此, 它和代表打开文件描述符的文件结构是不 同的. 可能有代表单个文件的多个打开描述符的许多文件结构, 但是它们都指向一个单个 inode 结构. ino ...
- inode结构体
inode分为内存中的inode和文件系统中的inode,为了避免混淆,我们称前者为VFS inode, 而后者以EXT2为代表,我们称为Ext2 inod.这里说明的是VFS inode. 重要成员 ...
- ext2元数据结构
概述 本篇博客主要描述ext2文件系统中的各种典型元数据结构,其中包括文件系统级别的元数据,如超级块,块组描述符等,也包括文件级的元数据,如文件目录项,文件inode等. ex ...
- inode file 结构
inode位图(inode Bitmap) 和块位图类似,本身占一个块,其中每个bit表示一个inode是否空闲可用. inode表(inode Table) 我们知道,一个文件除了数据需要存储之外, ...
- 文件存储结构inode与RAM结构建立联系
linux下一切皆文件,大致可分为以下几类:目录.普通文件.硬连接.软连接.字符设备.块设备.FIFO.Socket,其在物理存储体内存储按inode和数据块存储,inode代表元数据,是除实际数据外 ...
- Linux字符设备中的两个重要结构体(file、inode)
对于Linux系统中,一般字符设备和驱动之间的函数调用关系如下图所示 上图描述了用户空间应用程序通过系统调用来调用程序的过程.一般而言在驱动程序的设计中,会关系 struct file 和 struc ...
随机推荐
- 如何用eclipse运行导入的maven项目
1.配置jdk系统环境变量.找到安装的jdk的安装目录,新建系统环境变量,变量名为JAVA_HOME(作为一个引用),变量值为该路径. 找到Path,将%JAVA_HOME%/bin; 添加到变量值的 ...
- 图学java基础篇之并发
概述 并发处理本身就是编程开发重点之一,同时内容也很繁杂,从底层指令处理到上层应用开发都要涉及,也是最容易出问题的地方.这块知识也是评价一个开发人员水平的重要指标,本人自认为现在也只是学其皮毛,因此本 ...
- CQRS之旅——旅程5(准备发布V1版本)
旅程5:准备发布V1版本 添加功能和重构,为V1版本发布做准备. "大多数人在完成一件事之后,就像留声机的唱片一样,一遍又一遍地使用它,直到它破碎,忘记了过去是用来创造更多未来的东西.&qu ...
- 读取手机联系人,并用listview显示
读取手机联系人,用到的就是一个contentprovider. 数据库里面有三张重要的表 raw_contact 里面有所有联系人的数据 data 每个联系人的所有数据 mime-type 每条数据的 ...
- Spring MVC学习总结
Spring MVC学习总结 Spring MVC学习路(一) 下载配置文件 Spring MVC学习路(二) 设置配置文件 Spring MVC学习路(三) 编写第一个demo Spring MVC ...
- Asp.net Mvc 页面静态化
http://www.cnblogs.com/gowhy/archive/2013/01/01/2841472.html
- IOS开发---菜鸟学习之路--(十)-实现新闻详细信息浏览页面
前面已经将了上下拉刷新 实现了上下拉刷新后我们的第一级界面就做好,接下来我们就需要实现 新闻详细信息浏览了 我个人认为一般实现新闻详细页面的方法有两种(主要是数据源的不同导致了方法的不同) 第一种是本 ...
- mysql数据库增、删、改、查等基本命令
测试环境:windows7 64位 mysql.exe.Navicat Lite for MySQL.mysql 5.0.18 mysql数据库的基本结构: 数据库(database)包含多个表(ta ...
- github 客户端总是登录失败,提示密码错误
把输入法调成英文即可!!
- 安装配置apache sentry服务
环境 系统环境:Centos6.7 Hadoop版本:CDH5.10 jdk版本:jdk7 注:本文并未集成kerberos组件 安装Sentry Server 选择安装hive的节点进行安装测试: ...