aboutsummaryrefslogtreecommitdiff
path: root/umount.c
diff options
context:
space:
mode:
Diffstat (limited to 'umount.c')
-rw-r--r--umount.c68
1 files changed, 53 insertions, 15 deletions
diff --git a/umount.c b/umount.c
index 95f7dfb3c..e749c5f0f 100644
--- a/umount.c
+++ b/umount.c
@@ -29,24 +29,54 @@
29#include <errno.h> 29#include <errno.h>
30 30
31static const char umount_usage[] = 31static const char umount_usage[] =
32"Usage: umount filesystem\n" 32"Usage: umount [flags] filesystem|directory\n"
33" or: umount directory\n" 33"Optional Flags:\n"
34" or: umount -a" 34"\t-a:\tUnmount all file systems"
35"to unmount all mounted file systems.\n"; 35#ifdef BB_MTAB
36" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
37#else
38"\n"
39#endif
40;
41
42
43static int useMtab = TRUE;
44static int umountAll = FALSE;
45extern const char mtab_file[]; /* Defined in utility.c */
46
47#if ! defined BB_MTAB
48#define do_umount( blockDevice, useMtab) umount( blockDevice)
49#else
50static int
51do_umount(const char* name, int useMtab)
52{
53 int status = umount(name);
54
55 if ( status == 0 ) {
56 if ( useMtab==TRUE )
57 erase_mtab(name);
58 return 0;
59 }
60 else
61 return( status);
62}
63#endif
36 64
37static int 65static int
38umount_all() 66umount_all(int useMtab)
39{ 67{
40 int status; 68 int status;
41 struct mntent *m; 69 struct mntent *m;
42 FILE *mountTable; 70 FILE *mountTable;
43 71
44 if ((mountTable = setmntent ("/proc/mounts", "r"))) { 72 if ((mountTable = setmntent (mtab_file, "r"))) {
45 while ((m = getmntent (mountTable)) != 0) { 73 while ((m = getmntent (mountTable)) != 0) {
46 char *blockDevice = m->mnt_fsname; 74 char *blockDevice = m->mnt_fsname;
75#if ! defined BB_MTAB
47 if (strcmp (blockDevice, "/dev/root") == 0) 76 if (strcmp (blockDevice, "/dev/root") == 0)
48 blockDevice = (getfsfile ("/"))->fs_spec; 77 blockDevice = (getfsfile ("/"))->fs_spec;
49 status=umount (m->mnt_dir); 78#endif
79 status=do_umount (m->mnt_dir, useMtab);
50 if (status!=0) { 80 if (status!=0) {
51 /* Don't bother retrying the umount on busy devices */ 81 /* Don't bother retrying the umount on busy devices */
52 if (errno==EBUSY) { 82 if (errno==EBUSY) {
@@ -56,7 +86,7 @@ umount_all()
56 printf ("Trying to umount %s failed: %s\n", 86 printf ("Trying to umount %s failed: %s\n",
57 m->mnt_dir, strerror(errno)); 87 m->mnt_dir, strerror(errno));
58 printf ("Instead trying to umount %s\n", blockDevice); 88 printf ("Instead trying to umount %s\n", blockDevice);
59 status=umount (blockDevice); 89 status=do_umount (blockDevice, useMtab);
60 if (status!=0) { 90 if (status!=0) {
61 printf ("Couldn't umount %s on %s (type %s): %s\n", 91 printf ("Couldn't umount %s on %s (type %s): %s\n",
62 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); 92 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno));
@@ -69,27 +99,35 @@ umount_all()
69} 99}
70 100
71extern int 101extern int
72umount_main(int argc, char * * argv) 102umount_main(int argc, char** argv)
73{ 103{
74 104
75 if (argc < 2) { 105 if (argc < 2) {
76 usage( umount_usage); 106 usage( umount_usage);
77 } 107 }
78 argc--;
79 argv++;
80 108
81 /* Parse any options */ 109 /* Parse any options */
82 while (**argv == '-') { 110 while (argc-- > 0 && **(++argv) == '-') {
83 while (*++(*argv)) switch (**argv) { 111 while (*++(*argv)) switch (**argv) {
84 case 'a': 112 case 'a':
85 exit ( umount_all() ); 113 umountAll = TRUE;
114 break;
115#ifdef BB_MTAB
116 case 'n':
117 useMtab = FALSE;
86 break; 118 break;
119#endif
87 default: 120 default:
88 usage( umount_usage); 121 usage( umount_usage);
89 } 122 }
90 } 123 }
91 if ( umount(*argv) == 0 ) 124
92 exit (TRUE); 125
126 if(umountAll) {
127 exit(umount_all(useMtab));
128 }
129 if ( do_umount(*argv,useMtab) == 0 )
130 exit (TRUE);
93 else { 131 else {
94 perror("umount"); 132 perror("umount");
95 exit( FALSE); 133 exit( FALSE);