Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 11: Extended Attributes and Access Control Lists


if (name == NULL)
return -EINVAL;
name_len = strlen(name);
entry = *pentry;
for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
cmp = name_index - entry->e_name_index;
if (!cmp)
cmp = name_len - entry->e_name_len;
if (!cmp)
cmp = memcmp(name, entry->e_name, name_len);
if (cmp <= 0 && (sorted || cmp == 0))
break;
}
*pentry = entry;
...
return cmp? -ENODATA : 0;
}

pentrypoints to the start of the extended attribute entry table. The code loops over all entries and com-
pares the desired name with the entry name if the entry has the correct type (as indicated bycmp == 0,
which results from subtracting the namespace index of the entry under consideration from the index of
the queried entry — a slightly unconventional but nevertheless valid way to check this). Since the entries
do not have a uniform size, the kernel usesEXT3_XATTR_NEXTto compute the address of the next entry
in the table by adding the length of the actual attribute name (plus some padding that is handled by
EXT3_XATTR_LEN) to the size of the entry data structure:

fs/ext3/xattr.h
#define EXT3_XATTR_NEXT(entry) \
( (struct ext3_xattr_entry *)( \
(char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )

The end of the list is marked by a zero thatIS_LAST_ENTRYchecks for.

Afterext3_xattr_find_entryreturns with the data of the desired entry,ext3_xattr_ibody_getneeds
to copy the value to the buffer given in the function arguments if it is not aNULLpointer; otherwise, only
the size of the entry is returned.

If the desired extended attribute cannot be found within the inode, the kernel usesext3_xattr_block_
getto search for the entry. The associated code flow diagram is presented in Figure 11-7.

Read the block pointed to by i_file_acl

Copy attribute value to buffer if buffer != NULL

ext3_xattr_block_get

ext3_xattr_cache_insert

ext3_xattr_find_entry

Figure 11-7: Code flow diagram forext3_xattr_block_get.
Free download pdf