Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vol / test / ltlist.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 /* ltlist - a standalone program to dump the link count table. */
11
12 #include <afsconfig.h>
13 #include <afs/param.h>
14
15
16 #include <stdio.h>
17 #ifdef AFS_NT40_ENV
18 #include <windows.h>
19 #include <io.h>
20 #endif
21
22 main(int ac, char **av)
23 {
24 FILE *fp;
25 unsigned short row;
26 int i;
27 int count;
28 int stamp[2];
29
30 if (ac != 2) {
31 printf("Usage ltlist <filename>\n");
32 exit(1);
33 }
34
35 fp = fopen(av[1], "r");
36 if (!fp) {
37 printf("Can't open %s for reading.\n");
38 exit(1);
39 }
40
41 /* Print the magic and version numbers in hex. */
42 count = fread((void *)stamp, 1, 8, fp);
43 if (count != 8) {
44 if (feof(fp)) {
45 printf("Only read %d bytes of %s, wanted 8 for stamp.\n", count,
46 av[1]);
47 } else {
48 #ifdef AFS_NT40_ENV
49 printf("NT Error %d reading 8 bytes from %s\n", GetLastError(),
50 av[1]);
51 #else
52 perror("fread");
53 #endif
54 }
55 exit(1);
56 }
57
58 printf("magic=0x%x, version=0x%x\n", stamp[0], stamp[1]);
59
60 printf("%10s %2s %2s %2s %2s %2s\n", "Vnode", "F1", "F2", "F3", "F4",
61 "F5");
62 i = 0;
63 while (fread((void *)&row, 1, 2, fp)) {
64 printf("%10d %2d %2d %2d %2d %2d\n", i, (int)(row & 0x7),
65 (int)((row >> 3) & 0x7), (int)((row >> 6) & 0x7),
66 (int)((row >> 9) & 0x7), (int)((row >> 12) & 0x7));
67 i++;
68 }
69 }