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, |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 26 | opt_force, opt_err |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 29 | static const match_table_t tokens = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { opt_creator, "creator=%s" }, |
| 31 | { opt_type, "type=%s" }, |
| 32 | { opt_umask, "umask=%o" }, |
| 33 | { opt_uid, "uid=%u" }, |
| 34 | { opt_gid, "gid=%u" }, |
| 35 | { opt_part, "part=%u" }, |
| 36 | { opt_session, "session=%u" }, |
| 37 | { opt_nls, "nls=%s" }, |
| 38 | { opt_decompose, "decompose" }, |
| 39 | { opt_nodecompose, "nodecompose" }, |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 40 | { opt_force, "force" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { opt_err, NULL } |
| 42 | }; |
| 43 | |
| 44 | /* Initialize an options object to reasonable defaults */ |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 45 | void hfsplus_fill_defaults(struct hfsplus_sb_info *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | if (!opts) |
| 48 | return; |
| 49 | |
| 50 | opts->creator = HFSPLUS_DEF_CR_TYPE; |
| 51 | opts->type = HFSPLUS_DEF_CR_TYPE; |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 52 | opts->umask = current_umask(); |
David Howells | 4ac8489 | 2008-11-14 10:38:54 +1100 | [diff] [blame] | 53 | opts->uid = current_uid(); |
| 54 | opts->gid = current_gid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | opts->part = -1; |
| 56 | opts->session = -1; |
| 57 | } |
| 58 | |
| 59 | /* convert a "four byte character" to a 32 bit int with error checks */ |
| 60 | static inline int match_fourchar(substring_t *arg, u32 *result) |
| 61 | { |
| 62 | if (arg->to - arg->from != 4) |
| 63 | return -EINVAL; |
| 64 | memcpy(result, arg->from, 4); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /* Parse options from mount. Returns 0 on failure */ |
| 69 | /* input is the options passed to mount() as a string */ |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 70 | int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | char *p; |
| 73 | substring_t args[MAX_OPT_ARGS]; |
| 74 | int tmp, token; |
| 75 | |
| 76 | if (!input) |
| 77 | goto done; |
| 78 | |
| 79 | while ((p = strsep(&input, ",")) != NULL) { |
| 80 | if (!*p) |
| 81 | continue; |
| 82 | |
| 83 | token = match_token(p, tokens, args); |
| 84 | switch (token) { |
| 85 | case opt_creator: |
| 86 | if (match_fourchar(&args[0], &sbi->creator)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 87 | printk(KERN_ERR "hfs: creator requires a 4 character value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | break; |
| 91 | case opt_type: |
| 92 | if (match_fourchar(&args[0], &sbi->type)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 93 | printk(KERN_ERR "hfs: type requires a 4 character value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | break; |
| 97 | case opt_umask: |
| 98 | if (match_octal(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 99 | printk(KERN_ERR "hfs: umask requires a value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | sbi->umask = (umode_t)tmp; |
| 103 | break; |
| 104 | case opt_uid: |
| 105 | if (match_int(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 106 | printk(KERN_ERR "hfs: uid requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | sbi->uid = (uid_t)tmp; |
| 110 | break; |
| 111 | case opt_gid: |
| 112 | if (match_int(&args[0], &tmp)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 113 | printk(KERN_ERR "hfs: gid requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | sbi->gid = (gid_t)tmp; |
| 117 | break; |
| 118 | case opt_part: |
| 119 | if (match_int(&args[0], &sbi->part)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 120 | printk(KERN_ERR "hfs: part requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | break; |
| 124 | case opt_session: |
| 125 | if (match_int(&args[0], &sbi->session)) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 126 | printk(KERN_ERR "hfs: session requires an argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | break; |
| 130 | case opt_nls: |
| 131 | if (sbi->nls) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 132 | printk(KERN_ERR "hfs: unable to change nls mapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | p = match_strdup(&args[0]); |
Jim Meyering | cd6fda3 | 2008-04-29 00:59:08 -0700 | [diff] [blame] | 136 | if (p) |
| 137 | sbi->nls = load_nls(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | if (!sbi->nls) { |
Roman Zippel | 634725a | 2006-01-18 17:43:05 -0800 | [diff] [blame] | 139 | printk(KERN_ERR "hfs: unable to load nls mapping \"%s\"\n", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | kfree(p); |
| 141 | return 0; |
| 142 | } |
| 143 | kfree(p); |
| 144 | break; |
| 145 | case opt_decompose: |
| 146 | sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE; |
| 147 | break; |
| 148 | case opt_nodecompose: |
| 149 | sbi->flags |= HFSPLUS_SB_NODECOMPOSE; |
| 150 | break; |
Roman Zippel | b0b623c | 2005-11-29 19:34:41 -0800 | [diff] [blame] | 151 | case opt_force: |
| 152 | sbi->flags |= HFSPLUS_SB_FORCE; |
| 153 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | default: |
| 155 | return 0; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | done: |
| 160 | if (!sbi->nls) { |
| 161 | /* try utf8 first, as this is the old default behaviour */ |
| 162 | sbi->nls = load_nls("utf8"); |
| 163 | if (!sbi->nls) |
| 164 | sbi->nls = load_nls_default(); |
| 165 | if (!sbi->nls) |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | return 1; |
| 170 | } |
Roman Zippel | 717dd80e | 2005-09-06 15:18:48 -0700 | [diff] [blame] | 171 | |
| 172 | int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) |
| 173 | { |
| 174 | struct hfsplus_sb_info *sbi = &HFSPLUS_SB(mnt->mnt_sb); |
| 175 | |
| 176 | if (sbi->creator != HFSPLUS_DEF_CR_TYPE) |
| 177 | seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator); |
| 178 | if (sbi->type != HFSPLUS_DEF_CR_TYPE) |
| 179 | seq_printf(seq, ",type=%.4s", (char *)&sbi->type); |
| 180 | seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, sbi->uid, sbi->gid); |
| 181 | if (sbi->part >= 0) |
| 182 | seq_printf(seq, ",part=%u", sbi->part); |
| 183 | if (sbi->session >= 0) |
| 184 | seq_printf(seq, ",session=%u", sbi->session); |
| 185 | if (sbi->nls) |
| 186 | seq_printf(seq, ",nls=%s", sbi->nls->charset); |
| 187 | if (sbi->flags & HFSPLUS_SB_NODECOMPOSE) |
| 188 | seq_printf(seq, ",nodecompose"); |
| 189 | return 0; |
| 190 | } |