diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-09 04:16:43 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-09 04:16:43 +0000 |
commit | e132f4b09e5c9aedaef97f65279e8702633fd425 (patch) | |
tree | 50bfe1c027ff760e426ae31442da73e536dd4baa /util-linux | |
parent | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (diff) | |
download | busybox-w32-e132f4b09e5c9aedaef97f65279e8702633fd425.tar.gz busybox-w32-e132f4b09e5c9aedaef97f65279e8702633fd425.tar.bz2 busybox-w32-e132f4b09e5c9aedaef97f65279e8702633fd425.zip |
Fixed the init problem where it wouldn't unmount filesystems
on reboot. Also fixed swapoff -a so it works.
-Erik
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/mount.c | 54 | ||||
-rw-r--r-- | util-linux/swaponoff.c | 23 | ||||
-rw-r--r-- | util-linux/umount.c | 192 |
3 files changed, 135 insertions, 134 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index c3e3bbd75..37f789d3c 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -53,7 +53,7 @@ | |||
53 | #include <linux/loop.h> | 53 | #include <linux/loop.h> |
54 | 54 | ||
55 | 55 | ||
56 | static int use_loop = 0; | 56 | static int use_loop = FALSE; |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | extern const char mtab_file[]; /* Defined in utility.c */ | 59 | extern const char mtab_file[]; /* Defined in utility.c */ |
@@ -114,13 +114,14 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
114 | char *mtab_opts) | 114 | char *mtab_opts) |
115 | { | 115 | { |
116 | int status = 0; | 116 | int status = 0; |
117 | char *lofile = NULL; | ||
117 | 118 | ||
118 | #if defined BB_MTAB | 119 | #if defined BB_MTAB |
119 | if (fakeIt == FALSE) | 120 | if (fakeIt == FALSE) |
120 | #endif | 121 | #endif |
121 | { | 122 | { |
122 | #if defined BB_FEATURE_MOUNT_LOOP | 123 | #if defined BB_FEATURE_MOUNT_LOOP |
123 | if (use_loop) { | 124 | if (use_loop==TRUE) { |
124 | int loro = flags & MS_RDONLY; | 125 | int loro = flags & MS_RDONLY; |
125 | char *lofile = specialfile; | 126 | char *lofile = specialfile; |
126 | 127 | ||
@@ -137,6 +138,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
137 | fprintf(stderr, "WARNING: loop device is read-only\n"); | 138 | fprintf(stderr, "WARNING: loop device is read-only\n"); |
138 | flags &= ~MS_RDONLY; | 139 | flags &= ~MS_RDONLY; |
139 | } | 140 | } |
141 | use_loop = FALSE; | ||
140 | } | 142 | } |
141 | #endif | 143 | #endif |
142 | status = | 144 | status = |
@@ -157,7 +159,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
157 | 159 | ||
158 | /* Bummer. mount failed. Clean up */ | 160 | /* Bummer. mount failed. Clean up */ |
159 | #if defined BB_FEATURE_MOUNT_LOOP | 161 | #if defined BB_FEATURE_MOUNT_LOOP |
160 | if (specialfile != NULL) { | 162 | if (lofile != NULL) { |
161 | del_loop(specialfile); | 163 | del_loop(specialfile); |
162 | } | 164 | } |
163 | #endif | 165 | #endif |
@@ -166,20 +168,6 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
166 | 168 | ||
167 | 169 | ||
168 | 170 | ||
169 | #if defined BB_MTAB | ||
170 | #define whine_if_fstab_is_missing() {} | ||
171 | #else | ||
172 | extern void whine_if_fstab_is_missing() | ||
173 | { | ||
174 | struct stat statBuf; | ||
175 | |||
176 | if (stat("/etc/fstab", &statBuf) < 0) | ||
177 | fprintf(stderr, | ||
178 | "/etc/fstab file missing -- install one to name /dev/root.\n\n"); | ||
179 | } | ||
180 | #endif | ||
181 | |||
182 | |||
183 | /* Seperate standard mount options from the nonstandard string options */ | 171 | /* Seperate standard mount options from the nonstandard string options */ |
184 | static void | 172 | static void |
185 | parse_mount_options(char *options, unsigned long *flags, char *strflags) | 173 | parse_mount_options(char *options, unsigned long *flags, char *strflags) |
@@ -204,7 +192,7 @@ parse_mount_options(char *options, unsigned long *flags, char *strflags) | |||
204 | } | 192 | } |
205 | #if defined BB_FEATURE_MOUNT_LOOP | 193 | #if defined BB_FEATURE_MOUNT_LOOP |
206 | if (gotone == FALSE && !strcasecmp("loop", options)) { /* loop device support */ | 194 | if (gotone == FALSE && !strcasecmp("loop", options)) { /* loop device support */ |
207 | use_loop = 1; | 195 | use_loop = TRUE; |
208 | gotone = TRUE; | 196 | gotone = TRUE; |
209 | } | 197 | } |
210 | #endif | 198 | #endif |
@@ -229,7 +217,7 @@ parse_mount_options(char *options, unsigned long *flags, char *strflags) | |||
229 | int | 217 | int |
230 | mount_one(char *blockDevice, char *directory, char *filesystemType, | 218 | mount_one(char *blockDevice, char *directory, char *filesystemType, |
231 | unsigned long flags, char *string_flags, int useMtab, int fakeIt, | 219 | unsigned long flags, char *string_flags, int useMtab, int fakeIt, |
232 | char *mtab_opts) | 220 | char *mtab_opts, int whineOnErrors) |
233 | { | 221 | { |
234 | int status = 0; | 222 | int status = 0; |
235 | 223 | ||
@@ -270,9 +258,11 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
270 | fakeIt, mtab_opts); | 258 | fakeIt, mtab_opts); |
271 | } | 259 | } |
272 | 260 | ||
273 | if (status == FALSE) { | 261 | if (status == FALSE && whineOnErrors == TRUE) { |
274 | fprintf(stderr, "Mounting %s on %s failed: %s\n", | 262 | if (whineOnErrors == TRUE) { |
275 | blockDevice, directory, strerror(errno)); | 263 | fprintf(stderr, "Mounting %s on %s failed: %s\n", |
264 | blockDevice, directory, strerror(errno)); | ||
265 | } | ||
276 | return (FALSE); | 266 | return (FALSE); |
277 | } | 267 | } |
278 | return (TRUE); | 268 | return (TRUE); |
@@ -387,18 +377,28 @@ extern int mount_main(int argc, char **argv) | |||
387 | exit(FALSE); | 377 | exit(FALSE); |
388 | } | 378 | } |
389 | while ((m = getmntent(f)) != NULL) { | 379 | while ((m = getmntent(f)) != NULL) { |
390 | // If the file system isn't noauto, and isn't mounted on /, | 380 | // If the file system isn't noauto, |
391 | // and isn't swap or nfs, then mount it | 381 | // and isn't swap or nfs, then mount it |
392 | if ((!strstr(m->mnt_opts, "noauto")) && | 382 | if ((!strstr(m->mnt_opts, "noauto")) && |
393 | (m->mnt_dir[1] != '\0') && | ||
394 | (!strstr(m->mnt_type, "swap")) && | 383 | (!strstr(m->mnt_type, "swap")) && |
395 | (!strstr(m->mnt_type, "nfs"))) { | 384 | (!strstr(m->mnt_type, "nfs"))) { |
396 | flags = 0; | 385 | flags = 0; |
397 | *string_flags = '\0'; | 386 | *string_flags = '\0'; |
398 | parse_mount_options(m->mnt_opts, &flags, string_flags); | 387 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
399 | mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | 388 | /* If the directory is /, try to remount |
389 | * with the options specified in fstab */ | ||
390 | if (m->mnt_dir[0] == '/' && m->mnt_dir[1] == '\0') { | ||
391 | flags |= MS_REMOUNT; | ||
392 | } | ||
393 | if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
400 | flags, string_flags, useMtab, fakeIt, | 394 | flags, string_flags, useMtab, fakeIt, |
401 | extra_opts); | 395 | extra_opts, FALSE)) |
396 | { | ||
397 | /* Try again, but this time try a remount */ | ||
398 | mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
399 | flags|MS_REMOUNT, string_flags, useMtab, fakeIt, | ||
400 | extra_opts, TRUE); | ||
401 | } | ||
402 | } | 402 | } |
403 | } | 403 | } |
404 | endmntent(f); | 404 | endmntent(f); |
@@ -414,7 +414,7 @@ extern int mount_main(int argc, char **argv) | |||
414 | #endif | 414 | #endif |
415 | exit(mount_one(device, directory, filesystemType, | 415 | exit(mount_one(device, directory, filesystemType, |
416 | flags, string_flags, useMtab, fakeIt, | 416 | flags, string_flags, useMtab, fakeIt, |
417 | extra_opts)); | 417 | extra_opts, TRUE)); |
418 | } else { | 418 | } else { |
419 | goto goodbye; | 419 | goto goodbye; |
420 | } | 420 | } |
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 6bda22277..bc096ea95 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
@@ -36,13 +36,16 @@ static int whichApp; | |||
36 | static const char *appName; | 36 | static const char *appName; |
37 | 37 | ||
38 | static const char swapoff_usage[] = | 38 | static const char swapoff_usage[] = |
39 | "swapoff [OPTION] [device]\n\n" | ||
40 | "Stop swapping virtual memory pages on the given device.\n\n" | ||
41 | "Options:\n" | ||
42 | "\t-a\tStop swapping on all swap devices\n"; | ||
39 | 43 | ||
40 | "swapoff device\n" | ||
41 | "\nStop swapping virtual memory pages on the given device.\n"; | ||
42 | static const char swapon_usage[] = | 44 | static const char swapon_usage[] = |
43 | 45 | "swapon [OPTION] [device]\n\n" | |
44 | "swapon device\n" | 46 | "Start swapping virtual memory pages on the given device.\n\n" |
45 | "\nStart swapping virtual memory pages on the given device.\n"; | 47 | "Options:\n" |
48 | "\t-a\tStart swapping on all swap devices\n"; | ||
46 | 49 | ||
47 | 50 | ||
48 | #define SWAPON_APP 1 | 51 | #define SWAPON_APP 1 |
@@ -85,12 +88,6 @@ static void do_em_all() | |||
85 | 88 | ||
86 | extern int swap_on_off_main(int argc, char **argv) | 89 | extern int swap_on_off_main(int argc, char **argv) |
87 | { | 90 | { |
88 | struct stat statBuf; | ||
89 | |||
90 | if (stat("/etc/fstab", &statBuf) < 0) | ||
91 | fprintf(stderr, | ||
92 | "/etc/fstab file missing -- Please install one.\n\n"); | ||
93 | |||
94 | if (strcmp(*argv, "swapon") == 0) { | 91 | if (strcmp(*argv, "swapon") == 0) { |
95 | appName = *argv; | 92 | appName = *argv; |
96 | whichApp = SWAPON_APP; | 93 | whichApp = SWAPON_APP; |
@@ -100,8 +97,9 @@ extern int swap_on_off_main(int argc, char **argv) | |||
100 | whichApp = SWAPOFF_APP; | 97 | whichApp = SWAPOFF_APP; |
101 | } | 98 | } |
102 | 99 | ||
103 | if (argc < 2) | 100 | if (argc != 2) { |
104 | goto usage_and_exit; | 101 | goto usage_and_exit; |
102 | } | ||
105 | argc--; | 103 | argc--; |
106 | argv++; | 104 | argv++; |
107 | 105 | ||
@@ -110,6 +108,7 @@ extern int swap_on_off_main(int argc, char **argv) | |||
110 | while (*++(*argv)) | 108 | while (*++(*argv)) |
111 | switch (**argv) { | 109 | switch (**argv) { |
112 | case 'a': | 110 | case 'a': |
111 | whine_if_fstab_is_missing(); | ||
113 | do_em_all(); | 112 | do_em_all(); |
114 | break; | 113 | break; |
115 | default: | 114 | default: |
diff --git a/util-linux/umount.c b/util-linux/umount.c index a2ca8c74a..b58b1a08c 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <fstab.h> | 29 | #include <fstab.h> |
30 | #include <errno.h> | 30 | #include <errno.h> |
31 | 31 | ||
32 | |||
32 | static const char umount_usage[] = | 33 | static const char umount_usage[] = |
33 | "umount [flags] filesystem|directory\n\n" | 34 | "umount [flags] filesystem|directory\n\n" |
34 | "Flags:\n" "\t-a:\tUnmount all file systems" | 35 | "Flags:\n" "\t-a:\tUnmount all file systems" |
@@ -57,7 +58,99 @@ static int umountAll = FALSE; | |||
57 | static int doRemount = FALSE; | 58 | static int doRemount = FALSE; |
58 | extern const char mtab_file[]; /* Defined in utility.c */ | 59 | extern const char mtab_file[]; /* Defined in utility.c */ |
59 | 60 | ||
60 | #define MIN(x,y) (x > y ? x : y) | 61 | |
62 | /* These functions are here because the getmntent functions do not appear | ||
63 | * to be re-entrant, which leads to all sorts of problems when we try to | ||
64 | * use them recursively - randolph | ||
65 | */ | ||
66 | void mtab_read(void) | ||
67 | { | ||
68 | struct _mtab_entry_t *entry = NULL; | ||
69 | struct mntent *e; | ||
70 | FILE *fp; | ||
71 | |||
72 | if (mtab_cache != NULL) | ||
73 | return; | ||
74 | |||
75 | if ((fp = setmntent(mtab_file, "r")) == NULL) { | ||
76 | fprintf(stderr, "Cannot open %s\n", mtab_file); | ||
77 | return; | ||
78 | } | ||
79 | while ((e = getmntent(fp))) { | ||
80 | entry = malloc(sizeof(struct _mtab_entry_t)); | ||
81 | |||
82 | entry->device = strdup(e->mnt_fsname); | ||
83 | entry->mountpt = strdup(e->mnt_dir); | ||
84 | entry->next = mtab_cache; | ||
85 | mtab_cache = entry; | ||
86 | } | ||
87 | endmntent(fp); | ||
88 | } | ||
89 | |||
90 | char *mtab_getinfo(const char *match, const char which) | ||
91 | { | ||
92 | struct _mtab_entry_t *cur = mtab_cache; | ||
93 | |||
94 | while (cur) { | ||
95 | if (strcmp(cur->mountpt, match) == 0 || | ||
96 | strcmp(cur->device, match) == 0) { | ||
97 | if (which == MTAB_GETMOUNTPT) { | ||
98 | return cur->mountpt; | ||
99 | } else { | ||
100 | #if !defined BB_MTAB | ||
101 | if (strcmp(cur->device, "/dev/root") == 0) { | ||
102 | struct fstab *fstabItem; | ||
103 | |||
104 | fstabItem = getfsfile("/"); | ||
105 | if (fstabItem != NULL) | ||
106 | return fstabItem->fs_spec; | ||
107 | } | ||
108 | #endif | ||
109 | return cur->device; | ||
110 | } | ||
111 | } | ||
112 | cur = cur->next; | ||
113 | } | ||
114 | return NULL; | ||
115 | } | ||
116 | |||
117 | char *mtab_first(void **iter) | ||
118 | { | ||
119 | struct _mtab_entry_t *mtab_iter; | ||
120 | |||
121 | if (!iter) | ||
122 | return NULL; | ||
123 | mtab_iter = mtab_cache; | ||
124 | *iter = (void *) mtab_iter; | ||
125 | return mtab_next(iter); | ||
126 | } | ||
127 | |||
128 | char *mtab_next(void **iter) | ||
129 | { | ||
130 | char *mp; | ||
131 | |||
132 | if (iter == NULL || *iter == NULL) | ||
133 | return NULL; | ||
134 | mp = ((struct _mtab_entry_t *) (*iter))->mountpt; | ||
135 | *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next; | ||
136 | return mp; | ||
137 | } | ||
138 | |||
139 | void mtab_free(void) | ||
140 | { | ||
141 | struct _mtab_entry_t *this, *next; | ||
142 | |||
143 | this = mtab_cache; | ||
144 | while (this) { | ||
145 | next = this->next; | ||
146 | if (this->device) | ||
147 | free(this->device); | ||
148 | if (this->mountpt) | ||
149 | free(this->mountpt); | ||
150 | free(this); | ||
151 | this = next; | ||
152 | } | ||
153 | } | ||
61 | 154 | ||
62 | static int do_umount(const char *name, int useMtab) | 155 | static int do_umount(const char *name, int useMtab) |
63 | { | 156 | { |
@@ -105,6 +198,9 @@ static int umount_all(int useMtab) | |||
105 | void *iter; | 198 | void *iter; |
106 | 199 | ||
107 | for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) { | 200 | for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) { |
201 | /* Never umount /proc on a umount -a */ | ||
202 | if (strstr(mountpt, "proc")!= NULL) | ||
203 | continue; | ||
108 | status = do_umount(mountpt, useMtab); | 204 | status = do_umount(mountpt, useMtab); |
109 | if (status != 0) { | 205 | if (status != 0) { |
110 | /* Don't bother retrying the umount on busy devices */ | 206 | /* Don't bother retrying the umount on busy devices */ |
@@ -163,97 +259,3 @@ extern int umount_main(int argc, char **argv) | |||
163 | } | 259 | } |
164 | } | 260 | } |
165 | 261 | ||
166 | |||
167 | |||
168 | /* These functions are here because the getmntent functions do not appear | ||
169 | * to be re-entrant, which leads to all sorts of problems when we try to | ||
170 | * use them recursively - randolph | ||
171 | */ | ||
172 | void mtab_read(void) | ||
173 | { | ||
174 | struct _mtab_entry_t *entry = NULL; | ||
175 | struct mntent *e; | ||
176 | FILE *fp; | ||
177 | |||
178 | if (mtab_cache != NULL) | ||
179 | return; | ||
180 | |||
181 | if ((fp = setmntent(mtab_file, "r")) == NULL) { | ||
182 | fprintf(stderr, "Cannot open %s\n", mtab_file); | ||
183 | return; | ||
184 | } | ||
185 | while ((e = getmntent(fp))) { | ||
186 | entry = malloc(sizeof(struct _mtab_entry_t)); | ||
187 | |||
188 | entry->device = strdup(e->mnt_fsname); | ||
189 | entry->mountpt = strdup(e->mnt_dir); | ||
190 | entry->next = mtab_cache; | ||
191 | mtab_cache = entry; | ||
192 | } | ||
193 | endmntent(fp); | ||
194 | } | ||
195 | |||
196 | char *mtab_getinfo(const char *match, const char which) | ||
197 | { | ||
198 | struct _mtab_entry_t *cur = mtab_cache; | ||
199 | |||
200 | while (cur) { | ||
201 | if (strcmp(cur->mountpt, match) == 0 || | ||
202 | strcmp(cur->device, match) == 0) { | ||
203 | if (which == MTAB_GETMOUNTPT) { | ||
204 | return cur->mountpt; | ||
205 | } else { | ||
206 | #if !defined BB_MTAB | ||
207 | if (strcmp(cur->device, "/dev/root") == 0) { | ||
208 | struct fstab *fstabItem; | ||
209 | |||
210 | fstabItem = getfsfile("/"); | ||
211 | if (fstabItem != NULL) | ||
212 | return fstabItem->fs_spec; | ||
213 | } | ||
214 | #endif | ||
215 | return cur->device; | ||
216 | } | ||
217 | } | ||
218 | cur = cur->next; | ||
219 | } | ||
220 | return NULL; | ||
221 | } | ||
222 | |||
223 | char *mtab_first(void **iter) | ||
224 | { | ||
225 | struct _mtab_entry_t *mtab_iter; | ||
226 | |||
227 | if (!iter) | ||
228 | return NULL; | ||
229 | mtab_iter = mtab_cache; | ||
230 | *iter = (void *) mtab_iter; | ||
231 | return mtab_next(iter); | ||
232 | } | ||
233 | |||
234 | char *mtab_next(void **iter) | ||
235 | { | ||
236 | char *mp; | ||
237 | |||
238 | if (iter == NULL || *iter == NULL) | ||
239 | return NULL; | ||
240 | mp = ((struct _mtab_entry_t *) (*iter))->mountpt; | ||
241 | *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next; | ||
242 | return mp; | ||
243 | } | ||
244 | |||
245 | void mtab_free(void) | ||
246 | { | ||
247 | struct _mtab_entry_t *this, *next; | ||
248 | |||
249 | this = mtab_cache; | ||
250 | while (this) { | ||
251 | next = this->next; | ||
252 | if (this->device) | ||
253 | free(this->device); | ||
254 | if (this->mountpt) | ||
255 | free(this->mountpt); | ||
256 | free(this); | ||
257 | this = next; | ||
258 | } | ||
259 | } | ||