- 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 CONFIG_FEATURE_MTAB_SUPPORT
- if (strcmp(cur->device, "rootfs") == 0) {
- continue;
- } else if (strcmp(cur->device, "/dev/root") == 0) {
- /* Adjusts device to be the real root device,
- * or leaves device alone if it can't find it */
- cur->device = find_real_root_device_name(cur->device);
- }
-#endif
- return cur->device;
- }
+ int doForce;
+ char *const path = xmalloc(PATH_MAX + 2); /* to save stack */
+ struct mntent me;
+ FILE *fp;
+ char *fstype = NULL;
+ int status = EXIT_SUCCESS;
+ unsigned opt;
+ struct mtab_list {
+ char *dir;
+ char *device;
+ struct mtab_list *next;
+ } *mtl, *m;
+
+ opt = getopt32(argv, OPTION_STRING, &fstype);
+ //argc -= optind;
+ argv += optind;
+ doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY));
+
+ /* Get a list of mount points from mtab. We read them all in now mostly
+ * for umount -a (so we don't have to worry about the list changing while
+ * we iterate over it, or about getting stuck in a loop on the same failing
+ * entry. Notice that this also naturally reverses the list so that -a
+ * umounts the most recent entries first. */
+ m = mtl = NULL;
+
+ // If we're umounting all, then m points to the start of the list and
+ // the argument list should be empty (which will match all).
+ fp = setmntent(bb_path_mtab_file, "r");
+ if (!fp) {
+ if (opt & OPT_ALL)
+ bb_error_msg_and_die("can't open %s", bb_path_mtab_file);
+ } else {
+ while (getmntent_r(fp, &me, path, PATH_MAX)) {
+ /* Match fstype if passed */
+ if (fstype && match_fstype(&me, fstype))
+ continue;
+ m = xmalloc(sizeof(struct mtab_list));
+ m->next = mtl;
+ m->device = xstrdup(me.mnt_fsname);
+ m->dir = xstrdup(me.mnt_dir);
+ mtl = m;