Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


wolfgang@meitner>ls -l /proc/sys
total 0
dr-xr-xr-x 2 root root 0 2006-08-11 00:09 debug
dr-xr-xr-x 8 root root 0 2006-08-11 00:09 dev
dr-xr-xr-x 7 root root 0 2006-08-11 00:09 fs
dr-xr-xr-x 4 root root 0 2006-08-11 00:09 kernel
dr-xr-xr-x 8 root root 0 2006-08-11 00:09 net
dr-xr-xr-x 2 root root 0 2006-08-11 00:09 proc
dr-xr-xr-x 2 root root 0 2006-08-11 00:09 sunrpc
dr-xr-xr-x 2 root root 0 2006-08-11 00:09 vm

If the entry is not to be exported to theprocfilesystem (and is therefore only accessible using
thesysctlsystem call),procnamecan also be assigned a null pointer, although this is extremely
unusual.

❑ datamay be assigned any value — usually a function pointer or a string — that is processed by
sysctl-specific functions. The generic code leaves this element untouched.


❑ maxlenspecifies the maximum length (in bytes) of data accepted or output by a sysctl.


❑ modecontrols the access rights to the data and determines whether and by whom data may be
read or written. Rights are assigned using the virtual filesystem constants with which you are
familiar from Chapter 8.


❑ childis a pointer to an array of additionalctl_tableelements regarded as children of the cur-
rent element. For example, in theCTL_KERNsysctl entry,childpoints to a table containing entries
such asKERN_OSTYPE(operating system type),KERN_OSRELEASE(kernel version number), and
KERN_HOSTNAME(name of the host on which the kernel is running) because these are hierarchi-
cally subordinate to theCTL_KERNsysctl.
Because the length of thectl_tablearrays is not stored explicitly anywhere, the last entry must
always be an instance ofctl_tablewhose entries consist of null pointers.


❑ proc_readsysis invoked when data are output via theprocinterface. The kernel can output the
data stored in the kernel directly, but also has the option of translating it into a more readable
form (e.g., converting numeric constants into more meaningful strings).


❑ strategyis used by the kernel to read or write the value of a sysctl via the system call
interface discussed above (note thatprocuses different functions of its own for this purpose).
ctl_handleris atypedeffor a function pointer defined as follows:



typedef int ctl_handler (ctl_table *table, int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen);
In addition to the complete set of arguments used when thesysctlsystem call is invoked, the
function also expects a pointer to thectl_tableinstance where the current sysctl is located.
It also needs a context-dependentvoid*pointer that is currently unused and to which a null
pointer is therefore always assigned.

❑ The interface to theprocdata is set up byde.


❑ extra1andextra2can be filled withproc-specific data that are not manipulated by the generic
sysctl code. They are often used to define upper and lower limits for numeric arguments.

Free download pdf