Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / butc / tdump.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #define BLKSIZE (4096+24) /* actual block size on our backup tapes */
16
17 afs_int32
18 glong(cp, index)
19 int index;
20 char *cp;
21 {
22 afs_int32 temp;
23 memcpy(&temp, cp + index * 4, sizeof(afs_int32));
24 return temp;
25 }
26
27 #include "AFS_component_version_number.c"
28
29 main(argc, argv)
30 int argc;
31 char **argv;
32 {
33 char tbuffer[10000];
34 int fd;
35 afs_int32 code;
36 char *lp;
37 afs_int32 count;
38
39 #ifdef AFS_AIX32_ENV
40 /*
41 * The following signal action for AIX is necessary so that in case of a
42 * crash (i.e. core is generated) we can include the user's data section
43 * in the core dump. Unfortunately, by default, only a partial core is
44 * generated which, in many cases, isn't too useful.
45 */
46 struct sigaction nsa;
47
48 sigemptyset(&nsa.sa_mask);
49 nsa.sa_handler = SIG_DFL;
50 nsa.sa_flags = SA_FULLDUMP;
51 sigaction(SIGABRT, &nsa, NULL);
52 sigaction(SIGSEGV, &nsa, NULL);
53 #endif
54 fd = open(argv[1], O_RDONLY, 0);
55 if (fd < 0) {
56 perror("tape open");
57 exit(1);
58 }
59 for (count = 0;; count++) {
60 code = read(fd, tbuffer, BLKSIZE);
61 if (code == 0)
62 printf("***EOF***\n");
63 else if (code != BLKSIZE) {
64 printf("failed to read correct number of bytes, read %d\n", code);
65 if (code < 0)
66 perror("read");
67 exit(1);
68 } else {
69 printf("Block %d is:\n", count);
70 lp = tbuffer;
71 printf("%08x %08x %08x %08x %08x %08x %08x %08x\n", glong(lp, 0),
72 glong(lp, 1), glong(lp, 2), glong(lp, 3), glong(lp, 4),
73 glong(lp, 5), glong(lp, 6), glong(lp, 7));
74 printf("%08x %08x %08x %08x %08x %08x %08x %08x\n", glong(lp, 8),
75 glong(lp, 9), glong(lp, 10), glong(lp, 11), glong(lp, 12),
76 glong(lp, 13), glong(lp, 14), glong(lp, 15));
77 }
78 }
79 }