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>
26 typedef struct dirhandle {
35 printf("Usage: dtest <command [args]>, where command is one of:\n");
36 printf("-l file - lists directory in file\n");
37 printf("-c file - checks directory in file\n");
38 printf("-s ifile ofile - salvages directory in ifile, places in ofile\n");
40 ("-f file name count - creates count names based on \"name\" in directory in file\n");
41 printf("-d file name - delete name from directory in file\n");
42 printf("-r file name - lookup name in directory\n");
43 printf("-a file name - add name to directory in file\n");
57 switch ((*argv++)[1]) {
65 SalvageDir(*argv, argv[1]);
68 CRTest(*argv, argv[1], atoi(argv[2]));
71 DelTest(*argv, argv[1]);
74 LookupDir(*argv, argv[1]);
77 AddEntry(*argv, argv[1]);
85 LookupDir(dname, ename)
92 code = Lookup(&dir, ename, fid);
94 printf("lookup code %d\n", code);
96 printf("Found fid %d.%d for file '%s'\n", fid[1], fid[2], ename);
101 AddEntry(dname, ename)
107 fid[1] = fidCounter++;
109 OpenDir(dname, &dir);
110 code = Create(&dir, ename, fid);
112 printf("create code %d\n", code);
122 EnumerateDir(&dir, ListEntry, 0);
125 ListEntry(handle, name, vnode, unique)
126 long handle, vnode, unique;
129 printf("%s\t%d\t%d\n", name, vnode, unique);
138 printf("Directory ok.\n");
140 printf("Directory bad\n");
143 SalvageDir(iname, oname)
147 long myFid[3], parentFid[3];
149 if (Lookup(in, ".", myFid) || Lookup(in, "..", parentFid)) {
150 printf("Lookup of \".\" and/or \"..\" failed: ");
151 printf("%d %d %d %d\n", myFid[1], myFid[2], parentFid[1],
153 printf("Directory cannnot be salvaged\n");
155 CreateDir(oname, &out);
156 DirSalvage(&in, &out, myFid[1], myFid[2], parentFid[1], parentFid[2]);
160 DelTest(dname, ename)
167 OpenDir(dname, &dir);
168 code = Delete(&dir, ename);
170 printf("delete code is %d\n", code);
174 CRTest(dname, ename, count)
184 CreateDir(dname, &dir);
185 memset(fid, 0, sizeof(fid));
186 MakeDir(&dir, fid, fid);
187 for (i = 0; i < count; i++) {
188 sprintf(tbuffer, "%s%d", ename, i);
189 fid[1] = fidCounter++;
191 code = Create(&dir, tbuffer, &fid);
197 printf("code for '%s' is %d\n", tbuffer, code);
208 dir->fd = open(name, O_RDWR, 0666);
210 printf("Couldn't open %s\n", name);
220 dir->fd = open(name, O_CREAT | O_RDWR | O_TRUNC, 0666);
223 printf("Couldn't create %s\n", name);
228 ReallyRead(dir, block, data)
234 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
236 code = read(dir->fd, data, PAGESIZE);
239 if (code != PAGESIZE)
244 ReallyWrite(dir, block, data)
250 if (lseek(dir->fd, block * PAGESIZE, 0) == -1)
252 code = write(dir->fd, data, PAGESIZE);
255 if (code != PAGESIZE)
274 dirhandle *dir1, *dir2;
276 return (dir1->uniq == dir2->uniq);
286 FidCpy(todir, fromdir)
287 dirhandle *todir, *fromdir;
295 printf("Something died with this message: %s\n", msg);
298 Log(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
300 printf(a, b, c, d, e, f, g, h, i, j, k, l, m, n);