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. #if 0
  25. #define DEBUGP printk
  26. #else
  27. #define DEBUGP(fmt, a...)
  28. #endif
  29. static inline char dash2underscore(char c)
  30. {
  31. if (c == '-')
  32. return '_';
  33. return c;
  34. }
  35. static inline int parameq(const char *input, const char *paramname)
  36. {
  37. unsigned int i;
  38. for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
  39. if (input[i] == '\0')
  40. return 1;
  41. return 0;
  42. }
  43. static int parse_one(char *param,
  44. char *val,
  45. struct kernel_param *params,
  46. unsigned num_params,
  47. int (*handle_unknown)(char *param, char *val))
  48. {
  49. unsigned int i;
  50. /* Find parameter */
  51. for (i = 0; i < num_params; i++) {
  52. if (parameq(param, params[i].name)) {
  53. DEBUGP("They are equal! Calling %p\n",
  54. params[i].set);
  55. return params[i].set(val, &params[i]);
  56. }
  57. }
  58. if (handle_unknown) {
  59. DEBUGP("Unknown argument: calling %p\n", handle_unknown);
  60. return handle_unknown(param, val);
  61. }
  62. DEBUGP("Unknown argument `%s'\n", param);
  63. return -ENOENT;
  64. }
  65. /* You can use " around spaces, but can't escape ". */
  66. /* Hyphens and underscores equivalent in parameter names. */
  67. static char *next_arg(char *args, char **param, char **val)
  68. {
  69. unsigned int i, equals = 0;
  70. int in_quote = 0, quoted = 0;
  71. char *next;
  72. if (*args == '"') {
  73. args++;
  74. in_quote = 1;
  75. quoted = 1;
  76. }
  77. for (i = 0; args[i]; i++) {
  78. if (isspace(args[i]) && !in_quote)
  79. break;
  80. if (equals == 0) {
  81. if (args[i] == '=')
  82. equals = i;
  83. }
  84. if (args[i] == '"')
  85. in_quote = !in_quote;
  86. }
  87. *param = args;
  88. if (!equals)
  89. *val = NULL;
  90. else {
  91. args[equals] = '\0';
  92. *val = args + equals + 1;
  93. /* Don't include quotes in value. */
  94. if (**val == '"') {
  95. (*val)++;
  96. if (args[i-1] == '"')
  97. args[i-1] = '\0';
  98. }
  99. if (quoted && args[i-1] == '"')
  100. args[i-1] = '\0';
  101. }
  102. if (args[i]) {
  103. args[i] = '\0';
  104. next = args + i + 1;
  105. } else
  106. next = args + i;
  107. /* Chew up trailing spaces. */
  108. return skip_spaces(next);
  109. }
  110. /* Args looks like "foo=bar,bar2 baz=fuz wiz". */
  111. int parse_args(const char *name,
  112. char *args,
  113. struct kernel_param *params,
  114. unsigned num,
  115. int (*unknown)(char *param, char *val))
  116. {
  117. char *param, *val;
  118. DEBUGP("Parsing ARGS: %s\n", args);
  119. /* Chew leading spaces */
  120. args = skip_spaces(args);
  121. while (*args) {
  122. int ret;
  123. int irq_was_disabled;
  124. args = next_arg(args, &param, &val);
  125. irq_was_disabled = irqs_disabled();
  126. ret = parse_one(param, val, params, num, unknown);
  127. if (irq_was_disabled && !irqs_disabled()) {
  128. printk(KERN_WARNING "parse_args(): option '%s' enabled "
  129. "irq's!\n", param);
  130. }
  131. switch (ret) {
  132. case -ENOENT:
  133. printk(KERN_ERR "%s: Unknown parameter `%s'\n",
  134. name, param);
  135. return ret;
  136. case -ENOSPC:
  137. printk(KERN_ERR
  138. "%s: `%s' too large for parameter `%s'\n",
  139. name, val ?: "", param);
  140. return ret;
  141. case 0:
  142. break;
  143. default:
  144. printk(KERN_ERR
  145. "%s: `%s' invalid for parameter `%s'\n",
  146. name, val ?: "", param);
  147. return ret;
  148. }
  149. }
  150. /* All parsed OK. */
  151. return 0;
  152. }
  153. /* Lazy bastard, eh? */
  154. #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
  155. int param_set_##name(const char *val, struct kernel_param *kp) \
  156. { \
  157. tmptype l; \
  158. int ret; \
  159. \
  160. if (!val) return -EINVAL; \
  161. ret = strtolfn(val, 0, &l); \
  162. if (ret == -EINVAL || ((type)l != l)) \
  163. return -EINVAL; \
  164. *((type *)kp->arg) = l; \
  165. return 0; \
  166. } \
  167. int param_get_##name(char *buffer, struct kernel_param *kp) \
  168. { \
  169. return sprintf(buffer, format, *((type *)kp->arg)); \
  170. }
  171. STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
  172. STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
  173. STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, strict_strtoul);
  174. STANDARD_PARAM_DEF(int, int, "%i", long, strict_strtol);
  175. STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
  176. STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
  177. STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
  178. int param_set_charp(const char *val, struct kernel_param *kp)
  179. {
  180. if (!val) {
  181. printk(KERN_ERR "%s: string parameter expected\n",
  182. kp->name);
  183. return -EINVAL;
  184. }
  185. if (strlen(val) > 1024) {
  186. printk(KERN_ERR "%s: string parameter too long\n",
  187. kp->name);
  188. return -ENOSPC;
  189. }
  190. /* This is a hack. We can't need to strdup in early boot, and we
  191. * don't need to; this mangled commandline is preserved. */
  192. if (slab_is_available()) {
  193. *(char **)kp->arg = kstrdup(val, GFP_KERNEL);
  194. if (!*(char **)kp->arg)
  195. return -ENOMEM;
  196. } else
  197. *(const char **)kp->arg = val;
  198. return 0;
  199. }
  200. int param_get_charp(char *buffer, struct kernel_param *kp)
  201. {
  202. return sprintf(buffer, "%s", *((char **)kp->arg));
  203. }
  204. /* Actually could be a bool or an int, for historical reasons. */
  205. int param_set_bool(const char *val, struct kernel_param *kp)
  206. {
  207. bool v;
  208. /* No equals means "set"... */
  209. if (!val) val = "1";
  210. /* One of =[yYnN01] */
  211. switch (val[0]) {
  212. case 'y': case 'Y': case '1':
  213. v = true;
  214. break;
  215. case 'n': case 'N': case '0':
  216. v = false;
  217. break;
  218. default:
  219. return -EINVAL;
  220. }
  221. if (kp->flags & KPARAM_ISBOOL)
  222. *(bool *)kp->arg = v;
  223. else
  224. *(int *)kp->arg = v;
  225. return 0;
  226. }
  227. int param_get_bool(char *buffer, struct kernel_param *kp)
  228. {
  229. bool val;
  230. if (kp->flags & KPARAM_ISBOOL)
  231. val = *(bool *)kp->arg;
  232. else
  233. val = *(int *)kp->arg;
  234. /* Y and N chosen as being relatively non-coder friendly */
  235. return sprintf(buffer, "%c", val ? 'Y' : 'N');
  236. }
  237. /* This one must be bool. */
  238. int param_set_invbool(const char *val, struct kernel_param *kp)
  239. {
  240. int ret;
  241. bool boolval;
  242. struct kernel_param dummy;
  243. dummy.arg = &boolval;
  244. dummy.flags = KPARAM_ISBOOL;
  245. ret = param_set_bool(val, &dummy);
  246. if (ret == 0)
  247. *(bool *)kp->arg = !boolval;
  248. return ret;
  249. }
  250. int param_get_invbool(char *buffer, struct kernel_param *kp)
  251. {
  252. return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y');
  253. }
  254. /* We break the rule and mangle the string. */
  255. static int param_array(const char *name,
  256. const char *val,
  257. unsigned int min, unsigned int max,
  258. void *elem, int elemsize,
  259. int (*set)(const char *, struct kernel_param *kp),
  260. u16 flags,
  261. unsigned int *num)
  262. {
  263. int ret;
  264. struct kernel_param kp;
  265. char save;
  266. /* Get the name right for errors. */
  267. kp.name = name;
  268. kp.arg = elem;
  269. kp.flags = flags;
  270. /* No equals sign? */
  271. if (!val) {
  272. printk(KERN_ERR "%s: expects arguments\n", name);
  273. return -EINVAL;
  274. }
  275. *num = 0;
  276. /* We expect a comma-separated list of values. */
  277. do {
  278. int len;
  279. if (*num == max) {
  280. printk(KERN_ERR "%s: can only take %i arguments\n",
  281. name, max);
  282. return -EINVAL;
  283. }
  284. len = strcspn(val, ",");
  285. /* nul-terminate and parse */
  286. save = val[len];
  287. ((char *)val)[len] = '\0';
  288. ret = set(val, &kp);
  289. if (ret != 0)
  290. return ret;
  291. kp.arg += elemsize;
  292. val += len+1;
  293. (*num)++;
  294. } while (save == ',');
  295. if (*num < min) {
  296. printk(KERN_ERR "%s: needs at least %i arguments\n",
  297. name, min);
  298. return -EINVAL;
  299. }
  300. return 0;
  301. }
  302. int param_array_set(const char *val, struct kernel_param *kp)
  303. {
  304. const struct kparam_array *arr = kp->arr;
  305. unsigned int temp_num;
  306. return param_array(kp->name, val, 1, arr->max, arr->elem,
  307. arr->elemsize, arr->set, kp->flags,
  308. arr->num ?: &temp_num);
  309. }
  310. int param_array_get(char *buffer, struct kernel_param *kp)
  311. {
  312. int i, off, ret;
  313. const struct kparam_array *arr = kp->arr;
  314. struct kernel_param p;
  315. p = *kp;
  316. for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) {
  317. if (i)
  318. buffer[off++] = ',';
  319. p.arg = arr->elem + arr->elemsize * i;
  320. ret = arr->get(buffer + off, &p);
  321. if (ret < 0)
  322. return ret;
  323. off += ret;
  324. }
  325. buffer[off] = '\0';
  326. return off;
  327. }
  328. int param_set_copystring(const char *val, struct kernel_param *kp)
  329. {
  330. const struct kparam_string *kps = kp->str;
  331. if (!val) {
  332. printk(KERN_ERR "%s: missing param set value\n", kp->name);
  333. return -EINVAL;
  334. }
  335. if (strlen(val)+1 > kps->maxlen) {
  336. printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
  337. kp->name, kps->maxlen-1);
  338. return -ENOSPC;
  339. }
  340. strcpy(kps->string, val);
  341. return 0;
  342. }
  343. int param_get_string(char *buffer, struct kernel_param *kp)
  344. {
  345. const struct kparam_string *kps = kp->str;
  346. return strlcpy(buffer, kps->string, kps->maxlen);
  347. }
  348. /* sysfs output in /sys/modules/XYZ/parameters/ */
  349. #define to_module_attr(n) container_of(n, struct module_attribute, attr)
  350. #define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
  351. extern struct kernel_param __start___param[], __stop___param[];
  352. struct param_attribute
  353. {
  354. struct module_attribute mattr;
  355. struct kernel_param *param;
  356. };
  357. struct module_param_attrs
  358. {
  359. unsigned int num;
  360. struct attribute_group grp;
  361. struct param_attribute attrs[0];
  362. };
  363. #ifdef CONFIG_SYSFS
  364. #define to_param_attr(n) container_of(n, struct param_attribute, mattr)
  365. static ssize_t param_attr_show(struct module_attribute *mattr,
  366. struct module *mod, char *buf)
  367. {
  368. int count;
  369. struct param_attribute *attribute = to_param_attr(mattr);
  370. if (!attribute->param->get)
  371. return -EPERM;
  372. count = attribute->param->get(buf, attribute->param);
  373. if (count > 0) {
  374. strcat(buf, "\n");
  375. ++count;
  376. }
  377. return count;
  378. }
  379. /* sysfs always hands a nul-terminated string in buf. We rely on that. */
  380. static ssize_t param_attr_store(struct module_attribute *mattr,
  381. struct module *owner,
  382. const char *buf, size_t len)
  383. {
  384. int err;
  385. struct param_attribute *attribute = to_param_attr(mattr);
  386. if (!attribute->param->set)
  387. return -EPERM;
  388. err = attribute->param->set(buf, attribute->param);
  389. if (!err)
  390. return len;
  391. return err;
  392. }
  393. #endif
  394. #ifdef CONFIG_MODULES
  395. #define __modinit
  396. #else
  397. #define __modinit __init
  398. #endif
  399. #ifdef CONFIG_SYSFS
  400. /*
  401. * add_sysfs_param - add a parameter to sysfs
  402. * @mk: struct module_kobject
  403. * @kparam: the actual parameter definition to add to sysfs
  404. * @name: name of parameter
  405. *
  406. * Create a kobject if for a (per-module) parameter if mp NULL, and
  407. * create file in sysfs. Returns an error on out of memory. Always cleans up
  408. * if there's an error.
  409. */
  410. static __modinit int add_sysfs_param(struct module_kobject *mk,
  411. struct kernel_param *kp,
  412. const char *name)
  413. {
  414. struct module_param_attrs *new;
  415. struct attribute **attrs;
  416. int err, num;
  417. /* We don't bother calling this with invisible parameters. */
  418. BUG_ON(!kp->perm);
  419. if (!mk->mp) {
  420. num = 0;
  421. attrs = NULL;
  422. } else {
  423. num = mk->mp->num;
  424. attrs = mk->mp->grp.attrs;
  425. }
  426. /* Enlarge. */
  427. new = krealloc(mk->mp,
  428. sizeof(*mk->mp) + sizeof(mk->mp->attrs[0]) * (num+1),
  429. GFP_KERNEL);
  430. if (!new) {
  431. kfree(mk->mp);
  432. err = -ENOMEM;
  433. goto fail;
  434. }
  435. attrs = krealloc(attrs, sizeof(new->grp.attrs[0])*(num+2), GFP_KERNEL);
  436. if (!attrs) {
  437. err = -ENOMEM;
  438. goto fail_free_new;
  439. }
  440. /* Sysfs wants everything zeroed. */
  441. memset(new, 0, sizeof(*new));
  442. memset(&new->attrs[num], 0, sizeof(new->attrs[num]));
  443. memset(&attrs[num], 0, sizeof(attrs[num]));
  444. new->grp.name = "parameters";
  445. new->grp.attrs = attrs;
  446. /* Tack new one on the end. */
  447. sysfs_attr_init(&new->attrs[num].mattr.attr);
  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 const 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 const 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);