0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/string.h>
0013 #include <linux/kernel.h>
0014 #include <linux/sched.h>
0015 #include <linux/parser.h>
0016 #include <linux/nls.h>
0017 #include <linux/mount.h>
0018 #include <linux/seq_file.h>
0019 #include <linux/slab.h>
0020 #include "hfsplus_fs.h"
0021
0022 enum {
0023 opt_creator, opt_type,
0024 opt_umask, opt_uid, opt_gid,
0025 opt_part, opt_session, opt_nls,
0026 opt_nodecompose, opt_decompose,
0027 opt_barrier, opt_nobarrier,
0028 opt_force, opt_err
0029 };
0030
0031 static const match_table_t tokens = {
0032 { opt_creator, "creator=%s" },
0033 { opt_type, "type=%s" },
0034 { opt_umask, "umask=%o" },
0035 { opt_uid, "uid=%u" },
0036 { opt_gid, "gid=%u" },
0037 { opt_part, "part=%u" },
0038 { opt_session, "session=%u" },
0039 { opt_nls, "nls=%s" },
0040 { opt_decompose, "decompose" },
0041 { opt_nodecompose, "nodecompose" },
0042 { opt_barrier, "barrier" },
0043 { opt_nobarrier, "nobarrier" },
0044 { opt_force, "force" },
0045 { opt_err, NULL }
0046 };
0047
0048
0049 void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)
0050 {
0051 if (!opts)
0052 return;
0053
0054 opts->creator = HFSPLUS_DEF_CR_TYPE;
0055 opts->type = HFSPLUS_DEF_CR_TYPE;
0056 opts->umask = current_umask();
0057 opts->uid = current_uid();
0058 opts->gid = current_gid();
0059 opts->part = -1;
0060 opts->session = -1;
0061 }
0062
0063
0064 static inline int match_fourchar(substring_t *arg, u32 *result)
0065 {
0066 if (arg->to - arg->from != 4)
0067 return -EINVAL;
0068 memcpy(result, arg->from, 4);
0069 return 0;
0070 }
0071
0072 int hfsplus_parse_options_remount(char *input, int *force)
0073 {
0074 char *p;
0075 substring_t args[MAX_OPT_ARGS];
0076 int token;
0077
0078 if (!input)
0079 return 1;
0080
0081 while ((p = strsep(&input, ",")) != NULL) {
0082 if (!*p)
0083 continue;
0084
0085 token = match_token(p, tokens, args);
0086 switch (token) {
0087 case opt_force:
0088 *force = 1;
0089 break;
0090 default:
0091 break;
0092 }
0093 }
0094
0095 return 1;
0096 }
0097
0098
0099
0100 int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
0101 {
0102 char *p;
0103 substring_t args[MAX_OPT_ARGS];
0104 int tmp, token;
0105
0106 if (!input)
0107 goto done;
0108
0109 while ((p = strsep(&input, ",")) != NULL) {
0110 if (!*p)
0111 continue;
0112
0113 token = match_token(p, tokens, args);
0114 switch (token) {
0115 case opt_creator:
0116 if (match_fourchar(&args[0], &sbi->creator)) {
0117 pr_err("creator requires a 4 character value\n");
0118 return 0;
0119 }
0120 break;
0121 case opt_type:
0122 if (match_fourchar(&args[0], &sbi->type)) {
0123 pr_err("type requires a 4 character value\n");
0124 return 0;
0125 }
0126 break;
0127 case opt_umask:
0128 if (match_octal(&args[0], &tmp)) {
0129 pr_err("umask requires a value\n");
0130 return 0;
0131 }
0132 sbi->umask = (umode_t)tmp;
0133 break;
0134 case opt_uid:
0135 if (match_int(&args[0], &tmp)) {
0136 pr_err("uid requires an argument\n");
0137 return 0;
0138 }
0139 sbi->uid = make_kuid(current_user_ns(), (uid_t)tmp);
0140 if (!uid_valid(sbi->uid)) {
0141 pr_err("invalid uid specified\n");
0142 return 0;
0143 }
0144 break;
0145 case opt_gid:
0146 if (match_int(&args[0], &tmp)) {
0147 pr_err("gid requires an argument\n");
0148 return 0;
0149 }
0150 sbi->gid = make_kgid(current_user_ns(), (gid_t)tmp);
0151 if (!gid_valid(sbi->gid)) {
0152 pr_err("invalid gid specified\n");
0153 return 0;
0154 }
0155 break;
0156 case opt_part:
0157 if (match_int(&args[0], &sbi->part)) {
0158 pr_err("part requires an argument\n");
0159 return 0;
0160 }
0161 break;
0162 case opt_session:
0163 if (match_int(&args[0], &sbi->session)) {
0164 pr_err("session requires an argument\n");
0165 return 0;
0166 }
0167 break;
0168 case opt_nls:
0169 if (sbi->nls) {
0170 pr_err("unable to change nls mapping\n");
0171 return 0;
0172 }
0173 p = match_strdup(&args[0]);
0174 if (p)
0175 sbi->nls = load_nls(p);
0176 if (!sbi->nls) {
0177 pr_err("unable to load nls mapping \"%s\"\n",
0178 p);
0179 kfree(p);
0180 return 0;
0181 }
0182 kfree(p);
0183 break;
0184 case opt_decompose:
0185 clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
0186 break;
0187 case opt_nodecompose:
0188 set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
0189 break;
0190 case opt_barrier:
0191 clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
0192 break;
0193 case opt_nobarrier:
0194 set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
0195 break;
0196 case opt_force:
0197 set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
0198 break;
0199 default:
0200 return 0;
0201 }
0202 }
0203
0204 done:
0205 if (!sbi->nls) {
0206
0207 sbi->nls = load_nls("utf8");
0208 if (!sbi->nls)
0209 sbi->nls = load_nls_default();
0210 if (!sbi->nls)
0211 return 0;
0212 }
0213
0214 return 1;
0215 }
0216
0217 int hfsplus_show_options(struct seq_file *seq, struct dentry *root)
0218 {
0219 struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb);
0220
0221 if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
0222 seq_show_option_n(seq, "creator", (char *)&sbi->creator, 4);
0223 if (sbi->type != HFSPLUS_DEF_CR_TYPE)
0224 seq_show_option_n(seq, "type", (char *)&sbi->type, 4);
0225 seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask,
0226 from_kuid_munged(&init_user_ns, sbi->uid),
0227 from_kgid_munged(&init_user_ns, sbi->gid));
0228 if (sbi->part >= 0)
0229 seq_printf(seq, ",part=%u", sbi->part);
0230 if (sbi->session >= 0)
0231 seq_printf(seq, ",session=%u", sbi->session);
0232 if (sbi->nls)
0233 seq_printf(seq, ",nls=%s", sbi->nls->charset);
0234 if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
0235 seq_puts(seq, ",nodecompose");
0236 if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
0237 seq_puts(seq, ",nobarrier");
0238 return 0;
0239 }