hdd_image: Enter missing image mode on other open failures as well

This commit is contained in:
RichardG867
2024-11-07 13:02:52 -03:00
parent 1396afcea0
commit a3ad407a21

View File

@@ -295,7 +295,7 @@ hdd_image_load(int id)
if (fn[0] == '.') { if (fn[0] == '.') {
hdd_image_log("File name starts with .\n"); hdd_image_log("File name starts with .\n");
memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
return 0; goto fail_raw;
} }
hdd_images[id].file = plat_fopen(fn, "rb+"); hdd_images[id].file = plat_fopen(fn, "rb+");
if (hdd_images[id].file == NULL) { if (hdd_images[id].file == NULL) {
@@ -306,14 +306,14 @@ hdd_image_load(int id)
if (hdd[id].wp) { if (hdd[id].wp) {
hdd_image_log("A write-protected image must exist\n"); hdd_image_log("A write-protected image must exist\n");
memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
return 0; goto fail_raw;
} }
hdd_images[id].file = plat_fopen(fn, "wb+"); hdd_images[id].file = plat_fopen(fn, "wb+");
if (hdd_images[id].file == NULL) { if (hdd_images[id].file == NULL) {
hdd_image_log("Unable to open image\n"); hdd_image_log("Unable to open image\n");
memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
return 0; goto fail_raw;
} else { } else {
if (image_is_hdi(fn)) { if (image_is_hdi(fn)) {
full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL; full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL;
@@ -389,10 +389,13 @@ retry_vhd:
s = full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL; s = full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL;
ret = prepare_new_hard_disk(id, full_size); ret = prepare_new_hard_disk(id, full_size);
if (ret <= 0)
goto fail_raw;
return ret; return ret;
} else { } else {
/* Failed for another reason */ /* Failed for another reason */
hdd_image_log("Failed for another reason\n"); hdd_image_log("Failed for another reason\n");
fail_raw:
hdd_images[id].type = HDD_IMAGE_RAW; hdd_images[id].type = HDD_IMAGE_RAW;
hdd_images[id].last_sector = (uint32_t) (((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks)) - 1; hdd_images[id].last_sector = (uint32_t) (((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks)) - 1;
return 1; return 1;
@@ -418,7 +421,7 @@ retry_vhd:
fclose(hdd_images[id].file); fclose(hdd_images[id].file);
hdd_images[id].file = NULL; hdd_images[id].file = NULL;
memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
return 0; goto fail_raw;
} }
if (fread(&spt, 1, 4, hdd_images[id].file) != 4) if (fread(&spt, 1, 4, hdd_images[id].file) != 4)
fatal("hdd_image_load(): HDI: Error reading sectors per track\n"); fatal("hdd_image_load(): HDI: Error reading sectors per track\n");
@@ -446,7 +449,7 @@ retry_vhd:
fclose(hdd_images[id].file); fclose(hdd_images[id].file);
hdd_images[id].file = NULL; hdd_images[id].file = NULL;
memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
return 0; goto fail_raw;
} }
if (fread(&spt, 1, 4, hdd_images[id].file) != 4) if (fread(&spt, 1, 4, hdd_images[id].file) != 4)
fatal("hdd_image_load(): HDI: Error reading sectors per track\n"); fatal("hdd_image_load(): HDI: Error reading sectors per track\n");