sysctl.h 6.9 KB

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