params.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /* Helpers for initial module or kernel cmdline parsing
  2. Copyright (C) 2001 Rusty Russell.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include <linux/moduleparam.h>
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/errno.h>
  19. #include <linux/module.h>
  20. #include <linux/device.h>
  21. #include <linux/err.h>
  22. #include <linux/slab.h>
  23. /* We abuse the high bits of "perm" to record whether we kmalloc'ed. */
  24. #define KPARAM_KMALLOCED 0x80000000
  25. #if 0
  26. #define DEBUGP printk
  27. #else
  28. #define DEBUGP(fmt, a...)
  29. #endif
  30. static inline char dash2underscore(char c)
  31. {
  32. if (c == '-')
  33. return '_';
  34. return c;
  35. }
  36. static inline int parameq(const char *input, const char *paramname)
  37. {
  38. unsigned int i;
  39. for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
  40. if (input[i] == '\0')
  41. return 1;
  42. return 0;
  43. }
  44. static int parse_one(char *param,
  45. char *val,
  46. struct kernel_param *params,
  47. unsigned num_params,
  48. int (*handle_unknown)(char *param, char *val))
  49. {
  50. unsigned int i;
  51. /* Find parameter */
  52. for (i = 0; i < num_params; i++) {
  53. if (parameq(param, params[i].name)) {
  54. DEBUGP("They are equal! Calling %p\n",
  55. params[i].set);
  56. return params[i].set(val, &params[i]);
  57. }
  58. }
  59. if (handle_unknown) {
  60. DEBUGP("Unknown argument: calling %p\n", handle_unknown);
  61. return handle_unknown(param, val);
  62. }
  63. DEBUGP("Unknown argument `%s'\n", param);
  64. return -ENOENT;
  65. }
  66. /* You can use " around spaces, but can't escape ". */
  67. /* Hyphens and underscores equivalent in parameter names. */
  68. static char *next_arg(char *args, char **param, char **val)
  69. {
  70. unsigned int i, equals = 0;
  71. int in_quote = 0, quoted = 0;
  72. char *next;
  73. if (*args == '"') {
  74. args++;
  75. in_quote = 1;
  76. quoted = 1;
  77. }
  78. for (i = 0; args[i]; i++) {
  79. if (args[i] == ' ' && !in_quote)
  80. break;
  81. if (equals == 0) {
  82. if (args[i] == '=')
  83. equals = i;
  84. }
  85. if (args[i] == '"')
  86. in_quote = !in_quote;
  87. }
  88. *param = args;
  89. if (!equals)
  90. *val = NULL;
  91. else {
  92. args[equals] = '\0';
  93. *val = args + equals + 1;
  94. /* Don't include quotes in value. */
  95. if (**val == '"') {
  96. (*val)++;
  97. if (args[i-1] == '"')
  98. args[i-1] = '\0';
  99. }
  100. if (quoted && args[i-1] == '"')
  101. args[i-1] = '\0';
  102. }
  103. if (args[i]) {
  104. args[i] = '\0';
  105. next = args + i + 1;
  106. } else
  107. next = args + i;
  108. /* Chew up trailing spaces. */
  109. while (*next == ' ')
  110. next++;
  111. return next;
  112. }
  113. /* Args looks like "foo=bar,bar2 baz=fuz wiz". */
  114. int parse_args(const char *name,
  115. char *args,
  116. struct kernel_param *params,
  117. unsigned num,
  118. int (*unknown)(char *param, char *val))
  119. {
  120. char *param, *val;
  121. DEBUGP("Parsing ARGS: %s\n", args);
  122. /* Chew leading spaces */
  123. while (*args == ' ')
  124. args++;
  125. while (*args) {
  126. int ret;
  127. int irq_was_disabled;
  128. args = next_arg(args, &param, &val);
  129. irq_was_disabled = irqs_disabled();
  130. ret = parse_one(param, val, params, num, unknown);
  131. if (irq_was_disabled && !irqs_disabled()) {
  132. printk(KERN_WARNING "parse_args(): option '%s' enabled "
  133. "irq's!\n", param);
  134. }
  135. switch (ret) {
  136. case -ENOENT:
  137. printk(KERN_ERR "%s: Unknown parameter `%s'\n",
  138. name, param);
  139. return ret;
  140. case -ENOSPC:
  141. printk(KERN_ERR
  142. "%s: `%s' too large for parameter `%s'\n",
  143. name, val ?: "", param);
  144. return ret;
  145. case 0:
  146. break;
  147. default:
  148. printk(KERN_ERR
  149. "%s: `%s' invalid for parameter `%s'\n",
  150. name, val ?: "", param);
  151. return ret;
  152. }
  153. }
  154. /* All parsed OK. */
  155. return 0;
  156. }
  157. /* Lazy bastard, eh? */
  158. #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
  159. int param_set_##name(const char *val, struct kernel_param *kp) \
  160. { \
  161. tmptype l; \
  162. int ret; \
  163. \
  164. if (!val) return -EINVAL; \
  165. ret = strtolfn(val, 0, &l); \
  166. if (ret == -EINVAL || ((type)l != l)) \
  167. return -EINVAL; \
  168. *((type *)kp->arg) = l; \
  169. return 0; \
  170. } \
  171. int param_get_##name(char *buffer, struct kernel_param *kp) \
  172. { \
  173. return sprintf(buffer, format, *((type *)kp->arg)); \
  174. }
  175. STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
  176. STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
  177. STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, strict_strtoul);
  178. STANDARD_PARAM_DEF(int, int, "%i", long, strict_strtol);
  179. STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
  180. STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
  181. STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
  182. int param_set_charp(const char *val, struct kernel_param *kp)
  183. {
  184. if (!val) {
  185. printk(KERN_ERR "%s: string parameter expected\n",
  186. kp->name);
  187. return -EINVAL;
  188. }
  189. if (strlen(val) > 1024) {
  190. printk(KERN_ERR "%s: string parameter too long\n",
  191. kp->name);
  192. return -ENOSPC;
  193. }
  194. if (kp->perm & KPARAM_KMALLOCED)
  195. kfree(*(char **)kp->arg);
  196. /* This is a hack. We can't need to strdup in early boot, and we
  197. * don't need to; this mangled commandline is preserved. */
  198. if (slab_is_available()) {
  199. kp->perm |= KPARAM_KMALLOCED;
  200. *(char **)kp->arg = kstrdup(val, GFP_KERNEL);
  201. if (!kp->arg)
  202. return -ENOMEM;
  203. } else
  204. *(const char **)kp->arg = val;
  205. return 0;
  206. }
  207. int param_get_charp(char *buffer, struct kernel_param *kp)
  208. {
  209. return sprintf(buffer, "%s", *((char **)kp->arg));
  210. }
  211. int param_set_bool(const char *val, struct kernel_param *kp)
  212. {
  213. /* No equals means "set"... */
  214. if (!val) val = "1";
  215. /* One of =[yYnN01] */
  216. switch (val[0]) {
  217. case 'y': case 'Y': case '1':
  218. *(int *)kp->arg = 1;
  219. return 0;
  220. case 'n': case 'N': case '0':
  221. *(int *)kp->arg = 0;
  222. return 0;
  223. }
  224. return -EINVAL;
  225. }
  226. int param_get_bool(char *buffer, struct kernel_param *kp)
  227. {
  228. /* Y and N chosen as being relatively non-coder friendly */
  229. return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'Y' : 'N');
  230. }
  231. int param_set_invbool(const char *val, struct kernel_param *kp)
  232. {
  233. int boolval, ret;
  234. struct kernel_param dummy;
  235. dummy.arg = &boolval;
  236. ret = param_set_bool(val, &dummy);
  237. if (ret == 0)
  238. *(int *)kp->arg = !boolval;
  239. return ret;
  240. }
  241. int param_get_invbool(char *buffer, struct kernel_param *kp)
  242. {
  243. return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'N' : 'Y');
  244. }
  245. /* We break the rule and mangle the string. */
  246. static int param_array(const char *name,
  247. const char *val,
  248. unsigned int min, unsigned int max,
  249. void *elem, int elemsize,
  250. int (*set)(const char *, struct kernel_param *kp),
  251. unsigned int *num)
  252. {
  253. int ret;
  254. struct kernel_param kp;
  255. char save;
  256. /* Get the name right for errors. */
  257. kp.name = name;
  258. kp.arg = elem;
  259. /* No equals sign? */
  260. if (!val) {
  261. printk(KERN_ERR "%s: expects arguments\n", name);
  262. return -EINVAL;
  263. }
  264. *num = 0;
  265. /* We expect a comma-separated list of values. */
  266. do {
  267. int len;
  268. if (*num == max) {
  269. printk(KERN_ERR "%s: can only take %i arguments\n",
  270. name, max);
  271. return -EINVAL;
  272. }
  273. len = strcspn(val, ",");
  274. /* nul-terminate and parse */
  275. save = val[len];
  276. ((char *)val)[len] = '\0';
  277. ret = set(val, &kp);
  278. if (ret != 0)
  279. return ret;
  280. kp.arg += elemsize;
  281. val += len+1;
  282. (*num)++;
  283. } while (save == ',');
  284. if (*num < min) {
  285. printk(KERN_ERR "%s: needs at least %i arguments\n",
  286. name, min);
  287. return -EINVAL;
  288. }
  289. return 0;
  290. }
  291. int param_array_set(const char *val, struct kernel_param *kp)
  292. {
  293. const struct kparam_array *arr = kp->arr;
  294. unsigned int temp_num;
  295. return param_array(kp->name, val, 1, arr->max, arr->elem,
  296. arr->elemsize, arr->set, arr->num ?: &temp_num);
  297. }
  298. int param_array_get(char *buffer, struct kernel_param *kp)
  299. {
  300. int i, off, ret;
  301. const struct kparam_array *arr = kp->arr;
  302. struct kernel_param p;
  303. p = *kp;
  304. for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) {
  305. if (i)
  306. buffer[off++] = ',';
  307. p.arg = arr->elem + arr->elemsize * i;
  308. ret = arr->get(buffer + off, &p);
  309. if (ret < 0)
  310. return ret;
  311. off += ret;
  312. }
  313. buffer[off] = '\0';
  314. return off;
  315. }
  316. int param_set_copystring(const char *val, struct kernel_param *kp)
  317. {
  318. const struct kparam_string *kps = kp->str;
  319. if (!val) {
  320. printk(KERN_ERR "%s: missing param set value\n", kp->name);
  321. return -EINVAL;
  322. }
  323. if (strlen(val)+1 > kps->maxlen) {
  324. printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
  325. kp->name, kps->maxlen-1);
  326. return -ENOSPC;
  327. }
  328. strcpy(kps->string, val);
  329. return 0;
  330. }
  331. int param_get_string(char *buffer, struct kernel_param *kp)
  332. {
  333. const struct kparam_string *kps = kp->str;
  334. return strlcpy(buffer, kps->string, kps->maxlen);
  335. }
  336. /* sysfs output in /sys/modules/XYZ/parameters/ */
  337. #define to_module_attr(n) container_of(n, struct module_attribute, attr);
  338. #define to_module_kobject(n) container_of(n, struct module_kobject, kobj);
  339. extern struct kernel_param __start___param[], __stop___param[];
  340. struct param_attribute
  341. {
  342. struct module_attribute mattr;
  343. struct kernel_param *param;
  344. };
  345. struct module_param_attrs
  346. {
  347. unsigned int num;
  348. struct attribute_group grp;
  349. struct param_attribute attrs[0];
  350. };
  351. #ifdef CONFIG_SYSFS
  352. #define to_param_attr(n) container_of(n, struct param_attribute, mattr);
  353. static ssize_t param_attr_show(struct module_attribute *mattr,
  354. struct module *mod, char *buf)
  355. {
  356. int count;
  357. struct param_attribute *attribute = to_param_attr(mattr);
  358. if (!attribute->param->get)
  359. return -EPERM;
  360. count = attribute->param->get(buf, attribute->param);
  361. if (count > 0) {
  362. strcat(buf, "\n");
  363. ++count;
  364. }
  365. return count;
  366. }
  367. /* sysfs always hands a nul-terminated string in buf. We rely on that. */
  368. static ssize_t param_attr_store(struct module_attribute *mattr,
  369. struct module *owner,
  370. const char *buf, size_t len)
  371. {
  372. int err;
  373. struct param_attribute *attribute = to_param_attr(mattr);
  374. if (!attribute->param->set)
  375. return -EPERM;
  376. err = attribute->param->set(buf, attribute->param);
  377. if (!err)
  378. return len;
  379. return err;
  380. }
  381. #endif
  382. #ifdef CONFIG_MODULES
  383. #define __modinit
  384. #else
  385. #define __modinit __init
  386. #endif
  387. #ifdef CONFIG_SYSFS
  388. /*
  389. * add_sysfs_param - add a parameter to sysfs
  390. * @mk: struct module_kobject
  391. * @kparam: the actual parameter definition to add to sysfs
  392. * @name: name of parameter
  393. *
  394. * Create a kobject if for a (per-module) parameter if mp NULL, and
  395. * create file in sysfs. Returns an error on out of memory. Always cleans up
  396. * if there's an error.
  397. */
  398. static __modinit int add_sysfs_param(struct module_kobject *mk,
  399. struct kernel_param *kp,
  400. const char *name)
  401. {
  402. struct module_param_attrs *new;
  403. struct attribute **attrs;
  404. int err, num;
  405. /* We don't bother calling this with invisible parameters. */
  406. BUG_ON(!kp->perm);
  407. if (!mk->mp) {
  408. num = 0;
  409. attrs = NULL;
  410. } else {
  411. num = mk->mp->num;
  412. attrs = mk->mp->grp.attrs;
  413. }
  414. /* Enlarge. */
  415. new = krealloc(mk->mp,
  416. sizeof(*mk->mp) + sizeof(mk->mp->attrs[0]) * (num+1),
  417. GFP_KERNEL);
  418. if (!new) {
  419. kfree(mk->mp);
  420. err = -ENOMEM;
  421. goto fail;
  422. }
  423. attrs = krealloc(attrs, sizeof(new->grp.attrs[0])*(num+2), GFP_KERNEL);
  424. if (!attrs) {
  425. err = -ENOMEM;
  426. goto fail_free_new;
  427. }
  428. /* Sysfs wants everything zeroed. */
  429. memset(new, 0, sizeof(*new));
  430. memset(&new->attrs[num], 0, sizeof(new->attrs[num]));
  431. memset(&attrs[num], 0, sizeof(attrs[num]));
  432. new->grp.name = "parameters";
  433. new->grp.attrs = attrs;
  434. /* Tack new one on the end. */
  435. new->attrs[num].param = kp;
  436. new->attrs[num].mattr.show = param_attr_show;
  437. new->attrs[num].mattr.store = param_attr_store;
  438. new->attrs[num].mattr.attr.name = (char *)name;
  439. new->attrs[num].mattr.attr.mode = kp->perm;
  440. new->num = num+1;
  441. /* Fix up all the pointers, since krealloc can move us */
  442. for (num = 0; num < new->num; num++)
  443. new->grp.attrs[num] = &new->attrs[num].mattr.attr;
  444. new->grp.attrs[num] = NULL;
  445. mk->mp = new;
  446. return 0;
  447. fail_free_new:
  448. kfree(new);
  449. fail:
  450. mk->mp = NULL;
  451. return err;
  452. }
  453. #ifdef CONFIG_MODULES
  454. static void free_module_param_attrs(struct module_kobject *mk)
  455. {
  456. kfree(mk->mp->grp.attrs);
  457. kfree(mk->mp);
  458. mk->mp = NULL;
  459. }
  460. /*
  461. * module_param_sysfs_setup - setup sysfs support for one module
  462. * @mod: module
  463. * @kparam: module parameters (array)
  464. * @num_params: number of module parameters
  465. *
  466. * Adds sysfs entries for module parameters under
  467. * /sys/module/[mod->name]/parameters/
  468. */
  469. int module_param_sysfs_setup(struct module *mod,
  470. struct kernel_param *kparam,
  471. unsigned int num_params)
  472. {
  473. int i, err;
  474. bool params = false;
  475. for (i = 0; i < num_params; i++) {
  476. if (kparam[i].perm == 0)
  477. continue;
  478. err = add_sysfs_param(&mod->mkobj, &kparam[i], kparam[i].name);
  479. if (err)
  480. return err;
  481. params = true;
  482. }
  483. if (!params)
  484. return 0;
  485. /* Create the param group. */
  486. err = sysfs_create_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
  487. if (err)
  488. free_module_param_attrs(&mod->mkobj);
  489. return err;
  490. }
  491. /*
  492. * module_param_sysfs_remove - remove sysfs support for one module
  493. * @mod: module
  494. *
  495. * Remove sysfs entries for module parameters and the corresponding
  496. * kobject.
  497. */
  498. void module_param_sysfs_remove(struct module *mod)
  499. {
  500. if (mod->mkobj.mp) {
  501. sysfs_remove_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
  502. /* We are positive that no one is using any param
  503. * attrs at this point. Deallocate immediately. */
  504. free_module_param_attrs(&mod->mkobj);
  505. }
  506. }
  507. #endif
  508. void destroy_params(const struct kernel_param *params, unsigned num)
  509. {
  510. unsigned int i;
  511. for (i = 0; i < num; i++)
  512. if (params[i].perm & KPARAM_KMALLOCED)
  513. kfree(*(char **)params[i].arg);
  514. }
  515. static void __init kernel_add_sysfs_param(const char *name,
  516. struct kernel_param *kparam,
  517. unsigned int name_skip)
  518. {
  519. struct module_kobject *mk;
  520. struct kobject *kobj;
  521. int err;
  522. kobj = kset_find_obj(module_kset, name);
  523. if (kobj) {
  524. /* We already have one. Remove params so we can add more. */
  525. mk = to_module_kobject(kobj);
  526. /* We need to remove it before adding parameters. */
  527. sysfs_remove_group(&mk->kobj, &mk->mp->grp);
  528. } else {
  529. mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL);
  530. BUG_ON(!mk);
  531. mk->mod = THIS_MODULE;
  532. mk->kobj.kset = module_kset;
  533. err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL,
  534. "%s", name);
  535. if (err) {
  536. kobject_put(&mk->kobj);
  537. printk(KERN_ERR "Module '%s' failed add to sysfs, "
  538. "error number %d\n", name, err);
  539. printk(KERN_ERR "The system will be unstable now.\n");
  540. return;
  541. }
  542. /* So that exit path is even. */
  543. kobject_get(&mk->kobj);
  544. }
  545. /* These should not fail at boot. */
  546. err = add_sysfs_param(mk, kparam, kparam->name + name_skip);
  547. BUG_ON(err);
  548. err = sysfs_create_group(&mk->kobj, &mk->mp->grp);
  549. BUG_ON(err);
  550. kobject_uevent(&mk->kobj, KOBJ_ADD);
  551. kobject_put(&mk->kobj);
  552. }
  553. /*
  554. * param_sysfs_builtin - add contents in /sys/parameters for built-in modules
  555. *
  556. * Add module_parameters to sysfs for "modules" built into the kernel.
  557. *
  558. * The "module" name (KBUILD_MODNAME) is stored before a dot, the
  559. * "parameter" name is stored behind a dot in kernel_param->name. So,
  560. * extract the "module" name for all built-in kernel_param-eters,
  561. * and for all who have the same, call kernel_add_sysfs_param.
  562. */
  563. static void __init param_sysfs_builtin(void)
  564. {
  565. struct kernel_param *kp;
  566. unsigned int name_len;
  567. char modname[MODULE_NAME_LEN];
  568. for (kp = __start___param; kp < __stop___param; kp++) {
  569. char *dot;
  570. if (kp->perm == 0)
  571. continue;
  572. dot = strchr(kp->name, '.');
  573. if (!dot) {
  574. /* This happens for core_param() */
  575. strcpy(modname, "kernel");
  576. name_len = 0;
  577. } else {
  578. name_len = dot - kp->name + 1;
  579. strlcpy(modname, kp->name, name_len);
  580. }
  581. kernel_add_sysfs_param(modname, kp, name_len);
  582. }
  583. }
  584. /* module-related sysfs stuff */
  585. static ssize_t module_attr_show(struct kobject *kobj,
  586. struct attribute *attr,
  587. char *buf)
  588. {
  589. struct module_attribute *attribute;
  590. struct module_kobject *mk;
  591. int ret;
  592. attribute = to_module_attr(attr);
  593. mk = to_module_kobject(kobj);
  594. if (!attribute->show)
  595. return -EIO;
  596. ret = attribute->show(attribute, mk->mod, buf);
  597. return ret;
  598. }
  599. static ssize_t module_attr_store(struct kobject *kobj,
  600. struct attribute *attr,
  601. const char *buf, size_t len)
  602. {
  603. struct module_attribute *attribute;
  604. struct module_kobject *mk;
  605. int ret;
  606. attribute = to_module_attr(attr);
  607. mk = to_module_kobject(kobj);
  608. if (!attribute->store)
  609. return -EIO;
  610. ret = attribute->store(attribute, mk->mod, buf, len);
  611. return ret;
  612. }
  613. static struct sysfs_ops module_sysfs_ops = {
  614. .show = module_attr_show,
  615. .store = module_attr_store,
  616. };
  617. static int uevent_filter(struct kset *kset, struct kobject *kobj)
  618. {
  619. struct kobj_type *ktype = get_ktype(kobj);
  620. if (ktype == &module_ktype)
  621. return 1;
  622. return 0;
  623. }
  624. static struct kset_uevent_ops module_uevent_ops = {
  625. .filter = uevent_filter,
  626. };
  627. struct kset *module_kset;
  628. int module_sysfs_initialized;
  629. struct kobj_type module_ktype = {
  630. .sysfs_ops = &module_sysfs_ops,
  631. };
  632. /*
  633. * param_sysfs_init - wrapper for built-in params support
  634. */
  635. static int __init param_sysfs_init(void)
  636. {
  637. module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
  638. if (!module_kset) {
  639. printk(KERN_WARNING "%s (%d): error creating kset\n",
  640. __FILE__, __LINE__);
  641. return -ENOMEM;
  642. }
  643. module_sysfs_initialized = 1;
  644. param_sysfs_builtin();
  645. return 0;
  646. }
  647. subsys_initcall(param_sysfs_init);
  648. #endif /* CONFIG_SYSFS */
  649. EXPORT_SYMBOL(param_set_byte);
  650. EXPORT_SYMBOL(param_get_byte);
  651. EXPORT_SYMBOL(param_set_short);
  652. EXPORT_SYMBOL(param_get_short);
  653. EXPORT_SYMBOL(param_set_ushort);
  654. EXPORT_SYMBOL(param_get_ushort);
  655. EXPORT_SYMBOL(param_set_int);
  656. EXPORT_SYMBOL(param_get_int);
  657. EXPORT_SYMBOL(param_set_uint);
  658. EXPORT_SYMBOL(param_get_uint);
  659. EXPORT_SYMBOL(param_set_long);
  660. EXPORT_SYMBOL(param_get_long);
  661. EXPORT_SYMBOL(param_set_ulong);
  662. EXPORT_SYMBOL(param_get_ulong);
  663. EXPORT_SYMBOL(param_set_charp);
  664. EXPORT_SYMBOL(param_get_charp);
  665. EXPORT_SYMBOL(param_set_bool);
  666. EXPORT_SYMBOL(param_get_bool);
  667. EXPORT_SYMBOL(param_set_invbool);
  668. EXPORT_SYMBOL(param_get_invbool);
  669. EXPORT_SYMBOL(param_array_set);
  670. EXPORT_SYMBOL(param_array_get);
  671. EXPORT_SYMBOL(param_set_copystring);
  672. EXPORT_SYMBOL(param_get_string);