d098c9603f19bcfbdebb1fea275b598b4020be61
[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 /* 
29  * Time related macros
30  */
31 #define osi_Time()      time_second
32 #define afs_hz          hz
33
34 #define PAGESIZE 8192
35
36 #define AFS_UCRED       ucred
37 #define AFS_PROC        struct proc
38
39 #define afs_bufferpages bufpages
40 #ifndef iodone
41 #define iodone biodone
42 #endif
43
44 #define osi_vnhold(avc,r)       vref(AFSTOV(avc))
45 #undef vSetVfsp
46 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
47 #undef vSetType
48 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
49 #undef vType
50 #define vType(vc)               AFSTOV(vc)->v_type
51
52 #undef gop_lookupname
53 #define gop_lookupname osi_lookupname
54
55 #undef afs_suser
56
57 #define afs_strcat(s1, s2)      strcat((s1), (s2))
58
59 #ifdef KERNEL
60
61 #undef afs_osi_Alloc_NoSleep
62 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
63
64 #define VN_RELE(vp)             vrele(vp)
65 #define VN_HOLD(vp)             VREF(vp)
66
67 #ifdef AFS_FBSD60_ENV
68 #undef IsAfsVnode
69 #define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
70 extern struct vop_vector afs_vnodeops;
71 #endif
72
73 #undef osi_getpid
74 #if defined(AFS_FBSD50_ENV)
75 #define VT_AFS          "afs"
76 #define VROOT           VV_ROOT
77 #define v_flag          v_vflag
78 #define osi_curcred()   (curthread->td_ucred)
79 #define afs_suser(x)    (!suser(curthread))
80 #define osi_getpid()    (curthread->td_proc->p_pid)
81 #define simple_lock(x)  mtx_lock(x)
82 #define simple_unlock(x) mtx_unlock(x)
83 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
84   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
85 extern struct mtx afs_global_mtx;
86 #define AFS_GLOCK() mtx_lock(&afs_global_mtx)
87 #define AFS_GUNLOCK() mtx_unlock(&afs_global_mtx)
88 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
89
90 #else /* FBSD50 */
91 extern struct lock afs_global_lock;
92
93 #define osi_curcred()   (curproc->p_cred->pc_ucred)
94 #define afs_suser(x)    (!suser(curproc))
95 #define osi_getpid()    (curproc->p_pid)
96 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
97   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
98 extern struct proc *afs_global_owner;
99 #define AFS_GLOCK() \
100     do { \
101         osi_Assert(curproc); \
102         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
103         osi_Assert(afs_global_owner == 0); \
104         afs_global_owner = curproc; \
105     } while (0)
106 #define AFS_GUNLOCK() \
107     do { \
108         osi_Assert(curproc); \
109         osi_Assert(afs_global_owner == curproc); \
110         afs_global_owner = 0; \
111         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
112     } while(0)
113 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
114 #endif /* FBSD50 */
115
116 #undef SPLVAR
117 #define SPLVAR int splvar
118 #undef NETPRI
119 #define NETPRI splvar=splnet()
120 #undef USERPRI
121 #define USERPRI splx(splvar)
122 #endif /* KERNEL */
123
124 #define ifnet_flags(x) (x?(x)->if_flags:0)
125
126 #endif /* _OSI_MACHDEP_H_ */