2 * linux/fs/hfsplus/options.c
5 * Brad Boyer (flar@allandria.com)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
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>
16 #include <linux/mount.h>
17 #include <linux/seq_file.h>
18 #include <linux/slab.h>
19 #include "hfsplus_fs.h"
22 opt_creator
, opt_type
,
23 opt_umask
, opt_uid
, opt_gid
,
24 opt_part
, opt_session
, opt_nls
,
25 opt_nodecompose
, opt_decompose
,
26 opt_barrier
, opt_nobarrier
,
30 static const match_table_t tokens
= {
31 { opt_creator
, "creator=%s" },
32 { opt_type
, "type=%s" },
33 { opt_umask
, "umask=%o" },
34 { opt_uid
, "uid=%u" },
35 { opt_gid
, "gid=%u" },
36 { opt_part
, "part=%u" },
37 { opt_session
, "session=%u" },
38 { opt_nls
, "nls=%s" },
39 { opt_decompose
, "decompose" },
40 { opt_nodecompose
, "nodecompose" },
41 { opt_barrier
, "barrier" },
42 { opt_nobarrier
, "nobarrier" },
43 { opt_force
, "force" },
47 /* Initialize an options object to reasonable defaults */
48 void hfsplus_fill_defaults(struct hfsplus_sb_info
*opts
)
53 opts
->creator
= HFSPLUS_DEF_CR_TYPE
;
54 opts
->type
= HFSPLUS_DEF_CR_TYPE
;
55 opts
->umask
= current_umask();
56 opts
->uid
= current_uid();
57 opts
->gid
= current_gid();
62 /* convert a "four byte character" to a 32 bit int with error checks */
63 static inline int match_fourchar(substring_t
*arg
, u32
*result
)
65 if (arg
->to
- arg
->from
!= 4)
67 memcpy(result
, arg
->from
, 4);
71 int hfsplus_parse_options_remount(char *input
, int *force
)
74 substring_t args
[MAX_OPT_ARGS
];
80 while ((p
= strsep(&input
, ",")) != NULL
) {
84 token
= match_token(p
, tokens
, args
);
97 /* Parse options from mount. Returns 0 on failure */
98 /* input is the options passed to mount() as a string */
99 int hfsplus_parse_options(char *input
, struct hfsplus_sb_info
*sbi
)
102 substring_t args
[MAX_OPT_ARGS
];
108 while ((p
= strsep(&input
, ",")) != NULL
) {
112 token
= match_token(p
, tokens
, args
);
115 if (match_fourchar(&args
[0], &sbi
->creator
)) {
116 printk(KERN_ERR
"hfs: creator requires a 4 character value\n");
121 if (match_fourchar(&args
[0], &sbi
->type
)) {
122 printk(KERN_ERR
"hfs: type requires a 4 character value\n");
127 if (match_octal(&args
[0], &tmp
)) {
128 printk(KERN_ERR
"hfs: umask requires a value\n");
131 sbi
->umask
= (umode_t
)tmp
;
134 if (match_int(&args
[0], &tmp
)) {
135 printk(KERN_ERR
"hfs: uid requires an argument\n");
138 sbi
->uid
= (uid_t
)tmp
;
141 if (match_int(&args
[0], &tmp
)) {
142 printk(KERN_ERR
"hfs: gid requires an argument\n");
145 sbi
->gid
= (gid_t
)tmp
;
148 if (match_int(&args
[0], &sbi
->part
)) {
149 printk(KERN_ERR
"hfs: part requires an argument\n");
154 if (match_int(&args
[0], &sbi
->session
)) {
155 printk(KERN_ERR
"hfs: session requires an argument\n");
161 printk(KERN_ERR
"hfs: unable to change nls mapping\n");
164 p
= match_strdup(&args
[0]);
166 sbi
->nls
= load_nls(p
);
168 printk(KERN_ERR
"hfs: unable to load "
169 "nls mapping \"%s\"\n",
177 clear_bit(HFSPLUS_SB_NODECOMPOSE
, &sbi
->flags
);
179 case opt_nodecompose
:
180 set_bit(HFSPLUS_SB_NODECOMPOSE
, &sbi
->flags
);
183 clear_bit(HFSPLUS_SB_NOBARRIER
, &sbi
->flags
);
186 set_bit(HFSPLUS_SB_NOBARRIER
, &sbi
->flags
);
189 set_bit(HFSPLUS_SB_FORCE
, &sbi
->flags
);
198 /* try utf8 first, as this is the old default behaviour */
199 sbi
->nls
= load_nls("utf8");
201 sbi
->nls
= load_nls_default();
209 int hfsplus_show_options(struct seq_file
*seq
, struct dentry
*root
)
211 struct hfsplus_sb_info
*sbi
= HFSPLUS_SB(root
->d_sb
);
213 if (sbi
->creator
!= HFSPLUS_DEF_CR_TYPE
)
214 seq_printf(seq
, ",creator=%.4s", (char *)&sbi
->creator
);
215 if (sbi
->type
!= HFSPLUS_DEF_CR_TYPE
)
216 seq_printf(seq
, ",type=%.4s", (char *)&sbi
->type
);
217 seq_printf(seq
, ",umask=%o,uid=%u,gid=%u", sbi
->umask
,
220 seq_printf(seq
, ",part=%u", sbi
->part
);
221 if (sbi
->session
>= 0)
222 seq_printf(seq
, ",session=%u", sbi
->session
);
224 seq_printf(seq
, ",nls=%s", sbi
->nls
->charset
);
225 if (test_bit(HFSPLUS_SB_NODECOMPOSE
, &sbi
->flags
))
226 seq_printf(seq
, ",nodecompose");
227 if (test_bit(HFSPLUS_SB_NOBARRIER
, &sbi
->flags
))
228 seq_printf(seq
, ",nobarrier");