Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


Sending Data


Since the structure of an extended attribute is very simple, the kernel does not provide a specific data
structure to encapsulate the name/value pairs; instead, a simple string is used to represent the name,
while avoid-pointer denotes the area in memory where the value resides.

Nevertheless, there need to be methods that set, retrieve, remove, and list the extended attributes. Since
these operations are inode-specific, they are integrated intostruct inode_operations:

<fs.h>
struct inode_operations {
...
int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
ssize_t (*listxattr) (struct dentry *, char *, size_t);
int (*removexattr) (struct dentry *, const char*);
...
}

Naturally, a filesystem can provide custom implementations for these operations, but the kernel also
offers a set of generic handler functions. They are, for instance, used by the third extended filesystem, as
discussed below in the chapter. Before the implementation is presented, I need to introduce the funda-
mental data structures. For every class of extended attributes, functions that transfer the information to
and from the block device are required. They are encapsulated in the following structure:

<xattr.h>
struct xattr_handler {
char *prefix;
size_t (*list)(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len);
int (*get)(struct inode *inode, const char *name, void *buffer,
size_t size);
int (*set)(struct inode *inode, const char *name, const void *buffer,
size_t size, int flags);
};

prefixdenotes the namespace to whose attributes the operations apply: it can be any of the values intro-
duced byXATTR_*_PREFIXas discussed above in the chapter. Thegetandsetmethods read and write
extended attributes to the underlying block device, whilelistprovides a list of all extended attributes
associated with a file.

The superblock provides a link to an array of all supported handlers for the respective filesystem:

<fs.h>
struct super_block {
...
struct xattr_handler **s_xattr;
...
}

There is no fixed order in which the handlers need to appear in the array. The kernel can find the proper
one by comparing the handler’sprefixelement with the namespace prefix of the extended attribute
name in question. Figure 11-1 presents a graphical summary.
Free download pdf