DARWIN: remove errant typedef for etap_event_t
[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
22 #ifdef AFS_DARWIN80_ENV
23 #include <kern/locks.h>
24 #include <sys/mount.h>
25 #include <h/vnode.h>
26 #else
27 #include <sys/lock.h>
28 #include <sys/user.h>
29 #include <sys/vnode.h>
30 #endif
31 #include <sys/kauth.h>
32 #include <kern/thread.h>
33
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()
43 #else
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
52 #endif
53 #undef gop_lookupname
54 #define gop_lookupname osi_lookupname
55 #undef gop_lookupname_user
56 #define gop_lookupname_user osi_lookupname_user
57
58 #define FTRUNC 0
59
60 /* vcexcl - used only by afs_create */
61 enum vcexcl { EXCL, NONEXCL };
62
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)
70
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
78 #endif
79
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
85
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
93
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)
98 #else
99 #define crfree kauth_cred_rele
100 #endif
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)
104 #else
105 #define ubc_msync_range(X,Y,Z,A) ubc_sync_range(X,Y,Z,A)
106 #endif
107 extern vfs_context_t afs_osi_ctxtp;
108 extern int afs_osi_ctxtp_initialized;
109 #endif
110 extern u_int32_t afs_darwin_realmodes;
111 extern u_int32_t afs_darwin_fsevents;
112
113 /*
114  * Time related macros
115  */
116 #ifdef AFS_DARWIN80_ENV
117 static inline time_t osi_Time(void) {
118     struct timeval _now;
119     microtime(&_now);
120     return _now.tv_sec;
121 }
122 #else
123 #define osi_Time() (time.tv_sec)
124 #endif
125 #define afs_hz      hz
126 #ifdef AFS_DARWIN80_ENV
127 extern int hz;
128 #endif
129
130 typedef struct ucred afs_ucred_t;
131 typedef struct proc afs_proc_t;
132
133 #define VN_HOLD(vp) darwin_vn_hold(vp)
134 #define VN_RELE(vp) vrele(vp)
135
136 void darwin_vn_hold(struct vnode *vp);
137
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())
140
141 #undef afs_suser
142
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() \
149     do { \
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(); \
154     } while (0)
155 #define AFS_GUNLOCK() \
156     do { \
157         osi_Assert(afs_global_owner == current_thread()); \
158         afs_global_owner = 0; \
159         lck_mtx_unlock(afs_global_lock); \
160     } while(0)
161 #define osi_InitGlock() \
162     do { \
163         afs_global_owner = 0; \
164     } while (0)
165 #else
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
169  */
170 extern struct lock__bsd__ afs_global_lock;
171 #define AFS_GLOCK() \
172     do { \
173         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
174         osi_Assert(afs_global_owner == 0); \
175         afs_global_owner = current_thread(); \
176     } while (0)
177 #define AFS_GUNLOCK() \
178     do { \
179         osi_Assert(afs_global_owner == current_thread()); \
180         afs_global_owner = 0; \
181         lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
182     } while(0)
183 #define osi_InitGlock() \
184     do { \
185         lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
186         afs_global_owner = 0; \
187     } while (0)
188 #endif
189 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
190
191 #define SPLVAR
192 #define NETPRI
193 #define USERPRI
194 #define AFS_APPL_UFS_CACHE 1
195 #define AFS_APPL_HFS_CACHE 2
196 #define AFS_APPL_APFS_CACHE 3
197
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);
202
203 #define osi_curproc() current_proc()
204
205 /* FIXME */
206 #define osi_curcred() &afs_osi_cred
207
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
212 #endif
213
214 /* Vnode related macros */
215
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)
223 #else
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() */
230 #endif
231
232 #ifdef AFS_DARWIN80_ENV
233 #define osi_procname(procname, size) proc_selfname(procname, size)
234 #else
235 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
236 #endif
237
238 #endif /* _OSI_MACHDEP_H_ */