diff options
Diffstat (limited to 'mount.c')
-rw-r--r-- | mount.c | 71 |
1 files changed, 56 insertions, 15 deletions
@@ -41,11 +41,17 @@ | |||
41 | #include <ctype.h> | 41 | #include <ctype.h> |
42 | #include <fstab.h> | 42 | #include <fstab.h> |
43 | 43 | ||
44 | extern const char mtab_file[]; /* Defined in utility.c */ | ||
45 | |||
44 | static const char mount_usage[] = "Usage:\tmount [flags]\n" | 46 | static const char mount_usage[] = "Usage:\tmount [flags]\n" |
45 | "\tmount [flags] device directory [-o options,more-options]\n" | 47 | "\tmount [flags] device directory [-o options,more-options]\n" |
46 | "\n" | 48 | "\n" |
47 | "Flags:\n" | 49 | "Flags:\n" |
48 | "\t-a:\tMount all file systems in fstab.\n" | 50 | "\t-a:\tMount all file systems in fstab.\n" |
51 | #ifdef BB_MTAB | ||
52 | "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n" | ||
53 | "\t-n:\tDon't write a mount table entry.\n" | ||
54 | #endif | ||
49 | "\t-o option:\tOne of many filesystem options, listed below.\n" | 55 | "\t-o option:\tOne of many filesystem options, listed below.\n" |
50 | "\t-r:\tMount the filesystem read-only.\n" | 56 | "\t-r:\tMount the filesystem read-only.\n" |
51 | "\t-t filesystem-type:\tSpecify the filesystem type.\n" | 57 | "\t-t filesystem-type:\tSpecify the filesystem type.\n" |
@@ -62,6 +68,7 @@ static const char mount_usage[] = "Usage:\tmount [flags]\n" | |||
62 | "There are EVEN MORE flags that are specific to each filesystem.\n" | 68 | "There are EVEN MORE flags that are specific to each filesystem.\n" |
63 | "You'll have to see the written documentation for those.\n"; | 69 | "You'll have to see the written documentation for those.\n"; |
64 | 70 | ||
71 | |||
65 | struct mount_options { | 72 | struct mount_options { |
66 | const char *name; | 73 | const char *name; |
67 | unsigned long and; | 74 | unsigned long and; |
@@ -84,6 +91,29 @@ static const struct mount_options mount_options[] = { | |||
84 | {0, 0, 0} | 91 | {0, 0, 0} |
85 | }; | 92 | }; |
86 | 93 | ||
94 | #if ! defined BB_MTAB | ||
95 | #define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \ | ||
96 | mount(specialfile, dir, filesystemtype, flags, string_flags) | ||
97 | #else | ||
98 | static int | ||
99 | do_mount(char* specialfile, char* dir, char* filesystemtype, | ||
100 | long flags, void* string_flags, int useMtab, int fakeIt) | ||
101 | { | ||
102 | int status=0; | ||
103 | |||
104 | if (fakeIt==FALSE) | ||
105 | status=mount(specialfile, dir, filesystemtype, flags, string_flags); | ||
106 | |||
107 | if ( status == 0 ) { | ||
108 | if ( useMtab==TRUE ) | ||
109 | write_mtab(specialfile, dir, filesystemtype, flags, string_flags); | ||
110 | return 0; | ||
111 | } | ||
112 | else | ||
113 | return( status); | ||
114 | } | ||
115 | #endif | ||
116 | |||
87 | 117 | ||
88 | /* Seperate standard mount options from the nonstandard string options */ | 118 | /* Seperate standard mount options from the nonstandard string options */ |
89 | static void | 119 | static void |
@@ -126,9 +156,8 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags) | |||
126 | } | 156 | } |
127 | 157 | ||
128 | int | 158 | int |
129 | mount_one ( | 159 | mount_one(char *blockDevice, char *directory, char *filesystemType, |
130 | char *blockDevice, char *directory, char *filesystemType, | 160 | unsigned long flags, char *string_flags, int useMtab, int fakeIt) |
131 | unsigned long flags, char *string_flags) | ||
132 | { | 161 | { |
133 | int status = 0; | 162 | int status = 0; |
134 | 163 | ||
@@ -152,16 +181,16 @@ mount_one ( | |||
152 | filesystemType = buf; | 181 | filesystemType = buf; |
153 | filesystemType++; // hop past tab | 182 | filesystemType++; // hop past tab |
154 | 183 | ||
155 | status = mount (blockDevice, directory, filesystemType, | 184 | status = do_mount (blockDevice, directory, filesystemType, |
156 | flags | MS_MGC_VAL, string_flags); | 185 | flags | MS_MGC_VAL, string_flags, useMtab, fakeIt); |
157 | if (status == 0) | 186 | if (status == 0) |
158 | break; | 187 | break; |
159 | } | 188 | } |
160 | } | 189 | } |
161 | fclose (f); | 190 | fclose (f); |
162 | } else { | 191 | } else { |
163 | status = mount (blockDevice, directory, filesystemType, | 192 | status = do_mount (blockDevice, directory, filesystemType, |
164 | flags | MS_MGC_VAL, string_flags); | 193 | flags | MS_MGC_VAL, string_flags, useMtab, fakeIt); |
165 | } | 194 | } |
166 | 195 | ||
167 | if (status) { | 196 | if (status) { |
@@ -180,15 +209,17 @@ extern int mount_main (int argc, char **argv) | |||
180 | char *device = NULL; | 209 | char *device = NULL; |
181 | char *directory = NULL; | 210 | char *directory = NULL; |
182 | struct stat statBuf; | 211 | struct stat statBuf; |
183 | int all = 0; | 212 | int all = FALSE; |
213 | int fakeIt = FALSE; | ||
214 | int useMtab = TRUE; | ||
184 | int i; | 215 | int i; |
185 | 216 | ||
186 | if (stat("/etc/fstab", &statBuf) < 0) | 217 | if (stat("/etc/fstab", &statBuf) < 0) |
187 | fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); | 218 | fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); |
188 | 219 | ||
189 | if (argc == 1) { | 220 | if (argc == 1) { |
190 | FILE *mountTable; | 221 | FILE *mountTable = setmntent (mtab_file, "r"); |
191 | if ((mountTable = setmntent ("/proc/mounts", "r"))) { | 222 | if (mountTable) { |
192 | struct mntent *m; | 223 | struct mntent *m; |
193 | while ((m = getmntent (mountTable)) != 0) { | 224 | while ((m = getmntent (mountTable)) != 0) { |
194 | struct fstab* fstabItem; | 225 | struct fstab* fstabItem; |
@@ -203,6 +234,8 @@ extern int mount_main (int argc, char **argv) | |||
203 | m->mnt_type, m->mnt_opts); | 234 | m->mnt_type, m->mnt_opts); |
204 | } | 235 | } |
205 | endmntent (mountTable); | 236 | endmntent (mountTable); |
237 | } else { | ||
238 | perror(mtab_file); | ||
206 | } | 239 | } |
207 | exit( TRUE); | 240 | exit( TRUE); |
208 | } | 241 | } |
@@ -241,6 +274,14 @@ extern int mount_main (int argc, char **argv) | |||
241 | case 'a': | 274 | case 'a': |
242 | all = TRUE; | 275 | all = TRUE; |
243 | break; | 276 | break; |
277 | #ifdef BB_MTAB | ||
278 | case 'f': | ||
279 | fakeIt = TRUE; | ||
280 | break; | ||
281 | case 'n': | ||
282 | useMtab = FALSE; | ||
283 | break; | ||
284 | #endif | ||
244 | case 'v': | 285 | case 'v': |
245 | case 'h': | 286 | case 'h': |
246 | case '-': | 287 | case '-': |
@@ -263,7 +304,6 @@ extern int mount_main (int argc, char **argv) | |||
263 | } | 304 | } |
264 | 305 | ||
265 | if (all == TRUE) { | 306 | if (all == TRUE) { |
266 | long newFlags; | ||
267 | struct mntent *m; | 307 | struct mntent *m; |
268 | FILE *f = setmntent ("/etc/fstab", "r"); | 308 | FILE *f = setmntent ("/etc/fstab", "r"); |
269 | 309 | ||
@@ -279,17 +319,18 @@ extern int mount_main (int argc, char **argv) | |||
279 | (!strstr (m->mnt_type, "swap")) && | 319 | (!strstr (m->mnt_type, "swap")) && |
280 | (!strstr (m->mnt_type, "nfs"))) | 320 | (!strstr (m->mnt_type, "nfs"))) |
281 | { | 321 | { |
282 | newFlags = flags; | 322 | flags = 0; |
283 | *string_flags = '\0'; | 323 | *string_flags = '\0'; |
284 | parse_mount_options(m->mnt_opts, &newFlags, string_flags); | 324 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
285 | mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, newFlags, string_flags); | 325 | mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, |
326 | flags, string_flags, useMtab, fakeIt); | ||
286 | } | 327 | } |
287 | } | 328 | } |
288 | endmntent (f); | 329 | endmntent (f); |
289 | } else { | 330 | } else { |
290 | if (device && directory) { | 331 | if (device && directory) { |
291 | exit (mount_one (device, directory, filesystemType, | 332 | exit (mount_one (device, directory, filesystemType, |
292 | flags, string_flags)); | 333 | flags, string_flags, useMtab, fakeIt)); |
293 | } else { | 334 | } else { |
294 | fprintf (stderr, "%s\n", mount_usage); | 335 | fprintf (stderr, "%s\n", mount_usage); |
295 | exit( FALSE); | 336 | exit( FALSE); |