1/*	$NetBSD: freebsd_file.c,v 1.34 2015/10/23 19:40:10 maxv 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.34 2015/10/23 19:40:10 maxv Exp $");
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/namei.h>
42#include <sys/proc.h>
43#include <sys/file.h>
44#include <sys/stat.h>
45#include <sys/filedesc.h>
46#include <sys/ioctl.h>
47#include <sys/kernel.h>
48#include <sys/mount.h>
49
50#include <sys/syscallargs.h>
51
52#include <compat/freebsd/freebsd_syscallargs.h>
53#include <compat/common/compat_util.h>
54#include <compat/sys/mount.h>
55
56#define	ARRAY_LENGTH(array)	(sizeof(array)/sizeof(array[0]))
57
58static const char * convert_from_freebsd_mount_type(int);
59
60static const char *
61convert_from_freebsd_mount_type(int type)
62{
63	static const char * const netbsd_mount_type[] = {
64		NULL,     /*  0 = MOUNT_NONE */
65		"ffs",	  /*  1 = "Fast" Filesystem */
66		"nfs",	  /*  2 = Network Filesystem */
67		"mfs",	  /*  3 = Memory Filesystem */
68		"msdos",  /*  4 = MSDOS Filesystem */
69		"lfs",	  /*  5 = Log-based Filesystem */
70		"lofs",	  /*  6 = Loopback filesystem */
71		"fdesc",  /*  7 = File Descriptor Filesystem */
72		"portal", /*  8 = Portal Filesystem */
73		"null",	  /*  9 = Minimal Filesystem Layer */
74		"umap",	  /* 10 = User/Group Identifier Remapping Filesystem */
75		"kernfs", /* 11 = Kernel Information Filesystem */
76		"procfs", /* 12 = /proc Filesystem */
77		"afs",	  /* 13 = Andrew Filesystem */
78		"cd9660", /* 14 = ISO9660 (aka CDROM) Filesystem */
79		"union",  /* 15 = Union (translucent) Filesystem */
80		NULL,     /* 16 = "devfs" - existing device Filesystem */
81#if 0 /* These filesystems don't exist in FreeBSD */
82		"adosfs", /* ?? = AmigaDOS Filesystem */
83#endif
84	};
85
86	if (type < 0 || type >= ARRAY_LENGTH(netbsd_mount_type))
87		return (NULL);
88	return (netbsd_mount_type[type]);
89}
90
91int
92freebsd_sys_mount(struct lwp *l, const struct freebsd_sys_mount_args *uap, register_t *retval)
93{
94	/* {
95		syscallarg(int) type;
96		syscallarg(char *) path;
97		syscallarg(int) flags;
98		syscallarg(void *) data;
99	} */
100	const char *type;
101	register_t dummy;
102
103	if ((type = convert_from_freebsd_mount_type(SCARG(uap, type))) == NULL)
104		return ENODEV;
105
106	return do_sys_mount(l, type, UIO_SYSSPACE, SCARG(uap, path),
107	    SCARG(uap, flags), SCARG(uap, data), UIO_USERSPACE, 0, &dummy);
108}
109
110/* XXX - UNIX domain: int freebsd_sys_bind(int s, void *name, int namelen); */
111/* XXX - UNIX domain: int freebsd_sys_connect(int s, void *name, int namelen); */
112