Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


for_each_xattr_handleris a macro that iterates over all entries inhandlersuntil it encounters aNULL
entry. For every array element, the kernel compares the handler prefix with the namespace part of the
attribute name. If there is a match, the appropriate handler has been found.

The generic implementations for the other extendedattribute operations differ only slightly from the
code forgeneric_setxattr:

❑ generic_getxattrcallshandler->getinstead of thehandler->set.
❑ generic_removexattrcallshandler->setbut specifiesNULLfor the value and a size of 0. This
triggers, per convention, removing the attribute.^1

generic_listxattrcan operate in two modes: If aNULLpointer instead of a buffer was passed to the
function to hold the result, the code iterates over allhandlers registered in the superblock and calls the
listmethod for the inode in question; sincelistreturns the number of bytes required to hold the result,
they can be summed up to provide predictions about how much memory is required in total. If a buffer
for the results was specified,generic_listxattragain iterates over all handlers, but this time uses the
buffer to actually store the results.

11.1.2 Implementation in Ext3


Among the citizens in filesystem land, Ext3 is one of the most prominent members because it makes it
understood that support for extended attributes is available and well developed. Examine the following
source code to learn more about the filesystem side of extended attribute implementations. This also
raises a question that has not been touched on: namely, how extended attributes are permanently stored
on disk.

Data Structures


As an exemplary citizen, Ext3 starts with some good advice on coding efficiency and employs the generic
implementation presented above. A number of handler functions are provided, and the following map
makes it possible to access handler functions by their identification number and not by their string iden-
tifier; this simplifies many operations and allows a more efficient use of disk space because rather than
the prefix string, only a simple number needs to be stored:

fs/ext3/xattr.c
static struct xattr_handler *ext3_xattr_handler_map[] = {
[EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler,
#ifdef CONFIG_EXT3_FS_POSIX_ACL
[EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler,
[EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler,
#endif
[EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler,
#ifdef CONFIG_EXT3_FS_SECURITY
[EXT3_XATTR_INDEX_SECURITY] = &ext3_xattr_security_handler,
#endif
};

(^1) Note that both aNULLvalueanda size of 0 must be specified for it is possible to have empty attributes with size 0 and an empty
value string (which differs from a NULLvalue).

Free download pdf