|
|
1.1 ! root 1: /* physio.c 1.6 83/07/18 */ ! 2: ! 3: #include <stdio.h> ! 4: #include "cpmio.h" ! 5: #include <sys/file.h> ! 6: ! 7: /* ! 8: * Write physical sector to floppy disk file ! 9: */ ! 10: ! 11: putpsect(tr, sect, buf) ! 12: char buf[]; ! 13: { ! 14: ! 15: long newpos; ! 16: ! 17: if (sect > sectrk || sect < 1) { ! 18: fprintf(stderr, "putpsect: sector number out of range: %d\n", ! 19: sect); ! 20: return (EOF); ! 21: } ! 22: newpos = (long) (sect + (tr * sectrk) -1 ) * seclth; ! 23: if (lseek(fid, newpos, 0) == -1) { ! 24: perror("putpsect"); ! 25: return (EOF); ! 26: } ! 27: if (write(fid, buf, seclth) == seclth) ! 28: return (1); ! 29: perror("putpsect"); ! 30: fprintf(stderr, "track %d, sect %d\n", tr, sect); ! 31: return (EOF); ! 32: } ! 33: ! 34: /* ! 35: * Read physical sector from floppy disk file ! 36: */ ! 37: ! 38: getpsect(tr, sect, buf) ! 39: char buf[]; ! 40: { ! 41: ! 42: long newpos; ! 43: ! 44: if (sect > sectrk || sect < 1) { ! 45: fprintf("getpsect: sector number out of range: %d\n",sect); ! 46: return (EOF); ! 47: } ! 48: newpos = (long) (sect + (tr * sectrk) -1 ) * seclth; ! 49: if (lseek(fid, newpos, 0) == -1) { ! 50: perror("getpsect"); ! 51: return (EOF); ! 52: } ! 53: if (read(fid, buf, seclth) != seclth) { ! 54: perror("getpsect"); ! 55: fprintf(stderr, "track %d, sect %d\n", tr, sect); ! 56: return (EOF); ! 57: } ! 58: return (1); ! 59: } ! 60: ! 61: /* ! 62: * Initialize a new floppy disk file in "name", ! 63: * return its file pointer. ! 64: */ ! 65: ! 66: initcpm(name) ! 67: char *name; ! 68: { ! 69: int f, i; ! 70: char buf[512]; ! 71: ! 72: if ((f = open(name, O_CREAT|O_RDWR, 0644)) < 0) ! 73: return (EOF); ! 74: for (i=0; i<512; i++) ! 75: buf[i] = '\345'; ! 76: /* ! 77: * Initialize (with 0xe5) the first four tracks ! 78: * on the `floppy' ! 79: */ ! 80: for (i=0; i < (4*seclth*sectrk); i += 512) ! 81: write(f, buf, 512); ! 82: return (f); ! 83: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.