Implementation ofprocfileread

Data are read from a proc file in three steps:

1. A kernel memory page is allocated into which data are generated.

2. A file-specific function is invoked to fill the kernel memory page with data.

3. The data are copied from kernel space to userspace.

Obviously, the second step is the most important because the subsystem data and kernel data structures must be specially prepared. The other two steps are simple routine tasks. Section 10.1.2 noted that the kernel provides two function pointers to get_info and read_proc in the proc_dir_entry structure; these functions are used to read data, and the kernel must select the one that matches.

fs/proc/generic.c proc_file_read(struct file *file, loff_t *ppos)

char _user *buf, size_t nbytes, if (dp->get_info) {

/* Handle old net routines */ n = dp->get_info(page, &start, *ppos, count); if (n < count)

n = dp->read_proc(page, &start, *ppos, count, &eof, dp->data);

page is a pointer to the memory page allocated to hold the data in the first step.

Since a sample implementation of read_proc is included in Section 10.1.5, it need not be repeated here.

Continue reading here: Implementation ofprocfilewrite

Was this article helpful?

0 0