modutils.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Common modutils related functions for busybox
  3. *
  4. * Copyright (C) 2008 by Timo Teras <timo.teras@iki.fi>
  5. *
  6. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  7. */
  8. #ifndef MODUTILS_H
  9. #define MODUTILS_H 1
  10. #include "libbb.h"
  11. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  12. /* linux/include/linux/module.h has 64, but this is also used
  13. * internally for the maximum alias name length, which can be quite long */
  14. #define MODULE_NAME_LEN 256
  15. #define MODULE_HASH_SIZE 256
  16. typedef struct module_entry {
  17. struct module_entry *next;
  18. char *name, *modname;
  19. llist_t *deps;
  20. IF_MODPROBE(
  21. llist_t *realnames;
  22. unsigned flags;
  23. const char *probed_name; /* verbatim as seen on cmdline */
  24. char *options; /* options from config files */
  25. )
  26. IF_DEPMOD(
  27. llist_t *aliases;
  28. llist_t *symbols;
  29. struct module_entry *dnext, *dprev;
  30. )
  31. } module_entry;
  32. typedef struct module_db {
  33. module_entry *buckets[MODULE_HASH_SIZE];
  34. } module_db;
  35. #define moddb_foreach_module(db, module, index) \
  36. for ((index) = 0; (index) < MODULE_HASH_SIZE; (index)++) \
  37. for (module = (db)->buckets[index]; module; module = module->next)
  38. module_entry *moddb_get(module_db *db, const char *s) FAST_FUNC;
  39. module_entry *moddb_get_or_create(module_db *db, const char *s) FAST_FUNC;
  40. void moddb_free(module_db *db) FAST_FUNC;
  41. void replace(char *s, char what, char with) FAST_FUNC;
  42. int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC;
  43. char *filename2modname(const char *filename, char *modname) FAST_FUNC;
  44. #if ENABLE_FEATURE_CMDLINE_MODULE_OPTIONS
  45. char *parse_cmdline_module_options(char **argv, int quote_spaces) FAST_FUNC;
  46. #else
  47. # define parse_cmdline_module_options(argv, quote_spaces) ""
  48. #endif
  49. /* insmod for 2.4 and modprobe's options (insmod 2.6 has no options at all): */
  50. #define INSMOD_OPTS \
  51. "vqs" \
  52. IF_FEATURE_2_4_MODULES("Lfkx" IF_FEATURE_INSMOD_LOAD_MAP("m"))
  53. #define INSMOD_ARGS /* (was meant to support -o NAME) , NULL */
  54. enum {
  55. INSMOD_OPT_VERBOSE = (1 << 0),
  56. INSMOD_OPT_SILENT = (1 << 1),
  57. INSMOD_OPT_SYSLOG = (1 << 2),
  58. //INSMOD_OPT_OUTPUTNAME = (1 << x) - not supported yet
  59. INSMOD_OPT_LOCK = (1 << 3) * ENABLE_FEATURE_2_4_MODULES,
  60. INSMOD_OPT_FORCE = (1 << 4) * ENABLE_FEATURE_2_4_MODULES,
  61. INSMOD_OPT_KERNELD = (1 << 5) * ENABLE_FEATURE_2_4_MODULES,
  62. INSMOD_OPT_NO_EXPORT = (1 << 6) * ENABLE_FEATURE_2_4_MODULES,
  63. INSMOD_OPT_PRINT_MAP = (1 << 7) * ENABLE_FEATURE_INSMOD_LOAD_MAP,
  64. INSMOD_OPT_UNUSED =
  65. (INSMOD_OPT_PRINT_MAP ? INSMOD_OPT_PRINT_MAP
  66. : INSMOD_OPT_NO_EXPORT ? INSMOD_OPT_NO_EXPORT
  67. : INSMOD_OPT_SYSLOG
  68. ) << 1
  69. };
  70. #if ENABLE_FEATURE_INSMOD_TRY_MMAP
  71. void* FAST_FUNC try_to_mmap_module(const char *filename, size_t *image_size_p);
  72. #else
  73. # define try_to_mmap_module(filename, image_size) NULL
  74. #endif
  75. /* Return:
  76. * 0 on success,
  77. * -errno on open/read error,
  78. * errno on init_module() error
  79. */
  80. int FAST_FUNC bb_init_module(const char *module, const char *options);
  81. /* Return:
  82. * 0 on success,
  83. * errno on init_module() error
  84. */
  85. int FAST_FUNC bb_delete_module(const char *module, unsigned int flags);
  86. /* Translates error return to a string */
  87. const char *moderror(int err) FAST_FUNC;
  88. #if ENABLE_FEATURE_2_4_MODULES
  89. int FAST_FUNC bb_init_module_24(const char *module, const char *options);
  90. #endif
  91. POP_SAVED_FUNCTION_VISIBILITY
  92. #endif