DISK: Fix -O functionality to override VHD differencing disk consistency checks

This commit is contained in:
Mark Pizzolato 2016-11-26 07:06:19 -08:00
parent 4f1f439174
commit 3511b5e4e3

View file

@ -2896,7 +2896,10 @@ if ((sDynamic) &&
(sim_switches & SWMASK ('O')))) (sim_switches & SWMASK ('O'))))
strncpy (szParentVHDPath, CheckPath, ParentVHDPathSize); strncpy (szParentVHDPath, CheckPath, ParentVHDPathSize);
else { else {
if (0 != memcmp (sDynamic->ParentUniqueID, sParentFooter.UniqueID, sizeof (sParentFooter.UniqueID)))
sim_printf ("Error Invalid Parent VHD '%s' for Differencing VHD: %s\n", CheckPath, szVHDPath); sim_printf ("Error Invalid Parent VHD '%s' for Differencing VHD: %s\n", CheckPath, szVHDPath);
else
sim_printf ("Error Parent VHD '%s' has been modified since Differencing VHD: %s was created\n", CheckPath, szVHDPath);
Return = EINVAL; /* File Corrupt/Invalid */ Return = EINVAL; /* File Corrupt/Invalid */
} }
break; break;
@ -3005,6 +3008,7 @@ return (char *)(&hVHD->Footer.DriveType[0]);
static FILE *sim_vhd_disk_open (const char *szVHDPath, const char *DesiredAccess) static FILE *sim_vhd_disk_open (const char *szVHDPath, const char *DesiredAccess)
{ {
VHDHANDLE hVHD = (VHDHANDLE) calloc (1, sizeof(*hVHD)); VHDHANDLE hVHD = (VHDHANDLE) calloc (1, sizeof(*hVHD));
int NeedUpdate = FALSE;
int Status; int Status;
if (!hVHD) if (!hVHD)
@ -3037,11 +3041,23 @@ static FILE *sim_vhd_disk_open (const char *szVHDPath, const char *DesiredAccess
0); 0);
if (Status) if (Status)
goto Cleanup_Return; goto Cleanup_Return;
if (ParentModifiedTimeStamp != hVHD->Dynamic.ParentTimeStamp) { if ((0 != memcmp (hVHD->Dynamic.ParentUniqueID, ParentFooter.UniqueID, sizeof (ParentFooter.UniqueID))) ||
(ParentModifiedTimeStamp != hVHD->Dynamic.ParentTimeStamp)) {
if (sim_switches & SWMASK ('O')) { /* OVERRIDE consistency checks? */
if (strchr (DesiredAccess, '+')) { /* open for write/update? */
memcpy (hVHD->Dynamic.ParentUniqueID, ParentFooter.UniqueID, sizeof (ParentFooter.UniqueID));
hVHD->Dynamic.ParentTimeStamp = ParentModifiedTimeStamp;
hVHD->Dynamic.Checksum = 0;
hVHD->Dynamic.Checksum = CalculateVhdFooterChecksum (&hVHD->Dynamic, sizeof(hVHD->Dynamic));
NeedUpdate = TRUE;
}
}
else {
Status = EBADF; Status = EBADF;
goto Cleanup_Return; goto Cleanup_Return;
} }
} }
}
if (hVHD->Footer.SavedState) { if (hVHD->Footer.SavedState) {
Status = EAGAIN; /* Busy */ Status = EAGAIN; /* Busy */
goto Cleanup_Return; goto Cleanup_Return;
@ -3056,6 +3072,18 @@ Cleanup_Return:
sim_vhd_disk_close ((FILE *)hVHD); sim_vhd_disk_close ((FILE *)hVHD);
hVHD = NULL; hVHD = NULL;
} }
else {
if (NeedUpdate) { /* Update Differencing Disk Header? */
if (WriteFilePosition(hVHD->File,
&hVHD->Dynamic,
sizeof (hVHD->Dynamic),
NULL,
NtoHll (hVHD->Footer.DataOffset))) {
sim_vhd_disk_close ((FILE *)hVHD);
hVHD = NULL;
}
}
}
errno = Status; errno = Status;
return (FILE *)hVHD; return (FILE *)hVHD;
} }