/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
#include <afs/param.h>
+
+RCSID("$Header$");
+
#ifdef KERNEL
#if !defined(UKERNEL)
#include "../h/types.h"
#include "../h/errno.h"
#endif
#include "../h/time.h"
-#if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX20_ENV)
+#if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_FBSD_ENV)
#include "../h/errno.h"
#else
#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
#if defined(AFS_SUN56_ENV) || defined(AFS_HPUX_ENV)
#include "../afs/sysincludes.h"
#endif
-#ifndef AFS_SGI64_ENV
+#if defined(AFS_FBSD_ENV)
+#include "../h/lock.h"
+#include "../vm/vm.h"
+#include "../vm/vm_extern.h"
+#include "../vm/pmap.h"
+#include "../vm/vm_map.h"
+#endif /* AFS_FBSD_ENV */
+#if !defined(AFS_SGI64_ENV) && !defined(AFS_DARWIN60_ENV)
#include "../h/user.h"
#endif /* AFS_SGI64_ENV */
#include "../h/uio.h"
#endif /* AFS_MACH_ENV */
#endif
#endif
-#ifndef AFS_LINUX20_ENV
-#include "../netinet/in.h"
-#endif
#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
#include "../h/mbuf.h"
#endif
+#ifndef AFS_LINUX20_ENV
+#include "../netinet/in.h"
+#endif
#else /* !defined(UKERNEL) */
+#include "../afs/stds.h"
#include "../afs/sysincludes.h"
#endif /* !defined(UKERNEL) */
#include "../afs/afs_osi.h"
#define IsEmpty afs_dir_IsEmpty
#else /* KERNEL */
-# include <sys/types.h>
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+# include <sys/types.h>
# include <errno.h>
# include "dir.h"
#ifdef AFS_NT40_ENV
#else
#include <netinet/in.h>
#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
#endif /* KERNEL */
afs_int32 DErrno;
char *DRelease();
-static struct DirEntry *FindItem();
-struct DirEntry *GetBlob();
struct DirEntry *DRead();
struct DirEntry *DNew();
-void AddPage();
-void FreeBlobs();
+/* Local static prototypes */
+static struct DirEntry *FindItem (void *dir, char *ename,
+ unsigned short **previtem);
+
-int NameBlobs (name)
-char * name; {/* Find out how many entries are required to store a name. */
+int NameBlobs (char *name)
+{/* Find out how many entries are required to store a name. */
register int i;
i = strlen(name)+1;
return 1+((i+15)>>5);
}
-int Create (dir, entry, vfid)
-char *dir;
-char *entry;
-afs_int32 *vfid; {
- /* Create an entry in a file. Dir is a file representation, while entry is a string name. */
+/* Create an entry in a file. Dir is a file representation, while entry is a string name. */
+
+int Create (void *dir, char *entry, void *voidfid)
+{
+ afs_int32 *vfid = (afs_int32 *) voidfid;
int blobs, firstelt;
register int i;
register struct DirEntry *ep;
- unsigned short *pp;
+ unsigned short *pp = NULL;
register struct DirHeader *dhp;
/* check name quality */
if (*entry == 0) return EINVAL;
/* First check if file already exists. */
- ep = FindItem(dir,entry,&pp);
+ ep = FindItem(dir, entry, &pp);
if (ep) {
DRelease(ep, 0);
DRelease(pp, 0);
return EEXIST;
}
blobs = NameBlobs(entry); /* number of entries required */
- firstelt = FindBlobs(dir,blobs);
+ firstelt = FindBlobs(dir, blobs);
if (firstelt < 0) return EFBIG; /* directory is full */
/* First, we fill in the directory entry. */
- ep = GetBlob(dir,firstelt);
+ ep = GetBlob(dir, firstelt);
if (ep == 0) return EIO;
ep->flag = FFIRST;
ep->fid.vnode = htonl(vfid[1]);
ep->fid.vunique = htonl(vfid[2]);
- strcpy(ep->name,entry);
+ strcpy(ep->name, entry);
/* Now we just have to thread it on the hash table list. */
dhp = (struct DirHeader *) DRead(dir,0);
if (!dhp) {
return 0;
}
-int Length (dir)
-char *dir; {
+int Length (void *dir)
+{
int i,ctr;
struct DirHeader *dhp;
dhp = (struct DirHeader *) DRead(dir,0);
return ctr*AFS_PAGESIZE;
}
-Delete (dir, entry)
-char *dir;
-char *entry; {
+int Delete (void *dir, char *entry)
+{
/* Delete an entry from a directory, including update of all free entry descriptors. */
int nitems, index;
register struct DirEntry *firstitem;
return 0;
}
-FindBlobs (dir,nblobs)
-char *dir;
-int nblobs; {
+int FindBlobs (void *dir, int nblobs)
+{
/* Find a bunch of contiguous entries; at least nblobs in a row. */
register int i, j, k;
- int failed;
+ int failed = 0;
register struct DirHeader *dhp;
struct PageHeader *pp;
int pgcount;
return -1;
}
-void AddPage (dir,pageno)
-char *dir;
-int pageno; {/* Add a page to a directory. */
+void AddPage (void *dir, int pageno)
+{/* Add a page to a directory. */
register int i;
register struct PageHeader *pp;
DRelease(pp,1);
}
-void FreeBlobs(dir,firstblob,nblobs)
-char *dir;
-register int firstblob;
-int nblobs; {
- /* Free a whole bunch of directory entries. */
+/* Free a whole bunch of directory entries. */
+
+void FreeBlobs(void *dir, register int firstblob, int nblobs)
+{
register int i;
int page;
struct DirHeader *dhp;
if (pp) for (i=0;i<nblobs;i++)
pp->freebitmap[(firstblob+i)>>3] &= ~(1<<((firstblob+i)&7));
DRelease(pp,1);
- }
+}
-MakeDir (dir,me,parent)
-char *dir;
-afs_int32 *me;
-afs_int32 *parent; {
- /* Format an empty directory properly. Note that the first 13 entries in a directory header
- page are allocated, 1 to the page header, 4 to the allocation map and 8 to the hash table. */
+/*
+ * Format an empty directory properly. Note that the first 13 entries in a
+ * directory header page are allocated, 1 to the page header, 4 to the
+ * allocation map and 8 to the hash table.
+ */
+int MakeDir (void *dir, afs_int32 *me, afs_int32 *parent)
+{
register int i;
register struct DirHeader *dhp;
dhp = (struct DirHeader *) DNew(dir,0);
Create(dir,".",me);
Create(dir,"..",parent); /* Virtue is its own .. */
return 0;
- }
+}
-Lookup (dir, entry, fid)
- char *dir;
- char *entry;
- register afs_int32 *fid; {
- /* Look up a file name in directory. */
+/* Look up a file name in directory. */
+
+int Lookup (void *dir, char *entry, void *voidfid)
+{
+ afs_int32 *fid = (afs_int32 *) voidfid;
register struct DirEntry *firstitem;
unsigned short *previtem;
return 0;
}
-LookupOffset (dir, entry, fid, offsetp)
- char *dir;
- char *entry;
- long *offsetp;
- register afs_int32 *fid; {
- /* Look up a file name in directory. */
- register struct DirEntry *firstitem;
- unsigned short *previtem;
-
- firstitem = FindItem(dir,entry,&previtem);
- if (firstitem == 0) return ENOENT;
- DRelease(previtem,0);
- fid[1] = ntohl(firstitem->fid.vnode);
- fid[2] = ntohl(firstitem->fid.vunique);
- if (offsetp)
- *offsetp = DVOffset(firstitem);
- DRelease(firstitem,0);
- return 0;
+/* Look up a file name in directory. */
+
+int LookupOffset (void *dir, char *entry, void *voidfid, long *offsetp)
+{
+ afs_int32 *fid = (afs_int32 *) voidfid;
+ register struct DirEntry *firstitem;
+ unsigned short *previtem;
+
+ firstitem = FindItem(dir,entry,&previtem);
+ if (firstitem == 0) return ENOENT;
+ DRelease(previtem,0);
+ fid[1] = ntohl(firstitem->fid.vnode);
+ fid[2] = ntohl(firstitem->fid.vunique);
+ if (offsetp)
+ *offsetp = DVOffset(firstitem);
+ DRelease(firstitem,0);
+ return 0;
}
-EnumerateDir (dir,hookproc,hook)
- char *dir;
- void *hook;
- int (*hookproc)(); {
+int EnumerateDir (void *dir, int (*hookproc)(), void *hook)
+{
/* Enumerate the contents of a directory. */
register int i;
int num;
return 0;
}
-IsEmpty (dir)
-char *dir; {
+int IsEmpty (void *dir)
+{
/* Enumerate the contents of a directory. */
register int i;
int num;
return 0;
}
-struct DirEntry *GetBlob (dir, blobno)
- char *dir;
- afs_int32 blobno; {
+struct DirEntry *GetBlob (void *dir, afs_int32 blobno)
+{
/* Return a pointer to an entry, given its number. */
struct DirEntry *ep;
ep=DRead(dir,blobno>>LEPP);
return (struct DirEntry *) (((long)ep)+32*(blobno&(EPP-1)));
}
-DirHash (string)
- register char *string; {
+int DirHash (register char *string)
+{
/* Hash a string to a number between 0 and NHASHENT. */
register unsigned char tc;
register int hval;
register int tval;
hval = 0;
- while(tc=(*string++)) {
+ while((tc=(*string++))) {
hval *= 173;
hval += tc;
}
return tval;
}
-static struct DirEntry *FindItem (dir,ename,previtem)
-char *dir;
-char *ename;
-unsigned short **previtem; {
+static struct DirEntry *FindItem (void *dir, char *ename,
+ unsigned short **previtem)
+{
/* Find a directory entry, given its name. This entry returns a pointer to a locked buffer, and a pointer to a locked buffer (in previtem) referencing the found item (to aid the delete code). If no entry is found, however, no items are left locked, and a null pointer is returned instead. */
register int i;
register struct DirHeader *dhp;