Home | History | Annotate | Line # | Download | only in freebsd
      1 /*	$NetBSD: freebsd_file.c,v 1.35 2026/01/02 22:22:22 nia Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Frank van der Linden
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  *	from: linux_file.c,v 1.3 1995/04/04 04:21:30 mycroft Exp
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: freebsd_file.c,v 1.35 2026/01/02 22:22:22 nia Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/namei.h>
     38 #include <sys/proc.h>
     39 #include <sys/file.h>
     40 #include <sys/stat.h>
     41 #include <sys/filedesc.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/kernel.h>
     44 #include <sys/mount.h>
     45 
     46 #include <sys/syscallargs.h>
     47 
     48 #include <compat/freebsd/freebsd_syscallargs.h>
     49 #include <compat/common/compat_util.h>
     50 #include <compat/sys/mount.h>
     51 
     52 #define	ARRAY_LENGTH(array)	(sizeof(array)/sizeof(array[0]))
     53 
     54 static const char * convert_from_freebsd_mount_type(int);
     55 
     56 static const char *
     57 convert_from_freebsd_mount_type(int type)
     58 {
     59 	static const char * const netbsd_mount_type[] = {
     60 		NULL,     /*  0 = MOUNT_NONE */
     61 		"ffs",	  /*  1 = "Fast" Filesystem */
     62 		"nfs",	  /*  2 = Network Filesystem */
     63 		"mfs",	  /*  3 = Memory Filesystem */
     64 		"msdos",  /*  4 = MSDOS Filesystem */
     65 		"lfs",	  /*  5 = Log-based Filesystem */
     66 		"lofs",	  /*  6 = Loopback filesystem */
     67 		"fdesc",  /*  7 = File Descriptor Filesystem */
     68 		"portal", /*  8 = Portal Filesystem */
     69 		"null",	  /*  9 = Minimal Filesystem Layer */
     70 		"umap",	  /* 10 = User/Group Identifier Remapping Filesystem */
     71 		"kernfs", /* 11 = Kernel Information Filesystem */
     72 		"procfs", /* 12 = /proc Filesystem */
     73 		"afs",	  /* 13 = Andrew Filesystem */
     74 		"cd9660", /* 14 = ISO9660 (aka CDROM) Filesystem */
     75 		"union",  /* 15 = Union (translucent) Filesystem */
     76 		NULL,     /* 16 = "devfs" - existing device Filesystem */
     77 #if 0 /* These filesystems don't exist in FreeBSD */
     78 		"adosfs", /* ?? = AmigaDOS Filesystem */
     79 #endif
     80 	};
     81 
     82 	if (type < 0 || type >= ARRAY_LENGTH(netbsd_mount_type))
     83 		return (NULL);
     84 	return (netbsd_mount_type[type]);
     85 }
     86 
     87 int
     88 freebsd_sys_mount(struct lwp *l, const struct freebsd_sys_mount_args *uap, register_t *retval)
     89 {
     90 	/* {
     91 		syscallarg(int) type;
     92 		syscallarg(char *) path;
     93 		syscallarg(int) flags;
     94 		syscallarg(void *) data;
     95 	} */
     96 	const char *type;
     97 	register_t dummy;
     98 
     99 	if ((type = convert_from_freebsd_mount_type(SCARG(uap, type))) == NULL)
    100 		return ENODEV;
    101 
    102 	return do_sys_mount(l, type, UIO_SYSSPACE, SCARG(uap, path),
    103 	    SCARG(uap, flags), SCARG(uap, data), UIO_USERSPACE, 0, &dummy);
    104 }
    105 
    106 /* XXX - UNIX domain: int freebsd_sys_bind(int s, void *name, int namelen); */
    107 /* XXX - UNIX domain: int freebsd_sys_connect(int s, void *name, int namelen); */
    108