Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


Recall that there is a separate instance ofproc_dir_entryfor each entry in theprocfilesystem. They
are used by the kernel to represent the hierarchical structure of the filesystem by means of the following
elements:

❑ nlinkspecifies the number of subdirectories and symbolic links in a directory. (The number of
files of other types is irrelevant.)
❑ parentis a pointer to the directory containing a file (or subdirectory) represented by the current
proc_dir_entryinstance.
❑ subdirandnextsupport the hierarchical arrangement of files and directories.subdirpoints to
the first entry of a directory (which, in spite of the name of the element, can beeitherafileora
directory), andnextgroups all common entries of a directory in a singly linked list.

procinodes


The kernel provides a data structure calledproc_inodeto support an inode-oriented view of theproc
filesystem entries. This structure is defined as follows:

<proc_fs.h>
union proc_op {
int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
int (*proc_read)(struct task_struct *task, char *page);
};

struct proc_inode {
struct pid *pid;
int fd;
union proc_op op;
struct proc_dir_entry *pde;
struct inode vfs_inode;
};

The purpose of the structure is to link theproc-specific data with the inode data of the VFS layer.pde
contains a pointer to theproc_dir_entryinstance associated with each entry; the meaning of the instance
was discussed in the previous section. At the end of the structure there is an instance ofinode.

This is the actual data,nota pointer to an instance of the structure.

This is exactly the same data used by the VFS layer for inode management. In other words, directly before
each instance of aninodestructure linked with theprocfilesystem, there are additional data in memory
that can be extracted from a given instance ofproc_inodeusing the container mechanism. Because the
kernel frequently needs to access this information, it defines the following auxiliary procedure:

<proc_fs.h>
static inline struct proc_inode *PROC_I(const struct inode *inode)
{
return container_of(inode, struct proc_inode, vfs_inode);
}

This returns the inode-specific data associated with a VFS inode. Figure 10-1 illustrates the situation in
memory.
Free download pdf