netbsd: rebase cm at NetBSD 4.0
[openafs.git] / src / afs / NBSD / 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 #ifndef _OSI_MACHDEP_H_
20 #define _OSI_MACHDEP_H_
21
22 #define RXK_LISTENER_ENV 1
23 #define AFS_DIRENT 1
24
25 #include <sys/lock.h>
26 #include <sys/malloc.h>
27 #include <sys/syscall.h>
28 #include <sys/syscallargs.h>
29
30 #include "opt_ddb.h" /* Debugger() */
31
32 #define M_AFSFID        (M_TEMP-1)
33 #define M_AFSBUFHDR     (M_TEMP-2)
34 #define M_AFSBUFFER     (M_TEMP-3)
35 #define M_AFSGENERIC    (M_TEMP-4)
36
37 /* vfs */
38 #define osi_vfs         mount
39 #define osi_vfs_bsize   mnt_stat.f_bsize
40 #define osi_vfs_iosize  mnt_stat.f_iosize
41 #define osi_vfs_fsid    mnt_stat.f_fsid
42 #if 0
43 #define vfs_bsize       mnt_stat.f_bsize
44 #define vfs_fsid        mnt_stat.f_fsid
45 #endif
46 #define vfs_vnodecovered mnt_vnodecovered
47 #define v_vfsp          v_mount
48 #define VFS_STATFS      afs_statvfs
49
50 int
51 sys_ioctl(struct lwp *l, void *v, register_t *retval);
52
53 /* vnode */
54 #define VN_HOLD(vp)     (vref(vp))
55 #define VN_RELE(vp)     (vrele(vp))
56 #define osi_vnhold(avc, r) (VN_HOLD(AFSTOV(avc)))
57
58
59 #define va_nodeid       va_fileid
60 #define vnode_t         struct vnode
61
62 /* syscall */
63 struct afs_sysargs {
64     syscallarg(long) syscall;
65     syscallarg(long) parm1;
66     syscallarg(long) parm2;
67     syscallarg(long) parm3;
68     syscallarg(long) parm4;
69     syscallarg(long) parm5;
70     syscallarg(long) parm6;
71 };
72
73 /* uio */
74 #define afsio_iov       uio_iov
75 #define afsio_iovcnt    uio_iovcnt
76 #define afsio_offset    uio_offset
77 #define afsio_resid     uio_resid
78 #define afsio_seg       uio_segflg
79 #define AFS_UIOSYS      UIO_SYSSPACE
80 #define AFS_UIOUSER     UIO_USERSPACE
81
82 /* malloc */
83 inline void * afs_osi_Alloc(size_t asize);
84 inline void * afs_osi_Alloc_NoSleep(size_t asize);
85 inline void afs_osi_Free(void *buf, size_t asize);
86 inline void afs_osi_FreeStr(char *x);
87 extern void *osi_nbsd_Alloc(size_t asize, int cansleep);
88 extern void osi_nbsd_Free(void *p, size_t asize);
89
90 #ifdef AFS_KALLOC
91 #undef AFS_KALLOC
92 #define AFS_KALLOC(s) (osi_nbsd_Alloc((s), 1 /* cansleep */))
93 #endif
94
95 #ifdef AFS_KFREE
96 #undef AFS_KFREE
97 #define AFS_KFREE(p, s) (osi_nbsd_Free((p), (s)))
98 #endif
99
100 /* proc */
101 typedef struct lwp afs_proc_t;
102 #define osi_curproc()   curlwp
103 #define getpid()        (osi_curproc())->l_proc->p_pid
104
105 /*
106  * XXX  I'm exporting the internal definition of kauth_cred_t
107  * until I work out protocol for switching group buffers.
108  * Matt.
109  */
110
111 #define KAUTH_EXPORT 1
112 #if defined(KAUTH_EXPORT)
113 /* internal type from kern_auth.c */
114 #ifdef AFS_NBSD40_ENV
115 struct kauth_cred {
116         struct simplelock cr_lock;      /* lock on cr_refcnt */
117         u_int cr_refcnt;                /* reference count */
118         uid_t cr_uid;                   /* user id */
119         uid_t cr_euid;                  /* effective user id */
120         uid_t cr_svuid;                 /* saved effective user id */
121         gid_t cr_gid;                   /* group id */
122         gid_t cr_egid;                  /* effective group id */
123         gid_t cr_svgid;                 /* saved effective group id */
124         u_int cr_ngroups;               /* number of groups */
125         gid_t cr_groups[NGROUPS];       /* group memberships */
126 };
127 #else
128 #error TODO:  verify kauth_cred structure, if this is still here
129 #endif /* AFS_NBSD40_ENV */
130 #endif /* KAUTH_EXPORT */
131
132 typedef kauth_cred_t afs_ucred_t;
133 #define osi_curcred()   (kauth_cred_get())
134 #define afs_suser(x)    afs_osi_suser(osi_curcred())
135 #define osi_crgetruid(acred) (kauth_cred_getuid(acred))
136 #define osi_crgetrgid(acred) (kauth_cred_getgid(acred))
137 #define osi_crngroups(acred) (kauth_cred_ngroups(acred))
138 #define osi_proccred(aproc) (aproc->p_cred)
139 #define osi_crdup(acred) (kauth_cred_dup(acred))
140 #define crref osi_crdup
141 #define crdup osi_crdup
142 #define crhold crref
143 #define crfree kauth_cred_free
144
145 #define afs_cr_gid osi_crgetrgid
146 #define afs_cr_uid osi_crgetruid
147
148 inline gid_t osi_crgroupbyid(afs_ucred_t *acred, int gindex);
149
150 /* time */
151 #define afs_hz          hz
152 #define osi_GetTime(x)  microtime(x)
153 #define osi_Time()      time_second
154
155 /* str */
156 #define afs_strcasecmp(s1, s2)  strncasecmp((s1), (s2), 65535)
157 #define afs_strcat(s1, s2)      strcat((s1), (s2))
158
159 /* other */
160 #define afs_bufferpages bufpages
161 #ifndef iodone
162 #define iodone biodone
163 #endif
164 #define printk          printf  /* for RX version of xdr_* */
165 #define setgroups       sys_setgroups
166 #define UVM
167
168 /* This is not always in scope yet */
169 struct vcache;
170
171 extern int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg,
172                                int followlink, struct vnode **compvpp);
173 extern void afs_nbsd_getnewvnode(struct vcache *tvc);
174 extern int afs_vget();
175
176 #undef gop_lookupname
177 #undef gop_lookupname_user
178 #define osi_lookupname_user(fnamep, segflg, followlink, compvpp) \
179         afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
180 #define gop_lookupname_user osi_lookupname_user
181 #define gop_lookupname osi_lookupname_user
182
183 #ifdef KERNEL
184 #ifdef AFS_GLOBAL_SUNLOCK
185 extern struct lock afs_global_lock;
186
187 #if defined(LOCKDEBUG)
188 #define AFS_GLOCK() \
189   do { \
190       _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
191   } while(0);
192 #define AFS_GUNLOCK() \
193   do { \
194       _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
195   } while(0);
196 #else
197 #define AFS_GLOCK() \
198   do { \
199     lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
200   } while(0);
201 #define AFS_GUNLOCK() \
202   do { \
203     lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
204   } while(0);
205 #endif /* LOCKDEBUG */
206 #define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
207 #else
208 extern struct lock afs_global_lock;
209 #define AFS_GLOCKP(p)
210 #define AFS_GUNLOCKP(p)
211 #define AFS_ASSERT_GLOCK()
212 #define ISAFS_GLOCK() 1
213 #endif
214
215 #undef SPLVAR
216 #define SPLVAR int splvar
217 #undef NETPRI
218 #define NETPRI splvar=splnet()
219 #undef USERPRI
220 #define USERPRI splx(splvar)
221 #endif /* KERNEL */
222
223 #if     !defined(ASSEMBLER) && !defined(__LANGUAGE_ASSEMBLY__) && !defined(IGNORE_STDS_H)
224 enum vcexcl { NONEXCL, EXCL };
225
226 #ifndef MIN
227 #define MIN(A,B) ((A) < (B) ? (A) : (B))
228 #endif
229 #ifndef MAX
230 #define MAX(A,B) ((A) > (B) ? (A) : (B))
231 #endif
232
233 #endif /* ASSEMBLER */
234
235 /* vnodes */
236 extern int (**afs_vnodeop_p) ();
237 #define vType(vc)               AFSTOV(vc)->v_type
238 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
239 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
240 #define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
241 #define SetAfsVnode(v)     /* nothing; done in getnewvnode() */
242
243 #endif /* _OSI_MACHDEP_H_ */