]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix toolbox 'shrink' feature on newer distributions using bind mounts
authorVMware, Inc <>
Thu, 2 Aug 2012 05:24:55 +0000 (22:24 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Thu, 2 Aug 2012 18:08:03 +0000 (11:08 -0700)
VMware toolbox-cmd utility provides two disk related features i.e.
shrink and wipe. When the user executes 'shrink' or 'wipe' command, the
utility parses /etc/mtab and checks if there is an entry matching the
specific mount point. If a match exists, then the utlity immediately
stops the parsing. This approach is not very robust and may cause few
issues especially if there are multiple entries for the specified mount
point. If the first entry maps to an unsupported partition type and the
second entry maps to a supported partition type, the current parsing
logic returns EX_UNAVAILABLE error. We should fix this.

Modified the code to continue parsing the entries if the first match entry
maps to an unsupported partition type.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/toolbox/toolboxcmd-shrink.c

index acb74647f2910ced29222e0d593637b47c7f5cb6..5c49e3b11f5b344f181d71f0dfb4ad671094fece 100644 (file)
@@ -160,52 +160,6 @@ ShrinkGetMountPoints(WiperPartition_List *pl) // OUT: Known mount points
 }
 
 
-/*
- *-----------------------------------------------------------------------------
- *
- * ShrinkGetPartition  --
- *
- *      Finds the WiperPartion whose mountpoint is given.
- *
- * Results:
- *      The WiperPatition.
- *
- * Side effects:
- *      None
- *
- *-----------------------------------------------------------------------------
- */
-
-static WiperPartition*
-ShrinkGetPartition(char *mountPoint)
-{
-   WiperPartition_List plist;
-   WiperPartition *p, *part = NULL;
-   DblLnkLst_Links *curr;
-
-   if (!ShrinkGetMountPoints(&plist)) {
-      return NULL;
-   }
-
-   DblLnkLst_ForEach(curr, &plist.link) {
-      p = DblLnkLst_Container(curr, WiperPartition, link);
-      if (toolbox_strcmp(p->mountPoint, mountPoint) == 0) {
-         part = p;
-         /*
-          * Detach the element we are interested in so it is not
-          * destroyed when we call WiperPartition_Close.
-          */
-         DblLnkLst_Unlink1(&part->link);
-         break;
-      }
-   }
-
-   WiperPartition_Close(&plist);
-
-   return part;
-}
-
-
 /*
  *-----------------------------------------------------------------------------
  *
@@ -388,7 +342,8 @@ ShrinkDoWipeAndShrink(char *mountPoint,         // IN: mount point
    int i;
    int progress = 0;
    unsigned char *err;
-   WiperPartition *part;
+   WiperPartition *part = NULL;
+   WiperPartition_List plist;
    int rc;
 
 #if defined(_WIN32)
@@ -397,7 +352,26 @@ ShrinkDoWipeAndShrink(char *mountPoint,         // IN: mount point
    signal(SIGINT, ShrinkWiperDestroy);
 #endif
 
-   part = ShrinkGetPartition(mountPoint);
+   if (ShrinkGetMountPoints(&plist)) {
+      DblLnkLst_Links *curr, *nextElem;
+      DblLnkLst_ForEachSafe(curr, nextElem, &plist.link) {
+         WiperPartition *p = DblLnkLst_Container(curr, WiperPartition, link);
+         if (toolbox_strcmp(p->mountPoint, mountPoint) == 0) {
+            WiperSinglePartition_Close(part);
+            part = p;
+            /*
+             * Detach the element we are interested in so it is not
+             * destroyed when we call WiperPartition_Close.
+             */
+            DblLnkLst_Unlink1(&part->link);
+            if (part->type != PARTITION_UNSUPPORTED) {
+               break;
+            }
+         }
+      }
+      WiperPartition_Close(&plist);
+   }
+
    if (part == NULL) {
       ToolsCmd_PrintErr(SU_(disk.shrink.partition.notfound,
                             "Unable to find partition %s\n"),