如何在ext4 inode块中存储“扩展属性”,因为我们有inode额外的大小“i_extra_isize”

时间:2014-12-10 05:07:11

标签: filesystems inode ext4

根据

struct ext4_inode {
  .....
  __le16  i_extra_isize;
  .....
}

我看到这可用于存储扩展属性,因为我使用的是inode size = 256字节。几个问题:

  1. 我如何知道我的FS inode大小是256还是128字节?
  2. 如何设置小扩展属性(< 10字节)并将其存储在额外区域? (原因:性能很重要),因为我相信不会有额外的IO块读取它的连续性。 Fileystem / C lib为此调用了什么?典型的系统会调用" setattr"做这个?我一直在设置命令行" setfattr"并且不确定它是否在inode 128字节之后分配给额外区域。
  3. 是什么内存结构用于在128个字节的inode之后映射额外的字节,这是我想要存储我的小扩展属性的地方。

1 个答案:

答案 0 :(得分:1)

  

我如何知道我的FS inode大小是256还是128字节?

$ sudo tune2fs -l /dev/sda2  | egrep -i 'inode size'
Inode size:               256
  

如何设置小扩展属性

Ext3 / 4支持可配置的inode大小(来自-I选项mkfs.ext {3,4} cmd参数),但默认的inode大小为128个字节。 Ext4默认为256个字节。这需要适应一些额外的字段(如纳秒时间戳或inode版本控制),并且inode的剩余空间将用于存储足够小以适合该空间的扩展属性。您还可以查看fs / ext4 / file.c实现的函数:struct inode_operations {.setattr,.getattr}。

  

Fileystem / C lib调用了什么?

请参阅API setxattr(), lsetxattr(), fsetxattr()以设置扩展属性编程。使用命令attr, lsattr, chattr测试设置文件的扩展属性。您也可以look into

  

是什么内存结构用于在128个字节的inode之后映射额外的字节,这是我想要存储我的小扩展属性的地方。

参考fs/ext4/xattr.c

"

* Extended attributes are stored directly in inodes (on file systems with
 18  * inodes bigger than 128 bytes) and on additional disk blocks. The i_file_acl
 19  * field contains the block number if an inode uses an additional block. All
 20  * attributes must fit in the inode and one additional block. Blocks that
 21  * contain the identical set of attributes may be shared among several inodes.
 22  * Identical blocks are detected by keeping a cache of blocks that have
 23  * recently been accessed.
 24  *
 25  * The attributes in inodes and on blocks have a different header; the entries
 26  * are stored in the same format:
 27  *
 28  *   +------------------+
 29  *   | header           |
 30  *   | entry 1          | |
 31  *   | entry 2          | | growing downwards
 32  *   | entry 3          | v
 33  *   | four null bytes  |
 34  *   | . . .            |
 35  *   | value 1          | ^
 36  *   | value 3          | | growing upwards
 37  *   | value 2          | |
 38  *   +------------------+
 39  *
 40  * The header is followed by multiple entry descriptors. In disk blocks, the
 41  * entry descriptors are kept sorted. In inodes, they are unsorted. The
 42  * attribute values are aligned to the end of the block in no specific order.

"