diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-11-04 21:18:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-11-04 21:18:07 +0000 |
commit | d0246fb72b40320a74376af1bb944fef2c9b734f (patch) | |
tree | 9fa93d2acf052107f2b682ce2e77725eb7ec9d84 | |
parent | 3ae0c789627a29dbd76793eb666efe19144b30f0 (diff) | |
download | busybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.tar.gz busybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.tar.bz2 busybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.zip |
More stuff.
-rw-r--r-- | Changelog | 11 | ||||
-rw-r--r-- | busybox.def.h | 1 | ||||
-rw-r--r-- | coreutils/df.c | 7 | ||||
-rw-r--r-- | df.c | 7 | ||||
-rw-r--r-- | internal.h | 5 | ||||
-rw-r--r-- | mount.c | 71 | ||||
-rw-r--r-- | umount.c | 68 | ||||
-rw-r--r-- | util-linux/mount.c | 71 | ||||
-rw-r--r-- | util-linux/umount.c | 68 | ||||
-rw-r--r-- | utility.c | 9 |
10 files changed, 247 insertions, 71 deletions
@@ -4,12 +4,15 @@ | |||
4 | * Fixed mkdir -m option so that it works. | 4 | * Fixed mkdir -m option so that it works. |
5 | * kill segfaulted w/o any arguments. Now it doesn't do that. | 5 | * kill segfaulted w/o any arguments. Now it doesn't do that. |
6 | * kill wasn't properly accepting signal names. It does now. | 6 | * kill wasn't properly accepting signal names. It does now. |
7 | * Added new apps chvt and deallocvt | 7 | * Added new apps chvt and deallocvt (I should probably add open) |
8 | * Major adjustment of init.c. Code is now readable IMHO, | 8 | * Major rewrite of init.c. Code is now readable by mere mortals IMHO. |
9 | and much more solid. | ||
10 | * Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!). | 9 | * Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!). |
11 | * Fixed a stupid seg-fault in sync | 10 | * Fixed a stupid seg-fault in sync |
12 | * Fixed mount -- mount -a always mounted rw despite /etc/fstab ro entries. | 11 | * Fixed mount -- mount -a failed to parse and apply mount options |
12 | * Added BB_MTAB, allowing (at the cost of ~1.5k and the need for a rw /etc) | ||
13 | folks to use a real /etc/mtab file instead of a symlink to /proc/mounts. | ||
14 | mount, and umount will add/remove entries and df will now use /etc/mtab | ||
15 | if BB_MTAB is defined. | ||
13 | 16 | ||
14 | -Erik Andersen | 17 | -Erik Andersen |
15 | 18 | ||
diff --git a/busybox.def.h b/busybox.def.h index 0440b9f2b..880046318 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
@@ -38,6 +38,7 @@ | |||
38 | #define BB_MORE | 38 | #define BB_MORE |
39 | #define BB_MOUNT | 39 | #define BB_MOUNT |
40 | //#define BB_MT | 40 | //#define BB_MT |
41 | #define BB_MTAB | ||
41 | #define BB_MV | 42 | #define BB_MV |
42 | //#define BB_PRINTF | 43 | //#define BB_PRINTF |
43 | #define BB_PS | 44 | #define BB_PS |
diff --git a/coreutils/df.c b/coreutils/df.c index f8a953f7d..94b6b8231 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -31,6 +31,7 @@ | |||
31 | static const char df_usage[] = "df [filesystem ...]\n" | 31 | static const char df_usage[] = "df [filesystem ...]\n" |
32 | "\n" "\tPrint the filesystem space used and space available.\n"; | 32 | "\n" "\tPrint the filesystem space used and space available.\n"; |
33 | 33 | ||
34 | extern const char mtab_file[]; /* Defined in utility.c */ | ||
34 | 35 | ||
35 | static int df(char *device, const char *mountPoint) | 36 | static int df(char *device, const char *mountPoint) |
36 | { | 37 | { |
@@ -113,7 +114,7 @@ extern int df_main(int argc, char **argv) | |||
113 | int status; | 114 | int status; |
114 | 115 | ||
115 | while (argc > 1) { | 116 | while (argc > 1) { |
116 | if ((mountEntry = findMountPoint(argv[1], "/proc/mounts")) == | 117 | if ((mountEntry = findMountPoint(argv[1], mtab_file)) == |
117 | 0) { | 118 | 0) { |
118 | fprintf(stderr, "%s: can't find mount point.\n", argv[1]); | 119 | fprintf(stderr, "%s: can't find mount point.\n", argv[1]); |
119 | return 1; | 120 | return 1; |
@@ -129,9 +130,9 @@ extern int df_main(int argc, char **argv) | |||
129 | FILE *mountTable; | 130 | FILE *mountTable; |
130 | struct mntent *mountEntry; | 131 | struct mntent *mountEntry; |
131 | 132 | ||
132 | mountTable = setmntent("/proc/mounts", "r"); | 133 | mountTable = setmntent(mtab_file, "r"); |
133 | if (mountTable == 0) { | 134 | if (mountTable == 0) { |
134 | perror("/proc/mounts"); | 135 | perror(mtab_file); |
135 | exit(FALSE); | 136 | exit(FALSE); |
136 | } | 137 | } |
137 | 138 | ||
@@ -31,6 +31,7 @@ | |||
31 | static const char df_usage[] = "df [filesystem ...]\n" | 31 | static const char df_usage[] = "df [filesystem ...]\n" |
32 | "\n" "\tPrint the filesystem space used and space available.\n"; | 32 | "\n" "\tPrint the filesystem space used and space available.\n"; |
33 | 33 | ||
34 | extern const char mtab_file[]; /* Defined in utility.c */ | ||
34 | 35 | ||
35 | static int df(char *device, const char *mountPoint) | 36 | static int df(char *device, const char *mountPoint) |
36 | { | 37 | { |
@@ -113,7 +114,7 @@ extern int df_main(int argc, char **argv) | |||
113 | int status; | 114 | int status; |
114 | 115 | ||
115 | while (argc > 1) { | 116 | while (argc > 1) { |
116 | if ((mountEntry = findMountPoint(argv[1], "/proc/mounts")) == | 117 | if ((mountEntry = findMountPoint(argv[1], mtab_file)) == |
117 | 0) { | 118 | 0) { |
118 | fprintf(stderr, "%s: can't find mount point.\n", argv[1]); | 119 | fprintf(stderr, "%s: can't find mount point.\n", argv[1]); |
119 | return 1; | 120 | return 1; |
@@ -129,9 +130,9 @@ extern int df_main(int argc, char **argv) | |||
129 | FILE *mountTable; | 130 | FILE *mountTable; |
130 | struct mntent *mountEntry; | 131 | struct mntent *mountEntry; |
131 | 132 | ||
132 | mountTable = setmntent("/proc/mounts", "r"); | 133 | mountTable = setmntent(mtab_file, "r"); |
133 | if (mountTable == 0) { | 134 | if (mountTable == 0) { |
134 | perror("/proc/mounts"); | 135 | perror(mtab_file); |
135 | exit(FALSE); | 136 | exit(FALSE); |
136 | } | 137 | } |
137 | 138 | ||
diff --git a/internal.h b/internal.h index 81271be94..c66c9f116 100644 --- a/internal.h +++ b/internal.h | |||
@@ -47,7 +47,6 @@ | |||
47 | #define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '[')) | 47 | #define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '[')) |
48 | 48 | ||
49 | 49 | ||
50 | |||
51 | struct Applet { | 50 | struct Applet { |
52 | const char* name; | 51 | const char* name; |
53 | int (*main)(int argc, char** argv); | 52 | int (*main)(int argc, char** argv); |
@@ -147,6 +146,10 @@ extern void my_getgrgid(char* group, gid_t gid); | |||
147 | extern int get_kernel_revision(); | 146 | extern int get_kernel_revision(); |
148 | extern int get_console_fd(char* tty_name); | 147 | extern int get_console_fd(char* tty_name); |
149 | 148 | ||
149 | extern void write_mtab(char* blockDevice, char* directory, | ||
150 | char* filesystemType, long flags, char* string_flags); | ||
151 | extern void erase_mtab(const char * name); | ||
152 | |||
150 | 153 | ||
151 | #if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX) | 154 | #if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX) |
152 | 155 | ||
@@ -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); |
@@ -29,24 +29,54 @@ | |||
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | 30 | ||
31 | static const char umount_usage[] = | 31 | static const char umount_usage[] = |
32 | "Usage: umount filesystem\n" | 32 | "Usage: umount [flags] filesystem|directory\n" |
33 | " or: umount directory\n" | 33 | "Optional Flags:\n" |
34 | " or: umount -a" | 34 | "\t-a:\tUnmount all file systems" |
35 | "to unmount all mounted file systems.\n"; | 35 | #ifdef BB_MTAB |
36 | " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n" | ||
37 | #else | ||
38 | "\n" | ||
39 | #endif | ||
40 | ; | ||
41 | |||
42 | |||
43 | static int useMtab = TRUE; | ||
44 | static int umountAll = FALSE; | ||
45 | extern const char mtab_file[]; /* Defined in utility.c */ | ||
46 | |||
47 | #if ! defined BB_MTAB | ||
48 | #define do_umount( blockDevice, useMtab) umount( blockDevice) | ||
49 | #else | ||
50 | static int | ||
51 | do_umount(const char* name, int useMtab) | ||
52 | { | ||
53 | int status = umount(name); | ||
54 | |||
55 | if ( status == 0 ) { | ||
56 | if ( useMtab==TRUE ) | ||
57 | erase_mtab(name); | ||
58 | return 0; | ||
59 | } | ||
60 | else | ||
61 | return( status); | ||
62 | } | ||
63 | #endif | ||
36 | 64 | ||
37 | static int | 65 | static int |
38 | umount_all() | 66 | umount_all(int useMtab) |
39 | { | 67 | { |
40 | int status; | 68 | int status; |
41 | struct mntent *m; | 69 | struct mntent *m; |
42 | FILE *mountTable; | 70 | FILE *mountTable; |
43 | 71 | ||
44 | if ((mountTable = setmntent ("/proc/mounts", "r"))) { | 72 | if ((mountTable = setmntent (mtab_file, "r"))) { |
45 | while ((m = getmntent (mountTable)) != 0) { | 73 | while ((m = getmntent (mountTable)) != 0) { |
46 | char *blockDevice = m->mnt_fsname; | 74 | char *blockDevice = m->mnt_fsname; |
75 | #if ! defined BB_MTAB | ||
47 | if (strcmp (blockDevice, "/dev/root") == 0) | 76 | if (strcmp (blockDevice, "/dev/root") == 0) |
48 | blockDevice = (getfsfile ("/"))->fs_spec; | 77 | blockDevice = (getfsfile ("/"))->fs_spec; |
49 | status=umount (m->mnt_dir); | 78 | #endif |
79 | status=do_umount (m->mnt_dir, useMtab); | ||
50 | if (status!=0) { | 80 | if (status!=0) { |
51 | /* Don't bother retrying the umount on busy devices */ | 81 | /* Don't bother retrying the umount on busy devices */ |
52 | if (errno==EBUSY) { | 82 | if (errno==EBUSY) { |
@@ -56,7 +86,7 @@ umount_all() | |||
56 | printf ("Trying to umount %s failed: %s\n", | 86 | printf ("Trying to umount %s failed: %s\n", |
57 | m->mnt_dir, strerror(errno)); | 87 | m->mnt_dir, strerror(errno)); |
58 | printf ("Instead trying to umount %s\n", blockDevice); | 88 | printf ("Instead trying to umount %s\n", blockDevice); |
59 | status=umount (blockDevice); | 89 | status=do_umount (blockDevice, useMtab); |
60 | if (status!=0) { | 90 | if (status!=0) { |
61 | printf ("Couldn't umount %s on %s (type %s): %s\n", | 91 | printf ("Couldn't umount %s on %s (type %s): %s\n", |
62 | blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); | 92 | blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); |
@@ -69,27 +99,35 @@ umount_all() | |||
69 | } | 99 | } |
70 | 100 | ||
71 | extern int | 101 | extern int |
72 | umount_main(int argc, char * * argv) | 102 | umount_main(int argc, char** argv) |
73 | { | 103 | { |
74 | 104 | ||
75 | if (argc < 2) { | 105 | if (argc < 2) { |
76 | usage( umount_usage); | 106 | usage( umount_usage); |
77 | } | 107 | } |
78 | argc--; | ||
79 | argv++; | ||
80 | 108 | ||
81 | /* Parse any options */ | 109 | /* Parse any options */ |
82 | while (**argv == '-') { | 110 | while (argc-- > 0 && **(++argv) == '-') { |
83 | while (*++(*argv)) switch (**argv) { | 111 | while (*++(*argv)) switch (**argv) { |
84 | case 'a': | 112 | case 'a': |
85 | exit ( umount_all() ); | 113 | umountAll = TRUE; |
114 | break; | ||
115 | #ifdef BB_MTAB | ||
116 | case 'n': | ||
117 | useMtab = FALSE; | ||
86 | break; | 118 | break; |
119 | #endif | ||
87 | default: | 120 | default: |
88 | usage( umount_usage); | 121 | usage( umount_usage); |
89 | } | 122 | } |
90 | } | 123 | } |
91 | if ( umount(*argv) == 0 ) | 124 | |
92 | exit (TRUE); | 125 | |
126 | if(umountAll) { | ||
127 | exit(umount_all(useMtab)); | ||
128 | } | ||
129 | if ( do_umount(*argv,useMtab) == 0 ) | ||
130 | exit (TRUE); | ||
93 | else { | 131 | else { |
94 | perror("umount"); | 132 | perror("umount"); |
95 | exit( FALSE); | 133 | exit( FALSE); |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 1efbdf407..8b5efe14f 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -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); |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 95f7dfb3c..e749c5f0f 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -29,24 +29,54 @@ | |||
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | 30 | ||
31 | static const char umount_usage[] = | 31 | static const char umount_usage[] = |
32 | "Usage: umount filesystem\n" | 32 | "Usage: umount [flags] filesystem|directory\n" |
33 | " or: umount directory\n" | 33 | "Optional Flags:\n" |
34 | " or: umount -a" | 34 | "\t-a:\tUnmount all file systems" |
35 | "to unmount all mounted file systems.\n"; | 35 | #ifdef BB_MTAB |
36 | " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n" | ||
37 | #else | ||
38 | "\n" | ||
39 | #endif | ||
40 | ; | ||
41 | |||
42 | |||
43 | static int useMtab = TRUE; | ||
44 | static int umountAll = FALSE; | ||
45 | extern const char mtab_file[]; /* Defined in utility.c */ | ||
46 | |||
47 | #if ! defined BB_MTAB | ||
48 | #define do_umount( blockDevice, useMtab) umount( blockDevice) | ||
49 | #else | ||
50 | static int | ||
51 | do_umount(const char* name, int useMtab) | ||
52 | { | ||
53 | int status = umount(name); | ||
54 | |||
55 | if ( status == 0 ) { | ||
56 | if ( useMtab==TRUE ) | ||
57 | erase_mtab(name); | ||
58 | return 0; | ||
59 | } | ||
60 | else | ||
61 | return( status); | ||
62 | } | ||
63 | #endif | ||
36 | 64 | ||
37 | static int | 65 | static int |
38 | umount_all() | 66 | umount_all(int useMtab) |
39 | { | 67 | { |
40 | int status; | 68 | int status; |
41 | struct mntent *m; | 69 | struct mntent *m; |
42 | FILE *mountTable; | 70 | FILE *mountTable; |
43 | 71 | ||
44 | if ((mountTable = setmntent ("/proc/mounts", "r"))) { | 72 | if ((mountTable = setmntent (mtab_file, "r"))) { |
45 | while ((m = getmntent (mountTable)) != 0) { | 73 | while ((m = getmntent (mountTable)) != 0) { |
46 | char *blockDevice = m->mnt_fsname; | 74 | char *blockDevice = m->mnt_fsname; |
75 | #if ! defined BB_MTAB | ||
47 | if (strcmp (blockDevice, "/dev/root") == 0) | 76 | if (strcmp (blockDevice, "/dev/root") == 0) |
48 | blockDevice = (getfsfile ("/"))->fs_spec; | 77 | blockDevice = (getfsfile ("/"))->fs_spec; |
49 | status=umount (m->mnt_dir); | 78 | #endif |
79 | status=do_umount (m->mnt_dir, useMtab); | ||
50 | if (status!=0) { | 80 | if (status!=0) { |
51 | /* Don't bother retrying the umount on busy devices */ | 81 | /* Don't bother retrying the umount on busy devices */ |
52 | if (errno==EBUSY) { | 82 | if (errno==EBUSY) { |
@@ -56,7 +86,7 @@ umount_all() | |||
56 | printf ("Trying to umount %s failed: %s\n", | 86 | printf ("Trying to umount %s failed: %s\n", |
57 | m->mnt_dir, strerror(errno)); | 87 | m->mnt_dir, strerror(errno)); |
58 | printf ("Instead trying to umount %s\n", blockDevice); | 88 | printf ("Instead trying to umount %s\n", blockDevice); |
59 | status=umount (blockDevice); | 89 | status=do_umount (blockDevice, useMtab); |
60 | if (status!=0) { | 90 | if (status!=0) { |
61 | printf ("Couldn't umount %s on %s (type %s): %s\n", | 91 | printf ("Couldn't umount %s on %s (type %s): %s\n", |
62 | blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); | 92 | blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); |
@@ -69,27 +99,35 @@ umount_all() | |||
69 | } | 99 | } |
70 | 100 | ||
71 | extern int | 101 | extern int |
72 | umount_main(int argc, char * * argv) | 102 | umount_main(int argc, char** argv) |
73 | { | 103 | { |
74 | 104 | ||
75 | if (argc < 2) { | 105 | if (argc < 2) { |
76 | usage( umount_usage); | 106 | usage( umount_usage); |
77 | } | 107 | } |
78 | argc--; | ||
79 | argv++; | ||
80 | 108 | ||
81 | /* Parse any options */ | 109 | /* Parse any options */ |
82 | while (**argv == '-') { | 110 | while (argc-- > 0 && **(++argv) == '-') { |
83 | while (*++(*argv)) switch (**argv) { | 111 | while (*++(*argv)) switch (**argv) { |
84 | case 'a': | 112 | case 'a': |
85 | exit ( umount_all() ); | 113 | umountAll = TRUE; |
114 | break; | ||
115 | #ifdef BB_MTAB | ||
116 | case 'n': | ||
117 | useMtab = FALSE; | ||
86 | break; | 118 | break; |
119 | #endif | ||
87 | default: | 120 | default: |
88 | usage( umount_usage); | 121 | usage( umount_usage); |
89 | } | 122 | } |
90 | } | 123 | } |
91 | if ( umount(*argv) == 0 ) | 124 | |
92 | exit (TRUE); | 125 | |
126 | if(umountAll) { | ||
127 | exit(umount_all(useMtab)); | ||
128 | } | ||
129 | if ( do_umount(*argv,useMtab) == 0 ) | ||
130 | exit (TRUE); | ||
93 | else { | 131 | else { |
94 | perror("umount"); | 132 | perror("umount"); |
95 | exit( FALSE); | 133 | exit( FALSE); |
@@ -36,6 +36,15 @@ | |||
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <ctype.h> | 37 | #include <ctype.h> |
38 | 38 | ||
39 | #ifdef BB_MTAB | ||
40 | const char mtab_file[] = "/etc/mtab"; | ||
41 | #else | ||
42 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF | ||
43 | const char mtab_file[] = "/proc/mounts"; | ||
44 | #endif | ||
45 | #endif | ||
46 | |||
47 | |||
39 | /* volatile so gcc knows this is the enod of the line */ | 48 | /* volatile so gcc knows this is the enod of the line */ |
40 | volatile void usage(const char *usage) | 49 | volatile void usage(const char *usage) |
41 | { | 50 | { |