death to trailing whitespace
[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 #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))
71
72 #ifdef AFS_KALLOC
73 #undef AFS_KALLOC
74 #define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
75 #endif
76
77 #ifdef AFS_KFREE
78 #undef AFS_KFREE
79 #define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
80 #endif
81
82 #ifdef AFS_OBSD42_ENV
83 /* removed, live with it */
84 #define BSD_KMALLOC(p, ptype, msize, mtype, mflags)     \
85   (p) = malloc((msize), (mtype), (mflags))
86
87 #define BSD_KFREE(p, mflags) \
88   free((p), (mflags))
89 #else
90 #define BSD_KMALLOC MALLOC
91 #define BSD_KFREE FREE
92 #endif /* AFS_OBSD42_ENV */
93
94 /* proc, cred */
95 typedef struct proc afs_proc_t;
96 typedef struct ucred afs_ucred_t;
97
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
103
104 /* time */
105 #define afs_hz          hz
106 #define osi_GetTime(x)  microtime(x)
107 extern time_t osi_Time();
108
109 /* str */
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))
114 #else
115 #define afs_strcat(s1, s2)      strcat((s1), (s2))
116 #endif
117
118 /* other */
119 #define afs_bufferpages bufpages
120 #ifndef iodone
121 #define iodone biodone
122 #endif
123 #define printk          printf  /* for RX version of xdr_* */
124 #define setgroups       sys_setgroups
125 #define UVM
126
127 /* This is not always in scope yet */
128 struct vcache;
129
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();
136
137 #undef gop_lookupname
138 #define gop_lookupname(fnamep, segflg, followlink, compvpp) \
139         afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
140
141 #undef gop_lookupname_user
142 #define gop_lookupname_user(fnamep, segflg, followlink, compvpp) \
143         afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
144
145 #ifdef AFS_OBSD39_ENV
146 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i))
147 #else
148 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i), (p))
149 #endif
150
151 #ifdef AFS_OBSD44_ENV
152 /* Revert to classical, BSD locks */
153
154 extern struct lock afs_global_lock;
155 extern struct proc *afs_global_owner;
156
157 # ifdef AFS_GLOBAL_SUNLOCK
158
159 #  if defined(LOCKDEBUG)
160
161 #   define AFS_GLOCK() \
162   do { \
163   _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
164   } while(0);
165 #   define AFS_GUNLOCK() \
166   do { \
167   _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
168   } while(0);
169
170 #  else /* LOCKDEBUG */
171
172 #   define AFS_GLOCK() \
173   do { \
174   lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
175   } while(0);
176 #   define AFS_GUNLOCK() \
177   do { \
178   lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
179   } while(0);
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;
184 #  define AFS_GLOCK()
185 #  define AFS_GUNLOCK()
186 #  define AFS_ASSERT_GLOCK()
187 #  define ISAFS_GLOCK() 1
188 # endif
189
190 #else /* AFS_OBSD44_ENV */
191 /* I don't see doing locks this way for older kernels, either,
192  * but, smart folks wrote this
193  */
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) \
200     do { \
201         osi_Assert(p); \
202         afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
203         osi_Assert(afs_global_owner == NULL); \
204         afs_global_owner = (p); \
205     } while (0)
206 #  define AFS_GUNLOCKP(p) \
207     do { \
208         osi_Assert(p); \
209         osi_Assert(afs_global_owner == (p)); \
210         afs_global_owner = NULL; \
211         afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
212     } while(0)
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
220 # endif
221
222 #endif /* AFS_OBSD44_ENV */
223
224 #undef SPLVAR
225 #define SPLVAR int splvar
226 #undef NETPRI
227 #define NETPRI splvar=splnet()
228 #undef USERPRI
229 #define USERPRI splx(splvar)
230
231 #define osi_InitGlock() \
232     do { \
233         lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
234         afs_global_owner = 0; \
235     } while (0)
236
237 /* vnodes */
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() */
244
245 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
246
247 #endif /* _OSI_MACHDEP_H_ */