From a2ef425f9254da4424208ec24ea837bd44c055d3 Mon Sep 17 00:00:00 2001 From: waltje Date: Thu, 23 May 2019 15:08:35 -0500 Subject: [PATCH] Fixed some issues. in hdd_image.c and keyboard_at.c. --- src/devices/disk/hdd_image.c | 39 ++++++++++++++++++++------------- src/devices/input/keyboard_at.c | 4 ++-- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/devices/disk/hdd_image.c b/src/devices/disk/hdd_image.c index 90f6d3a..a8c5130 100644 --- a/src/devices/disk/hdd_image.c +++ b/src/devices/disk/hdd_image.c @@ -14,7 +14,7 @@ * merged with hdd.c, since that is the scope of hdd.c. The * actual format handlers can then be in hdd_format.c etc. * - * Version: @(#)hdd_image.c 1.0.10 2019/05/17 + * Version: @(#)hdd_image.c 1.0.11 2019/05/23 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -789,12 +789,16 @@ hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) /* Now read all (consecutive) blocks from the image. */ for (i = 0; i < count; i++) { /* If past end of image, give up. */ - if (feof(img->file)) + if (ferror(img->file) || feof(img->file)) break; /* Read a block. */ fread(buffer + (i << 9), 1, 512, img->file); + /* If error during read, give up. */ + if (ferror(img->file)) + break; + /* Update position. */ img->pos = sector + i; } @@ -827,7 +831,7 @@ hdd_image_read_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) fseeko64(img->file, ((uint64_t)sector << 9LL) + img->base, SEEK_SET); fread(buffer, 1, transfer_sectors << 9, img->file); - if (count != transfer_sectors) + if (ferror(img->file) || (count != transfer_sectors)) return 1; return 0; @@ -845,13 +849,13 @@ hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) /* Now write all (consecutive) blocks to the image. */ for (i = 0; i < count; i++) { - /* If past end of image, give up. */ - if (feof(img->file)) - break; - /* Write a block. */ fwrite(buffer + (i << 9), 512, 1, img->file); + /* If error during write, give up. */ + if (ferror(img->file)) + break; + /* Update position. */ img->pos = sector + i; } @@ -873,7 +877,7 @@ hdd_image_write_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) fseeko64(img->file, ((uint64_t)sector << 9LL) + img->base, SEEK_SET); fwrite(buffer, transfer_sectors << 9, 1, img->file); - if (count != transfer_sectors) + if (ferror(img->file) || (count != transfer_sectors)) return 1; return 0; @@ -894,13 +898,13 @@ hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count) /* Now write all (consecutive) blocks to the image. */ for (i = 0; i < count; i++) { - /* If past end of image, give up. */ - if (feof(img->file)) - break; - /* Write a block. */ fwrite(empty, 512, 1, img->file); + /* If error during write, give up. */ + if (ferror(img->file)) + break; + /* Update position. */ img->pos = sector + i; } @@ -925,10 +929,16 @@ hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count) fseeko64(img->file, ((uint64_t)sector << 9LL) + img->base, SEEK_SET); - for (i = 0; i < transfer_sectors; i++) + for (i = 0; i < transfer_sectors; i++) { fwrite(empty, 1, 512, img->file); - if (count != transfer_sectors) + /* If error during write, give up. */ + if (ferror(img->file)) + break; + + } + + if (ferror(img->file) || (count != transfer_sectors)) return 1; return 0; @@ -1013,5 +1023,4 @@ hdd_image_close(uint8_t id) } memset(img, 0x00, sizeof(hdd_image_t)); - img->loaded = 0; /* redundant --FvK */ } diff --git a/src/devices/input/keyboard_at.c b/src/devices/input/keyboard_at.c index 4f0a12d..00d25fc 100644 --- a/src/devices/input/keyboard_at.c +++ b/src/devices/input/keyboard_at.c @@ -16,7 +16,7 @@ * it either will not process ctrl-alt-esc, or it will not do * ANY input. * - * Version: @(#)keyboard_at.c 1.0.29 2019/05/20 + * Version: @(#)keyboard_at.c 1.0.30 2019/05/23 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -2739,7 +2739,7 @@ kbd_write(uint16_t port, uint8_t val, priv_t priv) case 0xd4: /* write to mouse */ DEBUG("ATkbd: write to mouse (%02x)\n", val); - /* FIXME: What does this do? --FvK */ + /* OS/2 Warp 3 sends this command. */ if (val == 0xbb) break;