Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vol / test / nino.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 /*
11 * translate between inode numbers and contents.
12 */
13 #include <afsconfig.h>
14 #include <afs/param.h>
15
16
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include "util/afsutil.h"
20
21 void
22 Usage(void)
23 {
24 printf("Usage: nino <-i ino> | <-c uniq tag vno> | <-a ino_base64>\n");
25 exit(1);
26 }
27
28 void do_contents(int ac, char **av);
29 void do_ino(int ac, char **av);
30 void do_inobase64(int ac, char **av);
31
32
33 main(int ac, char **av)
34 {
35 if (ac < 3)
36 Usage();
37
38 if (!strcmp("-c", av[1]))
39 do_contents(ac, av);
40 else if (!strcmp("-i", av[1]))
41 do_ino(ac, av);
42 else if (!strcmp("-a", av[1]))
43 do_inobase64(ac, av);
44 else
45 Usage();
46 }
47
48 void
49 do_contents(int ac, char **av)
50 {
51 int64_t ino;
52 int64_t vno, tag, uniq;
53 int count;
54 lb64_string_t str;
55
56 if (ac != 5) {
57 printf("Bad argument count for -c option.\n");
58 exit(1);
59 }
60
61 vno = (int64_t) atoi(av[4]);
62 vno &= 0x3ffffff;
63 tag = (int64_t) atoi(av[3]);
64 tag &= 0x7;
65 uniq = (int64_t) atoi(av[2]);
66
67 ino = vno;
68 ino |= tag << 26;
69 ino |= uniq << 32;
70 int64_to_flipbase64(str, ino);
71
72 printf("ino=%Lu, base64=%s\n", ino, str);
73
74 }
75
76 void
77 do_ino(int ac, char **av)
78 {
79 int64_t ino1 = 0;
80 int64_t ino = 0;
81 int64_t ino2 = 0;
82 int vno;
83 lb64_string_t str;
84
85 if (ac != 3) {
86 printf("Bad argument count for -i option.\n");
87 exit(1);
88 }
89
90 ino = (int64_t) - 1;
91 sscanf(av[2], "%qu", &ino);
92 printf("%Lu %Lu %Lu\n", ino, ino1, ino2);
93
94 vno = (int)ino;
95 if (vno == 0x3ffffff)
96 vno = -1;
97 int64_to_flipbase64(str, ino);
98 printf("ino=%Lu, vno=%d, tag=%u, uniq=%u, base64=%s\n", ino, vno,
99 (int)((ino >> 26) & 0x7), (int)((ino >> 32) & 0xffffffff), str);
100
101 }
102
103 void
104 do_inobase64(int ac, char **av)
105 {
106 int64_t ino1 = 0;
107 int64_t ino = 0;
108 int64_t ino2 = 0;
109 int vno;
110
111
112 if (ac != 3) {
113 printf("Bad argument count for -a option.\n");
114 exit(1);
115 }
116
117 ino = flipbase64_to_int64(av[2]);
118
119 vno = (int)ino;
120 if (vno == 0x3ffffff)
121 vno = -1;
122 printf("ino=%Lu, vno=%d, tag=%u, uniq=%u\n", ino, vno,
123 (int)((ino >> 26) & 0x7), (int)((ino >> 32) & 0xffffffff));
124
125 }