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_
22 #ifdef AFS_DARWIN80_ENV
23 #include <kern/locks.h>
24 #include <sys/mount.h>
29 #include <sys/vnode.h>
31 #include <sys/kauth.h>
32 #include <kern/thread.h>
34 #ifdef AFS_DARWIN80_ENV
35 #define vop_proc vfs_context_proc(ap->a_context)
36 #define vop_cred vfs_context_ucred(ap->a_context)
37 #define cn_proc(cnp) vfs_context_proc(ap->a_context)
38 #define cn_cred(cnp) vfs_context_ucred(ap->a_context)
39 #define vop_cn_proc vfs_context_proc(ap->a_context)
40 #define vop_cn_cred vfs_context_ucred(ap->a_context)
41 #define getpid() proc_selfpid()
42 #define getppid() proc_selfppid()
44 #define vop_proc ap->a_p
45 #define vop_cred ap->a_cred
46 #define cn_proc(cnp) (cnp)->cn_proc
47 #define cn_cred(cnp) (cnp)->cn_cred
48 #define vop_cn_proc cn_proc(ap->a_cnp)
49 #define vop_cn_cred cn_cred(ap->a_cnp)
50 #define getpid() current_proc()->p_pid
51 #define getppid() current_proc()->p_pptr->p_pid
54 #define gop_lookupname osi_lookupname
55 #undef gop_lookupname_user
56 #define gop_lookupname_user osi_lookupname_user
60 /* vcexcl - used only by afs_create */
61 enum vcexcl { EXCL, NONEXCL };
63 #ifndef AFS_DARWIN80_ENV
64 #define vnode_clearfsnode(x) ((x)->v_data = 0)
65 #define vnode_fsnode(x) (x)->v_data
66 #define vnode_lock(x) vn_lock(x, LK_EXCLUSIVE | LK_RETRY, current_proc())
67 #define vnode_isvroot(x) (((x)->v_flag & VROOT)?1:0)
68 #define vnode_vtype(x) (x)->v_type
69 #define vnode_isdir(x) ((x)->v_type == VDIR)
71 #define vfs_flags(x) (x)->v_flags
72 #define vfs_setflags(x, y) (x)->mnt_flag |= (y)
73 #define vfs_clearflags(x, y) (x)->mnt_flag &= (~(y))
74 #define vfs_isupdate(x) ((x)->mnt_flag & MNT_UPDATE)
75 #define vfs_fsprivate(x) (x)->mnt_data
76 #define vfs_setfsprivate(x,y) (x)->mnt_data = (y)
77 #define vfs_typenum(x) (x)->mnt_vfc->vfc_typenum
80 #ifdef AFS_DARWIN80_ENV
81 #define vrele vnode_rele
82 #define vput vnode_rele
83 #define vref vnode_ref
84 #define vattr vnode_attr
86 #define va_size va_data_size
87 #define va_atime va_access_time
88 #define va_mtime va_modify_time
89 #define va_ctime va_change_time
90 #define va_bytes va_total_alloc
91 #define va_blocksize va_iosize
92 #define va_nodeid va_fileid
94 #define crref kauth_cred_get_with_ref
95 #define crhold kauth_cred_ref
96 #ifdef AFS_DARWIN100_ENV
97 #define crfree(X) kauth_cred_unref(&X)
99 #define crfree kauth_cred_rele
101 #define crdup kauth_cred_dup
102 #ifdef AFS_DARWIN100_ENV
103 #define ubc_msync_range(X,Y,Z,A) ubc_msync(X,Y,Z,NULL,A)
105 #define ubc_msync_range(X,Y,Z,A) ubc_sync_range(X,Y,Z,A)
107 extern vfs_context_t afs_osi_ctxtp;
108 extern int afs_osi_ctxtp_initialized;
110 extern u_int32_t afs_darwin_realmodes;
111 extern u_int32_t afs_darwin_fsevents;
114 * Time related macros
116 #ifdef AFS_DARWIN80_ENV
117 static inline time_t osi_Time(void) {
123 #define osi_Time() (time.tv_sec)
126 #ifdef AFS_DARWIN80_ENV
130 typedef struct ucred afs_ucred_t;
131 typedef struct proc afs_proc_t;
133 #define VN_HOLD(vp) darwin_vn_hold(vp)
134 #define VN_RELE(vp) vrele(vp)
136 void darwin_vn_hold(struct vnode *vp);
138 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
139 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
143 extern thread_t afs_global_owner;
144 /* simple locks cannot be used since sleep can happen at any time */
145 #ifdef AFS_DARWIN80_ENV
146 /* mach locks still don't have an exported try, but we are forced to use them */
147 extern lck_mtx_t *afs_global_lock;
148 #define AFS_GLOCK() \
150 osi_Assert(afs_global_owner != current_thread()); \
151 lck_mtx_lock(afs_global_lock); \
152 osi_Assert(afs_global_owner == 0); \
153 afs_global_owner = current_thread(); \
155 #define AFS_GUNLOCK() \
157 osi_Assert(afs_global_owner == current_thread()); \
158 afs_global_owner = 0; \
159 lck_mtx_unlock(afs_global_lock); \
161 #define osi_InitGlock() \
163 afs_global_owner = 0; \
166 /* Should probably use mach locks rather than bsd locks, since we use the
167 mach thread control api's elsewhere (mach locks not used for consistency
168 with rx, since rx needs lock_write_try() in order to use mach locks
170 extern struct lock__bsd__ afs_global_lock;
171 #define AFS_GLOCK() \
173 lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
174 osi_Assert(afs_global_owner == 0); \
175 afs_global_owner = current_thread(); \
177 #define AFS_GUNLOCK() \
179 osi_Assert(afs_global_owner == current_thread()); \
180 afs_global_owner = 0; \
181 lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
183 #define osi_InitGlock() \
185 lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
186 afs_global_owner = 0; \
189 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
194 #define AFS_APPL_UFS_CACHE 1
195 #define AFS_APPL_HFS_CACHE 2
196 #define AFS_APPL_APFS_CACHE 3
198 extern ino_t VnodeToIno(vnode_t avp);
199 extern dev_t VnodeToDev(vnode_t vp);
200 extern int igetinode(mount_t vfsp, dev_t dev , ino_t inode, vnode_t *vpp,
201 struct vattr *va, int *perror);
203 #define osi_curproc() current_proc()
206 #define osi_curcred() afs_osi_credp
208 #ifdef AFS_DARWIN80_ENV
209 # define afsio_free(X) uio_free(X)
210 # define afsio_setoffset(X, Y) uio_setoffset(X, Y)
211 # define uprintf printf
214 /* Vnode related macros */
216 #if defined(AFS_DARWIN80_ENV)
217 extern int afs_vfs_typenum;
218 # define vType(vc) vnode_vtype(AFSTOV(vc))
219 # define vSetVfsp(vc, vfsp)
220 # define vSetType(vc, type) (vc)->f.m.Type = (type)
221 # define SetAfsVnode(vn) /* nothing; done in getnewvnode() */
222 # define IsAfsVnode(v) (vfs_typenum(vnode_mount((v))) == afs_vfs_typenum)
224 extern int (**afs_vnodeop_p) ();
225 # define vType(vc) AFSTOV(vc)->v_type
226 # define vSetVfsp(vc, vfsp) AFSTOV(vc)->v_mount = (vfsp)
227 # define vSetType(vc, type) AFSTOV(vc)->v_type = (type)
228 # define IsAfsVnode(v) ((v)->v_op == afs_vnodeop_p)
229 # define SetAfsVnode(v) /* nothing; done in getnewvnode() */
232 #ifdef AFS_DARWIN80_ENV
233 #define osi_procname(procname, size) proc_selfname(procname, size)
235 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
239 osi_GetTime(osi_timeval32_t *atv)
243 atv->tv_sec = now.tv_sec;
244 atv->tv_usec = now.tv_usec;
247 #endif /* _OSI_MACHDEP_H_ */