freebsd60-20050422
[openafs.git] / src / afs / FBSD / osi_machdep.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  *
12  * FBSD OSI header file. Extends afs_osi.h.
13  *
14  * afs_osi.h includes this file, which is the only way this file should
15  * be included in a source file. This file can redefine macros declared in
16  * afs_osi.h.
17  */
18
19 #ifndef _OSI_MACHDEP_H_
20 #define _OSI_MACHDEP_H_
21
22 #include <sys/lock.h>
23 #include <sys/time.h>
24 #if defined(AFS_FBSD50_ENV)
25 #include <sys/mutex.h>
26 #endif
27
28 extern struct simplelock afs_rxglobal_lock;
29
30 /* 
31  * Time related macros
32  */
33 #define osi_Time()      time_second
34 #define afs_hz          hz
35
36 #define PAGESIZE 8192
37
38 #define AFS_UCRED       ucred
39 #define AFS_PROC        struct proc
40
41 #define afs_bufferpages bufpages
42 #ifndef iodone
43 #define iodone biodone
44 #endif
45
46 #define osi_vnhold(avc,r)       vref(AFSTOV(avc))
47 #undef vSetVfsp
48 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
49 #undef vSetType
50 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
51 #undef vType
52 #define vType(vc)               AFSTOV(vc)->v_type
53
54 #undef gop_lookupname
55 #define gop_lookupname osi_lookupname
56
57 #undef afs_suser
58
59 #define afs_strcat(s1, s2)      strcat((s1), (s2))
60
61 #ifdef KERNEL
62
63 #undef afs_osi_Alloc_NoSleep
64 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
65
66 #define VN_RELE(vp)             vrele(vp)
67 #define VN_HOLD(vp)             VREF(vp)
68
69 #ifdef AFS_FBSD60_ENV
70 #undef IsAfsVnode
71 #define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
72 extern struct vop_vector afs_vnodeops;
73 #endif
74
75 #if defined(AFS_FBSD50_ENV)
76 #define VT_AFS          "afs"
77 #define VROOT           VV_ROOT
78 #define v_flag          v_vflag
79 #define osi_curcred()   (curthread->td_ucred)
80 #define afs_suser(x)    (!suser(curthread))
81 #define getpid()        (curthread->td_proc->p_pid)
82 #define simple_lock(x)  mtx_lock(x)
83 #define simple_unlock(x) mtx_unlock(x)
84 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
85   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
86 extern struct mtx afs_global_mtx;
87 #define AFS_GLOCK() mtx_lock(&afs_global_mtx)
88 #define AFS_GUNLOCK() mtx_unlock(&afs_global_mtx)
89 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
90
91 #else /* FBSD50 */
92 extern struct lock afs_global_lock;
93
94 #define osi_curcred()   (curproc->p_cred->pc_ucred)
95 #define afs_suser(x)    (!suser(curproc))
96 #define getpid()        (curproc->p_pid)
97 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
98   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
99 extern struct proc *afs_global_owner;
100 #define AFS_GLOCK() \
101     do { \
102         osi_Assert(curproc); \
103         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
104         osi_Assert(afs_global_owner == 0); \
105         afs_global_owner = curproc; \
106     } while (0)
107 #define AFS_GUNLOCK() \
108     do { \
109         osi_Assert(curproc); \
110         osi_Assert(afs_global_owner == curproc); \
111         afs_global_owner = 0; \
112         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
113     } while(0)
114 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
115 #endif /* FBSD50 */
116
117 #undef SPLVAR
118 #define SPLVAR int splvar
119 #undef NETPRI
120 #define NETPRI splvar=splnet()
121 #undef USERPRI
122 #define USERPRI splx(splvar)
123 #endif /* KERNEL */
124
125 #endif /* _OSI_MACHDEP_H_ */