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 #ifndef AFS_DARWIN80_ENV
62 #define ifaddr_address_family(x) (x)->ifa_addr->sa_family
63 #define ifaddr_address(x, y, z) memcpy(y, (x)->ifa_addr, z)
64 #define ifaddr_netmask(x, y, z) memcpy(y, (x)->ifa_netmask, z)
65 #define ifaddr_dstaddress(x, y, z) memcpy(y, (x)->ifa_dstaddr, z)
66 #define ifaddr_ifnet(x) (x?(x)->ifa_ifp:0)
67 #define ifnet_flags(x) (x?(x)->if_flags:0)
68 #define ifnet_metric(x) (x?(x)->if_data.ifi_metric:0)
70 #define vnode_clearfsnode(x) ((x)->v_data = 0)
71 #define vnode_fsnode(x) (x)->v_data
72 #define vnode_lock(x) vn_lock(x, LK_EXCLUSIVE | LK_RETRY, current_proc());
73 #define vnode_isvroot(x) (((x)->v_flag & VROOT)?1:0)
76 #ifdef AFS_DARWIN80_ENV
77 #define vrele vnode_rele
78 #define vput vnode_put
79 #define vref vnode_ref
80 #define vattr vnode_attr
82 #define va_size va_data_size
83 #define va_atime va_access_time
84 #define va_mtime va_modify_time
85 #define va_ctime va_change_time
86 #define va_bytes va_total_alloc
87 #define va_blocksize va_iosize
88 #define va_nodeid va_fileid
90 #define SetAfsVnode(vn) /* nothing; done in getnewvnode() */
91 /* vnode_vfsfsprivate is not declared, so no macro for us */
92 extern void * afs_fsprivate_data;
93 static inline int IsAfsVnode(vnode_t vn) {
98 res = (vfs_fsprivate(mp) == &afs_fsprivate_data);
106 * Time related macros
108 #ifndef AFS_DARWIN60_ENV
109 extern struct timeval time;
111 #ifdef AFS_DARWIN80_ENV
112 static inline time_t osi_Time(void) {
118 #define osi_Time() (time.tv_sec)
122 #define PAGESIZE 8192
124 #define AFS_UCRED ucred
126 #define AFS_PROC struct proc
128 #define osi_vnhold(avc,r) VN_HOLD(AFSTOV(avc))
129 #define VN_HOLD(vp) darwin_vn_hold(vp)
130 #define VN_RELE(vp) vrele(vp);
133 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
134 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
139 extern thread_t afs_global_owner;
140 /* simple locks cannot be used since sleep can happen at any time */
141 #ifdef AFS_DARWIN80_ENV
142 /* mach locks still don't have an exported try, but we are forced to use them */
143 extern lck_mtx_t *afs_global_lock;
144 #define AFS_GLOCK() \
146 lk_mtx_lock(afs_global_lock); \
147 osi_Assert(afs_global_owner == 0); \
148 afs_global_owner = current_thread(); \
150 #define AFS_GUNLOCK() \
152 osi_Assert(afs_global_owner == current_thread()); \
153 afs_global_owner = 0; \
154 lk_mtx_unlock(afs_global_lock); \
157 /* Should probably use mach locks rather than bsd locks, since we use the
158 mach thread control api's elsewhere (mach locks not used for consistency
159 with rx, since rx needs lock_write_try() in order to use mach locks
161 extern struct lock__bsd__ afs_global_lock;
162 #define AFS_GLOCK() \
164 lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
165 osi_Assert(afs_global_owner == 0); \
166 afs_global_owner = current_thread(); \
168 #define AFS_GUNLOCK() \
170 osi_Assert(afs_global_owner == current_thread()); \
171 afs_global_owner = 0; \
172 lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
175 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
182 #define SPLVAR int x;
184 #define NETPRI x=splnet();
186 #define USERPRI splx(x);
189 #define AFS_APPL_UFS_CACHE 1
190 #define AFS_APPL_HFS_CACHE 2
192 extern ino_t VnodeToIno(struct vnode * vp);
193 extern dev_t VnodeToDev(struct vnode * vp);
195 #define osi_curproc() current_proc()
198 #define osi_curcred() &afs_osi_cred
200 #ifdef AFS_DARWIN80_ENV
201 uio_t afsio_darwin_partialcopy(uio_t auio, int size);
206 #endif /* _OSI_MACHDEP_H_ */