2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afsconfig.h>
12 #include <afs/param.h>
22 typedef struct dirhandle {
28 static void OpenDir(char *name, dirhandle *dir);
29 static void CreateDir(char *name, dirhandle *dir);
34 printf("Usage: dtest <command [args]>, where command is one of:\n");
35 printf("-l file - lists directory in file\n");
36 printf("-c file - checks directory in file\n");
37 printf("-s ifile ofile - salvages directory in ifile, places in ofile\n");
39 ("-f file name count - creates count names based on \"name\" in directory in file\n");
40 printf("-d file name - delete name from directory in file\n");
41 printf("-r file name - lookup name in directory\n");
42 printf("-a file name - add name to directory in file\n");
47 LookupDir(char *dname, char *ename)
54 code = Lookup(&dir, ename, fid);
56 printf("lookup code %d\n", code);
58 printf("Found fid %ld.%ld for file '%s'\n", fid[1], fid[2], ename);
64 AddEntry(char *dname, char *ename)
70 fid[1] = fidCounter++;
73 code = Create(&dir, ename, fid);
75 printf("create code %d\n", code);
80 ListEntry(void * handle, char *name, afs_int32 vnode, afs_int32 unique)
82 printf("%s\t%ld\t%ld\n", name, afs_printable_int32_ld(vnode),
83 afs_printable_int32_ld(unique));
93 EnumerateDir(&dir, ListEntry, 0);
102 printf("Directory ok.\n");
104 printf("Directory bad\n");
108 SalvageDir(char *iname, char *oname)
111 afs_int32 myFid[3], parentFid[3];
114 if (Lookup(&in, ".", myFid) || Lookup(&in, "..", parentFid)) {
115 printf("Lookup of \".\" and/or \"..\" failed: ");
116 printf("%d %d %d %d\n", myFid[1], myFid[2], parentFid[1],
118 printf("Directory cannnot be salvaged\n");
120 CreateDir(oname, &out);
121 DirSalvage(&in, &out, myFid[1], myFid[2], parentFid[1], parentFid[2]);
126 DelTest(char *dname, char *ename)
131 OpenDir(dname, &dir);
132 code = Delete(&dir, ename);
134 printf("delete code is %d\n", code);
139 CRTest(char *dname, char *ename, int count)
147 CreateDir(dname, &dir);
148 memset(fid, 0, sizeof(fid));
149 MakeDir(&dir, fid, fid);
150 for (i = 0; i < count; i++) {
151 sprintf(tbuffer, "%s%d", ename, i);
152 fid[1] = fidCounter++;
154 code = Create(&dir, tbuffer, &fid);
160 printf("code for '%s' is %d\n", tbuffer, code);
168 OpenDir(char *name, dirhandle *dir)
170 dir->fd = open(name, O_RDWR, 0666);
172 printf("Couldn't open %s\n", name);
179 CreateDir(char *name, dirhandle *dir)
181 dir->fd = open(name, O_CREAT | O_RDWR | O_TRUNC, 0666);
184 printf("Couldn't create %s\n", name);
190 ReallyRead(dirhandle *dir, int block, char *data)
193 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
195 code = read(dir->fd, data, PAGESIZE);
198 if (code != PAGESIZE)
204 ReallyWrite(dirhandle *dir, int block, char *data)
207 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
209 code = write(dir->fd, data, PAGESIZE);
212 if (code != PAGESIZE)
218 FidZap(dirhandle *dir)
230 FidEq(dirhandle *dir1, dirhandle *dir2)
232 return (dir1->uniq == dir2->uniq);
236 FidVolEq(long *afid, long *bfid)
242 FidCpy(dirhandle *todir, dirhandle *fromdir)
250 printf("Something died with this message: %s\n", msg);
254 Log(const char *fmt, ...)
264 main(int argc, char **argv)
273 switch ((*argv++)[1]) {
281 SalvageDir(*argv, argv[1]);
284 CRTest(*argv, argv[1], atoi(argv[2]));
287 DelTest(*argv, argv[1]);
290 LookupDir(*argv, argv[1]);
293 AddEntry(*argv, argv[1]);