aoutm68k_stat.c revision 1.24 1 1.24 martin /* $NetBSD: aoutm68k_stat.c,v 1.24 2008/04/28 20:23:41 martin Exp $ */
2 1.1 scw
3 1.1 scw /*-
4 1.1 scw * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation
8 1.1 scw * by Steve C. Woodford.
9 1.1 scw *
10 1.1 scw * Redistribution and use in source and binary forms, with or without
11 1.1 scw * modification, are permitted provided that the following conditions
12 1.1 scw * are met:
13 1.1 scw * 1. Redistributions of source code must retain the above copyright
14 1.1 scw * notice, this list of conditions and the following disclaimer.
15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 scw * notice, this list of conditions and the following disclaimer in the
17 1.1 scw * documentation and/or other materials provided with the distribution.
18 1.1 scw *
19 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
30 1.1 scw */
31 1.5 lukem
32 1.5 lukem #include <sys/cdefs.h>
33 1.24 martin __KERNEL_RCSID(0, "$NetBSD: aoutm68k_stat.c,v 1.24 2008/04/28 20:23:41 martin Exp $");
34 1.1 scw
35 1.4 mrg #if defined(_KERNEL_OPT)
36 1.1 scw #include "opt_compat_netbsd.h"
37 1.1 scw #include "opt_compat_43.h"
38 1.2 jdolecek #endif
39 1.1 scw
40 1.1 scw #include <sys/param.h>
41 1.1 scw #include <sys/systm.h>
42 1.18 dsl #include <sys/filedesc.h>
43 1.1 scw #include <sys/mount.h>
44 1.18 dsl #include <sys/namei.h>
45 1.1 scw #include <sys/proc.h>
46 1.1 scw #include <sys/stat.h>
47 1.18 dsl #include <sys/vfs_syscalls.h>
48 1.1 scw
49 1.1 scw #include <sys/syscall.h>
50 1.1 scw #include <sys/syscallargs.h>
51 1.1 scw
52 1.12 he #include <compat/sys/stat.h>
53 1.12 he
54 1.1 scw #include <compat/aoutm68k/aoutm68k_util.h>
55 1.1 scw #include <compat/aoutm68k/aoutm68k_stat.h>
56 1.1 scw #include <compat/aoutm68k/aoutm68k_syscall.h>
57 1.1 scw #include <compat/aoutm68k/aoutm68k_syscallargs.h>
58 1.1 scw
59 1.1 scw #ifdef COMPAT_43
60 1.18 dsl static void aoutm68k_stat43_convert(struct stat *, struct aoutm68k_stat43 *);
61 1.1 scw #endif
62 1.1 scw #ifdef COMPAT_12
63 1.18 dsl static void aoutm68k_stat12_convert(struct stat *, struct aoutm68k_stat12 *);
64 1.1 scw #endif
65 1.1 scw static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *);
66 1.1 scw
67 1.1 scw
68 1.1 scw #ifdef COMPAT_43
69 1.1 scw int
70 1.22 dsl aoutm68k_compat_43_sys_stat(struct lwp *l, const struct aoutm68k_compat_43_sys_stat_args *uap, register_t *retval)
71 1.1 scw {
72 1.1 scw struct aoutm68k_stat43 ast;
73 1.18 dsl struct stat sb;
74 1.1 scw int error;
75 1.1 scw
76 1.23 ad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
77 1.18 dsl if (error)
78 1.18 dsl return error;
79 1.1 scw
80 1.18 dsl aoutm68k_stat43_convert(&sb, &ast);
81 1.1 scw
82 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
83 1.1 scw }
84 1.1 scw
85 1.1 scw int
86 1.22 dsl aoutm68k_compat_43_sys_fstat(struct lwp *l, const struct aoutm68k_compat_43_sys_fstat_args *uap, register_t *retval)
87 1.1 scw {
88 1.1 scw struct aoutm68k_stat43 ast;
89 1.18 dsl struct stat sb;
90 1.1 scw int error;
91 1.1 scw
92 1.23 ad error = do_sys_fstat(SCARG(uap, fd), &sb);
93 1.18 dsl if (error != 0)
94 1.18 dsl return error;
95 1.1 scw
96 1.18 dsl aoutm68k_stat43_convert(&sb, &ast);
97 1.1 scw
98 1.18 dsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
99 1.1 scw }
100 1.1 scw
101 1.1 scw int
102 1.22 dsl aoutm68k_compat_43_sys_lstat(struct lwp *l, const struct aoutm68k_compat_43_sys_lstat_args *uap, register_t *retval)
103 1.1 scw {
104 1.1 scw struct aoutm68k_stat43 ast;
105 1.18 dsl struct stat sb;
106 1.1 scw int error;
107 1.1 scw
108 1.23 ad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
109 1.18 dsl if (error)
110 1.18 dsl return error;
111 1.1 scw
112 1.18 dsl aoutm68k_stat43_convert(&sb, &ast);
113 1.1 scw
114 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
115 1.1 scw }
116 1.1 scw #endif /* COMPAT_43 */
117 1.1 scw
118 1.1 scw #ifdef COMPAT_12
119 1.1 scw int
120 1.22 dsl aoutm68k_compat_12_sys_stat(struct lwp *l, const struct aoutm68k_compat_12_sys_stat_args *uap, register_t *retval)
121 1.1 scw {
122 1.1 scw struct aoutm68k_stat12 ast;
123 1.18 dsl struct stat sb;
124 1.1 scw int error;
125 1.1 scw
126 1.23 ad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
127 1.18 dsl if (error)
128 1.18 dsl return error;
129 1.1 scw
130 1.18 dsl aoutm68k_stat12_convert(&sb, &ast);
131 1.1 scw
132 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
133 1.1 scw }
134 1.1 scw
135 1.1 scw int
136 1.22 dsl aoutm68k_compat_12_sys_fstat(struct lwp *l, const struct aoutm68k_compat_12_sys_fstat_args *uap, register_t *retval)
137 1.1 scw {
138 1.1 scw struct aoutm68k_stat12 ast;
139 1.18 dsl struct stat sb;
140 1.1 scw int error;
141 1.1 scw
142 1.23 ad error = do_sys_fstat(SCARG(uap, fd), &sb);
143 1.18 dsl if (error != 0)
144 1.18 dsl return error;
145 1.1 scw
146 1.18 dsl aoutm68k_stat12_convert(&sb, &ast);
147 1.1 scw
148 1.18 dsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
149 1.1 scw }
150 1.1 scw
151 1.1 scw int
152 1.22 dsl aoutm68k_compat_12_sys_lstat(struct lwp *l, const struct aoutm68k_compat_12_sys_lstat_args *uap, register_t *retval)
153 1.1 scw {
154 1.1 scw struct aoutm68k_stat12 ast;
155 1.18 dsl struct stat sb;
156 1.1 scw int error;
157 1.1 scw
158 1.23 ad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
159 1.18 dsl if (error)
160 1.18 dsl return error;
161 1.1 scw
162 1.18 dsl aoutm68k_stat12_convert(&sb, &ast);
163 1.1 scw
164 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
165 1.1 scw }
166 1.1 scw #endif /* COMPAT_12 */
167 1.1 scw
168 1.1 scw int
169 1.22 dsl aoutm68k_sys___stat13(struct lwp *l, const struct aoutm68k_sys___stat13_args *uap, register_t *retval)
170 1.1 scw {
171 1.1 scw struct aoutm68k_stat ast;
172 1.18 dsl struct stat sb;
173 1.1 scw int error;
174 1.1 scw
175 1.23 ad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
176 1.18 dsl if (error)
177 1.18 dsl return error;
178 1.1 scw
179 1.18 dsl aoutm68k_stat13_convert(&sb, &ast);
180 1.1 scw
181 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
182 1.1 scw }
183 1.1 scw
184 1.1 scw int
185 1.22 dsl aoutm68k_sys___fstat13(struct lwp *l, const struct aoutm68k_sys___fstat13_args *uap, register_t *retval)
186 1.1 scw {
187 1.1 scw struct aoutm68k_stat ast;
188 1.18 dsl struct stat sb;
189 1.1 scw int error;
190 1.1 scw
191 1.23 ad error = do_sys_fstat(SCARG(uap, fd), &sb);
192 1.18 dsl if (error != 0)
193 1.18 dsl return error;
194 1.1 scw
195 1.18 dsl aoutm68k_stat13_convert(&sb, &ast);
196 1.1 scw
197 1.18 dsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
198 1.1 scw
199 1.1 scw }
200 1.1 scw
201 1.1 scw int
202 1.22 dsl aoutm68k_sys___lstat13(struct lwp *l, const struct aoutm68k_sys___lstat13_args *uap, register_t *retval)
203 1.1 scw {
204 1.1 scw struct aoutm68k_stat ast;
205 1.18 dsl struct stat sb;
206 1.1 scw int error;
207 1.1 scw
208 1.23 ad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
209 1.18 dsl if (error)
210 1.18 dsl return error;
211 1.1 scw
212 1.18 dsl aoutm68k_stat13_convert(&sb, &ast);
213 1.1 scw
214 1.18 dsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
215 1.1 scw }
216 1.1 scw
217 1.1 scw int
218 1.22 dsl aoutm68k_sys_fhstat(struct lwp *l, const struct aoutm68k_sys_fhstat_args *uap, register_t *retval)
219 1.1 scw {
220 1.1 scw struct aoutm68k_stat ast;
221 1.20 dsl struct stat sb;
222 1.1 scw int error;
223 1.1 scw
224 1.20 dsl error = do_fhstat(l, SCARG(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
225 1.20 dsl if (error)
226 1.20 dsl return error;
227 1.1 scw
228 1.20 dsl aoutm68k_stat13_convert(&sb, &ast);
229 1.20 dsl return copyout(&sb, SCARG(uap, sb), sizeof(sb));
230 1.1 scw }
231 1.1 scw
232 1.1 scw #ifdef COMPAT_43
233 1.1 scw static void
234 1.21 dsl aoutm68k_stat43_convert(struct stat *st, struct aoutm68k_stat43 *ast)
235 1.1 scw {
236 1.1 scw
237 1.1 scw memset(ast, 0, sizeof(*ast));
238 1.1 scw ast->st_dev = st->st_dev;
239 1.1 scw ast->st_ino = st->st_ino;
240 1.1 scw ast->st_mode = st->st_mode;
241 1.1 scw ast->st_nlink = st->st_nlink;
242 1.1 scw ast->st_uid = st->st_uid;
243 1.1 scw ast->st_gid = st->st_gid;
244 1.1 scw ast->st_rdev = st->st_rdev;
245 1.18 dsl if (st->st_size < (off_t)1 << 32)
246 1.18 dsl ast->st_size = st->st_size;
247 1.18 dsl else
248 1.18 dsl ast->st_size = -2;
249 1.1 scw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
250 1.1 scw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
251 1.1 scw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
252 1.1 scw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
253 1.1 scw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
254 1.1 scw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
255 1.1 scw ast->st_blksize = st->st_blksize;
256 1.1 scw ast->st_blocks = st->st_blocks;
257 1.1 scw ast->st_flags = st->st_flags;
258 1.1 scw ast->st_gen = st->st_gen;
259 1.1 scw }
260 1.1 scw #endif /* COMPAT_43 */
261 1.1 scw
262 1.1 scw #ifdef COMPAT_12
263 1.1 scw static void
264 1.21 dsl aoutm68k_stat12_convert(struct stat *st, struct aoutm68k_stat12 *ast)
265 1.1 scw {
266 1.1 scw
267 1.1 scw memset(ast, 0, sizeof(*ast));
268 1.1 scw ast->st_dev = st->st_dev;
269 1.1 scw ast->st_ino = st->st_ino;
270 1.1 scw ast->st_mode = st->st_mode;
271 1.1 scw ast->st_nlink = st->st_nlink;
272 1.1 scw ast->st_uid = st->st_uid;
273 1.1 scw ast->st_gid = st->st_gid;
274 1.1 scw ast->st_rdev = st->st_rdev;
275 1.1 scw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
276 1.1 scw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
277 1.1 scw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
278 1.1 scw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
279 1.1 scw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
280 1.1 scw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
281 1.18 dsl if (st->st_size < (off_t)1 << 32)
282 1.18 dsl ast->st_size = st->st_size;
283 1.18 dsl else
284 1.18 dsl ast->st_size = -2;
285 1.1 scw ast->st_blocks = st->st_blocks;
286 1.1 scw ast->st_blksize = st->st_blksize;
287 1.1 scw ast->st_flags = st->st_flags;
288 1.1 scw ast->st_gen = st->st_gen;
289 1.1 scw }
290 1.1 scw #endif /* COMPAT_12 */
291 1.1 scw
292 1.1 scw static void
293 1.21 dsl aoutm68k_stat13_convert(struct stat *st, struct aoutm68k_stat *ast)
294 1.1 scw {
295 1.1 scw
296 1.1 scw memset(ast, 0, sizeof(*ast));
297 1.1 scw ast->st_dev = st->st_dev;
298 1.1 scw ast->st_ino = st->st_ino;
299 1.1 scw ast->st_mode = st->st_mode;
300 1.1 scw ast->st_nlink = st->st_nlink;
301 1.1 scw ast->st_uid = st->st_uid;
302 1.1 scw ast->st_gid = st->st_gid;
303 1.1 scw ast->st_rdev = st->st_rdev;
304 1.1 scw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
305 1.1 scw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
306 1.1 scw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
307 1.1 scw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
308 1.1 scw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
309 1.1 scw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
310 1.18 dsl if (st->st_size < (off_t)1 << 32)
311 1.18 dsl ast->st_size = st->st_size;
312 1.18 dsl else
313 1.18 dsl ast->st_size = -2;
314 1.1 scw ast->st_blocks = st->st_blocks;
315 1.1 scw ast->st_blksize = st->st_blksize;
316 1.1 scw ast->st_flags = st->st_flags;
317 1.1 scw ast->st_gen = st->st_gen;
318 1.8 he ast->st_qspare[0] = 0;
319 1.8 he ast->st_qspare[1] = 0;
320 1.1 scw }
321