4 #define DEBUG_SUBSYSTEM S_SM
6 #include <linux/module.h>
7 #include <linux/kmod.h>
8 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/string.h>
12 #include <linux/errno.h>
13 #include "smfs_internal.h"
16 static struct list_head option_list;
18 char *opt_left = NULL;
20 int init_option(char *data)
22 INIT_LIST_HEAD(&option_list);
23 SM_ALLOC(options, strlen(data) + 1);
25 CERROR("Can not allocate memory \n");
28 memcpy(options, data, strlen(data));
33 void cleanup_option(void)
35 struct option *option;
36 while (!list_empty(&option_list)) {
37 option = list_entry(option_list.next, struct option, list);
38 list_del(&option->list);
39 SM_FREE(option->opt, strlen(option->opt) + 1);
40 SM_FREE(option->value, strlen(option->value) + 1);
41 SM_FREE(option, sizeof(struct option));
43 SM_FREE(options, strlen(options) + 1);
45 int get_opt(struct option **option, char **pos)
47 char *name, *value, *left;
48 struct option *tmp_opt;
56 left = strchr(opt_left, '=');
58 if (left == opt_left || !left)
61 SM_ALLOC(tmp_opt, sizeof(struct option));
63 length = left - opt_left + 1;
64 SM_ALLOC(name, length);
66 memset(name, 0, length);
67 while (opt_left != left) *name++ = *opt_left++;
69 opt_left ++; /*after '='*/
71 left = strchr(opt_left, ',');
72 if (left == opt_left) {
73 SM_FREE(tmp_opt->opt, length);
74 SM_FREE(tmp_opt, sizeof(struct option));
79 left = opt_left + strlen(opt_left);
80 length = left - opt_left + 1;
81 SM_ALLOC(value, length);
82 tmp_opt->value = value;
83 memset(value, 0, length);
84 while (opt_left != left) *value++ = *opt_left++;
86 list_add(&tmp_opt->list, &option_list);
88 if (*opt_left == ',') opt_left ++; /*after ','*/