sysctl.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #include <linux/list.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/wait.h>
  26. #include <linux/rbtree.h>
  27. #include <uapi/linux/sysctl.h>
  28. /* For the /proc/sys support */
  29. struct ctl_table;
  30. struct nsproxy;
  31. struct ctl_table_root;
  32. struct ctl_table_header;
  33. struct ctl_dir;
  34. typedef struct ctl_table ctl_table;
  35. typedef int proc_handler (struct ctl_table *ctl, int write,
  36. void __user *buffer, size_t *lenp, loff_t *ppos);
  37. extern int proc_dostring(struct ctl_table *, int,
  38. void __user *, size_t *, loff_t *);
  39. extern int proc_dointvec(struct ctl_table *, int,
  40. void __user *, size_t *, loff_t *);
  41. extern int proc_dointvec_minmax(struct ctl_table *, int,
  42. void __user *, size_t *, loff_t *);
  43. extern int proc_dointvec_jiffies(struct ctl_table *, int,
  44. void __user *, size_t *, loff_t *);
  45. extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
  46. void __user *, size_t *, loff_t *);
  47. extern int proc_dointvec_ms_jiffies(struct ctl_table *, int,
  48. void __user *, size_t *, loff_t *);
  49. extern int proc_doulongvec_minmax(struct ctl_table *, int,
  50. void __user *, size_t *, loff_t *);
  51. extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
  52. void __user *, size_t *, loff_t *);
  53. extern int proc_do_large_bitmap(struct ctl_table *, int,
  54. void __user *, size_t *, loff_t *);
  55. /*
  56. * Register a set of sysctl names by calling register_sysctl_table
  57. * with an initialised array of struct ctl_table's. An entry with
  58. * NULL procname terminates the table. table->de will be
  59. * set up by the registration and need not be initialised in advance.
  60. *
  61. * sysctl names can be mirrored automatically under /proc/sys. The
  62. * procname supplied controls /proc naming.
  63. *
  64. * The table's mode will be honoured both for sys_sysctl(2) and
  65. * proc-fs access.
  66. *
  67. * Leaf nodes in the sysctl tree will be represented by a single file
  68. * under /proc; non-leaf nodes will be represented by directories. A
  69. * null procname disables /proc mirroring at this node.
  70. *
  71. * sysctl(2) can automatically manage read and write requests through
  72. * the sysctl table. The data and maxlen fields of the ctl_table
  73. * struct enable minimal validation of the values being written to be
  74. * performed, and the mode field allows minimal authentication.
  75. *
  76. * There must be a proc_handler routine for any terminal nodes
  77. * mirrored under /proc/sys (non-terminals are handled by a built-in
  78. * directory handler). Several default handlers are available to
  79. * cover common cases.
  80. */
  81. /* Support for userspace poll() to watch for changes */
  82. struct ctl_table_poll {
  83. atomic_t event;
  84. wait_queue_head_t wait;
  85. };
  86. static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
  87. {
  88. return (void *)(unsigned long)atomic_read(&poll->event);
  89. }
  90. #define __CTL_TABLE_POLL_INITIALIZER(name) { \
  91. .event = ATOMIC_INIT(0), \
  92. .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
  93. #define DEFINE_CTL_TABLE_POLL(name) \
  94. struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
  95. /* A sysctl table is an array of struct ctl_table: */
  96. struct ctl_table
  97. {
  98. const char *procname; /* Text ID for /proc/sys, or zero */
  99. void *data;
  100. int maxlen;
  101. umode_t mode;
  102. struct ctl_table *child; /* Deprecated */
  103. proc_handler *proc_handler; /* Callback for text formatting */
  104. struct ctl_table_poll *poll;
  105. void *extra1;
  106. void *extra2;
  107. };
  108. struct ctl_node {
  109. struct rb_node node;
  110. struct ctl_table_header *header;
  111. };
  112. /* struct ctl_table_header is used to maintain dynamic lists of
  113. struct ctl_table trees. */
  114. struct ctl_table_header
  115. {
  116. union {
  117. struct {
  118. struct ctl_table *ctl_table;
  119. int used;
  120. int count;
  121. int nreg;
  122. };
  123. struct rcu_head rcu;
  124. };
  125. struct completion *unregistering;
  126. struct ctl_table *ctl_table_arg;
  127. struct ctl_table_root *root;
  128. struct ctl_table_set *set;
  129. struct ctl_dir *parent;
  130. struct ctl_node *node;
  131. };
  132. struct ctl_dir {
  133. /* Header must be at the start of ctl_dir */
  134. struct ctl_table_header header;
  135. struct rb_root root;
  136. };
  137. struct ctl_table_set {
  138. int (*is_seen)(struct ctl_table_set *);
  139. struct ctl_dir dir;
  140. };
  141. struct ctl_table_root {
  142. struct ctl_table_set default_set;
  143. struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
  144. struct nsproxy *namespaces);
  145. int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
  146. };
  147. /* struct ctl_path describes where in the hierarchy a table is added */
  148. struct ctl_path {
  149. const char *procname;
  150. };
  151. #ifdef CONFIG_SYSCTL
  152. void proc_sys_poll_notify(struct ctl_table_poll *poll);
  153. extern void setup_sysctl_set(struct ctl_table_set *p,
  154. struct ctl_table_root *root,
  155. int (*is_seen)(struct ctl_table_set *));
  156. extern void retire_sysctl_set(struct ctl_table_set *set);
  157. void register_sysctl_root(struct ctl_table_root *root);
  158. struct ctl_table_header *__register_sysctl_table(
  159. struct ctl_table_set *set,
  160. const char *path, struct ctl_table *table);
  161. struct ctl_table_header *__register_sysctl_paths(
  162. struct ctl_table_set *set,
  163. const struct ctl_path *path, struct ctl_table *table);
  164. struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
  165. struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
  166. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  167. struct ctl_table *table);
  168. void unregister_sysctl_table(struct ctl_table_header * table);
  169. extern int sysctl_init(void);
  170. #else /* CONFIG_SYSCTL */
  171. static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  172. {
  173. return NULL;
  174. }
  175. static inline struct ctl_table_header *register_sysctl_paths(
  176. const struct ctl_path *path, struct ctl_table *table)
  177. {
  178. return NULL;
  179. }
  180. static inline void unregister_sysctl_table(struct ctl_table_header * table)
  181. {
  182. }
  183. static inline void setup_sysctl_set(struct ctl_table_set *p,
  184. struct ctl_table_root *root,
  185. int (*is_seen)(struct ctl_table_set *))
  186. {
  187. }
  188. #endif /* CONFIG_SYSCTL */
  189. #endif /* _LINUX_SYSCTL_H */