freebsd-50-20030416
[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 /* #include <kern/sched_prim.h> */
25 /* #include <sys/unix_defs.h> */
26
27 #define getpid()                curproc
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
43 #define osi_vnhold(avc,r) do { VN_HOLD((struct vnode *)(avc)); } while (0)
44
45 #undef gop_lookupname
46 #define gop_lookupname osi_lookupname
47
48 #undef afs_suser
49
50 #ifdef KERNEL
51 extern struct lock afs_global_lock;
52
53 #if defined(AFS_FBSD50_ENV)
54 #define VT_AFS          "afs"
55 #define VROOT           VV_ROOT
56 #define v_flag          v_vflag
57 #define afs_suser()     (!suser(curthread))
58 #define simple_lock(x)  mtx_lock(x)
59 #define simple_unlock(x) mtx_unlock(x)
60 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
61   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
62 extern struct thread * afs_global_owner;
63 #define AFS_GLOCK() \
64     do { \
65         osi_Assert(curthread); \
66         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curthread); \
67         osi_Assert(afs_global_owner == 0); \
68         afs_global_owner = curthread; \
69     } while (0)
70 #define AFS_GUNLOCK() \
71     do { \
72         osi_Assert(curthread); \
73         osi_Assert(afs_global_owner == curthread); \
74         afs_global_owner = 0; \
75         lockmgr(&afs_global_lock, LK_RELEASE, 0, curthread); \
76     } while(0)
77 #define ISAFS_GLOCK() (afs_global_owner == curthread && curthread)
78
79 #else /* FBSD50 */
80
81 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
82   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
83 extern struct proc * afs_global_owner;
84 #define AFS_GLOCK() \
85     do { \
86         osi_Assert(curproc); \
87         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
88         osi_Assert(afs_global_owner == 0); \
89         afs_global_owner = curproc; \
90     } while (0)
91 #define AFS_GUNLOCK() \
92     do { \
93         osi_Assert(curproc); \
94         osi_Assert(afs_global_owner == curproc); \
95         afs_global_owner = 0; \
96         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
97     } while(0)
98 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
99 #endif /* FBSD50 */
100
101 #define AFS_RXGLOCK()
102 #define AFS_RXGUNLOCK()
103 #define ISAFS_RXGLOCK() 1
104
105 #undef SPLVAR
106 #define SPLVAR int splvar
107 #undef NETPRI
108 #define NETPRI splvar=splnet()
109 #undef USERPRI
110 #define USERPRI splx(splvar)
111 #endif /* KERNEL */
112
113 #endif /* _OSI_MACHDEP_H_ */