2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * MACOS OSI header file. Extends afs_osi.h.
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
18 #ifndef _OSI_MACHDEP_H_
19 #define _OSI_MACHDEP_H_
21 #ifdef XAFS_DARWIN_ENV
24 typedef unsigned short etap_event_t;
28 #ifdef AFS_DARWIN80_ENV
29 #include <kern/locks.h>
34 #include <kern/thread.h>
36 #ifdef AFS_DARWIN80_ENV
37 #define getpid() proc_selfpid()
38 #define getppid() proc_selfppid()
40 #define getpid() current_proc()->p_pid
41 #define getppid() current_proc()->p_pptr->p_pid
44 #define gop_lookupname osi_lookupname
48 /* vcexcl - used only by afs_create */
49 enum vcexcl { EXCL, NONEXCL };
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)
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
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) {
75 res = (vfs_fsprivate(mp) == &afs_fsprivate_data);
85 #ifndef AFS_DARWIN60_ENV
86 extern struct timeval time;
88 #ifdef AFS_DARWIN80_ENV
89 static inline time_t osi_Time(void) {
95 #define osi_Time() (time.tv_sec)
101 #define AFS_UCRED ucred
103 #define AFS_PROC struct proc
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);
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())
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() \
123 lk_mtx_lock(afs_global_lock); \
124 osi_Assert(afs_global_owner == 0); \
125 afs_global_owner = current_thread(); \
127 #define AFS_GUNLOCK() \
129 osi_Assert(afs_global_owner == current_thread()); \
130 afs_global_owner = 0; \
131 lk_mtx_unlock(afs_global_lock); \
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
138 extern struct lock__bsd__ afs_global_lock;
139 #define AFS_GLOCK() \
141 lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
142 osi_Assert(afs_global_owner == 0); \
143 afs_global_owner = current_thread(); \
145 #define AFS_GUNLOCK() \
147 osi_Assert(afs_global_owner == current_thread()); \
148 afs_global_owner = 0; \
149 lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
152 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
159 #define SPLVAR int x;
161 #define NETPRI x=splnet();
163 #define USERPRI splx(x);
166 #define AFS_APPL_UFS_CACHE 1
167 #define AFS_APPL_HFS_CACHE 2
169 extern ino_t VnodeToIno(struct vnode * vp);
170 extern dev_t VnodeToDev(struct vnode * vp);
172 #define osi_curproc() current_proc()
175 #define osi_curcred() &afs_osi_cred
177 #ifdef AFS_DARWIN80_ENV
178 uio_t afsio_darwin_partialcopy(uio_t auio, int size);
183 #endif /* _OSI_MACHDEP_H_ */