Commit | Line | Data |
---|---|---|
805e021f CE |
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 | /* nicreate | |
11 | * Test "inode" creation in the user space file system. | |
12 | */ | |
13 | ||
14 | #include <afsconfig.h> | |
15 | #include <afs/param.h> | |
16 | ||
17 | ||
18 | #ifdef AFS_NAMEI_ENV | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <errno.h> | |
22 | #include <fcntl.h> | |
23 | #include <fcntl.h> | |
24 | #include <sys/stat.h> | |
25 | #include <lock.h> | |
26 | #include <afs/afsutil.h> | |
27 | #include "nfs.h" | |
28 | #include <afs/afsint.h> | |
29 | #include "ihandle.h" | |
30 | #include "vnode.h" | |
31 | #include "volume.h" | |
32 | #include "viceinode.h" | |
33 | #include "voldefs.h" | |
34 | #include "partition.h" | |
35 | #include <dirent.h> | |
36 | ||
37 | ||
38 | char *prog = "nincdec"; | |
39 | IHandle_t *GetLinkHandle(char *part, int volid); | |
40 | ||
41 | ||
42 | void | |
43 | Usage(void) | |
44 | { | |
45 | printf("Usage: %s <part> <volid> <-i ino | -v vno uniq tag> <inc|dec>\n", | |
46 | prog); | |
47 | exit(1); | |
48 | } | |
49 | ||
50 | main(int ac, char **av) | |
51 | { | |
52 | char *part; | |
53 | int volid; | |
54 | Inode ino; | |
55 | Inode vno; | |
56 | Inode tag; | |
57 | Inode uniq; | |
58 | int code; | |
59 | IHandle_t *lh; | |
60 | int do_inc = -1; | |
61 | char *incdecarg; | |
62 | int i; | |
63 | ||
64 | ||
65 | if (ac < 5) | |
66 | Usage(); | |
67 | ||
68 | part = av[1]; | |
69 | volid = atoi(av[2]); | |
70 | ||
71 | i = 4; | |
72 | if (!strcmp(av[3], "-i")) { | |
73 | code = sscanf(av[i++], "%Lu", &ino); | |
74 | if (code != 1) { | |
75 | printf("Failed to get inode from %s\n", av[4]); | |
76 | exit(1); | |
77 | } | |
78 | } else if (!strcmp(av[3], "-v")) { | |
79 | vno = (int64_t) atoi(av[i++]); | |
80 | vno &= 0x3ffffff; | |
81 | tag = (int64_t) atoi(av[i++]); | |
82 | uniq = (int64_t) atoi(av[i++]); | |
83 | ino = uniq; | |
84 | ino |= tag << 32; | |
85 | ino |= vno << 35; | |
86 | printf("ino=%Lu\n", ino); | |
87 | } else { | |
88 | printf("Expected \"-i\" or \"-v\" for inode value\n"); | |
89 | Usage(); | |
90 | } | |
91 | ||
92 | incdecarg = av[i++]; | |
93 | if (!strcmp(incdecarg, "dec")) | |
94 | do_inc = 0; | |
95 | else if (!strcmp(incdecarg, "inc")) | |
96 | do_inc = 1; | |
97 | else { | |
98 | printf("%s: Expected \"inc\" or \"dec\"\n", incdecarg); | |
99 | Usage(); | |
100 | } | |
101 | ||
102 | ||
103 | lh = GetLinkHandle(part, volid); | |
104 | if (!lh) { | |
105 | printf("Failed to get link handle, exiting\n"); | |
106 | exit(1); | |
107 | } | |
108 | ||
109 | if (do_inc) | |
110 | code = namei_inc(lh, ino, volid); | |
111 | else | |
112 | code = namei_dec(lh, ino, volid); | |
113 | ||
114 | printf("namei_%s returned %d\n", do_inc ? "inc" : "dec", code); | |
115 | ||
116 | exit(0); | |
117 | ||
118 | } | |
119 | ||
120 | #endif /* AFS_NAMEI_ENV */ |