From 6b5c3612b002a26e083eb55ae1b85064823261ee Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 24 Aug 2021 18:15:00 -0400 Subject: [PATCH] dos33: fix disk corruption on DELETE was using &vtoc where it should have just been vtoc so writing the pointer value rather than the buffer. urgh --- utils/dos33fs-utils/Makefile | 8 +++++--- utils/dos33fs-utils/dos33.c | 10 +++++++--- utils/dos33fs-utils/dos33_vtoc_bitmap.c | 5 +++++ utils/dos33fs-utils/mkdos33fs.c | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/utils/dos33fs-utils/Makefile b/utils/dos33fs-utils/Makefile index 42b70d05..0512f2a3 100644 --- a/utils/dos33fs-utils/Makefile +++ b/utils/dos33fs-utils/Makefile @@ -1,5 +1,7 @@ include ../../Makefile.inc +CFLAGS := $(CFLAGS) -g + all: dos33 mkdos33fs make_b \ dos33_raw \ dos33_text2ascii char2hex @@ -23,7 +25,7 @@ dos33: dos33.o \ dos33_vtoc_bitmap.o $(LFLAGS) dos33.o: dos33.c dos33.h - $(CC) $(CFLAGS) -g -c dos33.c + $(CC) $(CFLAGS) -c dos33.c ### @@ -31,7 +33,7 @@ dos33_raw: dos33_raw.o $(CC) -o dos33_raw dos33_raw.o $(LFLAGS) dos33_raw.o: dos33_raw.c - $(CC) $(CFLAGS) -g -c dos33_raw.c + $(CC) $(CFLAGS) -c dos33_raw.c ### @@ -66,7 +68,7 @@ dos33_vtoc_bitmap.o: dos33_vtoc_bitmap.c dos33.h ### dos33_catalog.o: dos33_catalog.c dos33.h - $(CC) $(CFLAGS) -g -c dos33_catalog.c + $(CC) $(CFLAGS) -c dos33_catalog.c ### diff --git a/utils/dos33fs-utils/dos33.c b/utils/dos33fs-utils/dos33.c index d97797d7..a6fa4245 100644 --- a/utils/dos33fs-utils/dos33.c +++ b/utils/dos33fs-utils/dos33.c @@ -11,7 +11,7 @@ #include "dos33.h" -int debug=1; +int debug=0; static int ignore_errors=0; @@ -120,10 +120,10 @@ static int dos33_free_sector(unsigned char *vtoc,int fd,int track,int sector) { /* write modified VTOC back out */ lseek(fd,DISK_OFFSET(VTOC_TRACK,VTOC_SECTOR),SEEK_SET); - result=write(fd,&vtoc,BYTES_PER_SECTOR); + result=write(fd,vtoc,BYTES_PER_SECTOR); if (result<0) { - fprintf(stderr,"Error on I/O\n"); + fprintf(stderr,"dos33_free_sector: error writing VTOC\n"); } return 0; @@ -767,6 +767,10 @@ keep_deleting: /* Erase file from catalog entry */ /* First reload proper catalog sector */ + if (debug) { + fprintf(stderr,"\treloading T=%d S=%d\n", + catalog_track,catalog_sector); + } lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET); result=read(fd,catalog_buffer,BYTES_PER_SECTOR); if (result<0) { diff --git a/utils/dos33fs-utils/dos33_vtoc_bitmap.c b/utils/dos33fs-utils/dos33_vtoc_bitmap.c index ce9ffccd..26e47ace 100644 --- a/utils/dos33fs-utils/dos33_vtoc_bitmap.c +++ b/utils/dos33fs-utils/dos33_vtoc_bitmap.c @@ -62,6 +62,11 @@ int dos33_vtoc_free_space(unsigned char *vtoc) { /* free a sector from the sector bitmap */ void dos33_vtoc_free_sector(unsigned char *vtoc, int track, int sector) { + if (debug) { + fprintf(stderr,"vtoc_free: freeing T=%d S=%d\n", + track,sector); + } + /* each bitmap is 32 bits. With 16-sector tracks only first 16 used */ /* 1 indicates free, 0 indicates used */ if (sector<8) { diff --git a/utils/dos33fs-utils/mkdos33fs.c b/utils/dos33fs-utils/mkdos33fs.c index c47ad64d..4f3c8375 100644 --- a/utils/dos33fs-utils/mkdos33fs.c +++ b/utils/dos33fs-utils/mkdos33fs.c @@ -9,6 +9,8 @@ #include "dos33.h" +int debug=0; + static void usage(char *binary,int help) { printf("\n%s - version %s\n",binary,VERSION);