Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


.get_sb = proc_get_sb,
.kill_sb = kill_anon_super,
};

The filesystem-specific superblock data are used to fill avfsmountstructure so that the new filesystem
can be incorporated in the VFS tree.

As the source code extract above shows, the superblock of theprocfilesystem is supplied by
proc_get_sb. The function builds on a further kernel auxiliary routine (get_sb_single) that enlists the
help ofproc_fill_superto fill a new instance ofsuper_block.

proc_fill_superis not very complex and is mainly responsible for filling thesuper_blockelements
with defined values that never change:

fs/proc/inode.c
int proc_fill_super(struct super_block *s, void *data, int silent)
{
struct inode * root_inode;
...
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
s->s_magic = PROC_SUPER_MAGIC;
s->s_op = &proc_sops;
...
root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root);
s->s_root = d_alloc_root(root_inode);
...
return 0;
}

The block size cannot be set and is always 1,024; as a result,s_blocksize_bitsmust always be 10 because
210 equals 1,024.

With the help of the pre-processor, the magic number used to recognize the filesystem is defined as
0x9fa0. (This number is not actually needed in the case ofprocbecause data do not reside on a storage
medium but are generated dynamically.)

More interesting is the assignment of theproc_sopssuperblock operations that group together the func-
tions needed by the kernel to manage the filesystem:

fs/proc/inode.c
static struct super_operations proc_sops = {
.alloc_inode = proc_alloc_inode,
.destroy_inode = proc_destroy_inode,
.read_inode = proc_read_inode,
.drop_inode = generic_delete_inode,
.delete_inode = proc_delete_inode,
.statfs = simple_statfs,
.remount_fs = proc_remount,
};
Free download pdf