Implementation

Since the handler implementation is quite similar for different attribute namespaces, the following discussion is restricted to the implementation for the user namespace; the handler functions for the other namespaces differ only little or not at all. ext3_xattr_user_handler is defined as follows:

fs/ext3/xattr_user.c struct xattr_handler ext3_xattr_user_handler = { .prefix = XATTR_USER_PREFIX, .list = ext3_xattr_user_list, .get = ext3_xattr_user_get, .set = ext3_xattr_user_set,

Retrieving Extended Attributes

Consider ext3_xattr_user_get first. The code is just a wrapper for a standard routine that works independently of the attribute type. Only the identification number of the type is necessary to choose the correct attributes from the set of all attributes:

fs/ext3/xattr_user.c static int ext3_xattr_user_get(struct inode *inode, const char *name, void *buffer, size_t size)

return -EOPNOTSUPP; return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size);

The test for xattr_user ensures that the filesystem supports extended attributes in the user namespace. 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 a buffer is allocated, the result is copied into it, but if a null pointer 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 for ext3_xattr_get. The function is a dispatcher that first tries to find the required attribute directly in the free space of the inode with ext3_xattr_ibody_get; if this fails, ext3_xattr_block_get is used to read the value from an external attribute data block.

ext3_xattr_get ext3_xattr_ibody_get

No xattrs directly stored in inode?

Continue reading here: Figure 115 Code flow diagram for ext3xattrget

Was this article helpful?

0 0