Merge tag 'soundwire-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul...
[linux-stable.git] / fs / hfsplus / options.c
bloba66a09a56bf70f889a7cd7299b3261df20d18835
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/fs/hfsplus/options.c
5 * Copyright (C) 2001
6 * Brad Boyer (flar@allandria.com)
7 * (C) 2003 Ardis Technologies <roman@ardistech.com>
9 * Option parsing
12 #include <linux/string.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/fs_context.h>
16 #include <linux/fs_parser.h>
17 #include <linux/nls.h>
18 #include <linux/mount.h>
19 #include <linux/seq_file.h>
20 #include <linux/slab.h>
21 #include "hfsplus_fs.h"
23 enum {
24 opt_creator, opt_type,
25 opt_umask, opt_uid, opt_gid,
26 opt_part, opt_session, opt_nls,
27 opt_decompose, opt_barrier,
28 opt_force,
31 static const struct fs_parameter_spec hfs_param_spec[] = {
32 fsparam_string ("creator", opt_creator),
33 fsparam_string ("type", opt_type),
34 fsparam_u32oct ("umask", opt_umask),
35 fsparam_u32 ("uid", opt_uid),
36 fsparam_u32 ("gid", opt_gid),
37 fsparam_u32 ("part", opt_part),
38 fsparam_u32 ("session", opt_session),
39 fsparam_string ("nls", opt_nls),
40 fsparam_flag_no ("decompose", opt_decompose),
41 fsparam_flag_no ("barrier", opt_barrier),
42 fsparam_flag ("force", opt_force),
46 /* Initialize an options object to reasonable defaults */
47 void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)
49 if (!opts)
50 return;
52 opts->creator = HFSPLUS_DEF_CR_TYPE;
53 opts->type = HFSPLUS_DEF_CR_TYPE;
54 opts->umask = current_umask();
55 opts->uid = current_uid();
56 opts->gid = current_gid();
57 opts->part = -1;
58 opts->session = -1;
61 /* Parse options from mount. Returns nonzero errno on failure */
62 int hfsplus_parse_param(struct fs_context *fc, struct fs_parameter *param)
64 struct hfsplus_sb_info *sbi = fc->s_fs_info;
65 struct fs_parse_result result;
66 int opt;
69 * Only the force option is examined during remount, all others
70 * are ignored.
72 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
73 strncmp(param->key, "force", 5))
74 return 0;
76 opt = fs_parse(fc, hfs_param_spec, param, &result);
77 if (opt < 0)
78 return opt;
80 switch (opt) {
81 case opt_creator:
82 if (strlen(param->string) != 4) {
83 pr_err("creator requires a 4 character value\n");
84 return -EINVAL;
86 memcpy(&sbi->creator, param->string, 4);
87 break;
88 case opt_type:
89 if (strlen(param->string) != 4) {
90 pr_err("type requires a 4 character value\n");
91 return -EINVAL;
93 memcpy(&sbi->type, param->string, 4);
94 break;
95 case opt_umask:
96 sbi->umask = (umode_t)result.uint_32;
97 break;
98 case opt_uid:
99 sbi->uid = result.uid;
100 set_bit(HFSPLUS_SB_UID, &sbi->flags);
101 break;
102 case opt_gid:
103 sbi->gid = result.gid;
104 set_bit(HFSPLUS_SB_GID, &sbi->flags);
105 break;
106 case opt_part:
107 sbi->part = result.uint_32;
108 break;
109 case opt_session:
110 sbi->session = result.uint_32;
111 break;
112 case opt_nls:
113 if (sbi->nls) {
114 pr_err("unable to change nls mapping\n");
115 return -EINVAL;
117 sbi->nls = load_nls(param->string);
118 if (!sbi->nls) {
119 pr_err("unable to load nls mapping \"%s\"\n",
120 param->string);
121 return -EINVAL;
123 break;
124 case opt_decompose:
125 if (result.negated)
126 set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
127 else
128 clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
129 break;
130 case opt_barrier:
131 if (result.negated)
132 set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
133 else
134 clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
135 break;
136 case opt_force:
137 set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
138 break;
139 default:
140 return -EINVAL;
143 return 0;
146 int hfsplus_show_options(struct seq_file *seq, struct dentry *root)
148 struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb);
150 if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
151 seq_show_option_n(seq, "creator", (char *)&sbi->creator, 4);
152 if (sbi->type != HFSPLUS_DEF_CR_TYPE)
153 seq_show_option_n(seq, "type", (char *)&sbi->type, 4);
154 seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask,
155 from_kuid_munged(&init_user_ns, sbi->uid),
156 from_kgid_munged(&init_user_ns, sbi->gid));
157 if (sbi->part >= 0)
158 seq_printf(seq, ",part=%u", sbi->part);
159 if (sbi->session >= 0)
160 seq_printf(seq, ",session=%u", sbi->session);
161 if (sbi->nls)
162 seq_printf(seq, ",nls=%s", sbi->nls->charset);
163 if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
164 seq_puts(seq, ",nodecompose");
165 if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
166 seq_puts(seq, ",nobarrier");
167 return 0;