2 * Mini umount implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/mount.h>
31 static const char umount_usage[] =
32 "Usage: umount [flags] filesystem|directory\n\n"
34 "\t-a:\tUnmount all file systems"
36 " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
43 static int useMtab = TRUE;
44 static int umountAll = FALSE;
45 extern const char mtab_file[]; /* Defined in utility.c */
48 #define do_umount( blockDevice, useMtab) umount( blockDevice)
51 do_umount(const char* name, int useMtab)
53 int status = umount(name);
66 umount_all(int useMtab)
72 if ((mountTable = setmntent (mtab_file, "r"))) {
73 while ((m = getmntent (mountTable)) != 0) {
74 char *blockDevice = m->mnt_fsname;
76 if (strcmp (blockDevice, "/dev/root") == 0) {
77 struct fstab* fstabItem;
78 fstabItem = getfsfile ("/");
79 if (fstabItem != NULL) {
80 blockDevice = fstabItem->fs_spec;
84 /* Don't umount /proc when doing umount -a */
85 if (strcmp (blockDevice, "proc") == 0)
88 status=do_umount (m->mnt_dir, useMtab);
90 /* Don't bother retrying the umount on busy devices */
95 status=do_umount (blockDevice, useMtab);
97 printf ("Couldn't umount %s on %s (type %s): %s\n",
98 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno));
102 endmntent (mountTable);
108 umount_main(int argc, char** argv)
112 usage( umount_usage);
115 /* Parse any options */
116 while (--argc > 0 && **(++argv) == '-') {
117 while (*++(*argv)) switch (**argv) {
127 usage( umount_usage);
132 if(umountAll==TRUE) {
133 exit(umount_all(useMtab));
135 if ( do_umount(*argv,useMtab) == 0 )