1c21dee17SSøren Schmidt /*- 2c21dee17SSøren Schmidt * Copyright (c) 1994-1995 S�ren Schmidt 3c21dee17SSøren Schmidt * All rights reserved. 4c21dee17SSøren Schmidt * 5c21dee17SSøren Schmidt * Redistribution and use in source and binary forms, with or without 6c21dee17SSøren Schmidt * modification, are permitted provided that the following conditions 7c21dee17SSøren Schmidt * are met: 8c21dee17SSøren Schmidt * 1. Redistributions of source code must retain the above copyright 9c21dee17SSøren Schmidt * notice, this list of conditions and the following disclaimer 10c21dee17SSøren Schmidt * in this position and unchanged. 11c21dee17SSøren Schmidt * 2. Redistributions in binary form must reproduce the above copyright 12c21dee17SSøren Schmidt * notice, this list of conditions and the following disclaimer in the 13c21dee17SSøren Schmidt * documentation and/or other materials provided with the distribution. 14c21dee17SSøren Schmidt * 3. The name of the author may not be used to endorse or promote products 1521dc7d4fSJens Schweikhardt * derived from this software without specific prior written permission 16c21dee17SSøren Schmidt * 17c21dee17SSøren Schmidt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18c21dee17SSøren Schmidt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19c21dee17SSøren Schmidt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20c21dee17SSøren Schmidt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21c21dee17SSøren Schmidt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22c21dee17SSøren Schmidt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23c21dee17SSøren Schmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24c21dee17SSøren Schmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25c21dee17SSøren Schmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26c21dee17SSøren Schmidt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27c21dee17SSøren Schmidt */ 28c21dee17SSøren Schmidt 2916dbc7f2SDavid E. O'Brien #include <sys/cdefs.h> 3016dbc7f2SDavid E. O'Brien __FBSDID("$FreeBSD$"); 3116dbc7f2SDavid E. O'Brien 32aefce619SRuslan Ermilov #include "opt_compat.h" 33eddc160eSRobert Watson #include "opt_mac.h" 34eddc160eSRobert Watson 35c21dee17SSøren Schmidt #include <sys/param.h> 36c21dee17SSøren Schmidt #include <sys/dirent.h> 37c21dee17SSøren Schmidt #include <sys/file.h> 38c21dee17SSøren Schmidt #include <sys/filedesc.h> 39c21dee17SSøren Schmidt #include <sys/proc.h> 40672d95c5SPawel Jakub Dawidek #include <sys/jail.h> 41eddc160eSRobert Watson #include <sys/mac.h> 4285422e62SBruce Evans #include <sys/malloc.h> 43c21dee17SSøren Schmidt #include <sys/mount.h> 44c21dee17SSøren Schmidt #include <sys/namei.h> 45c21dee17SSøren Schmidt #include <sys/stat.h> 46f7a25872SJohn Baldwin #include <sys/syscallsubr.h> 47408da119SMarcel Moolenaar #include <sys/systm.h> 48c21dee17SSøren Schmidt #include <sys/vnode.h> 49060e4882SDoug Ambrisko #include <sys/conf.h> 50060e4882SDoug Ambrisko #include <sys/fcntl.h> 51c21dee17SSøren Schmidt 521997c537SDavid E. O'Brien #ifdef COMPAT_LINUX32 534af27623STim J. Robbins #include <machine/../linux32/linux.h> 544af27623STim J. Robbins #include <machine/../linux32/linux32_proto.h> 551997c537SDavid E. O'Brien #else 561997c537SDavid E. O'Brien #include <machine/../linux/linux.h> 571997c537SDavid E. O'Brien #include <machine/../linux/linux_proto.h> 584af27623STim J. Robbins #endif 5985422e62SBruce Evans 60ac951e62SMarcel Moolenaar #include <compat/linux/linux_util.h> 61762e6b85SEivind Eklund 62bbbc2d96SPoul-Henning Kamp /* 63bbbc2d96SPoul-Henning Kamp * XXX: This was removed from newstat_copyout(), and almost identical 64bbbc2d96SPoul-Henning Kamp * XXX: code was in stat64_copyout(). findcdev() needs to be replaced 65bbbc2d96SPoul-Henning Kamp * XXX: with something that does lookup and locking properly. 66bbbc2d96SPoul-Henning Kamp * XXX: When somebody fixes this: please try to avoid duplicating it. 67bbbc2d96SPoul-Henning Kamp */ 68bbbc2d96SPoul-Henning Kamp #if 0 69bbbc2d96SPoul-Henning Kamp static void 70bbbc2d96SPoul-Henning Kamp disk_foo(struct somestat *tbuf) 71c21dee17SSøren Schmidt { 724c3a3ec0SJosef Karthauser struct cdevsw *cdevsw; 7389c9c53dSPoul-Henning Kamp struct cdev *dev; 74c21dee17SSøren Schmidt 754c3a3ec0SJosef Karthauser /* Lie about disk drives which are character devices 764c3a3ec0SJosef Karthauser * in FreeBSD but block devices under Linux. 774c3a3ec0SJosef Karthauser */ 785002a60fSMarcel Moolenaar if (S_ISCHR(tbuf.st_mode) && 79f3732fd1SPoul-Henning Kamp (dev = findcdev(buf->st_rdev)) != NULL) { 80f69f5fbdSPoul-Henning Kamp cdevsw = dev_refthread(dev); 81f69f5fbdSPoul-Henning Kamp if (cdevsw != NULL) { 82f69f5fbdSPoul-Henning Kamp if (cdevsw->d_flags & D_DISK) { 835002a60fSMarcel Moolenaar tbuf.st_mode &= ~S_IFMT; 845002a60fSMarcel Moolenaar tbuf.st_mode |= S_IFBLK; 857842f151SPaul Richards 867842f151SPaul Richards /* XXX this may not be quite right */ 877842f151SPaul Richards /* Map major number to 0 */ 885002a60fSMarcel Moolenaar tbuf.st_dev = uminor(buf->st_dev) & 0xf; 895002a60fSMarcel Moolenaar tbuf.st_rdev = buf->st_rdev & 0xff; 907842f151SPaul Richards } 91f69f5fbdSPoul-Henning Kamp dev_relthread(dev); 92f69f5fbdSPoul-Henning Kamp } 934c3a3ec0SJosef Karthauser } 944e0eaf69SMarcel Moolenaar 95bbbc2d96SPoul-Henning Kamp } 96bbbc2d96SPoul-Henning Kamp #endif 97bbbc2d96SPoul-Henning Kamp 98060e4882SDoug Ambrisko static void 99060e4882SDoug Ambrisko translate_fd_major_minor(struct thread *td, int fd, struct stat *buf) 100060e4882SDoug Ambrisko { 101060e4882SDoug Ambrisko struct file *fp; 102060e4882SDoug Ambrisko int error; 103060e4882SDoug Ambrisko int major, minor; 104060e4882SDoug Ambrisko 105060e4882SDoug Ambrisko if ((error = fget(td, fd, &fp)) != 0) 106060e4882SDoug Ambrisko return; 107060e4882SDoug Ambrisko if (fp->f_vnode) { 108060e4882SDoug Ambrisko if (fp->f_vnode->v_type == VCHR 109060e4882SDoug Ambrisko || fp->f_vnode->v_type == VBLK) { 110060e4882SDoug Ambrisko if (fp->f_vnode->v_un.vu_cdev) { 111060e4882SDoug Ambrisko if (linux_driver_get_major_minor( 112060e4882SDoug Ambrisko fp->f_vnode->v_un.vu_cdev->si_name, 113060e4882SDoug Ambrisko &major, &minor) == 0) { 114060e4882SDoug Ambrisko buf->st_rdev = (major << 8 | minor); 115060e4882SDoug Ambrisko } 116060e4882SDoug Ambrisko } 117060e4882SDoug Ambrisko } 118060e4882SDoug Ambrisko } 119060e4882SDoug Ambrisko fdrop(fp, td); 120060e4882SDoug Ambrisko } 121060e4882SDoug Ambrisko 122060e4882SDoug Ambrisko static void 123060e4882SDoug Ambrisko translate_path_major_minor(struct thread *td, char *path, struct stat *buf) 124060e4882SDoug Ambrisko { 125edb75ecaSDoug Ambrisko struct proc *p = td->td_proc; 126edb75ecaSDoug Ambrisko struct filedesc *fdp = p->p_fd; 127060e4882SDoug Ambrisko struct file *fp; 128060e4882SDoug Ambrisko int fd; 129060e4882SDoug Ambrisko int temp; 130060e4882SDoug Ambrisko 131060e4882SDoug Ambrisko temp = td->td_retval[0]; 132060e4882SDoug Ambrisko if (kern_open(td, path, UIO_SYSSPACE, O_RDONLY, 0) != 0) 133060e4882SDoug Ambrisko return; 134060e4882SDoug Ambrisko fd = td->td_retval[0]; 135060e4882SDoug Ambrisko td->td_retval[0] = temp; 136060e4882SDoug Ambrisko translate_fd_major_minor(td, fd, buf); 137edb75ecaSDoug Ambrisko FILEDESC_LOCK(fdp); 138edb75ecaSDoug Ambrisko fp = fdp->fd_ofiles[fd]; 139edb75ecaSDoug Ambrisko FILEDESC_UNLOCK(fdp); 140edb75ecaSDoug Ambrisko fdclose(fdp, fdp->fd_ofiles[fd], fd, td); 141060e4882SDoug Ambrisko } 142060e4882SDoug Ambrisko 143bbbc2d96SPoul-Henning Kamp static int 144bbbc2d96SPoul-Henning Kamp newstat_copyout(struct stat *buf, void *ubuf) 145bbbc2d96SPoul-Henning Kamp { 146bbbc2d96SPoul-Henning Kamp struct l_newstat tbuf; 147bbbc2d96SPoul-Henning Kamp 148bbbc2d96SPoul-Henning Kamp bzero(&tbuf, sizeof(tbuf)); 149bbbc2d96SPoul-Henning Kamp tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 150bbbc2d96SPoul-Henning Kamp tbuf.st_ino = buf->st_ino; 151bbbc2d96SPoul-Henning Kamp tbuf.st_mode = buf->st_mode; 152bbbc2d96SPoul-Henning Kamp tbuf.st_nlink = buf->st_nlink; 153bbbc2d96SPoul-Henning Kamp tbuf.st_uid = buf->st_uid; 154bbbc2d96SPoul-Henning Kamp tbuf.st_gid = buf->st_gid; 155bbbc2d96SPoul-Henning Kamp tbuf.st_rdev = buf->st_rdev; 156bbbc2d96SPoul-Henning Kamp tbuf.st_size = buf->st_size; 157bbbc2d96SPoul-Henning Kamp tbuf.st_atime = buf->st_atime; 158bbbc2d96SPoul-Henning Kamp tbuf.st_mtime = buf->st_mtime; 159bbbc2d96SPoul-Henning Kamp tbuf.st_ctime = buf->st_ctime; 160bbbc2d96SPoul-Henning Kamp tbuf.st_blksize = buf->st_blksize; 161bbbc2d96SPoul-Henning Kamp tbuf.st_blocks = buf->st_blocks; 162bbbc2d96SPoul-Henning Kamp 1634e0eaf69SMarcel Moolenaar return (copyout(&tbuf, ubuf, sizeof(tbuf))); 164c21dee17SSøren Schmidt } 165c21dee17SSøren Schmidt 166c21dee17SSøren Schmidt int 167b40ce416SJulian Elischer linux_newstat(struct thread *td, struct linux_newstat_args *args) 168c21dee17SSøren Schmidt { 169c21dee17SSøren Schmidt struct stat buf; 170206a5d3aSIan Dowse char *path; 171c21dee17SSøren Schmidt int error; 172d66a5066SPeter Wemm 173206a5d3aSIan Dowse LCONVPATHEXIST(td, args->path, &path); 174c21dee17SSøren Schmidt 175c21dee17SSøren Schmidt #ifdef DEBUG 17624593369SJonathan Lemon if (ldebug(newstat)) 177206a5d3aSIan Dowse printf(ARGS(newstat, "%s, *"), path); 178c21dee17SSøren Schmidt #endif 1794e0eaf69SMarcel Moolenaar 180f7a25872SJohn Baldwin error = kern_stat(td, path, UIO_SYSSPACE, &buf); 181e83d253bSOlivier Houchard if (!error && strlen(path) > strlen("/dev/pts/") && 182e83d253bSOlivier Houchard !strncmp(path, "/dev/pts/", strlen("/dev/pts/")) 183e83d253bSOlivier Houchard && path[9] >= '0' && path[9] <= '9') { 184e83d253bSOlivier Houchard /* 185e83d253bSOlivier Houchard * Linux checks major and minors of the slave device to make 186d425dbecSOlivier Houchard * sure it's a pty device, so let's make him believe it is. 187e83d253bSOlivier Houchard */ 188e83d253bSOlivier Houchard buf.st_rdev = (136 << 8); 189e83d253bSOlivier Houchard } 190e83d253bSOlivier Houchard 191060e4882SDoug Ambrisko translate_path_major_minor(td, path, &buf); 192060e4882SDoug Ambrisko 193206a5d3aSIan Dowse LFREEPATH(path); 1944e0eaf69SMarcel Moolenaar if (error) 1954e0eaf69SMarcel Moolenaar return (error); 1964e0eaf69SMarcel Moolenaar return (newstat_copyout(&buf, args->buf)); 197c21dee17SSøren Schmidt } 198c21dee17SSøren Schmidt 199c21dee17SSøren Schmidt int 200b40ce416SJulian Elischer linux_newlstat(struct thread *td, struct linux_newlstat_args *args) 201c21dee17SSøren Schmidt { 2024e0eaf69SMarcel Moolenaar struct stat sb; 203206a5d3aSIan Dowse char *path; 204f7a25872SJohn Baldwin int error; 205d66a5066SPeter Wemm 206206a5d3aSIan Dowse LCONVPATHEXIST(td, args->path, &path); 207c21dee17SSøren Schmidt 208c21dee17SSøren Schmidt #ifdef DEBUG 20924593369SJonathan Lemon if (ldebug(newlstat)) 210206a5d3aSIan Dowse printf(ARGS(newlstat, "%s, *"), path); 211c21dee17SSøren Schmidt #endif 2124e0eaf69SMarcel Moolenaar 213f7a25872SJohn Baldwin error = kern_lstat(td, path, UIO_SYSSPACE, &sb); 214060e4882SDoug Ambrisko translate_path_major_minor(td, path, &sb); 215206a5d3aSIan Dowse LFREEPATH(path); 216d66a5066SPeter Wemm if (error) 217d66a5066SPeter Wemm return (error); 2185002a60fSMarcel Moolenaar return (newstat_copyout(&sb, args->buf)); 219d66a5066SPeter Wemm } 220c21dee17SSøren Schmidt 221c21dee17SSøren Schmidt int 222b40ce416SJulian Elischer linux_newfstat(struct thread *td, struct linux_newfstat_args *args) 223c21dee17SSøren Schmidt { 224c21dee17SSøren Schmidt struct stat buf; 225c21dee17SSøren Schmidt int error; 226c21dee17SSøren Schmidt 227c21dee17SSøren Schmidt #ifdef DEBUG 22824593369SJonathan Lemon if (ldebug(newfstat)) 22924593369SJonathan Lemon printf(ARGS(newfstat, "%d, *"), args->fd); 230c21dee17SSøren Schmidt #endif 2314e0eaf69SMarcel Moolenaar 232f7a25872SJohn Baldwin error = kern_fstat(td, args->fd, &buf); 233060e4882SDoug Ambrisko translate_fd_major_minor(td, args->fd, &buf); 234c21dee17SSøren Schmidt if (!error) 235c21dee17SSøren Schmidt error = newstat_copyout(&buf, args->buf); 2364e0eaf69SMarcel Moolenaar 2374e0eaf69SMarcel Moolenaar return (error); 238c21dee17SSøren Schmidt } 239c21dee17SSøren Schmidt 2405c8919adSAlexander Leidinger static int 2415c8919adSAlexander Leidinger stat_copyout(struct stat *buf, void *ubuf) 2425c8919adSAlexander Leidinger { 2435c8919adSAlexander Leidinger struct l_stat lbuf; 2445c8919adSAlexander Leidinger 2455c8919adSAlexander Leidinger bzero(&lbuf, sizeof(lbuf)); 2465c8919adSAlexander Leidinger lbuf.st_dev = buf->st_dev; 2475c8919adSAlexander Leidinger lbuf.st_ino = buf->st_ino; 2485c8919adSAlexander Leidinger lbuf.st_mode = buf->st_mode; 2495c8919adSAlexander Leidinger lbuf.st_nlink = buf->st_nlink; 2505c8919adSAlexander Leidinger lbuf.st_uid = buf->st_uid; 2515c8919adSAlexander Leidinger lbuf.st_gid = buf->st_gid; 2525c8919adSAlexander Leidinger lbuf.st_rdev = buf->st_rdev; 2535c8919adSAlexander Leidinger if (buf->st_size < (quad_t)1 << 32) 2545c8919adSAlexander Leidinger lbuf.st_size = buf->st_size; 2555c8919adSAlexander Leidinger else 2565c8919adSAlexander Leidinger lbuf.st_size = -2; 2575c8919adSAlexander Leidinger lbuf.st_atime = buf->st_atime; 2585c8919adSAlexander Leidinger lbuf.st_mtime = buf->st_mtime; 2595c8919adSAlexander Leidinger lbuf.st_ctime = buf->st_ctime; 2605c8919adSAlexander Leidinger lbuf.st_blksize = buf->st_blksize; 2615c8919adSAlexander Leidinger lbuf.st_blocks = buf->st_blocks; 2625c8919adSAlexander Leidinger lbuf.st_flags = buf->st_flags; 2635c8919adSAlexander Leidinger lbuf.st_gen = buf->st_gen; 2645c8919adSAlexander Leidinger 2655c8919adSAlexander Leidinger return (copyout(&lbuf, ubuf, sizeof(lbuf))); 2665c8919adSAlexander Leidinger } 2675c8919adSAlexander Leidinger 2685c8919adSAlexander Leidinger int 2695c8919adSAlexander Leidinger linux_stat(struct thread *td, struct linux_stat_args *args) 2705c8919adSAlexander Leidinger { 2715c8919adSAlexander Leidinger struct stat buf; 2725c8919adSAlexander Leidinger int error; 2735c8919adSAlexander Leidinger #ifdef DEBUG 2745c8919adSAlexander Leidinger if (ldebug(stat)) 2755c8919adSAlexander Leidinger printf(ARGS(stat, "%s, *"), args->path); 2765c8919adSAlexander Leidinger #endif 2775c8919adSAlexander Leidinger error = kern_stat(td, args->path, UIO_SYSSPACE, &buf); 2785c8919adSAlexander Leidinger if (error) 2795c8919adSAlexander Leidinger return (error); 280060e4882SDoug Ambrisko translate_path_major_minor(td, args->path, &buf); 2815c8919adSAlexander Leidinger return(stat_copyout(&buf, args->up)); 2825c8919adSAlexander Leidinger } 2835c8919adSAlexander Leidinger 2845c8919adSAlexander Leidinger int 2855c8919adSAlexander Leidinger linux_lstat(struct thread *td, struct linux_lstat_args *args) 2865c8919adSAlexander Leidinger { 2875c8919adSAlexander Leidinger struct stat buf; 2885c8919adSAlexander Leidinger int error; 2895c8919adSAlexander Leidinger 2905c8919adSAlexander Leidinger #ifdef DEBUG 2915c8919adSAlexander Leidinger if (ldebug(lstat)) 2925c8919adSAlexander Leidinger printf(ARGS(lstat, "%s, *"), args->path); 2935c8919adSAlexander Leidinger #endif 2945c8919adSAlexander Leidinger error = kern_lstat(td, args->path, UIO_SYSSPACE, &buf); 2955c8919adSAlexander Leidinger if (error) 2965c8919adSAlexander Leidinger return (error); 297060e4882SDoug Ambrisko translate_path_major_minor(td, args->path, &buf); 2985c8919adSAlexander Leidinger return(stat_copyout(&buf, args->up)); 2995c8919adSAlexander Leidinger } 3005c8919adSAlexander Leidinger 3015002a60fSMarcel Moolenaar /* XXX - All fields of type l_int are defined as l_long on i386 */ 3025002a60fSMarcel Moolenaar struct l_statfs { 3035002a60fSMarcel Moolenaar l_int f_type; 3045002a60fSMarcel Moolenaar l_int f_bsize; 3055002a60fSMarcel Moolenaar l_int f_blocks; 3065002a60fSMarcel Moolenaar l_int f_bfree; 3075002a60fSMarcel Moolenaar l_int f_bavail; 3085002a60fSMarcel Moolenaar l_int f_files; 3095002a60fSMarcel Moolenaar l_int f_ffree; 3105002a60fSMarcel Moolenaar l_fsid_t f_fsid; 3115002a60fSMarcel Moolenaar l_int f_namelen; 3125002a60fSMarcel Moolenaar l_int f_spare[6]; 313c21dee17SSøren Schmidt }; 314c21dee17SSøren Schmidt 315835e5061SAlexander Leidinger struct l_statfs64 { 316835e5061SAlexander Leidinger l_int f_type; 317835e5061SAlexander Leidinger l_int f_bsize; 318835e5061SAlexander Leidinger uint64_t f_blocks; 319835e5061SAlexander Leidinger uint64_t f_bfree; 320835e5061SAlexander Leidinger uint64_t f_bavail; 321835e5061SAlexander Leidinger uint64_t f_files; 322835e5061SAlexander Leidinger uint64_t f_ffree; 323835e5061SAlexander Leidinger l_fsid_t f_fsid; 324835e5061SAlexander Leidinger l_int f_namelen; 325835e5061SAlexander Leidinger l_int f_spare[6]; 326835e5061SAlexander Leidinger }; 327835e5061SAlexander Leidinger 328dca60efcSMarcel Moolenaar #define LINUX_CODA_SUPER_MAGIC 0x73757245L 329dca60efcSMarcel Moolenaar #define LINUX_EXT2_SUPER_MAGIC 0xEF53L 330dca60efcSMarcel Moolenaar #define LINUX_HPFS_SUPER_MAGIC 0xf995e849L 331dca60efcSMarcel Moolenaar #define LINUX_ISOFS_SUPER_MAGIC 0x9660L 332dca60efcSMarcel Moolenaar #define LINUX_MSDOS_SUPER_MAGIC 0x4d44L 333dca60efcSMarcel Moolenaar #define LINUX_NCP_SUPER_MAGIC 0x564cL 334dca60efcSMarcel Moolenaar #define LINUX_NFS_SUPER_MAGIC 0x6969L 335dca60efcSMarcel Moolenaar #define LINUX_NTFS_SUPER_MAGIC 0x5346544EL 336dca60efcSMarcel Moolenaar #define LINUX_PROC_SUPER_MAGIC 0x9fa0L 337dca60efcSMarcel Moolenaar #define LINUX_UFS_SUPER_MAGIC 0x00011954L /* XXX - UFS_MAGIC in Linux */ 338e83d253bSOlivier Houchard #define LINUX_DEVFS_SUPER_MAGIC 0x1373L 339dca60efcSMarcel Moolenaar 340dca60efcSMarcel Moolenaar static long 341962cf420SMaxim Sobolev bsd_to_linux_ftype(const char *fstypename) 342dca60efcSMarcel Moolenaar { 343962cf420SMaxim Sobolev int i; 344962cf420SMaxim Sobolev static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = { 345962cf420SMaxim Sobolev {"ufs", LINUX_UFS_SUPER_MAGIC}, 346962cf420SMaxim Sobolev {"cd9660", LINUX_ISOFS_SUPER_MAGIC}, 347962cf420SMaxim Sobolev {"nfs", LINUX_NFS_SUPER_MAGIC}, 348962cf420SMaxim Sobolev {"ext2fs", LINUX_EXT2_SUPER_MAGIC}, 349962cf420SMaxim Sobolev {"procfs", LINUX_PROC_SUPER_MAGIC}, 350962cf420SMaxim Sobolev {"msdosfs", LINUX_MSDOS_SUPER_MAGIC}, 351962cf420SMaxim Sobolev {"ntfs", LINUX_NTFS_SUPER_MAGIC}, 352962cf420SMaxim Sobolev {"nwfs", LINUX_NCP_SUPER_MAGIC}, 353962cf420SMaxim Sobolev {"hpfs", LINUX_HPFS_SUPER_MAGIC}, 354962cf420SMaxim Sobolev {"coda", LINUX_CODA_SUPER_MAGIC}, 355e83d253bSOlivier Houchard {"devfs", LINUX_DEVFS_SUPER_MAGIC}, 356962cf420SMaxim Sobolev {NULL, 0L}}; 357dca60efcSMarcel Moolenaar 358962cf420SMaxim Sobolev for (i = 0; b2l_tbl[i].bsd_name != NULL; i++) 359962cf420SMaxim Sobolev if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0) 360962cf420SMaxim Sobolev return (b2l_tbl[i].linux_type); 361dca60efcSMarcel Moolenaar 362dca60efcSMarcel Moolenaar return (0L); 363dca60efcSMarcel Moolenaar } 364dca60efcSMarcel Moolenaar 365f7a25872SJohn Baldwin static void 366d0cad55dSPawel Jakub Dawidek bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs) 367f7a25872SJohn Baldwin { 368f7a25872SJohn Baldwin 369f7a25872SJohn Baldwin linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 370f7a25872SJohn Baldwin linux_statfs->f_bsize = bsd_statfs->f_bsize; 371f7a25872SJohn Baldwin linux_statfs->f_blocks = bsd_statfs->f_blocks; 372f7a25872SJohn Baldwin linux_statfs->f_bfree = bsd_statfs->f_bfree; 373f7a25872SJohn Baldwin linux_statfs->f_bavail = bsd_statfs->f_bavail; 374f7a25872SJohn Baldwin linux_statfs->f_ffree = bsd_statfs->f_ffree; 375f7a25872SJohn Baldwin linux_statfs->f_files = bsd_statfs->f_files; 376f7a25872SJohn Baldwin linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 377f7a25872SJohn Baldwin linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 378f7a25872SJohn Baldwin linux_statfs->f_namelen = MAXNAMLEN; 379f7a25872SJohn Baldwin } 380f7a25872SJohn Baldwin 381c21dee17SSøren Schmidt int 382b40ce416SJulian Elischer linux_statfs(struct thread *td, struct linux_statfs_args *args) 383c21dee17SSøren Schmidt { 3845002a60fSMarcel Moolenaar struct l_statfs linux_statfs; 385f7a25872SJohn Baldwin struct statfs bsd_statfs; 386206a5d3aSIan Dowse char *path; 387c21dee17SSøren Schmidt int error; 388d66a5066SPeter Wemm 389206a5d3aSIan Dowse LCONVPATHEXIST(td, args->path, &path); 390c21dee17SSøren Schmidt 391c21dee17SSøren Schmidt #ifdef DEBUG 39224593369SJonathan Lemon if (ldebug(statfs)) 393206a5d3aSIan Dowse printf(ARGS(statfs, "%s, *"), path); 394c21dee17SSøren Schmidt #endif 395f7a25872SJohn Baldwin error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 396206a5d3aSIan Dowse LFREEPATH(path); 397d5558c00SPeter Wemm if (error) 398eddc160eSRobert Watson return (error); 399d0cad55dSPawel Jakub Dawidek bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 4004b7ef73dSDag-Erling Smørgrav return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 401c21dee17SSøren Schmidt } 402c21dee17SSøren Schmidt 403835e5061SAlexander Leidinger static void 404835e5061SAlexander Leidinger bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs) 405835e5061SAlexander Leidinger { 406835e5061SAlexander Leidinger 407835e5061SAlexander Leidinger linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 408835e5061SAlexander Leidinger linux_statfs->f_bsize = bsd_statfs->f_bsize; 409835e5061SAlexander Leidinger linux_statfs->f_blocks = bsd_statfs->f_blocks; 410835e5061SAlexander Leidinger linux_statfs->f_bfree = bsd_statfs->f_bfree; 411835e5061SAlexander Leidinger linux_statfs->f_bavail = bsd_statfs->f_bavail; 412835e5061SAlexander Leidinger linux_statfs->f_ffree = bsd_statfs->f_ffree; 413835e5061SAlexander Leidinger linux_statfs->f_files = bsd_statfs->f_files; 414835e5061SAlexander Leidinger linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 415835e5061SAlexander Leidinger linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 416835e5061SAlexander Leidinger linux_statfs->f_namelen = MAXNAMLEN; 417835e5061SAlexander Leidinger } 418835e5061SAlexander Leidinger 419835e5061SAlexander Leidinger int 420835e5061SAlexander Leidinger linux_statfs64(struct thread *td, struct linux_statfs64_args *args) 421835e5061SAlexander Leidinger { 422835e5061SAlexander Leidinger struct l_statfs64 linux_statfs; 423835e5061SAlexander Leidinger struct statfs bsd_statfs; 424835e5061SAlexander Leidinger char *path; 425835e5061SAlexander Leidinger int error; 426835e5061SAlexander Leidinger 427835e5061SAlexander Leidinger LCONVPATHEXIST(td, args->path, &path); 428835e5061SAlexander Leidinger 429835e5061SAlexander Leidinger #ifdef DEBUG 430835e5061SAlexander Leidinger if (ldebug(statfs64)) 431835e5061SAlexander Leidinger printf(ARGS(statfs64, "%s, *"), path); 432835e5061SAlexander Leidinger #endif 433835e5061SAlexander Leidinger error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 434835e5061SAlexander Leidinger LFREEPATH(path); 435835e5061SAlexander Leidinger if (error) 436835e5061SAlexander Leidinger return (error); 437835e5061SAlexander Leidinger bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); 438835e5061SAlexander Leidinger return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 439835e5061SAlexander Leidinger } 440835e5061SAlexander Leidinger 441c21dee17SSøren Schmidt int 442b40ce416SJulian Elischer linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) 443c21dee17SSøren Schmidt { 4445002a60fSMarcel Moolenaar struct l_statfs linux_statfs; 445f7a25872SJohn Baldwin struct statfs bsd_statfs; 446c21dee17SSøren Schmidt int error; 447c21dee17SSøren Schmidt 448c21dee17SSøren Schmidt #ifdef DEBUG 44924593369SJonathan Lemon if (ldebug(fstatfs)) 45024593369SJonathan Lemon printf(ARGS(fstatfs, "%d, *"), args->fd); 451c21dee17SSøren Schmidt #endif 452f7a25872SJohn Baldwin error = kern_fstatfs(td, args->fd, &bsd_statfs); 453d5558c00SPeter Wemm if (error) 454c21dee17SSøren Schmidt return error; 455d0cad55dSPawel Jakub Dawidek bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 456f7a25872SJohn Baldwin return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 457c21dee17SSøren Schmidt } 458408da119SMarcel Moolenaar 4595002a60fSMarcel Moolenaar struct l_ustat 460408da119SMarcel Moolenaar { 4615002a60fSMarcel Moolenaar l_daddr_t f_tfree; 4625002a60fSMarcel Moolenaar l_ino_t f_tinode; 4635002a60fSMarcel Moolenaar char f_fname[6]; 4645002a60fSMarcel Moolenaar char f_fpack[6]; 4655002a60fSMarcel Moolenaar }; 4665002a60fSMarcel Moolenaar 4675002a60fSMarcel Moolenaar int 468b40ce416SJulian Elischer linux_ustat(struct thread *td, struct linux_ustat_args *args) 4695002a60fSMarcel Moolenaar { 4701e247cc2SPoul-Henning Kamp #ifdef DEBUG 4711e247cc2SPoul-Henning Kamp if (ldebug(ustat)) 4721e247cc2SPoul-Henning Kamp printf(ARGS(ustat, "%d, *"), args->dev); 4731e247cc2SPoul-Henning Kamp #endif 4741e247cc2SPoul-Henning Kamp 4751e247cc2SPoul-Henning Kamp return (EOPNOTSUPP); 476408da119SMarcel Moolenaar } 4775002a60fSMarcel Moolenaar 4781997c537SDavid E. O'Brien #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 4795002a60fSMarcel Moolenaar 4805002a60fSMarcel Moolenaar static int 4815002a60fSMarcel Moolenaar stat64_copyout(struct stat *buf, void *ubuf) 4825002a60fSMarcel Moolenaar { 4835002a60fSMarcel Moolenaar struct l_stat64 lbuf; 4845002a60fSMarcel Moolenaar 4855002a60fSMarcel Moolenaar bzero(&lbuf, sizeof(lbuf)); 4865002a60fSMarcel Moolenaar lbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 4875002a60fSMarcel Moolenaar lbuf.st_ino = buf->st_ino; 4885002a60fSMarcel Moolenaar lbuf.st_mode = buf->st_mode; 4895002a60fSMarcel Moolenaar lbuf.st_nlink = buf->st_nlink; 4905002a60fSMarcel Moolenaar lbuf.st_uid = buf->st_uid; 4915002a60fSMarcel Moolenaar lbuf.st_gid = buf->st_gid; 4925002a60fSMarcel Moolenaar lbuf.st_rdev = buf->st_rdev; 4935002a60fSMarcel Moolenaar lbuf.st_size = buf->st_size; 4945002a60fSMarcel Moolenaar lbuf.st_atime = buf->st_atime; 4955002a60fSMarcel Moolenaar lbuf.st_mtime = buf->st_mtime; 4965002a60fSMarcel Moolenaar lbuf.st_ctime = buf->st_ctime; 4975002a60fSMarcel Moolenaar lbuf.st_blksize = buf->st_blksize; 4985002a60fSMarcel Moolenaar lbuf.st_blocks = buf->st_blocks; 4995002a60fSMarcel Moolenaar 5005002a60fSMarcel Moolenaar /* 5015002a60fSMarcel Moolenaar * The __st_ino field makes all the difference. In the Linux kernel 5025002a60fSMarcel Moolenaar * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO, 5035002a60fSMarcel Moolenaar * but without the assignment to __st_ino the runtime linker refuses 5045002a60fSMarcel Moolenaar * to mmap(2) any shared libraries. I guess it's broken alright :-) 5055002a60fSMarcel Moolenaar */ 5065002a60fSMarcel Moolenaar lbuf.__st_ino = buf->st_ino; 5075002a60fSMarcel Moolenaar 5085002a60fSMarcel Moolenaar return (copyout(&lbuf, ubuf, sizeof(lbuf))); 5095002a60fSMarcel Moolenaar } 5105002a60fSMarcel Moolenaar 5115002a60fSMarcel Moolenaar int 512b40ce416SJulian Elischer linux_stat64(struct thread *td, struct linux_stat64_args *args) 5135002a60fSMarcel Moolenaar { 5145002a60fSMarcel Moolenaar struct stat buf; 515206a5d3aSIan Dowse char *filename; 516f7a25872SJohn Baldwin int error; 5175002a60fSMarcel Moolenaar 518206a5d3aSIan Dowse LCONVPATHEXIST(td, args->filename, &filename); 5195002a60fSMarcel Moolenaar 5205002a60fSMarcel Moolenaar #ifdef DEBUG 5215002a60fSMarcel Moolenaar if (ldebug(stat64)) 522206a5d3aSIan Dowse printf(ARGS(stat64, "%s, *"), filename); 5235002a60fSMarcel Moolenaar #endif 5245002a60fSMarcel Moolenaar 525f7a25872SJohn Baldwin error = kern_stat(td, filename, UIO_SYSSPACE, &buf); 526e83d253bSOlivier Houchard if (!error && strlen(filename) > strlen("/dev/pts/") && 527e83d253bSOlivier Houchard !strncmp(filename, "/dev/pts/", strlen("/dev/pts/")) 528e83d253bSOlivier Houchard && filename[9] >= '0' && filename[9] <= '9') { 529e83d253bSOlivier Houchard /* 530e83d253bSOlivier Houchard * Linux checks major and minors of the slave device to make 531e83d253bSOlivier Houchard * sure it's a pty deivce, so let's make him believe it is. 532e83d253bSOlivier Houchard */ 533e83d253bSOlivier Houchard buf.st_rdev = (136 << 8); 534e83d253bSOlivier Houchard } 535e83d253bSOlivier Houchard 536060e4882SDoug Ambrisko translate_path_major_minor(td, filename, &buf); 537060e4882SDoug Ambrisko 538206a5d3aSIan Dowse LFREEPATH(filename); 5395002a60fSMarcel Moolenaar if (error) 5405002a60fSMarcel Moolenaar return (error); 5415002a60fSMarcel Moolenaar return (stat64_copyout(&buf, args->statbuf)); 5425002a60fSMarcel Moolenaar } 5435002a60fSMarcel Moolenaar 5445002a60fSMarcel Moolenaar int 545b40ce416SJulian Elischer linux_lstat64(struct thread *td, struct linux_lstat64_args *args) 5465002a60fSMarcel Moolenaar { 5475002a60fSMarcel Moolenaar struct stat sb; 548206a5d3aSIan Dowse char *filename; 549f7a25872SJohn Baldwin int error; 5505002a60fSMarcel Moolenaar 551206a5d3aSIan Dowse LCONVPATHEXIST(td, args->filename, &filename); 5525002a60fSMarcel Moolenaar 5535002a60fSMarcel Moolenaar #ifdef DEBUG 5545002a60fSMarcel Moolenaar if (ldebug(lstat64)) 5555002a60fSMarcel Moolenaar printf(ARGS(lstat64, "%s, *"), args->filename); 5565002a60fSMarcel Moolenaar #endif 5575002a60fSMarcel Moolenaar 558f7a25872SJohn Baldwin error = kern_lstat(td, filename, UIO_SYSSPACE, &sb); 559060e4882SDoug Ambrisko translate_path_major_minor(td, filename, &sb); 560206a5d3aSIan Dowse LFREEPATH(filename); 5615002a60fSMarcel Moolenaar if (error) 5625002a60fSMarcel Moolenaar return (error); 5635002a60fSMarcel Moolenaar return (stat64_copyout(&sb, args->statbuf)); 5645002a60fSMarcel Moolenaar } 5655002a60fSMarcel Moolenaar 5665002a60fSMarcel Moolenaar int 567b40ce416SJulian Elischer linux_fstat64(struct thread *td, struct linux_fstat64_args *args) 5685002a60fSMarcel Moolenaar { 5695002a60fSMarcel Moolenaar struct stat buf; 5705002a60fSMarcel Moolenaar int error; 5715002a60fSMarcel Moolenaar 5725002a60fSMarcel Moolenaar #ifdef DEBUG 5735002a60fSMarcel Moolenaar if (ldebug(fstat64)) 5745002a60fSMarcel Moolenaar printf(ARGS(fstat64, "%d, *"), args->fd); 5755002a60fSMarcel Moolenaar #endif 5765002a60fSMarcel Moolenaar 577f7a25872SJohn Baldwin error = kern_fstat(td, args->fd, &buf); 578060e4882SDoug Ambrisko translate_fd_major_minor(td, args->fd, &buf); 5795002a60fSMarcel Moolenaar if (!error) 5805002a60fSMarcel Moolenaar error = stat64_copyout(&buf, args->statbuf); 5815002a60fSMarcel Moolenaar 5825002a60fSMarcel Moolenaar return (error); 5835002a60fSMarcel Moolenaar } 5845002a60fSMarcel Moolenaar 5851997c537SDavid E. O'Brien #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 586