mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-09 22:29:36 +00:00
Merge branch 'master' of git://github.com/deater/dos33fsprogs
This commit is contained in:
commit
9c75cb72af
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]={
|
||||
|
@ -47,7 +49,7 @@ static unsigned char dos33_file_type(int value) {
|
|||
|
||||
unsigned char result;
|
||||
|
||||
switch(value&0x7f){
|
||||
switch(value&0x7f) {
|
||||
case 0x0: result='T'; break;
|
||||
case 0x1: result='I'; break;
|
||||
case 0x2: result='A'; break;
|
||||
|
@ -99,7 +101,6 @@ static char *dos33_filename_to_ascii(char *dest,unsigned char *src,int len) {
|
|||
|
||||
dest[i]='\0';
|
||||
return dest;
|
||||
|
||||
}
|
||||
|
||||
/* Read VTOC into a buffer */
|
||||
|
@ -109,6 +110,7 @@ static int dos33_read_vtoc(int fd) {
|
|||
|
||||
/* Seek to VTOC */
|
||||
lseek(fd,DISK_OFFSET(VTOC_TRACK,VTOC_SECTOR),SEEK_SET);
|
||||
|
||||
/* read in VTOC */
|
||||
result=read(fd,§or_buffer,BYTES_PER_SECTOR);
|
||||
|
||||
|
@ -116,6 +118,7 @@ static int dos33_read_vtoc(int fd) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate available freespace */
|
||||
static int dos33_free_space(int fd) {
|
||||
|
||||
|
@ -133,7 +136,6 @@ static int dos33_free_space(int fd) {
|
|||
sectors_free+=ones_lookup[(bitmap[0]>>4)&0xf];
|
||||
sectors_free+=ones_lookup[bitmap[1]&0xf];
|
||||
sectors_free+=ones_lookup[(bitmap[1]>>4)&0xf];
|
||||
|
||||
}
|
||||
|
||||
return sectors_free*BYTES_PER_SECTOR;
|
||||
|
@ -142,6 +144,7 @@ static int dos33_free_space(int fd) {
|
|||
|
||||
/* Get a T/S value from a Catalog Sector */
|
||||
static int dos33_get_catalog_ts(int fd) {
|
||||
|
||||
dos33_read_vtoc(fd);
|
||||
|
||||
return TS_TO_INT(sector_buffer[VTOC_CATALOG_T],
|
||||
|
@ -152,7 +155,6 @@ static int dos33_get_catalog_ts(int fd) {
|
|||
/* after the one passed in */
|
||||
static int dos33_find_next_file(int fd,int catalog_tsf) {
|
||||
|
||||
|
||||
int catalog_track,catalog_sector,catalog_file;
|
||||
int file_track,i;
|
||||
int result;
|
||||
|
@ -170,10 +172,11 @@ catalog_loop:
|
|||
i=catalog_file;
|
||||
while(i<7) {
|
||||
|
||||
file_track=sector_buffer[CATALOG_FILE_LIST+(i*CATALOG_ENTRY_SIZE)];
|
||||
file_track=sector_buffer[CATALOG_FILE_LIST+
|
||||
(i*CATALOG_ENTRY_SIZE)];
|
||||
/* 0xff means file deleted */
|
||||
/* 0x0 means empty */
|
||||
if ((file_track!=0xff) && (file_track!=0x0)){
|
||||
if ((file_track!=0xff) && (file_track!=0x0)) {
|
||||
return ((i<<16)+(catalog_track<<8)+catalog_sector);
|
||||
}
|
||||
i++;
|
||||
|
@ -421,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,
|
||||
|
@ -435,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,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) */
|
||||
|
@ -474,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;
|
||||
|
@ -595,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];
|
||||
|
@ -1138,7 +1157,7 @@ int dos33_rename_hello(int fd, char *new_name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int display_help(char *name) {
|
||||
static int display_help(char *name) {
|
||||
printf("\ndos33 version %s\n",VERSION);
|
||||
printf("by Vince Weaver <vince@deater.net>\n");
|
||||
printf("\n");
|
||||
|
@ -1179,6 +1198,39 @@ int display_help(char *name) {
|
|||
#define COMMAND_COPY 10
|
||||
#define COMMAND_DUMP 11
|
||||
#define COMMAND_HELLO 12
|
||||
#define MAX_COMMAND 13
|
||||
|
||||
static struct command_type {
|
||||
int type;
|
||||
char name[32];
|
||||
} commands[MAX_COMMAND] = {
|
||||
{COMMAND_LOAD,"LOAD"},
|
||||
{COMMAND_SAVE,"SAVE"},
|
||||
{COMMAND_CATALOG,"CATALOG"},
|
||||
{COMMAND_DELETE,"DELETE"},
|
||||
{COMMAND_UNDELETE,"UNDELETE"},
|
||||
{COMMAND_LOCK,"LOCK"},
|
||||
{COMMAND_UNLOCK,"UNLOCK"},
|
||||
{COMMAND_INIT,"INIT"},
|
||||
{COMMAND_RENAME,"RENAME"},
|
||||
{COMMAND_COPY,"COPY"},
|
||||
{COMMAND_DUMP,"DUMP"},
|
||||
{COMMAND_HELLO,"HELLO"},
|
||||
};
|
||||
|
||||
static int lookup_command(char *name) {
|
||||
|
||||
int which=COMMAND_UNKNOWN,i;
|
||||
|
||||
for(i=1;i<MAX_COMMAND;i++) {
|
||||
if(!strncmp(name,commands[i].name,strlen(commands[i].name))) {
|
||||
which=commands[i].type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return which;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
|
@ -1193,7 +1245,6 @@ int main(int argc, char **argv) {
|
|||
char *result_string;
|
||||
int always_yes=0,firstarg=1,extra_ops=0;
|
||||
|
||||
|
||||
/* Check command line arguments */
|
||||
/* Ugh I should use getopt() or something similar here */
|
||||
|
||||
|
@ -1213,7 +1264,6 @@ int main(int argc, char **argv) {
|
|||
firstarg++;
|
||||
}
|
||||
|
||||
|
||||
if (argc<3) {
|
||||
printf("\nInvalid arguments!\n");
|
||||
display_help(argv[0]);
|
||||
|
@ -1230,55 +1280,21 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Check argument #2 which is command */
|
||||
strncpy(temp_string,argv[firstarg+1],BUFSIZ);
|
||||
|
||||
/* Make command be uppercase */
|
||||
for(i=0;i<strlen(temp_string);i++) {
|
||||
temp_string[i]=toupper(temp_string[i]);
|
||||
}
|
||||
|
||||
if (!strncmp(temp_string,"LOAD",4)) {
|
||||
command=COMMAND_LOAD;
|
||||
}
|
||||
else if (!strncmp(temp_string,"SAVE",4)) {
|
||||
command=COMMAND_SAVE;
|
||||
}
|
||||
else if (!strncmp(temp_string,"CATALOG",7)) {
|
||||
command=COMMAND_CATALOG;
|
||||
}
|
||||
else if (!strncmp(temp_string,"DELETE",6)) {
|
||||
command=COMMAND_DELETE;
|
||||
}
|
||||
else if (!strncmp(temp_string,"UNDELETE",8)) {
|
||||
command=COMMAND_UNDELETE;
|
||||
}
|
||||
else if (!strncmp(temp_string,"LOCK",4)) {
|
||||
command=COMMAND_LOCK;
|
||||
}
|
||||
else if (!strncmp(temp_string,"UNLOCK",6)) {
|
||||
command=COMMAND_UNLOCK;
|
||||
}
|
||||
else if (!strncmp(temp_string,"INIT",4)) {
|
||||
command=COMMAND_INIT;
|
||||
}
|
||||
else if (!strncmp(temp_string,"RENAME",6)) {
|
||||
command=COMMAND_RENAME;
|
||||
}
|
||||
else if (!strncmp(temp_string,"COPY",4)) {
|
||||
command=COMMAND_COPY;
|
||||
}
|
||||
else if (!strncmp(temp_string,"DUMP",4)) {
|
||||
command=COMMAND_DUMP;
|
||||
}
|
||||
else if (!strncmp(temp_string,"HELLO",5)) {
|
||||
command=COMMAND_HELLO;
|
||||
}
|
||||
else {
|
||||
display_help(argv[0]);
|
||||
goto exit_program;
|
||||
}
|
||||
|
||||
|
||||
command=lookup_command(temp_string);
|
||||
|
||||
switch(command) {
|
||||
|
||||
case COMMAND_UNKNOWN:
|
||||
display_help(argv[0]);
|
||||
goto exit_program;
|
||||
break;
|
||||
|
||||
/* Load a file from disk image to local machine */
|
||||
case COMMAND_LOAD:
|
||||
/* check and make sure we have apple_filename */
|
||||
|
@ -1334,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;
|
||||
}
|
||||
|
@ -1351,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;
|
||||
|
@ -1535,9 +1552,7 @@ int main(int argc, char **argv) {
|
|||
fprintf(stderr,
|
||||
"Warning! File %s does not exist\n",argv[firstarg+2]);
|
||||
}
|
||||
|
||||
dos33_rename_hello(dos_fd,argv[firstarg+2]);
|
||||
|
||||
break;
|
||||
case COMMAND_INIT:
|
||||
/* use common code from mkdos33fs? */
|
||||
|
@ -1548,10 +1563,8 @@ int main(int argc, char **argv) {
|
|||
goto exit_and_close;
|
||||
}
|
||||
|
||||
|
||||
exit_and_close:
|
||||
close(dos_fd);
|
||||
exit_program:
|
||||
|
||||
return 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);
|
||||
|
@ -151,14 +149,15 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Create VTOC */
|
||||
buffer[VTOC_DOS_RELEASE]=0x3; /* fake dos 3.3 */
|
||||
buffer[VTOC_CATALOG_T]=17;
|
||||
buffer[VTOC_CATALOG_S]=1; /* 1st Catalog typically at 0x11/0x1 */
|
||||
buffer[VTOC_CATALOG_T]=0x11;
|
||||
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 */
|
||||
/* in a T/S list sector */
|
||||
/* Note, overflows if block_size>524 */
|
||||
buffer[VTOC_LAST_ALLOC_T]=18; /* last track space was allocated */
|
||||
buffer[VTOC_LAST_ALLOC_T]=0x12; /* last track space was allocated */
|
||||
/* Start at middle, work way out */
|
||||
buffer[VTOC_ALLOC_DIRECT]=1; /* Working our way outward */
|
||||
buffer[VTOC_NUM_TRACKS]=num_tracks;
|
||||
|
@ -196,7 +195,7 @@ int main(int argc, char **argv) {
|
|||
buffer[VTOC_FREE_BITMAPS+11]=0x00;
|
||||
}
|
||||
|
||||
/* reserve track 17 */
|
||||
/* reserve track 17 (0x11) */
|
||||
/* reserved for vtoc and catalog stuff */
|
||||
buffer[VTOC_FREE_BITMAPS+17*4]=0x00;
|
||||
buffer[VTOC_FREE_BITMAPS+17*4+1]=0x00;
|
||||
|
@ -205,15 +204,24 @@ 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:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define VERSION "0.0.11"
|
||||
#define VERSION "0.0.12"
|
||||
|
|
|
@ -10,16 +10,32 @@ SETUP.BAS: setup.bas
|
|||
WEBSERVER.BAS: webserver.bas
|
||||
$(TXT2BAS) < webserver.bas > WEBSERVER.BAS
|
||||
|
||||
about.html: ./c/about.html
|
||||
$(MAKEB) ./c/about.html about.html 0xc000
|
||||
|
||||
index.html: ./c/index.html
|
||||
$(MAKEB) ./c/index.html index.html 0xc000
|
||||
|
||||
favicon.ico: ./c/favicon.ico
|
||||
$(MAKEB) ./c/favicon.ico favicon.ico 0xc000
|
||||
|
||||
vmw_logo.png: ./c/vmw_logo.png
|
||||
$(MAKEB) ./c/vmw_logo.png vmw_logo.png 0xc000
|
||||
|
||||
R.TXT: request.txt
|
||||
$(MAKEB) request.txt R.TXT 0xc000
|
||||
|
||||
ethernet.dsk: SETUP.BAS \
|
||||
WEBSERVER.BAS \
|
||||
R.TXT
|
||||
R.TXT \
|
||||
about.html index.html favicon.ico vmw_logo.png
|
||||
$(DOS33) -y ethernet.dsk SAVE A SETUP.BAS
|
||||
$(DOS33) -y ethernet.dsk SAVE A WEBSERVER.BAS
|
||||
$(DOS33) -y ethernet.dsk SAVE B R.TXT
|
||||
|
||||
$(DOS33) -y ethernet.dsk SAVE B about.html
|
||||
$(DOS33) -y ethernet.dsk SAVE B index.html
|
||||
$(DOS33) -y ethernet.dsk SAVE B favicon.ico
|
||||
$(DOS33) -y ethernet.dsk SAVE B vmw_logo.png
|
||||
|
||||
clean:
|
||||
rm -f *~ *.BAS R.TXT
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user