params.c 18 KB

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