Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


The test forXATTR_USERensures that the filesystem supports extended attributes in theusernamespace.
It is possible to enable or disable this support at mount time.


Note that all get-type functions can be used for two purposes. If abufferis allocated, the result is copied
into it, but if aNULLpointer is given instead of a proper buffer, only the required size for the attribute
value is computed and returned. This allows the calling code to first identify the size of the required
allocation for the buffer. After the buffer has been allocated, a second call fills in the data.


Figure 11-5 shows the code flow diagram forext3_xattr_get. The function is a dispatcher that first tries
to find the required attribute directly in the free space of the inode withext3_xattr_ibody_get;ifthis
fails,ext3_xattr_block_getis used to read the value from an external attribute data block.


No xattrs directly stored in inode?

ext3_xattr_get

ext3_xattr_ibody_get

ext3_xattr_block_get

Figure 11-5: Code flow diagram forext3_xattr_get.

Consider the direct search in the free inode space first. The associated code flow diagram is depicted in
Figure 11-6.


Locate inode

Copy value to buffer if buffer!= NULL

ext3_xattr_ibody_get

ext3_xattr_check_names

ext3_xattr_find_entry

Figure 11-6: Code flow diagram for
ext3_xattr_ibody_get.

After the location of the inode is determined and access to the raw data is ascertained,
ext3_xattr_check_namesperforms several sanity checks that ensure that the entry table is
located within the free space of the inode. The real work is delegated toext3_xattr_find_entry.Since
the routine will be used on several more occasions further below, we need to discuss it in more detail.


fs/ext3/xattr.c
static int
ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
const char *name, size_t size, int sorted)
{
struct ext3_xattr_entry *entry;
size_t name_len;
int cmp = 1;
Free download pdf