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> 16 #include <linux/mount.h> 17 #include <linux/seq_file.h> 18 #include "hfsplus_fs.h" 19 20 enum { 21 opt_creator, opt_type, 22 opt_umask, opt_uid, opt_gid, 23 opt_part, opt_session, opt_nls, 24 opt_nodecompose, opt_decompose, 25 opt_err 26 }; 27 28 static match_table_t tokens = { 29 { opt_creator, "creator=%s" }, 30 { opt_type, "type=%s" }, 31 { opt_umask, "umask=%o" }, 32 { opt_uid, "uid=%u" }, 33 { opt_gid, "gid=%u" }, 34 { opt_part, "part=%u" }, 35 { opt_session, "session=%u" }, 36 { opt_nls, "nls=%s" }, 37 { opt_decompose, "decompose" }, 38 { opt_nodecompose, "nodecompose" }, 39 { opt_err, NULL } 40 }; 41 42 /* Initialize an options object to reasonable defaults */ 43 void hfsplus_fill_defaults(struct hfsplus_sb_info *opts) 44 { 45 if (!opts) 46 return; 47 48 opts->creator = HFSPLUS_DEF_CR_TYPE; 49 opts->type = HFSPLUS_DEF_CR_TYPE; 50 opts->umask = current->fs->umask; 51 opts->uid = current->uid; 52 opts->gid = current->gid; 53 opts->part = -1; 54 opts->session = -1; 55 } 56 57 /* convert a "four byte character" to a 32 bit int with error checks */ 58 static inline int match_fourchar(substring_t *arg, u32 *result) 59 { 60 if (arg->to - arg->from != 4) 61 return -EINVAL; 62 memcpy(result, arg->from, 4); 63 return 0; 64 } 65 66 /* Parse options from mount. Returns 0 on failure */ 67 /* input is the options passed to mount() as a string */ 68 int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) 69 { 70 char *p; 71 substring_t args[MAX_OPT_ARGS]; 72 int tmp, token; 73 74 if (!input) 75 goto done; 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_creator: 84 if (match_fourchar(&args[0], &sbi->creator)) { 85 printk("HFS+-fs: creator requires a 4 character value\n"); 86 return 0; 87 } 88 break; 89 case opt_type: 90 if (match_fourchar(&args[0], &sbi->type)) { 91 printk("HFS+-fs: type requires a 4 character value\n"); 92 return 0; 93 } 94 break; 95 case opt_umask: 96 if (match_octal(&args[0], &tmp)) { 97 printk("HFS+-fs: umask requires a value\n"); 98 return 0; 99 } 100 sbi->umask = (umode_t)tmp; 101 break; 102 case opt_uid: 103 if (match_int(&args[0], &tmp)) { 104 printk("HFS+-fs: uid requires an argument\n"); 105 return 0; 106 } 107 sbi->uid = (uid_t)tmp; 108 break; 109 case opt_gid: 110 if (match_int(&args[0], &tmp)) { 111 printk("HFS+-fs: gid requires an argument\n"); 112 return 0; 113 } 114 sbi->gid = (gid_t)tmp; 115 break; 116 case opt_part: 117 if (match_int(&args[0], &sbi->part)) { 118 printk("HFS+-fs: part requires an argument\n"); 119 return 0; 120 } 121 break; 122 case opt_session: 123 if (match_int(&args[0], &sbi->session)) { 124 printk("HFS+-fs: session requires an argument\n"); 125 return 0; 126 } 127 break; 128 case opt_nls: 129 if (sbi->nls) { 130 printk("HFS+-fs: unable to change nls mapping\n"); 131 return 0; 132 } 133 p = match_strdup(&args[0]); 134 sbi->nls = load_nls(p); 135 if (!sbi->nls) { 136 printk("HFS+-fs: unable to load nls mapping \"%s\"\n", p); 137 kfree(p); 138 return 0; 139 } 140 kfree(p); 141 break; 142 case opt_decompose: 143 sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE; 144 break; 145 case opt_nodecompose: 146 sbi->flags |= HFSPLUS_SB_NODECOMPOSE; 147 break; 148 default: 149 return 0; 150 } 151 } 152 153 done: 154 if (!sbi->nls) { 155 /* try utf8 first, as this is the old default behaviour */ 156 sbi->nls = load_nls("utf8"); 157 if (!sbi->nls) 158 sbi->nls = load_nls_default(); 159 if (!sbi->nls) 160 return 0; 161 } 162 163 return 1; 164 } 165 166 int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) 167 { 168 struct hfsplus_sb_info *sbi = &HFSPLUS_SB(mnt->mnt_sb); 169 170 if (sbi->creator != HFSPLUS_DEF_CR_TYPE) 171 seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator); 172 if (sbi->type != HFSPLUS_DEF_CR_TYPE) 173 seq_printf(seq, ",type=%.4s", (char *)&sbi->type); 174 seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, sbi->uid, sbi->gid); 175 if (sbi->part >= 0) 176 seq_printf(seq, ",part=%u", sbi->part); 177 if (sbi->session >= 0) 178 seq_printf(seq, ",session=%u", sbi->session); 179 if (sbi->nls) 180 seq_printf(seq, ",nls=%s", sbi->nls->charset); 181 if (sbi->flags & HFSPLUS_SB_NODECOMPOSE) 182 seq_printf(seq, ",nodecompose"); 183 return 0; 184 } 185