14bc7dd09cbfa7977d958e5ec98884f6132c8d93
[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 #include <sys/user.h>
33 #endif
34 #include <kern/thread.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 #ifndef AFS_DARWIN80_ENV
52 #define ifaddr_address_family(x) (x)->ifa_addr->sa_family
53 #define ifaddr_address(x, y, z) memcpy(y, (x)->ifa_addr, z)
54 #define ifaddr_netmask(x, y, z) memcpy(y, (x)->ifa_netmask, z)
55 #define ifaddr_dstaddress(x, y, z) memcpy(y, (x)->ifa_dstaddr, z)
56 #define ifaddr_ifnet(x) (x?(x)->ifa_ifp:0)
57 #define ifnet_flags(x) (x?(x)->if_flags:0)
58 #define ifnet_metric(x) (x?(x)->if_data.ifi_metric:0)
59 #endif
60
61 #ifdef AFS_DARWIN80_ENV
62 #define vrele vnode_rele
63 #define vput vnode_put
64 #define vref vnode_ref
65 #define vattr vnode_attr
66
67 #define SetAfsVnode(vn)         /* nothing; done in getnewvnode() */
68 /* vnode_vfsfsprivate is not declared, so no macro for us */
69 extern void * afs_fsprivate_data;
70 static inline int IsAfsVnode(vnode_t vn) {
71    mount_t mp;
72    int res = 0;
73    mp = vnode_mount(vn);
74    if (mp) {
75       res = (vfs_fsprivate(mp) == &afs_fsprivate_data);
76       vfs_mountrelease(mp);
77    }
78    return res;
79 }
80 #endif
81
82 /* 
83  * Time related macros
84  */
85 #ifndef AFS_DARWIN60_ENV
86 extern struct timeval time;
87 #endif
88 #ifdef AFS_DARWIN80_ENV
89 static inline time_t osi_Time(void) {
90     struct timeval _now;
91     microtime(&_now);
92     return _now.tv_sec;
93 }
94 #else
95 #define osi_Time() (time.tv_sec)
96 #endif
97 #define afs_hz      hz
98
99 #define PAGESIZE 8192
100
101 #define AFS_UCRED       ucred
102
103 #define AFS_PROC        struct proc
104
105 #define osi_vnhold(avc,r)       VN_HOLD(AFSTOV(avc))
106 #define VN_HOLD(vp) darwin_vn_hold(vp)
107 #define VN_RELE(vp) vrele(vp);
108
109
110 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
111   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
112
113 #undef afs_suser
114
115 #ifdef KERNEL
116 extern thread_t afs_global_owner;
117 /* simple locks cannot be used since sleep can happen at any time */
118 #ifdef AFS_DARWIN80_ENV
119 /* mach locks still don't have an exported try, but we are forced to use them */
120 extern lck_mtx_t  *afs_global_lock;
121 #define AFS_GLOCK() \
122     do { \
123         lk_mtx_lock(afs_global_lock); \
124         osi_Assert(afs_global_owner == 0); \
125         afs_global_owner = current_thread(); \
126     } while (0)
127 #define AFS_GUNLOCK() \
128     do { \
129         osi_Assert(afs_global_owner == current_thread()); \
130         afs_global_owner = 0; \
131         lk_mtx_unlock(afs_global_lock); \
132     } while(0)
133 #else
134 /* Should probably use mach locks rather than bsd locks, since we use the
135    mach thread control api's elsewhere (mach locks not used for consistency
136    with rx, since rx needs lock_write_try() in order to use mach locks
137  */
138 extern struct lock__bsd__ afs_global_lock;
139 #define AFS_GLOCK() \
140     do { \
141         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
142         osi_Assert(afs_global_owner == 0); \
143         afs_global_owner = current_thread(); \
144     } while (0)
145 #define AFS_GUNLOCK() \
146     do { \
147         osi_Assert(afs_global_owner == current_thread()); \
148         afs_global_owner = 0; \
149         lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
150     } while(0)
151 #endif
152 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
153
154 #define SPLVAR
155 #define NETPRI
156 #define USERPRI
157 #if 0
158 #undef SPLVAR
159 #define SPLVAR int x;
160 #undef NETPRI
161 #define NETPRI x=splnet();
162 #undef USERPRI
163 #define USERPRI splx(x);
164 #endif
165
166 #define AFS_APPL_UFS_CACHE 1
167 #define AFS_APPL_HFS_CACHE 2
168
169 extern ino_t VnodeToIno(struct vnode * vp);
170 extern dev_t VnodeToDev(struct vnode * vp);
171
172 #define osi_curproc() current_proc()
173
174 /* FIXME */
175 #define osi_curcred() &afs_osi_cred 
176
177 #ifdef AFS_DARWIN80_ENV
178 uio_t afsio_darwin_partialcopy(uio_t auio, int size);
179 #endif
180
181 #endif /* KERNEL */
182
183 #endif /* _OSI_MACHDEP_H_ */