diff --git a/utils/dos33fs-utils/dos33_vtoc_bitmap.c b/utils/dos33fs-utils/dos33_vtoc_bitmap.c index b2348c71..ce9ffccd 100644 --- a/utils/dos33fs-utils/dos33_vtoc_bitmap.c +++ b/utils/dos33fs-utils/dos33_vtoc_bitmap.c @@ -2,6 +2,9 @@ #include "dos33.h" +/* FIXME: this code assumes that we have 16 sectors pretty much everywhere */ + + static int ones_lookup[16]={ /* 0x0 = 0000 */ 0, /* 0x1 = 0001 */ 1, diff --git a/utils/dos33fs-utils/mkdos33fs.c b/utils/dos33fs-utils/mkdos33fs.c index 30f5cce6..c47ad64d 100644 --- a/utils/dos33fs-utils/mkdos33fs.c +++ b/utils/dos33fs-utils/mkdos33fs.c @@ -32,12 +32,14 @@ static void usage(char *binary,int help) { int main(int argc, char **argv) { - int num_tracks=35,num_sectors=16,block_size=256; + 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 max_ts_pairs=255; int fd,dos_fd; char device[BUFSIZ],dos_src[BUFSIZ]; - char *vtoc_buffer=NULL,*sector_buffer=NULL,*endptr; + unsigned char *vtoc_buffer=NULL,*sector_buffer=NULL; + char *endptr; int i,c,copy_dos=0; int result; @@ -59,7 +61,7 @@ int main(int argc, char **argv) { break; case 'b': - block_size=strtol(optarg,&endptr,10); + sector_size=strtol(optarg,&endptr,10); if ( endptr == optarg ) usage(argv[0], 1); break; @@ -98,35 +100,40 @@ int main(int argc, char **argv) { strncpy(device,argv[optind],BUFSIZ-1); + /***********************/ /* Sanity check values */ + /***********************/ - /* s 2->32 (limited by 4-byte bitfields) */ + /* sectors: 2->32 (limited by 4-byte bitfields) */ if ((num_sectors<2) || (num_sectors>32)) { printf("Number of sectors must be >2 and <=32\n\n"); goto end_of_program; } - /* t 1 ->(block_size-0x38)/2 */ - if ((num_tracks<1) || (num_tracks>(block_size-0x38)/2)) { - printf("Number of tracks must be >18 and <=%i (block_size-0x38)/2\n\n", - (block_size-0x38)/2); + /* tracks 18-50 ->(sector_size-0x38)/4 */ + /* limited by VTOC room for freespace bitmap (which is $38 to $ff) */ + /* VOTC is always on track 17 so we need at least that many */ + /* though could double if we used the unused sector fields */ + if ((num_tracks(sector_size-0x38)/4)) { + printf("Number of tracks must be >%d and <=%i\n\n", + vtoc_track,(sector_size-0x38)/4); goto end_of_program; } /* sector_size 256->65536 (or 512 based on one byte t/s size field?) */ - if ((block_size<256)||(block_size>65536)) { + if ((sector_size<256)||(sector_size>65536)) { printf("Block size must be >=256 and <65536\n\n"); goto end_of_program; } /* allocate space for buffers */ - vtoc_buffer=calloc(1,sizeof(char)*block_size); + vtoc_buffer=calloc(1,sizeof(char)*sector_size); if (vtoc_buffer==NULL) { fprintf(stderr,"Error allocating memory!\n"); goto end_of_program; } - sector_buffer=calloc(1,sizeof(char)*block_size); + sector_buffer=calloc(1,sizeof(char)*sector_size); if (sector_buffer==NULL) { fprintf(stderr,"Error allocating memory!\n"); goto end_of_program; @@ -143,7 +150,7 @@ int main(int argc, char **argv) { /* zero out file */ for(i=0;i255) { printf("Warning! Truncating max_ts pairs to 255\n"); max_ts_pairs=255; } + 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; + } + /***************/ /* Create VTOC */ /***************/ @@ -193,7 +207,7 @@ int main(int argc, char **argv) { /* Number of T/S pairs fitting */ /* in a T/S list sector */ - /* Note, overflows if block_size>524 */ + /* Note, overflows if sector_size>524 */ vtoc_buffer[VTOC_MAX_TS_PAIRS]=max_ts_pairs; /* last track space was allocated on */ @@ -204,11 +218,11 @@ int main(int argc, char **argv) { vtoc_buffer[VTOC_NUM_TRACKS]=num_tracks; vtoc_buffer[VTOC_S_PER_TRACK]=num_sectors; - vtoc_buffer[VTOC_BYTES_PER_SL]=block_size&0xff; - vtoc_buffer[VTOC_BYTES_PER_SH]=(block_size>>8)&0xff; + vtoc_buffer[VTOC_BYTES_PER_SL]=sector_size&0xff; + vtoc_buffer[VTOC_BYTES_PER_SH]=(sector_size>>8)&0xff; /* Set sector bitmap so whole disk is free */ - for(i=VTOC_FREE_BITMAPS;i16) { @@ -228,36 +242,26 @@ int main(int argc, char **argv) { lseek(fd,0,SEEK_SET); /* copy first 3 sectors */ for(i=0;i<3*(num_sectors);i++) { - result=read(dos_fd,vtoc_buffer,block_size); - result=write(fd,vtoc_buffer,block_size); + result=read(dos_fd,vtoc_buffer,sector_size); + result=write(fd,vtoc_buffer,sector_size); } close(dos_fd); /* Set boot filename */ /* Track 1 sector 9 */ - lseek(fd,((1*num_sectors)+9)*block_size,SEEK_SET); - result=read(fd,vtoc_buffer,block_size); + lseek(fd,((1*num_sectors)+9)*sector_size,SEEK_SET); + result=read(fd,vtoc_buffer,sector_size); /* filename begins at offset 75 */ for(i=0;i<30;i++) { vtoc_buffer[0x75+i]=boot_filename[i]|0x80; } - lseek(fd,((1*num_sectors)+9)*block_size,SEEK_SET); - result=write(fd,vtoc_buffer,block_size); - } + lseek(fd,((1*num_sectors)+9)*sector_size,SEEK_SET); + result=write(fd,vtoc_buffer,sector_size); + /* if copying dos reserve tracks 1 and 2 as well */ - /* reserve track 0 */ - /* No user data can be stored here as track=0 is special case */ - /* end of file indicator */ - vtoc_buffer[VTOC_FREE_BITMAPS]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+1]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+2]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+3]=0x00; - - /* if copying dos reserve tracks 1 and 2 as well */ - if (copy_dos) { vtoc_buffer[VTOC_FREE_BITMAPS+4]=0x00; vtoc_buffer[VTOC_FREE_BITMAPS+5]=0x00; vtoc_buffer[VTOC_FREE_BITMAPS+6]=0x00; @@ -266,36 +270,76 @@ int main(int argc, char **argv) { vtoc_buffer[VTOC_FREE_BITMAPS+9]=0x00; vtoc_buffer[VTOC_FREE_BITMAPS+10]=0x00; vtoc_buffer[VTOC_FREE_BITMAPS+11]=0x00; + } - /* reserve track 17 (0x11) */ - /* reserved for vtoc and catalog stuff */ - vtoc_buffer[VTOC_FREE_BITMAPS+17*4]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+17*4+1]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+17*4+2]=0x00; - vtoc_buffer[VTOC_FREE_BITMAPS+17*4+3]=0x00; + + /* reserve track 0 */ + /* No user data can be stored here as track=0 is used */ + /* as a special-case end of file indicator */ + for(i=0;i1;i--) { - vtoc_buffer[1]=0x11; - vtoc_buffer[2]=i-1; - lseek(fd,((17*num_sectors)+i)*block_size,SEEK_SET); - result=write(fd,vtoc_buffer,block_size); - if (result<0) fprintf(stderr,"Error writing!\n"); - } close(fd);