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 filesystem\n"
33 " or: umount directory\n"
35 "to unmount all mounted file systems.\n";
44 if ((mountTable = setmntent ("/proc/mounts", "r"))) {
45 while ((m = getmntent (mountTable)) != 0) {
46 char *blockDevice = m->mnt_fsname;
47 if (strcmp (blockDevice, "/dev/root") == 0)
48 blockDevice = (getfsfile ("/"))->fs_spec;
49 status=umount (m->mnt_dir);
51 /* Don't bother retrying the umount on busy devices */
56 printf ("Trying to umount %s failed: %s\n",
57 m->mnt_dir, strerror(errno));
58 printf ("Instead trying to umount %s\n", blockDevice);
59 status=umount (blockDevice);
61 printf ("Couldn't umount %s on %s (type %s): %s\n",
62 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno));
66 endmntent (mountTable);
72 umount_main(int argc, char * * argv)
81 /* Parse any options */
82 while (**argv == '-') {
83 while (*++(*argv)) switch (**argv) {
85 exit ( umount_all() );
91 if ( umount(*argv) == 0 )