From 98ac7af6fa1904e0663417b7baec79461343f627 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 16 Mar 2014 01:11:35 -0700 Subject: [PATCH] PDP11, VAX: Fix differencing virtual disk corruption during creation problems --- scp.c | 1 + sim_defs.h | 3 +- sim_disk.c | 83 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/scp.c b/scp.c index 1122e901..734f8533 100644 --- a/scp.c +++ b/scp.c @@ -567,6 +567,7 @@ const struct scp_error { {"STALL", "Console Telnet output stall"}, {"AFAIL", "Assertion failed"}, {"INVREM", "Invalid remote console command"}, + {"NOTATT", "Not attached"}, }; const size_t size_map[] = { sizeof (int8), diff --git a/sim_defs.h b/sim_defs.h index d2cfd5c7..bbcf5373 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -304,8 +304,9 @@ typedef uint32 t_addr; #define SCPE_STALL (SCPE_BASE + 41) /* Telnet conn stall */ #define SCPE_AFAIL (SCPE_BASE + 42) /* assert failed */ #define SCPE_INVREM (SCPE_BASE + 43) /* invalid remote console command */ +#define SCPE_NOTATT (SCPE_BASE + 44) /* not attached */ -#define SCPE_MAX_ERR (SCPE_BASE + 44) /* Maximum SCPE Error Value */ +#define SCPE_MAX_ERR (SCPE_BASE + 45) /* Maximum SCPE Error Value */ #define SCPE_KFLAG 0x1000 /* tti data flag */ #define SCPE_BREAK 0x2000 /* tti break flag */ #define SCPE_NOMESSAGE 0x10000000 /* message display supression flag */ diff --git a/sim_disk.c b/sim_disk.c index 422f9784..9fcb6330 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -1198,7 +1198,7 @@ FILE *fileref; t_bool auto_format; if ((uptr == NULL) || !(uptr->flags & UNIT_ATT)) - return SCPE_IERR; + return SCPE_NOTATT; ctx = (struct disk_context *)uptr->disk_ctx; fileref = uptr->fileref; @@ -1322,7 +1322,7 @@ fprintf (st, " Volume Serial Number is F8DE-510C\n\n"); fprintf (st, " Directory of H:\\Data\n\n"); fprintf (st, " 04/14/2011 12:57 PM 5,120 RA92.vhd\n"); fprintf (st, " 1 File(s) 5,120 bytes\n"); -fprintf (st, " sim> atta rq3 -c RA92-1.vhd RA92.vhd\n"); +fprintf (st, " sim> atta rq3 -d RA92-1-Diff.vhd RA92.vhd\n"); fprintf (st, " sim> atta rq3 -c RA92-1.vhd RA92.vhd\n"); fprintf (st, " RQ3: creating new virtual disk 'RA92-1.vhd'\n"); fprintf (st, " RQ3: Copied 1505MB. 99%% complete.\n"); @@ -3541,6 +3541,7 @@ hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataLength = NtoHl ((uint32)(2*str hVHD->Dynamic.ParentLocatorEntries[4].Reserved = 0; hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataOffset = NtoHll (LocatorPosition+LocatorsWritten*BytesPerSector); ++LocatorsWritten; +hVHD->Dynamic.TableOffset = NtoHll (LocatorPosition+LocatorsWritten*BytesPerSector); hVHD->Dynamic.Checksum = NtoHl (CalculateVhdFooterChecksum (&hVHD->Dynamic, sizeof(hVHD->Dynamic))); hVHD->Footer.Checksum = 0; hVHD->Footer.DiskType = NtoHl (VHD_DT_Differencing); @@ -3563,6 +3564,14 @@ if (WriteFilePosition (hVHD->File, Status = errno; goto Cleanup_Return; } +if (WriteFilePosition (hVHD->File, + hVHD->BAT, + BytesPerSector*((NtoHl (hVHD->Dynamic.MaxTableEntries)*sizeof(*hVHD->BAT)+BytesPerSector-1)/BytesPerSector), + NULL, + NtoHll (hVHD->Dynamic.TableOffset))) { + Status = errno; + goto Cleanup_Return; + } if (WriteFilePosition (hVHD->File, &hVHD->Footer, sizeof (hVHD->Footer), @@ -3571,38 +3580,42 @@ if (WriteFilePosition (hVHD->File, Status = errno; goto Cleanup_Return; } -if (WriteFilePosition (hVHD->File, - RelativeParentVHDPath, - BytesPerSector, - NULL, - NtoHll (hVHD->Dynamic.ParentLocatorEntries[7].PlatformDataOffset))) { - Status = errno; - goto Cleanup_Return; - } -if (WriteFilePosition (hVHD->File, - FullParentVHDPath, - BytesPerSector, - NULL, - NtoHll (hVHD->Dynamic.ParentLocatorEntries[6].PlatformDataOffset))) { - Status = errno; - goto Cleanup_Return; - } -if (WriteFilePosition (hVHD->File, - RelativeParentVHDPathUnicode, - BytesPerSector, - NULL, - NtoHll (hVHD->Dynamic.ParentLocatorEntries[5].PlatformDataOffset))) { - Status = errno; - goto Cleanup_Return; - } -if (WriteFilePosition (hVHD->File, - FullParentVHDPathUnicode, - BytesPerSector, - NULL, - NtoHll (hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataOffset))) { - Status = errno; - goto Cleanup_Return; - } +if (hVHD->Dynamic.ParentLocatorEntries[7].PlatformDataLength) + if (WriteFilePosition (hVHD->File, + RelativeParentVHDPath, + BytesPerSector, + NULL, + NtoHll (hVHD->Dynamic.ParentLocatorEntries[7].PlatformDataOffset))) { + Status = errno; + goto Cleanup_Return; + } +if (hVHD->Dynamic.ParentLocatorEntries[6].PlatformDataLength) + if (WriteFilePosition (hVHD->File, + FullParentVHDPath, + BytesPerSector, + NULL, + NtoHll (hVHD->Dynamic.ParentLocatorEntries[6].PlatformDataOffset))) { + Status = errno; + goto Cleanup_Return; + } +if (hVHD->Dynamic.ParentLocatorEntries[5].PlatformDataLength) + if (WriteFilePosition (hVHD->File, + RelativeParentVHDPathUnicode, + BytesPerSector, + NULL, + NtoHll (hVHD->Dynamic.ParentLocatorEntries[5].PlatformDataOffset))) { + Status = errno; + goto Cleanup_Return; + } +if (hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataLength) + if (WriteFilePosition (hVHD->File, + FullParentVHDPathUnicode, + BytesPerSector, + NULL, + NtoHll (hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataOffset))) { + Status = errno; + goto Cleanup_Return; + } Cleanup_Return: free (RelativeParentVHDPath); @@ -3613,7 +3626,7 @@ free (FullVHDPath); sim_vhd_disk_close ((FILE *)hVHD); hVHD = NULL; if (Status) { - if (EEXIST != Status) + if ((EEXIST != Status) && (ENOENT != Status)) remove (szVHDPath); } else {