Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


size_t size = handler->list(inode, buffer, rest,
entry->e_name,
entry->e_name_len);
if (buffer) {
if (size > rest)
return -ERANGE;
buffer += size;
}
rest -= size;
}
}
return buffer_size - rest;
}

Since the list handler implementation is quite similar for the various attribute types, it suffices to consider
the variant for theusernamespace. Observe the following code:

fs/ext3/xattr_user.c
static size_t
ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len)
{
const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;

if (!test_opt(inode->i_sb, XATTR_USER))
return 0;

if (list && total_len <= list_size) {
memcpy(list, XATTR_USER_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = ’\0’;
}
return total_len;
}

The routine copies the prefix ‘‘user.’’ followed by the attribute name and a null byte into the bufferlist
and returns the number of copied bytes as result.

11.1.3 Implementation in Ext2


The implementation of extended attributes in Ext2 is quite similar to the implementation in Ext3 pre-
sented above. This is not surprising since Ext3 is a direct descendent of Ext2, but nevertheless, some
features present in Ext3 that are not available in Ext2 are the source of some differences in the xattr
implementation:

❑ Since Ext2 does not support dynamic inode sizes, there is not sufficient space left in the on-disk
inode to store the data of extended attributes. Thus, xattrs are always stored on a separate data
block. This simplifies some functions because no distinction between different locations of the
extended attribute data is necessary.
❑ Ext2 does not use journaling, so all journaling-related function calls are not necessary. This also
eliminates the need for some wrapper functions that are just dealing with handle operations.
Free download pdf