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 "hfsplus_fs.h"
19 opt_creator, opt_type,
20 opt_umask, opt_uid, opt_gid,
21 opt_part, opt_session, opt_nls,
22 opt_nodecompose, opt_decompose,
26 static match_table_t tokens = {
27 { opt_creator, "creator=%s" },
28 { opt_type, "type=%s" },
29 { opt_umask, "umask=%o" },
30 { opt_uid, "uid=%u" },
31 { opt_gid, "gid=%u" },
32 { opt_part, "part=%u" },
33 { opt_session, "session=%u" },
34 { opt_nls, "nls=%s" },
35 { opt_decompose, "decompose" },
36 { opt_nodecompose, "nodecompose" },
40 /* Initialize an options object to reasonable defaults */
41 void fill_defaults(struct hfsplus_sb_info *opts)
46 opts->creator = HFSPLUS_DEF_CR_TYPE;
47 opts->type = HFSPLUS_DEF_CR_TYPE;
48 opts->umask = current->fs->umask;
49 opts->uid = current->uid;
50 opts->gid = current->gid;
55 /* convert a "four byte character" to a 32 bit int with error checks */
56 static inline int match_fourchar(substring_t *arg, u32 *result)
58 if (arg->to - arg->from != 4)
60 memcpy(result, arg->from, 4);
64 /* Parse options from mount. Returns 0 on failure */
65 /* input is the options passed to mount() as a string */
66 int parse_options(char *input, struct hfsplus_sb_info *sbi)
69 substring_t args[MAX_OPT_ARGS];
75 while ((p = strsep(&input, ",")) != NULL) {
79 token = match_token(p, tokens, args);
82 if (match_fourchar(&args[0], &sbi->creator)) {
83 printk("HFS+-fs: creator requires a 4 character value\n");
88 if (match_fourchar(&args[0], &sbi->type)) {
89 printk("HFS+-fs: type requires a 4 character value\n");
94 if (match_octal(&args[0], &tmp)) {
95 printk("HFS+-fs: umask requires a value\n");
98 sbi->umask = (umode_t)tmp;
101 if (match_int(&args[0], &tmp)) {
102 printk("HFS+-fs: uid requires an argument\n");
105 sbi->uid = (uid_t)tmp;
108 if (match_int(&args[0], &tmp)) {
109 printk("HFS+-fs: gid requires an argument\n");
112 sbi->gid = (gid_t)tmp;
115 if (match_int(&args[0], &sbi->part)) {
116 printk("HFS+-fs: part requires an argument\n");
121 if (match_int(&args[0], &sbi->session)) {
122 printk("HFS+-fs: session requires an argument\n");
128 printk("HFS+-fs: unable to change nls mapping\n");
131 p = match_strdup(&args[0]);
132 sbi->nls = load_nls(p);
134 printk("HFS+-fs: unable to load nls mapping \"%s\"\n", p);
141 sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE;
143 case opt_nodecompose:
144 sbi->flags |= HFSPLUS_SB_NODECOMPOSE;
153 /* try utf8 first, as this is the old default behaviour */
154 sbi->nls = load_nls("utf8");
156 sbi->nls = load_nls_default();