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