sysctl.h 7.1 KB

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