Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


&proc_##OTYPE##_inode_operations, &proc_##OTYPE##_operations, \
{} )
#define LNK(NAME, OTYPE) \
NOD(NAME, (S_IFLNK|S_IRWXUGO), \
&proc_pid_link_inode_operations, NULL, \
{ .proc_get_link = &proc_##OTYPE##_link } )
#define REG(NAME, MODE, OTYPE) \
NOD(NAME, (S_IFREG|(MODE)), NULL, \
&proc_##OTYPE##_operations, {})
#define INF(NAME, MODE, OTYPE) \
NOD(NAME, (S_IFREG|(MODE)), \
NULL, &proc_info_file_operations, \
{ .proc_read = &proc_##OTYPE } )

As the names indicate, the macros generate directories, links, and regular files.INFalso generates regular
files, but in contrast toREGfiles, they do not need to provide specialized inode operations, but need only
fill inproc_readfrompid_entry->op.Observehow

REG("environ", S_IRUSR, environ)
/*********************************/
INF("auxv", S_IRUSR, pid_auxv)

is expanded to see how both types differ:

{ .name = ("environ"),
.len = sizeof("environ") - 1,
.mode = (S_IFREG|(S_IRUSR)),
.iop = NULL,
.fop = &proc_environ_operations,
.op = {},
}
/*********************************/
{ .name = ("auxv"),
.len = sizeof("auxv") - 1,
.mode = (S_IFREG|(S_IRUSR)),
.iop = NULL,
.fop = &proc_info_file_operations,
.op = { .proc_read = &proc_pid_auxv },
}

The macros are used to construct the TGID-specific directory entries intgid_base_stuff:

fs/proc/base.c
static const struct pid_entry tgid_base_stuff[] = {
DIR("task", S_IRUGO|S_IXUGO, task),
DIR("fd", S_IRUSR|S_IXUSR, fd),
DIR("fdinfo", S_IRUSR|S_IXUSR, fdinfo),
REG("environ", S_IRUSR, environ),
INF("auxv", S_IRUSR, pid_auxv),
INF("status", S_IRUGO, pid_status),
INF("limits", S_IRUSR, pid_limits),
...
INF("oom_score", S_IRUGO, oom_score),
REG("oom_adj", S_IRUGO|S_IWUSR, oom_adjust),
Free download pdf