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>
30 #include <sys/mount.h>
35 #include <sys/vnode.h>
37 #include <kern/thread.h>
39 #ifdef AFS_DARWIN80_ENV
40 #define vop_proc vfs_context_proc(ap->a_context)
41 #define vop_cred vfs_context_ucred(ap->a_context)
42 #define cn_proc(cnp) vfs_context_proc(ap->a_context)
43 #define cn_cred(cnp) vfs_context_ucred(ap->a_context)
44 #define vop_cn_proc vfs_context_proc(ap->a_context)
45 #define vop_cn_cred vfs_context_ucred(ap->a_context)
46 #define getpid() proc_selfpid()
47 #define getppid() proc_selfppid()
49 #define vop_proc ap->a_p
50 #define vop_cred ap->a_cred
51 #define cn_proc(cnp) (cnp)->cn_proc
52 #define cn_cred(cnp) (cnp)->cn_cred
53 #define vop_cn_proc cn_proc(ap->a_cnp)
54 #define vop_cn_cred cn_cred(ap->a_cnp)
55 #define getpid() current_proc()->p_pid
56 #define getppid() current_proc()->p_pptr->p_pid
59 #define gop_lookupname osi_lookupname
63 /* vcexcl - used only by afs_create */
64 enum vcexcl { EXCL, NONEXCL };
66 #ifndef AFS_DARWIN80_ENV
67 #define vnode_clearfsnode(x) ((x)->v_data = 0)
68 #define vnode_fsnode(x) (x)->v_data
69 #define vnode_lock(x) vn_lock(x, LK_EXCLUSIVE | LK_RETRY, current_proc());
70 #define vnode_isvroot(x) (((x)->v_flag & VROOT)?1:0)
71 #define vnode_vtype(x) (x)->v_type
72 #define vnode_isdir(x) ((x)->v_type == VDIR)
74 #define vfs_flags(x) (x)->v_flags
75 #define vfs_setflags(x, y) (x)->mnt_flag |= (y)
76 #define vfs_clearflags(x, y) (x)->mnt_flag &= (~(y))
77 #define vfs_isupdate(x) ((x)->mnt_flag & MNT_UPDATE)
78 #define vfs_fsprivate(x) (x)->mnt_data
79 #define vfs_setfsprivate(x,y) (x)->mnt_data = (y)
80 #define vfs_typenum(x) (x)->mnt_vfc->vfc_typenum
83 #ifdef AFS_DARWIN80_ENV
84 #define vrele vnode_rele
85 #define vput vnode_rele
86 #define vref vnode_ref
87 #define vattr vnode_attr
89 #define vn_lock(v, unused1, unused2) vnode_get((v))
90 #define VOP_LOCK(v, unused1, unused2) vnode_get((v))
91 #define VOP_UNLOCK(v, unused1, unused2) vnode_put((v))
94 #define va_size va_data_size
95 #define va_atime va_access_time
96 #define va_mtime va_modify_time
97 #define va_ctime va_change_time
98 #define va_bytes va_total_alloc
99 #define va_blocksize va_iosize
100 #define va_nodeid va_fileid
102 #define crref kauth_cred_get_with_ref
103 #define crhold kauth_cred_ref
104 #define crfree kauth_cred_rele
105 #define crdup kauth_cred_dup
107 extern vfs_context_t afs_osi_ctxtp;
108 extern int afs_osi_ctxtp_initialized;
112 * Time related macros
114 #ifndef AFS_DARWIN60_ENV
115 extern struct timeval time;
117 #ifdef AFS_DARWIN80_ENV
118 static inline time_t osi_Time(void) {
124 #define osi_Time() (time.tv_sec)
127 #ifdef AFS_DARWIN80_ENV
131 #define PAGESIZE 8192
133 #define AFS_UCRED ucred
135 #define AFS_PROC struct proc
137 #define osi_vnhold(avc,r) VN_HOLD(AFSTOV(avc))
138 #define VN_HOLD(vp) darwin_vn_hold(vp)
139 #define VN_RELE(vp) vrele(vp);
141 void darwin_vn_hold(struct vnode *vp);
142 #ifdef AFS_DARWIN80_ENV
143 void darwin_vn_rele(struct vnode *vp);
146 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
147 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
152 extern thread_t afs_global_owner;
153 /* simple locks cannot be used since sleep can happen at any time */
154 #ifdef AFS_DARWIN80_ENV
155 /* mach locks still don't have an exported try, but we are forced to use them */
156 extern lck_mtx_t *afs_global_lock;
157 #define AFS_GLOCK() \
159 osi_Assert(afs_global_owner != current_thread()); \
160 lck_mtx_lock(afs_global_lock); \
161 osi_Assert(afs_global_owner == 0); \
162 afs_global_owner = current_thread(); \
164 #define AFS_GUNLOCK() \
166 osi_Assert(afs_global_owner == current_thread()); \
167 afs_global_owner = 0; \
168 lck_mtx_unlock(afs_global_lock); \
171 /* Should probably use mach locks rather than bsd locks, since we use the
172 mach thread control api's elsewhere (mach locks not used for consistency
173 with rx, since rx needs lock_write_try() in order to use mach locks
175 extern struct lock__bsd__ afs_global_lock;
176 #define AFS_GLOCK() \
178 lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
179 osi_Assert(afs_global_owner == 0); \
180 afs_global_owner = current_thread(); \
182 #define AFS_GUNLOCK() \
184 osi_Assert(afs_global_owner == current_thread()); \
185 afs_global_owner = 0; \
186 lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
189 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
196 #define SPLVAR int x;
198 #define NETPRI x=splnet();
200 #define USERPRI splx(x);
203 #define AFS_APPL_UFS_CACHE 1
204 #define AFS_APPL_HFS_CACHE 2
206 extern ino_t VnodeToIno(vnode_t avp);
207 extern dev_t VnodeToDev(vnode_t vp);
208 extern int igetinode(mount_t vfsp, dev_t dev , ino_t inode, vnode_t *vpp,
209 struct vattr *va, int *perror);
211 #define osi_curproc() current_proc()
214 #define osi_curcred() &afs_osi_cred
216 #ifdef AFS_DARWIN80_ENV
217 uio_t afsio_darwin_partialcopy(uio_t auio, int size);
219 #define uprintf printf
222 #ifndef AFS_DARWIN80_ENV
223 #define ifaddr_address_family(x) (x)->ifa_addr->sa_family
224 #define ifaddr_address(x, y, z) memcpy(y, (x)->ifa_addr, z)
225 #define ifaddr_netmask(x, y, z) memcpy(y, (x)->ifa_netmask, z)
226 #define ifaddr_dstaddress(x, y, z) memcpy(y, (x)->ifa_dstaddr, z)
227 #define ifaddr_ifnet(x) (x?(x)->ifa_ifp:0)
228 #define ifnet_flags(x) (x?(x)->if_flags:0)
229 #define ifnet_metric(x) (x?(x)->if_data.ifi_metric:0)
230 /*#define ifnet_mtu(x) (x)->if_mtu*/
231 #define ifaddr_withnet(x) ifa_ifwithnet(x)
236 #endif /* _OSI_MACHDEP_H_ */