2 * linux/fs/hfsplus/options.c
5 * Brad Boyer (flar@allandria.com)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
11 #include <linux/string.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include "hfsplus_fs.h"
16 /* Initialize an options object to reasonable defaults */
17 void fill_defaults(struct hfsplus_sb_info *opts)
22 opts->creator = HFSPLUS_DEF_CR_TYPE;
23 opts->type = HFSPLUS_DEF_CR_TYPE;
24 opts->charcase = HFSPLUS_CASE_ASIS;
25 opts->fork = HFSPLUS_FORK_RAW;
26 opts->namemap = HFSPLUS_NAMES_TRIVIAL;
27 opts->umask = current->fs->umask;
28 opts->uid = current->uid;
29 opts->gid = current->gid;
32 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
33 /* Copy settings from one hfsplus_sb_info object to another */
34 void fill_current(struct hfsplus_sb_info *curopts,
35 struct hfsplus_sb_info *opts)
37 if (!curopts || !opts)
40 opts->creator = curopts->creator;
41 opts->type = curopts->type;
42 opts->charcase = curopts->charcase;
43 opts->fork = curopts->fork;
44 opts->namemap = curopts->namemap;
45 opts->umask = curopts->umask;
46 opts->uid = curopts->uid;
47 opts->gid = curopts->gid;
51 /* convert a "four byte character" to a 32 bit int with error checks */
52 static int fill_fourchar(u32 *result, char *input)
57 if (!result || !input || !*input || (strlen(input) != 4))
60 for (out = 0, i = 0; i < 4; i++) {
62 out |= ((int)(input[i])) & 0xFF;
68 /* convert a string to int with error checks */
69 static int fill_int(int *result, char *input, int base)
74 if (!result || !input || !*input)
77 intval = simple_strtoul(tmp, &tmp, base);
85 /* Parse options from mount. Returns 0 on failure */
86 /* input is the options passed to mount() as a string */
87 int parse_options(char *input, struct hfsplus_sb_info *results)
89 char *curropt, *value;
95 while ((curropt = strsep(&input,",")) != NULL) {
99 if ((value = strchr(curropt, '=')) != NULL)
102 if (!strcmp(curropt, "creator")) {
103 if (!fill_fourchar(&(results->creator), value)) {
104 printk("HFS+-fs: creator requires a 4 character value\n");
107 } else if (!strcmp(curropt, "type")) {
108 if (!fill_fourchar(&(results->type), value)) {
109 printk("HFS+-fs: type requires a 4 character value\n");
112 } else if (!strcmp(curropt, "case")) {
113 } else if (!strcmp(curropt, "fork")) {
114 } else if (!strcmp(curropt, "names")) {
115 } else if (!strcmp(curropt, "umask")) {
116 if (!fill_int(&tmp, value, 8)) {
117 printk("HFS+-fs: umask requires a value\n");
120 results->umask = (umode_t)tmp;
121 } else if (!strcmp(curropt, "uid")) {
122 if (!fill_int(&tmp, value, 0)) {
123 printk("HFS+-fs: uid requires an argument\n");
126 results->uid = (uid_t)tmp;
127 } else if (!strcmp(curropt, "gid")) {
128 if (!fill_int(&tmp, value, 0)) {
129 printk("HFS+-fs: gid requires an argument\n");
132 results->gid = (gid_t)tmp;
134 printk("HFS+-fs: unknown option %s\n", curropt);