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