Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


starting point for the whole sysfs tree. The routine can not only be used to obtain the root inode, but is
a generic function that works for any sysfs entry. This routine first checks if the inode is already present
in the inode hash. Because the filesystem has not been mounted before, this check will fail in our case,
sosysfs_init_inodeis used to construct a new inode instance from scratch. I will come back to this
function in a moment.

The final steps are again performed insysfs_fill_super. After allocating a root dentry with
d_alloc_root, the connection between the sysfs data and the filesystem entry is established:

sysfs/mount.c
static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
{
struct inode *inode;
struct dentry *root;
...
root->d_fsdata = &sysfs_root;
sb->s_root = root;
...
}

Recall thatdentry->d_fsdatais a function pointer reserved for filesystem internal use, so sysfs is allowed
to create a connection betweensysfs_direntsanddentryinstances this way.sysfs_rootis a static
instance ofstuct sysfs_direntthat represents the root entry of sysfs.Itisdefinedasfollows:

sysfs/mount.c
struct sysfs_dirent sysfs_root = {
.s_name = "",
.s_count = ATOMIC_INIT(1),
.s_flags = SYSFS_DIR,
.s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
.s_ino = 1,
};

Note thatd_fsdataalways points to the associated instance ofstruct sysfs_dirent; the scheme is not
only used for the root entry, but also for all other entries of sysfs. This connection allows the kernel to
derive the sysfs-specific data from the generic VFS data structures.

I will now consider inode initialization insysfs_init_inodein more detail as promised above. The code
flow diagram for the function is depicted in Figure 10-11.

sysfs_init_inode

Set inode, file, and address space operations

Yes

No

Non-standard attributes specified? sysfs_inode_attr

set_default_inode_attr

Figure 10-11: Code flow diagram forsysfs_new_inode.

sysfs_init_inodesets the inode operations such that onlysetattris implemented by a filesystem-
specific function, namely,sysfs_setattr. Following this, the kernel takes care of assigning the inode
Free download pdf