Chapter 10: Filesystems without Persistent Storage
sysfs_write_file
fill_write_file
Something to write? flush_write_buffer
Figure 10-15: Code flow diagram forsysfs_write_file.
Directory Traversal
Thelookupmethod ofsysfs_dir_inode_operationsis the basic building block for directory traversal.
We therefore need to have a closer look atsysfs_lookup. Figure 10-16 provides the code flow diagram.
sysfs_lookup
sysfs_find_dirent
sysfs_get_inode
Update and rehash dentry
Figure 10-16: Code flow diagram
forsysfs_lookup.
Attributes constitute the entries of a directory, and the function tries to find an attribute with a specific
name that belongs to an instance ofstruct sysfs_dirent. By iterating over them and comparing names,
the desired entry can be found. Recall that all attributes associated with akobjectare stored in a linked
list whose head issysfs_dirent.s_dir.children. This data structure is now brought to good use:
fs/sysfs/dir.c
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
const unsigned char *name)
{
struct sysfs_dirent *sd;
for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling)
if (!strcmp(sd->s_name, name))
return sd;
return NULL;
}
sysfs_find_direntis used bysysfs_lookupto find the desiredsysfs_direntinstance for a given
filename. With this in hand, the kernel then needs to establish the connection between sysfs, kernel
subsystem, and the filesystem representation by attaching thesysfs_direntinstance of the attribute
with thedentryinstance of the attribute file.
Dentry and inode are then connected withsysfs_get_inode. The method resorts tosysfs_init_inode;
this function is discussed in Section 10.3.3.
The final steps are not sysfs-specific: The inode information is filled into thedentry.Thisalsorequires
rehashing thedentryon the global dentry hash.