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 without 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 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include "opt_compat.h" 33 34 #include <sys/param.h> 35 #include <sys/dirent.h> 36 #include <sys/file.h> 37 #include <sys/filedesc.h> 38 #include <sys/proc.h> 39 #include <sys/malloc.h> 40 #include <sys/mount.h> 41 #include <sys/namei.h> 42 #include <sys/stat.h> 43 #include <sys/syscallsubr.h> 44 #include <sys/systm.h> 45 #include <sys/tty.h> 46 #include <sys/vnode.h> 47 #include <sys/conf.h> 48 #include <sys/fcntl.h> 49 50 #ifdef COMPAT_LINUX32 51 #include <machine/../linux32/linux.h> 52 #include <machine/../linux32/linux32_proto.h> 53 #else 54 #include <machine/../linux/linux.h> 55 #include <machine/../linux/linux_proto.h> 56 #endif 57 58 #include <compat/linux/linux_util.h> 59 #include <compat/linux/linux_file.h> 60 61 62 static void 63 translate_vnhook_major_minor(struct vnode *vp, struct stat *sb) 64 { 65 int major, minor; 66 67 if (vp->v_type == VCHR && vp->v_rdev != NULL && 68 linux_driver_get_major_minor(devtoname(vp->v_rdev), 69 &major, &minor) == 0) { 70 sb->st_rdev = (major << 8 | minor); 71 } 72 } 73 74 static int 75 linux_kern_statat(struct thread *td, int flag, int fd, char *path, 76 enum uio_seg pathseg, struct stat *sbp) 77 { 78 79 return (kern_statat(td, flag, fd, path, pathseg, sbp, 80 translate_vnhook_major_minor)); 81 } 82 83 static int 84 linux_kern_stat(struct thread *td, char *path, enum uio_seg pathseg, 85 struct stat *sbp) 86 { 87 88 return (linux_kern_statat(td, 0, AT_FDCWD, path, pathseg, sbp)); 89 } 90 91 static int 92 linux_kern_lstat(struct thread *td, char *path, enum uio_seg pathseg, 93 struct stat *sbp) 94 { 95 96 return (linux_kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path, 97 pathseg, sbp)); 98 } 99 100 /* 101 * XXX: This was removed from newstat_copyout(), and almost identical 102 * XXX: code was in stat64_copyout(). findcdev() needs to be replaced 103 * XXX: with something that does lookup and locking properly. 104 * XXX: When somebody fixes this: please try to avoid duplicating it. 105 */ 106 #if 0 107 static void 108 disk_foo(struct somestat *tbuf) 109 { 110 struct cdevsw *cdevsw; 111 struct cdev *dev; 112 113 /* Lie about disk drives which are character devices 114 * in FreeBSD but block devices under Linux. 115 */ 116 if (S_ISCHR(tbuf.st_mode) && 117 (dev = findcdev(buf->st_rdev)) != NULL) { 118 cdevsw = dev_refthread(dev); 119 if (cdevsw != NULL) { 120 if (cdevsw->d_flags & D_DISK) { 121 tbuf.st_mode &= ~S_IFMT; 122 tbuf.st_mode |= S_IFBLK; 123 124 /* XXX this may not be quite right */ 125 /* Map major number to 0 */ 126 tbuf.st_dev = minor(buf->st_dev) & 0xf; 127 tbuf.st_rdev = buf->st_rdev & 0xff; 128 } 129 dev_relthread(dev); 130 } 131 } 132 133 } 134 #endif 135 136 static void 137 translate_fd_major_minor(struct thread *td, int fd, struct stat *buf) 138 { 139 struct file *fp; 140 struct vnode *vp; 141 int major, minor; 142 143 /* 144 * No capability rights required here. 145 */ 146 if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) || 147 fget(td, fd, 0, &fp) != 0) 148 return; 149 vp = fp->f_vnode; 150 if (vp != NULL && vp->v_rdev != NULL && 151 linux_driver_get_major_minor(devtoname(vp->v_rdev), 152 &major, &minor) == 0) { 153 buf->st_rdev = (major << 8 | minor); 154 } else if (fp->f_type == DTYPE_PTS) { 155 struct tty *tp = fp->f_data; 156 157 /* Convert the numbers for the slave device. */ 158 if (linux_driver_get_major_minor(devtoname(tp->t_dev), 159 &major, &minor) == 0) { 160 buf->st_rdev = (major << 8 | minor); 161 } 162 } 163 fdrop(fp, td); 164 } 165 166 static int 167 newstat_copyout(struct stat *buf, void *ubuf) 168 { 169 struct l_newstat tbuf; 170 171 bzero(&tbuf, sizeof(tbuf)); 172 tbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8); 173 tbuf.st_ino = buf->st_ino; 174 tbuf.st_mode = buf->st_mode; 175 tbuf.st_nlink = buf->st_nlink; 176 tbuf.st_uid = buf->st_uid; 177 tbuf.st_gid = buf->st_gid; 178 tbuf.st_rdev = buf->st_rdev; 179 tbuf.st_size = buf->st_size; 180 tbuf.st_atim.tv_sec = buf->st_atim.tv_sec; 181 tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; 182 tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; 183 tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; 184 tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; 185 tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; 186 tbuf.st_blksize = buf->st_blksize; 187 tbuf.st_blocks = buf->st_blocks; 188 189 return (copyout(&tbuf, ubuf, sizeof(tbuf))); 190 } 191 192 int 193 linux_newstat(struct thread *td, struct linux_newstat_args *args) 194 { 195 struct stat buf; 196 char *path; 197 int error; 198 199 LCONVPATHEXIST(td, args->path, &path); 200 201 #ifdef DEBUG 202 if (ldebug(newstat)) 203 printf(ARGS(newstat, "%s, *"), path); 204 #endif 205 206 error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); 207 LFREEPATH(path); 208 if (error) 209 return (error); 210 return (newstat_copyout(&buf, args->buf)); 211 } 212 213 int 214 linux_newlstat(struct thread *td, struct linux_newlstat_args *args) 215 { 216 struct stat sb; 217 char *path; 218 int error; 219 220 LCONVPATHEXIST(td, args->path, &path); 221 222 #ifdef DEBUG 223 if (ldebug(newlstat)) 224 printf(ARGS(newlstat, "%s, *"), path); 225 #endif 226 227 error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb); 228 LFREEPATH(path); 229 if (error) 230 return (error); 231 return (newstat_copyout(&sb, args->buf)); 232 } 233 234 int 235 linux_newfstat(struct thread *td, struct linux_newfstat_args *args) 236 { 237 struct stat buf; 238 int error; 239 240 #ifdef DEBUG 241 if (ldebug(newfstat)) 242 printf(ARGS(newfstat, "%d, *"), args->fd); 243 #endif 244 245 error = kern_fstat(td, args->fd, &buf); 246 translate_fd_major_minor(td, args->fd, &buf); 247 if (!error) 248 error = newstat_copyout(&buf, args->buf); 249 250 return (error); 251 } 252 253 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 254 static int 255 stat_copyout(struct stat *buf, void *ubuf) 256 { 257 struct l_stat lbuf; 258 259 bzero(&lbuf, sizeof(lbuf)); 260 lbuf.st_dev = buf->st_dev; 261 lbuf.st_ino = buf->st_ino; 262 lbuf.st_mode = buf->st_mode; 263 lbuf.st_nlink = buf->st_nlink; 264 lbuf.st_uid = buf->st_uid; 265 lbuf.st_gid = buf->st_gid; 266 lbuf.st_rdev = buf->st_rdev; 267 if (buf->st_size < (quad_t)1 << 32) 268 lbuf.st_size = buf->st_size; 269 else 270 lbuf.st_size = -2; 271 lbuf.st_atim.tv_sec = buf->st_atim.tv_sec; 272 lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; 273 lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; 274 lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; 275 lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; 276 lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; 277 lbuf.st_blksize = buf->st_blksize; 278 lbuf.st_blocks = buf->st_blocks; 279 lbuf.st_flags = buf->st_flags; 280 lbuf.st_gen = buf->st_gen; 281 282 return (copyout(&lbuf, ubuf, sizeof(lbuf))); 283 } 284 285 int 286 linux_stat(struct thread *td, struct linux_stat_args *args) 287 { 288 struct stat buf; 289 char *path; 290 int error; 291 292 LCONVPATHEXIST(td, args->path, &path); 293 294 #ifdef DEBUG 295 if (ldebug(stat)) 296 printf(ARGS(stat, "%s, *"), path); 297 #endif 298 error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); 299 if (error) { 300 LFREEPATH(path); 301 return (error); 302 } 303 LFREEPATH(path); 304 return(stat_copyout(&buf, args->up)); 305 } 306 307 int 308 linux_lstat(struct thread *td, struct linux_lstat_args *args) 309 { 310 struct stat buf; 311 char *path; 312 int error; 313 314 LCONVPATHEXIST(td, args->path, &path); 315 316 #ifdef DEBUG 317 if (ldebug(lstat)) 318 printf(ARGS(lstat, "%s, *"), path); 319 #endif 320 error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf); 321 if (error) { 322 LFREEPATH(path); 323 return (error); 324 } 325 LFREEPATH(path); 326 return(stat_copyout(&buf, args->up)); 327 } 328 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 329 330 struct l_statfs { 331 l_long f_type; 332 l_long f_bsize; 333 l_long f_blocks; 334 l_long f_bfree; 335 l_long f_bavail; 336 l_long f_files; 337 l_long f_ffree; 338 l_fsid_t f_fsid; 339 l_long f_namelen; 340 l_long f_spare[6]; 341 }; 342 343 #define LINUX_CODA_SUPER_MAGIC 0x73757245L 344 #define LINUX_EXT2_SUPER_MAGIC 0xEF53L 345 #define LINUX_HPFS_SUPER_MAGIC 0xf995e849L 346 #define LINUX_ISOFS_SUPER_MAGIC 0x9660L 347 #define LINUX_MSDOS_SUPER_MAGIC 0x4d44L 348 #define LINUX_NCP_SUPER_MAGIC 0x564cL 349 #define LINUX_NFS_SUPER_MAGIC 0x6969L 350 #define LINUX_NTFS_SUPER_MAGIC 0x5346544EL 351 #define LINUX_PROC_SUPER_MAGIC 0x9fa0L 352 #define LINUX_UFS_SUPER_MAGIC 0x00011954L /* XXX - UFS_MAGIC in Linux */ 353 #define LINUX_DEVFS_SUPER_MAGIC 0x1373L 354 #define LINUX_SHMFS_MAGIC 0x01021994 355 356 static long 357 bsd_to_linux_ftype(const char *fstypename) 358 { 359 int i; 360 static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = { 361 {"ufs", LINUX_UFS_SUPER_MAGIC}, 362 {"cd9660", LINUX_ISOFS_SUPER_MAGIC}, 363 {"nfs", LINUX_NFS_SUPER_MAGIC}, 364 {"ext2fs", LINUX_EXT2_SUPER_MAGIC}, 365 {"procfs", LINUX_PROC_SUPER_MAGIC}, 366 {"msdosfs", LINUX_MSDOS_SUPER_MAGIC}, 367 {"ntfs", LINUX_NTFS_SUPER_MAGIC}, 368 {"nwfs", LINUX_NCP_SUPER_MAGIC}, 369 {"hpfs", LINUX_HPFS_SUPER_MAGIC}, 370 {"coda", LINUX_CODA_SUPER_MAGIC}, 371 {"devfs", LINUX_DEVFS_SUPER_MAGIC}, 372 {"tmpfs", LINUX_SHMFS_MAGIC}, 373 {NULL, 0L}}; 374 375 for (i = 0; b2l_tbl[i].bsd_name != NULL; i++) 376 if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0) 377 return (b2l_tbl[i].linux_type); 378 379 return (0L); 380 } 381 382 static void 383 bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs) 384 { 385 386 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 387 linux_statfs->f_bsize = bsd_statfs->f_bsize; 388 linux_statfs->f_blocks = bsd_statfs->f_blocks; 389 linux_statfs->f_bfree = bsd_statfs->f_bfree; 390 linux_statfs->f_bavail = bsd_statfs->f_bavail; 391 linux_statfs->f_ffree = bsd_statfs->f_ffree; 392 linux_statfs->f_files = bsd_statfs->f_files; 393 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 394 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 395 linux_statfs->f_namelen = MAXNAMLEN; 396 } 397 398 int 399 linux_statfs(struct thread *td, struct linux_statfs_args *args) 400 { 401 struct l_statfs linux_statfs; 402 struct statfs bsd_statfs; 403 char *path; 404 int error; 405 406 LCONVPATHEXIST(td, args->path, &path); 407 408 #ifdef DEBUG 409 if (ldebug(statfs)) 410 printf(ARGS(statfs, "%s, *"), path); 411 #endif 412 error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 413 LFREEPATH(path); 414 if (error) 415 return (error); 416 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 417 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 418 } 419 420 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 421 static void 422 bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs) 423 { 424 425 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 426 linux_statfs->f_bsize = bsd_statfs->f_bsize; 427 linux_statfs->f_blocks = bsd_statfs->f_blocks; 428 linux_statfs->f_bfree = bsd_statfs->f_bfree; 429 linux_statfs->f_bavail = bsd_statfs->f_bavail; 430 linux_statfs->f_ffree = bsd_statfs->f_ffree; 431 linux_statfs->f_files = bsd_statfs->f_files; 432 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 433 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 434 linux_statfs->f_namelen = MAXNAMLEN; 435 } 436 437 int 438 linux_statfs64(struct thread *td, struct linux_statfs64_args *args) 439 { 440 struct l_statfs64 linux_statfs; 441 struct statfs bsd_statfs; 442 char *path; 443 int error; 444 445 if (args->bufsize != sizeof(struct l_statfs64)) 446 return EINVAL; 447 448 LCONVPATHEXIST(td, args->path, &path); 449 450 #ifdef DEBUG 451 if (ldebug(statfs64)) 452 printf(ARGS(statfs64, "%s, *"), path); 453 #endif 454 error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 455 LFREEPATH(path); 456 if (error) 457 return (error); 458 bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); 459 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 460 } 461 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 462 463 int 464 linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) 465 { 466 struct l_statfs linux_statfs; 467 struct statfs bsd_statfs; 468 int error; 469 470 #ifdef DEBUG 471 if (ldebug(fstatfs)) 472 printf(ARGS(fstatfs, "%d, *"), args->fd); 473 #endif 474 error = kern_fstatfs(td, args->fd, &bsd_statfs); 475 if (error) 476 return error; 477 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 478 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 479 } 480 481 struct l_ustat 482 { 483 l_daddr_t f_tfree; 484 l_ino_t f_tinode; 485 char f_fname[6]; 486 char f_fpack[6]; 487 }; 488 489 int 490 linux_ustat(struct thread *td, struct linux_ustat_args *args) 491 { 492 #ifdef DEBUG 493 if (ldebug(ustat)) 494 printf(ARGS(ustat, "%ju, *"), (uintmax_t)args->dev); 495 #endif 496 497 return (EOPNOTSUPP); 498 } 499 500 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 501 502 static int 503 stat64_copyout(struct stat *buf, void *ubuf) 504 { 505 struct l_stat64 lbuf; 506 507 bzero(&lbuf, sizeof(lbuf)); 508 lbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8); 509 lbuf.st_ino = buf->st_ino; 510 lbuf.st_mode = buf->st_mode; 511 lbuf.st_nlink = buf->st_nlink; 512 lbuf.st_uid = buf->st_uid; 513 lbuf.st_gid = buf->st_gid; 514 lbuf.st_rdev = buf->st_rdev; 515 lbuf.st_size = buf->st_size; 516 lbuf.st_atim.tv_sec = buf->st_atim.tv_sec; 517 lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; 518 lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; 519 lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; 520 lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; 521 lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; 522 lbuf.st_blksize = buf->st_blksize; 523 lbuf.st_blocks = buf->st_blocks; 524 525 /* 526 * The __st_ino field makes all the difference. In the Linux kernel 527 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO, 528 * but without the assignment to __st_ino the runtime linker refuses 529 * to mmap(2) any shared libraries. I guess it's broken alright :-) 530 */ 531 lbuf.__st_ino = buf->st_ino; 532 533 return (copyout(&lbuf, ubuf, sizeof(lbuf))); 534 } 535 536 int 537 linux_stat64(struct thread *td, struct linux_stat64_args *args) 538 { 539 struct stat buf; 540 char *filename; 541 int error; 542 543 LCONVPATHEXIST(td, args->filename, &filename); 544 545 #ifdef DEBUG 546 if (ldebug(stat64)) 547 printf(ARGS(stat64, "%s, *"), filename); 548 #endif 549 550 error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf); 551 LFREEPATH(filename); 552 if (error) 553 return (error); 554 return (stat64_copyout(&buf, args->statbuf)); 555 } 556 557 int 558 linux_lstat64(struct thread *td, struct linux_lstat64_args *args) 559 { 560 struct stat sb; 561 char *filename; 562 int error; 563 564 LCONVPATHEXIST(td, args->filename, &filename); 565 566 #ifdef DEBUG 567 if (ldebug(lstat64)) 568 printf(ARGS(lstat64, "%s, *"), args->filename); 569 #endif 570 571 error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb); 572 LFREEPATH(filename); 573 if (error) 574 return (error); 575 return (stat64_copyout(&sb, args->statbuf)); 576 } 577 578 int 579 linux_fstat64(struct thread *td, struct linux_fstat64_args *args) 580 { 581 struct stat buf; 582 int error; 583 584 #ifdef DEBUG 585 if (ldebug(fstat64)) 586 printf(ARGS(fstat64, "%d, *"), args->fd); 587 #endif 588 589 error = kern_fstat(td, args->fd, &buf); 590 translate_fd_major_minor(td, args->fd, &buf); 591 if (!error) 592 error = stat64_copyout(&buf, args->statbuf); 593 594 return (error); 595 } 596 597 int 598 linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) 599 { 600 char *path; 601 int error, dfd, flag; 602 struct stat buf; 603 604 if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW) 605 return (EINVAL); 606 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? 607 AT_SYMLINK_NOFOLLOW : 0; 608 609 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; 610 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd); 611 612 #ifdef DEBUG 613 if (ldebug(fstatat64)) 614 printf(ARGS(fstatat64, "%i, %s, %i"), args->dfd, path, args->flag); 615 #endif 616 617 error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); 618 if (!error) 619 error = stat64_copyout(&buf, args->statbuf); 620 LFREEPATH(path); 621 622 return (error); 623 } 624 625 #else /* __amd64__ && !COMPAT_LINUX32 */ 626 627 int 628 linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args) 629 { 630 char *path; 631 int error, dfd, flag; 632 struct stat buf; 633 634 if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW) 635 return (EINVAL); 636 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? 637 AT_SYMLINK_NOFOLLOW : 0; 638 639 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; 640 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd); 641 642 #ifdef DEBUG 643 if (ldebug(newfstatat)) 644 printf(ARGS(newfstatat, "%i, %s, %i"), args->dfd, path, args->flag); 645 #endif 646 647 error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); 648 if (error == 0) 649 error = newstat_copyout(&buf, args->statbuf); 650 LFREEPATH(path); 651 652 return (error); 653 } 654 655 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 656