Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/util-linux/umount.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/util-linux/umount.c
r902 r1770 6 6 * Copyright (C) 2005 by Rob Landley <rob@landley.net> 7 7 * 8 * This program is licensed under the GNU General Public license (GPL) 9 * version 2 or later, see http://www.fsf.org/licensing/licenses/gpl.html 10 * or the file "LICENSE" in the busybox source tarball for the full text. 11 * 8 * Licensed under GPL version 2, see file LICENSE in this tarball for details. 12 9 */ 13 10 14 #include "busybox.h"15 11 #include <mntent.h> 16 #include <errno.h>17 12 #include <getopt.h> 13 #include "libbb.h" 18 14 19 #define OPTION_STRING "flDnravd "15 #define OPTION_STRING "flDnravdt:" 20 16 #define OPT_FORCE 1 21 17 #define OPT_LAZY 2 … … 25 21 #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0) 26 22 23 int umount_main(int argc, char **argv); 27 24 int umount_main(int argc, char **argv) 28 25 { … … 31 28 struct mntent me; 32 29 FILE *fp; 30 char *fstype = 0; 33 31 int status = EXIT_SUCCESS; 34 unsigned longopt;32 unsigned opt; 35 33 struct mtab_list { 36 34 char *dir; … … 41 39 /* Parse any options */ 42 40 43 opt = bb_getopt_ulflags(argc, argv, OPTION_STRING);41 opt = getopt32(argv, OPTION_STRING, &fstype); 44 42 45 43 argc -= optind; … … 59 57 * the argument list should be empty (which will match all). */ 60 58 61 if (!(fp = setmntent(bb_path_mtab_file, "r"))) { 59 fp = setmntent(bb_path_mtab_file, "r"); 60 if (!fp) { 62 61 if (opt & OPT_ALL) 63 bb_error_msg_and_die("Cannot open %s", bb_path_mtab_file); 64 } else while (getmntent_r(fp,&me,path,sizeof(path))) { 65 m = xmalloc(sizeof(struct mtab_list)); 66 m->next = mtl; 67 m->device = bb_xstrdup(me.mnt_fsname); 68 m->dir = bb_xstrdup(me.mnt_dir); 69 mtl = m; 62 bb_error_msg_and_die("cannot open %s", bb_path_mtab_file); 63 } else { 64 while (getmntent_r(fp, &me, path, sizeof(path))) { 65 /* Match fstype if passed */ 66 if (fstype && match_fstype(&me, fstype)) 67 continue; 68 m = xmalloc(sizeof(struct mtab_list)); 69 m->next = mtl; 70 m->device = xstrdup(me.mnt_fsname); 71 m->dir = xstrdup(me.mnt_dir); 72 mtl = m; 73 } 74 endmntent(fp); 70 75 } 71 endmntent(fp);72 76 73 /* If we're not mounting all, we need at least one argument. */74 if (!(opt & OPT_ALL) ) {77 /* If we're not umounting all, we need at least one argument. */ 78 if (!(opt & OPT_ALL) && !fstype) { 75 79 m = 0; 76 80 if (!argc) bb_show_usage(); 77 81 } 78 82 79 83 // Loop through everything we're supposed to umount, and do so. 80 84 for (;;) { … … 107 111 curstat = umount2(zapit, doForce); 108 112 if (curstat) 109 bb_error_msg _and_die("forced umount of %s failed!", zapit);113 bb_error_msg("forced umount of %s failed!", zapit); 110 114 } 111 115 … … 113 117 if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) { 114 118 curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL); 115 bb_error_msg(curstat ? " Cannot remount %s read-only" :119 bb_error_msg(curstat ? "cannot remount %s read-only" : 116 120 "%s busy - remounted read-only", m->device); 117 121 } … … 119 123 if (curstat) { 120 124 status = EXIT_FAILURE; 121 bb_perror_msg(" Couldn't umount %s", zapit);125 bb_perror_msg("cannot umount %s", zapit); 122 126 } else { 123 127 /* De-allocate the loop device. This ioctl should be ignored on … … 133 137 // of /dev/blah, not just the most recent. 134 138 while (m && (m = m->next)) 135 if ((opt & OPT_ALL) || !strcmp(path, m->device))139 if ((opt & OPT_ALL) || !strcmp(path, m->device)) 136 140 break; 137 141 } … … 145 149 free(mtl->dir); 146 150 free(mtl); 147 mtl =m;151 mtl = m; 148 152 } 149 153 }
Note:
See TracChangeset
for help on using the changeset viewer.