summaryrefslogtreecommitdiff
path: root/umount.c
diff options
context:
space:
mode:
authorErik Andersen2000-02-09 04:16:43 +0000
committerErik Andersen2000-02-09 04:16:43 +0000
commite132f4b09e5c9aedaef97f65279e8702633fd425 (patch)
tree50bfe1c027ff760e426ae31442da73e536dd4baa /umount.c
parente49d5ecbbe51718fa925b6890a735e5937cc2aa2 (diff)
downloadbusybox-e132f4b09e5c9aedaef97f65279e8702633fd425.zip
busybox-e132f4b09e5c9aedaef97f65279e8702633fd425.tar.gz
Fixed the init problem where it wouldn't unmount filesystems
on reboot. Also fixed swapoff -a so it works. -Erik
Diffstat (limited to 'umount.c')
-rw-r--r--umount.c192
1 files changed, 97 insertions, 95 deletions
diff --git a/umount.c b/umount.c
index a2ca8c7..b58b1a0 100644
--- a/umount.c
+++ b/umount.c
@@ -29,6 +29,7 @@
#include <fstab.h>
#include <errno.h>
+
static const char umount_usage[] =
"umount [flags] filesystem|directory\n\n"
"Flags:\n" "\t-a:\tUnmount all file systems"
@@ -57,7 +58,99 @@ static int umountAll = FALSE;
static int doRemount = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
-#define MIN(x,y) (x > y ? x : y)
+
+/* These functions are here because the getmntent functions do not appear
+ * to be re-entrant, which leads to all sorts of problems when we try to
+ * use them recursively - randolph
+ */
+void mtab_read(void)
+{
+ struct _mtab_entry_t *entry = NULL;
+ struct mntent *e;
+ FILE *fp;
+
+ if (mtab_cache != NULL)
+ return;
+
+ if ((fp = setmntent(mtab_file, "r")) == NULL) {
+ fprintf(stderr, "Cannot open %s\n", mtab_file);
+ return;
+ }
+ while ((e = getmntent(fp))) {
+ entry = malloc(sizeof(struct _mtab_entry_t));
+
+ entry->device = strdup(e->mnt_fsname);
+ entry->mountpt = strdup(e->mnt_dir);
+ entry->next = mtab_cache;
+ mtab_cache = entry;
+ }
+ endmntent(fp);
+}
+
+char *mtab_getinfo(const char *match, const char which)
+{
+ struct _mtab_entry_t *cur = mtab_cache;
+
+ while (cur) {
+ if (strcmp(cur->mountpt, match) == 0 ||
+ strcmp(cur->device, match) == 0) {
+ if (which == MTAB_GETMOUNTPT) {
+ return cur->mountpt;
+ } else {
+#if !defined BB_MTAB
+ if (strcmp(cur->device, "/dev/root") == 0) {
+ struct fstab *fstabItem;
+
+ fstabItem = getfsfile("/");
+ if (fstabItem != NULL)
+ return fstabItem->fs_spec;
+ }
+#endif
+ return cur->device;
+ }
+ }
+ cur = cur->next;
+ }
+ return NULL;
+}
+
+char *mtab_first(void **iter)
+{
+ struct _mtab_entry_t *mtab_iter;
+
+ if (!iter)
+ return NULL;
+ mtab_iter = mtab_cache;
+ *iter = (void *) mtab_iter;
+ return mtab_next(iter);
+}
+
+char *mtab_next(void **iter)
+{
+ char *mp;
+
+ if (iter == NULL || *iter == NULL)
+ return NULL;
+ mp = ((struct _mtab_entry_t *) (*iter))->mountpt;
+ *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next;
+ return mp;
+}
+
+void mtab_free(void)
+{
+ struct _mtab_entry_t *this, *next;
+
+ this = mtab_cache;
+ while (this) {
+ next = this->next;
+ if (this->device)
+ free(this->device);
+ if (this->mountpt)
+ free(this->mountpt);
+ free(this);
+ this = next;
+ }
+}
static int do_umount(const char *name, int useMtab)
{
@@ -105,6 +198,9 @@ static int umount_all(int useMtab)
void *iter;
for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) {
+ /* Never umount /proc on a umount -a */
+ if (strstr(mountpt, "proc")!= NULL)
+ continue;
status = do_umount(mountpt, useMtab);
if (status != 0) {
/* Don't bother retrying the umount on busy devices */
@@ -163,97 +259,3 @@ extern int umount_main(int argc, char **argv)
}
}
-
-
-/* These functions are here because the getmntent functions do not appear
- * to be re-entrant, which leads to all sorts of problems when we try to
- * use them recursively - randolph
- */
-void mtab_read(void)
-{
- struct _mtab_entry_t *entry = NULL;
- struct mntent *e;
- FILE *fp;
-
- if (mtab_cache != NULL)
- return;
-
- if ((fp = setmntent(mtab_file, "r")) == NULL) {
- fprintf(stderr, "Cannot open %s\n", mtab_file);
- return;
- }
- while ((e = getmntent(fp))) {
- entry = malloc(sizeof(struct _mtab_entry_t));
-
- entry->device = strdup(e->mnt_fsname);
- entry->mountpt = strdup(e->mnt_dir);
- entry->next = mtab_cache;
- mtab_cache = entry;
- }
- endmntent(fp);
-}
-
-char *mtab_getinfo(const char *match, const char which)
-{
- struct _mtab_entry_t *cur = mtab_cache;
-
- while (cur) {
- if (strcmp(cur->mountpt, match) == 0 ||
- strcmp(cur->device, match) == 0) {
- if (which == MTAB_GETMOUNTPT) {
- return cur->mountpt;
- } else {
-#if !defined BB_MTAB
- if (strcmp(cur->device, "/dev/root") == 0) {
- struct fstab *fstabItem;
-
- fstabItem = getfsfile("/");
- if (fstabItem != NULL)
- return fstabItem->fs_spec;
- }
-#endif
- return cur->device;
- }
- }
- cur = cur->next;
- }
- return NULL;
-}
-
-char *mtab_first(void **iter)
-{
- struct _mtab_entry_t *mtab_iter;
-
- if (!iter)
- return NULL;
- mtab_iter = mtab_cache;
- *iter = (void *) mtab_iter;
- return mtab_next(iter);
-}
-
-char *mtab_next(void **iter)
-{
- char *mp;
-
- if (iter == NULL || *iter == NULL)
- return NULL;
- mp = ((struct _mtab_entry_t *) (*iter))->mountpt;
- *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next;
- return mp;
-}
-
-void mtab_free(void)
-{
- struct _mtab_entry_t *this, *next;
-
- this = mtab_cache;
- while (this) {
- next = this->next;
- if (this->device)
- free(this->device);
- if (this->mountpt)
- free(this->mountpt);
- free(this);
- this = next;
- }
-}