扩展属性如何存储和保留?


11

我对扩展文件属性有一个小问题。假设我使用扩展属性中的元数据来标记我的文件(例如,考虑到完整性,但这对我的问题无关紧要)。现在出现的问题:

  • 这些属性存储在哪里?我想当然不是在索引节点中,而是在哪个位置-或更合适的是:结构?
  • 这些属性如何连接到文件?从属性结构到索引节点之间是否存在链接?
  • 在文件中复制/移动时会发生什么?我刚刚测试了它,当移动文件时,文件仍然保留其属性。复制时,副本没有属性。因此,我假设将其刻录到CD或通过电子邮件发送文件,它也会丢失其属性吗?

Answers:


10

您的问题的答案是特定于文件系统的。例如,对于ext3,请查看fs / ext3 / xattr.c,其中包含以下描述:

  16 /*
  17  * 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.
  43  *
  44  * Locking strategy
  45  * ----------------
  46  * EXT3_I(inode)->i_file_acl is protected by EXT3_I(inode)->xattr_sem.
  47  * EA blocks are only changed if they are exclusive to an inode, so
  48  * holding xattr_sem also means that nothing but the EA block's reference
  49  * count can change. Multiple writers to the same block are synchronized
  50  * by the buffer lock.
  51  */

关于“如何连接属性”的问题,该链接是倒过来,这个inode有一个链接到扩展属性,看到EXT3_XATTR_NEXText3_xattr_list_entries分别在xattr.h和xattr.c。

回顾一下,这些属性链接到inode并依赖于fs,因此,是的,在刻录CD rom或通过电子邮件发送文件时,您将丢失这些属性。


6
这里没有回答一个小细节:复制时可以保留属性(当然,必须复制到具有xattr支持的文件系统)。cp有一个选项“ --preserve = xattr”
Marcel Stimberg 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.