- struct mntent *m;
- FILE *mountTable;
-
- if ((mountTable = setmntent (mtab_file, "r"))) {
- while ((m = getmntent (mountTable)) != 0) {
- char *blockDevice = m->mnt_fsname;
-#if ! defined BB_MTAB
- if (strcmp (blockDevice, "/dev/root") == 0) {
- struct fstab* fstabItem;
- fstabItem = getfsfile ("/");
- if (fstabItem != NULL) {
- blockDevice = fstabItem->fs_spec;
- }
+ char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE);
+
+ if (blockDevice && strcmp(blockDevice, name) == 0)
+ name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT);
+
+ status = umount(name);
+
+#if defined BB_FEATURE_MOUNT_LOOP
+ if (freeLoop == TRUE && blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9))
+ /* this was a loop device, delete it */
+ del_loop(blockDevice);
+#endif
+#if defined BB_FEATURE_MOUNT_FORCE
+ if (status != 0 && doForce == TRUE) {
+ status = umount2(blockDevice, MNT_FORCE);
+ if (status != 0) {
+ error_msg_and_die("forced umount of %s failed!", blockDevice);
+ }
+ }
+#endif
+ if (status != 0 && doRemount == TRUE && errno == EBUSY) {
+ status = mount(blockDevice, name, NULL,
+ MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL);
+ if (status == 0) {
+ error_msg("%s busy - remounted read-only", blockDevice);
+ } else {
+ error_msg("Cannot remount %s read-only", blockDevice);