Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 16 | #include <linux/mount.h> |
| 17 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Christoph Hellwig | 34a2d31 | 2010-11-23 14:38:21 +0100 | [diff] [blame] | 26 | opt_barrier, opt_nobarrier, |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 27 | opt_force, opt_err |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 30 | static const match_table_t tokens = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" }, |
Christoph Hellwig | 34a2d31 | 2010-11-23 14:38:21 +0100 | [diff] [blame] | 41 | { opt_barrier, "barrier" }, |
| 42 | { opt_nobarrier, "nobarrier" }, |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 43 | { opt_force, "force" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { opt_err, NULL } |
| 45 | }; |
| 46 | |
| 47 | /* Initialize an options object to reasonable defaults */ |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 48 | void hfsplus_fill_defaults(struct hfsplus_sb_info *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | if (!opts) |
| 51 | return; |
| 52 | |
| 53 | opts->creator = HFSPLUS_DEF_CR_TYPE; |
| 54 | opts->type = HFSPLUS_DEF_CR_TYPE; |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 55 | opts->umask = current_umask(); |
David Howells | 4ac8489 | 2008-11-14 10:38:54 +1100 | [diff] [blame] | 56 | opts->uid = current_uid(); |
| 57 | opts->gid = current_gid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | opts->part = -1; |
| 59 | opts->session = -1; |
| 60 | } |
| 61 | |
| 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) |
| 64 | { |
| 65 | if (arg->to - arg->from != 4) |
| 66 | return -EINVAL; |
| 67 | memcpy(result, arg->from, 4); |
| 68 | return 0; |
| 69 | } |
| 70 | |
Christoph Hellwig | 6f80dfe | 2010-11-07 23:01:17 +0100 | [diff] [blame] | 71 | int hfsplus_parse_options_remount(char *input, int *force) |
| 72 | { |
| 73 | char *p; |
| 74 | substring_t args[MAX_OPT_ARGS]; |
| 75 | int token; |
| 76 | |
| 77 | if (!input) |
| 78 | return 0; |
| 79 | |
| 80 | while ((p = strsep(&input, ",")) != NULL) { |
| 81 | if (!*p) |
| 82 | continue; |
| 83 | |
| 84 | token = match_token(p, tokens, args); |
| 85 | switch (token) { |
| 86 | case opt_force: |
| 87 | *force = 1; |
| 88 | break; |
| 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return 1; |
| 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* Parse options from mount. Returns 0 on failure */ |
| 98 | /* input is the options passed to mount() as a string */ |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 99 | int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | char *p; |
| 102 | substring_t args[MAX_OPT_ARGS]; |
| 103 | int tmp, token; |
| 104 | |
| 105 | if (!input) |
| 106 | goto done; |
| 107 | |
| 108 | while ((p = strsep(&input, ",")) != NULL) { |
| 109 | if (!*p) |
| 110 | continue; |
| 111 | |
| 112 | token = match_token(p, tokens, args); |
| 113 | switch (token) { |
| 114 | case opt_creator: |
| 115 | if (match_fourchar(&args[0], &sbi->creator)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 116 | printk(KERN_ERR "hfs: creator requires a 4 character value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | break; |
| 120 | case opt_type: |
| 121 | if (match_fourchar(&args[0], &sbi->type)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 122 | printk(KERN_ERR "hfs: type requires a 4 character value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | break; |
| 126 | case opt_umask: |
| 127 | if (match_octal(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 128 | printk(KERN_ERR "hfs: umask requires a value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | sbi->umask = (umode_t)tmp; |
| 132 | break; |
| 133 | case opt_uid: |
| 134 | if (match_int(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 135 | printk(KERN_ERR "hfs: uid requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | sbi->uid = (uid_t)tmp; |
| 139 | break; |
| 140 | case opt_gid: |
| 141 | if (match_int(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 142 | printk(KERN_ERR "hfs: gid requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | sbi->gid = (gid_t)tmp; |
| 146 | break; |
| 147 | case opt_part: |
| 148 | if (match_int(&args[0], &sbi->part)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 149 | printk(KERN_ERR "hfs: part requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | break; |
| 153 | case opt_session: |
| 154 | if (match_int(&args[0], &sbi->session)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 155 | printk(KERN_ERR "hfs: session requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | break; |
| 159 | case opt_nls: |
| 160 | if (sbi->nls) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 161 | printk(KERN_ERR "hfs: unable to change nls mapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | p = match_strdup(&args[0]); |
Jim Meyering | cd6fda3 | 2008-04-29 00:59:08 -0700 | [diff] [blame] | 165 | if (p) |
| 166 | sbi->nls = load_nls(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (!sbi->nls) { |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 168 | printk(KERN_ERR "hfs: unable to load " |
| 169 | "nls mapping \"%s\"\n", |
| 170 | p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | kfree(p); |
| 172 | return 0; |
| 173 | } |
| 174 | kfree(p); |
| 175 | break; |
| 176 | case opt_decompose: |
Christoph Hellwig | 84adede | 2010-10-01 05:45:20 +0200 | [diff] [blame] | 177 | clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | case opt_nodecompose: |
Christoph Hellwig | 84adede | 2010-10-01 05:45:20 +0200 | [diff] [blame] | 180 | set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | break; |
Christoph Hellwig | 34a2d31 | 2010-11-23 14:38:21 +0100 | [diff] [blame] | 182 | case opt_barrier: |
| 183 | clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags); |
| 184 | break; |
| 185 | case opt_nobarrier: |
| 186 | set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags); |
| 187 | break; |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 188 | case opt_force: |
Christoph Hellwig | 84adede | 2010-10-01 05:45:20 +0200 | [diff] [blame] | 189 | set_bit(HFSPLUS_SB_FORCE, &sbi->flags); |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 190 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | default: |
| 192 | return 0; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | done: |
| 197 | if (!sbi->nls) { |
| 198 | /* try utf8 first, as this is the old default behaviour */ |
| 199 | sbi->nls = load_nls("utf8"); |
| 200 | if (!sbi->nls) |
| 201 | sbi->nls = load_nls_default(); |
| 202 | if (!sbi->nls) |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | return 1; |
| 207 | } |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 208 | |
| 209 | int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) |
| 210 | { |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 211 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(mnt->mnt_sb); |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 212 | |
| 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); |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 217 | seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, |
| 218 | sbi->uid, sbi->gid); |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 219 | if (sbi->part >= 0) |
| 220 | seq_printf(seq, ",part=%u", sbi->part); |
| 221 | if (sbi->session >= 0) |
| 222 | seq_printf(seq, ",session=%u", sbi->session); |
| 223 | if (sbi->nls) |
| 224 | seq_printf(seq, ",nls=%s", sbi->nls->charset); |
Christoph Hellwig | 84adede | 2010-10-01 05:45:20 +0200 | [diff] [blame] | 225 | if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags)) |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 226 | seq_printf(seq, ",nodecompose"); |
Christoph Hellwig | 34a2d31 | 2010-11-23 14:38:21 +0100 | [diff] [blame] | 227 | if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags)) |
| 228 | seq_printf(seq, ",nobarrier"); |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 229 | return 0; |
| 230 | } |