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