linux/include/linux/sysctl.h
<<
>>
Prefs
   1/*
   2 * sysctl.h: General linux system control interface
   3 *
   4 * Begun 24 March 1995, Stephen Tweedie
   5 *
   6 ****************************************************************
   7 ****************************************************************
   8 **
   9 **  WARNING:
  10 **  The values in this file are exported to user space via 
  11 **  the sysctl() binary interface.  Do *NOT* change the
  12 **  numbering of any existing values here, and do not change
  13 **  any numbers within any one set of values.  If you have to
  14 **  redefine an existing interface, use a new number for it.
  15 **  The kernel will then return -ENOTDIR to any application using
  16 **  the old binary interface.
  17 **
  18 ****************************************************************
  19 ****************************************************************
  20 */
  21#ifndef _LINUX_SYSCTL_H
  22#define _LINUX_SYSCTL_H
  23
  24#include <linux/list.h>
  25#include <linux/rcupdate.h>
  26#include <linux/wait.h>
  27#include <linux/rbtree.h>
  28#include <uapi/linux/sysctl.h>
  29
  30/* For the /proc/sys support */
  31struct ctl_table;
  32struct nsproxy;
  33struct ctl_table_root;
  34struct ctl_table_header;
  35struct ctl_dir;
  36
  37typedef struct ctl_table ctl_table;
  38
  39typedef int proc_handler (struct ctl_table *ctl, int write,
  40                          void __user *buffer, size_t *lenp, loff_t *ppos);
  41
  42extern int proc_dostring(struct ctl_table *, int,
  43                         void __user *, size_t *, loff_t *);
  44extern int proc_dointvec(struct ctl_table *, int,
  45                         void __user *, size_t *, loff_t *);
  46extern int proc_douintvec(struct ctl_table *, int,
  47                         void __user *, size_t *, loff_t *);
  48extern int proc_dointvec_minmax(struct ctl_table *, int,
  49                                void __user *, size_t *, loff_t *);
  50extern int proc_douintvec_minmax(struct ctl_table *table, int write,
  51                                 void __user *buffer, size_t *lenp,
  52                                 loff_t *ppos);
  53extern int proc_dopipe_max_size(struct ctl_table *table, int write,
  54                                void __user *buffer, size_t *lenp,
  55                                loff_t *ppos);
  56extern int proc_dointvec_jiffies(struct ctl_table *, int,
  57                                 void __user *, size_t *, loff_t *);
  58extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
  59                                        void __user *, size_t *, loff_t *);
  60extern int proc_dointvec_ms_jiffies(struct ctl_table *, int,
  61                                    void __user *, size_t *, loff_t *);
  62extern int proc_doulongvec_minmax(struct ctl_table *, int,
  63                                  void __user *, size_t *, loff_t *);
  64extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
  65                                      void __user *, size_t *, loff_t *);
  66extern int proc_do_large_bitmap(struct ctl_table *, int,
  67                                void __user *, size_t *, loff_t *);
  68
  69/*
  70 * Register a set of sysctl names by calling register_sysctl_table
  71 * with an initialised array of struct ctl_table's.  An entry with 
  72 * NULL procname terminates the table.  table->de will be
  73 * set up by the registration and need not be initialised in advance.
  74 *
  75 * sysctl names can be mirrored automatically under /proc/sys.  The
  76 * procname supplied controls /proc naming.
  77 *
  78 * The table's mode will be honoured both for sys_sysctl(2) and
  79 * proc-fs access.
  80 *
  81 * Leaf nodes in the sysctl tree will be represented by a single file
  82 * under /proc; non-leaf nodes will be represented by directories.  A
  83 * null procname disables /proc mirroring at this node.
  84 *
  85 * sysctl(2) can automatically manage read and write requests through
  86 * the sysctl table.  The data and maxlen fields of the ctl_table
  87 * struct enable minimal validation of the values being written to be
  88 * performed, and the mode field allows minimal authentication.
  89 * 
  90 * There must be a proc_handler routine for any terminal nodes
  91 * mirrored under /proc/sys (non-terminals are handled by a built-in
  92 * directory handler).  Several default handlers are available to
  93 * cover common cases.
  94 */
  95
  96/* Support for userspace poll() to watch for changes */
  97struct ctl_table_poll {
  98        atomic_t event;
  99        wait_queue_head_t wait;
 100};
 101
 102static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
 103{
 104        return (void *)(unsigned long)atomic_read(&poll->event);
 105}
 106
 107#define __CTL_TABLE_POLL_INITIALIZER(name) {                            \
 108        .event = ATOMIC_INIT(0),                                        \
 109        .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
 110
 111#define DEFINE_CTL_TABLE_POLL(name)                                     \
 112        struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
 113
 114/* A sysctl table is an array of struct ctl_table: */
 115struct ctl_table 
 116{
 117        const char *procname;           /* Text ID for /proc/sys, or zero */
 118        void *data;
 119        int maxlen;
 120        umode_t mode;
 121        struct ctl_table *child;        /* Deprecated */
 122        proc_handler *proc_handler;     /* Callback for text formatting */
 123        struct ctl_table_poll *poll;
 124        void *extra1;
 125        void *extra2;
 126};
 127
 128struct ctl_node {
 129        struct rb_node node;
 130        struct ctl_table_header *header;
 131};
 132
 133/* struct ctl_table_header is used to maintain dynamic lists of
 134   struct ctl_table trees. */
 135struct ctl_table_header
 136{
 137        union {
 138                struct {
 139                        struct ctl_table *ctl_table;
 140                        int used;
 141                        int count;
 142                        int nreg;
 143                };
 144                struct rcu_head rcu;
 145        };
 146        struct completion *unregistering;
 147        struct ctl_table *ctl_table_arg;
 148        struct ctl_table_root *root;
 149        struct ctl_table_set *set;
 150        struct ctl_dir *parent;
 151        struct ctl_node *node;
 152        RH_KABI_EXTEND(struct hlist_head inodes) /* head for proc_inode->sysctl_inodes */
 153};
 154
 155struct ctl_dir {
 156        /* Header must be at the start of ctl_dir */
 157        struct ctl_table_header header;
 158        struct rb_root root;
 159};
 160
 161struct ctl_table_set {
 162        int (*is_seen)(struct ctl_table_set *);
 163        struct ctl_dir dir;
 164};
 165
 166struct ctl_table_root {
 167        struct ctl_table_set default_set;
 168        struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
 169                                           struct nsproxy *namespaces);
 170        int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
 171};
 172
 173/* struct ctl_path describes where in the hierarchy a table is added */
 174struct ctl_path {
 175        const char *procname;
 176};
 177
 178#ifdef CONFIG_SYSCTL
 179
 180void proc_sys_poll_notify(struct ctl_table_poll *poll);
 181
 182extern void setup_sysctl_set(struct ctl_table_set *p,
 183        struct ctl_table_root *root,
 184        int (*is_seen)(struct ctl_table_set *));
 185extern void retire_sysctl_set(struct ctl_table_set *set);
 186
 187void register_sysctl_root(struct ctl_table_root *root);
 188struct ctl_table_header *__register_sysctl_table(
 189        struct ctl_table_set *set,
 190        const char *path, struct ctl_table *table);
 191struct ctl_table_header *__register_sysctl_paths(
 192        struct ctl_table_set *set,
 193        const struct ctl_path *path, struct ctl_table *table);
 194struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
 195struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
 196struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
 197                                                struct ctl_table *table);
 198
 199void unregister_sysctl_table(struct ctl_table_header * table);
 200
 201extern int sysctl_init(void);
 202
 203extern struct ctl_table sysctl_mount_point[];
 204
 205#else /* CONFIG_SYSCTL */
 206static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
 207{
 208        return NULL;
 209}
 210
 211static inline struct ctl_table_header *register_sysctl_paths(
 212                        const struct ctl_path *path, struct ctl_table *table)
 213{
 214        return NULL;
 215}
 216
 217static inline void unregister_sysctl_table(struct ctl_table_header * table)
 218{
 219}
 220
 221static inline void setup_sysctl_set(struct ctl_table_set *p,
 222        struct ctl_table_root *root,
 223        int (*is_seen)(struct ctl_table_set *))
 224{
 225}
 226
 227#endif /* CONFIG_SYSCTL */
 228
 229#endif /* _LINUX_SYSCTL_H */
 230