From db49ead0b63bf90d0caa6c34fdfaea5aad1af48e Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 6 Jun 2022 17:01:07 -0400 Subject: [PATCH] dos33: try to propogate errors a bit better --- utils/dos33fs-utils/dos33.c | 34 +++++++++++++++++----------------- utils/dos33fs-utils/dos33.h | 7 +++++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/utils/dos33fs-utils/dos33.c b/utils/dos33fs-utils/dos33.c index a6fa4245..e9c00dbc 100644 --- a/utils/dos33fs-utils/dos33.c +++ b/utils/dos33fs-utils/dos33.c @@ -108,7 +108,7 @@ repeat_catalog: if (result<0) fprintf(stderr,"Error on I/O\n"); - return -1; + return -ERROR_FILE_NOT_FOUND; } static int dos33_free_sector(unsigned char *vtoc,int fd,int track,int sector) { @@ -139,7 +139,7 @@ static int dos33_allocate_sector(int fd, unsigned char *vtoc) { if (result<0) { fprintf(stderr,"ERROR: dos33_allocate_sector: Disk full!\n"); - return -1; + return -ERROR_NO_SPACE; } @@ -161,11 +161,7 @@ static int dos33_allocate_sector(int fd, unsigned char *vtoc) { } -#define ERROR_INVALID_FILENAME 1 -#define ERROR_FILE_NOT_FOUND 2 -#define ERROR_NO_SPACE 3 -#define ERROR_IMAGE_NOT_FOUND 4 -#define ERROR_CATALOG_FULL 5 + #define ADD_RAW 0 #define ADD_BINARY 1 @@ -192,7 +188,7 @@ static int dos33_add_file(unsigned char *vtoc, if (apple_filename[0]<64) { fprintf(stderr,"Error! First char of filename " "must be ASCII 64 or above!\n"); - if (!ignore_errors) return ERROR_INVALID_FILENAME; + if (!ignore_errors) return -ERROR_INVALID_FILENAME; } /* Check for comma in filename */ @@ -200,7 +196,7 @@ static int dos33_add_file(unsigned char *vtoc, if (apple_filename[i]==',') { fprintf(stderr,"Error! " "Cannot have , in a filename!\n"); - return ERROR_INVALID_FILENAME; + return -ERROR_INVALID_FILENAME; } } @@ -211,7 +207,7 @@ static int dos33_add_file(unsigned char *vtoc, /* Determine size of file to upload */ if (stat(filename,&file_info)<0) { fprintf(stderr,"Error! %s not found!\n",filename); - return ERROR_FILE_NOT_FOUND; + return -ERROR_FILE_NOT_FOUND; } file_size=(int)file_info.st_size; @@ -240,7 +236,7 @@ static int dos33_add_file(unsigned char *vtoc, fprintf(stderr,"Error! Not enough free space " "on disk image (need %d have %d)\n", needed_sectors*BYTES_PER_SECTOR,free_space); - return ERROR_NO_SPACE; + return -ERROR_NO_SPACE; } /* plus one because we need a sector for the tail */ @@ -253,20 +249,23 @@ static int dos33_add_file(unsigned char *vtoc, input_fd=open(filename,O_RDONLY); if (input_fd<0) { fprintf(stderr,"Error! could not open %s\n",filename); - return ERROR_IMAGE_NOT_FOUND; + return -ERROR_IMAGE_NOT_FOUND; } i=0; while (i