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>
21 typedef struct DirHandle {
27 static void OpenDir(char *name, dirhandle *dir);
28 static void CreateDir(char *name, dirhandle *dir);
33 printf("Usage: dtest <command [args]>, where command is one of:\n");
34 printf("-l file - lists directory in file\n");
35 printf("-c file - checks directory in file\n");
36 printf("-s ifile ofile - salvages directory in ifile, places in ofile\n");
38 ("-f file name count - creates count names based on \"name\" in directory in file\n");
39 printf("-d file name - delete name from directory in file\n");
40 printf("-r file name - lookup name in directory\n");
41 printf("-a file name - add name to directory in file\n");
46 LookupDir(char *dname, char *ename)
53 code = afs_dir_Lookup(&dir, ename, fid);
55 printf("lookup code %d\n", code);
57 printf("Found fid %d.%d for file '%s'\n", fid[1], fid[2], ename);
63 AddEntry(char *dname, char *ename)
69 fid[1] = fidCounter++;
72 code = afs_dir_Create(&dir, ename, fid);
74 printf("create code %d\n", code);
79 ListEntry(void * handle, char *name, afs_int32 vnode, afs_int32 unique)
81 printf("%s\t%ld\t%ld\n", name, afs_printable_int32_ld(vnode),
82 afs_printable_int32_ld(unique));
92 afs_dir_EnumerateDir(&dir, ListEntry, 0);
101 printf("Directory ok.\n");
103 printf("Directory bad\n");
107 SalvageDir(char *iname, char *oname)
110 afs_int32 myFid[3], parentFid[3];
113 if (afs_dir_Lookup(&in, ".", myFid) ||
114 afs_dir_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 = afs_dir_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 afs_dir_MakeDir(&dir, fid, fid);
150 for (i = 0; i < count; i++) {
151 sprintf(tbuffer, "%s%d", ename, i);
152 fid[1] = fidCounter++;
154 code = afs_dir_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)
224 FidZero(afs_int32 *afid)
230 FidEq(dirhandle *dir1, dirhandle *dir2)
232 return (dir1->uniq == dir2->uniq);
236 FidVolEq(afs_int32 *afid, afs_int32 *bfid)
242 FidCpy(dirhandle *todir, dirhandle *fromdir)
250 printf("Something died with this message: %s\n", msg);
255 Log(const char *fmt, ...)
265 main(int argc, char **argv)
274 switch ((*argv++)[1]) {
282 SalvageDir(*argv, argv[1]);
285 CRTest(*argv, argv[1], atoi(argv[2]));
288 DelTest(*argv, argv[1]);
291 LookupDir(*argv, argv[1]);
294 AddEntry(*argv, argv[1]);