From: Simon Wilkinson Date: Mon, 16 Mar 2009 13:28:55 +0000 (+0000) Subject: dir-prototypes-20090316 X-Git-Tag: openafs-devel-1_5_61~472 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=4fdda50ca7ea47d5b4b8a5cd31797b527deb148f dir-prototypes-20090316 LICENSE IPL10 FIXES 124242 prototype the dir directory --- diff --git a/src/dir/buffer.c b/src/dir/buffer.c index 9f795e4..b46df54 100644 --- a/src/dir/buffer.c +++ b/src/dir/buffer.c @@ -71,7 +71,24 @@ int nbuffers; int timecounter; static int calls = 0, ios = 0; -struct buffer *newslot(); +struct buffer *newslot(afs_int32 *afid, afs_int32 apage, + struct buffer *lp); + +/* XXX - This sucks. The correct prototypes for these functions are ... + * + * extern void FidZero(DirHandle *); + * extern int FidEq(DirHandle *a, DirHandle *b); + * extern int ReallyRead(DirHandle *a, int block, char *data); + */ + +extern void FidZero(afs_int32 *file); +extern int FidEq(afs_int32 *a, afs_int32 *b); +extern int ReallyRead(afs_int32 *file, int block, char *data); +extern int ReallyWrite(afs_int32 *file, int block, char *data); +extern void FidZap(afs_int32 *file); +extern int FidVolEq(afs_int32 *file, afs_int32 vid); +extern void FidCpy(afs_int32 *tofile, afs_int32 *fromfile); +extern void Die(char *msg); int DStat(int *abuffers, int *acalls, int *aios) @@ -135,7 +152,7 @@ DRead(register afs_int32 *fid, register int page) * macros. With the use of these LRU queues, the old one-cache is * probably obsolete. */ - if (tb = phTable[pHash(fid)]) { /* ASSMT HERE */ + if ((tb = phTable[pHash(fid)])) { /* ASSMT HERE */ if (bufmatch(tb)) { ObtainWriteLock(&tb->lock); tb->lockers++; @@ -145,7 +162,7 @@ DRead(register afs_int32 *fid, register int page) return tb->data; } else { bufhead = &(phTable[pHash(fid)]); - while (tb2 = tb->hashNext) { + while ((tb2 = tb->hashNext)) { if (bufmatch(tb2)) { buf_Front(bufhead, tb, tb2); ObtainWriteLock(&tb2->lock); @@ -155,7 +172,7 @@ DRead(register afs_int32 *fid, register int page) ReleaseWriteLock(&tb2->lock); return tb2->data; } - if (tb = tb2->hashNext) { /* ASSIGNMENT HERE! */ + if ((tb = tb2->hashNext)) { /* ASSIGNMENT HERE! */ if (bufmatch(tb)) { buf_Front(bufhead, tb2, tb); ObtainWriteLock(&tb->lock); @@ -369,7 +386,7 @@ DFlushEntry(register afs_int32 *fid) } int -DFlush() +DFlush(void) { /* Flush all the modified buffers. */ register int i; diff --git a/src/dir/dir.c b/src/dir/dir.c index 133a497..a6ca6bf 100644 --- a/src/dir/dir.c +++ b/src/dir/dir.c @@ -53,8 +53,8 @@ RCSID /* afs_buffer.c */ /* These are needed because afs_prototypes.h is not included here */ -extern void *DRead(); -extern void *DNew(); +extern void *DRead(struct dcache *adc, int page); +extern void *DNew(struct dcache *adc, int page); #else /* !defined(UKERNEL) */ #include "afs/stds.h" @@ -62,8 +62,8 @@ extern void *DNew(); /* afs_buffer.c */ /* These are needed because afs_prototypes.h is not included here */ -extern void *DRead(); -extern void *DNew(); +extern void *DRead(register afs_int32 *fid, register int page); +extern void *DNew(register afs_int32 *fid, register int page); #endif /* !defined(UKERNEL) */ #include "afs/afs_osi.h" @@ -140,8 +140,8 @@ Create(void *dir, char *entry, void *voidfid) /* First check if file already exists. */ ep = FindItem(dir, entry, &pp); if (ep) { - DRelease(ep, 0); - DRelease(pp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)pp, 0); return EEXIST; } blobs = NameBlobs(entry); /* number of entries required */ @@ -159,14 +159,14 @@ Create(void *dir, char *entry, void *voidfid) /* Now we just have to thread it on the hash table list. */ dhp = (struct DirHeader *)DRead(dir, 0); if (!dhp) { - DRelease(ep, 1); + DRelease((struct buffer *)ep, 1); return EIO; } i = DirHash(entry); ep->next = dhp->hashTable[i]; dhp->hashTable[i] = htons(firstelt); - DRelease(dhp, 1); - DRelease(ep, 1); + DRelease((struct buffer *)dhp, 1); + DRelease((struct buffer *)ep, 1); return 0; } @@ -187,7 +187,7 @@ Length(void *dir) if (dhp->alloMap[i] != EPP) ctr++; } - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return ctr * AFS_PAGESIZE; } @@ -202,10 +202,10 @@ Delete(void *dir, char *entry) if (firstitem == 0) return ENOENT; *previtem = firstitem->next; - DRelease(previtem, 1); + DRelease((struct buffer *)previtem, 1); index = DVOffset(firstitem) / 32; nitems = NameBlobs(firstitem->name); - DRelease(firstitem, 0); + DRelease((struct buffer *)firstitem, 0); FreeBlobs(dir, index, nitems); return 0; } @@ -247,7 +247,7 @@ FindBlobs(void *dir, int nblobs) } pp = (struct PageHeader *)DRead(dir, i); /* read the page in. */ if (!pp) { - DRelease(dhp, 1); + DRelease((struct buffer *)dhp, 1); break; } for (j = 0; j <= EPP - nblobs; j++) { @@ -266,17 +266,17 @@ FindBlobs(void *dir, int nblobs) * and free up any resources we've got allocated. */ if (i < MAXPAGES) dhp->alloMap[i] -= nblobs; - DRelease(dhp, 1); + DRelease((struct buffer *)dhp, 1); for (k = 0; k < nblobs; k++) pp->freebitmap[(j + k) >> 3] |= 1 << ((j + k) & 7); - DRelease(pp, 1); + DRelease((struct buffer *)pp, 1); return j + i * EPP; } - DRelease(pp, 0); /* This dir page is unchanged. */ + DRelease((struct buffer *)pp, 0); /* This dir page is unchanged. */ } } /* If we make it here, the directory is full. */ - DRelease(dhp, 1); + DRelease((struct buffer *)dhp, 1); return -1; } @@ -294,7 +294,7 @@ AddPage(void *dir, int pageno) pp->freebitmap[0] = 0x01; for (i = 1; i < EPP / 8; i++) /* It's a constant */ pp->freebitmap[i] = 0; - DRelease(pp, 1); + DRelease((struct buffer *)pp, 1); } /* Free a whole bunch of directory entries. */ @@ -313,13 +313,13 @@ FreeBlobs(void *dir, register int firstblob, int nblobs) return; if (page < MAXPAGES) dhp->alloMap[page] += nblobs; - DRelease(dhp, 1); + DRelease((struct buffer *)dhp, 1); pp = (struct PageHeader *)DRead(dir, page); if (pp) for (i = 0; i < nblobs; i++) pp->freebitmap[(firstblob + i) >> 3] &= ~(1 << ((firstblob + i) & 7)); - DRelease(pp, 1); + DRelease((struct buffer *)pp, 1); } /* @@ -345,7 +345,7 @@ MakeDir(void *dir, afs_int32 * me, afs_int32 * parent) dhp->alloMap[i] = EPP; for (i = 0; i < NHASHENT; i++) dhp->hashTable[i] = 0; - DRelease(dhp, 1); + DRelease((struct buffer *)dhp, 1); Create(dir, ".", me); Create(dir, "..", parent); /* Virtue is its own .. */ return 0; @@ -363,10 +363,10 @@ Lookup(void *dir, char *entry, void *voidfid) firstitem = FindItem(dir, entry, &previtem); if (firstitem == 0) return ENOENT; - DRelease(previtem, 0); + DRelease((struct buffer *)previtem, 0); fid[1] = ntohl(firstitem->fid.vnode); fid[2] = ntohl(firstitem->fid.vunique); - DRelease(firstitem, 0); + DRelease((struct buffer *)firstitem, 0); return 0; } @@ -382,17 +382,19 @@ LookupOffset(void *dir, char *entry, void *voidfid, long *offsetp) firstitem = FindItem(dir, entry, &previtem); if (firstitem == 0) return ENOENT; - DRelease(previtem, 0); + DRelease((struct buffer *)previtem, 0); fid[1] = ntohl(firstitem->fid.vnode); fid[2] = ntohl(firstitem->fid.vunique); if (offsetp) *offsetp = DVOffset(firstitem); - DRelease(firstitem, 0); + DRelease((struct buffer *)firstitem, 0); return 0; } int -EnumerateDir(void *dir, int (*hookproc) (), void *hook) +EnumerateDir(void *dir, int (*hookproc) (void *dir, char *name, + afs_int32 vnode, afs_int32 unique), + void *hook) { /* Enumerate the contents of a directory. * Break when hook function returns non 0. @@ -417,7 +419,7 @@ EnumerateDir(void *dir, int (*hookproc) (), void *hook) if (!ep) { if (DErrno) { /* we failed, return why */ - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return DErrno; } break; @@ -426,12 +428,12 @@ EnumerateDir(void *dir, int (*hookproc) (), void *hook) num = ntohs(ep->next); code = (*hookproc) (hook, ep->name, ntohl(ep->fid.vnode), ntohl(ep->fid.vunique)); - DRelease(ep, 0); + DRelease((struct buffer *)ep, 0); if (code) break; } } - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -455,15 +457,15 @@ IsEmpty(void *dir) if (!ep) break; if (strcmp(ep->name, "..") && strcmp(ep->name, ".")) { - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 1; } num = ntohs(ep->next); - DRelease(ep, 0); + DRelease((struct buffer *)ep, 0); } } - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -512,12 +514,12 @@ FindItem(void *dir, char *ename, unsigned short **previtem) return 0; if (dhp->hashTable[i] == 0) { /* no such entry */ - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } tp = GetBlob(dir, (u_short) ntohs(dhp->hashTable[i])); if (!tp) { - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } lp = &(dhp->hashTable[i]); @@ -528,16 +530,16 @@ FindItem(void *dir, char *ename, unsigned short **previtem) *previtem = lp; return tp; } - DRelease(lp, 0); + DRelease((struct buffer *)lp, 0); lp = &(tp->next); if (tp->next == 0) { /* The end of the line */ - DRelease(lp, 0); /* Release all locks. */ + DRelease((struct buffer *)lp, 0); /* Release all locks. */ return 0; } tp = GetBlob(dir, (u_short) ntohs(tp->next)); if (!tp) { - DRelease(lp, 0); + DRelease((struct buffer *)lp, 0); return 0; } } diff --git a/src/dir/dir.h b/src/dir/dir.h index 238c670..998f70e 100644 --- a/src/dir/dir.h +++ b/src/dir/dir.h @@ -101,7 +101,7 @@ extern struct DirEntry *GetBlob(void *dir, afs_int32 blobno); extern int DirHash(register char *string); extern int DStat(int *abuffers, int *acalls, int *aios); -extern void DRelease(); +extern void DRelease(struct buffer *bp, int flag); extern int DVOffset(register void *ap); extern int DFlushVolume(register afs_int32 vid); extern int DFlushEntry(register afs_int32 *fid); @@ -110,8 +110,8 @@ extern int DFlushEntry(register afs_int32 *fid); in afs_prototypes.h */ #ifndef KERNEL extern int DInit(int abuffers); -extern void *DRead(); -extern int DFlush(); +extern void *DRead(register afs_int32 *fid, register int page); +extern int DFlush(void); extern void *DNew(register afs_int32 *fid, register int page); extern void DZap(register afs_int32 *fid); #endif diff --git a/src/dir/salvage.c b/src/dir/salvage.c index 4b867e0..75f5bc3 100644 --- a/src/dir/salvage.c +++ b/src/dir/salvage.c @@ -7,7 +7,11 @@ * directory or online at http://www.openafs.org/dl/license10.html */ -/* This is the directory salvager. It consists of two routines. The first, DirOK, checks to see if the directory looks good. If the directory does NOT look good, the approved procedure is to then call Salvage, which copies all the good entries from the damaged dir into a new directory. */ +/* This is the directory salvager. It consists of two routines. The first, + * DirOK, checks to see if the directory looks good. If the directory does + * NOT look good, the approved procedure is to then call Salvage, which + * copies all the good entries from the damaged dir into a new directory. + */ #include #include @@ -26,18 +30,25 @@ RCSID #include #include "dir.h" +/* Defined in vol/vol-salvage.c */ +extern void Log(const char *format, ...); +/* Defined in vol/physio.c */ +extern void Die(char *); + #define printf Log /* To make it work with volume salvager */ -/* This routine is called with one parameter, the id (the same thing that is passed to physio or the buffer package) of a directory to check. It returns 1 if the directory looks good, and 0 otherwise. */ +/* This routine is called with one parameter, the id (the same thing that is + * passed to physio or the buffer package) of a directory to check. It + * returns 1 if the directory looks good, and 0 otherwise. */ #define MAXENAME 256 extern afs_int32 DErrno; -/* figure out how many pages in use in a directory, given ptr to its (locked) header */ -static -ComputeUsedPages(dhp) - register struct DirHeader *dhp; +/* figure out how many pages in use in a directory, given ptr to its (locked) + * header */ +static int +ComputeUsedPages(register struct DirHeader *dhp) { register afs_int32 usedPages, i; @@ -63,8 +74,7 @@ ComputeUsedPages(dhp) * false if we *know* that the dir is bad. */ int -DirOK(file) - char *file; +DirOK(void *file) { struct DirHeader *dhp; struct PageHeader *pp; @@ -98,7 +108,7 @@ DirOK(file) /* Check magic number for first page */ if (dhp->header.tag != htons(1234)) { printf("Bad first pageheader magic number.\n"); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -119,13 +129,13 @@ DirOK(file) * two must exist for "." and ".." */ printf("The dir header alloc map for page %d is bad.\n", i); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } else { if ((j < 0) || (j > EPP)) { printf("The dir header alloc map for page %d is bad.\n", i); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } @@ -136,7 +146,7 @@ DirOK(file) printf ("A partially-full page occurs in slot %d, after the dir end.\n", i); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } else if (j == EPP) { /* is this the last page */ @@ -154,7 +164,7 @@ DirOK(file) if (usedPages < up) { printf ("Count of used directory pages does not match count in directory header\n"); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -166,7 +176,7 @@ DirOK(file) /* Read the page header */ pp = (struct PageHeader *)DRead(file, i); if (!pp) { - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); if (DErrno != 0) { /* couldn't read page, but not because it wasn't there permanently */ printf("Failed to read dir page %d (errno %d)\n", i, DErrno); @@ -180,8 +190,8 @@ DirOK(file) /* check the tag field */ if (pp->tag != htons(1234)) { printf("Directory page %d has a bad magic number.\n", i); - DRelease(pp, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)pp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -215,12 +225,12 @@ DirOK(file) printf ("Header alloMap count doesn't match count in freebitmap for page %d.\n", i); - DRelease(pp, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)pp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } - DRelease(pp, 0); + DRelease((struct buffer *)pp, 0); } /* Initialize the in-memory freebit map for all pages. */ @@ -248,7 +258,7 @@ DirOK(file) /* Verify that the entry is within range */ if (entry < 0 || entry >= maxents) { printf("Out-of-range hash id %d in chain %d.\n", entry, i); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -262,11 +272,11 @@ DirOK(file) */ printf("Could not get dir blob %d (errno %d)\n", entry, DErrno); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); Die("dirok3"); } printf("Invalid hash id %d in chain %d.\n", entry, i); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } ne = ntohs(ep->next); @@ -274,8 +284,8 @@ DirOK(file) /* There can't be more than maxents entries */ if (++entcount >= maxents) { printf("Directory's hash chain %d is circular.\n", i); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -283,8 +293,8 @@ DirOK(file) if (ep->name[0] == '\000') { printf("Dir entry %x in chain %d has bogus (null) name.\n", (int)ep, i); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -292,8 +302,8 @@ DirOK(file) if (ep->flag != FFIRST) { printf("Dir entry %x in chain %d has bogus flag field.\n", (int)ep, i); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -302,8 +312,8 @@ DirOK(file) if (j >= MAXENAME) { /* MAXENAME counts the null */ printf("Dir entry %x in chain %d has too-long name.\n", (int)ep, i); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -320,8 +330,8 @@ DirOK(file) printf ("Dir entry %x should be in hash bucket %d but IS in %d.\n", (int)ep, j, i); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -333,8 +343,8 @@ DirOK(file) printf ("Dir entry %x, index 13 has name '%s' should be '.'\n", (int)ep, ep->name); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } @@ -347,15 +357,15 @@ DirOK(file) printf ("Dir entry %x, index 14 has name '%s' should be '..'\n", (int)ep, ep->name); - DRelease(ep, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)ep, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } /* CHECK FOR DUPLICATE NAMES? */ - DRelease(ep, 0); + DRelease((struct buffer *)ep, 0); } } @@ -363,7 +373,7 @@ DirOK(file) if (!havedot || !havedotdot) { printf ("Directory entry '.' or '..' does not exist or is in the wrong index.\n"); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } @@ -377,7 +387,7 @@ DirOK(file) printf ("Failed on second attempt to read dir page %d (errno %d)\n", i, DErrno); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); /* if DErrno is 0, then the dir is really bad, and we return dir *not* OK. * otherwise, we want to return true (1), meaning the dir isn't known * to be bad (we can't tell, since I/Os are failing. @@ -394,17 +404,17 @@ DirOK(file) printf ("Entry freebitmap error, page %d, map offset %d, %x should be %x.\n", i, j, pp->freebitmap[j], eaMap[count + j]); - DRelease(pp, 0); - DRelease(dhp, 0); + DRelease((struct buffer *)pp, 0); + DRelease((struct buffer *)dhp, 0); return 0; } } - DRelease(pp, 0); + DRelease((struct buffer *)pp, 0); } /* Finally cleanup and return. */ - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 1; } @@ -417,9 +427,8 @@ DirOK(file) * parent directory. */ int -DirSalvage(fromFile, toFile, vn, vu, pvn, pvu) - char *fromFile, *toFile; - afs_int32 vn, vu, pvn, pvu; +DirSalvage(char *fromFile, char *toFile, afs_int32 vn, afs_int32 vu, + afs_int32 pvn, afs_int32 pvu) { /* First do a MakeDir on the target. */ afs_int32 dot[3], dotdot[3], lfid[3], code, usedPages; @@ -472,7 +481,7 @@ DirSalvage(fromFile, toFile, vn, vu, pvn, pvu) printf ("can't continue down hash chain (entry %d, errno %d)\n", entry, DErrno); - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return DErrno; } printf @@ -493,15 +502,15 @@ DirSalvage(fromFile, toFile, vn, vu, pvn, pvu) printf ("Create of %s returned code %d, skipping to next hash chain.\n", tname, code); - DRelease(ep, 0); + DRelease((struct buffer *)ep, 0); break; } } - DRelease(ep, 0); + DRelease((struct buffer *)ep, 0); } } /* Clean up things. */ - DRelease(dhp, 0); + DRelease((struct buffer *)dhp, 0); return 0; }