+#if ENABLE_FEATURE_MTAB_SUPPORT
+static int useMtab;
+static int fakeIt;
+#else
+#define useMtab 0
+#define fakeIt 0
+#endif
+
+// Perform actual mount of specific filesystem at specific location.
+
+static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
+{
+ int rc;
+
+ if (fakeIt) { return 0; }
+
+ // Mount, with fallback to read-only if necessary.
+
+ for(;;) {
+ rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
+ vfsflags, filteropts);
+ if(!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS))
+ break;
+ bb_error_msg("%s is write-protected, mounting read-only",
+ mp->mnt_fsname);
+ vfsflags |= MS_RDONLY;
+ }
+
+ // Abort entirely if permission denied.
+
+ if (rc && errno == EPERM)
+ bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
+
+ /* If the mount was successful, and we're maintaining an old-style
+ * mtab file by hand, add the new entry to it now. */
+
+ if(ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc) {
+ FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
+ int i;
+
+ if(!mountTable)
+ bb_error_msg("No %s\n",bb_path_mtab_file);
+
+ // Add vfs string flags
+
+ for(i=0; mount_options[i].flags != MS_REMOUNT; i++)
+ if (mount_options[i].flags > 0)
+ append_mount_options(&(mp->mnt_opts),
+// Shut up about the darn const. It's not important. I don't care.
+ (char *)mount_options[i].name);
+
+ // Remove trailing / (if any) from directory we mounted on
+
+ i = strlen(mp->mnt_dir);
+ if(i>1 && mp->mnt_dir[i-1] == '/') mp->mnt_dir[i-1] = 0;
+
+ // Write and close.
+
+ if(!mp->mnt_type || !*mp->mnt_type) mp->mnt_type="--bind";
+ addmntent(mountTable, mp);
+ endmntent(mountTable);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ if(strcmp(mp->mnt_type,"--bind")) mp->mnt_type = 0;