netbsd32_conv.h revision 1.14 1 1.14 perry /* $NetBSD: netbsd32_conv.h,v 1.14 2006/02/16 20:17:15 perry Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.1 mrg
31 1.1 mrg #ifndef _COMPAT_NETBSD32_NETBSD32_CONV_H_
32 1.1 mrg #define _COMPAT_NETBSD32_NETBSD32_CONV_H_
33 1.1 mrg
34 1.1 mrg /*
35 1.1 mrg * Though COMPAT_OLDSOCK is needed only for COMPAT_43, SunOS, Linux,
36 1.1 mrg * HP-UX, FreeBSD, Ultrix, OSF1, we define it unconditionally so that
37 1.1 mrg * this would be LKM-safe.
38 1.1 mrg */
39 1.1 mrg #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
40 1.1 mrg
41 1.1 mrg #include <sys/param.h>
42 1.1 mrg #include <sys/systm.h>
43 1.1 mrg #include <sys/kernel.h>
44 1.1 mrg #include <sys/ipc.h>
45 1.1 mrg #include <sys/msg.h>
46 1.1 mrg #define msg __msg /* Don't ask me! */
47 1.1 mrg #include <sys/sem.h>
48 1.1 mrg #include <sys/shm.h>
49 1.1 mrg #include <sys/socket.h>
50 1.1 mrg #include <sys/stat.h>
51 1.1 mrg #include <sys/time.h>
52 1.1 mrg #include <sys/timex.h>
53 1.11 cube #include <sys/event.h>
54 1.1 mrg
55 1.10 christos #include <compat/sys/dirent.h>
56 1.10 christos
57 1.1 mrg #include <compat/netbsd32/netbsd32.h>
58 1.1 mrg
59 1.14 perry static __inline void netbsd32_from_timeval __P((const struct timeval *, struct netbsd32_timeval *));
60 1.14 perry static __inline void netbsd32_to_timeval __P((const struct netbsd32_timeval *, struct timeval *));
61 1.14 perry static __inline void netbsd32_from_itimerval __P((const struct itimerval *, struct netbsd32_itimerval *));
62 1.14 perry static __inline void netbsd32_to_itimerval __P((const struct netbsd32_itimerval *, struct itimerval *));
63 1.14 perry static __inline void netbsd32_to_timespec __P((const struct netbsd32_timespec *, struct timespec *));
64 1.14 perry static __inline void netbsd32_from_timespec __P((const struct timespec *, struct netbsd32_timespec *));
65 1.14 perry static __inline void netbsd32_from_rusage __P((const struct rusage *, struct netbsd32_rusage *));
66 1.14 perry static __inline void netbsd32_to_rusage __P((const struct netbsd32_rusage *, struct rusage *));
67 1.14 perry static __inline int netbsd32_to_iovecin __P((const struct netbsd32_iovec *, struct iovec *, int));
68 1.14 perry static __inline void netbsd32_to_msghdr __P((const struct netbsd32_msghdr *, struct msghdr *));
69 1.14 perry static __inline void netbsd32_from_msghdr __P((struct netbsd32_msghdr *, const struct msghdr *));
70 1.14 perry static __inline void netbsd32_from_statvfs __P((const struct statvfs *, struct netbsd32_statvfs *));
71 1.14 perry static __inline void netbsd32_from_timex __P((const struct timex *, struct netbsd32_timex *));
72 1.14 perry static __inline void netbsd32_to_timex __P((const struct netbsd32_timex *, struct timex *));
73 1.14 perry static __inline void netbsd32_from___stat13 __P((const struct stat *, struct netbsd32_stat13 *));
74 1.14 perry static __inline void netbsd32_from___stat30 __P((const struct stat *, struct netbsd32_stat *));
75 1.14 perry static __inline void netbsd32_to_ipc_perm __P((const struct netbsd32_ipc_perm *, struct ipc_perm *));
76 1.14 perry static __inline void netbsd32_from_ipc_perm __P((const struct ipc_perm *, struct netbsd32_ipc_perm *));
77 1.14 perry static __inline void netbsd32_to_msg __P((const struct netbsd32_msg *, struct msg *));
78 1.14 perry static __inline void netbsd32_from_msg __P((const struct msg *, struct netbsd32_msg *));
79 1.14 perry static __inline void netbsd32_to_msqid_ds __P((const struct netbsd32_msqid_ds *, struct msqid_ds *));
80 1.14 perry static __inline void netbsd32_from_msqid_ds __P((const struct msqid_ds *, struct netbsd32_msqid_ds *));
81 1.14 perry static __inline void netbsd32_to_shmid_ds __P((const struct netbsd32_shmid_ds *, struct shmid_ds *));
82 1.14 perry static __inline void netbsd32_from_shmid_ds __P((const struct shmid_ds *, struct netbsd32_shmid_ds *));
83 1.14 perry static __inline void netbsd32_to_semid_ds __P((const struct netbsd32_semid_ds *, struct semid_ds *));
84 1.14 perry static __inline void netbsd32_from_semid_ds __P((const struct semid_ds *, struct netbsd32_semid_ds *));
85 1.14 perry static __inline void netbsd32_from_loadavg __P((struct netbsd32_loadavg *, const struct loadavg *));
86 1.14 perry static __inline void netbsd32_to_sigevent(const struct netbsd32_sigevent *, struct sigevent *);
87 1.14 perry static __inline int netbsd32_to_dirent12(char *, int);
88 1.1 mrg
89 1.1 mrg /* converters for structures that we need */
90 1.14 perry static __inline void
91 1.1 mrg netbsd32_from_timeval(tv, tv32)
92 1.7 cube const struct timeval *tv;
93 1.1 mrg struct netbsd32_timeval *tv32;
94 1.1 mrg {
95 1.1 mrg
96 1.1 mrg tv32->tv_sec = (netbsd32_long)tv->tv_sec;
97 1.1 mrg tv32->tv_usec = (netbsd32_long)tv->tv_usec;
98 1.1 mrg }
99 1.1 mrg
100 1.14 perry static __inline void
101 1.1 mrg netbsd32_to_timeval(tv32, tv)
102 1.7 cube const struct netbsd32_timeval *tv32;
103 1.1 mrg struct timeval *tv;
104 1.1 mrg {
105 1.1 mrg
106 1.1 mrg tv->tv_sec = (long)tv32->tv_sec;
107 1.1 mrg tv->tv_usec = (long)tv32->tv_usec;
108 1.1 mrg }
109 1.1 mrg
110 1.14 perry static __inline void
111 1.1 mrg netbsd32_from_itimerval(itv, itv32)
112 1.7 cube const struct itimerval *itv;
113 1.1 mrg struct netbsd32_itimerval *itv32;
114 1.1 mrg {
115 1.1 mrg
116 1.5 perry netbsd32_from_timeval(&itv->it_interval,
117 1.1 mrg &itv32->it_interval);
118 1.5 perry netbsd32_from_timeval(&itv->it_value,
119 1.1 mrg &itv32->it_value);
120 1.1 mrg }
121 1.1 mrg
122 1.14 perry static __inline void
123 1.1 mrg netbsd32_to_itimerval(itv32, itv)
124 1.7 cube const struct netbsd32_itimerval *itv32;
125 1.1 mrg struct itimerval *itv;
126 1.1 mrg {
127 1.1 mrg
128 1.1 mrg netbsd32_to_timeval(&itv32->it_interval, &itv->it_interval);
129 1.1 mrg netbsd32_to_timeval(&itv32->it_value, &itv->it_value);
130 1.1 mrg }
131 1.1 mrg
132 1.14 perry static __inline void
133 1.1 mrg netbsd32_to_timespec(s32p, p)
134 1.7 cube const struct netbsd32_timespec *s32p;
135 1.1 mrg struct timespec *p;
136 1.1 mrg {
137 1.1 mrg
138 1.1 mrg p->tv_sec = (time_t)s32p->tv_sec;
139 1.1 mrg p->tv_nsec = (long)s32p->tv_nsec;
140 1.1 mrg }
141 1.1 mrg
142 1.14 perry static __inline void
143 1.1 mrg netbsd32_from_timespec(p, s32p)
144 1.7 cube const struct timespec *p;
145 1.1 mrg struct netbsd32_timespec *s32p;
146 1.1 mrg {
147 1.1 mrg
148 1.1 mrg s32p->tv_sec = (netbsd32_time_t)p->tv_sec;
149 1.1 mrg s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
150 1.1 mrg }
151 1.1 mrg
152 1.14 perry static __inline void
153 1.1 mrg netbsd32_from_rusage(rup, ru32p)
154 1.7 cube const struct rusage *rup;
155 1.1 mrg struct netbsd32_rusage *ru32p;
156 1.1 mrg {
157 1.1 mrg
158 1.1 mrg netbsd32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
159 1.1 mrg netbsd32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
160 1.1 mrg #define C(var) ru32p->var = (netbsd32_long)rup->var
161 1.1 mrg C(ru_maxrss);
162 1.1 mrg C(ru_ixrss);
163 1.1 mrg C(ru_idrss);
164 1.1 mrg C(ru_isrss);
165 1.1 mrg C(ru_minflt);
166 1.1 mrg C(ru_majflt);
167 1.1 mrg C(ru_nswap);
168 1.1 mrg C(ru_inblock);
169 1.1 mrg C(ru_oublock);
170 1.1 mrg C(ru_msgsnd);
171 1.1 mrg C(ru_msgrcv);
172 1.1 mrg C(ru_nsignals);
173 1.1 mrg C(ru_nvcsw);
174 1.1 mrg C(ru_nivcsw);
175 1.1 mrg #undef C
176 1.1 mrg }
177 1.1 mrg
178 1.14 perry static __inline void
179 1.1 mrg netbsd32_to_rusage(ru32p, rup)
180 1.7 cube const struct netbsd32_rusage *ru32p;
181 1.1 mrg struct rusage *rup;
182 1.1 mrg {
183 1.1 mrg
184 1.1 mrg netbsd32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
185 1.1 mrg netbsd32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
186 1.1 mrg #define C(var) rup->var = (long)ru32p->var
187 1.1 mrg C(ru_maxrss);
188 1.1 mrg C(ru_ixrss);
189 1.1 mrg C(ru_idrss);
190 1.1 mrg C(ru_isrss);
191 1.1 mrg C(ru_minflt);
192 1.1 mrg C(ru_majflt);
193 1.1 mrg C(ru_nswap);
194 1.1 mrg C(ru_inblock);
195 1.1 mrg C(ru_oublock);
196 1.1 mrg C(ru_msgsnd);
197 1.1 mrg C(ru_msgrcv);
198 1.1 mrg C(ru_nsignals);
199 1.1 mrg C(ru_nvcsw);
200 1.1 mrg C(ru_nivcsw);
201 1.1 mrg #undef C
202 1.1 mrg }
203 1.1 mrg
204 1.14 perry static __inline int
205 1.1 mrg netbsd32_to_iovecin(iov32p, iovp, len)
206 1.7 cube const struct netbsd32_iovec *iov32p;
207 1.1 mrg struct iovec *iovp;
208 1.1 mrg int len;
209 1.1 mrg {
210 1.1 mrg int i, error=0;
211 1.1 mrg u_int32_t iov_base;
212 1.1 mrg u_int32_t iov_len;
213 1.5 perry /*
214 1.1 mrg * We could allocate an iov32p, do a copyin, and translate
215 1.1 mrg * each field and then free it all up, or we could copyin
216 1.1 mrg * each field separately. I'm doing the latter to reduce
217 1.1 mrg * the number of MALLOC()s.
218 1.1 mrg */
219 1.1 mrg for (i = 0; i < len; i++, iovp++, iov32p++) {
220 1.7 cube if ((error = copyin(&iov32p->iov_base, &iov_base, sizeof(iov_base))))
221 1.1 mrg return (error);
222 1.7 cube if ((error = copyin(&iov32p->iov_len, &iov_len, sizeof(iov_len))))
223 1.1 mrg return (error);
224 1.1 mrg iovp->iov_base = (void *)(u_long)iov_base;
225 1.1 mrg iovp->iov_len = (size_t)iov_len;
226 1.1 mrg }
227 1.1 mrg return error;
228 1.1 mrg }
229 1.1 mrg
230 1.1 mrg /* msg_iov must be done separately */
231 1.14 perry static __inline void
232 1.1 mrg netbsd32_to_msghdr(mhp32, mhp)
233 1.7 cube const struct netbsd32_msghdr *mhp32;
234 1.1 mrg struct msghdr *mhp;
235 1.1 mrg {
236 1.1 mrg
237 1.1 mrg mhp->msg_name = (caddr_t)(u_long)mhp32->msg_name;
238 1.1 mrg mhp->msg_namelen = mhp32->msg_namelen;
239 1.1 mrg mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
240 1.1 mrg mhp->msg_control = (caddr_t)(u_long)mhp32->msg_control;
241 1.1 mrg mhp->msg_controllen = mhp32->msg_controllen;
242 1.1 mrg mhp->msg_flags = mhp32->msg_flags;
243 1.1 mrg }
244 1.1 mrg
245 1.1 mrg /* msg_iov must be done separately */
246 1.14 perry static __inline void
247 1.1 mrg netbsd32_from_msghdr(mhp32, mhp)
248 1.1 mrg struct netbsd32_msghdr *mhp32;
249 1.7 cube const struct msghdr *mhp;
250 1.1 mrg {
251 1.1 mrg
252 1.1 mrg mhp32->msg_name = mhp32->msg_name;
253 1.1 mrg mhp32->msg_namelen = mhp32->msg_namelen;
254 1.1 mrg mhp32->msg_iovlen = mhp32->msg_iovlen;
255 1.1 mrg mhp32->msg_control = mhp32->msg_control;
256 1.1 mrg mhp32->msg_controllen = mhp->msg_controllen;
257 1.1 mrg mhp32->msg_flags = mhp->msg_flags;
258 1.1 mrg }
259 1.1 mrg
260 1.14 perry static __inline void
261 1.2 christos netbsd32_from_statvfs(sbp, sb32p)
262 1.7 cube const struct statvfs *sbp;
263 1.4 cube struct netbsd32_statvfs *sb32p;
264 1.1 mrg {
265 1.4 cube sb32p->f_flag = sbp->f_flag;
266 1.4 cube sb32p->f_bsize = (netbsd32_u_long)sbp->f_bsize;
267 1.4 cube sb32p->f_frsize = (netbsd32_u_long)sbp->f_frsize;
268 1.4 cube sb32p->f_iosize = (netbsd32_u_long)sbp->f_iosize;
269 1.4 cube sb32p->f_blocks = sbp->f_blocks;
270 1.4 cube sb32p->f_bfree = sbp->f_bfree;
271 1.4 cube sb32p->f_bavail = sbp->f_bavail;
272 1.4 cube sb32p->f_bresvd = sbp->f_bresvd;
273 1.4 cube sb32p->f_files = sbp->f_files;
274 1.4 cube sb32p->f_ffree = sbp->f_ffree;
275 1.4 cube sb32p->f_favail = sbp->f_favail;
276 1.4 cube sb32p->f_fresvd = sbp->f_fresvd;
277 1.4 cube sb32p->f_syncreads = sbp->f_syncreads;
278 1.4 cube sb32p->f_syncwrites = sbp->f_syncwrites;
279 1.4 cube sb32p->f_asyncreads = sbp->f_asyncreads;
280 1.4 cube sb32p->f_asyncwrites = sbp->f_asyncwrites;
281 1.4 cube sb32p->f_fsidx = sbp->f_fsidx;
282 1.4 cube sb32p->f_fsid = (netbsd32_u_long)sbp->f_fsid;
283 1.4 cube sb32p->f_namemax = (netbsd32_u_long)sbp->f_namemax;
284 1.1 mrg sb32p->f_owner = sbp->f_owner;
285 1.1 mrg sb32p->f_spare[0] = 0;
286 1.1 mrg sb32p->f_spare[1] = 0;
287 1.1 mrg sb32p->f_spare[2] = 0;
288 1.1 mrg sb32p->f_spare[3] = 0;
289 1.1 mrg #if 1
290 1.1 mrg /* May as well do the whole batch in one go */
291 1.4 cube memcpy(sb32p->f_fstypename, sbp->f_fstypename,
292 1.4 cube sizeof(sb32p->f_fstypename) + sizeof(sb32p->f_mntonname) +
293 1.4 cube sizeof(sb32p->f_mntfromname));
294 1.1 mrg #else
295 1.1 mrg /* If we want to be careful */
296 1.4 cube memcpy(sb32p->f_fstypename, sbp->f_fstypename, sizeof(sb32p->f_fstypename));
297 1.4 cube memcpy(sb32p->f_mntonname, sbp->f_mntonname, sizeof(sb32p->f_mntonname));
298 1.4 cube memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, sizeof(sb32p->f_mntfromname));
299 1.1 mrg #endif
300 1.1 mrg }
301 1.1 mrg
302 1.14 perry static __inline void
303 1.1 mrg netbsd32_from_timex(txp, tx32p)
304 1.7 cube const struct timex *txp;
305 1.1 mrg struct netbsd32_timex *tx32p;
306 1.1 mrg {
307 1.1 mrg
308 1.1 mrg tx32p->modes = txp->modes;
309 1.1 mrg tx32p->offset = (netbsd32_long)txp->offset;
310 1.1 mrg tx32p->freq = (netbsd32_long)txp->freq;
311 1.1 mrg tx32p->maxerror = (netbsd32_long)txp->maxerror;
312 1.1 mrg tx32p->esterror = (netbsd32_long)txp->esterror;
313 1.1 mrg tx32p->status = txp->status;
314 1.1 mrg tx32p->constant = (netbsd32_long)txp->constant;
315 1.1 mrg tx32p->precision = (netbsd32_long)txp->precision;
316 1.1 mrg tx32p->tolerance = (netbsd32_long)txp->tolerance;
317 1.1 mrg tx32p->ppsfreq = (netbsd32_long)txp->ppsfreq;
318 1.1 mrg tx32p->jitter = (netbsd32_long)txp->jitter;
319 1.1 mrg tx32p->shift = txp->shift;
320 1.1 mrg tx32p->stabil = (netbsd32_long)txp->stabil;
321 1.1 mrg tx32p->jitcnt = (netbsd32_long)txp->jitcnt;
322 1.1 mrg tx32p->calcnt = (netbsd32_long)txp->calcnt;
323 1.1 mrg tx32p->errcnt = (netbsd32_long)txp->errcnt;
324 1.1 mrg tx32p->stbcnt = (netbsd32_long)txp->stbcnt;
325 1.1 mrg }
326 1.1 mrg
327 1.14 perry static __inline void
328 1.1 mrg netbsd32_to_timex(tx32p, txp)
329 1.7 cube const struct netbsd32_timex *tx32p;
330 1.1 mrg struct timex *txp;
331 1.1 mrg {
332 1.1 mrg
333 1.1 mrg txp->modes = tx32p->modes;
334 1.1 mrg txp->offset = (long)tx32p->offset;
335 1.1 mrg txp->freq = (long)tx32p->freq;
336 1.1 mrg txp->maxerror = (long)tx32p->maxerror;
337 1.1 mrg txp->esterror = (long)tx32p->esterror;
338 1.1 mrg txp->status = tx32p->status;
339 1.1 mrg txp->constant = (long)tx32p->constant;
340 1.1 mrg txp->precision = (long)tx32p->precision;
341 1.1 mrg txp->tolerance = (long)tx32p->tolerance;
342 1.1 mrg txp->ppsfreq = (long)tx32p->ppsfreq;
343 1.1 mrg txp->jitter = (long)tx32p->jitter;
344 1.1 mrg txp->shift = tx32p->shift;
345 1.1 mrg txp->stabil = (long)tx32p->stabil;
346 1.1 mrg txp->jitcnt = (long)tx32p->jitcnt;
347 1.1 mrg txp->calcnt = (long)tx32p->calcnt;
348 1.1 mrg txp->errcnt = (long)tx32p->errcnt;
349 1.1 mrg txp->stbcnt = (long)tx32p->stbcnt;
350 1.1 mrg }
351 1.1 mrg
352 1.14 perry static __inline void
353 1.1 mrg netbsd32_from___stat13(sbp, sb32p)
354 1.7 cube const struct stat *sbp;
355 1.8 christos struct netbsd32_stat13 *sb32p;
356 1.8 christos {
357 1.8 christos sb32p->st_dev = sbp->st_dev;
358 1.8 christos sb32p->st_ino = sbp->st_ino;
359 1.8 christos sb32p->st_mode = sbp->st_mode;
360 1.8 christos sb32p->st_nlink = sbp->st_nlink;
361 1.8 christos sb32p->st_uid = sbp->st_uid;
362 1.8 christos sb32p->st_gid = sbp->st_gid;
363 1.8 christos sb32p->st_rdev = sbp->st_rdev;
364 1.8 christos sb32p->st_size = sbp->st_size;
365 1.8 christos sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
366 1.8 christos sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
367 1.8 christos sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
368 1.8 christos sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
369 1.8 christos sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
370 1.8 christos sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
371 1.8 christos sb32p->st_blksize = sbp->st_blksize;
372 1.8 christos sb32p->st_blocks = sbp->st_blocks;
373 1.8 christos sb32p->st_flags = sbp->st_flags;
374 1.8 christos sb32p->st_gen = sbp->st_gen;
375 1.8 christos }
376 1.8 christos
377 1.14 perry static __inline void
378 1.8 christos netbsd32_from___stat30(sbp, sb32p)
379 1.8 christos const struct stat *sbp;
380 1.1 mrg struct netbsd32_stat *sb32p;
381 1.1 mrg {
382 1.1 mrg sb32p->st_dev = sbp->st_dev;
383 1.1 mrg sb32p->st_ino = sbp->st_ino;
384 1.1 mrg sb32p->st_mode = sbp->st_mode;
385 1.1 mrg sb32p->st_nlink = sbp->st_nlink;
386 1.1 mrg sb32p->st_uid = sbp->st_uid;
387 1.1 mrg sb32p->st_gid = sbp->st_gid;
388 1.1 mrg sb32p->st_rdev = sbp->st_rdev;
389 1.8 christos sb32p->st_size = sbp->st_size;
390 1.1 mrg sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
391 1.1 mrg sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
392 1.1 mrg sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
393 1.1 mrg sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
394 1.1 mrg sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
395 1.1 mrg sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
396 1.1 mrg sb32p->st_blksize = sbp->st_blksize;
397 1.1 mrg sb32p->st_blocks = sbp->st_blocks;
398 1.1 mrg sb32p->st_flags = sbp->st_flags;
399 1.1 mrg sb32p->st_gen = sbp->st_gen;
400 1.1 mrg }
401 1.1 mrg
402 1.14 perry static __inline void
403 1.1 mrg netbsd32_to_ipc_perm(ip32p, ipp)
404 1.7 cube const struct netbsd32_ipc_perm *ip32p;
405 1.1 mrg struct ipc_perm *ipp;
406 1.1 mrg {
407 1.1 mrg
408 1.1 mrg ipp->cuid = ip32p->cuid;
409 1.1 mrg ipp->cgid = ip32p->cgid;
410 1.1 mrg ipp->uid = ip32p->uid;
411 1.1 mrg ipp->gid = ip32p->gid;
412 1.1 mrg ipp->mode = ip32p->mode;
413 1.1 mrg ipp->_seq = ip32p->_seq;
414 1.1 mrg ipp->_key = (key_t)ip32p->_key;
415 1.1 mrg }
416 1.1 mrg
417 1.14 perry static __inline void
418 1.1 mrg netbsd32_from_ipc_perm(ipp, ip32p)
419 1.7 cube const struct ipc_perm *ipp;
420 1.1 mrg struct netbsd32_ipc_perm *ip32p;
421 1.1 mrg {
422 1.1 mrg
423 1.1 mrg ip32p->cuid = ipp->cuid;
424 1.1 mrg ip32p->cgid = ipp->cgid;
425 1.1 mrg ip32p->uid = ipp->uid;
426 1.1 mrg ip32p->gid = ipp->gid;
427 1.1 mrg ip32p->mode = ipp->mode;
428 1.1 mrg ip32p->_seq = ipp->_seq;
429 1.1 mrg ip32p->_key = (netbsd32_key_t)ipp->_key;
430 1.1 mrg }
431 1.1 mrg
432 1.14 perry static __inline void
433 1.1 mrg netbsd32_to_msg(m32p, mp)
434 1.7 cube const struct netbsd32_msg *m32p;
435 1.1 mrg struct msg *mp;
436 1.1 mrg {
437 1.1 mrg
438 1.1 mrg mp->msg_next = (struct msg *)(u_long)m32p->msg_next;
439 1.1 mrg mp->msg_type = (long)m32p->msg_type;
440 1.1 mrg mp->msg_ts = m32p->msg_ts;
441 1.1 mrg mp->msg_spot = m32p->msg_spot;
442 1.1 mrg }
443 1.1 mrg
444 1.14 perry static __inline void
445 1.1 mrg netbsd32_from_msg(mp, m32p)
446 1.7 cube const struct msg *mp;
447 1.1 mrg struct netbsd32_msg *m32p;
448 1.1 mrg {
449 1.1 mrg
450 1.1 mrg m32p->msg_next = (netbsd32_msgp_t)(u_long)mp->msg_next;
451 1.1 mrg m32p->msg_type = (netbsd32_long)mp->msg_type;
452 1.1 mrg m32p->msg_ts = mp->msg_ts;
453 1.1 mrg m32p->msg_spot = mp->msg_spot;
454 1.1 mrg }
455 1.1 mrg
456 1.14 perry static __inline void
457 1.1 mrg netbsd32_to_msqid_ds(ds32p, dsp)
458 1.7 cube const struct netbsd32_msqid_ds *ds32p;
459 1.1 mrg struct msqid_ds *dsp;
460 1.1 mrg {
461 1.1 mrg
462 1.1 mrg netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
463 1.1 mrg netbsd32_to_msg((struct netbsd32_msg *)(u_long)ds32p->_msg_first, dsp->_msg_first);
464 1.1 mrg netbsd32_to_msg((struct netbsd32_msg *)(u_long)ds32p->_msg_last, dsp->_msg_last);
465 1.1 mrg dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
466 1.1 mrg dsp->msg_qnum = (u_long)ds32p->msg_qnum;
467 1.1 mrg dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
468 1.1 mrg dsp->msg_lspid = ds32p->msg_lspid;
469 1.1 mrg dsp->msg_lrpid = ds32p->msg_lrpid;
470 1.1 mrg dsp->msg_rtime = (time_t)ds32p->msg_rtime;
471 1.1 mrg dsp->msg_stime = (time_t)ds32p->msg_stime;
472 1.1 mrg dsp->msg_ctime = (time_t)ds32p->msg_ctime;
473 1.1 mrg }
474 1.1 mrg
475 1.14 perry static __inline void
476 1.1 mrg netbsd32_from_msqid_ds(dsp, ds32p)
477 1.7 cube const struct msqid_ds *dsp;
478 1.1 mrg struct netbsd32_msqid_ds *ds32p;
479 1.1 mrg {
480 1.1 mrg
481 1.1 mrg netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
482 1.1 mrg netbsd32_from_msg(dsp->_msg_first, (struct netbsd32_msg *)(u_long)ds32p->_msg_first);
483 1.1 mrg netbsd32_from_msg(dsp->_msg_last, (struct netbsd32_msg *)(u_long)ds32p->_msg_last);
484 1.1 mrg ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
485 1.1 mrg ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
486 1.1 mrg ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
487 1.1 mrg ds32p->msg_lspid = dsp->msg_lspid;
488 1.1 mrg ds32p->msg_lrpid = dsp->msg_lrpid;
489 1.1 mrg ds32p->msg_rtime = dsp->msg_rtime;
490 1.1 mrg ds32p->msg_stime = dsp->msg_stime;
491 1.1 mrg ds32p->msg_ctime = dsp->msg_ctime;
492 1.1 mrg }
493 1.1 mrg
494 1.14 perry static __inline void
495 1.1 mrg netbsd32_to_shmid_ds(ds32p, dsp)
496 1.7 cube const struct netbsd32_shmid_ds *ds32p;
497 1.1 mrg struct shmid_ds *dsp;
498 1.1 mrg {
499 1.1 mrg
500 1.1 mrg netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
501 1.1 mrg dsp->shm_segsz = ds32p->shm_segsz;
502 1.1 mrg dsp->shm_lpid = ds32p->shm_lpid;
503 1.1 mrg dsp->shm_cpid = ds32p->shm_cpid;
504 1.1 mrg dsp->shm_nattch = ds32p->shm_nattch;
505 1.1 mrg dsp->shm_atime = (long)ds32p->shm_atime;
506 1.1 mrg dsp->shm_dtime = (long)ds32p->shm_dtime;
507 1.1 mrg dsp->shm_ctime = (long)ds32p->shm_ctime;
508 1.1 mrg dsp->_shm_internal = (void *)(u_long)ds32p->_shm_internal;
509 1.1 mrg }
510 1.1 mrg
511 1.14 perry static __inline void
512 1.1 mrg netbsd32_from_shmid_ds(dsp, ds32p)
513 1.7 cube const struct shmid_ds *dsp;
514 1.1 mrg struct netbsd32_shmid_ds *ds32p;
515 1.1 mrg {
516 1.1 mrg
517 1.1 mrg netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
518 1.1 mrg ds32p->shm_segsz = dsp->shm_segsz;
519 1.1 mrg ds32p->shm_lpid = dsp->shm_lpid;
520 1.1 mrg ds32p->shm_cpid = dsp->shm_cpid;
521 1.1 mrg ds32p->shm_nattch = dsp->shm_nattch;
522 1.1 mrg ds32p->shm_atime = (netbsd32_long)dsp->shm_atime;
523 1.1 mrg ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime;
524 1.1 mrg ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime;
525 1.1 mrg ds32p->_shm_internal = (netbsd32_voidp)(u_long)dsp->_shm_internal;
526 1.1 mrg }
527 1.1 mrg
528 1.14 perry static __inline void
529 1.1 mrg netbsd32_to_semid_ds(s32dsp, dsp)
530 1.7 cube const struct netbsd32_semid_ds *s32dsp;
531 1.1 mrg struct semid_ds *dsp;
532 1.1 mrg {
533 1.1 mrg
534 1.7 cube netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
535 1.1 mrg dsp->_sem_base = (struct __sem *)(u_long)s32dsp->_sem_base;
536 1.1 mrg dsp->sem_nsems = s32dsp->sem_nsems;
537 1.1 mrg dsp->sem_otime = s32dsp->sem_otime;
538 1.1 mrg dsp->sem_ctime = s32dsp->sem_ctime;
539 1.1 mrg }
540 1.1 mrg
541 1.14 perry static __inline void
542 1.1 mrg netbsd32_from_semid_ds(dsp, s32dsp)
543 1.7 cube const struct semid_ds *dsp;
544 1.1 mrg struct netbsd32_semid_ds *s32dsp;
545 1.1 mrg {
546 1.1 mrg
547 1.7 cube netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
548 1.1 mrg s32dsp->_sem_base = (netbsd32_semp_t)(u_long)dsp->_sem_base;
549 1.1 mrg s32dsp->sem_nsems = dsp->sem_nsems;
550 1.1 mrg s32dsp->sem_otime = dsp->sem_otime;
551 1.1 mrg s32dsp->sem_ctime = dsp->sem_ctime;
552 1.1 mrg }
553 1.1 mrg
554 1.14 perry static __inline void
555 1.1 mrg netbsd32_from_loadavg(av32, av)
556 1.1 mrg struct netbsd32_loadavg *av32;
557 1.7 cube const struct loadavg *av;
558 1.1 mrg {
559 1.1 mrg
560 1.1 mrg av32->ldavg[0] = av->ldavg[0];
561 1.1 mrg av32->ldavg[1] = av->ldavg[1];
562 1.1 mrg av32->ldavg[2] = av->ldavg[2];
563 1.1 mrg av32->fscale = (netbsd32_long)av->fscale;
564 1.1 mrg }
565 1.1 mrg
566 1.14 perry static __inline void
567 1.11 cube netbsd32_to_kevent(struct netbsd32_kevent *ke32, struct kevent *ke)
568 1.11 cube {
569 1.11 cube ke->ident = ke32->ident;
570 1.11 cube ke->filter = ke32->filter;
571 1.11 cube ke->flags = ke32->flags;
572 1.11 cube ke->fflags = ke32->fflags;
573 1.11 cube ke->data = ke32->data;
574 1.11 cube ke->udata = ke32->udata;
575 1.11 cube }
576 1.11 cube
577 1.14 perry static __inline void
578 1.11 cube netbsd32_from_kevent(struct kevent *ke, struct netbsd32_kevent *ke32)
579 1.11 cube {
580 1.11 cube ke32->ident = ke->ident;
581 1.11 cube ke32->filter = ke->filter;
582 1.11 cube ke32->flags = ke->flags;
583 1.11 cube ke32->fflags = ke->fflags;
584 1.11 cube ke32->data = ke->data;
585 1.11 cube ke32->udata = ke->udata;
586 1.11 cube }
587 1.11 cube
588 1.14 perry static __inline void
589 1.7 cube netbsd32_to_sigevent(const struct netbsd32_sigevent *ev32, struct sigevent *ev)
590 1.6 cube {
591 1.6 cube ev->sigev_notify = ev32->sigev_notify;
592 1.6 cube ev->sigev_signo = ev32->sigev_signo;
593 1.6 cube /*
594 1.6 cube * XXX sival_ptr, sigev_notify_function and
595 1.6 cube * sigev_notify_attributes are currently unused
596 1.6 cube */
597 1.6 cube ev->sigev_value.sival_int = ev32->sigev_value.sival_int;
598 1.6 cube ev->sigev_notify_function = (void *)(intptr_t)ev32->sigev_notify_function;
599 1.6 cube ev->sigev_notify_attributes = (void *)(intptr_t)ev32->sigev_notify_attributes;
600 1.6 cube }
601 1.9 christos
602 1.14 perry static __inline int
603 1.9 christos netbsd32_to_dirent12(char *buf, int nbytes)
604 1.8 christos {
605 1.8 christos struct dirent *ndp, *nndp, *endp;
606 1.8 christos struct dirent12 *odp;
607 1.8 christos
608 1.8 christos odp = (struct dirent12 *)(void *)buf;
609 1.8 christos ndp = (struct dirent *)(void *)buf;
610 1.8 christos endp = (struct dirent *)(void *)&buf[nbytes];
611 1.8 christos
612 1.8 christos /*
613 1.8 christos * In-place conversion. This works because odp
614 1.8 christos * is smaller than ndp, but it has to be done
615 1.8 christos * in the right sequence.
616 1.8 christos */
617 1.8 christos for (; ndp < endp; ndp = nndp) {
618 1.8 christos nndp = _DIRENT_NEXT(ndp);
619 1.9 christos odp->d_fileno = (u_int32_t)ndp->d_fileno;
620 1.8 christos if (ndp->d_namlen >= sizeof(odp->d_name))
621 1.8 christos odp->d_namlen = sizeof(odp->d_name) - 1;
622 1.8 christos else
623 1.8 christos odp->d_namlen = (u_int8_t)ndp->d_namlen;
624 1.8 christos odp->d_type = ndp->d_type;
625 1.8 christos (void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen);
626 1.8 christos odp->d_name[odp->d_namlen] = '\0';
627 1.8 christos odp->d_reclen = _DIRENT_SIZE(odp);
628 1.8 christos odp = _DIRENT_NEXT(odp);
629 1.8 christos }
630 1.8 christos return ((char *)(void *)odp) - buf;
631 1.8 christos }
632 1.6 cube
633 1.1 mrg #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */
634