Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / OBSD / 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 *
12 * OpenBSD OSI header file. Extends afs_osi.h.
13 *
14 * afs_osi.h includes this file, which is the only way this file should
15 * be included in a source file. This file can redefine macros declared in
16 * afs_osi.h.
17 */
18
19 /* $Id$ */
20
21 #ifndef _OSI_MACHDEP_H_
22 #define _OSI_MACHDEP_H_
23
24 #include <sys/lock.h>
25
26 #if defined(M_IP6OPT)
27 #define M_AFSFID (M_IP6OPT-1)
28 #else
29 #define M_AFSFID (M_TEMP-1)
30 #endif
31
32 #define M_AFSBUFHDR (M_AFSFID-1)
33 #define M_AFSBUFFER (M_AFSFID-2)
34 #define M_AFSGENERIC (M_AFSFID-3)
35
36 /* vfs */
37 #define osi_vfs mount
38 #define osi_vfs_bsize mnt_stat.f_bsize
39 #define osi_vfs_fsid mnt_stat.f_fsid
40 #define vfs_bsize mnt_stat.f_bsize
41 #define vfs_fsid mnt_stat.f_fsid
42 #define vfs_vnodecovered mnt_vnodecovered
43 #define v_vfsp v_mount
44
45 /* vnode */
46 #define VN_HOLD(vp) afs_vget((vp), 0)
47 #define VN_RELE(vp) vrele(vp)
48 #define osi_vnhold(avc, r) afs_vget(AFSTOV(avc), 0)
49 #define va_nodeid va_fileid
50 #define vnode_t struct vnode
51
52 /* uio */
53 #define afsio_iov uio_iov
54 #define afsio_iovcnt uio_iovcnt
55 #define afsio_offset uio_offset
56 #define afsio_resid uio_resid
57 #define afsio_seg uio_segflg
58 #define AFS_UIOSYS UIO_SYSSPACE
59 #define AFS_UIOUSER UIO_USERSPACE
60
61 /* malloc */
62 inline void afs_osi_Free(void *buf, size_t asize);
63 inline void afs_osi_FreeStr(char *x);
64 extern void *osi_obsd_Alloc(size_t asize, int cansleep);
65 extern void osi_obsd_Free(void *p, size_t asize);
66
67 #ifdef AFS_KALLOC
68 #undef AFS_KALLOC
69 #endif
70 #define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
71
72 #ifdef AFS_KFREE
73 #undef AFS_KFREE
74 #endif
75 #define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
76
77 #ifdef AFS_OBSD42_ENV
78 /* removed, live with it */
79 #define BSD_KMALLOC(p, ptype, msize, mtype, mflags) \
80 (p) = malloc((msize), (mtype), (mflags))
81
82 #define BSD_KFREE(p, mflags) \
83 free((p), (mflags))
84 #else
85 #define BSD_KMALLOC MALLOC
86 #define BSD_KFREE FREE
87 #endif /* AFS_OBSD42_ENV */
88
89 /* proc, cred */
90 typedef struct proc afs_proc_t;
91 typedef struct ucred afs_ucred_t;
92
93 #define afs_suser(x) afs_osi_suser(osi_curcred())
94 #define getpid() curproc
95 #define osi_curcred() (curproc->p_cred->pc_ucred)
96 #define osi_curproc() curproc
97 #define p_rcred p_ucred
98
99 /* time */
100 #define afs_hz hz
101 #define osi_GetTime(x) microtime(x)
102 extern time_t osi_Time();
103
104 /* str */
105 #define afs_strcasecmp(s1, s2) strncasecmp((s1), (s2), 65535)
106 #ifdef AFS_OBSD34_ENV
107 #define strcpy(s1, s2) afs_strcpy((s1), (s2))
108 #define strcat(s1, s2) afs_strcat((s1), (s2))
109 #else
110 #define afs_strcat(s1, s2) strcat((s1), (s2))
111 #endif
112
113 /* other */
114 #define afs_bufferpages bufpages
115 #ifndef iodone
116 #define iodone biodone
117 #endif
118 #define printk printf /* for RX version of xdr_* */
119 #define setgroups sys_setgroups
120 #define UVM
121
122 /* This is not always in scope yet */
123 struct vcache;
124
125 extern int afs_obsd_lookupname(char *fnamep, enum uio_seg segflg,
126 int followlink, struct vnode **compvpp);
127 extern void afs_obsd_getnewvnode(struct vcache *tvc);
128 extern void *afs_obsd_Alloc(size_t asize);
129 extern void afs_obsd_Free(void *p, size_t asize);
130 extern int afs_vget();
131
132 #undef gop_lookupname
133 #define gop_lookupname(fnamep, segflg, followlink, compvpp) \
134 afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
135
136 #undef gop_lookupname_user
137 #define gop_lookupname_user(fnamep, segflg, followlink, compvpp) \
138 afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
139
140 #ifdef AFS_OBSD39_ENV
141 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i))
142 #else
143 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i), (p))
144 #endif
145
146 #ifdef AFS_OBSD44_ENV
147 /* Revert to classical, BSD locks */
148
149 extern struct lock afs_global_lock;
150 extern struct proc *afs_global_owner;
151
152 # ifdef AFS_GLOBAL_SUNLOCK
153
154 # if defined(LOCKDEBUG)
155
156 # define AFS_GLOCK() \
157 do { \
158 _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
159 } while(0);
160 # define AFS_GUNLOCK() \
161 do { \
162 _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
163 } while(0);
164
165 # else /* LOCKDEBUG */
166
167 # define AFS_GLOCK() \
168 do { \
169 lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
170 } while(0);
171 # define AFS_GUNLOCK() \
172 do { \
173 lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
174 } while(0);
175 # endif /* LOCKDEBUG */
176 # define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
177 # else /* AFS_GLOBAL_SUNLOCK */
178 extern struct lock afs_global_lock;
179 # define AFS_GLOCK()
180 # define AFS_GUNLOCK()
181 # define AFS_ASSERT_GLOCK()
182 # define ISAFS_GLOCK() 1
183 # endif
184
185 #else /* AFS_OBSD44_ENV */
186 /* I don't see doing locks this way for older kernels, either,
187 * but, smart folks wrote this
188 */
189 #define AFS_GLOCK() AFS_GLOCKP(curproc)
190 #define AFS_GUNLOCK() AFS_GUNLOCKP(curproc)
191 # ifdef AFS_GLOBAL_SUNLOCK
192 extern struct proc *afs_global_owner;
193 extern struct lock afs_global_lock;
194 # define AFS_GLOCKP(p) \
195 do { \
196 osi_Assert(p); \
197 afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
198 osi_Assert(afs_global_owner == NULL); \
199 afs_global_owner = (p); \
200 } while (0)
201 # define AFS_GUNLOCKP(p) \
202 do { \
203 osi_Assert(p); \
204 osi_Assert(afs_global_owner == (p)); \
205 afs_global_owner = NULL; \
206 afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
207 } while(0)
208 # define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
209 # else /* AFS_GLOBAL_SUNLOCK */
210 extern struct lock afs_global_lock;
211 # define AFS_GLOCKP(p)
212 # define AFS_GUNLOCKP(p)
213 # define AFS_ASSERT_GLOCK()
214 # define ISAFS_GLOCK() 1
215 # endif
216
217 #endif /* AFS_OBSD44_ENV */
218
219 #undef SPLVAR
220 #define SPLVAR int splvar
221 #undef NETPRI
222 #define NETPRI splvar=splnet()
223 #undef USERPRI
224 #define USERPRI splx(splvar)
225
226 #define osi_InitGlock() \
227 do { \
228 lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
229 afs_global_owner = 0; \
230 } while (0)
231
232 /* vnodes */
233 #if defined(AFS_OBSD49_ENV)
234 extern struct vops afs_vops;
235 #define IsAfsVnode(v) ((v)->v_op == &afs_vops)
236 #else
237 extern int (**afs_vnodeop_p) ();
238 #define IsAfsVnode(v) ((v)->v_op == afs_vnodeop_p)
239 #endif
240 #define vType(vc) AFSTOV(vc)->v_type
241 #define vSetVfsp(vc, vfsp) AFSTOV(vc)->v_mount = (vfsp)
242 #define vSetType(vc, type) AFSTOV(vc)->v_type = (type)
243 #define SetAfsVnode(v) /* nothing; done in getnewvnode() */
244
245 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
246
247 #endif /* _OSI_MACHDEP_H_ */