1 // SPDX-License-Identifier: GPL-2.0
3 * linux/fs/hfsplus/options.c
6 * Brad Boyer (flar@allandria.com)
7 * (C) 2003 Ardis Technologies <roman@ardistech.com>
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"
24 opt_creator
, opt_type
,
25 opt_umask
, opt_uid
, opt_gid
,
26 opt_part
, opt_session
, opt_nls
,
27 opt_decompose
, opt_barrier
,
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
)
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();
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
;
69 * Only the force option is examined during remount, all others
72 if (fc
->purpose
== FS_CONTEXT_FOR_RECONFIGURE
&&
73 strncmp(param
->key
, "force", 5))
76 opt
= fs_parse(fc
, hfs_param_spec
, param
, &result
);
82 if (strlen(param
->string
) != 4) {
83 pr_err("creator requires a 4 character value\n");
86 memcpy(&sbi
->creator
, param
->string
, 4);
89 if (strlen(param
->string
) != 4) {
90 pr_err("type requires a 4 character value\n");
93 memcpy(&sbi
->type
, param
->string
, 4);
96 sbi
->umask
= (umode_t
)result
.uint_32
;
99 sbi
->uid
= result
.uid
;
100 set_bit(HFSPLUS_SB_UID
, &sbi
->flags
);
103 sbi
->gid
= result
.gid
;
104 set_bit(HFSPLUS_SB_GID
, &sbi
->flags
);
107 sbi
->part
= result
.uint_32
;
110 sbi
->session
= result
.uint_32
;
114 pr_err("unable to change nls mapping\n");
117 sbi
->nls
= load_nls(param
->string
);
119 pr_err("unable to load nls mapping \"%s\"\n",
126 set_bit(HFSPLUS_SB_NODECOMPOSE
, &sbi
->flags
);
128 clear_bit(HFSPLUS_SB_NODECOMPOSE
, &sbi
->flags
);
132 set_bit(HFSPLUS_SB_NOBARRIER
, &sbi
->flags
);
134 clear_bit(HFSPLUS_SB_NOBARRIER
, &sbi
->flags
);
137 set_bit(HFSPLUS_SB_FORCE
, &sbi
->flags
);
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
));
158 seq_printf(seq
, ",part=%u", sbi
->part
);
159 if (sbi
->session
>= 0)
160 seq_printf(seq
, ",session=%u", sbi
->session
);
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");