mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-08-28 12:29:35 +00:00
mkdos33fs: properly create catalog tables
this didn't work at all before
This commit is contained in:
parent
a868c4957b
commit
98a0c6b2b3
2
dos33fs-utils/TODO
Normal file
2
dos33fs-utils/TODO
Normal file
@ -0,0 +1,2 @@
|
||||
getopt in dos33fs
|
||||
BSAVE/BLOAD command in dos33fs, get rid of need for makeb
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "dos33.h"
|
||||
|
||||
static int debug=1;
|
||||
|
||||
static unsigned char sector_buffer[BYTES_PER_SECTOR];
|
||||
|
||||
static int ones_lookup[16]={
|
||||
@ -422,6 +424,12 @@ found_one:
|
||||
return ((found_track<<8)+found_sector);
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
/* creates file apple_filename on the image from local file filename */
|
||||
/* returns ?? */
|
||||
static int dos33_add_file(int fd,char type,char *filename,
|
||||
@ -436,17 +444,17 @@ static int dos33_add_file(int fd,char type,char *filename,
|
||||
int result;
|
||||
|
||||
if (apple_filename[0]<64) {
|
||||
fprintf(stderr,"Error! First char of filename must be ASCII 64 or above!\n");
|
||||
exit(3);
|
||||
fprintf(stderr,"Error! First char of filename "
|
||||
"must be ASCII 64 or above!\n");
|
||||
return ERROR_INVALID_FILENAME;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for comma in filename */
|
||||
for(i=0;i<strlen(apple_filename);i++) {
|
||||
if (apple_filename[i]==',') {
|
||||
fprintf(stderr,"Error! Cannot have , in a filename!\n");
|
||||
exit(3);
|
||||
}
|
||||
fprintf(stderr,"Error! "
|
||||
"Cannot have , in a filename!\n");
|
||||
return ERROR_INVALID_FILENAME;
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,14 +462,16 @@ static int dos33_add_file(int fd,char type,char *filename,
|
||||
/* check type */
|
||||
/* and sanity check a/b filesize is set properly */
|
||||
|
||||
|
||||
/* Determine size of file to upload */
|
||||
if (stat(filename,&file_info)<0) {
|
||||
fprintf(stderr,"Error! %s not found!\n",filename);
|
||||
exit(3);
|
||||
return ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
file_size=(int)file_info.st_size;
|
||||
|
||||
if (debug) printf("Filesize: %d\n",file_size);
|
||||
|
||||
/* We need to round up to nearest sector size */
|
||||
/* Add an extra sector for the T/S list */
|
||||
/* Then add extra sector for a T/S list every 122*256 bytes (~31k) */
|
||||
@ -475,22 +485,23 @@ static int dos33_add_file(int fd,char type,char *filename,
|
||||
|
||||
/* Check for free space */
|
||||
if (needed_sectors*BYTES_PER_SECTOR>free_space) {
|
||||
fprintf(stderr,"Error! Not enough free space on disk image (need %d have %d)\n",
|
||||
fprintf(stderr,"Error! Not enough free space "
|
||||
"on disk image (need %d have %d)\n",
|
||||
needed_sectors*BYTES_PER_SECTOR,free_space);
|
||||
exit(4);
|
||||
return ERROR_NO_SPACE;
|
||||
}
|
||||
|
||||
/* plus one because we need a sector for the tail */
|
||||
size_in_sectors=(file_size/BYTES_PER_SECTOR)+
|
||||
((file_size%BYTES_PER_SECTOR)!=0);
|
||||
// printf("Need to allocate %i data sectors\n",size_in_sectors);
|
||||
// printf("Need to allocate %i total sectors\n",needed_sectors);
|
||||
if (debug) printf("Need to allocate %i data sectors\n",size_in_sectors);
|
||||
if (debug) printf("Need to allocate %i total sectors\n",needed_sectors);
|
||||
|
||||
/* Open the local file */
|
||||
input_fd=open(filename,O_RDONLY);
|
||||
if (input_fd<0) {
|
||||
fprintf(stderr,"Error! could not open %s\n",filename);
|
||||
return -1;
|
||||
return ERROR_IMAGE_NOT_FOUND;
|
||||
}
|
||||
|
||||
i=0;
|
||||
@ -596,18 +607,25 @@ continue_parsing_catalog:
|
||||
/* Find empty directory entry */
|
||||
i=0;
|
||||
while(i<7) {
|
||||
if ((sector_buffer[CATALOG_FILE_LIST+(i*CATALOG_ENTRY_SIZE)]==0xff) ||
|
||||
(sector_buffer[CATALOG_FILE_LIST+(i*CATALOG_ENTRY_SIZE)]==0x00))
|
||||
/* for undelete purposes might want to skip 0xff */
|
||||
/* (deleted) files first and only use if no room */
|
||||
|
||||
if ((sector_buffer[CATALOG_FILE_LIST+
|
||||
(i*CATALOG_ENTRY_SIZE)]==0xff) ||
|
||||
(sector_buffer[CATALOG_FILE_LIST+
|
||||
(i*CATALOG_ENTRY_SIZE)]==0x00)) {
|
||||
goto got_a_dentry;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if ((catalog_track=0x11) && (catalog_sector==1)) {
|
||||
/* in theory can only have 105 files */
|
||||
/* if full, we have no recourse! */
|
||||
/* can we allocate new catalog sectors and point to them?? */
|
||||
/* can we allocate new catalog sectors */
|
||||
/* and point to them?? */
|
||||
fprintf(stderr,"Error! No more room for files!\n");
|
||||
return -1;
|
||||
return ERROR_CATALOG_FULL;
|
||||
}
|
||||
|
||||
catalog_track=sector_buffer[CATALOG_NEXT_T];
|
||||
@ -1332,14 +1350,14 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
|
||||
case COMMAND_SAVE:
|
||||
|
||||
/* argv3 == type == A,B,T,I,N,L etc */
|
||||
/* argv4 == name of local file */
|
||||
/* argv5 == optional name of file on disk image */
|
||||
|
||||
if (argc<5+extra_ops) {
|
||||
fprintf(stderr,"Error! Need type and file_name\n");
|
||||
fprintf(stderr,"%s %s SAVE type file_name apple_filename\n",
|
||||
fprintf(stderr,"%s %s SAVE type "
|
||||
"file_name apple_filename\n",
|
||||
argv[0],image);
|
||||
goto exit_and_close;
|
||||
}
|
||||
@ -1349,7 +1367,8 @@ int main(int argc, char **argv) {
|
||||
if (argc==6+extra_ops) {
|
||||
if (strlen(argv[firstarg+4])>30) {
|
||||
fprintf(stderr,
|
||||
"Warning! Truncating filename to 30 chars!\n");
|
||||
"Warning! Truncating filename "
|
||||
"to 30 chars!\n");
|
||||
}
|
||||
strncpy(apple_filename,argv[firstarg+4],30);
|
||||
apple_filename[30]=0;
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "dos33.h"
|
||||
|
||||
void usage(char *binary,int help) {
|
||||
static void usage(char *binary,int help) {
|
||||
|
||||
printf("\n%s - version %s\n",binary,VERSION);
|
||||
printf("\tby Vince Weaver <vince@deater.net>\n");
|
||||
@ -101,7 +101,6 @@ int main(int argc, char **argv) {
|
||||
goto end_of_program;
|
||||
}
|
||||
|
||||
|
||||
buffer=calloc(1,sizeof(char)*block_size);
|
||||
|
||||
/* Open device */
|
||||
@ -118,7 +117,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Copy over OS from elsewhere, if desired */
|
||||
if (copy_dos) {
|
||||
|
||||
dos_fd=open(dos_src,O_RDONLY);
|
||||
if (fd<0) {
|
||||
fprintf(stderr,"Error opening %s\n",dos_src);
|
||||
@ -152,7 +150,8 @@ int main(int argc, char **argv) {
|
||||
/* Create VTOC */
|
||||
buffer[VTOC_DOS_RELEASE]=0x3; /* fake dos 3.3 */
|
||||
buffer[VTOC_CATALOG_T]=0x11;
|
||||
buffer[VTOC_CATALOG_S]=0xf; /* 1st Catalog typically at 0x11/0xf */
|
||||
buffer[VTOC_CATALOG_S]=num_sectors-1;
|
||||
/* 1st Catalog typically at 0x11/0xf */
|
||||
buffer[VTOC_DISK_VOLUME]=254; /* typical volume 254 */
|
||||
buffer[VTOC_MAX_TS_PAIRS]=((block_size-0xc)/2)&0xff;
|
||||
/* Number of T/S pairs fitting */
|
||||
@ -205,10 +204,22 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Write out VTOC to disk */
|
||||
lseek(fd,((17*num_sectors)+0)*block_size,SEEK_SET);
|
||||
result=write(fd,buffer,block_size);
|
||||
|
||||
result=write(fd,buffer,block_size);
|
||||
if (result<0) fprintf(stderr,"Error writing!\n");
|
||||
|
||||
/* clear buffer */
|
||||
for(i=0;i<block_size;i++) buffer[i]=0;
|
||||
/* Set catalog next pointers */
|
||||
for(i=(num_sectors-1);i>1;i--) {
|
||||
buffer[1]=0x11;
|
||||
buffer[2]=i-1;
|
||||
|
||||
lseek(fd,((17*num_sectors)+i)*block_size,SEEK_SET);
|
||||
result=write(fd,buffer,block_size);
|
||||
if (result<0) fprintf(stderr,"Error writing!\n");
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
end_of_program:
|
||||
|
@ -1 +1 @@
|
||||
#define VERSION "0.0.11"
|
||||
#define VERSION "0.0.12"
|
||||
|
Loading…
Reference in New Issue
Block a user