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>
20 typedef struct DirHandle {
26 static void OpenDir(char *name, dirhandle *dir);
27 static void CreateDir(char *name, dirhandle *dir);
32 printf("Usage: dtest <command [args]>, where command is one of:\n");
33 printf("-l file - lists directory in file\n");
34 printf("-c file - checks directory in file\n");
35 printf("-s ifile ofile - salvages directory in ifile, places in ofile\n");
37 ("-f file name count - creates count names based on \"name\" in directory in file\n");
38 printf("-d file name - delete name from directory in file\n");
39 printf("-r file name - lookup name in directory\n");
40 printf("-a file name - add name to directory in file\n");
45 LookupDir(char *dname, char *ename)
52 code = afs_dir_Lookup(&dir, ename, fid);
54 printf("lookup code %d\n", code);
56 printf("Found fid %ld.%ld for file '%s'\n", fid[1], fid[2], ename);
62 AddEntry(char *dname, char *ename)
68 fid[1] = fidCounter++;
71 code = afs_dir_Create(&dir, ename, fid);
73 printf("create code %d\n", code);
78 ListEntry(void * handle, char *name, afs_int32 vnode, afs_int32 unique)
80 printf("%s\t%ld\t%ld\n", name, afs_printable_int32_ld(vnode),
81 afs_printable_int32_ld(unique));
91 afs_dir_EnumerateDir(&dir, ListEntry, 0);
100 printf("Directory ok.\n");
102 printf("Directory bad\n");
106 SalvageDir(char *iname, char *oname)
109 afs_int32 myFid[3], parentFid[3];
112 if (afs_dir_Lookup(&in, ".", myFid) ||
113 afs_dir_Lookup(&in, "..", parentFid)) {
114 printf("Lookup of \".\" and/or \"..\" failed: ");
115 printf("%d %d %d %d\n", myFid[1], myFid[2], parentFid[1],
117 printf("Directory cannnot be salvaged\n");
119 CreateDir(oname, &out);
120 DirSalvage(&in, &out, myFid[1], myFid[2], parentFid[1], parentFid[2]);
125 DelTest(char *dname, char *ename)
130 OpenDir(dname, &dir);
131 code = afs_dir_Delete(&dir, ename);
133 printf("delete code is %d\n", code);
138 CRTest(char *dname, char *ename, int count)
146 CreateDir(dname, &dir);
147 memset(fid, 0, sizeof(fid));
148 afs_dir_MakeDir(&dir, fid, fid);
149 for (i = 0; i < count; i++) {
150 sprintf(tbuffer, "%s%d", ename, i);
151 fid[1] = fidCounter++;
153 code = afs_dir_Create(&dir, tbuffer, &fid);
159 printf("code for '%s' is %d\n", tbuffer, code);
167 OpenDir(char *name, dirhandle *dir)
169 dir->fd = open(name, O_RDWR, 0666);
171 printf("Couldn't open %s\n", name);
178 CreateDir(char *name, dirhandle *dir)
180 dir->fd = open(name, O_CREAT | O_RDWR | O_TRUNC, 0666);
183 printf("Couldn't create %s\n", name);
189 ReallyRead(dirhandle *dir, int block, char *data)
192 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
194 code = read(dir->fd, data, PAGESIZE);
197 if (code != PAGESIZE)
203 ReallyWrite(dirhandle *dir, int block, char *data)
206 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
208 code = write(dir->fd, data, PAGESIZE);
211 if (code != PAGESIZE)
217 FidZap(dirhandle *dir)
229 FidEq(dirhandle *dir1, dirhandle *dir2)
231 return (dir1->uniq == dir2->uniq);
235 FidVolEq(long *afid, long *bfid)
241 FidCpy(dirhandle *todir, dirhandle *fromdir)
249 printf("Something died with this message: %s\n", msg);
253 Log(const char *fmt, ...)
263 main(int argc, char **argv)
272 switch ((*argv++)[1]) {
280 SalvageDir(*argv, argv[1]);
283 CRTest(*argv, argv[1], atoi(argv[2]));
286 DelTest(*argv, argv[1]);
289 LookupDir(*argv, argv[1]);
292 AddEntry(*argv, argv[1]);