Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


The comments in the code precisely describe the meaning of the elements, and nothing more needs to be
added. The only exception ish_blocks: Although this element suggests that multiple blocks can be used
to store extended attribute data, it is at the moment always set to 1. Any other value is treated as an error.

Every entry is represented by the following data structure:

fs/ext3/xattr.h
struct ext3_xattr_entry {
__u8 e_name_len; /* length of name */
__u8 e_name_index; /* attribute name index */
__le16 e_value_offs; /* offset in disk block of value */
__le32 e_value_block; /* disk block attribute is stored on (n/i) */
__le32 e_value_size; /* size of attribute value */
__le32 e_hash; /* hash value of name and value */
char e_name[0]; /* attribute name */
};

Note that the entries are not of a uniform size because the length of the attribute names is variable; this is
why the name is stored at the end of the structure;e_name_lenis available to determine the name length
and thus compute the size of each entry.e_value_block,togetherwithe_value_offset, dertermines the
location of the attribute value associated with the extended attribute name (if the extended attribute is
stored within the inode,ext3_value_offsis used as an offset that starts at the first entry).e_name_index
is used as an index into the tableext3_xattr_handler_mapdefined above.

Implementation


Since the handler implementation is quite similar for different attribute namespaces, the following dis-
cussion is restricted to the implementation for theusernamespace; the handler functions for the other
namespaces differ only little or not at all.ext3_xattr_user_handleris defined as follows:

fs/ext3/xattr_user.c
struct xattr_handler ext3_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.list = ext3_xattr_user_list,
.get = ext3_xattr_user_get,
.set = ext3_xattr_user_set,
};

Retrieving Extended Attributes


Considerext3_xattr_user_getfirst. The code is just a wrapper for a standard routine that works inde-
pendently of the attribute type. Only the identification number of the type is necessary to choose the
correct attributes from the set of all attributes:

fs/ext3/xattr_user.c
static int
ext3_xattr_user_get(struct inode *inode, const char *name,
void *buffer, size_t size)
{
...
if (!test_opt(inode->i_sb, XATTR_USER))
return -EOPNOTSUPP;
return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size);
}
Free download pdf