906ec104da227775792d38eb1fb14880248e5b36
[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 #define M_AFSFID        (M_TEMP-1)
27 #define M_AFSBUFHDR     (M_TEMP-2)
28 #define M_AFSBUFFER     (M_TEMP-3)
29 #define M_AFSGENERIC    (M_TEMP-4)
30
31 /* vfs */
32 #define osi_vfs         mount
33 #define osi_vfs_bsize   mnt_stat.f_bsize
34 #define osi_vfs_fsid    mnt_stat.f_fsid
35 #define vfs_bsize       mnt_stat.f_bsize
36 #define vfs_fsid        mnt_stat.f_fsid
37 #define vfs_vnodecovered mnt_vnodecovered
38 #define v_vfsp          v_mount
39
40 /* vnode */
41 #define VN_HOLD(vp)     afs_vget((vp), 0)
42 #define VN_RELE(vp)     vrele(vp)
43 #define osi_vnhold(avc, r) afs_vget(AFSTOV(avc), 0)
44 #define va_nodeid       va_fileid
45 #define vnode_t         struct vnode
46
47 /* uio */
48 #define afsio_iov       uio_iov
49 #define afsio_iovcnt    uio_iovcnt
50 #define afsio_offset    uio_offset
51 #define afsio_resid     uio_resid
52 #define afsio_seg       uio_segflg
53 #define AFS_UIOSYS      UIO_SYSSPACE
54 #define AFS_UIOUSER     UIO_USERSPACE
55
56 /* malloc */
57 inline void afs_osi_Free(void *buf, size_t asize);
58 inline void afs_osi_FreeStr(char *x);
59 extern void *osi_obsd_Alloc(size_t asize, int cansleep);
60 extern void osi_obsd_Free(void *p, size_t asize);
61
62 #define afs_osi_Alloc_NoSleep(asize) osi_obsd_Alloc((asize), 0)
63 #define afs_osi_Alloc(asize) osi_obsd_Alloc((asize), 1)
64 #define afs_osi_FreeStr(s) afs_osi_Free((s), strlen((s)) + 1)
65 #define afs_osi_Free(buf, asize) osi_obsd_Free((buf), (asize))
66
67 #ifdef AFS_KALLOC
68 #undef AFS_KALLOC
69 #define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
70 #endif
71
72 #ifdef AFS_KFREE
73 #undef AFS_KFREE
74 #define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
75 #endif
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 KFREE
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_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
135
136 #undef gop_lookupname_user
137 #define gop_lookupname_user(fnamep, segflg, followlink, compvpp) \
138         afs_nbsd_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 KERNEL
147
148 #ifdef AFS_OBSD44_ENV
149 /* Revert to classical, BSD locks */
150
151 extern struct lock afs_global_lock;
152 extern struct proc *afs_global_owner;
153
154 #ifdef AFS_GLOBAL_SUNLOCK
155
156 #if defined(LOCKDEBUG)
157
158 #define AFS_GLOCK() \
159   do { \
160   _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
161   } while(0);
162 #define AFS_GUNLOCK() \
163   do { \
164   _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
165   } while(0);
166
167 #else
168
169 #define AFS_GLOCK() \
170   do { \
171   lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
172   } while(0);
173 #define AFS_GUNLOCK() \
174   do { \
175   lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
176   } while(0);
177 #endif /* LOCKDEBUG */
178 #define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
179 #else
180 extern struct lock afs_global_lock;
181 #define AFS_GLOCKP(p)
182 #define AFS_GUNLOCKP(p)
183 #define AFS_ASSERT_GLOCK()
184 #define ISAFS_GLOCK() 1
185 #endif
186
187 #else
188 /* I don't see doing locks this way for older kernels, either,
189  * but, smart folks wrote this
190  */
191 #define AFS_GLOCK() AFS_GLOCKP(curproc)
192 #define AFS_GUNLOCK() AFS_GUNLOCKP(curproc)
193 #ifdef AFS_GLOBAL_SUNLOCK
194 extern struct proc *afs_global_owner;
195 extern struct lock afs_global_lock;
196 #define AFS_GLOCKP(p) \
197     do { \
198         osi_Assert(p); \
199         afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
200         osi_Assert(afs_global_owner == NULL); \
201         afs_global_owner = (p); \
202     } while (0)
203 #define AFS_GUNLOCKP(p) \
204     do { \
205         osi_Assert(p); \
206         osi_Assert(afs_global_owner == (p)); \
207         afs_global_owner = NULL; \
208         afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
209     } while(0)
210 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
211 #else
212 extern struct lock afs_global_lock;
213 #define AFS_GLOCKP(p)
214 #define AFS_GUNLOCKP(p)
215 #define AFS_ASSERT_GLOCK()
216 #define ISAFS_GLOCK() 1
217 #endif
218
219 #endif /* AFS_OBSD44_ENV */
220
221 #undef SPLVAR
222 #define SPLVAR int splvar
223 #undef NETPRI
224 #define NETPRI splvar=splnet()
225 #undef USERPRI
226 #define USERPRI splx(splvar)
227 #endif /* KERNEL */
228
229 /* vnodes */
230 extern int (**afs_vnodeop_p) ();
231 #define vType(vc)               AFSTOV(vc)->v_type
232 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
233 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
234 #define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
235 #define SetAfsVnode(v)     /* nothing; done in getnewvnode() */
236
237 #endif /* _OSI_MACHDEP_H_ */