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
12 * OpenBSD OSI header file. Extends afs_osi.h.
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
21 #ifndef _OSI_MACHDEP_H_
22 #define _OSI_MACHDEP_H_
27 #define M_AFSFID (M_IP6OPT-1)
29 #define M_AFSFID (M_TEMP-1)
32 #define M_AFSBUFHDR (M_AFSFID-1)
33 #define M_AFSBUFFER (M_AFSFID-2)
34 #define M_AFSGENERIC (M_AFSFID-3)
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
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
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
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);
67 #define afs_osi_Alloc_NoSleep(asize) osi_obsd_Alloc((asize), 0)
68 #define afs_osi_Alloc(asize) osi_obsd_Alloc((asize), 1)
69 #define afs_osi_FreeStr(s) afs_osi_Free((s), strlen((s)) + 1)
70 #define afs_osi_Free(buf, asize) osi_obsd_Free((buf), (asize))
74 #define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
79 #define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
83 /* removed, live with it */
84 #define BSD_KMALLOC(p, ptype, msize, mtype, mflags) \
85 (p) = malloc((msize), (mtype), (mflags))
87 #define BSD_KFREE(p, mflags) \
90 #define BSD_KMALLOC MALLOC
91 #define BSD_KFREE KFREE
92 #endif /* AFS_OBSD42_ENV */
95 typedef struct proc afs_proc_t;
96 typedef struct ucred afs_ucred_t;
98 #define afs_suser(x) afs_osi_suser(osi_curcred())
99 #define getpid() curproc
100 #define osi_curcred() (curproc->p_cred->pc_ucred)
101 #define osi_curproc() curproc
102 #define p_rcred p_ucred
106 #define osi_GetTime(x) microtime(x)
107 extern time_t osi_Time();
110 #define afs_strcasecmp(s1, s2) strncasecmp((s1), (s2), 65535)
111 #ifdef AFS_OBSD34_ENV
112 #define strcpy(s1, s2) afs_strcpy((s1), (s2))
113 #define strcat(s1, s2) afs_strcat((s1), (s2))
115 #define afs_strcat(s1, s2) strcat((s1), (s2))
119 #define afs_bufferpages bufpages
121 #define iodone biodone
123 #define printk printf /* for RX version of xdr_* */
124 #define setgroups sys_setgroups
127 /* This is not always in scope yet */
130 extern int afs_obsd_lookupname(char *fnamep, enum uio_seg segflg,
131 int followlink, struct vnode **compvpp);
132 extern void afs_obsd_getnewvnode(struct vcache *tvc);
133 extern void *afs_obsd_Alloc(size_t asize);
134 extern void afs_obsd_Free(void *p, size_t asize);
135 extern int afs_vget();
137 #undef gop_lookupname
138 #define gop_lookupname(fnamep, segflg, followlink, compvpp) \
139 afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
141 #undef gop_lookupname_user
142 #define gop_lookupname_user(fnamep, segflg, followlink, compvpp) \
143 afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
145 #ifdef AFS_OBSD39_ENV
146 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i))
148 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i), (p))
151 #ifdef AFS_OBSD44_ENV
152 /* Revert to classical, BSD locks */
154 extern struct lock afs_global_lock;
155 extern struct proc *afs_global_owner;
157 # ifdef AFS_GLOBAL_SUNLOCK
159 # if defined(LOCKDEBUG)
161 # define AFS_GLOCK() \
163 _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
165 # define AFS_GUNLOCK() \
167 _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
170 # else /* LOCKDEBUG */
172 # define AFS_GLOCK() \
174 lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
176 # define AFS_GUNLOCK() \
178 lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
180 # endif /* LOCKDEBUG */
181 # define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
182 # else /* AFS_GLOBAL_SUNLOCK */
183 extern struct lock afs_global_lock;
185 # define AFS_GUNLOCK()
186 # define AFS_ASSERT_GLOCK()
187 # define ISAFS_GLOCK() 1
190 #else /* AFS_OBSD44_ENV */
191 /* I don't see doing locks this way for older kernels, either,
192 * but, smart folks wrote this
194 #define AFS_GLOCK() AFS_GLOCKP(curproc)
195 #define AFS_GUNLOCK() AFS_GUNLOCKP(curproc)
196 # ifdef AFS_GLOBAL_SUNLOCK
197 extern struct proc *afs_global_owner;
198 extern struct lock afs_global_lock;
199 # define AFS_GLOCKP(p) \
202 afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
203 osi_Assert(afs_global_owner == NULL); \
204 afs_global_owner = (p); \
206 # define AFS_GUNLOCKP(p) \
209 osi_Assert(afs_global_owner == (p)); \
210 afs_global_owner = NULL; \
211 afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
213 # define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
214 # else /* AFS_GLOBAL_SUNLOCK */
215 extern struct lock afs_global_lock;
216 # define AFS_GLOCKP(p)
217 # define AFS_GUNLOCKP(p)
218 # define AFS_ASSERT_GLOCK()
219 # define ISAFS_GLOCK() 1
222 #endif /* AFS_OBSD44_ENV */
225 #define SPLVAR int splvar
227 #define NETPRI splvar=splnet()
229 #define USERPRI splx(splvar)
231 #define osi_InitGlock() \
233 lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
234 afs_global_owner = 0; \
238 extern int (**afs_vnodeop_p) ();
239 #define vType(vc) AFSTOV(vc)->v_type
240 #define vSetVfsp(vc, vfsp) AFSTOV(vc)->v_mount = (vfsp)
241 #define vSetType(vc, type) AFSTOV(vc)->v_type = (type)
242 #define IsAfsVnode(v) ((v)->v_op == afs_vnodeop_p)
243 #define SetAfsVnode(v) /* nothing; done in getnewvnode() */
245 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
247 #endif /* _OSI_MACHDEP_H_ */