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