DISK: Preserve container dates when adding or removing container meta data
This commit is contained in:
parent
079e4780d2
commit
e6611c61b3
1 changed files with 28 additions and 15 deletions
43
sim_disk.c
43
sim_disk.c
|
@ -2255,6 +2255,7 @@ static t_stat store_disk_footer (UNIT *uptr, const char *dtype)
|
||||||
{
|
{
|
||||||
DEVICE *dptr;
|
DEVICE *dptr;
|
||||||
struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx;
|
struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx;
|
||||||
|
struct stat statb;
|
||||||
struct simh_disk_footer *f;
|
struct simh_disk_footer *f;
|
||||||
time_t now = time (NULL);
|
time_t now = time (NULL);
|
||||||
t_offset total_sectors;
|
t_offset total_sectors;
|
||||||
|
@ -2263,6 +2264,7 @@ if ((dptr = find_dev_from_unit (uptr)) == NULL)
|
||||||
return SCPE_NOATT;
|
return SCPE_NOATT;
|
||||||
if (uptr->flags & UNIT_RO)
|
if (uptr->flags & UNIT_RO)
|
||||||
return SCPE_RO;
|
return SCPE_RO;
|
||||||
|
sim_stat (uptr->filename, &statb);
|
||||||
f = (struct simh_disk_footer *)calloc (1, sizeof (*f));
|
f = (struct simh_disk_footer *)calloc (1, sizeof (*f));
|
||||||
f->AccessFormat = DK_GET_FMT (uptr);
|
f->AccessFormat = DK_GET_FMT (uptr);
|
||||||
total_sectors = (((t_offset)uptr->capac) * ctx->capac_factor * ((dptr->flags & DEV_SECTORS) ? 512 : 1)) / ctx->sector_size;
|
total_sectors = (((t_offset)uptr->capac) * ctx->capac_factor * ((dptr->flags & DEV_SECTORS) ? 512 : 1)) / ctx->sector_size;
|
||||||
|
@ -2284,13 +2286,18 @@ switch (f->AccessFormat) {
|
||||||
case DKUF_F_STD: /* SIMH format */
|
case DKUF_F_STD: /* SIMH format */
|
||||||
if (sim_fseeko ((FILE *)uptr->fileref, total_sectors * ctx->sector_size, SEEK_SET) == 0) {
|
if (sim_fseeko ((FILE *)uptr->fileref, total_sectors * ctx->sector_size, SEEK_SET) == 0) {
|
||||||
sim_fwrite (f, sizeof (*f), 1, (FILE *)uptr->fileref);
|
sim_fwrite (f, sizeof (*f), 1, (FILE *)uptr->fileref);
|
||||||
fflush ((FILE *)uptr->fileref);
|
fclose ((FILE *)uptr->fileref);
|
||||||
|
sim_set_file_times (uptr->filename, statb.st_atime, statb.st_mtime);
|
||||||
|
uptr->fileref = sim_fopen (uptr->filename, "rb+");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DKUF_F_VHD: /* VHD format */
|
case DKUF_F_VHD: /* VHD format */
|
||||||
break;
|
break;
|
||||||
case DKUF_F_RAW: /* Raw Physical Disk Access */
|
case DKUF_F_RAW: /* Raw Physical Disk Access */
|
||||||
sim_os_disk_write (uptr, total_sectors * ctx->sector_size, (uint8 *)f, NULL, sizeof (*f));
|
sim_os_disk_write (uptr, total_sectors * ctx->sector_size, (uint8 *)f, NULL, sizeof (*f));
|
||||||
|
sim_os_disk_close_raw (uptr->fileref);
|
||||||
|
sim_set_file_times (uptr->filename, statb.st_atime, statb.st_mtime);
|
||||||
|
uptr->fileref = sim_os_disk_open_raw (uptr->filename, "rb+");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -2871,24 +2878,24 @@ if (container_size && (container_size != (t_offset)-1)) {
|
||||||
if ((container_size != current_unit_size) &&
|
if ((container_size != current_unit_size) &&
|
||||||
((DKUF_F_VHD == DK_GET_FMT (uptr)) || (0 != (uptr->flags & UNIT_RO)) ||
|
((DKUF_F_VHD == DK_GET_FMT (uptr)) || (0 != (uptr->flags & UNIT_RO)) ||
|
||||||
(ctx->footer))) {
|
(ctx->footer))) {
|
||||||
if (!sim_quiet) {
|
if (!sim_quiet) {
|
||||||
int32 saved_switches = sim_switches;
|
int32 saved_switches = sim_switches;
|
||||||
const char *container_dtype = ctx->footer ? (const char *)ctx->footer->DriveType : "";
|
const char *container_dtype = ctx->footer ? (const char *)ctx->footer->DriveType : "";
|
||||||
|
|
||||||
sim_switches = SWMASK ('R');
|
sim_switches = SWMASK ('R');
|
||||||
uptr->capac = (t_addr)(container_size/(ctx->capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1)));
|
uptr->capac = (t_addr)(container_size/(ctx->capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1)));
|
||||||
sim_printf ("%s: non expandable %s%sdisk container '%s' is %s than simulated device (%s %s ",
|
sim_printf ("%s: non expandable %s%sdisk container '%s' is %s than simulated device (%s %s ",
|
||||||
sim_uname (uptr), container_dtype, (*container_dtype != '\0') ? " " : "", cptr,
|
sim_uname (uptr), container_dtype, (*container_dtype != '\0') ? " " : "", cptr,
|
||||||
(container_size < current_unit_size) ? "smaller" : "larger", sprint_capac (dptr, uptr),
|
(container_size < current_unit_size) ? "smaller" : "larger", sprint_capac (dptr, uptr),
|
||||||
(container_size < current_unit_size) ? "<" : ">");
|
(container_size < current_unit_size) ? "<" : ">");
|
||||||
uptr->capac = saved_capac;
|
uptr->capac = saved_capac;
|
||||||
sim_printf ("%s)\n", sprint_capac (dptr, uptr));
|
sim_printf ("%s)\n", sprint_capac (dptr, uptr));
|
||||||
sim_switches = saved_switches;
|
sim_switches = saved_switches;
|
||||||
}
|
|
||||||
sim_disk_detach (uptr);
|
|
||||||
return SCPE_OPENERR;
|
|
||||||
}
|
}
|
||||||
|
sim_disk_detach (uptr);
|
||||||
|
return SCPE_OPENERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else { /* Autosize by changing capacity */
|
else { /* Autosize by changing capacity */
|
||||||
if (filesystem_size != (t_offset)-1) { /* Known file system data size AND */
|
if (filesystem_size != (t_offset)-1) { /* Known file system data size AND */
|
||||||
if (filesystem_size > container_size) /* Data size greater than container size? */
|
if (filesystem_size > container_size) /* Data size greater than container size? */
|
||||||
|
@ -6052,13 +6059,18 @@ t_offset container_size;
|
||||||
sprintf (FullPath, "%s%s", directory, filename);
|
sprintf (FullPath, "%s%s", directory, filename);
|
||||||
|
|
||||||
if (info->flag) { /* zap type */
|
if (info->flag) { /* zap type */
|
||||||
|
struct stat statb;
|
||||||
container = sim_vhd_disk_open (FullPath, "r");
|
container = sim_vhd_disk_open (FullPath, "r");
|
||||||
if (container != NULL) {
|
if (container != NULL) {
|
||||||
sim_vhd_disk_close (container);
|
sim_vhd_disk_close (container);
|
||||||
info->stat = sim_messagef (SCPE_OPENERR, "Cannot change the disk type of a VHD container file\n");
|
info->stat = sim_messagef (SCPE_OPENERR, "Cannot change the disk type of a VHD container file\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
container = sim_fopen (FullPath, "r+");
|
if (sim_stat (FullPath, &statb)) {
|
||||||
|
info->stat = sim_messagef (SCPE_OPENERR, "Cannot stat file: '%s' - %s\n", FullPath, strerror (errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
container = sim_fopen (FullPath, "rb+");
|
||||||
if (container == NULL) {
|
if (container == NULL) {
|
||||||
info->stat = sim_messagef (SCPE_OPENERR, "Cannot open container file '%s' - %s\n", FullPath, strerror (errno));
|
info->stat = sim_messagef (SCPE_OPENERR, "Cannot open container file '%s' - %s\n", FullPath, strerror (errno));
|
||||||
return;
|
return;
|
||||||
|
@ -6077,7 +6089,7 @@ if (info->flag) { /* zap type */
|
||||||
zero_sector = (uint8 *)calloc (sector_size, sizeof (*sector_data));
|
zero_sector = (uint8 *)calloc (sector_size, sizeof (*sector_data));
|
||||||
/* Chop off the disk footer and trailing zero sectors */
|
/* Chop off the disk footer and trailing zero sectors */
|
||||||
container_size -= sizeof (*f);
|
container_size -= sizeof (*f);
|
||||||
while (container_size > 0) {
|
while ((sim_switches & SWMASK ('Z')) && (container_size > 0)) {
|
||||||
if ((sim_fseeko (container, container_size - sector_size, SEEK_SET) != 0) ||
|
if ((sim_fseeko (container, container_size - sector_size, SEEK_SET) != 0) ||
|
||||||
(sector_size != sim_fread (sector_data, 1, sector_size, container)) ||
|
(sector_size != sim_fread (sector_data, 1, sector_size, container)) ||
|
||||||
(0 != memcmp (sector_data, zero_sector, sector_size)))
|
(0 != memcmp (sector_data, zero_sector, sector_size)))
|
||||||
|
@ -6088,6 +6100,7 @@ if (info->flag) { /* zap type */
|
||||||
free (zero_sector);
|
free (zero_sector);
|
||||||
(void)sim_set_fsize (container, (t_addr)container_size);
|
(void)sim_set_fsize (container, (t_addr)container_size);
|
||||||
fclose (container);
|
fclose (container);
|
||||||
|
sim_set_file_times (FullPath, statb.st_atime, statb.st_mtime);
|
||||||
info->stat = sim_messagef (SCPE_OK, "Disk Type Removed from container '%s'\n", FullPath);
|
info->stat = sim_messagef (SCPE_OK, "Disk Type Removed from container '%s'\n", FullPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6114,7 +6127,7 @@ if (info->flag == 0) {
|
||||||
container = sim_vhd_disk_open (FullPath, "r");
|
container = sim_vhd_disk_open (FullPath, "r");
|
||||||
if (container == NULL) {
|
if (container == NULL) {
|
||||||
sim_disk_set_fmt (uptr, 0, "SIMH", NULL);
|
sim_disk_set_fmt (uptr, 0, "SIMH", NULL);
|
||||||
container = sim_fopen (FullPath, "r+");
|
container = sim_fopen (FullPath, "rb+");
|
||||||
close_function = fclose;
|
close_function = fclose;
|
||||||
size_function = sim_fsize_ex;
|
size_function = sim_fsize_ex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue