Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


entry->write_proc = hypercard_proc_write;
}

Once the entry has been created, it is registered with theprocfilesystem usingproc_registerin
fs/proc/generic.c. The task is divided into three steps:



  1. Auniqueproc-internal number is generated to give the entry its own identity.
    get_inode_numberis used to return an unused number for dynamically generated
    entries.

  2. Thenextandparentelements of theproc_dir_entryinstance must be set appropriately to
    incorporate the new entry into the hierarchy.

  3. Depending on the file type, the pointers must be set appropriately to file and inode
    operations if the corresponding elements ofproc_dir_entry,proc_iopsandproc_fops
    previously contained a null pointer. Otherwise, the value held there is retained.


Which file and inode operations are used forprocfiles? The corresponding pointers are set as
follows:


fs/proc/generic.c
static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
{
if (S_ISDIR(dp->mode)) {
if (dp->proc_iops == NULL) {
dp->proc_fops = &proc_dir_operations;
dp->proc_iops = &proc_dir_inode_operations;
}
dir->nlink++;
} else if (S_ISLNK(dp->mode)) {
if (dp->proc_iops == NULL)
dp->proc_iops = &proc_link_inode_operations;
} else if (S_ISREG(dp->mode)) {
if (dp->proc_fops == NULL)
dp->proc_fops = &proc_file_operations;
if (dp->proc_iops == NULL)
dp->proc_iops = &proc_file_inode_operations;
}
...
}

For regular files, the kernel usesproc_file_operationsandproc_file_inode_operationsto define
the file and inode operation methods:


fs/proc/generic.c
static struct inode_operations proc_file_inode_operations = {
.setattr = proc_notify_change,
};

fs/proc/generic.c
static struct file_operations proc_file_operations = {
.llseek = proc_file_lseek,
.read = proc_file_read,
.write = proc_file_write,
};
Free download pdf