params.c 18 KB

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