params.c 18 KB

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