Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mount_main.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: 1910 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1910 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 | #include <sys/mount.h> |
5 | #include <errno.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
9 | #include <unistd.h> |
10 | |
11 | #include "mount_opts.h" |
12 | |
13 | char *progname; |
14 | |
15 | static struct extra_opts extra; |
16 | static unsigned long rwflag; |
17 | |
18 | static int |
19 | do_mount(char *dev, char *dir, char *type, unsigned long rwflag, void *data) |
20 | { |
21 | char *s; |
22 | int error = 0; |
23 | |
24 | while ((s = strsep(&type, ",")) != NULL) { |
25 | retry: |
26 | if (mount(dev, dir, s, rwflag, data) == -1) { |
27 | error = errno; |
28 | /* |
29 | * If the filesystem is not found, or the |
30 | * superblock is invalid, try the next. |
31 | */ |
32 | if (error == ENODEV || error == EINVAL) |
33 | continue; |
34 | |
35 | /* |
36 | * If we get EACCESS, and we're trying to |
37 | * mount readwrite and this isn't a remount, |
38 | * try read only. |
39 | */ |
40 | if (error == EACCES && |
41 | (rwflag & (MS_REMOUNT | MS_RDONLY)) == 0) { |
42 | rwflag |= MS_RDONLY; |
43 | goto retry; |
44 | } |
45 | break; |
46 | } |
47 | } |
48 | |
49 | if (error) { |
50 | errno = error; |
51 | perror("mount"); |
52 | return 255; |
53 | } |
54 | |
55 | return 0; |
56 | } |
57 | |
58 | int main(int argc, char *argv[]) |
59 | { |
60 | char *type = NULL; |
61 | int c; |
62 | |
63 | progname = argv[0]; |
64 | rwflag = MS_VERBOSE; |
65 | |
66 | do { |
67 | c = getopt(argc, argv, "o:rt:w"); |
68 | if (c == EOF) |
69 | break; |
70 | switch (c) { |
71 | case 'o': |
72 | rwflag = parse_mount_options(optarg, rwflag, &extra); |
73 | break; |
74 | case 'r': |
75 | rwflag |= MS_RDONLY; |
76 | break; |
77 | case 't': |
78 | type = optarg; |
79 | break; |
80 | case 'w': |
81 | rwflag &= ~MS_RDONLY; |
82 | break; |
83 | case '?': |
84 | fprintf(stderr, "%s: invalid option -%c\n", |
85 | progname, optopt); |
86 | exit(1); |
87 | } |
88 | } while (1); |
89 | |
90 | /* |
91 | * If remount, bind or move was specified, then we don't |
92 | * have a "type" as such. Use the dummy "none" type. |
93 | */ |
94 | if (rwflag & MS_TYPE) |
95 | type = "none"; |
96 | |
97 | if (optind + 2 != argc || type == NULL) { |
98 | fprintf(stderr, "Usage: %s [-r] [-w] [-o options] [-t type] " |
99 | "device directory\n", progname); |
100 | exit(1); |
101 | } |
102 | |
103 | return do_mount(argv[optind], argv[optind + 1], type, rwflag, |
104 | extra.str); |
105 | } |