Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


The following calling convention is used:

❑ If the data buffer passed to the function isNULL, then remove an existing extended attribute.
❑ If the data buffer contains a value, replace an existing extended attribute or create a new one. The
flagsXATTR_REPLACEandXATTR_CREATEcan be used to indicate that the attribute must or must
not exist before the call as per the documentation in the man pagesetxattr(2).

ext3_xattr_set_handleimplements these requirements by utilizing the previously introduced frame-
work as follows:


  1. Find the location of the inode.

  2. Useext3_xattr_ibody_findto find the data of the extended attribute. If this fails, search in
    the external data block withext3_xattr_block_find.

  3. If no value is given, delete the attribute withext3_xattr_ibody_setorext3_xattrblock
    setdepending on whether the entry is contained in the inode or in a separate data block.

  4. If a value was given, useext3xattr*_setto modify the value or create a new value either
    within the inode or on the external data block depending on where enough space is left.


The functionsext3_xattr_ibody_setandext3_xattr_block_sethandle the low-level work of remov-
ing an entry from the data structure described in Section 11.1.2. If no value is given to update, the
functions respectively create a new entry. This is primarily a matter of data structure manipulation and
will not be discussed in detail here.

Listing Extended Attributes


Although the kernel includes a generic function (generic_listxattr) for listing all extended attributes
associated with a file, it is not among the filesystemfavorites: Only the shared memory implementation
makes use of it. So let’s step back a little farther to discuss the operation for Ext3.

Theinode_operationsinstance for Ext3 listsext3_listxattras the handler function for
listxattr. The method is just a one-line wrapper forext3_xattr_list. This routine calls, in turn,
ext3_xattr_ibody_listandext3_xattr_block_list, depending on where extended attributes are
stored. Both functions compute the location of the extended attributes and read the data, but then
delegate the work toext3_xattr_list_entries, which finally does the real work — after all, someone
has to do it! It uses the previously introduced macros to iterate over all extended attributes defined
for the inode, callshandler->listto retrieve the name of the attribute for each entry, and collects the
results in a buffer:

fs/ext3/xattr.c
static int
ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry,
char *buffer, size_t buffer_size)
{
size_t rest = buffer_size;

for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
struct xattr_handler *handler =
ext3_xattr_handler(entry->e_name_index);

if (handler) {
Free download pdf