cpm commands
This commit is contained in:
parent
fe5b620919
commit
674f28f04b
|
|
@ -0,0 +1,143 @@
|
|||
/* bitmap.c 1.9 83/05/13 */
|
||||
#include <stdio.h>
|
||||
#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<bm_size; i++) {
|
||||
j = ffc(0, INTSIZE, *(bitmap+i));
|
||||
if ( j < INTSIZE) break;
|
||||
}
|
||||
blk = i * INTSIZE + j;
|
||||
if (blk >= 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<bm_size; i++, j++)
|
||||
printf("%.x%s", *(bitmap+i), (j % 10) == 0 ? "\n": "\t");
|
||||
putchar( '\n');
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of bloks used in the
|
||||
* dkrectory, including the directory blocks
|
||||
*/
|
||||
|
||||
blks_used()
|
||||
{
|
||||
|
||||
int j, i, temp;
|
||||
int buse = 0;
|
||||
|
||||
for (i=0; i < bm_size; i++) {
|
||||
if (*(bitmap+i) == 0)
|
||||
continue;
|
||||
if (*(bitmap+i) == -1) {
|
||||
buse += INTSIZE;
|
||||
} else {
|
||||
temp = *(bitmap+i);
|
||||
for (j=0; j < INTSIZE; j++) {
|
||||
if (1 & temp)
|
||||
++buse;
|
||||
temp >>= 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; i<bm_size; i++)
|
||||
bitmap[i] = 0;
|
||||
|
||||
/* i equals the number of blocis occupied by the directory */
|
||||
i = (maxdir*32)/blksiz;
|
||||
|
||||
/* set the directory blocks busy in the bitmap */
|
||||
*bitmap = (1 << i) -1;
|
||||
for (i=0; i<maxdir; i++) {
|
||||
if ((dirbuf+i)->status != (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
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* blockio.c
|
||||
* blockorientirte Funktionen von cpm
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/* cclose.c 1.10 83/05/13 */
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue