sysctl.h 6.8 KB

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