From e132f4b09e5c9aedaef97f65279e8702633fd425 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Wed, 9 Feb 2000 04:16:43 +0000 Subject: Fixed the init problem where it wouldn't unmount filesystems on reboot. Also fixed swapoff -a so it works. -Erik --- umount.c | 192 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 97 insertions(+), 95 deletions(-) (limited to 'umount.c') diff --git a/umount.c b/umount.c index a2ca8c74a..b58b1a08c 100644 --- a/umount.c +++ b/umount.c @@ -29,6 +29,7 @@ #include #include + 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; - } -} -- cgit v1.2.3