1 /* $NetBSD: aoutm68k_stat.c,v 1.13 2005/12/11 12:19:56 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Steve C. Woodford. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: aoutm68k_stat.c,v 1.13 2005/12/11 12:19:56 christos Exp $"); 41 42 #if defined(_KERNEL_OPT) 43 #include "opt_compat_netbsd.h" 44 #include "opt_compat_43.h" 45 #endif 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/mount.h> 50 #include <sys/proc.h> 51 #include <sys/stat.h> 52 53 #include <sys/syscall.h> 54 #include <sys/sa.h> 55 #include <sys/syscallargs.h> 56 57 #include <compat/sys/stat.h> 58 59 #include <compat/aoutm68k/aoutm68k_util.h> 60 #include <compat/aoutm68k/aoutm68k_stat.h> 61 #include <compat/aoutm68k/aoutm68k_syscall.h> 62 #include <compat/aoutm68k/aoutm68k_syscallargs.h> 63 64 #ifdef COMPAT_43 65 static void aoutm68k_stat43_convert(struct stat43 *, struct aoutm68k_stat43 *); 66 #endif 67 #ifdef COMPAT_12 68 static void aoutm68k_stat12_convert(struct stat12 *, struct aoutm68k_stat12 *); 69 #endif 70 static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *); 71 72 73 #ifdef COMPAT_43 74 int 75 aoutm68k_compat_43_sys_stat(l, v, retval) 76 struct lwp *l; 77 void *v; 78 register_t *retval; 79 { 80 struct aoutm68k_compat_43_sys_stat_args *uap = v; 81 struct proc *p = l->l_proc; 82 caddr_t sg = stackgap_init(p, 0); 83 struct compat_43_sys_stat_args cup; 84 struct aoutm68k_stat43 ast; 85 struct stat43 st; 86 int error; 87 88 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 89 #ifdef COMPAT_AOUT_ALTPATH 90 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 91 #endif 92 SCARG(&cup, path) = SCARG(uap, path); 93 94 if ((error = compat_43_sys_stat(l, &cup, retval)) != 0 || 95 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 96 return (error); 97 98 aoutm68k_stat43_convert(&st, &ast); 99 100 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 101 } 102 103 int 104 aoutm68k_compat_43_sys_fstat(l, v, retval) 105 struct lwp *l; 106 void *v; 107 register_t *retval; 108 { 109 struct aoutm68k_compat_43_sys_fstat_args *uap = v; 110 struct proc *p = l->l_proc; 111 caddr_t sg = stackgap_init(p, 0); 112 struct compat_43_sys_fstat_args cup; 113 struct aoutm68k_stat43 ast; 114 struct stat43 st; 115 int error; 116 117 SCARG(&cup, fd) = SCARG(uap, fd); 118 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st)); 119 120 if ((error = compat_43_sys_fstat(l, &cup, retval)) != 0 || 121 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0) 122 return (error); 123 124 aoutm68k_stat43_convert(&st, &ast); 125 126 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast))); 127 } 128 129 int 130 aoutm68k_compat_43_sys_lstat(l, v, retval) 131 struct lwp *l; 132 void *v; 133 register_t *retval; 134 { 135 struct aoutm68k_compat_43_sys_lstat_args *uap = v; 136 struct proc *p = l->l_proc; 137 caddr_t sg = stackgap_init(p, 0); 138 struct compat_43_sys_lstat_args cup; 139 struct aoutm68k_stat43 ast; 140 struct stat43 st; 141 int error; 142 143 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 144 #ifdef COMPAT_AOUT_ALTPATH 145 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 146 #endif 147 SCARG(&cup, path) = SCARG(uap, path); 148 149 if ((error = compat_43_sys_lstat(l, &cup, retval)) != 0 || 150 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 151 return (error); 152 153 aoutm68k_stat43_convert(&st, &ast); 154 155 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 156 } 157 #endif /* COMPAT_43 */ 158 159 #ifdef COMPAT_12 160 int 161 aoutm68k_compat_12_sys_stat(l, v, retval) 162 struct lwp *l; 163 void *v; 164 register_t *retval; 165 { 166 struct aoutm68k_compat_12_sys_stat_args *uap = v; 167 struct proc *p = l->l_proc; 168 caddr_t sg = stackgap_init(p, 0); 169 struct compat_12_sys_stat_args cup; 170 struct aoutm68k_stat12 ast; 171 struct stat12 st; 172 int error; 173 174 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 175 #ifdef COMPAT_AOUT_ALTPATH 176 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 177 #endif 178 SCARG(&cup, path) = SCARG(uap, path); 179 180 if ((error = compat_12_sys_stat(l, &cup, retval)) != 0 || 181 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 182 return (error); 183 184 aoutm68k_stat12_convert(&st, &ast); 185 186 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 187 } 188 189 int 190 aoutm68k_compat_12_sys_fstat(l, v, retval) 191 struct lwp *l; 192 void *v; 193 register_t *retval; 194 { 195 struct aoutm68k_compat_12_sys_fstat_args *uap = v; 196 struct proc *p = l->l_proc; 197 caddr_t sg = stackgap_init(p, 0); 198 struct compat_12_sys_fstat_args cup; 199 struct aoutm68k_stat12 ast; 200 struct stat12 st; 201 int error; 202 203 SCARG(&cup, fd) = SCARG(uap, fd); 204 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st)); 205 206 if ((error = compat_12_sys_fstat(l, &cup, retval)) != 0 || 207 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0) 208 return (error); 209 210 aoutm68k_stat12_convert(&st, &ast); 211 212 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast))); 213 } 214 215 int 216 aoutm68k_compat_12_sys_lstat(l, v, retval) 217 struct lwp *l; 218 void *v; 219 register_t *retval; 220 { 221 struct aoutm68k_compat_12_sys_lstat_args *uap = v; 222 struct proc *p = l->l_proc; 223 caddr_t sg = stackgap_init(p, 0); 224 struct compat_12_sys_lstat_args cup; 225 struct aoutm68k_stat12 ast; 226 struct stat12 st; 227 int error; 228 229 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 230 #ifdef COMPAT_AOUT_ALTPATH 231 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 232 #endif 233 SCARG(&cup, path) = SCARG(uap, path); 234 235 if ((error = compat_12_sys_lstat(l, &cup, retval)) != 0 || 236 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 237 return (error); 238 239 aoutm68k_stat12_convert(&st, &ast); 240 241 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 242 } 243 #endif /* COMPAT_12 */ 244 245 int 246 aoutm68k_sys___stat13(l, v, retval) 247 struct lwp *l; 248 void *v; 249 register_t *retval; 250 { 251 struct aoutm68k_sys___stat13_args *uap = v; 252 struct proc *p = l->l_proc; 253 caddr_t sg = stackgap_init(p, 0); 254 struct sys___stat30_args cup; 255 struct aoutm68k_stat ast; 256 struct stat st; 257 int error; 258 259 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 260 #ifdef COMPAT_AOUT_ALTPATH 261 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 262 #endif 263 SCARG(&cup, path) = SCARG(uap, path); 264 265 if ((error = sys___stat30(l, &cup, retval)) != 0 || 266 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 267 return (error); 268 269 aoutm68k_stat13_convert(&st, &ast); 270 271 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 272 } 273 274 int 275 aoutm68k_sys___fstat13(l, v, retval) 276 struct lwp *l; 277 void *v; 278 register_t *retval; 279 { 280 struct aoutm68k_sys___fstat13_args *uap = v; 281 struct proc *p = l->l_proc; 282 caddr_t sg = stackgap_init(p, 0); 283 struct sys___fstat30_args cup; 284 struct aoutm68k_stat ast; 285 struct stat st; 286 int error; 287 288 SCARG(&cup, fd) = SCARG(uap, fd); 289 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st)); 290 291 if ((error = sys___fstat30(l, &cup, retval)) != 0 || 292 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0) 293 return (error); 294 295 aoutm68k_stat13_convert(&st, &ast); 296 297 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast))); 298 299 } 300 301 int 302 aoutm68k_sys___lstat13(l, v, retval) 303 struct lwp *l; 304 void *v; 305 register_t *retval; 306 { 307 struct aoutm68k_sys___lstat13_args *uap = v; 308 struct proc *p = l->l_proc; 309 caddr_t sg = stackgap_init(p, 0); 310 struct sys___lstat30_args cup; 311 struct aoutm68k_stat ast; 312 struct stat st; 313 int error; 314 315 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st)); 316 #ifdef COMPAT_AOUT_ALTPATH 317 CHECK_ALT_EXIST(l, &sg, SCARG(uap, path)); 318 #endif 319 SCARG(&cup, path) = SCARG(uap, path); 320 321 if ((error = sys___lstat30(l, &cup, retval)) != 0 || 322 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0) 323 return (error); 324 325 aoutm68k_stat13_convert(&st, &ast); 326 327 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast))); 328 } 329 330 int 331 aoutm68k_sys_fhstat(l, v, retval) 332 struct lwp *l; 333 void *v; 334 register_t *retval; 335 { 336 struct aoutm68k_sys_fhstat_args *uap = v; 337 struct proc *p = l->l_proc; 338 caddr_t sg = stackgap_init(p, 0); 339 struct sys_fhstat_args cup; 340 struct aoutm68k_stat ast; 341 struct stat st; 342 int error; 343 344 SCARG(&cup, fhp) = SCARG(uap, fhp); 345 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st)); 346 347 if ((error = sys_fhstat(l, &cup, retval)) != 0 || 348 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0) 349 return (error); 350 351 aoutm68k_stat13_convert(&st, &ast); 352 353 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast))); 354 } 355 356 #ifdef COMPAT_43 357 static void 358 aoutm68k_stat43_convert(st, ast) 359 struct stat43 *st; 360 struct aoutm68k_stat43 *ast; 361 { 362 363 memset(ast, 0, sizeof(*ast)); 364 ast->st_dev = st->st_dev; 365 ast->st_ino = st->st_ino; 366 ast->st_mode = st->st_mode; 367 ast->st_nlink = st->st_nlink; 368 ast->st_uid = st->st_uid; 369 ast->st_gid = st->st_gid; 370 ast->st_rdev = st->st_rdev; 371 ast->st_size = st->st_size; 372 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec; 373 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec; 374 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec; 375 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec; 376 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec; 377 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec; 378 ast->st_blksize = st->st_blksize; 379 ast->st_blocks = st->st_blocks; 380 ast->st_flags = st->st_flags; 381 ast->st_gen = st->st_gen; 382 } 383 #endif /* COMPAT_43 */ 384 385 #ifdef COMPAT_12 386 static void 387 aoutm68k_stat12_convert(st, ast) 388 struct stat12 *st; 389 struct aoutm68k_stat12 *ast; 390 { 391 392 memset(ast, 0, sizeof(*ast)); 393 ast->st_dev = st->st_dev; 394 ast->st_ino = st->st_ino; 395 ast->st_mode = st->st_mode; 396 ast->st_nlink = st->st_nlink; 397 ast->st_uid = st->st_uid; 398 ast->st_gid = st->st_gid; 399 ast->st_rdev = st->st_rdev; 400 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec; 401 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec; 402 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec; 403 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec; 404 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec; 405 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec; 406 ast->st_size = st->st_size; 407 ast->st_blocks = st->st_blocks; 408 ast->st_blksize = st->st_blksize; 409 ast->st_flags = st->st_flags; 410 ast->st_gen = st->st_gen; 411 ast->st_lspare = st->st_lspare; 412 ast->st_qspare[0] = st->st_qspare[0]; 413 ast->st_qspare[1] = st->st_qspare[1]; 414 } 415 #endif /* COMPAT_12 */ 416 417 static void 418 aoutm68k_stat13_convert(st, ast) 419 struct stat *st; 420 struct aoutm68k_stat *ast; 421 { 422 423 memset(ast, 0, sizeof(*ast)); 424 ast->st_dev = st->st_dev; 425 ast->st_ino = st->st_ino; 426 ast->st_mode = st->st_mode; 427 ast->st_nlink = st->st_nlink; 428 ast->st_uid = st->st_uid; 429 ast->st_gid = st->st_gid; 430 ast->st_rdev = st->st_rdev; 431 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec; 432 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec; 433 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec; 434 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec; 435 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec; 436 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec; 437 ast->st_size = st->st_size; 438 ast->st_blocks = st->st_blocks; 439 ast->st_blksize = st->st_blksize; 440 ast->st_flags = st->st_flags; 441 ast->st_gen = st->st_gen; 442 ast->st_qspare[0] = 0; 443 ast->st_qspare[1] = 0; 444 } 445