linux-and-64bit-cleanup-20050710
[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 <sys/types.h
11 #include <sys/file.h>
12 #ifdef  AFS_AIX32_ENV
13 #include <signal.h>
14 #endif
15
16 #define BLKSIZE (4096+24)       /* actual block size on our backup tapes */
17
18 afs_int32
19 glong(cp, index)
20      int index;
21      char *cp;
22 {
23     afs_int32 temp;
24     memcpy(&temp, cp + index * 4, sizeof(afs_int32));
25     return temp;
26 }
27
28 #include "AFS_component_version_number.c"
29
30 main(argc, argv)
31      int argc;
32      char **argv;
33 {
34     char tbuffer[10000];
35     int fd;
36     register afs_int32 code;
37     register char *lp;
38     afs_int32 count;
39
40 #ifdef  AFS_AIX32_ENV
41     /*
42      * The following signal action for AIX is necessary so that in case of a 
43      * crash (i.e. core is generated) we can include the user's data section 
44      * in the core dump. Unfortunately, by default, only a partial core is
45      * generated which, in many cases, isn't too useful.
46      */
47     struct sigaction nsa;
48
49     sigemptyset(&nsa.sa_mask);
50     nsa.sa_handler = SIG_DFL;
51     nsa.sa_flags = SA_FULLDUMP;
52     sigaction(SIGABRT, &nsa, NULL);
53     sigaction(SIGSEGV, &nsa, NULL);
54 #endif
55     fd = open(argv[1], O_RDONLY, 0);
56     if (fd < 0) {
57         perror("tape open");
58         exit(1);
59     }
60     for (count = 0;; count++) {
61         code = read(fd, tbuffer, BLKSIZE);
62         if (code == 0)
63             printf("***EOF***\n");
64         else if (code != BLKSIZE) {
65             printf("failed to read correct number of bytes, read %d\n", code);
66             if (code < 0)
67                 perror("read");
68             exit(1);
69         } else {
70             printf("Block %d is:\n", count);
71             lp = tbuffer;
72             printf("%08x %08x %08x %08x %08x %08x %08x %08x\n", glong(lp, 0),
73                    glong(lp, 1), glong(lp, 2), glong(lp, 3), glong(lp, 4),
74                    glong(lp, 5), glong(lp, 6), glong(lp, 7));
75             printf("%08x %08x %08x %08x %08x %08x %08x %08x\n", glong(lp, 8),
76                    glong(lp, 9), glong(lp, 10), glong(lp, 11), glong(lp, 12),
77                    glong(lp, 13), glong(lp, 14), glong(lp, 15));
78         }
79     }
80 }