Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mount_opts.c
Parent Directory | Revision Log
Revision 815 -
(show annotations)
(download)
Fri Apr 24 18:32:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2108 byte(s)
Fri Apr 24 18:32:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2108 byte(s)
-updated to klibc-1.5.15
1 | /* |
2 | * by rmk |
3 | * |
4 | * Decode mount options. |
5 | */ |
6 | #include <sys/mount.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
9 | |
10 | #include "mount_opts.h" |
11 | |
12 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) |
13 | |
14 | static const struct mount_opts options[] = { |
15 | /* name mask set noset */ |
16 | {"async", MS_SYNCHRONOUS, 0, MS_SYNCHRONOUS}, |
17 | {"atime", MS_NOATIME, 0, MS_NOATIME}, |
18 | {"bind", MS_TYPE, MS_BIND, 0,}, |
19 | {"dev", MS_NODEV, 0, MS_NODEV}, |
20 | {"diratime", MS_NODIRATIME, 0, MS_NODIRATIME}, |
21 | {"dirsync", MS_DIRSYNC, MS_DIRSYNC, 0}, |
22 | {"exec", MS_NOEXEC, 0, MS_NOEXEC}, |
23 | {"move", MS_TYPE, MS_MOVE, 0}, |
24 | {"nodev", MS_NODEV, MS_NODEV, 0}, |
25 | {"noexec", MS_NOEXEC, MS_NOEXEC, 0}, |
26 | {"nosuid", MS_NOSUID, MS_NOSUID, 0}, |
27 | {"recurse", MS_REC, MS_REC, 0}, |
28 | {"remount", MS_TYPE, MS_REMOUNT, 0}, |
29 | {"ro", MS_RDONLY, MS_RDONLY, 0}, |
30 | {"rw", MS_RDONLY, 0, MS_RDONLY}, |
31 | {"suid", MS_NOSUID, 0, MS_NOSUID}, |
32 | {"sync", MS_SYNCHRONOUS, MS_SYNCHRONOUS, 0}, |
33 | {"verbose", MS_VERBOSE, MS_VERBOSE, 0}, |
34 | }; |
35 | |
36 | static void add_extra_option(struct extra_opts *extra, char *s) |
37 | { |
38 | int len = strlen(s); |
39 | int newlen = extra->used_size + len; |
40 | |
41 | if (extra->str) |
42 | len++; /* +1 for ',' */ |
43 | |
44 | if (newlen >= extra->alloc_size) { |
45 | char *new; |
46 | |
47 | new = realloc(extra->str, newlen + 1); /* +1 for NUL */ |
48 | if (!new) |
49 | return; |
50 | |
51 | extra->str = new; |
52 | extra->end = extra->str + extra->used_size; |
53 | extra->alloc_size = newlen; |
54 | } |
55 | |
56 | if (extra->used_size) { |
57 | *extra->end = ','; |
58 | extra->end++; |
59 | } |
60 | strcpy(extra->end, s); |
61 | extra->used_size += len; |
62 | |
63 | } |
64 | |
65 | unsigned long |
66 | parse_mount_options(char *arg, unsigned long rwflag, struct extra_opts *extra) |
67 | { |
68 | char *s; |
69 | |
70 | while ((s = strsep(&arg, ",")) != NULL) { |
71 | char *opt = s; |
72 | unsigned int i; |
73 | int res, no = s[0] == 'n' && s[1] == 'o'; |
74 | |
75 | if (no) |
76 | s += 2; |
77 | |
78 | for (i = 0, res = 1; i < ARRAY_SIZE(options); i++) { |
79 | res = strcmp(s, options[i].str); |
80 | |
81 | if (res == 0) { |
82 | rwflag &= ~options[i].rwmask; |
83 | if (no) |
84 | rwflag |= options[i].rwnoset; |
85 | else |
86 | rwflag |= options[i].rwset; |
87 | } |
88 | if (res <= 0) |
89 | break; |
90 | } |
91 | |
92 | if (res != 0 && s[0]) |
93 | add_extra_option(extra, opt); |
94 | } |
95 | |
96 | return rwflag; |
97 | } |