initial commit with v2.6.9
[linux-2.6.9-moxart.git] / fs / hfsplus / options.c
blob20c802ff5db04bcb4ef25493f7c2dc4224966d44
1 /*
2 * linux/fs/hfsplus/options.c
4 * Copyright (C) 2001
5 * Brad Boyer (flar@allandria.com)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
8 * Option parsing
9 */
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)
19 if (!opts)
20 return;
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;
27 opts->part = -1;
28 opts->session = -1;
31 /* convert a "four byte character" to a 32 bit int with error checks */
32 static int fill_fourchar(u32 *result, char *input)
34 u32 out;
35 int i;
37 if (!result || !input || !*input || (strlen(input) != 4))
38 return 0;
40 for (out = 0, i = 0; i < 4; i++) {
41 out <<= 8;
42 out |= ((int)(input[i])) & 0xFF;
44 *result = out;
45 return 1;
48 /* convert a string to int with error checks */
49 static int fill_int(int *result, char *input, int base)
51 char *tmp = input;
52 int intval;
54 if (!result || !input || !*input)
55 return 0;
57 intval = simple_strtoul(tmp, &tmp, base);
58 if (*tmp)
59 return 0;
61 *result = intval;
62 return 1;
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;
70 int tmp;
72 if (!input)
73 return 1;
75 while ((curropt = strsep(&input,",")) != NULL) {
76 if (!*curropt)
77 continue;
79 if ((value = strchr(curropt, '=')) != NULL)
80 *value++ = '\0';
82 if (!strcmp(curropt, "creator")) {
83 if (!fill_fourchar(&(results->creator), value)) {
84 printk("HFS+-fs: creator requires a 4 character value\n");
85 return 0;
87 } else if (!strcmp(curropt, "type")) {
88 if (!fill_fourchar(&(results->type), value)) {
89 printk("HFS+-fs: type requires a 4 character value\n");
90 return 0;
92 } else if (!strcmp(curropt, "umask")) {
93 if (!fill_int(&tmp, value, 8)) {
94 printk("HFS+-fs: umask requires a value\n");
95 return 0;
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");
101 return 0;
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");
107 return 0;
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");
113 return 0;
115 } else if (!strcmp(curropt, "session")) {
116 if (!fill_int(&results->session, value, 0)) {
117 printk("HFS+-fs: session requires an argument\n");
118 return 0;
120 } else {
121 printk("HFS+-fs: unknown option %s\n", curropt);
122 return 0;
126 return 1;