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->umask = current->fs->umask;
25 opts->uid = current->uid;
26 opts->gid = current->gid;
31 /* convert a "four byte character" to a 32 bit int with error checks */
32 static int fill_fourchar(u32 *result, char *input)
37 if (!result || !input || !*input || (strlen(input) != 4))
40 for (out = 0, i = 0; i < 4; i++) {
42 out |= ((int)(input[i])) & 0xFF;
48 /* convert a string to int with error checks */
49 static int fill_int(int *result, char *input, int base)
54 if (!result || !input || !*input)
57 intval = simple_strtoul(tmp, &tmp, base);
65 /* Parse options from mount. Returns 0 on failure */
66 /* input is the options passed to mount() as a string */
67 int parse_options(char *input, struct hfsplus_sb_info *results)
69 char *curropt, *value;
75 while ((curropt = strsep(&input,",")) != NULL) {
79 if ((value = strchr(curropt, '=')) != NULL)
82 if (!strcmp(curropt, "creator")) {
83 if (!fill_fourchar(&(results->creator), value)) {
84 printk("HFS+-fs: creator requires a 4 character value\n");
87 } else if (!strcmp(curropt, "type")) {
88 if (!fill_fourchar(&(results->type), value)) {
89 printk("HFS+-fs: type requires a 4 character value\n");
92 } else if (!strcmp(curropt, "umask")) {
93 if (!fill_int(&tmp, value, 8)) {
94 printk("HFS+-fs: umask requires a value\n");
97 results->umask = (umode_t)tmp;
98 } else if (!strcmp(curropt, "uid")) {
99 if (!fill_int(&tmp, value, 0)) {
100 printk("HFS+-fs: uid requires an argument\n");
103 results->uid = (uid_t)tmp;
104 } else if (!strcmp(curropt, "gid")) {
105 if (!fill_int(&tmp, value, 0)) {
106 printk("HFS+-fs: gid requires an argument\n");
109 results->gid = (gid_t)tmp;
110 } else if (!strcmp(curropt, "part")) {
111 if (!fill_int(&results->part, value, 0)) {
112 printk("HFS+-fs: part requires an argument\n");
115 } else if (!strcmp(curropt, "session")) {
116 if (!fill_int(&results->session, value, 0)) {
117 printk("HFS+-fs: session requires an argument\n");
121 printk("HFS+-fs: unknown option %s\n", curropt);