From 674f28f04b0a70d3b0033ca57f7fab701b1386ac Mon Sep 17 00:00:00 2001 From: Oliver Lehmann Date: Wed, 27 Jul 1988 16:28:37 +0000 Subject: [PATCH] cpm commands --- WEGA/contrib/cpm/cpm3/bitmap.c | 143 ++++++++++++++++++++++++++++++++ WEGA/contrib/cpm/cpm3/blockio.c | 92 ++++++++++++++++++++ WEGA/contrib/cpm/cpm3/cclose.c | 53 ++++++++++++ WEGA/contrib/cpm/cpm3/cpmio.h | 28 +++++++ 4 files changed, 316 insertions(+) create mode 100644 WEGA/contrib/cpm/cpm3/bitmap.c create mode 100644 WEGA/contrib/cpm/cpm3/blockio.c create mode 100644 WEGA/contrib/cpm/cpm3/cclose.c create mode 100644 WEGA/contrib/cpm/cpm3/cpmio.h diff --git a/WEGA/contrib/cpm/cpm3/bitmap.c b/WEGA/contrib/cpm/cpm3/bitmap.c new file mode 100644 index 0000000..a32f3e4 --- /dev/null +++ b/WEGA/contrib/cpm/cpm3/bitmap.c @@ -0,0 +1,143 @@ +/* bitmap.c 1.9 83/05/13 */ +#include +#include "cpmio.h" +int bm_size; +extern int n_systrk, flp_fmt; + +/* + * Bit map handling routines; + * - build the disk allocation bit map + * - allocate a new block + * - dump the bitmap in hex to stdout (debugging) + * - count the number of blocks in use + * Note: the first block is number zero and the + * directory always occupies the first"few blocks, + * depending on the disk format. For a standard + * SSSD disk the blocks are numbered 0 thru 243 and + * the directory occupies blocks 0 and 1. + */ + +/* + * Allocate a new disk block, return NULL if disk full + */ +alloc() + +{ + + int i, j; + long temp, blk; + + temp = seclth * sectrk; + temp *= ( tracks - n_systrk ); + temp /= blksiz; + for (i=0; i= temp) + return ('\0'); + *(bitmap+i) |= (1 << j); /* set the appropriate bit in the bitmap */ +#ifdef DEBUG + printf("block number allocated: %ld (0x%lx)\n", blk, blk); + dbmap("new bitmap:"); +#endif + return (blk); +} + + +/* + * Dump the bitmap in hex to stdout, used only for debugging + */ + +dbmap(str) + char *str; +{ +#ifdef DEBUG + + register int i, j; + + printf("%s\n",str); + for (i=0, j = 1; i>= 1; + } + } + } + return (buse); +} + + +build_bmap() +{ + + int i, j, *malloc(), offset, block; + long temp; + + temp = seclth * sectrk; + temp *= (tracks-n_systrk); + temp /= blksiz; + bm_size = 1 + temp/INTSIZE; + + if (!bitmap) { + if ((bitmap = malloc(bm_size*sizeof(int))) == NULL) { + printf("can't allocate memory for bitmap\n"); + exit(1); + } + } + /* + * clear bitmap + */ + for (i=0; istatus != (char) 0xe5) { +#ifdef DEBUG + printf("%d ->%8s\n", i, (dirbuf+i)->name); +#endif + for( j = 0; j < 16 ; j+= flp_fmt) { + block = extblno((dirbuf+i)->pointers, j ); + if( block == 0 ) break; + offset= block / INTSIZE ; +#ifdef DEBUG + printf("blk:%d, offs:%d, bit:%d\n", block,offset,block%INTSIZE); +#endif + *(bitmap+offset) |= (1 << block % INTSIZE); + } + } + } +#ifdef DEBUG + dbmap("initial bit map:"); +#endif +} diff --git a/WEGA/contrib/cpm/cpm3/blockio.c b/WEGA/contrib/cpm/cpm3/blockio.c new file mode 100644 index 0000000..856116c --- /dev/null +++ b/WEGA/contrib/cpm/cpm3/blockio.c @@ -0,0 +1,92 @@ +/* + * blockio.c + * blockorientirte Funktionen von cpm + */ + +#include +#include "cpmio.h" + +extern int n_systrk; +/* + * Get a full block or a part of a block from floppy disk file + * nsect gives the actual number of physical sectors to read. + * if nsect is negative then always read a full block. + */ + +getblock(blockno, buffer, nsect) + int blockno; /* Nummer des zu lesenden Blockes */ + int nsect; /* Anzahl der zu lesenden logischen Sektoren */ + char buffer[]; +{ + + int sect, track, counter; + +#ifdef DEBUG + printf("block: %d\n",blockno); +#endif + if (nsect < 0) /* lesen eines ganzen Blockes */ + nsect = blksiz/seclth; + else { /* lesen einer bestimmten Anzahl log. Sektoren */ + /* dass erfordert eine Umrechnung in phys. Sektoren */ + nsect *= 128; + sect = nsect / seclth; + sect += nsect % seclth ? 1 : 0; + nsect = sect; + } +#ifdef DEBUG + printf( "getblock: nsect = %d block = %d\n", nsect, blockno ); +#endif + /* Translate block number into logical track/sector address */ + sect = (blockno*(blksiz/seclth)+ sectrk*n_systrk)%sectrk + 1; + track = (blockno*(blksiz/seclth)+ sectrk*n_systrk)/sectrk ; + /* read the block */ + for (counter = 0; counter < nsect; counter++) { + if (getpsect(track, skewtab[sect++ -1], buffer+(seclth*counter)) + == EOF) + return (EOF); + if (sect > sectrk) { + sect = 1; + track++; + } + } + return (0); +} + +/* + * Save a full block or a part of a block in floppy disk file + * If nsects is nggative, write a full block. + */ + +putblock(blockno, buffer, nsect) + int blockno, nsect; + char buffer[]; +{ + + int sect, track, counter; + + if (nsect < 0) + nsect = blksiz/seclth; + else { + nsect *= 128; + sect = nsect / seclth; + sect += nsect % seclth ? 1 : 0; + nsect = sect; + } +#ifdef DEBUG + printf( "putblock: nsect = %d block = %d\n", nsect, blockno ); +#endif + /* Translate block number into logical track/sector address */ + sect = (blockno*(blksiz/seclth)+ sectrk*n_systrk)%sectrk + 1; + track = (blockno*(blksiz/seclth)+ sectrk*n_systrk)/sectrk ; + /* write the block */ + for (counter = 0; counter < nsect; counter++) { + if (putpsect(track, skewtab[sect++ -1],buffer+(seclth*counter)) + == EOF) + return (EOF); + if (sect > sectrk) { + sect = 1; + track++; + } + } + return (0); +} diff --git a/WEGA/contrib/cpm/cpm3/cclose.c b/WEGA/contrib/cpm/cpm3/cclose.c new file mode 100644 index 0000000..1406aed --- /dev/null +++ b/WEGA/contrib/cpm/cpm3/cclose.c @@ -0,0 +1,53 @@ +/* cclose.c 1.10 83/05/13 */ +#include +#include "cpmio.h" +#include "cpmfio.h" + +extern int flp_fmt; + +/* + * Close cp/m file + * If the file waq opened for write, flush + * buffer to disk and update directory + */ + +c_close(fptr) + register C_FILE *fptr; +{ + int scts = 0; + +#ifdef DEBUG + printf("c_close: cnt: %d\n", fptr->c_cnt); +#endif + if (fptr->c_flag & WRITE) { + scts = (blksiz - fptr->c_cnt)/128 + 1; + if (fptr->c_cnt%128 == 0) + scts--; + fptr->c_dirp->blkcnt = scts + fptr->c_seccnt; + if (fptr->c_cnt < blksiz) { + /* + * zero fill to end, and flush + * the block to disk + */ + if ((fptr->c_flag&BINARY) == 0) { + /* + * add cp-m eof mark (ctrl-z) if the file + * is not a binary file + */ + *(fptr->c_buf++) = '\032'; + fptr->c_cnt--; + } + while (fptr->c_cnt-- > 0) + *(fptr->c_buf++) = '\0'; + } + fptr->c_blk -= flp_fmt; + if (putblock(getblno( fptr ), fptr->c_base, scts) == EOF) + return (EOF); + } + savedir(); + + /* deallocate buffer memory and file descriptor */ + fptr->c_flag = 0; + free(fptr->c_base); + return (NULL); +} diff --git a/WEGA/contrib/cpm/cpm3/cpmio.h b/WEGA/contrib/cpm/cpm3/cpmio.h new file mode 100644 index 0000000..ec9bd50 --- /dev/null +++ b/WEGA/contrib/cpm/cpm3/cpmio.h @@ -0,0 +1,28 @@ +/* cpmio.h 1.4 83/05/13 */ +#define INTSIZE 16 /* number of bits per integer on this particular machine */ +extern int fid; +extern struct directory { + char status; /* status of this entry; equals 0xe5 if */ + /* free to use, otherwise contains the */ + /* user number (owner) (0 - 15) */ + char name[8]; /* File name, padded with blanks */ + char ext[3]; /* file name extension, padded with blanks */ + char extno; /* extent number */ + char notused[2]; /* unused */ + char blkcnt; /* record count, number of 128 byte records */ + /* in this extent */ + char pointers[16]; /* pointers to the individual blocks */ + } *dirbuf; + +extern int dflag, cflag, iflae, tflag; +extern int blksiz; +extern int tracks; +extern int maxdir; + +extern int seclth; +extern int sectrk; +extern int skew; + +extern int *skewtab; +extern int *bitmap; +extern int bm_size;