next up previous
Next: basic proc_handlers Up: /proc/sys Sysctl functions list Previous: ctl_table

ctl_table hirarchy

The struct ctl_table_header is used to maintain dynamic lists of ctl_table trees. These trees are then "`translated"' to /proc/sys/ based directory structures.


struct ctl_table_header
{
   ctl_table        *ctl_table;
   struct list_head  ctl_entry;
};

An example of a file using a self-defined proc callback handler:


enum {
   DEV_SIMPLE_INFO=1,
   DEV_SIMPLE_DEBUG=2
};
...
/* files named "info" and "debug" */
ctl_table simple_table[] = {
   {DEV_SIMPLE_INFO, "info", 
      &simple_sysctl_settings.info, 
      INFO_STR_SIZE, 0444, NULL, 
      &simple_sysctl_info},
   {DEV_SIMPLE_DEBUG, "debug", 
      &simple_sysctl_settings.debug, 
      sizeof(int), 0644, NULL, 
      &simple_sysctl_handler},
   {0}};

Setup a simple sub-directory:


ctl_table simple_simple_table[] = {
   {DEV_SIMPLE_INFO, "simple", NULL, 
      0, 0555, simple_table},
   {0}};

To create a directory below /proc/sys/dev in order to put the simple device related files into, a further table needs to be created. Checking in linux/sysctl.h gives:

 
/* CTL_DEV names: */
enum {
   DEV_CDROM   = 1,
   DEV_HWMON   = 2,
   DEV_PARPORT = 3,
   DEV_RAID    = 4,
   DEV_MAC_HID = 5
};

Even if the system might only show one directory (say cdrom) in /proc/sys/dev, the number to use cannot be chosen freely. This is a somewhat irritating problem. In the general proc interface, it's sufficient to chose a unique name for the directories and files; for sysctl interfaces it is up to the programmer to ensure that there are no conflicts with predefined names!


#define DEV_SIMPLE 6
...
ctl_table simple_simple_table[] = {
   {DEV_SIMPLE, "simple", NULL, 
      0, 0555, simple_table},
   {0}};

The simple device directory is now put into /proc/sys/dev as this seems to be the appropriate place for a device related sysctl. CTL_DEV is defined in linux/sysctl.h again.


ctl_table simple_root_table[] = {
   {CTL_DEV, "dev", NULL, 
      0, 0555, simple_simple_table},
   {0}};

If a new file should be created in /proc/sys, then a value that is not yet in use has to be selected. In most cases it should be possible to fit it into the existing structure, which should ensure that /proc/sys does not clutter up. As of kernel 2.4.19 the list is:


enum
{
  CTL_KERN = 1, /* General kernel info and control */
  CTL_VM   = 2, /* VM management */
  CTL_NET  = 3, /* Networking */
  CTL_PROC = 4, /* Process info */
  CTL_FS   = 5, /* file systems */
  CTL_DEBUG= 6, /* Debugging */
  CTL_DEV  = 7, /* Devices */
  CTL_BUS  = 8, /* Busses */
  CTL_ABI  = 9, /* Binary emulation */
  CTL_CPU  =10  /* CPU stuff (speed scaling, etc) */
};


next up previous
Next: basic proc_handlers Up: /proc/sys Sysctl functions list Previous: ctl_table
Der Herr Hofrat
2003-03-26