|
|
1.1 root 1: static char *sccsid ="@(#)flcopy.c 4.3 (Berkeley) 10/20/80";
2: int floppydes;
3: char *flopname = "/dev/floppy";
4: long dsize = 77 * 26 * 128;
5: int hflag;
6: int rflag;
7:
8: main(argc,argv)
9: register char **argv;
10: {
11: static char buff[512];
12: register long count;
13: register startad = -26 * 128;
14: register int n, file; register char *cp;
15:
16: while((cp = *++argv), --argc > 0) {
17: if(*cp++!='-') continue;
18: while(*cp) switch(*cp++) {
19: case 'h':
20: hflag++;
21: printf("Halftime!\n");
22: if((file = open("floppy",0))<0)
23: printf("failed to open floppy image, for reading\n"),
24: exit(1);
25: continue;
26: case 't':
27: if(*cp >= '0' && *cp <= '9')
28: dsize = atoi(cp);
29: else if(argc > 1) {
30: dsize = atoi(*++argv);
31: argc--;
32: } else dsize = 77;
33: if (dsize <= 0 || dsize > 77)
34: printf("Bad number of tracks\n"), exit(2);
35: dsize *= 26 * 128;
36: continue;
37: case 'r':
38: rflag++;
39: }
40: }
41: if(!hflag) {
42: file = creat("floppy",0666);
43: close(file);
44: file = open("floppy",2);
45: if(file < 0)
46: printf("failed to open floppy image"),
47: exit(1);
48: for(count = dsize; count > 0 ; count -= 512) {
49: n = count > 512 ? 512 : count ;
50: lread(startad,n,buff);
51: write(file,buff,n);
52: startad += 512;
53: }
54: }
55: if(rflag) exit(0);
56: printf("Change Floppy, Hit return when done.\n");
57: gets(buff);
58: lseek(file,0,0);
59: count = dsize; startad = -26 * 128;
60: for( ; count > 0 ; count -= 512) {
61: n = count > 512 ? 512 : count ;
62: read(file,buff,n);
63: lwrite(startad,n,buff);
64: startad += 512;
65: }
66: }
67: rt_init()
68: {
69: static initized = 0;
70: int mode = 2;
71:
72: if(initized) return;
73: if(rflag) mode = 0;
74: initized = 1;
75: if((floppydes = open(flopname,mode)) < 0) {
76: printf("Floppy open failed\n");
77: exit(1);
78: }
79: }
80:
81: long trans(logical)
82: register int logical;
83: {
84: /* Logical to physical adress translation */
85: register int sector, bytes, track;
86:
87: logical += 26 * 128;
88: bytes = (logical & 127);
89: logical >>= 7;
90: sector = logical % 26;
91: if(sector >= 13)
92: sector = sector *2 +1;
93: else
94: sector *= 2;
95: sector += 26 + ((track = (logical / 26)) - 1) * 6;
96: sector %= 26;
97: return( (((track *26) + sector) << 7) + bytes);
98: }
99: lread(startad,count,obuff)
100: register startad, count;
101: register char * obuff;
102: {
103: long trans();
104: extern floppydes;
105: rt_init();
106: while( (count -= 128) >= 0) {
107: lseek(floppydes, trans(startad), 0);
108: read(floppydes,obuff,128);
109: obuff += 128;
110: startad += 128;
111: }
112: }
113: lwrite(startad,count,obuff)
114: register startad, count;
115: register char * obuff;
116: {
117: long trans();
118: extern floppydes;
119: rt_init();
120: while( (count -= 128) >= 0) {
121: lseek(floppydes, trans(startad), 0);
122: write(floppydes,obuff,128);
123: obuff += 128;
124: startad += 128;
125: }
126: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.