2 * Copyright (c) 1994 Christos Zoulas
3 * Copyright (c) 1995 Frank van der Linden
4 * Copyright (c) 1995 Scott Bartram
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
29 * from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
37 #include <sys/param.h>
40 #include <sys/malloc.h>
41 #include <sys/linker_set.h>
42 #include <sys/mutex.h>
43 #include <sys/namei.h>
45 #include <sys/syscallsubr.h>
46 #include <sys/systm.h>
47 #include <sys/vnode.h>
49 #include <machine/stdarg.h>
51 #include <compat/linux/linux_util.h>
53 #include <machine/../linux32/linux.h>
55 #include <machine/../linux/linux.h>
58 const char linux_emul_path[] = "/compat/linux";
61 * Search an alternate path before passing pathname arguments on to
62 * system calls. Useful for keeping a separate 'emulation tree'.
64 * If cflag is set, we check if an attempt can be made to create the
65 * named file, i.e. we check if the directory it should be in exists.
68 linux_emul_convpath(td, path, pathseg, pbuf, cflag)
76 return (kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf,
81 linux_msg(const struct thread *td, const char *fmt, ...)
87 printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm);
96 TAILQ_ENTRY(device_element) list;
97 struct linux_device_handler entry;
100 static TAILQ_HEAD(, device_element) devices =
101 TAILQ_HEAD_INITIALIZER(devices);
103 static struct linux_device_handler null_handler =
104 { "mem", "mem", "null", "null", 1, 3, 1};
106 DATA_SET(linux_device_handler_set, null_handler);
109 linux_driver_get_name_dev(device_t dev)
111 struct device_element *de;
112 const char *device_name = device_get_name(dev);
114 if (device_name == NULL)
116 TAILQ_FOREACH(de, &devices, list) {
117 if (strcmp(device_name, de->entry.bsd_driver_name) == 0)
118 return (de->entry.linux_driver_name);
125 linux_driver_get_major_minor(char *node, int *major, int *minor)
127 struct device_element *de;
129 if (node == NULL || major == NULL || minor == NULL)
131 TAILQ_FOREACH(de, &devices, list) {
132 if (strcmp(node, de->entry.bsd_device_name) == 0) {
133 *major = de->entry.linux_major;
134 *minor = de->entry.linux_minor;
143 linux_get_char_devices()
145 struct device_element *de;
146 char *temp, *string, *last;
148 int current_size = 0, string_size = 1024;
150 MALLOC(string, char *, string_size, M_LINUX, M_WAITOK);
153 TAILQ_FOREACH(de, &devices, list) {
154 if (!de->entry.linux_char_device)
157 if (strcmp(last, de->entry.bsd_driver_name) != 0) {
158 last = de->entry.bsd_driver_name;
160 snprintf(formated, sizeof(formated), "%3d %s\n",
161 de->entry.linux_major,
162 de->entry.linux_device_name);
163 if (strlen(formated) + current_size
166 MALLOC(string, char *, string_size,
168 bcopy(temp, string, current_size);
171 strcat(string, formated);
172 current_size = strlen(string);
180 linux_free_get_char_devices(char *string)
182 FREE(string, M_LINUX);
185 static int linux_major_starting = 200;
188 linux_device_register_handler(struct linux_device_handler *d)
190 struct device_element *de;
195 MALLOC(de, struct device_element *, sizeof(*de),
197 if (d->linux_major < 0) {
198 d->linux_major = linux_major_starting++;
200 bcopy(d, &de->entry, sizeof(*d));
202 /* Add the element to the list, sorted on span. */
203 TAILQ_INSERT_TAIL(&devices, de, list);
209 linux_device_unregister_handler(struct linux_device_handler *d)
211 struct device_element *de;
216 TAILQ_FOREACH(de, &devices, list) {
217 if (bcmp(d, &de->entry, sizeof(*d)) == 0) {
218 TAILQ_REMOVE(&devices, de, list);