kmod.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef __LINUX_KMOD_H__
  2. #define __LINUX_KMOD_H__
  3. /*
  4. * include/linux/kmod.h
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/gfp.h>
  21. #include <linux/stddef.h>
  22. #include <linux/errno.h>
  23. #include <linux/compiler.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/sysctl.h>
  26. #define KMOD_PATH_LEN 256
  27. #ifdef CONFIG_MODULES
  28. extern char modprobe_path[]; /* for sysctl */
  29. /* modprobe exit status on success, -ve on error. Return value
  30. * usually useless though. */
  31. extern __printf(2, 3)
  32. int __request_module(bool wait, const char *name, ...);
  33. #define request_module(mod...) __request_module(true, mod)
  34. #define request_module_nowait(mod...) __request_module(false, mod)
  35. #define try_then_request_module(x, mod...) \
  36. ((x) ?: (__request_module(true, mod), (x)))
  37. #else
  38. static inline int request_module(const char *name, ...) { return -ENOSYS; }
  39. static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; }
  40. #define try_then_request_module(x, mod...) (x)
  41. #endif
  42. struct cred;
  43. struct file;
  44. #define UMH_NO_WAIT 0 /* don't wait at all */
  45. #define UMH_WAIT_EXEC 1 /* wait for the exec, but not the process */
  46. #define UMH_WAIT_PROC 2 /* wait for the process to complete */
  47. #define UMH_KILLABLE 4 /* wait for EXEC/PROC killable */
  48. struct subprocess_info {
  49. struct work_struct work;
  50. struct completion *complete;
  51. char *path;
  52. char **argv;
  53. char **envp;
  54. int wait;
  55. int retval;
  56. int (*init)(struct subprocess_info *info, struct cred *new);
  57. void (*cleanup)(struct subprocess_info *info);
  58. void *data;
  59. };
  60. /* Allocate a subprocess_info structure */
  61. struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
  62. char **envp, gfp_t gfp_mask);
  63. /* Set various pieces of state into the subprocess_info structure */
  64. void call_usermodehelper_setfns(struct subprocess_info *info,
  65. int (*init)(struct subprocess_info *info, struct cred *new),
  66. void (*cleanup)(struct subprocess_info *info),
  67. void *data);
  68. /* Actually execute the sub-process */
  69. int call_usermodehelper_exec(struct subprocess_info *info, int wait);
  70. /* Free the subprocess_info. This is only needed if you're not going
  71. to call call_usermodehelper_exec */
  72. void call_usermodehelper_freeinfo(struct subprocess_info *info);
  73. static inline int
  74. call_usermodehelper_fns(char *path, char **argv, char **envp, int wait,
  75. int (*init)(struct subprocess_info *info, struct cred *new),
  76. void (*cleanup)(struct subprocess_info *), void *data)
  77. {
  78. struct subprocess_info *info;
  79. gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
  80. info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
  81. if (info == NULL)
  82. return -ENOMEM;
  83. call_usermodehelper_setfns(info, init, cleanup, data);
  84. return call_usermodehelper_exec(info, wait);
  85. }
  86. static inline int
  87. call_usermodehelper(char *path, char **argv, char **envp, int wait)
  88. {
  89. return call_usermodehelper_fns(path, argv, envp, wait,
  90. NULL, NULL, NULL);
  91. }
  92. extern struct ctl_table usermodehelper_table[];
  93. enum umh_disable_depth {
  94. UMH_ENABLED = 0,
  95. UMH_FREEZING,
  96. UMH_DISABLED,
  97. };
  98. extern void usermodehelper_init(void);
  99. extern int __usermodehelper_disable(enum umh_disable_depth depth);
  100. extern void __usermodehelper_set_disable_depth(enum umh_disable_depth depth);
  101. static inline int usermodehelper_disable(void)
  102. {
  103. return __usermodehelper_disable(UMH_DISABLED);
  104. }
  105. static inline void usermodehelper_enable(void)
  106. {
  107. __usermodehelper_set_disable_depth(UMH_ENABLED);
  108. }
  109. extern int usermodehelper_read_trylock(void);
  110. extern long usermodehelper_read_lock_wait(long timeout);
  111. extern void usermodehelper_read_unlock(void);
  112. #endif /* __LINUX_KMOD_H__ */