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/jbd.h>
13 #include <linux/ext3_fs.h>
14 #include <linux/snap.h>
15 #include <linux/errno.h>
16 #include "smfs_internal.h"
19 static struct list_head option_list;
21 char *opt_left = NULL;
23 int init_option(char *data)
25 INIT_LIST_HEAD(&option_list);
26 SM_ALLOC(options, strlen(data) + 1);
28 CERROR("Can not allocate memory \n");
31 memcpy(options, data, strlen(data));
36 void cleanup_option(void)
38 struct option *option;
39 while (!list_empty(&option_list)) {
40 option = list_entry(option_list.next, struct option, list);
41 list_del(&option->list);
42 SM_FREE(option->opt, strlen(option->opt) + 1);
43 SM_FREE(option->value, strlen(option->value) + 1);
44 SM_FREE(option, sizeof(struct option));
46 SM_FREE(options, strlen(options) + 1);
48 int get_opt(struct option **option, char **pos)
50 char *name, *value, *left;
51 struct option *tmp_opt;
59 left = strchr(opt_left, '=');
61 if (left == opt_left || !left)
64 SM_ALLOC(tmp_opt, sizeof(struct option));
66 length = left - opt_left + 1;
67 SM_ALLOC(name, length);
69 memset(name, 0, length);
70 while (opt_left != left) *name++ = *opt_left++;
72 opt_left ++; /*after '='*/
74 left = strchr(opt_left, ',');
75 if (left == opt_left) {
76 SM_FREE(tmp_opt->opt, length);
77 SM_FREE(tmp_opt, sizeof(struct option));
82 left = opt_left + strlen(opt_left);
83 length = left - opt_left + 1;
84 SM_ALLOC(value, length);
85 tmp_opt->value = value;
86 memset(value, 0, length);
87 while (opt_left != left) *value++ = *opt_left++;
89 list_add(&tmp_opt->list, &option_list);
91 if (*opt_left == ',') opt_left ++; /*after ','*/