1 /*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software withough specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: linux_file.c,v 1.20 1998/03/29 07:59:09 peter Exp $ 29 */ 30 31 #include "opt_compat.h" 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/sysproto.h> 36 #include <sys/fcntl.h> 37 #include <sys/file.h> 38 #include <sys/filedesc.h> 39 #include <sys/lock.h> 40 #include <sys/proc.h> 41 #include <sys/vnode.h> 42 #include <sys/malloc.h> 43 #include <sys/dirent.h> 44 #include <sys/conf.h> 45 #include <sys/tty.h> 46 47 #include <i386/linux/linux.h> 48 #include <i386/linux/linux_proto.h> 49 #include <i386/linux/linux_util.h> 50 51 int 52 linux_creat(struct proc *p, struct linux_creat_args *args) 53 { 54 struct open_args /* { 55 char *path; 56 int flags; 57 int mode; 58 } */ bsd_open_args; 59 caddr_t sg; 60 61 sg = stackgap_init(); 62 CHECKALTCREAT(p, &sg, args->path); 63 64 #ifdef DEBUG 65 printf("Linux-emul(%d): creat(%s, %d)\n", 66 p->p_pid, args->path, args->mode); 67 #endif 68 bsd_open_args.path = args->path; 69 bsd_open_args.mode = args->mode; 70 bsd_open_args.flags = O_WRONLY | O_CREAT | O_TRUNC; 71 return open(p, &bsd_open_args); 72 } 73 74 int 75 linux_open(struct proc *p, struct linux_open_args *args) 76 { 77 struct open_args /* { 78 char *path; 79 int flags; 80 int mode; 81 } */ bsd_open_args; 82 int error; 83 caddr_t sg; 84 85 sg = stackgap_init(); 86 87 if (args->flags & LINUX_O_CREAT) 88 CHECKALTCREAT(p, &sg, args->path); 89 else 90 CHECKALTEXIST(p, &sg, args->path); 91 92 #ifdef DEBUG 93 printf("Linux-emul(%d): open(%s, 0x%x, 0x%x)\n", 94 p->p_pid, args->path, args->flags, args->mode); 95 #endif 96 bsd_open_args.flags = 0; 97 if (args->flags & LINUX_O_RDONLY) 98 bsd_open_args.flags |= O_RDONLY; 99 if (args->flags & LINUX_O_WRONLY) 100 bsd_open_args.flags |= O_WRONLY; 101 if (args->flags & LINUX_O_RDWR) 102 bsd_open_args.flags |= O_RDWR; 103 if (args->flags & LINUX_O_NDELAY) 104 bsd_open_args.flags |= O_NONBLOCK; 105 if (args->flags & LINUX_O_APPEND) 106 bsd_open_args.flags |= O_APPEND; 107 if (args->flags & LINUX_O_SYNC) 108 bsd_open_args.flags |= O_FSYNC; 109 if (args->flags & LINUX_O_NONBLOCK) 110 bsd_open_args.flags |= O_NONBLOCK; 111 if (args->flags & LINUX_FASYNC) 112 bsd_open_args.flags |= O_ASYNC; 113 if (args->flags & LINUX_O_CREAT) 114 bsd_open_args.flags |= O_CREAT; 115 if (args->flags & LINUX_O_TRUNC) 116 bsd_open_args.flags |= O_TRUNC; 117 if (args->flags & LINUX_O_EXCL) 118 bsd_open_args.flags |= O_EXCL; 119 if (args->flags & LINUX_O_NOCTTY) 120 bsd_open_args.flags |= O_NOCTTY; 121 bsd_open_args.path = args->path; 122 bsd_open_args.mode = args->mode; 123 124 error = open(p, &bsd_open_args); 125 if (!error && !(bsd_open_args.flags & O_NOCTTY) && 126 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { 127 struct filedesc *fdp = p->p_fd; 128 struct file *fp = fdp->fd_ofiles[p->p_retval[0]]; 129 130 if (fp->f_type == DTYPE_VNODE) 131 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p); 132 } 133 #ifdef DEBUG 134 printf("Linux-emul(%d): open returns error %d\n", 135 p->p_pid, error); 136 #endif 137 return error; 138 } 139 140 struct linux_flock { 141 short l_type; 142 short l_whence; 143 linux_off_t l_start; 144 linux_off_t l_len; 145 linux_pid_t l_pid; 146 }; 147 148 static void 149 linux_to_bsd_flock(struct linux_flock *linux_flock, struct flock *bsd_flock) 150 { 151 switch (linux_flock->l_type) { 152 case LINUX_F_RDLCK: 153 bsd_flock->l_type = F_RDLCK; 154 break; 155 case LINUX_F_WRLCK: 156 bsd_flock->l_type = F_WRLCK; 157 break; 158 case LINUX_F_UNLCK: 159 bsd_flock->l_type = F_UNLCK; 160 break; 161 } 162 bsd_flock->l_whence = linux_flock->l_whence; 163 bsd_flock->l_start = (off_t)linux_flock->l_start; 164 bsd_flock->l_len = (off_t)linux_flock->l_len; 165 bsd_flock->l_pid = (pid_t)linux_flock->l_pid; 166 } 167 168 static void 169 bsd_to_linux_flock(struct flock *bsd_flock, struct linux_flock *linux_flock) 170 { 171 switch (bsd_flock->l_type) { 172 case F_RDLCK: 173 linux_flock->l_type = LINUX_F_RDLCK; 174 break; 175 case F_WRLCK: 176 linux_flock->l_type = LINUX_F_WRLCK; 177 break; 178 case F_UNLCK: 179 linux_flock->l_type = LINUX_F_UNLCK; 180 break; 181 } 182 linux_flock->l_whence = bsd_flock->l_whence; 183 linux_flock->l_start = (linux_off_t)bsd_flock->l_start; 184 linux_flock->l_len = (linux_off_t)bsd_flock->l_len; 185 linux_flock->l_pid = (linux_pid_t)bsd_flock->l_pid; 186 } 187 188 int 189 linux_fcntl(struct proc *p, struct linux_fcntl_args *args) 190 { 191 int error, result; 192 struct fcntl_args /* { 193 int fd; 194 int cmd; 195 int arg; 196 } */ fcntl_args; 197 struct linux_flock linux_flock; 198 struct flock *bsd_flock; 199 struct filedesc *fdp; 200 struct file *fp; 201 struct vnode *vp; 202 struct vattr va; 203 long pgid; 204 struct pgrp *pgrp; 205 struct tty *tp, *(*d_tty) __P((dev_t)); 206 caddr_t sg; 207 208 sg = stackgap_init(); 209 bsd_flock = (struct flock *)stackgap_alloc(&sg, sizeof(struct flock)); 210 d_tty = NULL; 211 212 #ifdef DEBUG 213 printf("Linux-emul(%d): fcntl(%d, %08x, *)\n", 214 p->p_pid, args->fd, args->cmd); 215 #endif 216 fcntl_args.fd = args->fd; 217 fcntl_args.arg = 0; 218 219 switch (args->cmd) { 220 case LINUX_F_DUPFD: 221 fcntl_args.cmd = F_DUPFD; 222 return fcntl(p, &fcntl_args); 223 224 case LINUX_F_GETFD: 225 fcntl_args.cmd = F_GETFD; 226 return fcntl(p, &fcntl_args); 227 228 case LINUX_F_SETFD: 229 fcntl_args.cmd = F_SETFD; 230 return fcntl(p, &fcntl_args); 231 232 case LINUX_F_GETFL: 233 fcntl_args.cmd = F_GETFL; 234 error = fcntl(p, &fcntl_args); 235 result = p->p_retval[0]; 236 p->p_retval[0] = 0; 237 if (result & O_RDONLY) p->p_retval[0] |= LINUX_O_RDONLY; 238 if (result & O_WRONLY) p->p_retval[0] |= LINUX_O_WRONLY; 239 if (result & O_RDWR) p->p_retval[0] |= LINUX_O_RDWR; 240 if (result & O_NDELAY) p->p_retval[0] |= LINUX_O_NONBLOCK; 241 if (result & O_APPEND) p->p_retval[0] |= LINUX_O_APPEND; 242 if (result & O_FSYNC) p->p_retval[0] |= LINUX_O_SYNC; 243 return error; 244 245 case LINUX_F_SETFL: 246 if (args->arg & LINUX_O_NDELAY) fcntl_args.arg |= O_NONBLOCK; 247 if (args->arg & LINUX_O_APPEND) fcntl_args.arg |= O_APPEND; 248 if (args->arg & LINUX_O_SYNC) fcntl_args.arg |= O_FSYNC; 249 fcntl_args.cmd = F_SETFL; 250 return fcntl(p, &fcntl_args); 251 252 case LINUX_F_GETLK: 253 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 254 sizeof(struct linux_flock)))) 255 return error; 256 linux_to_bsd_flock(&linux_flock, bsd_flock); 257 fcntl_args.cmd = F_GETLK; 258 fcntl_args.arg = (int)bsd_flock; 259 if (error = fcntl(p, &fcntl_args)) 260 return error; 261 bsd_to_linux_flock(bsd_flock, &linux_flock); 262 return copyout((caddr_t)&linux_flock, (caddr_t)args->arg, 263 sizeof(struct linux_flock)); 264 265 case LINUX_F_SETLK: 266 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 267 sizeof(struct linux_flock)))) 268 return error; 269 linux_to_bsd_flock(&linux_flock, bsd_flock); 270 fcntl_args.cmd = F_SETLK; 271 fcntl_args.arg = (int)bsd_flock; 272 return fcntl(p, &fcntl_args); 273 274 case LINUX_F_SETLKW: 275 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 276 sizeof(struct linux_flock)))) 277 return error; 278 linux_to_bsd_flock(&linux_flock, bsd_flock); 279 fcntl_args.cmd = F_SETLKW; 280 fcntl_args.arg = (int)bsd_flock; 281 return fcntl(p, &fcntl_args); 282 283 case LINUX_F_SETOWN: 284 case LINUX_F_GETOWN: 285 /* 286 * We need to route around the normal fcntl() for these calls, 287 * since it uses TIOC{G,S}PGRP, which is too restrictive for 288 * Linux F_{G,S}ETOWN semantics. For sockets, this problem 289 * does not exist. 290 */ 291 fdp = p->p_fd; 292 if ((u_int)args->fd >= fdp->fd_nfiles || 293 (fp = fdp->fd_ofiles[args->fd]) == NULL) 294 return EBADF; 295 if (fp->f_type == DTYPE_SOCKET) { 296 fcntl_args.cmd = args->cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN; 297 return fcntl(p, &fcntl_args); 298 } 299 vp = (struct vnode *)fp->f_data; 300 if (vp->v_type != VCHR) 301 return EINVAL; 302 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) 303 return error; 304 305 d_tty = cdevsw[major(va.va_rdev)]->d_devtotty; 306 if (!d_tty || (!(tp = (*d_tty)(va.va_rdev)))) 307 return EINVAL; 308 if (args->cmd == LINUX_F_GETOWN) { 309 p->p_retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID; 310 return 0; 311 } 312 if ((long)args->arg <= 0) { 313 pgid = -(long)args->arg; 314 } else { 315 struct proc *p1 = pfind((long)args->arg); 316 if (p1 == 0) 317 return (ESRCH); 318 pgid = (long)p1->p_pgrp->pg_id; 319 } 320 pgrp = pgfind(pgid); 321 if (pgrp == NULL || pgrp->pg_session != p->p_session) 322 return EPERM; 323 tp->t_pgrp = pgrp; 324 return 0; 325 } 326 return EINVAL; 327 } 328 329 int 330 linux_lseek(struct proc *p, struct linux_lseek_args *args) 331 { 332 333 struct lseek_args /* { 334 int fd; 335 int pad; 336 off_t offset; 337 int whence; 338 } */ tmp_args; 339 int error; 340 341 #ifdef DEBUG 342 printf("Linux-emul(%ld): lseek(%d, %ld, %d)\n", 343 (long)p->p_pid, args->fdes, args->off, args->whence); 344 #endif 345 tmp_args.fd = args->fdes; 346 tmp_args.offset = (off_t)args->off; 347 tmp_args.whence = args->whence; 348 error = lseek(p, &tmp_args); 349 return error; 350 } 351 352 int 353 linux_llseek(struct proc *p, struct linux_llseek_args *args) 354 { 355 struct lseek_args bsd_args; 356 int error; 357 off_t off; 358 359 #ifdef DEBUG 360 printf("Linux-emul(%d): llseek(%d, %d:%d, %d)\n", 361 p->p_pid, args->fd, args->ohigh, args->olow, args->whence); 362 #endif 363 off = (args->olow) | (((off_t) args->ohigh) << 32); 364 365 bsd_args.fd = args->fd; 366 bsd_args.offset = off; 367 bsd_args.whence = args->whence; 368 369 if ((error = lseek(p, &bsd_args))) 370 return error; 371 372 if ((error = copyout(p->p_retval, (caddr_t)args->res, sizeof (off_t)))) 373 return error; 374 375 p->p_retval[0] = 0; 376 return 0; 377 } 378 379 380 struct linux_dirent { 381 long dino; 382 linux_off_t doff; 383 unsigned short dreclen; 384 char dname[LINUX_NAME_MAX + 1]; 385 }; 386 387 #define LINUX_RECLEN(de,namlen) \ 388 ALIGN((((char *)&(de)->dname - (char *)de) + (namlen) + 1)) 389 390 int 391 linux_readdir(struct proc *p, struct linux_readdir_args *args) 392 { 393 struct linux_getdents_args lda; 394 395 lda.fd = args->fd; 396 lda.dent = args->dent; 397 lda.count = 1; 398 return linux_getdents(p, &lda); 399 } 400 401 int 402 linux_getdents(struct proc *p, struct linux_getdents_args *args) 403 { 404 register struct dirent *bdp; 405 struct vnode *vp; 406 caddr_t inp, buf; /* BSD-format */ 407 int len, reclen; /* BSD-format */ 408 caddr_t outp; /* Linux-format */ 409 int resid, linuxreclen=0; /* Linux-format */ 410 struct file *fp; 411 struct uio auio; 412 struct iovec aiov; 413 struct vattr va; 414 off_t off; 415 struct linux_dirent linux_dirent; 416 int buflen, error, eofflag, nbytes, justone; 417 u_long *cookies = NULL, *cookiep; 418 int ncookies; 419 420 #ifdef DEBUG 421 printf("Linux-emul(%d): getdents(%d, *, %d)\n", 422 p->p_pid, args->fd, args->count); 423 #endif 424 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0) { 425 return (error); 426 } 427 428 if ((fp->f_flag & FREAD) == 0) 429 return (EBADF); 430 431 vp = (struct vnode *) fp->f_data; 432 433 if (vp->v_type != VDIR) 434 return (EINVAL); 435 436 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) { 437 return error; 438 } 439 440 nbytes = args->count; 441 if (nbytes == 1) { 442 nbytes = sizeof (struct linux_dirent); 443 justone = 1; 444 } 445 else 446 justone = 0; 447 448 off = fp->f_offset; 449 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 450 buflen = max(DIRBLKSIZ, nbytes); 451 buflen = min(buflen, MAXBSIZE); 452 buf = malloc(buflen, M_TEMP, M_WAITOK); 453 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 454 again: 455 aiov.iov_base = buf; 456 aiov.iov_len = buflen; 457 auio.uio_iov = &aiov; 458 auio.uio_iovcnt = 1; 459 auio.uio_rw = UIO_READ; 460 auio.uio_segflg = UIO_SYSSPACE; 461 auio.uio_procp = p; 462 auio.uio_resid = buflen; 463 auio.uio_offset = off; 464 465 if (cookies) { 466 free(cookies, M_TEMP); 467 cookies = NULL; 468 } 469 470 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies); 471 if (error) { 472 goto out; 473 } 474 475 inp = buf; 476 outp = (caddr_t) args->dent; 477 resid = nbytes; 478 if ((len = buflen - auio.uio_resid) <= 0) { 479 goto eof; 480 } 481 482 cookiep = cookies; 483 484 if (cookies) { 485 /* 486 * When using cookies, the vfs has the option of reading from 487 * a different offset than that supplied (UFS truncates the 488 * offset to a block boundary to make sure that it never reads 489 * partway through a directory entry, even if the directory 490 * has been compacted). 491 */ 492 while (len > 0 && ncookies > 0 && *cookiep <= off) { 493 bdp = (struct dirent *) inp; 494 len -= bdp->d_reclen; 495 inp += bdp->d_reclen; 496 cookiep++; 497 ncookies--; 498 } 499 } 500 501 while (len > 0) { 502 if (cookiep && ncookies == 0) 503 break; 504 bdp = (struct dirent *) inp; 505 reclen = bdp->d_reclen; 506 if (reclen & 3) { 507 printf("linux_readdir: reclen=%d\n", reclen); 508 error = EFAULT; 509 goto out; 510 } 511 512 if (bdp->d_fileno == 0) { 513 inp += reclen; 514 if (cookiep) { 515 off = *cookiep++; 516 ncookies--; 517 } else 518 off += reclen; 519 len -= reclen; 520 continue; 521 } 522 linuxreclen = LINUX_RECLEN(&linux_dirent, bdp->d_namlen); 523 if (reclen > len || resid < linuxreclen) { 524 outp++; 525 break; 526 } 527 linux_dirent.dino = (long) bdp->d_fileno; 528 if (justone) { 529 /* 530 * old linux-style readdir usage. 531 */ 532 linux_dirent.doff = (linux_off_t) linuxreclen; 533 linux_dirent.dreclen = (u_short) bdp->d_namlen; 534 } else { 535 linux_dirent.doff = (linux_off_t) off; 536 linux_dirent.dreclen = (u_short) linuxreclen; 537 } 538 strcpy(linux_dirent.dname, bdp->d_name); 539 if ((error = copyout((caddr_t)&linux_dirent, outp, linuxreclen))) { 540 goto out; 541 } 542 inp += reclen; 543 if (cookiep) { 544 off = *cookiep++; 545 ncookies--; 546 } else 547 off += reclen; 548 outp += linuxreclen; 549 resid -= linuxreclen; 550 len -= reclen; 551 if (justone) 552 break; 553 } 554 555 if (outp == (caddr_t) args->dent) 556 goto again; 557 fp->f_offset = off; 558 559 if (justone) 560 nbytes = resid + linuxreclen; 561 562 eof: 563 p->p_retval[0] = nbytes - resid; 564 out: 565 if (cookies) 566 free(cookies, M_TEMP); 567 VOP_UNLOCK(vp, 0, p); 568 free(buf, M_TEMP); 569 return error; 570 } 571 572 /* 573 * These exist mainly for hooks for doing /compat/linux translation. 574 */ 575 576 int 577 linux_access(struct proc *p, struct linux_access_args *args) 578 { 579 struct access_args bsd; 580 caddr_t sg; 581 582 sg = stackgap_init(); 583 CHECKALTEXIST(p, &sg, args->path); 584 585 #ifdef DEBUG 586 printf("Linux-emul(%d): access(%s, %d)\n", 587 p->p_pid, args->path, args->flags); 588 #endif 589 bsd.path = args->path; 590 bsd.flags = args->flags; 591 592 return access(p, &bsd); 593 } 594 595 int 596 linux_unlink(struct proc *p, struct linux_unlink_args *args) 597 { 598 struct unlink_args bsd; 599 caddr_t sg; 600 601 sg = stackgap_init(); 602 CHECKALTEXIST(p, &sg, args->path); 603 604 #ifdef DEBUG 605 printf("Linux-emul(%d): unlink(%s)\n", 606 p->p_pid, args->path); 607 #endif 608 bsd.path = args->path; 609 610 return unlink(p, &bsd); 611 } 612 613 int 614 linux_chdir(struct proc *p, struct linux_chdir_args *args) 615 { 616 struct chdir_args bsd; 617 caddr_t sg; 618 619 sg = stackgap_init(); 620 CHECKALTEXIST(p, &sg, args->path); 621 622 #ifdef DEBUG 623 printf("Linux-emul(%d): chdir(%s)\n", 624 p->p_pid, args->path); 625 #endif 626 bsd.path = args->path; 627 628 return chdir(p, &bsd); 629 } 630 631 int 632 linux_chmod(struct proc *p, struct linux_chmod_args *args) 633 { 634 struct chmod_args bsd; 635 caddr_t sg; 636 637 sg = stackgap_init(); 638 CHECKALTEXIST(p, &sg, args->path); 639 640 #ifdef DEBUG 641 printf("Linux-emul(%d): chmod(%s, %d)\n", 642 p->p_pid, args->path, args->mode); 643 #endif 644 bsd.path = args->path; 645 bsd.mode = args->mode; 646 647 return chmod(p, &bsd); 648 } 649 650 int 651 linux_chown(struct proc *p, struct linux_chown_args *args) 652 { 653 struct chown_args bsd; 654 caddr_t sg; 655 656 sg = stackgap_init(); 657 CHECKALTEXIST(p, &sg, args->path); 658 659 #ifdef DEBUG 660 printf("Linux-emul(%d): chown(%s, %d, %d)\n", 661 p->p_pid, args->path, args->uid, args->gid); 662 #endif 663 bsd.path = args->path; 664 /* XXX size casts here */ 665 bsd.uid = args->uid; 666 bsd.gid = args->gid; 667 668 return chown(p, &bsd); 669 } 670 671 int 672 linux_lchown(struct proc *p, struct linux_lchown_args *args) 673 { 674 struct lchown_args bsd; 675 caddr_t sg; 676 677 sg = stackgap_init(); 678 CHECKALTEXIST(p, &sg, args->path); 679 680 #ifdef DEBUG 681 printf("Linux-emul(%d): lchown(%s, %d, %d)\n", 682 p->p_pid, args->path, args->uid, args->gid); 683 #endif 684 bsd.path = args->path; 685 /* XXX size casts here */ 686 bsd.uid = args->uid; 687 bsd.gid = args->gid; 688 689 return lchown(p, &bsd); 690 } 691 692 int 693 linux_mkdir(struct proc *p, struct linux_mkdir_args *args) 694 { 695 struct mkdir_args bsd; 696 caddr_t sg; 697 698 sg = stackgap_init(); 699 CHECKALTCREAT(p, &sg, args->path); 700 701 #ifdef DEBUG 702 printf("Linux-emul(%d): mkdir(%s, %d)\n", 703 p->p_pid, args->path, args->mode); 704 #endif 705 bsd.path = args->path; 706 bsd.mode = args->mode; 707 708 return mkdir(p, &bsd); 709 } 710 711 int 712 linux_rmdir(struct proc *p, struct linux_rmdir_args *args) 713 { 714 struct rmdir_args bsd; 715 caddr_t sg; 716 717 sg = stackgap_init(); 718 CHECKALTEXIST(p, &sg, args->path); 719 720 #ifdef DEBUG 721 printf("Linux-emul(%d): rmdir(%s)\n", 722 p->p_pid, args->path); 723 #endif 724 bsd.path = args->path; 725 726 return rmdir(p, &bsd); 727 } 728 729 int 730 linux_rename(struct proc *p, struct linux_rename_args *args) 731 { 732 struct rename_args bsd; 733 caddr_t sg; 734 735 sg = stackgap_init(); 736 CHECKALTEXIST(p, &sg, args->from); 737 CHECKALTCREAT(p, &sg, args->to); 738 739 #ifdef DEBUG 740 printf("Linux-emul(%d): rename(%s, %s)\n", 741 p->p_pid, args->from, args->to); 742 #endif 743 bsd.from = args->from; 744 bsd.to = args->to; 745 746 return rename(p, &bsd); 747 } 748 749 int 750 linux_symlink(struct proc *p, struct linux_symlink_args *args) 751 { 752 struct symlink_args bsd; 753 caddr_t sg; 754 755 sg = stackgap_init(); 756 CHECKALTEXIST(p, &sg, args->path); 757 CHECKALTCREAT(p, &sg, args->to); 758 759 #ifdef DEBUG 760 printf("Linux-emul(%d): symlink(%s, %s)\n", 761 p->p_pid, args->path, args->to); 762 #endif 763 bsd.path = args->path; 764 bsd.link = args->to; 765 766 return symlink(p, &bsd); 767 } 768 769 int 770 linux_execve(struct proc *p, struct linux_execve_args *args) 771 { 772 struct execve_args bsd; 773 caddr_t sg; 774 775 sg = stackgap_init(); 776 CHECKALTEXIST(p, &sg, args->path); 777 778 #ifdef DEBUG 779 printf("Linux-emul(%d): execve(%s)\n", 780 p->p_pid, args->path); 781 #endif 782 bsd.fname = args->path; 783 bsd.argv = args->argp; 784 bsd.envv = args->envp; 785 786 return execve(p, &bsd); 787 } 788 789 int 790 linux_readlink(struct proc *p, struct linux_readlink_args *args) 791 { 792 struct readlink_args bsd; 793 caddr_t sg; 794 795 sg = stackgap_init(); 796 CHECKALTEXIST(p, &sg, args->name); 797 798 #ifdef DEBUG 799 printf("Linux-emul(%ld): readlink(%s, %p, %d)\n", 800 (long)p->p_pid, args->name, (void *)args->buf, args->count); 801 #endif 802 bsd.path = args->name; 803 bsd.buf = args->buf; 804 bsd.count = args->count; 805 806 return readlink(p, &bsd); 807 } 808 809 int 810 linux_truncate(struct proc *p, struct linux_truncate_args *args) 811 { 812 struct otruncate_args bsd; 813 caddr_t sg; 814 815 sg = stackgap_init(); 816 CHECKALTEXIST(p, &sg, args->path); 817 818 #ifdef DEBUG 819 printf("Linux-emul(%d): truncate(%s, %ld)\n", 820 p->p_pid, args->path, args->length); 821 #endif 822 bsd.path = args->path; 823 bsd.length = args->length; 824 825 return otruncate(p, &bsd); 826 } 827 828