? openafs/src/config/param.i386_fbsd_4.h
? openafs/src/config/param.i386_fbsd_4_usr.h
? openafs/src/config/param.i386_fbsd_5.h
? openafs/src/config/param.i386_fbsd_5_usr.h
? openafs/src/libafs/Makefile.common
? openafs/src/libafs/STATIC
? openafs/src/libuafs/Makefile.common
? openafs/src/libuafs/MakefileProto.FBSD
? openafs/src/tests/Makefile
? openafs/src/tests/OpenAFS/Dirpath.pm
Index: openafs/acinclude.m4
===================================================================
RCS file: /cvs/openafs/acinclude.m4,v
retrieving revision 1.24
diff -u -r1.24 acinclude.m4
--- openafs/acinclude.m4	2002/04/25 21:44:53	1.24
+++ openafs/acinclude.m4	2002/06/11 19:04:55
@@ -222,8 +222,8 @@
 else
 	AC_MSG_CHECKING(your AFS sysname)
 	case $host in
-		i?86-*-freebsd4.2*)
-			AFS_SYSNAME="i386_fbsd_42"
+		i?86-*-freebsd4*)
+			AFS_SYSNAME="i386_fbsd_4"
 			;;
 		i?86-*-freebsd4.3*)
 			AFS_SYSNAME="i386_fbsd_43"
Index: openafs/src/afs/afs_call.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_call.c,v
retrieving revision 1.28
diff -u -r1.28 afs_call.c
--- openafs/src/afs/afs_call.c	2002/05/23 05:21:13	1.28
+++ openafs/src/afs/afs_call.c	2002/06/11 19:04:58
@@ -952,11 +952,19 @@
     int *retval = &rvp->r_val1;
 #else /* AFS_SUN5_ENV */
 #if	defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD5_ENV)
+afs3_syscall(td, args, retval)
+        struct thread *td;
+#else
 afs3_syscall(p, args, retval)
 	struct proc *p;
+#endif /* AFS_FBSD5_ENV */
 	void *args;
 	int *retval;
 {
+#if defined(AFS_FBSD5_ENV)
+    struct proc *p = td->td_proc;
+#endif /* AFS_FBSD5_ENV */
     register struct a {
 	    long syscall;
 	    long parm1;
@@ -1120,7 +1128,11 @@
         code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
 #else
 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD5_ENV)
+        code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_ucred);
+#else
         code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
+#endif
 #else
 	code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
 #endif
Index: openafs/src/afs/afs_init.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_init.c,v
retrieving revision 1.15
diff -u -r1.15 afs_init.c
--- openafs/src/afs/afs_init.c	2002/05/21 06:35:57	1.15
+++ openafs/src/afs/afs_init.c	2002/06/11 19:04:58
@@ -448,7 +448,11 @@
         if (!VFS_STATFS(filevp->v_mount, &st, current_proc()))
 #else 
 #if defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD_KTHREAD)
+        if (!VFS_STATFS(filevp->v_mount, &st, curthread))
+#else
         if (!VFS_STATFS(filevp->v_mount, &st, curproc))
+#endif /* AFS_FBSD_KTHREAD */
 #else 
 	if (!VFS_STATFS(filevp->v_vfsp, &st))  
 #endif /* AFS_FBSD_ENV */
Index: openafs/src/afs/afs_osi.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_osi.c,v
retrieving revision 1.15
diff -u -r1.15 afs_osi.c
--- openafs/src/afs/afs_osi.c	2002/03/25 17:11:49	1.15
+++ openafs/src/afs/afs_osi.c	2002/06/11 19:04:58
@@ -73,7 +73,13 @@
 	if ( !afs_osicred_initialized )
 	{
 		memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
+#if defined(AFS_FBSD5_ENV)
+		/* from sys/kern/kern_prot.c:crhold() */
+		afs_osi_cred.cr_ref = 1;
+		afs_osi_cred.cr_mtxp = mtx_pool_find(&afs_osi_cred);
+#else
 		crhold(&afs_osi_cred);      /* don't let it evaporate */
+#endif /* AFS_FBSD5_ENV */
 		afs_osicred_initialized = 1;
 	}
 #ifdef AFS_SGI64_ENV
@@ -372,7 +378,10 @@
     AFS_GLOCK();
 #else
 #if defined(AFS_FBSD_ENV)
-    /* does not impliment security features of kern_time.c:settime() */
+    /* copied largely from sys/kern/kern_time.c:settime(), but security
+     * features bypassed to allow time changes greater than +/- 1
+     * second.
+     */
     struct timespec ts;
     struct timeval tv,delta;
     extern void (*lease_updatetime)();
@@ -384,7 +393,12 @@
     timevalsub(&delta, &tv);
     ts.tv_sec=atv->tv_sec;
     ts.tv_nsec=atv->tv_usec * 1000;
+#if defined(AFS_FBSD5_ENV)
+    /* the SMP-ification conversion continues */
+    tc_setclock(&ts);
+#else
     set_timecounter(&ts);
+#endif /* AFS_FBSD5_ENV */
     (void) splsoftclock();
     lease_updatetime(delta.tv_sec);
     splx(s);
Index: openafs/src/afs/afs_pioctl.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_pioctl.c,v
retrieving revision 1.34
diff -u -r1.34 afs_pioctl.c
--- openafs/src/afs/afs_pioctl.c	2002/05/16 12:54:56	1.34
+++ openafs/src/afs/afs_pioctl.c	2002/06/11 19:04:58
@@ -401,8 +401,13 @@
         u_long com;
         caddr_t arg;
 };
+#if defined(AFS_FBSD5_ENV)
+afs_xioctl(td, uap, retval)
+        struct thread *td;
+#else
 afs_xioctl(p, uap, retval) 
         struct proc *p; 
+#endif /* AFS_FBSD5_ENV */
         register struct ioctl_args *uap;
         register_t *retval;
 {
@@ -437,6 +442,9 @@
 #endif
 #endif
 #if defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD5_ENV)
+      struct proc *p = td->td_proc;
+#endif /* AFS_FBSD5_ENV */
       register struct filedesc *fdp;
 #endif
       register struct vcache *tvc;
@@ -601,7 +609,11 @@
           code = ioctl(uap, rvp);
 #else
 #if defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD5_ENV)
+        return ioctl(td, uap);
+#else
         return ioctl(p, uap);
+#endif /* AFS_FBSD5_ENV */
 #else
 #if defined(AFS_DARWIN_ENV) 
         return ioctl(p, uap, retval);
@@ -714,7 +726,12 @@
     } *uap = (struct a *) args;
     
     AFS_STATCNT(afs_pioctl);
-    return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow, p->p_cred->pc_ucred));
+    return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow,
+#if defined(AFS_FBSD5_ENV)
+			       p->p_ucred));
+#else
+			       p->p_cred->pc_ucred));
+#endif /* AFS_FBSD5_ENV */
 }   
 
 extern struct mount *afs_globalVFS;
Index: openafs/src/afs/afs_vcache.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_vcache.c,v
retrieving revision 1.27
diff -u -r1.27 afs_vcache.c
--- openafs/src/afs/afs_vcache.c	2002/04/05 18:13:32	1.27
+++ openafs/src/afs/afs_vcache.c	2002/06/11 19:04:58
@@ -726,15 +726,27 @@
 #if defined(AFS_FBSD_ENV)
 	   if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
 	       && (tvc->states & CUnlinkedDel) == 0) {
-               if (!(VOP_LOCK(&tvc->v, LK_EXCLUSIVE, curproc))) {
+#if defined(AFS_FBSD_KTHREAD)
+	     if (!(VOP_LOCK(&tvc->v, LK_EXCLUSIVE, curthread))) {
+#else
+	     if (!(VOP_LOCK(&tvc->v, LK_EXCLUSIVE, curproc))) {
+#endif /* AFS_FBSD_KTHREAD */
 	          if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
 	              && (tvc->states & CUnlinkedDel) == 0) {
                       VREFCOUNT_DEC(tvc);
                       AFS_GUNLOCK(); /* perhaps inline inactive for locking */
+#if defined(AFS_FBSD_KTHREAD)
+                      VOP_INACTIVE(&tvc->v, curthread);
+#else
                       VOP_INACTIVE(&tvc->v, curproc);
+#endif /* AFS_FBSD_KTHREAD */
                       AFS_GLOCK();
                   } else {
+#if defined(AFS_FBSD_KTHREAD)
+		     VOP_UNLOCK(&tvc->v, 0, curthread);
+#else
                      VOP_UNLOCK(&tvc->v, 0, curproc);
+#endif /* AFS_FBSD_KTHREAD */
                   }
                }
            }
@@ -921,6 +933,11 @@
 #endif 
 #ifdef AFS_FBSD_ENV
     lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
+#if defined(AFS_FBSD5_ENV)
+    if(!mtx_initialized(&(tvc->v.v_interlock))){
+      mtx_init(&(tvc->v.v_interlock), "vnode interlock", MTX_DEF);
+    }
+#endif /* AFS_FBSD5_ENV */
     cache_purge(AFSTOV(tvc)); 
     tvc->v.v_data=tvc;
     tvc->v.v_tag=VT_AFS;
Index: openafs/src/afs/sysincludes.h
===================================================================
RCS file: /cvs/openafs/src/afs/sysincludes.h,v
retrieving revision 1.8
diff -u -r1.8 sysincludes.h
--- openafs/src/afs/sysincludes.h	2002/02/16 18:23:49	1.8
+++ openafs/src/afs/sysincludes.h	2002/06/11 19:04:58
@@ -182,10 +182,13 @@
 
 #if !defined(AFS_SGI64_ENV) && !defined(AFS_FBSD_ENV)
 #include "../h/user.h"
-#endif /* AFS_SGI64_ENV */
+#endif /* !AFS_SGI64_ENV && !AFS_FBSD_ENV */
 #define	MACH_USER_API	1
 #include "../h/file.h"
 #include "../h/uio.h"
+#if defined(AFS_FBSD5_ENV)
+#include <sys/bio.h>
+#endif /* AFS_FBSD5_ENV */
 #include "../h/buf.h"
 #include "../h/stat.h"
 
@@ -217,7 +220,7 @@
 #    include "../h/swap.h"	/* for struct swpdbd, for vnode.h compiler warnings */
 #    include "../h/dbd.h"	/* for union idbd, for vnode.h compiler warnings */
 #  endif /* AFS_HPUX_ENV */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD40_ENV)
+#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
 #  include <sys/uio.h>
 #  include <sys/mount.h> 
 #  include <sys/namei.h>
@@ -236,6 +239,9 @@
 #  include <vm/pmap.h>
 #  include <vm/vm_map.h>
 #  include <sys/lock.h>
+#if defined(AFS_FBSD5_ENV)
+#  include <sys/mutex.h>
+#endif /* AFS_FBSD5_ENV */
 #  include <sys/user.h>
 #endif
 #undef timeout_fcn_t
Index: openafs/src/afs/FBSD/osi_file.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_file.c,v
retrieving revision 1.5
diff -u -r1.5 osi_file.c
--- openafs/src/afs/FBSD/osi_file.c	2002/02/16 18:23:49	1.5
+++ openafs/src/afs/FBSD/osi_file.c	2002/06/11 19:04:58
@@ -51,7 +51,11 @@
 	osi_Panic("UFSOpen: igetinode failed");
     }
     afile->vnode = ITOV(ip);
+#if defined(AFS_FBSD5_ENV)
+    VOP_UNLOCK(afile->vnode, 0, curthread);
+#else
     VOP_UNLOCK(afile->vnode, 0, curproc);
+#endif /* AFS_FBSD5_ENV */
     afile->size = VTOI(afile->vnode)->i_size;
     afile->offset = 0;
     afile->proc = (int (*)()) 0;
@@ -67,7 +71,11 @@
     AFS_STATCNT(osi_Stat);
     MObtainWriteLock(&afs_xosi,320);
     AFS_GUNLOCK();
+#if defined(AFS_FBSD5_ENV)
+    code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
+#else
     code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
+#endif /* AFS_FBSD5_ENV */
     AFS_GLOCK();
     if (code == 0) {
 	astat->size = tvattr.va_size;
@@ -109,7 +117,11 @@
     VATTR_NULL(&tvattr);
     tvattr.va_size = asize;
     AFS_GUNLOCK();
+#if defined(AFS_FBSD5_ENV)
+    code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
+#else
     code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
+#endif /* AFS_FBSD5_ENV */
     AFS_GLOCK();
     MReleaseWriteLock(&afs_xosi);
     return code;
Index: openafs/src/afs/FBSD/osi_groups.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_groups.c,v
retrieving revision 1.4
diff -u -r1.4 osi_groups.c
--- openafs/src/afs/FBSD/osi_groups.c	2002/02/16 18:23:49	1.4
+++ openafs/src/afs/FBSD/osi_groups.c	2002/06/11 19:04:58
@@ -38,16 +38,32 @@
     int change_parent);
 
 int
+#if defined(AFS_FBSD5_ENV)
+Afs_xsetgroups(td, args, retval)
+    struct thread *td;
+#else
 Afs_xsetgroups(p, args, retval)
     struct proc *p;
+#endif /* AFS_FBSD5_ENV */
     void *args;
     int *retval;
 {
+#if defined(AFS_FBSD5_ENV)
+    struct proc *p = td->td_proc;
+#endif /* AFS_FBSD5_ENV */
     int code = 0;
     struct vrequest treq;
     struct ucred *cr;
 
+#if defined(AFS_FBSD5_ENV)
+    if(p->p_ucred == NULL){
+      cr=crget();
+    } else {
+      cr=crdup(p->p_ucred);
+    }
+#else
     cr=crdup(p->p_cred->pc_ucred);
+#endif /* AFS_FBSD5_ENV */
 
     AFS_STATCNT(afs_xsetgroups);
     AFS_GLOCK();
@@ -61,7 +77,15 @@
     /* Note that if there is a pag already in the new groups we don't
      * overwrite it with the old pag.
      */
+#if defined(AFS_FBSD5_ENV)
+    if(p->p_ucred == NULL){
+      cr=crget();
+    } else {
+      cr=crdup(p->p_ucred);
+    }
+#else
     cr=crdup(p->p_cred->pc_ucred);
+#endif /* AFS_FBSD5_ENV */
 
     if (PagInCred(cr) == NOPAG) {
 	if (((treq.uid >> 24) & 0xff) == 'A') {
@@ -153,13 +177,23 @@
 	*gp++ = *gidset++;
     if (change_parent) {
 	crhold(cr);
+#if defined(AFS_FBSD5_ENV)
+	oldcr=proc->p_pptr->p_ucred;
+	proc->p_pptr->p_ucred=cr;
+#else
 	oldcr=proc->p_pptr->p_cred->pc_ucred;
 	proc->p_pptr->p_cred->pc_ucred=cr;
+#endif /* AFS_FBSD5_ENV */
 	crfree(oldcr);
     }
     crhold(cr);
+#if defined(AFS_FBSD5_ENV)
+    oldcr=proc->p_ucred;
+    proc->p_ucred=cr;
+#else
     oldcr=proc->p_cred->pc_ucred;
     proc->p_cred->pc_ucred=cr;
+#endif /* AFS_FBSD5_ENV */
     crfree(oldcr);
     return(0);
 }
Index: openafs/src/afs/FBSD/osi_inode.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_inode.c,v
retrieving revision 1.4
diff -u -r1.4 osi_inode.c
--- openafs/src/afs/FBSD/osi_inode.c	2002/02/16 18:23:49	1.4
+++ openafs/src/afs/FBSD/osi_inode.c	2002/06/11 19:04:58
@@ -24,6 +24,9 @@
 #include "../afs/afs_stats.h" /* statistics stuff */
 #include <sys/queue.h>
 #include <sys/lock.h>
+#if defined(AFS_FBSD5_ENV)
+#include <ufs/extattr.h>
+#endif /* AFS_FBSD5_ENV */
 #include <ufs/ufsmount.h>
 #include <ufs/ufs/dinode.h>
 
@@ -43,7 +46,7 @@
 	register struct ufsmount *ump;
 	register struct mount *mp;
 	
-        simple_lock(&mountlist_slock);
+        MOUNTLIST_LOCK();
 	if (mp = TAILQ_FIRST(&mountlist)) do {
 	    /*
 	     * XXX Also do the test for MFS 
@@ -60,7 +63,7 @@
 	    }
 	    mp = TAILQ_NEXT(mp, mnt_list);
 	} while (mp != TAILQ_FIRST(&mountlist));
-        simple_unlock(&mountlist_slock);
+	MOUNTLIST_UNLOCK();
 	if (!fs)
 	    return(ENXIO);
     }
@@ -207,7 +210,11 @@
     if (code) {
 	return(code);
     }
+#if defined(AFS_FBSD5_ENV)
+    if ((code = falloc(curthread, &fp, &fd)) != 0) {
+#else
     if ((code = falloc(curproc, &fp, &fd)) != 0) {
+#endif /* AFS_FBSD5_ENV */
 	iput(ip);
 	return(code);
     }
Index: openafs/src/afs/FBSD/osi_inode.h
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_inode.h,v
retrieving revision 1.1
diff -u -r1.1 osi_inode.h
--- openafs/src/afs/FBSD/osi_inode.h	2001/04/14 17:27:37	1.1
+++ openafs/src/afs/FBSD/osi_inode.h	2002/06/11 19:04:58
@@ -25,8 +25,14 @@
 	( ((u_int)((p)->i_vicep3a)) << 16 | ((u_int)((p)->i_vicep3b)) )
 
 #define FAKE_INODE_SIZE    (sizeof(struct vnode)+sizeof(struct inode))
+#if defined(AFS_FBSD5_ENV)
+/* Hooray for real synchronization primitives!  Hooray! */
+#define MOUNTLIST_UNLOCK() mtx_unlock(&mountlist_mtx)
+#define MOUNTLIST_LOCK()   mtx_lock(&mountlist_mtx)
+#else
 #define MOUNTLIST_UNLOCK() simple_lock_unlock(&mountlist_slock)
 #define MOUNTLIST_LOCK()   simple_lock(&mountlist_slock)
+#endif /* AFS_FBSD5_ENV */
 
 /* FreeBSD doesn't actually have a di_proplb, so we use di_spare[0] */
 #define di_proplb       di_spare[0]
Index: openafs/src/afs/FBSD/osi_machdep.h
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_machdep.h,v
retrieving revision 1.2
diff -u -r1.2 osi_machdep.h
--- openafs/src/afs/FBSD/osi_machdep.h	2002/02/16 18:23:49	1.2
+++ openafs/src/afs/FBSD/osi_machdep.h	2002/06/11 19:04:58
@@ -33,17 +33,22 @@
 #define osi_Time() time_second
 #define	afs_hz	    hz
 
-#define PAGESIZE 8192
+#define PAGESIZE 4096
 
 #define	AFS_UCRED	ucred
 #define	AFS_PROC	struct proc
 
 #define afs_bufferpages bufpages
 
-#define osi_vnhold(avc,r) do { VN_HOLD((struct vnode *)(avc)); } while (0)
+#define osi_vnhold(avc,r) do { VN_HOLD((struct vnode *)(&(avc->v))); } while (0)
 
+#if (__FreeBSD__ < 5)
 #define	gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
+#else
+#define	gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
+  vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curthread)
+#endif /* __FreeBSD__ < 5 */
 #undef gop_lookupname
 #define gop_lookupname osi_lookupname
 
@@ -52,6 +57,7 @@
 #ifdef KERNEL
 extern struct proc * afs_global_owner;
 extern struct lock afs_global_lock;
+#if (__FreeBSD__ < 5)
 #define AFS_GLOCK() \
     do { \
         osi_Assert(curproc); \
@@ -66,6 +72,22 @@
         afs_global_owner = 0; \
         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
     } while(0)
+#else /* __FreeBSD__ < 5 */
+#define AFS_GLOCK() \
+    do { \
+        osi_Assert(curproc); \
+ 	lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curthread); \
+        osi_Assert(afs_global_owner == 0); \
+   	afs_global_owner = curproc; \
+    } while (0)
+#define AFS_GUNLOCK() \
+    do { \
+        osi_Assert(curproc); \
+ 	osi_Assert(afs_global_owner == curproc); \
+        afs_global_owner = 0; \
+        lockmgr(&afs_global_lock, LK_RELEASE, 0, curthread); \
+    } while(0)
+#endif /* __FreeBSD__ < 5 */
 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
 #define AFS_RXGLOCK()
 #define AFS_RXGUNLOCK()
Index: openafs/src/afs/FBSD/osi_misc.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_misc.c,v
retrieving revision 1.4
diff -u -r1.4 osi_misc.c
--- openafs/src/afs/FBSD/osi_misc.c	2002/02/16 18:23:49	1.4
+++ openafs/src/afs/FBSD/osi_misc.c	2002/06/11 19:04:58
@@ -49,7 +49,11 @@
    else 
      flags|=NOFOLLOW;
 /*   if (dirvpp) flags|=WANTPARENT;*/ /* XXX LOCKPARENT? */
+#if defined(AFS_FBSD5_ENV)
+   NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
+#else
    NDINIT(&n, LOOKUP, flags, seg, aname, curproc);
+#endif /* AFS_FBSD5_ENV */
    if (error=namei(&n))
       return error;
    *vpp=n.ni_vp;
@@ -58,7 +62,11 @@
       *dirvpp = n.ni_dvp;
 */
    /* should we do this? */
+#if defined(AFS_FBSD5_ENV)
+   VOP_UNLOCK(n.ni_vp, 0, curthread);
+#else
    VOP_UNLOCK(n.ni_vp, 0, curproc);
+#endif /* AFS_FBSD5_ENV */
    NDFREE(&n, NDF_ONLY_PNBUF);
    return 0;
 }
Index: openafs/src/afs/FBSD/osi_module.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_module.c,v
retrieving revision 1.1
diff -u -r1.1 osi_module.c
--- openafs/src/afs/FBSD/osi_module.c	2002/02/16 18:23:49	1.1
+++ openafs/src/afs/FBSD/osi_module.c	2002/06/11 19:04:58
@@ -37,20 +37,29 @@
                  error=-1;
                  break;
            }
+	   printf("Beginning AFS MOD_LOAD\n");
            memset(&afs_vfsconf, 0, sizeof(struct vfsconf));
+	   printf("did memset\n");
            strcpy(afs_vfsconf.vfc_name, "AFS");
+	   printf("did strcpy\n");
            afs_vfsconf.vfc_vfsops=&afs_vfsops;
            afs_vfsconf.vfc_typenum=-1; /* set by vfs_register */
            afs_vfsconf.vfc_flags=VFCF_NETWORK;
+	   printf("set afs_vfsconf variables\n");
            vfs_register(&afs_vfsconf); /* doesn't fail */
            vfs_add_vnodeops(&afs_vnodeop_opv_desc);
+	   printf("About to osi_Init()\n");
            osi_Init();
+	   printf("About to sysent Afs_xsetgroups\n");
            sysent[SYS_setgroups].sy_call=Afs_xsetgroups;
+	   printf("About to sysent afs_xioctl\n");
            sysent[SYS_ioctl].sy_call=afs_xioctl;
            old_handler=sysent[AFS_SYSCALL].sy_call;
+	   printf("About to sysent afs3_syscall\n");
            sysent[AFS_SYSCALL].sy_call=afs3_syscall;
            sysent[AFS_SYSCALL].sy_narg = 5;
            inited=1;
+	   printf("Finished AFS MOD_LOAD\n");
            break;
         case MOD_UNLOAD:
 #ifndef RXK_LISTENER_ENV
Index: openafs/src/afs/FBSD/osi_vfsops.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_vfsops.c,v
retrieving revision 1.6
diff -u -r1.6 osi_vfsops.c
--- openafs/src/afs/FBSD/osi_vfsops.c	2002/03/25 17:11:52	1.6
+++ openafs/src/afs/FBSD/osi_vfsops.c	2002/06/11 19:04:58
@@ -78,11 +78,12 @@
     vfs_getnewfsid(mp);
     mp->mnt_stat.f_iosize=8192;
     
-    (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size);
-    memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
-    memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
-    strcpy(mp->mnt_stat.f_mntfromname, "AFS");
+    AFS_COPYINSTR(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size, error);
+    /* memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN); */
+    /* memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN); */
+    /* (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size); */
     /* null terminated string "AFS" will fit, just leave it be. */
+    strcpy(mp->mnt_stat.f_mntfromname, "AFS");
     strcpy(mp->mnt_stat.f_fstypename, "afs");
     AFS_GUNLOCK();
     (void) afs_statfs(mp, &mp->mnt_stat, p);
@@ -112,14 +113,23 @@
     int error;
     struct vrequest treq;
     register struct vcache *tvp=0;
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td=curthread;
+#else
     struct proc *p=curproc;
+#endif /* AFS_FBSD_KTHREAD */
     struct ucred cr;
 
+#if defined(AFS_FBSD_KTHREAD)
+    cr=*td->td_ucred;
+#else
     cr=*p->p_cred->pc_ucred;
+#endif /* AFS_FBSD_KTHREAD */
     AFS_GLOCK();
     AFS_STATCNT(afs_root);
     if (afs_globalVp && (afs_globalVp->states & CStatd)) {
 	tvp = afs_globalVp;
+	printf("afs_root: Setting tvp to afs_globalVP\n");
         error=0;
     } else {
 	
@@ -132,12 +142,17 @@
 	        afs_globalVp = tvp;
 	    } else
 	        error = ENOENT;
+	    printf("afs_root: Setting tvp to afs_GetVCache()\n");
 	}
     }
     if (tvp) {
         osi_vnhold(tvp,0);
     AFS_GUNLOCK();
+#if defined(AFS_FBSD_KTHREAD)
+        vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, td);
+#else
         vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
     AFS_GLOCK();
 	afs_globalVFS = mp;
 	*vpp = AFSTOV(tvp);
@@ -162,7 +177,11 @@
 	vprint("bad usecount", vp);
 	panic("afs_vget");
     }
+#if defined(AFS_FBSD_KTHREAD)
+    error = vget(vp, lfl, curthread);
+#else
     error = vget(vp, lfl, curproc);
+#endif /* AFS_FBSD_KTHREAD */
     if (!error)
 	insmntque(vp, afs_globalVFS);   /* take off free list */
     return error;
Index: openafs/src/afs/FBSD/osi_vm.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_vm.c,v
retrieving revision 1.5
diff -u -r1.5 osi_vm.c
--- openafs/src/afs/FBSD/osi_vm.c	2002/03/25 17:11:52	1.5
+++ openafs/src/afs/FBSD/osi_vm.c	2002/06/11 19:04:58
@@ -66,7 +66,11 @@
 
     AFS_GUNLOCK();
     vp=avc;
+#if defined(AFS_FBSD5_ENV)
+    mtx_lock(&vp->v_interlock);
+#else
     simple_lock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     if (VOP_GETVOBJECT(vp, &obj) == 0) {
        vm_object_page_remove(obj, 0, 0, FALSE);
 #if 0
@@ -78,7 +82,11 @@
         }
 #endif
     } 
+#if defined(AFS_FBSD5_ENV)
+    mtx_unlock(&vp->v_interlock);
+#else
     simple_unlock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     AFS_GLOCK();
 
     return 0;
@@ -102,11 +110,19 @@
     vp=avc;
     do {
     anyio=0;
+#if defined(AFS_FBSD5_ENV)
+    mtx_lock(&vp->v_interlock);
+#else
     simple_lock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     if (VOP_GETVOBJECT(vp, &obj) == 0 &&
        (obj->flags & OBJ_MIGHTBEDIRTY)) {
         if (!vget(vp,
+#if defined(AFS_FBSD5_ENV)
+            LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curthread)) {
+#else
             LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) {
+#endif /* AFS_FBSD5_ENV */
             if (VOP_GETVOBJECT(vp, &obj) == 0) {
                vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
                anyio = 1;
@@ -114,7 +130,11 @@
             vput(vp);
         }
     } else {
-        simple_unlock(&vp->v_interlock);
+#if defined(AFS_FBSD5_ENV)
+      mtx_unlock(&vp->v_interlock);
+#else
+      simple_unlock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     }
     } while (anyio && (--tries > 0));
     AFS_GLOCK();
@@ -145,11 +165,19 @@
     vp=avc;
     do {
        anyio=0;
+#if defined(AFS_FBSD5_ENV)
+       mtx_lock(&vp->v_interlock);
+#else
        simple_lock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
        if (VOP_GETVOBJECT(vp, &obj) == 0 &&
           (obj->flags & OBJ_MIGHTBEDIRTY)) {
            if (!vget(vp,
+#if defined(AFS_FBSD5_ENV)
+               LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curthread)) {
+#else
                LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) {
+#endif /* AFS_FBSD5_ENV */
                if (VOP_GETVOBJECT(vp, &obj) == 0) {
                   vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
                   anyio = 1;
@@ -157,14 +185,26 @@
                vput(vp);
            }
        } else {
-           simple_unlock(&vp->v_interlock);
+#if defined(AFS_FBSD5_ENV)
+	 mtx_unlock(&vp->v_interlock);
+#else
+	 simple_unlock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
        }
     } while (anyio && (--tries > 0));
+#if defined(AFS_FBSD5_ENV)
+    mtx_lock(&vp->v_interlock);
+#else
     simple_lock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     if (VOP_GETVOBJECT(vp, &obj) == 0) {
        vm_object_page_remove(obj, 0, 0, FALSE);
     }
+#if defined(AFS_FBSD5_ENV)
+    mtx_unlock(&vp->v_interlock);
+#else
     simple_unlock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */    
     /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/
     AFS_GLOCK();
     ObtainWriteLock(&avc->lock,59);
@@ -183,12 +223,20 @@
     struct vm_object *obj;
     printf("|");
     vp=avc;
+#if defined(AFS_FBSD5_ENV)
+    mtx_lock(&vp->v_interlock);
+#else
     simple_lock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     if (VOP_GETVOBJECT(vp, &obj) == 0) {
        printf("X|");
        vm_object_page_remove(obj, 0, 0, FALSE);
     }
+#if defined(AFS_FBSD5_ENV)
+    mtx_unlock(&vp->v_interlock);
+#else
     simple_unlock(&vp->v_interlock);
+#endif /* AFS_FBSD5_ENV */
     /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/
 }
 
Index: openafs/src/afs/FBSD/osi_vnodeops.c
===================================================================
RCS file: /cvs/openafs/src/afs/FBSD/osi_vnodeops.c,v
retrieving revision 1.6
diff -u -r1.6 osi_vnodeops.c
--- openafs/src/afs/FBSD/osi_vnodeops.c	2002/03/25 17:11:52	1.6
+++ openafs/src/afs/FBSD/osi_vnodeops.c	2002/06/11 19:04:58
@@ -48,9 +48,10 @@
 int afs_vop_print(struct vop_print_args *);
 int afs_vop_islocked(struct vop_islocked_args *);
 int afs_vop_advlock(struct vop_advlock_args *);
+#if defined(AFS_FBSD5_ENV)  
+int afs_vop_bwrite(struct vop_bwrite_args *);
+#endif /* AFS_FBSD5_ENV */
 
-
-
 /* Global vfs data structures for AFS. */
 vop_t **afs_vnodeop_p;
 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
@@ -58,7 +59,9 @@
 	{ &vop_access_desc, (vop_t *) afs_vop_access },          /* access */
 	{ &vop_advlock_desc, (vop_t *) afs_vop_advlock },        /* advlock */
 	{ &vop_bmap_desc, (vop_t *) afs_vop_bmap },              /* bmap */
+#if !defined(AFS_FBSD5_ENV)
 	{ &vop_bwrite_desc, (vop_t *) vop_stdbwrite },
+#endif /* !AFS_FBSD5_ENV */
 	{ &vop_close_desc, (vop_t *) afs_vop_close },            /* close */
         { &vop_createvobject_desc,  (vop_t *) vop_stdcreatevobject },
         { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
@@ -76,7 +79,9 @@
 	{ &vop_lookup_desc, (vop_t *) afs_vop_lookup },          /* lookup */
 	{ &vop_mkdir_desc, (vop_t *) afs_vop_mkdir },            /* mkdir */
 	{ &vop_mknod_desc, (vop_t *) afs_vop_mknod },            /* mknod */
+#if !defined(AFS_FBSD5_ENV)
 	{ &vop_mmap_desc, (vop_t *) afs_vop_mmap },              /* mmap */
+#endif
 	{ &vop_open_desc, (vop_t *) afs_vop_open },              /* open */
 	{ &vop_poll_desc, (vop_t *) afs_vop_poll },          /* select */
 	{ &vop_print_desc, (vop_t *) afs_vop_print },            /* print */
@@ -125,9 +130,17 @@
     register int flags = ap->a_cnp->cn_flags;
     int lockparent;                     /* 1 => lockparent flag is set */
     int wantparent;                     /* 1 => wantparent or lockparent flag */
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td;
+#else
     struct proc *p;
+#endif /* AFS_FBSD_KTHREAD */
     GETNAME();
+#if defined(AFS_FBSD_KTHREAD)
+    td=cnp->cn_thread;
+#else
     p=cnp->cn_proc;
+#endif
     lockparent = flags & LOCKPARENT;
     wantparent = flags & (LOCKPARENT|WANTPARENT);
 
@@ -138,13 +151,21 @@
     }
     dvp = ap->a_dvp;
     if (flags & ISDOTDOT) 
+#if defined(AFS_FBSD_KTHREAD)
+       VOP_UNLOCK(dvp, 0, td);
+#else
        VOP_UNLOCK(dvp, 0, p);
+#endif /* AFS_FBSD_KTHREAD */
     AFS_GLOCK();
     error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
     AFS_GUNLOCK();
     if (error) {
         if (flags & ISDOTDOT) 
+#if defined(AFS_FBSD_KTHREAD)
+           VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, td);
+#else
            VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
 	if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
 	    (flags & ISLASTCN) && error == ENOENT)
 	    error = EJUSTRETURN;
@@ -161,10 +182,18 @@
        we also always return the vnode locked. */
 
     if (flags & ISDOTDOT) {
+#if defined(AFS_FBSD_KTHREAD)
+	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
+#else
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
         /* always return the child locked */
         if (lockparent && (flags & ISLASTCN) &&
+#if defined(AFS_FBSD_KTHREAD)
+           (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
+#else
            (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
+#endif /*AFS_FBSD_KTHREAD */
             vput(vp);
             DROPNAME();
             return (error);
@@ -174,8 +203,13 @@
 	   It came in locked, so we don't need to ref OR lock it */
     } else {
 	if (!lockparent || !(flags & ISLASTCN))
+#if defined(AFS_FBSD_KTHREAD)
+	    VOP_UNLOCK(dvp, 0, td);        /* done with parent. */
+	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
+#else
 	    VOP_UNLOCK(dvp, 0, p);         /* done with parent. */
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
         /* always return the child locked */
     }
     *ap->a_vpp = vp;
@@ -200,9 +234,17 @@
     int error = 0;
     struct vcache *vcp;
     register struct vnode *dvp = ap->a_dvp;
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td;
+#else
     struct proc *p;
+#endif /* AFS_FBSD_KTHREAD */
     GETNAME();
+#if defined(AFS_FBSD_KTHREAD)
+    td=cnp->cn_thread;
+#else
     p=cnp->cn_proc;
+#endif /* AFS_FBSD_KTHREAD */
 
     AFS_GLOCK();
     error = afs_create(VTOAFS(dvp), name, ap->a_vap, ap->a_vap->va_vaflags & VA_EXCLUSIVE? EXCL : NONEXCL,
@@ -216,7 +258,11 @@
 
     if (vcp) {
 	*ap->a_vpp = AFSTOV(vcp);
+#if defined(AFS_FBSD_KTHREAD)
+	vn_lock(AFSTOV(vcp), LK_EXCLUSIVE| LK_RETRY, td);
+#else
 	vn_lock(AFSTOV(vcp), LK_EXCLUSIVE| LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
     }
     else *ap->a_vpp = 0;
 
@@ -406,7 +452,7 @@
                /* vm_page_zero_invalid(m, TRUE); */
                for (i = 0; i < npages; ++i) {
                        if (i != ap->a_reqpage)
-                               vnode_pager_freepage(ap->a_m[i]);
+                               vm_page_free(ap->a_m[i]);
                }
                return(0);
        }
@@ -422,11 +468,19 @@
     uio.uio_resid=ap->a_count;
     uio.uio_segflg=UIO_SYSSPACE;
     uio.uio_rw=UIO_READ;
+#if defined(AFS_FBSD_KTHREAD)
+    uio.uio_td=curthread;
+#else
     uio.uio_procp=curproc;
+#endif /* AFS_FBSD_KTHREAD */
     AFS_GLOCK();
     afs_BozonLock(&avc->pvnLock, avc);
     osi_FlushPages(avc);        /* hold bozon lock, but not basic vnode lock */
+#if defined(AFS_FBSD_KTHREAD)
+    code=afs_read(avc, &uio, curproc->p_ucred, 0, 0, 0);
+#else
     code=afs_read(avc, &uio, curproc->p_cred->pc_ucred, 0, 0, 0);
+#endif /* AFS_FBSD_KTHREAD */
     afs_BozonUnlock(&avc->pvnLock, avc);
     AFS_GUNLOCK();
     pmap_qremove(kva, npages);
@@ -435,7 +489,7 @@
     if (code && (uio.uio_resid == ap->a_count)) {
            for (i = 0; i < npages; ++i) {
                if (i != ap->a_reqpage)
-                   vnode_pager_freepage(ap->a_m[i]);
+                   vm_page_free(ap->a_m[i]);
            }
            return VM_PAGER_ERROR;
     }
@@ -483,7 +537,7 @@
                                 vm_page_deactivate(m);
                         vm_page_wakeup(m);
                 } else {
-                        vnode_pager_freepage(m);
+                        vm_page_free(m);
                 }
         }
     }
@@ -550,7 +604,11 @@
     uio.uio_resid=ap->a_count;
     uio.uio_segflg=UIO_SYSSPACE;
     uio.uio_rw=UIO_WRITE;
+#if defined(AFS_FBSD_KTHREAD)
+    uio.uio_td=curthread;
+#else
     uio.uio_procp=curproc;
+#endif /* AFS_FBSD_KTHREAD */
     sync=IO_VMIO;
     if (ap->a_sync & VM_PAGER_PUT_SYNC)
        sync|=IO_SYNC;
@@ -559,7 +617,11 @@
 
     AFS_GLOCK();
     afs_BozonLock(&avc->pvnLock, avc);
+#if defined(AFS_FBSD_KTHREAD)
+    code=afs_write(avc, &uio, sync, curproc->p_ucred,  0);
+#else
     code=afs_write(avc, &uio, sync, curproc->p_cred->pc_ucred,  0);
+#endif /* AFS_FBSD_KTHREAD */
     afs_BozonUnlock(&avc->pvnLock, avc);
     AFS_GUNLOCK();
     pmap_qremove(kva, npages);
@@ -694,10 +756,18 @@
     int error = 0;
     register struct vnode *dvp = ap->a_tdvp;
     register struct vnode *vp = ap->a_vp;
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td;
+#else
     struct proc *p;
+#endif /* AFS_FBSD_KTHREAD */
 
     GETNAME();
+#if defined(AFS_FBSD_KTHREAD)
+    td=cnp->cn_thread;
+#else
     p=cnp->cn_proc;
+#endif /* AFS_FBSD_KTHREAD */
     if (dvp->v_mount != vp->v_mount) {
 	error = EXDEV;
 	goto out;
@@ -706,14 +776,22 @@
 	error = EISDIR;
 	goto out;
     }
+#if defined(AFS_FBSD_KTHREAD)
+    if (error = vn_lock(vp, LK_EXCLUSIVE, td)) {
+#else
     if (error = vn_lock(vp, LK_EXCLUSIVE, p)) {
+#endif /* AFS_FBSD_KTHREAD */
 	goto out;
     }
     AFS_GLOCK();
     error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
     AFS_GUNLOCK();
     if (dvp != vp)
+#if defined(AFS_FBSD_KTHREAD)
+	VOP_UNLOCK(vp,0, td);
+#else
 	VOP_UNLOCK(vp,0, p);
+#endif /* AFS_FBSD_KTHREAD */
 out:
     DROPNAME();
     return error;
@@ -739,7 +817,11 @@
     register struct vnode *tdvp = ap->a_tdvp;
     struct vnode *fvp = ap->a_fvp;
     register struct vnode *fdvp = ap->a_fdvp;
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td=fcnp->cn_thread;
+#else
     struct proc *p=fcnp->cn_proc;
+#endif /* AFS_FBSD_KTHREAD */
 
     /*
      * Check for cross-device rename.
@@ -798,7 +880,11 @@
         vput(fvp);
         return (error);
     }
+#if defined(AFS_FBSD_KTHREAD)
+    if (error = vn_lock(fvp, LK_EXCLUSIVE, td))
+#else
     if (error = vn_lock(fvp, LK_EXCLUSIVE, p))
+#endif /* AFS_FBSD_KTHREAD */
 	goto abortit;
 
     MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK);
@@ -840,10 +926,18 @@
     register struct vattr *vap = ap->a_vap;
     int error = 0;
     struct vcache *vcp;
+#if defined(AFS_FBSD_KTHREAD)
+    struct thread *td;
+#else
     struct proc *p;
+#endif /* AFS_FBSD_KTHREAD */
 
     GETNAME();
+#if defined(AFS_FBSD_KTHREAD)
+    td=cnp->cn_thread;
+#else
     p=cnp->cn_proc;
+#endif /* AFS_FBSD_KTHREAD */
 #ifdef DIAGNOSTIC
     if ((cnp->cn_flags & HASBUF) == 0)
 	panic("afs_vop_mkdir: no name");
@@ -858,7 +952,11 @@
     }
     if (vcp) {
 	*ap->a_vpp = AFSTOV(vcp);
+#if defined(AFS_FBSD_KTHREAD)
+	vn_lock(AFSTOV(vcp), LK_EXCLUSIVE|LK_RETRY, td);
+#else
 	vn_lock(AFSTOV(vcp), LK_EXCLUSIVE|LK_RETRY, p);
+#endif /* AFS_FBSD_KTHREAD */
     } else
 	*ap->a_vpp = 0;
     DROPNAME();
@@ -1138,7 +1236,11 @@
     int error;
     struct proc *p=curproc;
     struct ucred cr;
+#if defined(AFS_FBSD_KTHREAD)
+    cr=*p->p_ucred;
+#else
     cr=*p->p_cred->pc_ucred;
+#endif /* AFS_FBSD_KTHREAD */
     AFS_GLOCK();
     error= afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr,
 	               (int) ap->a_id);
@@ -1146,3 +1248,14 @@
     return error;
 }
 
+#if defined(AFS_FBSD5_ENV)
+/*
+ * filesystem buffer write
+ */
+int
+afs_vop_bwrite(ap)
+     struct vop_bwrite_args *ap;
+{
+        return (bwrite(ap->a_bp));
+}
+#endif /* AFS_FBSD5_ENV */
Index: openafs/src/afs/VNOPS/afs_vnop_strategy.c
===================================================================
RCS file: /cvs/openafs/src/afs/VNOPS/afs_vnop_strategy.c,v
retrieving revision 1.11
diff -u -r1.11 afs_vnop_strategy.c
--- openafs/src/afs/VNOPS/afs_vnop_strategy.c	2002/03/25 17:11:56	1.11
+++ openafs/src/afs/VNOPS/afs_vnop_strategy.c	2002/06/11 19:04:58
@@ -67,7 +67,11 @@
     ReleaseReadLock(&tvc->lock);
     osi_Assert(credp);
 #endif
+#ifndef AFS_FBSD5_ENV
     if ((abp->b_flags & B_READ) == B_READ) {
+#else
+    if ((abp->b_iocmd & BIO_READ) == BIO_READ) {
+#endif /* AFS_FBSD5_ENV */
 	/* read b_bcount bytes into kernel address b_un.b_addr starting
 	    at byte DEV_BSIZE * b_blkno.  Bzero anything we can't read,
 	    and finally call iodone(abp).  File is in abp->b_vp.  Credentials
@@ -184,7 +188,11 @@
 #if defined(AFS_DUX40_ENV) || defined (AFS_FBSD_ENV)
     if (code) {
 	abp->b_error = code;
+#ifndef AFS_FBSD5_ENV
 	abp->b_flags |= B_ERROR;
+#else
+	abp->b_iocmd |= BIO_ERROR;
+#endif /* AFS_FBSD5_ENV */
     }
     biodone(abp);
 #if defined(AFS_DUX40_ENV)
Index: openafs/src/afsmonitor/afsmonitor.c
===================================================================
RCS file: /cvs/openafs/src/afsmonitor/afsmonitor.c,v
retrieving revision 1.11
diff -u -r1.11 afsmonitor.c
--- openafs/src/afsmonitor/afsmonitor.c	2002/03/10 18:41:52	1.11
+++ openafs/src/afsmonitor/afsmonitor.c	2002/06/11 19:04:59
@@ -327,7 +327,6 @@
 	return(he);
 }
 
-
 /*-----------------------------------------------------------------------
  * afsmon_Exit()
  *
Index: openafs/src/cf/osconf.m4
===================================================================
RCS file: /cvs/openafs/src/cf/osconf.m4,v
retrieving revision 1.14
diff -u -r1.14 osconf.m4
--- openafs/src/cf/osconf.m4	2002/05/02 15:11:17	1.14
+++ openafs/src/cf/osconf.m4	2002/06/11 19:04:59
@@ -171,6 +171,19 @@
 		XLIBS="${LIB_AFSDB} -lcompat"
 		YACC="byacc"
 		;;
+	i386_fbsd_5)
+		LEX="flex -l"
+		MT_CFLAGS='-DAFS_PTHREAD_ENV -pthread -D_REENTRANT ${XCFLAGS}'
+		MT_LIBS="-pthread"
+		#MT_CFLAGS='-DAFS_PTHREAD_ENV -D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads ${XCFLAGS}'
+		#MT_LIBS="-L/usr/local/lib -llthread -llgcc_r"
+		PAM_CFLAGS="-O2 -pipe -fPIC"
+		SHLIB_LDFLAGS="-shared -Xlinker -x"
+		TXLIBS="/usr/lib/libncurses.so"
+		XCFLAGS="-O2 -pipe"
+		XLIBS="${LIB_AFSDB} -lcompat"
+		YACC="byacc"
+		;;
 
 	*nbsd15)
 		LEX="flex -l"
Index: openafs/src/config/afs_sysnames.h
===================================================================
RCS file: /cvs/openafs/src/config/afs_sysnames.h,v
retrieving revision 1.20
diff -u -r1.20 afs_sysnames.h
--- openafs/src/config/afs_sysnames.h	2002/02/16 18:23:54	1.20
+++ openafs/src/config/afs_sysnames.h	2002/06/11 19:04:59
@@ -140,10 +140,8 @@
 #define SYS_NAME_ID_alpha_linux_22      2001
 #define SYS_NAME_ID_alpha_linux_24      2002
 
-#define SYS_NAME_ID_i386_fbsd_42        2100
-#define SYS_NAME_ID_i386_fbsd_43        2101
-#define SYS_NAME_ID_i386_fbsd_44        2102
-#define SYS_NAME_ID_i386_fbsd_45        2103
+#define SYS_NAME_ID_i386_fbsd_4         2100
+#define SYS_NAME_ID_i386_fbsd_5		2101
 
 #define SYS_NAME_ID_ia64_linux2		2200
 #define SYS_NAME_ID_ia64_linux22	2201
Index: openafs/src/config/mkvers.c
===================================================================
RCS file: /cvs/openafs/src/config/mkvers.c,v
retrieving revision 1.4
diff -u -r1.4 mkvers.c
--- openafs/src/config/mkvers.c	2001/10/05 20:41:09	1.4
+++ openafs/src/config/mkvers.c	2002/06/11 19:04:59
@@ -16,8 +16,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
-#ifndef __APPLE_CC__
+#if !defined(__APPLE_CC__) && !defined(__FreeBSD__)
 #include <malloc.h>
+#endif
+#ifdef __FreeBSD__
+#include <stdlib.h>
 #endif
 #include <assert.h>
 #include <string.h>
Index: openafs/src/libafs/MakefileProto.FBSD.in
===================================================================
RCS file: /cvs/openafs/src/libafs/MakefileProto.FBSD.in,v
retrieving revision 1.12
diff -u -r1.12 MakefileProto.FBSD.in
--- openafs/src/libafs/MakefileProto.FBSD.in	2002/02/16 18:23:57	1.12
+++ openafs/src/libafs/MakefileProto.FBSD.in	2002/06/11 19:04:59
@@ -32,7 +32,7 @@
 #	-DRT -DKERNEL -D_KERNEL
 KDEFS=-Wall -fformat-extensions -ansi -nostdinc -I/usr/include -D_KERNEL \
 	-DKLD_MODULE -elf -mpreferred-stack-boundary=2 -I.. -I../afs
-DBUG = -O2
+DBUG = -g
 DEFINES= -DAFSDEBUG -DKERNEL -DAFS -DVICE -DNFS -DUFS -DINET -DQUOTA -DGETMOUNT
 OPTF=${OPT} 
 OPTF2=${OPT2} 
@@ -69,21 +69,18 @@
 
 
 # Below this line are targets when in the COMMON directory:
-LIBAFS = libafs.o
+LIBAFS = libafs.nonfs.o
 LIBAFSNONFS = libafs.nonfs.o
 
-INST_LIBAFS = ${DESTDIR}${afskerneldir}/${LIBAFS}
+INST_LIBAFS = ${DESTDIR}${afskerneldir}/${LIBAFSNONFS}
 INST_LIBAFSNONFS = ${DESTDIR}${afskerneldir}/${LIBAFSNONFS}
 
-DEST_LIBAFS = ${DEST}/root.client/bin/${LIBAFS}
+DEST_LIBAFS = ${DEST}/root.client/bin/${LIBAFSNONFS}
 DEST_LIBAFSNONFS = ${DEST}/root.client/bin/${LIBAFSNONFS}
 
 
-# libafs:	$(LIBAFS) $(LIBAFSNONFS)
 libafs:	$(LIBAFSNONFS)
-# install_libafs:	$(INST_LIBAFS) $(INST_LIBAFSNONFS)
 install_libafs:	$(INST_LIBAFSNONFS)
-# dest_libafs:	$(DEST_LIBAFS) $(DEST_LIBAFSNONFS)
 dest_libafs:	$(DEST_LIBAFSNONFS)
 #libafs:
 #	echo WARNING: No kernel module for ${SYS_NAME}
@@ -107,18 +104,27 @@
 $(DEST_LIBAFSNONFS): $(LIBAFSNONFS)
 	$(INSTALL) -f $? $@
 
-${LIBAFS}: $(AFSAOBJS) $(AFSNFSOBJS)
-	$(LD) -r -o ${LIBAFS}.kld ${AFSAOBJS} ${AFSNFSOBJS}
-	gensetdefs ${LIBAFS}.kld
-	$(MAKE) setdef0.o setdef1.o
-	$(LD) -Bshareable -o ${LIBAFS} setdef0.o ${LIBAFS}.kld setdef1.o
+${LIBAFS}: $(AFSAOBJS) $(AFSNONFSOBJS)
+	$(LD) -r -o ${LIBAFS}.kld ${AFSAOBJS} ${AFSNONFSOBJS}
+	case ${SYS_NAME} in\
+		*fbsd_4*) \
+			gensetdefs ${LIBAFS}.kld ; \
+			$(MAKE) setdef0.o setdef1.o ; \
+			$(LD) -Bshareable -o ${LIBAFS} setdef0.o ${LIBAFS}.kld setdef1.o ;; \
+		*fbsd_5*) \
+			$(LD) -Bshareable -o ${LIBAFS} ${LIBAFS}.kld ;; \
+	esac
 
 ${LIBAFSNONFS}:  $(AFSAOBJS) $(AFSNONFSOBJS)
 	$(LD) -r -o ${LIBAFSNONFS}.kld ${AFSAOBJS} ${AFSNONFSOBJS}
-	gensetdefs ${LIBAFSNONFS}.kld
-	$(MAKE) setdef0.o setdef1.o
-	$(LD) -Bshareable -o ${LIBAFSNONFS} setdef0.o ${LIBAFSNONFS}.kld setdef1.o
-
+	case ${SYS_NAME} in\
+		*fbsd_4*) \
+			gensetdefs ${LIBAFSNONFS}.kld ; \
+			$(MAKE) setdef0.o setdef1.o ; \
+			$(LD) -Bshareable -o ${LIBAFSNONFS} setdef0.o ${LIBAFSNONFS}.kld setdef1.o ;; \
+		*fbsd_5*) \
+			$(LD) -Bshareable -o ${LIBAFSNONFS} ${LIBAFSNONFS}.kld ;; \
+	esac
 
 # Object build rules:
 osi_groups.o: $(AFS)/osi_groups.c
Index: openafs/src/rx/rx_kcommon.c
===================================================================
RCS file: /cvs/openafs/src/rx/rx_kcommon.c,v
retrieving revision 1.17
diff -u -r1.17 rx_kcommon.c
--- openafs/src/rx/rx_kcommon.c	2002/04/26 21:27:29	1.17
+++ openafs/src/rx/rx_kcommon.c	2002/06/11 19:04:59
@@ -756,7 +756,12 @@
 #ifdef AFS_SGI65_ENV
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM,IPPROTO_UDP);
 #elif defined(AFS_XBSD_ENV)
+#if defined(AFS_FBSD_KTHREAD)
+    code = socreate(AF_INET, &newSocket, SOCK_DGRAM,IPPROTO_UDP,
+		    curthread->td_ucred, curthread);
+#else
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM,IPPROTO_UDP, curproc);
+#endif /* AFS_FBSD_KTHREAD */
 #else
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0);
 #endif /* AFS_SGI65_ENV */
@@ -796,7 +801,11 @@
     }
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 #if defined(AFS_XBSD_ENV)
+#if defined(AFS_FBSD_KTHREAD)
+    code = sobind(newSocket, (struct sockaddr *)&myaddr, curthread);
+#else
     code = sobind(newSocket, (struct sockaddr *)&myaddr, curproc);
+#endif /* AFS_FBSD_KTHREAD */
 #else
     code = sobind(newSocket, (struct sockaddr *)&myaddr);
 #endif
@@ -827,7 +836,11 @@
     code = sobind(&bhv, nam);
     m_freem(nam);
 #elif defined(AFS_XBSD_ENV)
+#if defined(AFS_FBSD_KTHREAD)
+    code = sobind(newSocket, nam, curthread);
+#else
     code = sobind(newSocket, nam, curproc);
+#endif /* AFS_FBSD_KTHREAD */
 #else
     code = sobind(newSocket, nam);
 #endif
Index: openafs/src/rx/rx_kcommon.h
===================================================================
RCS file: /cvs/openafs/src/rx/rx_kcommon.h,v
retrieving revision 1.7
diff -u -r1.7 rx_kcommon.h
--- openafs/src/rx/rx_kcommon.h	2002/02/16 18:23:59	1.7
+++ openafs/src/rx/rx_kcommon.h	2002/06/11 19:04:59
@@ -45,6 +45,9 @@
 #include "../h/dirent.h"
 #include "../h/socket.h"
 #include "../h/domain.h"
+#if defined(AFS_FBSD5_ENV)
+#include "../h/bio.h"
+#endif /* AFS_FBSD5_ENV */
 #include "../h/buf.h"
 #include "../h/mbuf.h"
 #endif /* AFS_XBSD_ENV */
Index: openafs/src/rx/FBSD/rx_kmutex.h
===================================================================
RCS file: /cvs/openafs/src/rx/FBSD/rx_kmutex.h,v
retrieving revision 1.3
diff -u -r1.3 rx_kmutex.h
--- openafs/src/rx/FBSD/rx_kmutex.h	2002/02/16 18:23:59	1.3
+++ openafs/src/rx/FBSD/rx_kmutex.h	2002/06/11 19:05:00
@@ -19,6 +19,7 @@
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/lock.h>
+#include <sys/mutex.h>
 
 #define RX_ENABLE_LOCKS         1
 #define AFS_GLOBAL_RXLOCK_KERNEL
@@ -102,6 +103,7 @@
     do { \
 	(a)->owner = (struct proc *)-1; \
     } while(0);
+#if (__FreeBSD__ < 5)
 #define MUTEX_ENTER(a) \
     do { \
 	lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curproc); \
@@ -110,14 +112,33 @@
     } while(0);
 #define MUTEX_TRYENTER(a) \
     ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curproc) ? 0 : ((a)->owner = curproc, 1) )
+#else
+#define MUTEX_ENTER(a) \
+    do { \
+	lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curthread); \
+	osi_Assert((a)->owner == 0); \
+	(a)->owner = curproc; \
+    } while(0);
+#define MUTEX_TRYENTER(a) \
+    ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curthread) ? 0 : ((a)->owner = curproc, 1) )
+#endif /* __FreeBSD__ < 5 */
 #define xMUTEX_TRYENTER(a) \
     ( osi_Assert((a)->owner == 0), (a)->owner = curproc, 1)
+#if (__FreeBSD__ < 5)
 #define MUTEX_EXIT(a) \
     do { \
 	osi_Assert((a)->owner == curproc); \
 	(a)->owner = 0; \
 	lockmgr(&(a)->lock, LK_RELEASE, 0, curproc); \
     } while(0);
+#else
+#define MUTEX_EXIT(a) \
+    do { \
+	osi_Assert((a)->owner == curproc); \
+	(a)->owner = 0; \
+	lockmgr(&(a)->lock, LK_RELEASE, 0, curthread); \
+    } while(0);
+#endif /* __FreeBSD__ < 5 */
 
 #undef MUTEX_ISMINE
 #define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc)
Index: openafs/src/rx/FBSD/rx_knet.c
===================================================================
RCS file: /cvs/openafs/src/rx/FBSD/rx_knet.c,v
retrieving revision 1.6
diff -u -r1.6 rx_knet.c
--- openafs/src/rx/FBSD/rx_knet.c	2002/02/16 18:23:59	1.6
+++ openafs/src/rx/FBSD/rx_knet.c	2002/06/11 19:05:00
@@ -25,7 +25,7 @@
 
 RCSID("$Header: /cvs/openafs/src/rx/FBSD/rx_knet.c,v 1.6 2002/02/16 18:23:59 shadow Exp $");
 
-#ifdef AFS_FBSD40_ENV
+#ifdef AFS_FBSD_ENV
 #include "../rx/rx_kcommon.h"
 
 
@@ -61,7 +61,11 @@
     u.uio_resid=*alength;
     u.uio_segflg=UIO_SYSSPACE; 
     u.uio_rw=UIO_READ;
-    u.uio_procp=NULL;  
+#if defined(AFS_FBSD_KTHREAD)
+    u.uio_td=NULL;
+#else
+    u.uio_procp=NULL;
+#endif /* AFS_FBSD_KTHREAD */
 
     if (haveGlock) { 
         AFS_GUNLOCK();
@@ -134,7 +138,11 @@
     u.uio_resid=alength;
     u.uio_segflg=UIO_SYSSPACE;
     u.uio_rw=UIO_WRITE;
+#if defined(AFS_FBSD_KTHREAD)
+    u.uio_td=NULL;
+#else
     u.uio_procp=NULL;
+#endif /* AFS_FBSD_KTHREAD */    
 
     addr->sin_len=sizeof(struct sockaddr_in);
 
@@ -144,7 +152,11 @@
 #if KNET_DEBUG
     printf("+");
 #endif
+#if defined(AFS_FBSD_KTHREAD)
+    code = sosend(asocket, addr, &u, NULL, NULL, 0, curthread);
+#else
     code = sosend(asocket, addr, &u, NULL, NULL, 0, curproc);
+#endif /* AFS_FBSD_KTHREAD */
 #if KNET_DEBUG
     if (code) {
         if (code == EINVAL)
@@ -511,4 +523,4 @@
 }
 #endif
 
-#endif /* AFS_FBSD40_ENV */
+#endif /* AFS_FBSD_ENV */
