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>
|
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/* 62 * XXX: This was removed from newstat_copyout(), and almost identical 63 * XXX: code was in stat64_copyout(). findcdev() needs to be replaced 64 * XXX: with something that does lookup and locking properly. 65 * XXX: When somebody fixes this: please try to avoid duplicating it. 66 */ 67#if 0 68static void 69disk_foo(struct somestat *tbuf) 70{ 71 struct cdevsw *cdevsw; 72 struct cdev *dev; 73 74 /* Lie about disk drives which are character devices 75 * in FreeBSD but block devices under Linux. 76 */ 77 if (S_ISCHR(tbuf.st_mode) && 78 (dev = findcdev(buf->st_rdev)) != NULL) { 79 cdevsw = dev_refthread(dev); 80 if (cdevsw != NULL) { 81 if (cdevsw->d_flags & D_DISK) { 82 tbuf.st_mode &= ~S_IFMT; 83 tbuf.st_mode |= S_IFBLK; 84 85 /* XXX this may not be quite right */ 86 /* Map major number to 0 */ 87 tbuf.st_dev = uminor(buf->st_dev) & 0xf; 88 tbuf.st_rdev = buf->st_rdev & 0xff; 89 } 90 dev_relthread(dev); 91 } 92 } 93 94} 95#endif 96 97static int 98newstat_copyout(struct stat *buf, void *ubuf) 99{ 100 struct l_newstat tbuf; 101 102 bzero(&tbuf, sizeof(tbuf)); 103 tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 104 tbuf.st_ino = buf->st_ino; 105 tbuf.st_mode = buf->st_mode; 106 tbuf.st_nlink = buf->st_nlink; 107 tbuf.st_uid = buf->st_uid; 108 tbuf.st_gid = buf->st_gid; 109 tbuf.st_rdev = buf->st_rdev; 110 tbuf.st_size = buf->st_size; 111 tbuf.st_atime = buf->st_atime; 112 tbuf.st_mtime = buf->st_mtime; 113 tbuf.st_ctime = buf->st_ctime; 114 tbuf.st_blksize = buf->st_blksize; 115 tbuf.st_blocks = buf->st_blocks; 116 117 return (copyout(&tbuf, ubuf, sizeof(tbuf))); 118} 119 120int 121linux_newstat(struct thread *td, struct linux_newstat_args *args) 122{ 123 struct stat buf; 124 char *path; 125 int error; 126 127 LCONVPATHEXIST(td, args->path, &path); 128 129#ifdef DEBUG 130 if (ldebug(newstat)) 131 printf(ARGS(newstat, "%s, *"), path); 132#endif 133 134 error = kern_stat(td, path, UIO_SYSSPACE, &buf); 135 if (!error && strlen(path) > strlen("/dev/pts/") && 136 !strncmp(path, "/dev/pts/", strlen("/dev/pts/")) 137 && path[9] >= '0' && path[9] <= '9') { 138 /* 139 * Linux checks major and minors of the slave device to make 140 * sure it's a pty device, so let's make him believe it is. 141 */ 142 buf.st_rdev = (136 << 8); 143 } 144 145 LFREEPATH(path); 146 if (error) 147 return (error); 148 return (newstat_copyout(&buf, args->buf)); 149} 150 151int 152linux_newlstat(struct thread *td, struct linux_newlstat_args *args) 153{ 154 struct stat sb; 155 char *path; 156 int error; 157 158 LCONVPATHEXIST(td, args->path, &path); 159 160#ifdef DEBUG 161 if (ldebug(newlstat)) 162 printf(ARGS(newlstat, "%s, *"), path); 163#endif 164 165 error = kern_lstat(td, path, UIO_SYSSPACE, &sb); 166 LFREEPATH(path); 167 if (error) 168 return (error); 169 return (newstat_copyout(&sb, args->buf)); 170} 171 172int 173linux_newfstat(struct thread *td, struct linux_newfstat_args *args) 174{ 175 struct stat buf; 176 int error; 177 178#ifdef DEBUG 179 if (ldebug(newfstat)) 180 printf(ARGS(newfstat, "%d, *"), args->fd); 181#endif 182 183 error = kern_fstat(td, args->fd, &buf); 184 if (!error) 185 error = newstat_copyout(&buf, args->buf); 186 187 return (error); 188} 189
| 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 60/* 61 * XXX: This was removed from newstat_copyout(), and almost identical 62 * XXX: code was in stat64_copyout(). findcdev() needs to be replaced 63 * XXX: with something that does lookup and locking properly. 64 * XXX: When somebody fixes this: please try to avoid duplicating it. 65 */ 66#if 0 67static void 68disk_foo(struct somestat *tbuf) 69{ 70 struct cdevsw *cdevsw; 71 struct cdev *dev; 72 73 /* Lie about disk drives which are character devices 74 * in FreeBSD but block devices under Linux. 75 */ 76 if (S_ISCHR(tbuf.st_mode) && 77 (dev = findcdev(buf->st_rdev)) != NULL) { 78 cdevsw = dev_refthread(dev); 79 if (cdevsw != NULL) { 80 if (cdevsw->d_flags & D_DISK) { 81 tbuf.st_mode &= ~S_IFMT; 82 tbuf.st_mode |= S_IFBLK; 83 84 /* XXX this may not be quite right */ 85 /* Map major number to 0 */ 86 tbuf.st_dev = uminor(buf->st_dev) & 0xf; 87 tbuf.st_rdev = buf->st_rdev & 0xff; 88 } 89 dev_relthread(dev); 90 } 91 } 92 93} 94#endif 95 96static int 97newstat_copyout(struct stat *buf, void *ubuf) 98{ 99 struct l_newstat tbuf; 100 101 bzero(&tbuf, sizeof(tbuf)); 102 tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 103 tbuf.st_ino = buf->st_ino; 104 tbuf.st_mode = buf->st_mode; 105 tbuf.st_nlink = buf->st_nlink; 106 tbuf.st_uid = buf->st_uid; 107 tbuf.st_gid = buf->st_gid; 108 tbuf.st_rdev = buf->st_rdev; 109 tbuf.st_size = buf->st_size; 110 tbuf.st_atime = buf->st_atime; 111 tbuf.st_mtime = buf->st_mtime; 112 tbuf.st_ctime = buf->st_ctime; 113 tbuf.st_blksize = buf->st_blksize; 114 tbuf.st_blocks = buf->st_blocks; 115 116 return (copyout(&tbuf, ubuf, sizeof(tbuf))); 117} 118 119int 120linux_newstat(struct thread *td, struct linux_newstat_args *args) 121{ 122 struct stat buf; 123 char *path; 124 int error; 125 126 LCONVPATHEXIST(td, args->path, &path); 127 128#ifdef DEBUG 129 if (ldebug(newstat)) 130 printf(ARGS(newstat, "%s, *"), path); 131#endif 132 133 error = kern_stat(td, path, UIO_SYSSPACE, &buf); 134 if (!error && strlen(path) > strlen("/dev/pts/") && 135 !strncmp(path, "/dev/pts/", strlen("/dev/pts/")) 136 && path[9] >= '0' && path[9] <= '9') { 137 /* 138 * Linux checks major and minors of the slave device to make 139 * sure it's a pty device, so let's make him believe it is. 140 */ 141 buf.st_rdev = (136 << 8); 142 } 143 144 LFREEPATH(path); 145 if (error) 146 return (error); 147 return (newstat_copyout(&buf, args->buf)); 148} 149 150int 151linux_newlstat(struct thread *td, struct linux_newlstat_args *args) 152{ 153 struct stat sb; 154 char *path; 155 int error; 156 157 LCONVPATHEXIST(td, args->path, &path); 158 159#ifdef DEBUG 160 if (ldebug(newlstat)) 161 printf(ARGS(newlstat, "%s, *"), path); 162#endif 163 164 error = kern_lstat(td, path, UIO_SYSSPACE, &sb); 165 LFREEPATH(path); 166 if (error) 167 return (error); 168 return (newstat_copyout(&sb, args->buf)); 169} 170 171int 172linux_newfstat(struct thread *td, struct linux_newfstat_args *args) 173{ 174 struct stat buf; 175 int error; 176 177#ifdef DEBUG 178 if (ldebug(newfstat)) 179 printf(ARGS(newfstat, "%d, *"), args->fd); 180#endif 181 182 error = kern_fstat(td, args->fd, &buf); 183 if (!error) 184 error = newstat_copyout(&buf, args->buf); 185 186 return (error); 187} 188
|
190/* XXX - All fields of type l_int are defined as l_long on i386 */ 191struct l_statfs { 192 l_int f_type; 193 l_int f_bsize; 194 l_int f_blocks; 195 l_int f_bfree; 196 l_int f_bavail; 197 l_int f_files; 198 l_int f_ffree; 199 l_fsid_t f_fsid; 200 l_int f_namelen; 201 l_int f_spare[6]; 202}; 203 204#define LINUX_CODA_SUPER_MAGIC 0x73757245L 205#define LINUX_EXT2_SUPER_MAGIC 0xEF53L 206#define LINUX_HPFS_SUPER_MAGIC 0xf995e849L 207#define LINUX_ISOFS_SUPER_MAGIC 0x9660L 208#define LINUX_MSDOS_SUPER_MAGIC 0x4d44L 209#define LINUX_NCP_SUPER_MAGIC 0x564cL 210#define LINUX_NFS_SUPER_MAGIC 0x6969L 211#define LINUX_NTFS_SUPER_MAGIC 0x5346544EL 212#define LINUX_PROC_SUPER_MAGIC 0x9fa0L 213#define LINUX_UFS_SUPER_MAGIC 0x00011954L /* XXX - UFS_MAGIC in Linux */ 214#define LINUX_DEVFS_SUPER_MAGIC 0x1373L 215 216static long 217bsd_to_linux_ftype(const char *fstypename) 218{ 219 int i; 220 static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = { 221 {"ufs", LINUX_UFS_SUPER_MAGIC}, 222 {"cd9660", LINUX_ISOFS_SUPER_MAGIC}, 223 {"nfs", LINUX_NFS_SUPER_MAGIC}, 224 {"ext2fs", LINUX_EXT2_SUPER_MAGIC}, 225 {"procfs", LINUX_PROC_SUPER_MAGIC}, 226 {"msdosfs", LINUX_MSDOS_SUPER_MAGIC}, 227 {"ntfs", LINUX_NTFS_SUPER_MAGIC}, 228 {"nwfs", LINUX_NCP_SUPER_MAGIC}, 229 {"hpfs", LINUX_HPFS_SUPER_MAGIC}, 230 {"coda", LINUX_CODA_SUPER_MAGIC}, 231 {"devfs", LINUX_DEVFS_SUPER_MAGIC}, 232 {NULL, 0L}}; 233 234 for (i = 0; b2l_tbl[i].bsd_name != NULL; i++) 235 if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0) 236 return (b2l_tbl[i].linux_type); 237 238 return (0L); 239} 240 241static void 242bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs) 243{ 244 245 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 246 linux_statfs->f_bsize = bsd_statfs->f_bsize; 247 linux_statfs->f_blocks = bsd_statfs->f_blocks; 248 linux_statfs->f_bfree = bsd_statfs->f_bfree; 249 linux_statfs->f_bavail = bsd_statfs->f_bavail; 250 linux_statfs->f_ffree = bsd_statfs->f_ffree; 251 linux_statfs->f_files = bsd_statfs->f_files; 252 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 253 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 254 linux_statfs->f_namelen = MAXNAMLEN; 255} 256 257int 258linux_statfs(struct thread *td, struct linux_statfs_args *args) 259{ 260 struct l_statfs linux_statfs; 261 struct statfs bsd_statfs; 262 char *path; 263 int error; 264 265 LCONVPATHEXIST(td, args->path, &path); 266 267#ifdef DEBUG 268 if (ldebug(statfs)) 269 printf(ARGS(statfs, "%s, *"), path); 270#endif 271 error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 272 LFREEPATH(path); 273 if (error) 274 return (error); 275 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 276 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 277} 278 279int 280linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) 281{ 282 struct l_statfs linux_statfs; 283 struct statfs bsd_statfs; 284 int error; 285 286#ifdef DEBUG 287 if (ldebug(fstatfs)) 288 printf(ARGS(fstatfs, "%d, *"), args->fd); 289#endif 290 error = kern_fstatfs(td, args->fd, &bsd_statfs); 291 if (error) 292 return error; 293 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 294 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 295} 296 297struct l_ustat 298{ 299 l_daddr_t f_tfree; 300 l_ino_t f_tinode; 301 char f_fname[6]; 302 char f_fpack[6]; 303}; 304 305int 306linux_ustat(struct thread *td, struct linux_ustat_args *args) 307{ 308#ifdef DEBUG 309 if (ldebug(ustat)) 310 printf(ARGS(ustat, "%d, *"), args->dev); 311#endif 312 313 return (EOPNOTSUPP); 314} 315 316#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 317 318static int 319stat64_copyout(struct stat *buf, void *ubuf) 320{ 321 struct l_stat64 lbuf; 322 323 bzero(&lbuf, sizeof(lbuf)); 324 lbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 325 lbuf.st_ino = buf->st_ino; 326 lbuf.st_mode = buf->st_mode; 327 lbuf.st_nlink = buf->st_nlink; 328 lbuf.st_uid = buf->st_uid; 329 lbuf.st_gid = buf->st_gid; 330 lbuf.st_rdev = buf->st_rdev; 331 lbuf.st_size = buf->st_size; 332 lbuf.st_atime = buf->st_atime; 333 lbuf.st_mtime = buf->st_mtime; 334 lbuf.st_ctime = buf->st_ctime; 335 lbuf.st_blksize = buf->st_blksize; 336 lbuf.st_blocks = buf->st_blocks; 337 338 /* 339 * The __st_ino field makes all the difference. In the Linux kernel 340 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO, 341 * but without the assignment to __st_ino the runtime linker refuses 342 * to mmap(2) any shared libraries. I guess it's broken alright :-) 343 */ 344 lbuf.__st_ino = buf->st_ino; 345 346 return (copyout(&lbuf, ubuf, sizeof(lbuf))); 347} 348 349int 350linux_stat64(struct thread *td, struct linux_stat64_args *args) 351{ 352 struct stat buf; 353 char *filename; 354 int error; 355 356 LCONVPATHEXIST(td, args->filename, &filename); 357 358#ifdef DEBUG 359 if (ldebug(stat64)) 360 printf(ARGS(stat64, "%s, *"), filename); 361#endif 362 363 error = kern_stat(td, filename, UIO_SYSSPACE, &buf); 364 if (!error && strlen(filename) > strlen("/dev/pts/") && 365 !strncmp(filename, "/dev/pts/", strlen("/dev/pts/")) 366 && filename[9] >= '0' && filename[9] <= '9') { 367 /* 368 * Linux checks major and minors of the slave device to make 369 * sure it's a pty deivce, so let's make him believe it is. 370 */ 371 buf.st_rdev = (136 << 8); 372 } 373 374 LFREEPATH(filename); 375 if (error) 376 return (error); 377 return (stat64_copyout(&buf, args->statbuf)); 378} 379 380int 381linux_lstat64(struct thread *td, struct linux_lstat64_args *args) 382{ 383 struct stat sb; 384 char *filename; 385 int error; 386 387 LCONVPATHEXIST(td, args->filename, &filename); 388 389#ifdef DEBUG 390 if (ldebug(lstat64)) 391 printf(ARGS(lstat64, "%s, *"), args->filename); 392#endif 393 394 error = kern_lstat(td, filename, UIO_SYSSPACE, &sb); 395 LFREEPATH(filename); 396 if (error) 397 return (error); 398 return (stat64_copyout(&sb, args->statbuf)); 399} 400 401int 402linux_fstat64(struct thread *td, struct linux_fstat64_args *args) 403{ 404 struct stat buf; 405 int error; 406 407#ifdef DEBUG 408 if (ldebug(fstat64)) 409 printf(ARGS(fstat64, "%d, *"), args->fd); 410#endif 411 412 error = kern_fstat(td, args->fd, &buf); 413 if (!error) 414 error = stat64_copyout(&buf, args->statbuf); 415 416 return (error); 417} 418 419#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
| 248/* XXX - All fields of type l_int are defined as l_long on i386 */ 249struct l_statfs { 250 l_int f_type; 251 l_int f_bsize; 252 l_int f_blocks; 253 l_int f_bfree; 254 l_int f_bavail; 255 l_int f_files; 256 l_int f_ffree; 257 l_fsid_t f_fsid; 258 l_int f_namelen; 259 l_int f_spare[6]; 260}; 261 262#define LINUX_CODA_SUPER_MAGIC 0x73757245L 263#define LINUX_EXT2_SUPER_MAGIC 0xEF53L 264#define LINUX_HPFS_SUPER_MAGIC 0xf995e849L 265#define LINUX_ISOFS_SUPER_MAGIC 0x9660L 266#define LINUX_MSDOS_SUPER_MAGIC 0x4d44L 267#define LINUX_NCP_SUPER_MAGIC 0x564cL 268#define LINUX_NFS_SUPER_MAGIC 0x6969L 269#define LINUX_NTFS_SUPER_MAGIC 0x5346544EL 270#define LINUX_PROC_SUPER_MAGIC 0x9fa0L 271#define LINUX_UFS_SUPER_MAGIC 0x00011954L /* XXX - UFS_MAGIC in Linux */ 272#define LINUX_DEVFS_SUPER_MAGIC 0x1373L 273 274static long 275bsd_to_linux_ftype(const char *fstypename) 276{ 277 int i; 278 static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = { 279 {"ufs", LINUX_UFS_SUPER_MAGIC}, 280 {"cd9660", LINUX_ISOFS_SUPER_MAGIC}, 281 {"nfs", LINUX_NFS_SUPER_MAGIC}, 282 {"ext2fs", LINUX_EXT2_SUPER_MAGIC}, 283 {"procfs", LINUX_PROC_SUPER_MAGIC}, 284 {"msdosfs", LINUX_MSDOS_SUPER_MAGIC}, 285 {"ntfs", LINUX_NTFS_SUPER_MAGIC}, 286 {"nwfs", LINUX_NCP_SUPER_MAGIC}, 287 {"hpfs", LINUX_HPFS_SUPER_MAGIC}, 288 {"coda", LINUX_CODA_SUPER_MAGIC}, 289 {"devfs", LINUX_DEVFS_SUPER_MAGIC}, 290 {NULL, 0L}}; 291 292 for (i = 0; b2l_tbl[i].bsd_name != NULL; i++) 293 if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0) 294 return (b2l_tbl[i].linux_type); 295 296 return (0L); 297} 298 299static void 300bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs) 301{ 302 303 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); 304 linux_statfs->f_bsize = bsd_statfs->f_bsize; 305 linux_statfs->f_blocks = bsd_statfs->f_blocks; 306 linux_statfs->f_bfree = bsd_statfs->f_bfree; 307 linux_statfs->f_bavail = bsd_statfs->f_bavail; 308 linux_statfs->f_ffree = bsd_statfs->f_ffree; 309 linux_statfs->f_files = bsd_statfs->f_files; 310 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; 311 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; 312 linux_statfs->f_namelen = MAXNAMLEN; 313} 314 315int 316linux_statfs(struct thread *td, struct linux_statfs_args *args) 317{ 318 struct l_statfs linux_statfs; 319 struct statfs bsd_statfs; 320 char *path; 321 int error; 322 323 LCONVPATHEXIST(td, args->path, &path); 324 325#ifdef DEBUG 326 if (ldebug(statfs)) 327 printf(ARGS(statfs, "%s, *"), path); 328#endif 329 error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); 330 LFREEPATH(path); 331 if (error) 332 return (error); 333 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 334 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 335} 336 337int 338linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) 339{ 340 struct l_statfs linux_statfs; 341 struct statfs bsd_statfs; 342 int error; 343 344#ifdef DEBUG 345 if (ldebug(fstatfs)) 346 printf(ARGS(fstatfs, "%d, *"), args->fd); 347#endif 348 error = kern_fstatfs(td, args->fd, &bsd_statfs); 349 if (error) 350 return error; 351 bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); 352 return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); 353} 354 355struct l_ustat 356{ 357 l_daddr_t f_tfree; 358 l_ino_t f_tinode; 359 char f_fname[6]; 360 char f_fpack[6]; 361}; 362 363int 364linux_ustat(struct thread *td, struct linux_ustat_args *args) 365{ 366#ifdef DEBUG 367 if (ldebug(ustat)) 368 printf(ARGS(ustat, "%d, *"), args->dev); 369#endif 370 371 return (EOPNOTSUPP); 372} 373 374#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 375 376static int 377stat64_copyout(struct stat *buf, void *ubuf) 378{ 379 struct l_stat64 lbuf; 380 381 bzero(&lbuf, sizeof(lbuf)); 382 lbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); 383 lbuf.st_ino = buf->st_ino; 384 lbuf.st_mode = buf->st_mode; 385 lbuf.st_nlink = buf->st_nlink; 386 lbuf.st_uid = buf->st_uid; 387 lbuf.st_gid = buf->st_gid; 388 lbuf.st_rdev = buf->st_rdev; 389 lbuf.st_size = buf->st_size; 390 lbuf.st_atime = buf->st_atime; 391 lbuf.st_mtime = buf->st_mtime; 392 lbuf.st_ctime = buf->st_ctime; 393 lbuf.st_blksize = buf->st_blksize; 394 lbuf.st_blocks = buf->st_blocks; 395 396 /* 397 * The __st_ino field makes all the difference. In the Linux kernel 398 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO, 399 * but without the assignment to __st_ino the runtime linker refuses 400 * to mmap(2) any shared libraries. I guess it's broken alright :-) 401 */ 402 lbuf.__st_ino = buf->st_ino; 403 404 return (copyout(&lbuf, ubuf, sizeof(lbuf))); 405} 406 407int 408linux_stat64(struct thread *td, struct linux_stat64_args *args) 409{ 410 struct stat buf; 411 char *filename; 412 int error; 413 414 LCONVPATHEXIST(td, args->filename, &filename); 415 416#ifdef DEBUG 417 if (ldebug(stat64)) 418 printf(ARGS(stat64, "%s, *"), filename); 419#endif 420 421 error = kern_stat(td, filename, UIO_SYSSPACE, &buf); 422 if (!error && strlen(filename) > strlen("/dev/pts/") && 423 !strncmp(filename, "/dev/pts/", strlen("/dev/pts/")) 424 && filename[9] >= '0' && filename[9] <= '9') { 425 /* 426 * Linux checks major and minors of the slave device to make 427 * sure it's a pty deivce, so let's make him believe it is. 428 */ 429 buf.st_rdev = (136 << 8); 430 } 431 432 LFREEPATH(filename); 433 if (error) 434 return (error); 435 return (stat64_copyout(&buf, args->statbuf)); 436} 437 438int 439linux_lstat64(struct thread *td, struct linux_lstat64_args *args) 440{ 441 struct stat sb; 442 char *filename; 443 int error; 444 445 LCONVPATHEXIST(td, args->filename, &filename); 446 447#ifdef DEBUG 448 if (ldebug(lstat64)) 449 printf(ARGS(lstat64, "%s, *"), args->filename); 450#endif 451 452 error = kern_lstat(td, filename, UIO_SYSSPACE, &sb); 453 LFREEPATH(filename); 454 if (error) 455 return (error); 456 return (stat64_copyout(&sb, args->statbuf)); 457} 458 459int 460linux_fstat64(struct thread *td, struct linux_fstat64_args *args) 461{ 462 struct stat buf; 463 int error; 464 465#ifdef DEBUG 466 if (ldebug(fstat64)) 467 printf(ARGS(fstat64, "%d, *"), args->fd); 468#endif 469 470 error = kern_fstat(td, args->fd, &buf); 471 if (!error) 472 error = stat64_copyout(&buf, args->statbuf); 473 474 return (error); 475} 476 477#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|