From 4cde5ae2844eceec50f50a348b7fd0637b42c7bb Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 5 Sep 2022 20:47:29 -0400 Subject: [PATCH] dos33: re-write mkdos33fs catalog creation a bit more robust in theory can generate images with non-105 catalog entries should test this thoroughly --- utils/dos33fs-utils/dos33.c | 2 +- utils/dos33fs-utils/dos33.h | 2 +- utils/dos33fs-utils/dos33_vtoc_bitmap.c | 73 +++++++++++++++++++------ utils/dos33fs-utils/mkdos33fs.c | 67 ++++++++++++++++------- 4 files changed, 104 insertions(+), 40 deletions(-) diff --git a/utils/dos33fs-utils/dos33.c b/utils/dos33fs-utils/dos33.c index 1c9f403e..5420e259 100644 --- a/utils/dos33fs-utils/dos33.c +++ b/utils/dos33fs-utils/dos33.c @@ -139,7 +139,7 @@ static int dos33_allocate_sector(int fd, unsigned char *vtoc) { int result; /* Find an empty sector */ - result=dos33_vtoc_find_free_sector(vtoc,&found_track,&found_sector); + result=dos33_vtoc_find_free_sector(vtoc,&found_track,&found_sector,0); if (result<0) { fprintf(stderr,"ERROR: dos33_allocate_sector: Disk full!\n"); diff --git a/utils/dos33fs-utils/dos33.h b/utils/dos33fs-utils/dos33.h index f2dc8ab8..db42d0f6 100644 --- a/utils/dos33fs-utils/dos33.h +++ b/utils/dos33fs-utils/dos33.h @@ -76,7 +76,7 @@ void dos33_vtoc_free_sector(unsigned char *vtoc, int track, int sector); void dos33_vtoc_reserve_sector(unsigned char *vtoc, int track, int sector); void dos33_vtoc_dump_bitmap(unsigned char *vtoc, int num_tracks); int dos33_vtoc_find_free_sector(unsigned char *vtoc, - int *found_track, int *found_sector); + int *found_track, int *found_sector, int is_catalog); /* dos33_catalog.c */ unsigned char dos33_char_to_type(char type, int lock); diff --git a/utils/dos33fs-utils/dos33_vtoc_bitmap.c b/utils/dos33fs-utils/dos33_vtoc_bitmap.c index 26e47ace..47d805ff 100644 --- a/utils/dos33fs-utils/dos33_vtoc_bitmap.c +++ b/utils/dos33fs-utils/dos33_vtoc_bitmap.c @@ -38,6 +38,19 @@ static int find_first_one(unsigned char byte) { return i; } +static int find_last_one(unsigned char byte) { + + int i=7; + + if (byte==0) return -1; + + while((byte & (0x1<\n"); printf("\thttp://www.deater.net/weave/vmwprod/apple/\n\n"); if (help) { - printf("Usage:\t%s [-t track] [-s sector] [-b size] " - "[-d filename] [-f filename] device_name\n\n",binary); + printf("Usage:\t%s [-d debug] [-t track] [-s sector] [-b size] " + "[-i filename] [-f filename] device_name\n\n",binary); printf("\t-t tracks : number of tracks (default is 35)\n"); printf("\t-s sectors : number of sectors (default is 16)\n"); printf("\t-b blocksize : size of sector, in bytes (default is 256)\n"); - printf("\t-d filename : file to copy first 3 tracks over from\n"); + printf("\t-i filename : file to copy first 3 tracks over from\n"); printf("\t-f filename : name of BASIC file to autoboot. Default is HELLO\n"); printf("\t-m maxfiles : maximum files in CATALOG (default is 105)\n"); printf("\t-n volume : volume number (default is 254)\n"); @@ -36,7 +36,8 @@ int main(int argc, char **argv) { int num_tracks=35,num_sectors=16,sector_size=256; int max_files=105,catalog_track=17,vtoc_track=17,volume_number=254; - int catalog_sectors,current_sector; + int catalog_sectors,current_sector,current_track; + int next_track,next_sector; int max_ts_pairs=255; int fd,dos_fd; char device[BUFSIZ],dos_src[BUFSIZ]; @@ -49,9 +50,12 @@ int main(int argc, char **argv) { /* Parse Command Line Arguments */ - while ((c = getopt (argc, argv,"t:s:b:d:f:m:n:hv"))!=-1) { + while ((c = getopt (argc, argv,"t:s:b:df:i:m:n:hv"))!=-1) { switch (c) { + case 'd': + debug=1; + break; case 't': num_tracks=strtol(optarg,&endptr,10); if ( endptr == optarg ) usage(argv[0], 1); @@ -77,7 +81,7 @@ int main(int argc, char **argv) { if ( endptr == optarg ) usage(argv[0], 1); break; - case 'd': + case 'i': copy_dos=1; strncpy(dos_src,optarg,BUFSIZ-1); break; @@ -186,11 +190,11 @@ int main(int argc, char **argv) { max_ts_pairs=255; } + /* default is 105 files (15 catalog sectors) */ catalog_sectors=max_files/7; if (max_files%7) catalog_sectors++; if (catalog_sectors>num_sectors-1) { - printf("Warning! num_files leads to too many sectors %d, max is %d\n",catalog_sectors,num_sectors-1); - catalog_sectors=num_sectors-1; + printf("Warning! num_files higher than normal %d sectors, ususal is %d\n",catalog_sectors,num_sectors-1); } /***************/ @@ -297,30 +301,49 @@ int main(int argc, char **argv) { memset(sector_buffer,0,sector_size); /* Set catalog next pointers */ + + + /* start at T17S15 */ + vtoc_buffer[VTOC_LAST_ALLOC_T]=17; + vtoc_buffer[VTOC_ALLOC_DIRECT]=255; /* -1 direction */ + + /* Get first catalog sector */ + + if (dos33_vtoc_find_free_sector(vtoc_buffer, + ¤t_track,¤t_sector,1)) { + + return ERROR_NO_SPACE; + } + + for(i=0;i