|
|
1.1 root 1: /*
2: * Copyright (c) 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted provided
6: * that: (1) source distributions retain this entire copyright notice and
7: * comment, and (2) distributions including binaries display the following
8: * acknowledgement: ``This product includes software developed by the
9: * University of California, Berkeley and its contributors'' in the
10: * documentation or other materials provided with the distribution and in
11: * all advertising materials mentioning features or use of this software.
12: * Neither the name of the University nor the names of its contributors may
13: * be used to endorse or promote products derived from this software without
14: * specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: char copyright[] =
22: "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
23: All rights reserved.\n";
24: #endif /* not lint */
25:
26: #ifndef lint
27: static char sccsid[] = "@(#)flcopy.c 5.3 (Berkeley) 6/1/90";
28: #endif /* not lint */
29:
30: #include <sys/file.h>
31: #include "pathnames.h"
32:
33: int floppydes;
34: char *flopname = _PATH_FLOPPY;
35: long dsize = 77 * 26 * 128;
36: int hflag;
37: int rflag;
38:
39: main(argc, argv)
40: register char **argv;
41: {
42: static char buff[512];
43: register long count;
44: register startad = -26 * 128;
45: register int n, file;
46: register char *cp;
47:
48: while ((cp = *++argv), --argc > 0) {
49: while (*cp) {
50: switch(*cp++) {
51:
52: case '-':
53: continue;
54:
55: case 'h':
56: hflag++;
57: printf("Halftime!\n");
58: if ((file = open("floppy", 0)) < 0) {
59: printf("can't open \"floppy\"\n");
60: exit(1);
61: }
62: continue;
63:
64: case 'f':
65: if (argc < 1) {
66: printf(
67: "flcopy: -f: missing file name\n");
68: exit(1);
69: }
70: flopname = *++argv;
71: argc--;
72: break;
73:
74: case 't':
75: if (*cp >= '0' && *cp <= '9')
76: dsize = atoi(cp);
77: else if (argc > 1) {
78: dsize = atoi(*++argv);
79: argc--;
80: } else
81: dsize = 77;
82: if (dsize <= 0 || dsize > 77) {
83: printf("Bad number of tracks\n");
84: exit(2);
85: }
86: dsize *= 26 * 128;
87: continue;
88:
89: case 'r':
90: rflag++;
91: }
92: break;
93: }
94: }
95: if (!hflag) {
96: file = open("floppy", O_RDWR|O_CREAT|O_TRUNC, 0666);
97: if (file < 0) {
98: printf("can't open \"floppy\"\n");
99: exit(1);
100: }
101: for (count = dsize; count > 0 ; count -= 512) {
102: n = count > 512 ? 512 : count;
103: lread(startad, n, buff);
104: write(file, buff, n);
105: startad += 512;
106: }
107: }
108: if (rflag)
109: exit(0);
110: printf("Change Floppy, Hit return when done.\n");
111: gets(buff);
112: lseek(file, 0, 0);
113: count = dsize;
114: startad = -26 * 128;
115: for ( ; count > 0 ; count -= 512) {
116: n = count > 512 ? 512 : count;
117: read(file, buff, n);
118: lwrite(startad, n, buff);
119: startad += 512;
120: }
121: exit(0);
122: }
123:
124: rt_init()
125: {
126: static initized = 0;
127: int mode = 2;
128:
129: if (initized)
130: return;
131: if (rflag)
132: mode = 0;
133: initized = 1;
134: if ((floppydes = open(flopname, mode)) < 0) {
135: printf("Floppy open failed\n");
136: exit(1);
137: }
138: }
139:
140: /*
141: * Logical to physical adress translation
142: */
143: long
144: trans(logical)
145: register int logical;
146: {
147: register int sector, bytes, track;
148:
149: logical += 26 * 128;
150: bytes = (logical & 127);
151: logical >>= 7;
152: sector = logical % 26;
153: if (sector >= 13)
154: sector = sector*2 +1;
155: else
156: sector *= 2;
157: sector += 26 + ((track = (logical / 26)) - 1) * 6;
158: sector %= 26;
159: return ((((track *26) + sector) << 7) + bytes);
160: }
161:
162: lread(startad, count, obuff)
163: register startad, count;
164: register char *obuff;
165: {
166: long trans();
167: extern floppydes;
168:
169: rt_init();
170: while ((count -= 128) >= 0) {
171: lseek(floppydes, trans(startad), 0);
172: read(floppydes, obuff, 128);
173: obuff += 128;
174: startad += 128;
175: }
176: }
177:
178: lwrite(startad, count, obuff)
179: register startad, count;
180: register char *obuff;
181: {
182: long trans();
183: extern floppydes;
184:
185: rt_init();
186: while ((count -= 128) >= 0) {
187: lseek(floppydes, trans(startad), 0);
188: write(floppydes, obuff, 128);
189: obuff += 128;
190: startad += 128;
191: }
192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.