From: VMware, Inc <> Date: Thu, 2 Aug 2012 05:24:55 +0000 (-0700) Subject: Fix toolbox 'shrink' feature on newer distributions using bind mounts X-Git-Tag: 2012.10.14-874563~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d6e01d595a2a6c596a8f1679d5857e610bc54ef;p=thirdparty%2Fopen-vm-tools.git Fix toolbox 'shrink' feature on newer distributions using bind mounts 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 --- diff --git a/open-vm-tools/toolbox/toolboxcmd-shrink.c b/open-vm-tools/toolbox/toolboxcmd-shrink.c index acb74647f..5c49e3b11 100644 --- a/open-vm-tools/toolbox/toolboxcmd-shrink.c +++ b/open-vm-tools/toolbox/toolboxcmd-shrink.c @@ -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"),