PDP11, VAX: Fix differencing virtual disk corruption during creation problems

This commit is contained in:
Mark Pizzolato 2014-03-16 01:11:35 -07:00
parent 194b35f6e8
commit 98ac7af6fa
3 changed files with 51 additions and 36 deletions

1
scp.c
View file

@ -567,6 +567,7 @@ const struct scp_error {
{"STALL", "Console Telnet output stall"}, {"STALL", "Console Telnet output stall"},
{"AFAIL", "Assertion failed"}, {"AFAIL", "Assertion failed"},
{"INVREM", "Invalid remote console command"}, {"INVREM", "Invalid remote console command"},
{"NOTATT", "Not attached"},
}; };
const size_t size_map[] = { sizeof (int8), const size_t size_map[] = { sizeof (int8),

View file

@ -304,8 +304,9 @@ typedef uint32 t_addr;
#define SCPE_STALL (SCPE_BASE + 41) /* Telnet conn stall */ #define SCPE_STALL (SCPE_BASE + 41) /* Telnet conn stall */
#define SCPE_AFAIL (SCPE_BASE + 42) /* assert failed */ #define SCPE_AFAIL (SCPE_BASE + 42) /* assert failed */
#define SCPE_INVREM (SCPE_BASE + 43) /* invalid remote console command */ #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_KFLAG 0x1000 /* tti data flag */
#define SCPE_BREAK 0x2000 /* tti break flag */ #define SCPE_BREAK 0x2000 /* tti break flag */
#define SCPE_NOMESSAGE 0x10000000 /* message display supression flag */ #define SCPE_NOMESSAGE 0x10000000 /* message display supression flag */

View file

@ -1198,7 +1198,7 @@ FILE *fileref;
t_bool auto_format; t_bool auto_format;
if ((uptr == NULL) || !(uptr->flags & UNIT_ATT)) if ((uptr == NULL) || !(uptr->flags & UNIT_ATT))
return SCPE_IERR; return SCPE_NOTATT;
ctx = (struct disk_context *)uptr->disk_ctx; ctx = (struct disk_context *)uptr->disk_ctx;
fileref = uptr->fileref; 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, " Directory of H:\\Data\n\n");
fprintf (st, " 04/14/2011 12:57 PM 5,120 RA92.vhd\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, " 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, " sim> atta rq3 -c RA92-1.vhd RA92.vhd\n");
fprintf (st, " RQ3: creating new virtual disk 'RA92-1.vhd'\n"); fprintf (st, " RQ3: creating new virtual disk 'RA92-1.vhd'\n");
fprintf (st, " RQ3: Copied 1505MB. 99%% complete.\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].Reserved = 0;
hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataOffset = NtoHll (LocatorPosition+LocatorsWritten*BytesPerSector); hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataOffset = NtoHll (LocatorPosition+LocatorsWritten*BytesPerSector);
++LocatorsWritten; ++LocatorsWritten;
hVHD->Dynamic.TableOffset = NtoHll (LocatorPosition+LocatorsWritten*BytesPerSector);
hVHD->Dynamic.Checksum = NtoHl (CalculateVhdFooterChecksum (&hVHD->Dynamic, sizeof(hVHD->Dynamic))); hVHD->Dynamic.Checksum = NtoHl (CalculateVhdFooterChecksum (&hVHD->Dynamic, sizeof(hVHD->Dynamic)));
hVHD->Footer.Checksum = 0; hVHD->Footer.Checksum = 0;
hVHD->Footer.DiskType = NtoHl (VHD_DT_Differencing); hVHD->Footer.DiskType = NtoHl (VHD_DT_Differencing);
@ -3563,6 +3564,14 @@ if (WriteFilePosition (hVHD->File,
Status = errno; Status = errno;
goto Cleanup_Return; 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, if (WriteFilePosition (hVHD->File,
&hVHD->Footer, &hVHD->Footer,
sizeof (hVHD->Footer), sizeof (hVHD->Footer),
@ -3571,7 +3580,8 @@ if (WriteFilePosition (hVHD->File,
Status = errno; Status = errno;
goto Cleanup_Return; goto Cleanup_Return;
} }
if (WriteFilePosition (hVHD->File, if (hVHD->Dynamic.ParentLocatorEntries[7].PlatformDataLength)
if (WriteFilePosition (hVHD->File,
RelativeParentVHDPath, RelativeParentVHDPath,
BytesPerSector, BytesPerSector,
NULL, NULL,
@ -3579,7 +3589,8 @@ if (WriteFilePosition (hVHD->File,
Status = errno; Status = errno;
goto Cleanup_Return; goto Cleanup_Return;
} }
if (WriteFilePosition (hVHD->File, if (hVHD->Dynamic.ParentLocatorEntries[6].PlatformDataLength)
if (WriteFilePosition (hVHD->File,
FullParentVHDPath, FullParentVHDPath,
BytesPerSector, BytesPerSector,
NULL, NULL,
@ -3587,7 +3598,8 @@ if (WriteFilePosition (hVHD->File,
Status = errno; Status = errno;
goto Cleanup_Return; goto Cleanup_Return;
} }
if (WriteFilePosition (hVHD->File, if (hVHD->Dynamic.ParentLocatorEntries[5].PlatformDataLength)
if (WriteFilePosition (hVHD->File,
RelativeParentVHDPathUnicode, RelativeParentVHDPathUnicode,
BytesPerSector, BytesPerSector,
NULL, NULL,
@ -3595,7 +3607,8 @@ if (WriteFilePosition (hVHD->File,
Status = errno; Status = errno;
goto Cleanup_Return; goto Cleanup_Return;
} }
if (WriteFilePosition (hVHD->File, if (hVHD->Dynamic.ParentLocatorEntries[4].PlatformDataLength)
if (WriteFilePosition (hVHD->File,
FullParentVHDPathUnicode, FullParentVHDPathUnicode,
BytesPerSector, BytesPerSector,
NULL, NULL,
@ -3613,7 +3626,7 @@ free (FullVHDPath);
sim_vhd_disk_close ((FILE *)hVHD); sim_vhd_disk_close ((FILE *)hVHD);
hVHD = NULL; hVHD = NULL;
if (Status) { if (Status) {
if (EEXIST != Status) if ((EEXIST != Status) && (ENOENT != Status))
remove (szVHDPath); remove (szVHDPath);
} }
else { else {