Deleted Added
sdiff udiff text old ( 258541 ) new ( 283421 )
full compact
1/*-
2 * Copyright (c) 1994 Christos Zoulas
3 * Copyright (c) 1995 Frank van der Linden
4 * Copyright (c) 1995 Scott Bartram
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

--- 16 unchanged lines hidden (view full) ---

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: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/compat/linux/linux_util.c 283421 2015-05-24 15:51:18Z dchagin $");
34
35#include "opt_compat.h"
36
37#include <sys/param.h>
38#include <sys/bus.h>
39#include <sys/fcntl.h>
40#include <sys/lock.h>
41#include <sys/malloc.h>

--- 5 unchanged lines hidden (view full) ---

47#include <sys/sdt.h>
48#include <sys/syscallsubr.h>
49#include <sys/systm.h>
50#include <sys/vnode.h>
51
52#include <machine/stdarg.h>
53
54#include <compat/linux/linux_util.h>
55
56MALLOC_DEFINE(M_LINUX, "linux", "Linux mode structures");
57
58const char linux_emul_path[] = "/compat/linux";
59
60/*
61 * Search an alternate path before passing pathname arguments on to
62 * system calls. Useful for keeping a separate 'emulation tree'.
63 *
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.
66 */
67int
68linux_emul_convpath(struct thread *td, const char *path, enum uio_seg pathseg,
69 char **pbuf, int cflag, int dfd)
70{
71 int retval;
72
73 retval = kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf,
74 cflag, dfd);
75
76 return (retval);
77}
78
79void
80linux_msg(const struct thread *td, const char *fmt, ...)
81{
82 va_list ap;
83 struct proc *p;
84
85 p = td->td_proc;
86 printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm);
87 va_start(ap, fmt);
88 vprintf(fmt, ap);
89 va_end(ap);
90 printf("\n");
91}
92
93struct device_element
94{
95 TAILQ_ENTRY(device_element) list;
96 struct linux_device_handler entry;
97};
98

--- 6 unchanged lines hidden (view full) ---

105DATA_SET(linux_device_handler_set, null_handler);
106
107char *
108linux_driver_get_name_dev(device_t dev)
109{
110 struct device_element *de;
111 const char *device_name = device_get_name(dev);
112
113 if (device_name == NULL)
114 return NULL;
115 TAILQ_FOREACH(de, &devices, list) {
116 if (strcmp(device_name, de->entry.bsd_driver_name) == 0)
117 return (de->entry.linux_driver_name);
118 }
119
120 return (NULL);
121}
122
123int
124linux_driver_get_major_minor(const char *node, int *major, int *minor)
125{
126 struct device_element *de;
127
128 if (node == NULL || major == NULL || minor == NULL)
129 return 1;
130
131 if (strlen(node) > strlen("pts/") &&
132 strncmp(node, "pts/", strlen("pts/")) == 0) {
133 unsigned long devno;
134
135 /*
136 * Linux checks major and minors of the slave device
137 * to make sure it's a pty device, so let's make him
138 * believe it is.
139 */
140 devno = strtoul(node + strlen("pts/"), NULL, 10);
141 *major = 136 + (devno / 256);
142 *minor = devno % 256;
143
144 return (0);
145 }
146
147 TAILQ_FOREACH(de, &devices, list) {
148 if (strcmp(node, de->entry.bsd_device_name) == 0) {
149 *major = de->entry.linux_major;
150 *minor = de->entry.linux_minor;
151 return (0);
152 }
153 }
154
155 return (1);
156}
157
158char *
159linux_get_char_devices()
160{
161 struct device_element *de;
162 char *temp, *string, *last;
163 char formated[256];
164 int current_size = 0, string_size = 1024;
165
166 string = malloc(string_size, M_LINUX, M_WAITOK);
167 string[0] = '\000';
168 last = "";
169 TAILQ_FOREACH(de, &devices, list) {
170 if (!de->entry.linux_char_device)
171 continue;
172 temp = string;
173 if (strcmp(last, de->entry.bsd_driver_name) != 0) {

--- 10 unchanged lines hidden (view full) ---

184 bcopy(temp, string, current_size);
185 free(temp, M_LINUX);
186 }
187 strcat(string, formated);
188 current_size = strlen(string);
189 }
190 }
191
192 return (string);
193}
194
195void
196linux_free_get_char_devices(char *string)
197{
198
199 free(string, M_LINUX);
200}
201
202static int linux_major_starting = 200;
203
204int
205linux_device_register_handler(struct linux_device_handler *d)
206{
207 struct device_element *de;
208
209 if (d == NULL)
210 return (EINVAL);
211
212 de = malloc(sizeof(*de), M_LINUX, M_WAITOK);
213 if (d->linux_major < 0) {
214 d->linux_major = linux_major_starting++;
215 }
216 bcopy(d, &de->entry, sizeof(*d));
217
218 /* Add the element to the list, sorted on span. */
219 TAILQ_INSERT_TAIL(&devices, de, list);
220
221 return (0);
222}
223
224int
225linux_device_unregister_handler(struct linux_device_handler *d)
226{
227 struct device_element *de;
228
229 if (d == NULL)
230 return (EINVAL);
231
232 TAILQ_FOREACH(de, &devices, list) {
233 if (bcmp(d, &de->entry, sizeof(*d)) == 0) {
234 TAILQ_REMOVE(&devices, de, list);
235 free(de, M_LINUX);
236
237 return (0);
238 }
239 }
240
241 return (EINVAL);
242}