+#include <getopt.h>
+
+#define OPTION_STRING "flDnravd"
+#define OPT_FORCE 1
+#define OPT_LAZY 2
+#define OPT_DONTFREELOOP 4
+#define OPT_NO_MTAB 8
+#define OPT_REMOUNT 16
+#define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0)
+
+int umount_main(int argc, char **argv);
+int umount_main(int argc, char **argv)
+{
+ int doForce;
+ char path[2*PATH_MAX];
+ struct mntent me;
+ FILE *fp;
+ int status = EXIT_SUCCESS;
+ unsigned opt;
+ struct mtab_list {
+ char *dir;
+ char *device;
+ struct mtab_list *next;
+ } *mtl, *m;
+
+ /* Parse any options */
+
+ opt = getopt32(argc, argv, OPTION_STRING);
+
+ 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 = 0;
+
+ /* 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("cannot open %s", bb_path_mtab_file);
+ } else {
+ while (getmntent_r(fp, &me, path, sizeof(path))) {
+ m = xmalloc(sizeof(struct mtab_list));
+ m->next = mtl;
+ m->device = xstrdup(me.mnt_fsname);
+ m->dir = xstrdup(me.mnt_dir);
+ mtl = m;
+ }
+ endmntent(fp);
+ }