insmod.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini insmod implementation for busybox
  4. *
  5. * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. //config:config INSMOD
  10. //config: bool "insmod (22 kb)"
  11. //config: default y
  12. //config: select PLATFORM_LINUX
  13. //config: help
  14. //config: insmod is used to load specified modules in the running kernel.
  15. //applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET_NOEXEC(insmod, insmod, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
  16. //kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
  17. //kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o
  18. //kbuild:endif
  19. #include "libbb.h"
  20. #include "modutils.h"
  21. /* 2.6 style insmod has no options and required filename
  22. * (not module name - .ko can't be omitted) */
  23. //usage:#if !ENABLE_MODPROBE_SMALL
  24. //usage:#define insmod_trivial_usage
  25. //usage: IF_FEATURE_2_4_MODULES("[OPTIONS] MODULE")
  26. //usage: IF_NOT_FEATURE_2_4_MODULES("FILE")
  27. //usage: IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...")
  28. //usage:#define insmod_full_usage "\n\n"
  29. //usage: "Load kernel module"
  30. //usage: IF_FEATURE_2_4_MODULES( "\n"
  31. //usage: "\n -f Force module to load into the wrong kernel version"
  32. //usage: "\n -k Make module autoclean-able"
  33. //usage: "\n -v Verbose"
  34. //usage: "\n -q Quiet"
  35. //usage: "\n -L Lock: prevent simultaneous loads"
  36. //usage: IF_FEATURE_INSMOD_LOAD_MAP(
  37. //usage: "\n -m Output load map to stdout"
  38. //usage: )
  39. //usage: "\n -x Don't export externs"
  40. //usage: )
  41. //usage:#endif
  42. int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  43. int insmod_main(int argc UNUSED_PARAM, char **argv)
  44. {
  45. char *filename;
  46. int rc;
  47. /* Compat note:
  48. * 2.6 style insmod has no options and required filename
  49. * (not module name - .ko can't be omitted).
  50. * 2.4 style insmod can take module name without .o
  51. * and performs module search in default directories
  52. * or in $MODPATH.
  53. */
  54. IF_FEATURE_2_4_MODULES(
  55. getopt32(argv, INSMOD_OPTS INSMOD_ARGS);
  56. argv += optind - 1;
  57. );
  58. filename = *++argv;
  59. if (!filename)
  60. bb_show_usage();
  61. rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
  62. if (rc)
  63. bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
  64. return rc;
  65. }