1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
--- tapecopy.c.orig Thu Nov 29 13:53:46 2001
+++ tapecopy.c Thu Jan 31 13:26:01 2002
@@ -8,357 +8,18 @@
/* prints a summary of the tape files and blocksizes. */
/*-------------------------------------------------------------------*/
-#include "hercules.h"
-
-/*-------------------------------------------------------------------*/
-/* Structure definition for AWSTAPE block header */
-/*-------------------------------------------------------------------*/
-typedef struct _AWSTAPE_BLKHDR {
- HWORD curblkl; /* Length of this block */
- HWORD prvblkl; /* Length of previous block */
- BYTE flags1; /* Flags byte 1 */
- BYTE flags2; /* Flags byte 2 */
- } AWSTAPE_BLKHDR;
-
-/* Definitions for AWSTAPE_BLKHDR flags byte 1 */
-#define AWSTAPE_FLAG1_NEWREC 0x80 /* Start of new record */
-#define AWSTAPE_FLAG1_TAPEMARK 0x40 /* Tape mark */
-#define AWSTAPE_FLAG1_ENDREC 0x20 /* End of record */
-
-/*-------------------------------------------------------------------*/
-/* Static data areas */
-/*-------------------------------------------------------------------*/
-static BYTE vollbl[] = "\xE5\xD6\xD3"; /* EBCDIC characters "VOL" */
-static BYTE hdrlbl[] = "\xC8\xC4\xD9"; /* EBCDIC characters "HDR" */
-static BYTE eoflbl[] = "\xC5\xD6\xC6"; /* EBCDIC characters "EOF" */
-static BYTE eovlbl[] = "\xC5\xD6\xE5"; /* EBCDIC characters "EOV" */
-static struct mt_tape_info tapeinfo[] = MT_TAPE_INFO;
-static struct mt_tape_info densinfo[] = {
- {0x01, "NRZI (800 bpi)"},
- {0x02, "PE (1600 bpi)"},
- {0x03, "GCR (6250 bpi)"},
- {0x05, "QIC-45/60 (GCR, 8000 bpi)"},
- {0x06, "PE (3200 bpi)"},
- {0x07, "IMFM (6400 bpi)"},
- {0x08, "GCR (8000 bpi)"},
- {0x09, "GCR /37871 bpi)"},
- {0x0A, "MFM (6667 bpi)"},
- {0x0B, "PE (1600 bpi)"},
- {0x0C, "GCR (12960 bpi)"},
- {0x0D, "GCR (25380 bpi)"},
- {0x0F, "QIC-120 (GCR 10000 bpi)"},
- {0x10, "QIC-150/250 (GCR 10000 bpi)"},
- {0x11, "QIC-320/525 (GCR 16000 bpi)"},
- {0x12, "QIC-1350 (RLL 51667 bpi)"},
- {0x13, "DDS (61000 bpi)"},
- {0x14, "EXB-8200 (RLL 43245 bpi)"},
- {0x15, "EXB-8500 (RLL 45434 bpi)"},
- {0x16, "MFM 10000 bpi"},
- {0x17, "MFM 42500 bpi"},
- {0x24, "DDS-2"},
- {0x8C, "EXB-8505 compressed"},
- {0x90, "EXB-8205 compressed"},
- {0, NULL}};
-static BYTE buf[65500];
-
-/*-------------------------------------------------------------------*/
-/* ASCII to EBCDIC translate tables */
-/*-------------------------------------------------------------------*/
-#include "codeconv.h"
-
-/*-------------------------------------------------------------------*/
-/* Subroutine to print tape status */
-/*-------------------------------------------------------------------*/
-static void print_status (BYTE *devname, long stat)
-{
- printf ("%s status: %8.8lX", devname, stat);
- if (GMT_EOF(stat)) printf (" EOF");
- if (GMT_BOT(stat)) printf (" BOT");
- if (GMT_EOT(stat)) printf (" EOT");
- if (GMT_SM(stat)) printf (" SETMARK");
- if (GMT_EOD(stat)) printf (" EOD");
- if (GMT_WR_PROT(stat)) printf (" WRPROT");
- if (GMT_ONLINE(stat)) printf (" ONLINE");
- if (GMT_D_6250(stat)) printf (" 6250");
- if (GMT_D_1600(stat)) printf (" 1600");
- if (GMT_D_800(stat)) printf (" 800");
- if (GMT_DR_OPEN(stat)) printf (" NOTAPE");
- printf ("\n");
-
-} /* end function print_status */
-
-/*-------------------------------------------------------------------*/
-/* Subroutine to obtain and print tape status */
-/* Return value: 0=normal, 1=end of tape, -1=error */
-/*-------------------------------------------------------------------*/
-static int obtain_status (BYTE *devname, int devfd)
-{
-int rc; /* Return code */
-struct mtget stblk; /* Area for MTIOCGET ioctl */
-
- rc = ioctl (devfd, MTIOCGET, (char*)&stblk);
- if (rc < 0)
- {
- printf ("tapecopy: Error reading status of %s: %s\n",
- devname, strerror(errno));
- return -1;
- }
-
- print_status (devname, stblk.mt_gstat);
-
- if (GMT_EOD(stblk.mt_gstat)) return 1;
- if (GMT_EOT(stblk.mt_gstat)) return 1;
-
- return 0;
-} /* end function print_status */
/*-------------------------------------------------------------------*/
/* TAPECOPY main entry point */
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
-int rc; /* Return code */
-int i; /* Array subscript */
-int len; /* Block length */
-int prevlen; /* Previous block length */
-BYTE *devname; /* -> Tape device name */
-BYTE *filename; /* -> Output file name */
-int devfd; /* Tape file descriptor */
-int outfd = -1; /* Output file descriptor */
-int fileno; /* Tape file number */
-int blkcount; /* Block count */
-int minblksz; /* Minimum block size */
-int maxblksz; /* Maximum block size */
-struct mtop opblk; /* Area for MTIOCTOP ioctl */
-struct mtget stblk; /* Area for MTIOCGET ioctl */
-long density; /* Tape density code */
-BYTE labelrec[81]; /* Standard label (ASCIIZ) */
-AWSTAPE_BLKHDR awshdr; /* AWSTAPE block header */
-
- /* Display the program identification message */
- display_version (stderr, "Hercules tape copy program ");
-
- /* The first argument is the tape device name */
- if (argc > 1 && argv[1] != NULL && strlen(argv[1]) > 5
- && memcmp (argv[1], "/dev/", 5) == 0)
- {
- devname = argv[1];
- }
- else
- {
- printf ("Usage: tapecopy /dev/st0 [outfile]\n");
- exit (1);
- }
-
- /* The second argument is the output file name */
- if (argc > 2 && argv[2] != NULL)
- filename = argv[2];
- else
- filename = NULL;
-
- /* Open the tape device */
- devfd = open (devname, O_RDONLY|O_BINARY);
- if (devfd < 0)
- {
- printf ("tapecopy: Error opening %s: %s\n",
- devname, strerror(errno));
- exit (3);
- }
- /* Obtain the tape status */
- rc = ioctl (devfd, MTIOCGET, (char*)&stblk);
- if (rc < 0)
- {
- printf ("tapecopy: Error reading status of %s: %s\n",
- devname, strerror(errno));
- exit (7);
- }
- /* Display tape status information */
- for (i = 0; tapeinfo[i].t_type != 0
- && tapeinfo[i].t_type != stblk.mt_type; i++);
-
- if (tapeinfo[i].t_name != NULL)
- printf ("%s device type: %s\n", devname, tapeinfo[i].t_name);
- else
- printf ("%s device type: 0x%lX\n", devname, stblk.mt_type);
-
- density = (stblk.mt_dsreg & MT_ST_DENSITY_MASK)
- >> MT_ST_DENSITY_SHIFT;
-
- for (i = 0; densinfo[i].t_type != 0
- && densinfo[i].t_type != density; i++);
-
- if (densinfo[i].t_name != NULL)
- printf ("%s tape density: %s\n", devname, densinfo[i].t_name);
- else
- printf ("%s tape density code: 0x%lX\n", devname, density);
-
- if (stblk.mt_gstat != 0)
- {
- print_status (devname, stblk.mt_gstat);
- }
-
- /* Set the tape device to process variable length blocks */
- opblk.mt_op = MTSETBLK;
- opblk.mt_count = 0;
- rc = ioctl (devfd, MTIOCTOP, (char*)&opblk);
- if (rc < 0)
- {
- printf ("tapecopy: Error setting attributes for %s: %s\n",
- devname, strerror(errno));
- exit (5);
- }
-
- /* Rewind the tape to the beginning */
- opblk.mt_op = MTREW;
- opblk.mt_count = 1;
- rc = ioctl (devfd, MTIOCTOP, (char*)&opblk);
- if (rc < 0)
- {
- printf ("tapecopy: Error rewinding %s: %s\n",
- devname, strerror(errno));
- exit (6);
- }
-
- /* Open the output file */
- if (filename != NULL)
- {
- outfd = open (filename, O_WRONLY | O_CREAT | O_BINARY,
- S_IRUSR | S_IWUSR | S_IRGRP);
- if (outfd < 0)
- {
- printf ("tapecopy: Error opening %s: %s\n",
- filename, strerror(errno));
- exit (4);
- }
- }
-
- /* Copy blocks from tape to the output file */
- fileno = 1;
- blkcount = 0;
- minblksz = 0;
- maxblksz = 0;
- len = 0;
-
- while (1)
- {
- /* Save previous block length */
- prevlen = len;
-
- /* Read a block from the tape */
- len = read (devfd, buf, sizeof(buf));
- if (len < 0)
- {
- printf ("tapecopy: Error reading %s: %s\n",
- devname, strerror(errno));
- obtain_status (devname, devfd);
- exit (8);
- }
-
- /* Check for tape mark */
- if (len == 0)
- {
- /* Print summary of current file */
- printf ("File %u: Blocks=%u, block size min=%u, max=%u\n",
- fileno, blkcount, minblksz, maxblksz);
-
- /* Write tape mark to output file */
- if (outfd >= 0)
- {
- /* Build block header for tape mark */
- awshdr.curblkl[0] = 0;
- awshdr.curblkl[1] = 0;
- awshdr.prvblkl[0] = prevlen & 0xFF;
- awshdr.prvblkl[1] = (prevlen >> 8) & 0xFF;
- awshdr.flags1 = AWSTAPE_FLAG1_TAPEMARK;
- awshdr.flags2 = 0;
-
- /* Write block header to output file */
- rc = write (outfd, &awshdr, sizeof(AWSTAPE_BLKHDR));
- if (rc < sizeof(AWSTAPE_BLKHDR))
- {
- printf ("tapecopy: Error writing %s: %s\n",
- filename, strerror(errno));
- exit (9);
- } /* end if(rc) */
-
- } /* end if(outfd) */
-
- /* Reset counters for next file */
- fileno++;
- minblksz = 0;
- maxblksz = 0;
- blkcount = 0;
-
- /* Determine whether end of tape has been read */
- rc = obtain_status (devname, devfd);
- if (rc == 0) continue;
- if (rc > 0) printf ("End of tape\n");
- break;
-
- } /* end if(tapemark) */
-
- /* Count blocks and block sizes */
- blkcount++;
- if (len > maxblksz) maxblksz = len;
- if (minblksz == 0 || len < minblksz) minblksz = len;
-
- /* Print standard labels */
- if (len == 80 && blkcount < 4
- && (memcmp(buf, vollbl, 3) == 0
- || memcmp(buf, hdrlbl, 3) == 0
- || memcmp(buf, eoflbl, 3) == 0
- || memcmp(buf, eovlbl, 3) == 0))
- {
- for (i=0; i < 80; i++)
- labelrec[i] = ebcdic_to_ascii[buf[i]];
- labelrec[i] = '\0';
- printf ("%s\n", labelrec);
- }
- else
- {
- printf ("File %u: Block %u\r", fileno, blkcount);
- }
-
- /* Write block to output file */
- if (outfd >= 0)
- {
- /* Build the block header */
- awshdr.curblkl[0] = len & 0xFF;
- awshdr.curblkl[1] = (len >> 8) & 0xFF;
- awshdr.prvblkl[0] = prevlen & 0xFF;
- awshdr.prvblkl[1] = (prevlen >> 8) & 0xFF;
- awshdr.flags1 = AWSTAPE_FLAG1_NEWREC
- | AWSTAPE_FLAG1_ENDREC;
- awshdr.flags2 = 0;
-
- /* Write block header to output file */
- rc = write (outfd, &awshdr, sizeof(AWSTAPE_BLKHDR));
- if (rc < sizeof(AWSTAPE_BLKHDR))
- {
- printf ("tapecopy: Error writing %s: %s\n",
- filename, strerror(errno));
- exit (10);
- } /* end if(rc) */
-
- /* Write data block to output file */
- rc = write (outfd, buf, len);
- if (rc < len)
- {
- printf ("tapecopy: Error writing %s: %s\n",
- filename, strerror(errno));
- exit (11);
- } /* end if(rc) */
-
- } /* end if(outfd) */
-
- } /* end while */
-
- /* Close files and exit */
- close (devfd);
- if (filename != NULL) close (outfd);
+ /* Display the program identification message */
+
+ printf("Tape copy is broken, sorry\n");
return 0;
} /* end function main */
|