f7db2cd7cfae487565f2ee20475c67a898c126f2
[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 #ifdef XAFS_DARWIN_ENV
22 #ifndef _MACH_ETAP_H_
23 #define _MACH_ETAP_H_
24 typedef unsigned short etap_event_t;
25 #endif
26 #endif
27
28 #ifdef AFS_DARWIN80_ENV
29 #include <kern/locks.h>
30 #else
31 #include <sys/lock.h>
32 #include <sys/user.h>
33 #endif
34 #include <kern/thread.h>
35
36 #ifdef AFS_DARWIN80_ENV
37 #define getpid()                proc_selfpid()
38 #define getppid()               proc_selfppid()
39 #else
40 #define getpid()                current_proc()->p_pid
41 #define getppid()               current_proc()->p_pptr->p_pid
42 #endif
43 #undef gop_lookupname
44 #define gop_lookupname osi_lookupname
45
46 #define FTRUNC 0
47
48 /* vcexcl - used only by afs_create */
49 enum vcexcl { EXCL, NONEXCL };
50
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)
59 #endif
60
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)
69
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)
74 #endif
75
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
81
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
89
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) {
94    mount_t mp;
95    int res = 0;
96    mp = vnode_mount(vn);
97    if (mp) {
98       res = (vfs_fsprivate(mp) == &afs_fsprivate_data);
99       vfs_mountrelease(mp);
100    }
101    return res;
102 }
103 #endif
104
105 /* 
106  * Time related macros
107  */
108 #ifndef AFS_DARWIN60_ENV
109 extern struct timeval time;
110 #endif
111 #ifdef AFS_DARWIN80_ENV
112 static inline time_t osi_Time(void) {
113     struct timeval _now;
114     microtime(&_now);
115     return _now.tv_sec;
116 }
117 #else
118 #define osi_Time() (time.tv_sec)
119 #endif
120 #define afs_hz      hz
121
122 #define PAGESIZE 8192
123
124 #define AFS_UCRED       ucred
125
126 #define AFS_PROC        struct proc
127
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);
131
132
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())
135
136 #undef afs_suser
137
138 #ifdef KERNEL
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() \
145     do { \
146         lk_mtx_lock(afs_global_lock); \
147         osi_Assert(afs_global_owner == 0); \
148         afs_global_owner = current_thread(); \
149     } while (0)
150 #define AFS_GUNLOCK() \
151     do { \
152         osi_Assert(afs_global_owner == current_thread()); \
153         afs_global_owner = 0; \
154         lk_mtx_unlock(afs_global_lock); \
155     } while(0)
156 #else
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
160  */
161 extern struct lock__bsd__ afs_global_lock;
162 #define AFS_GLOCK() \
163     do { \
164         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
165         osi_Assert(afs_global_owner == 0); \
166         afs_global_owner = current_thread(); \
167     } while (0)
168 #define AFS_GUNLOCK() \
169     do { \
170         osi_Assert(afs_global_owner == current_thread()); \
171         afs_global_owner = 0; \
172         lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
173     } while(0)
174 #endif
175 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
176
177 #define SPLVAR
178 #define NETPRI
179 #define USERPRI
180 #if 0
181 #undef SPLVAR
182 #define SPLVAR int x;
183 #undef NETPRI
184 #define NETPRI x=splnet();
185 #undef USERPRI
186 #define USERPRI splx(x);
187 #endif
188
189 #define AFS_APPL_UFS_CACHE 1
190 #define AFS_APPL_HFS_CACHE 2
191
192 extern ino_t VnodeToIno(struct vnode * vp);
193 extern dev_t VnodeToDev(struct vnode * vp);
194
195 #define osi_curproc() current_proc()
196
197 /* FIXME */
198 #define osi_curcred() &afs_osi_cred 
199
200 #ifdef AFS_DARWIN80_ENV
201 uio_t afsio_darwin_partialcopy(uio_t auio, int size);
202 #endif
203
204 #endif /* KERNEL */
205
206 #endif /* _OSI_MACHDEP_H_ */