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