macos-104-not-yet-20050508
[openafs.git] / src / afs / DARWIN / 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  * MACOS OSI header file. Extends afs_osi.h.
12  *
13  * afs_osi.h includes this file, which is the only way this file should
14  * be included in a source file. This file can redefine macros declared in
15  * afs_osi.h.
16  */
17
18 #ifndef _OSI_MACHDEP_H_
19 #define _OSI_MACHDEP_H_
20
21 #ifdef XAFS_DARWIN_ENV
22 #ifndef _MACH_ETAP_H_
23 #define _MACH_ETAP_H_
24 typedef unsigned short etap_event_t;
25 #endif
26 #endif
27
28 #ifdef AFS_DARWIN80_ENV
29 #include <kern/locks.h>
30 #else
31 #include <sys/lock.h>
32 #endif
33 #include <kern/thread.h>
34 #include <sys/user.h>
35
36 #ifdef AFS_DARWIN80_ENV
37 #define getpid()                proc_selfpid()
38 #define getppid()               proc_selfppid()
39 #else
40 #define getpid()                current_proc()->p_pid
41 #define getppid()               current_proc()->p_pptr->p_pid
42 #endif
43 #undef gop_lookupname
44 #define gop_lookupname osi_lookupname
45
46 #define FTRUNC 0
47
48 /* vcexcl - used only by afs_create */
49 enum vcexcl { EXCL, NONEXCL };
50
51 #ifdef AFS_DARWIN80_ENV
52 #define vrele vnode_rele
53 #define vput vnode_put
54 #define vref vnode_ref
55 #endif
56
57 /* 
58  * Time related macros
59  */
60 #ifndef AFS_DARWIN60_ENV
61 extern struct timeval time;
62 #endif
63 #define osi_Time() (time.tv_sec)
64 #define afs_hz      hz
65
66 #define PAGESIZE 8192
67
68 #define AFS_UCRED       ucred
69
70 #define AFS_PROC        struct proc
71
72 #define osi_vnhold(avc,r)       VN_HOLD(AFSTOV(avc))
73 #define VN_HOLD(vp) darwin_vn_hold(vp)
74 #define VN_RELE(vp) vrele(vp);
75
76
77 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
78   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
79
80 #undef afs_suser
81
82 #ifdef KERNEL
83 extern thread_t afs_global_owner;
84 /* simple locks cannot be used since sleep can happen at any time */
85 #ifdef AFS_DARWIN80_ENV
86 /* mach locks still don't have an exported try, but we are forced to use them */
87 extern lck_mtx_t  *afs_global_lock;
88 #define AFS_GLOCK() \
89     do { \
90         lk_mtx_lock(afs_global_lock); \
91         osi_Assert(afs_global_owner == 0); \
92         afs_global_owner = current_thread(); \
93     } while (0)
94 #define AFS_GUNLOCK() \
95     do { \
96         osi_Assert(afs_global_owner == current_thread()); \
97         afs_global_owner = 0; \
98         lk_mtx_unlock(afs_global_lock); \
99     } while(0)
100 #else
101 /* Should probably use mach locks rather than bsd locks, since we use the
102    mach thread control api's elsewhere (mach locks not used for consistency
103    with rx, since rx needs lock_write_try() in order to use mach locks
104  */
105 extern struct lock__bsd__ afs_global_lock;
106 #define AFS_GLOCK() \
107     do { \
108         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
109         osi_Assert(afs_global_owner == 0); \
110         afs_global_owner = current_thread(); \
111     } while (0)
112 #define AFS_GUNLOCK() \
113     do { \
114         osi_Assert(afs_global_owner == current_thread()); \
115         afs_global_owner = 0; \
116         lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
117     } while(0)
118 #endif
119 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
120
121 #define SPLVAR
122 #define NETPRI
123 #define USERPRI
124 #if 0
125 #undef SPLVAR
126 #define SPLVAR int x;
127 #undef NETPRI
128 #define NETPRI x=splnet();
129 #undef USERPRI
130 #define USERPRI splx(x);
131 #endif
132
133 #define AFS_APPL_UFS_CACHE 1
134 #define AFS_APPL_HFS_CACHE 2
135
136 extern ino_t VnodeToIno(vnode_t * vp);
137 extern dev_t VnodeToDev(vnode_t * vp);
138
139 #define osi_curproc() current_proc()
140
141 /* FIXME */
142 #define osi_curcred() &afs_osi_cred 
143
144 #endif /* KERNEL */
145
146 #endif /* _OSI_MACHDEP_H_ */