12

I have a small question about extended file attributes. Assume I label my files with metadata in extended attributes (e.g. to account for the integrity - but this does not matter for my question). The questions that arise now:

  • Where are these attributes stored? Surely not in the inode I guess, but in what location - or better: structure?
  • How are these attributes connected to a file? Is there a link from the attribute structture to the inode or so?
  • What happens when copying/moving around files? I just tested it, when moving a file, the file remains its attributes. When copying it, the copy does not have attributes. So I assume whe burning it to CD or emailing the file, it will also lose its attributes?

1 Answer 1

11

The answer to you question is filesystem specific. For ext3, for example, have a look at fs/ext3/xattr.c, it contains the following description:

  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  */

Regarding the "how are attributes connected" question, the link is in the other way round, the inode has a link to the extended attributes, see EXT3_XATTR_NEXT and ext3_xattr_list_entries in xattr.h and xattr.c respectively.

To recap, the attributes are linked to the inode and are fs dependent, so yes, you will lose the attributes when burning a CD rom or emailing a file.

1
  • 6
    One minor detail that is not answered here: You can preserve the attributes when copying (of course you have to copy to a filesystem with xattr support). cp has an option "--preserve=xattr" Apr 20, 2011 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .