Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/hfsplus/options.c | |
3 | * | |
4 | * Copyright (C) 2001 | |
5 | * Brad Boyer (flar@allandria.com) | |
6 | * (C) 2003 Ardis Technologies <roman@ardistech.com> | |
7 | * | |
8 | * Option parsing | |
9 | */ | |
10 | ||
11 | #include <linux/string.h> | |
12 | #include <linux/kernel.h> | |
13 | #include <linux/sched.h> | |
14 | #include <linux/parser.h> | |
15 | #include <linux/nls.h> | |
717dd80e RZ |
16 | #include <linux/mount.h> |
17 | #include <linux/seq_file.h> | |
5a0e3ad6 | 18 | #include <linux/slab.h> |
1da177e4 LT |
19 | #include "hfsplus_fs.h" |
20 | ||
21 | enum { | |
22 | opt_creator, opt_type, | |
23 | opt_umask, opt_uid, opt_gid, | |
24 | opt_part, opt_session, opt_nls, | |
25 | opt_nodecompose, opt_decompose, | |
b0b623c3 | 26 | opt_force, opt_err |
1da177e4 LT |
27 | }; |
28 | ||
a447c093 | 29 | static const match_table_t tokens = { |
1da177e4 LT |
30 | { opt_creator, "creator=%s" }, |
31 | { opt_type, "type=%s" }, | |
32 | { opt_umask, "umask=%o" }, | |
33 | { opt_uid, "uid=%u" }, | |
34 | { opt_gid, "gid=%u" }, | |
35 | { opt_part, "part=%u" }, | |
36 | { opt_session, "session=%u" }, | |
37 | { opt_nls, "nls=%s" }, | |
38 | { opt_decompose, "decompose" }, | |
39 | { opt_nodecompose, "nodecompose" }, | |
b0b623c3 | 40 | { opt_force, "force" }, |
1da177e4 LT |
41 | { opt_err, NULL } |
42 | }; | |
43 | ||
44 | /* Initialize an options object to reasonable defaults */ | |
717dd80e | 45 | void hfsplus_fill_defaults(struct hfsplus_sb_info *opts) |
1da177e4 LT |
46 | { |
47 | if (!opts) | |
48 | return; | |
49 | ||
50 | opts->creator = HFSPLUS_DEF_CR_TYPE; | |
51 | opts->type = HFSPLUS_DEF_CR_TYPE; | |
ce3b0f8d | 52 | opts->umask = current_umask(); |
4ac8489a DH |
53 | opts->uid = current_uid(); |
54 | opts->gid = current_gid(); | |
1da177e4 LT |
55 | opts->part = -1; |
56 | opts->session = -1; | |
57 | } | |
58 | ||
59 | /* convert a "four byte character" to a 32 bit int with error checks */ | |
60 | static inline int match_fourchar(substring_t *arg, u32 *result) | |
61 | { | |
62 | if (arg->to - arg->from != 4) | |
63 | return -EINVAL; | |
64 | memcpy(result, arg->from, 4); | |
65 | return 0; | |
66 | } | |
67 | ||
6f80dfe5 CH |
68 | int hfsplus_parse_options_remount(char *input, int *force) |
69 | { | |
70 | char *p; | |
71 | substring_t args[MAX_OPT_ARGS]; | |
72 | int token; | |
73 | ||
74 | if (!input) | |
75 | return 0; | |
76 | ||
77 | while ((p = strsep(&input, ",")) != NULL) { | |
78 | if (!*p) | |
79 | continue; | |
80 | ||
81 | token = match_token(p, tokens, args); | |
82 | switch (token) { | |
83 | case opt_force: | |
84 | *force = 1; | |
85 | break; | |
86 | default: | |
87 | break; | |
88 | } | |
89 | } | |
90 | ||
91 | return 1; | |
92 | } | |
93 | ||
1da177e4 LT |
94 | /* Parse options from mount. Returns 0 on failure */ |
95 | /* input is the options passed to mount() as a string */ | |
717dd80e | 96 | int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) |
1da177e4 LT |
97 | { |
98 | char *p; | |
99 | substring_t args[MAX_OPT_ARGS]; | |
100 | int tmp, token; | |
101 | ||
102 | if (!input) | |
103 | goto done; | |
104 | ||
105 | while ((p = strsep(&input, ",")) != NULL) { | |
106 | if (!*p) | |
107 | continue; | |
108 | ||
109 | token = match_token(p, tokens, args); | |
110 | switch (token) { | |
111 | case opt_creator: | |
112 | if (match_fourchar(&args[0], &sbi->creator)) { | |
634725a9 | 113 | printk(KERN_ERR "hfs: creator requires a 4 character value\n"); |
1da177e4 LT |
114 | return 0; |
115 | } | |
116 | break; | |
117 | case opt_type: | |
118 | if (match_fourchar(&args[0], &sbi->type)) { | |
634725a9 | 119 | printk(KERN_ERR "hfs: type requires a 4 character value\n"); |
1da177e4 LT |
120 | return 0; |
121 | } | |
122 | break; | |
123 | case opt_umask: | |
124 | if (match_octal(&args[0], &tmp)) { | |
634725a9 | 125 | printk(KERN_ERR "hfs: umask requires a value\n"); |
1da177e4 LT |
126 | return 0; |
127 | } | |
128 | sbi->umask = (umode_t)tmp; | |
129 | break; | |
130 | case opt_uid: | |
131 | if (match_int(&args[0], &tmp)) { | |
634725a9 | 132 | printk(KERN_ERR "hfs: uid requires an argument\n"); |
1da177e4 LT |
133 | return 0; |
134 | } | |
135 | sbi->uid = (uid_t)tmp; | |
136 | break; | |
137 | case opt_gid: | |
138 | if (match_int(&args[0], &tmp)) { | |
634725a9 | 139 | printk(KERN_ERR "hfs: gid requires an argument\n"); |
1da177e4 LT |
140 | return 0; |
141 | } | |
142 | sbi->gid = (gid_t)tmp; | |
143 | break; | |
144 | case opt_part: | |
145 | if (match_int(&args[0], &sbi->part)) { | |
634725a9 | 146 | printk(KERN_ERR "hfs: part requires an argument\n"); |
1da177e4 LT |
147 | return 0; |
148 | } | |
149 | break; | |
150 | case opt_session: | |
151 | if (match_int(&args[0], &sbi->session)) { | |
634725a9 | 152 | printk(KERN_ERR "hfs: session requires an argument\n"); |
1da177e4 LT |
153 | return 0; |
154 | } | |
155 | break; | |
156 | case opt_nls: | |
157 | if (sbi->nls) { | |
634725a9 | 158 | printk(KERN_ERR "hfs: unable to change nls mapping\n"); |
1da177e4 LT |
159 | return 0; |
160 | } | |
161 | p = match_strdup(&args[0]); | |
cd6fda36 JM |
162 | if (p) |
163 | sbi->nls = load_nls(p); | |
1da177e4 | 164 | if (!sbi->nls) { |
634725a9 | 165 | printk(KERN_ERR "hfs: unable to load nls mapping \"%s\"\n", p); |
1da177e4 LT |
166 | kfree(p); |
167 | return 0; | |
168 | } | |
169 | kfree(p); | |
170 | break; | |
171 | case opt_decompose: | |
84adede3 | 172 | clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); |
1da177e4 LT |
173 | break; |
174 | case opt_nodecompose: | |
84adede3 | 175 | set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); |
1da177e4 | 176 | break; |
b0b623c3 | 177 | case opt_force: |
84adede3 | 178 | set_bit(HFSPLUS_SB_FORCE, &sbi->flags); |
b0b623c3 | 179 | break; |
1da177e4 LT |
180 | default: |
181 | return 0; | |
182 | } | |
183 | } | |
184 | ||
185 | done: | |
186 | if (!sbi->nls) { | |
187 | /* try utf8 first, as this is the old default behaviour */ | |
188 | sbi->nls = load_nls("utf8"); | |
189 | if (!sbi->nls) | |
190 | sbi->nls = load_nls_default(); | |
191 | if (!sbi->nls) | |
192 | return 0; | |
193 | } | |
194 | ||
195 | return 1; | |
196 | } | |
717dd80e RZ |
197 | |
198 | int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) | |
199 | { | |
dd73a01a | 200 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(mnt->mnt_sb); |
717dd80e RZ |
201 | |
202 | if (sbi->creator != HFSPLUS_DEF_CR_TYPE) | |
203 | seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator); | |
204 | if (sbi->type != HFSPLUS_DEF_CR_TYPE) | |
205 | seq_printf(seq, ",type=%.4s", (char *)&sbi->type); | |
206 | seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, sbi->uid, sbi->gid); | |
207 | if (sbi->part >= 0) | |
208 | seq_printf(seq, ",part=%u", sbi->part); | |
209 | if (sbi->session >= 0) | |
210 | seq_printf(seq, ",session=%u", sbi->session); | |
211 | if (sbi->nls) | |
212 | seq_printf(seq, ",nls=%s", sbi->nls->charset); | |
84adede3 | 213 | if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags)) |
717dd80e RZ |
214 | seq_printf(seq, ",nodecompose"); |
215 | return 0; | |
216 | } |