Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mount_opts.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1997 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1997 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
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 | {"recurse", MS_REC, MS_REC, 0}, |
25 | {"remount", MS_TYPE, MS_REMOUNT, 0}, |
26 | {"ro", MS_RDONLY, MS_RDONLY, 0}, |
27 | {"rw", MS_RDONLY, 0, MS_RDONLY}, |
28 | {"suid", MS_NOSUID, 0, MS_NOSUID}, |
29 | {"sync", MS_SYNCHRONOUS, MS_SYNCHRONOUS, 0}, |
30 | {"verbose", MS_VERBOSE, MS_VERBOSE, 0}, |
31 | }; |
32 | |
33 | static void add_extra_option(struct extra_opts *extra, char *s) |
34 | { |
35 | int len = strlen(s); |
36 | int newlen = extra->used_size + len; |
37 | |
38 | if (extra->str) |
39 | len++; /* +1 for ',' */ |
40 | |
41 | if (newlen >= extra->alloc_size) { |
42 | char *new; |
43 | |
44 | new = realloc(extra->str, newlen + 1); /* +1 for NUL */ |
45 | if (!new) |
46 | return; |
47 | |
48 | extra->str = new; |
49 | extra->end = extra->str + extra->used_size; |
50 | extra->alloc_size = newlen; |
51 | } |
52 | |
53 | if (extra->used_size) { |
54 | *extra->end = ','; |
55 | extra->end++; |
56 | } |
57 | strcpy(extra->end, s); |
58 | extra->used_size += len; |
59 | |
60 | } |
61 | |
62 | unsigned long |
63 | parse_mount_options(char *arg, unsigned long rwflag, struct extra_opts *extra) |
64 | { |
65 | char *s; |
66 | |
67 | while ((s = strsep(&arg, ",")) != NULL) { |
68 | char *opt = s; |
69 | unsigned int i; |
70 | int res, no = s[0] == 'n' && s[1] == 'o'; |
71 | |
72 | if (no) |
73 | s += 2; |
74 | |
75 | for (i = 0, res = 1; i < ARRAY_SIZE(options); i++) { |
76 | res = strcmp(s, options[i].str); |
77 | |
78 | if (res == 0) { |
79 | rwflag &= ~options[i].rwmask; |
80 | if (no) |
81 | rwflag |= options[i].rwnoset; |
82 | else |
83 | rwflag |= options[i].rwset; |
84 | } |
85 | if (res <= 0) |
86 | break; |
87 | } |
88 | |
89 | if (res != 0 && s[0]) |
90 | add_extra_option(extra, opt); |
91 | } |
92 | |
93 | return rwflag; |
94 | } |