linux_file.c revision 39978
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.21 1998/07/29 16:43:00 bde 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 51int 52linux_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 74int 75linux_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 140struct 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 148static void 149linux_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 168static void 169bsd_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 188int 189linux_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 if (result & O_ASYNC) p->p_retval[0] |= LINUX_FASYNC; 244 return error; 245 246 case LINUX_F_SETFL: 247 if (args->arg & LINUX_O_NDELAY) fcntl_args.arg |= O_NONBLOCK; 248 if (args->arg & LINUX_O_APPEND) fcntl_args.arg |= O_APPEND; 249 if (args->arg & LINUX_O_SYNC) fcntl_args.arg |= O_FSYNC; 250 if (args->arg & LINUX_FASYNC) fcntl_args.arg |= O_ASYNC; 251 fcntl_args.cmd = F_SETFL; 252 return fcntl(p, &fcntl_args); 253 254 case LINUX_F_GETLK: 255 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 256 sizeof(struct linux_flock)))) 257 return error; 258 linux_to_bsd_flock(&linux_flock, bsd_flock); 259 fcntl_args.cmd = F_GETLK; 260 fcntl_args.arg = (int)bsd_flock; 261 if (error = fcntl(p, &fcntl_args)) 262 return error; 263 bsd_to_linux_flock(bsd_flock, &linux_flock); 264 return copyout((caddr_t)&linux_flock, (caddr_t)args->arg, 265 sizeof(struct linux_flock)); 266 267 case LINUX_F_SETLK: 268 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 269 sizeof(struct linux_flock)))) 270 return error; 271 linux_to_bsd_flock(&linux_flock, bsd_flock); 272 fcntl_args.cmd = F_SETLK; 273 fcntl_args.arg = (int)bsd_flock; 274 return fcntl(p, &fcntl_args); 275 276 case LINUX_F_SETLKW: 277 if ((error = copyin((caddr_t)args->arg, (caddr_t)&linux_flock, 278 sizeof(struct linux_flock)))) 279 return error; 280 linux_to_bsd_flock(&linux_flock, bsd_flock); 281 fcntl_args.cmd = F_SETLKW; 282 fcntl_args.arg = (int)bsd_flock; 283 return fcntl(p, &fcntl_args); 284 285 case LINUX_F_SETOWN: 286 case LINUX_F_GETOWN: 287 /* 288 * We need to route around the normal fcntl() for these calls, 289 * since it uses TIOC{G,S}PGRP, which is too restrictive for 290 * Linux F_{G,S}ETOWN semantics. For sockets, this problem 291 * does not exist. 292 */ 293 fdp = p->p_fd; 294 if ((u_int)args->fd >= fdp->fd_nfiles || 295 (fp = fdp->fd_ofiles[args->fd]) == NULL) 296 return EBADF; 297 if (fp->f_type == DTYPE_SOCKET) { 298 fcntl_args.cmd = args->cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN; 299 fcntl_args.arg = args->arg; 300 return fcntl(p, &fcntl_args); 301 } 302 vp = (struct vnode *)fp->f_data; 303 if (vp->v_type != VCHR) 304 return EINVAL; 305 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) 306 return error; 307 308 d_tty = cdevsw[major(va.va_rdev)]->d_devtotty; 309 if (!d_tty || (!(tp = (*d_tty)(va.va_rdev)))) 310 return EINVAL; 311 if (args->cmd == LINUX_F_GETOWN) { 312 p->p_retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID; 313 return 0; 314 } 315 if ((long)args->arg <= 0) { 316 pgid = -(long)args->arg; 317 } else { 318 struct proc *p1 = pfind((long)args->arg); 319 if (p1 == 0) 320 return (ESRCH); 321 pgid = (long)p1->p_pgrp->pg_id; 322 } 323 pgrp = pgfind(pgid); 324 if (pgrp == NULL || pgrp->pg_session != p->p_session) 325 return EPERM; 326 tp->t_pgrp = pgrp; 327 return 0; 328 } 329 return EINVAL; 330} 331 332int 333linux_lseek(struct proc *p, struct linux_lseek_args *args) 334{ 335 336 struct lseek_args /* { 337 int fd; 338 int pad; 339 off_t offset; 340 int whence; 341 } */ tmp_args; 342 int error; 343 344#ifdef DEBUG 345 printf("Linux-emul(%ld): lseek(%d, %ld, %d)\n", 346 (long)p->p_pid, args->fdes, args->off, args->whence); 347#endif 348 tmp_args.fd = args->fdes; 349 tmp_args.offset = (off_t)args->off; 350 tmp_args.whence = args->whence; 351 error = lseek(p, &tmp_args); 352 return error; 353} 354 355int 356linux_llseek(struct proc *p, struct linux_llseek_args *args) 357{ 358 struct lseek_args bsd_args; 359 int error; 360 off_t off; 361 362#ifdef DEBUG 363 printf("Linux-emul(%d): llseek(%d, %d:%d, %d)\n", 364 p->p_pid, args->fd, args->ohigh, args->olow, args->whence); 365#endif 366 off = (args->olow) | (((off_t) args->ohigh) << 32); 367 368 bsd_args.fd = args->fd; 369 bsd_args.offset = off; 370 bsd_args.whence = args->whence; 371 372 if ((error = lseek(p, &bsd_args))) 373 return error; 374 375 if ((error = copyout(p->p_retval, (caddr_t)args->res, sizeof (off_t)))) 376 return error; 377 378 p->p_retval[0] = 0; 379 return 0; 380} 381 382 383struct linux_dirent { 384 long dino; 385 linux_off_t doff; 386 unsigned short dreclen; 387 char dname[LINUX_NAME_MAX + 1]; 388}; 389 390#define LINUX_RECLEN(de,namlen) \ 391 ALIGN((((char *)&(de)->dname - (char *)de) + (namlen) + 1)) 392 393int 394linux_readdir(struct proc *p, struct linux_readdir_args *args) 395{ 396 struct linux_getdents_args lda; 397 398 lda.fd = args->fd; 399 lda.dent = args->dent; 400 lda.count = 1; 401 return linux_getdents(p, &lda); 402} 403 404int 405linux_getdents(struct proc *p, struct linux_getdents_args *args) 406{ 407 register struct dirent *bdp; 408 struct vnode *vp; 409 caddr_t inp, buf; /* BSD-format */ 410 int len, reclen; /* BSD-format */ 411 caddr_t outp; /* Linux-format */ 412 int resid, linuxreclen=0; /* Linux-format */ 413 struct file *fp; 414 struct uio auio; 415 struct iovec aiov; 416 struct vattr va; 417 off_t off; 418 struct linux_dirent linux_dirent; 419 int buflen, error, eofflag, nbytes, justone; 420 u_long *cookies = NULL, *cookiep; 421 int ncookies; 422 423#ifdef DEBUG 424 printf("Linux-emul(%d): getdents(%d, *, %d)\n", 425 p->p_pid, args->fd, args->count); 426#endif 427 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0) { 428 return (error); 429 } 430 431 if ((fp->f_flag & FREAD) == 0) 432 return (EBADF); 433 434 vp = (struct vnode *) fp->f_data; 435 436 if (vp->v_type != VDIR) 437 return (EINVAL); 438 439 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) { 440 return error; 441 } 442 443 nbytes = args->count; 444 if (nbytes == 1) { 445 nbytes = sizeof (struct linux_dirent); 446 justone = 1; 447 } 448 else 449 justone = 0; 450 451 off = fp->f_offset; 452#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 453 buflen = max(DIRBLKSIZ, nbytes); 454 buflen = min(buflen, MAXBSIZE); 455 buf = malloc(buflen, M_TEMP, M_WAITOK); 456 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 457again: 458 aiov.iov_base = buf; 459 aiov.iov_len = buflen; 460 auio.uio_iov = &aiov; 461 auio.uio_iovcnt = 1; 462 auio.uio_rw = UIO_READ; 463 auio.uio_segflg = UIO_SYSSPACE; 464 auio.uio_procp = p; 465 auio.uio_resid = buflen; 466 auio.uio_offset = off; 467 468 if (cookies) { 469 free(cookies, M_TEMP); 470 cookies = NULL; 471 } 472 473 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies); 474 if (error) { 475 goto out; 476 } 477 478 inp = buf; 479 outp = (caddr_t) args->dent; 480 resid = nbytes; 481 if ((len = buflen - auio.uio_resid) <= 0) { 482 goto eof; 483 } 484 485 cookiep = cookies; 486 487 if (cookies) { 488 /* 489 * When using cookies, the vfs has the option of reading from 490 * a different offset than that supplied (UFS truncates the 491 * offset to a block boundary to make sure that it never reads 492 * partway through a directory entry, even if the directory 493 * has been compacted). 494 */ 495 while (len > 0 && ncookies > 0 && *cookiep <= off) { 496 bdp = (struct dirent *) inp; 497 len -= bdp->d_reclen; 498 inp += bdp->d_reclen; 499 cookiep++; 500 ncookies--; 501 } 502 } 503 504 while (len > 0) { 505 if (cookiep && ncookies == 0) 506 break; 507 bdp = (struct dirent *) inp; 508 reclen = bdp->d_reclen; 509 if (reclen & 3) { 510 printf("linux_readdir: reclen=%d\n", reclen); 511 error = EFAULT; 512 goto out; 513 } 514 515 if (bdp->d_fileno == 0) { 516 inp += reclen; 517 if (cookiep) { 518 off = *cookiep++; 519 ncookies--; 520 } else 521 off += reclen; 522 len -= reclen; 523 continue; 524 } 525 linuxreclen = LINUX_RECLEN(&linux_dirent, bdp->d_namlen); 526 if (reclen > len || resid < linuxreclen) { 527 outp++; 528 break; 529 } 530 linux_dirent.dino = (long) bdp->d_fileno; 531 if (justone) { 532 /* 533 * old linux-style readdir usage. 534 */ 535 linux_dirent.doff = (linux_off_t) linuxreclen; 536 linux_dirent.dreclen = (u_short) bdp->d_namlen; 537 } else { 538 linux_dirent.doff = (linux_off_t) off; 539 linux_dirent.dreclen = (u_short) linuxreclen; 540 } 541 strcpy(linux_dirent.dname, bdp->d_name); 542 if ((error = copyout((caddr_t)&linux_dirent, outp, linuxreclen))) { 543 goto out; 544 } 545 inp += reclen; 546 if (cookiep) { 547 off = *cookiep++; 548 ncookies--; 549 } else 550 off += reclen; 551 outp += linuxreclen; 552 resid -= linuxreclen; 553 len -= reclen; 554 if (justone) 555 break; 556 } 557 558 if (outp == (caddr_t) args->dent) 559 goto again; 560 fp->f_offset = off; 561 562 if (justone) 563 nbytes = resid + linuxreclen; 564 565eof: 566 p->p_retval[0] = nbytes - resid; 567out: 568 if (cookies) 569 free(cookies, M_TEMP); 570 VOP_UNLOCK(vp, 0, p); 571 free(buf, M_TEMP); 572 return error; 573} 574 575/* 576 * These exist mainly for hooks for doing /compat/linux translation. 577 */ 578 579int 580linux_access(struct proc *p, struct linux_access_args *args) 581{ 582 struct access_args bsd; 583 caddr_t sg; 584 585 sg = stackgap_init(); 586 CHECKALTEXIST(p, &sg, args->path); 587 588#ifdef DEBUG 589 printf("Linux-emul(%d): access(%s, %d)\n", 590 p->p_pid, args->path, args->flags); 591#endif 592 bsd.path = args->path; 593 bsd.flags = args->flags; 594 595 return access(p, &bsd); 596} 597 598int 599linux_unlink(struct proc *p, struct linux_unlink_args *args) 600{ 601 struct unlink_args bsd; 602 caddr_t sg; 603 604 sg = stackgap_init(); 605 CHECKALTEXIST(p, &sg, args->path); 606 607#ifdef DEBUG 608 printf("Linux-emul(%d): unlink(%s)\n", 609 p->p_pid, args->path); 610#endif 611 bsd.path = args->path; 612 613 return unlink(p, &bsd); 614} 615 616int 617linux_chdir(struct proc *p, struct linux_chdir_args *args) 618{ 619 struct chdir_args bsd; 620 caddr_t sg; 621 622 sg = stackgap_init(); 623 CHECKALTEXIST(p, &sg, args->path); 624 625#ifdef DEBUG 626 printf("Linux-emul(%d): chdir(%s)\n", 627 p->p_pid, args->path); 628#endif 629 bsd.path = args->path; 630 631 return chdir(p, &bsd); 632} 633 634int 635linux_chmod(struct proc *p, struct linux_chmod_args *args) 636{ 637 struct chmod_args bsd; 638 caddr_t sg; 639 640 sg = stackgap_init(); 641 CHECKALTEXIST(p, &sg, args->path); 642 643#ifdef DEBUG 644 printf("Linux-emul(%d): chmod(%s, %d)\n", 645 p->p_pid, args->path, args->mode); 646#endif 647 bsd.path = args->path; 648 bsd.mode = args->mode; 649 650 return chmod(p, &bsd); 651} 652 653int 654linux_chown(struct proc *p, struct linux_chown_args *args) 655{ 656 struct chown_args bsd; 657 caddr_t sg; 658 659 sg = stackgap_init(); 660 CHECKALTEXIST(p, &sg, args->path); 661 662#ifdef DEBUG 663 printf("Linux-emul(%d): chown(%s, %d, %d)\n", 664 p->p_pid, args->path, args->uid, args->gid); 665#endif 666 bsd.path = args->path; 667 /* XXX size casts here */ 668 bsd.uid = args->uid; 669 bsd.gid = args->gid; 670 671 return chown(p, &bsd); 672} 673 674int 675linux_lchown(struct proc *p, struct linux_lchown_args *args) 676{ 677 struct lchown_args bsd; 678 caddr_t sg; 679 680 sg = stackgap_init(); 681 CHECKALTEXIST(p, &sg, args->path); 682 683#ifdef DEBUG 684 printf("Linux-emul(%d): lchown(%s, %d, %d)\n", 685 p->p_pid, args->path, args->uid, args->gid); 686#endif 687 bsd.path = args->path; 688 /* XXX size casts here */ 689 bsd.uid = args->uid; 690 bsd.gid = args->gid; 691 692 return lchown(p, &bsd); 693} 694 695int 696linux_mkdir(struct proc *p, struct linux_mkdir_args *args) 697{ 698 struct mkdir_args bsd; 699 caddr_t sg; 700 701 sg = stackgap_init(); 702 CHECKALTCREAT(p, &sg, args->path); 703 704#ifdef DEBUG 705 printf("Linux-emul(%d): mkdir(%s, %d)\n", 706 p->p_pid, args->path, args->mode); 707#endif 708 bsd.path = args->path; 709 bsd.mode = args->mode; 710 711 return mkdir(p, &bsd); 712} 713 714int 715linux_rmdir(struct proc *p, struct linux_rmdir_args *args) 716{ 717 struct rmdir_args bsd; 718 caddr_t sg; 719 720 sg = stackgap_init(); 721 CHECKALTEXIST(p, &sg, args->path); 722 723#ifdef DEBUG 724 printf("Linux-emul(%d): rmdir(%s)\n", 725 p->p_pid, args->path); 726#endif 727 bsd.path = args->path; 728 729 return rmdir(p, &bsd); 730} 731 732int 733linux_rename(struct proc *p, struct linux_rename_args *args) 734{ 735 struct rename_args bsd; 736 caddr_t sg; 737 738 sg = stackgap_init(); 739 CHECKALTEXIST(p, &sg, args->from); 740 CHECKALTCREAT(p, &sg, args->to); 741 742#ifdef DEBUG 743 printf("Linux-emul(%d): rename(%s, %s)\n", 744 p->p_pid, args->from, args->to); 745#endif 746 bsd.from = args->from; 747 bsd.to = args->to; 748 749 return rename(p, &bsd); 750} 751 752int 753linux_symlink(struct proc *p, struct linux_symlink_args *args) 754{ 755 struct symlink_args bsd; 756 caddr_t sg; 757 758 sg = stackgap_init(); 759 CHECKALTEXIST(p, &sg, args->path); 760 CHECKALTCREAT(p, &sg, args->to); 761 762#ifdef DEBUG 763 printf("Linux-emul(%d): symlink(%s, %s)\n", 764 p->p_pid, args->path, args->to); 765#endif 766 bsd.path = args->path; 767 bsd.link = args->to; 768 769 return symlink(p, &bsd); 770} 771 772int 773linux_execve(struct proc *p, struct linux_execve_args *args) 774{ 775 struct execve_args bsd; 776 caddr_t sg; 777 778 sg = stackgap_init(); 779 CHECKALTEXIST(p, &sg, args->path); 780 781#ifdef DEBUG 782 printf("Linux-emul(%d): execve(%s)\n", 783 p->p_pid, args->path); 784#endif 785 bsd.fname = args->path; 786 bsd.argv = args->argp; 787 bsd.envv = args->envp; 788 789 return execve(p, &bsd); 790} 791 792int 793linux_readlink(struct proc *p, struct linux_readlink_args *args) 794{ 795 struct readlink_args bsd; 796 caddr_t sg; 797 798 sg = stackgap_init(); 799 CHECKALTEXIST(p, &sg, args->name); 800 801#ifdef DEBUG 802 printf("Linux-emul(%ld): readlink(%s, %p, %d)\n", 803 (long)p->p_pid, args->name, (void *)args->buf, args->count); 804#endif 805 bsd.path = args->name; 806 bsd.buf = args->buf; 807 bsd.count = args->count; 808 809 return readlink(p, &bsd); 810} 811 812int 813linux_truncate(struct proc *p, struct linux_truncate_args *args) 814{ 815 struct otruncate_args bsd; 816 caddr_t sg; 817 818 sg = stackgap_init(); 819 CHECKALTEXIST(p, &sg, args->path); 820 821#ifdef DEBUG 822 printf("Linux-emul(%d): truncate(%s, %ld)\n", 823 p->p_pid, args->path, args->length); 824#endif 825 bsd.path = args->path; 826 bsd.length = args->length; 827 828 return otruncate(p, &bsd); 829} 830 831