Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / vol / test / nincdec.c
blob6ad457a5adaa645d62ceca3a328bb9a615e59838
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 */
10 /* nicreate
11 * Test "inode" creation in the user space file system.
14 #include <afsconfig.h>
15 #include <afs/param.h>
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 #include <afs/afs_assert.h>
39 char *prog = "nincdec";
40 IHandle_t *GetLinkHandle(char *part, int volid);
43 void
44 Usage(void)
46 printf("Usage: %s <part> <volid> <-i ino | -v vno uniq tag> <inc|dec>\n",
47 prog);
48 exit(1);
51 main(int ac, char **av)
53 char *part;
54 int volid;
55 Inode ino;
56 Inode vno;
57 Inode tag;
58 Inode uniq;
59 int code;
60 IHandle_t *lh;
61 int do_inc = -1;
62 char *incdecarg;
63 int i;
66 if (ac < 5)
67 Usage();
69 part = av[1];
70 volid = atoi(av[2]);
72 i = 4;
73 if (!strcmp(av[3], "-i")) {
74 code = sscanf(av[i++], "%Lu", &ino);
75 if (code != 1) {
76 printf("Failed to get inode from %s\n", av[4]);
77 exit(1);
79 } else if (!strcmp(av[3], "-v")) {
80 vno = (int64_t) atoi(av[i++]);
81 vno &= 0x3ffffff;
82 tag = (int64_t) atoi(av[i++]);
83 uniq = (int64_t) atoi(av[i++]);
84 ino = uniq;
85 ino |= tag << 32;
86 ino |= vno << 35;
87 printf("ino=%Lu\n", ino);
88 } else {
89 printf("Expected \"-i\" or \"-v\" for inode value\n");
90 Usage();
93 incdecarg = av[i++];
94 if (!strcmp(incdecarg, "dec"))
95 do_inc = 0;
96 else if (!strcmp(incdecarg, "inc"))
97 do_inc = 1;
98 else {
99 printf("%s: Expected \"inc\" or \"dec\"\n", incdecarg);
100 Usage();
104 lh = GetLinkHandle(part, volid);
105 if (!lh) {
106 printf("Failed to get link handle, exiting\n");
107 exit(1);
110 if (do_inc)
111 code = namei_inc(lh, ino, volid);
112 else
113 code = namei_dec(lh, ino, volid);
115 printf("namei_%s returned %d\n", do_inc ? "inc" : "dec", code);
117 exit(0);
121 #endif /* AFS_NAMEI_ENV */