This source file includes following definitions.
- emul_find
- emul_flags_translate
- stackgap_init
- stackgap_alloc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/namei.h>
36 #include <sys/proc.h>
37 #include <sys/file.h>
38 #include <sys/stat.h>
39 #include <sys/filedesc.h>
40 #include <sys/ioctl.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/vnode.h>
44
45 #include <compat/common/compat_util.h>
46
47
48
49
50
51
52
53
54
55 int
56 emul_find(p, sgp, prefix, path, pbuf, cflag)
57 struct proc *p;
58 caddr_t *sgp;
59 const char *prefix;
60 char *path;
61 char **pbuf;
62 int cflag;
63 {
64 struct nameidata nd;
65 struct nameidata ndroot;
66 struct vattr vat;
67 struct vattr vatroot;
68 int error;
69 char *ptr, *buf, *cp;
70 const char *pr;
71 size_t sz, len;
72
73 buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
74 *pbuf = path;
75
76 for (ptr = buf, pr = prefix; (*ptr = *pr) != '\0'; ptr++, pr++)
77 continue;
78
79 sz = MAXPATHLEN - (ptr - buf);
80
81
82
83
84 if (sgp == NULL)
85 error = copystr(path, ptr, sz, &len);
86 else
87 error = copyinstr(path, ptr, sz, &len);
88
89 if (error)
90 goto bad;
91
92 if (*ptr != '/') {
93 error = EINVAL;
94 goto bad;
95 }
96
97
98
99
100
101
102
103
104
105 if (cflag) {
106 for (cp = &ptr[len] - 1; *cp != '/'; cp--)
107 ;
108 *cp = '\0';
109
110 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p);
111
112 if ((error = namei(&nd)) != 0)
113 goto bad;
114
115 *cp = '/';
116 }
117 else {
118 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p);
119
120 if ((error = namei(&nd)) != 0)
121 goto bad;
122
123
124
125
126
127
128
129
130
131
132 NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, prefix, p);
133
134 if ((error = namei(&ndroot)) != 0)
135 goto bad2;
136
137 if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0)
138 goto bad3;
139
140 if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p))
141 != 0)
142 goto bad3;
143
144 if (vat.va_fsid == vatroot.va_fsid &&
145 vat.va_fileid == vatroot.va_fileid) {
146 error = ENOENT;
147 goto bad3;
148 }
149 }
150 if (sgp == NULL)
151 *pbuf = buf;
152 else {
153 sz = &ptr[len] - buf;
154 *pbuf = stackgap_alloc(sgp, sz + 1);
155 if (*pbuf == NULL) {
156 error = ENAMETOOLONG;
157 goto bad;
158 }
159 if ((error = copyout(buf, *pbuf, sz)) != 0) {
160 *pbuf = path;
161 goto bad;
162 }
163 free(buf, M_TEMP);
164 }
165
166 vrele(nd.ni_vp);
167 if (!cflag)
168 vrele(ndroot.ni_vp);
169 return error;
170
171 bad3:
172 vrele(ndroot.ni_vp);
173 bad2:
174 vrele(nd.ni_vp);
175 bad:
176 free(buf, M_TEMP);
177 return error;
178 }
179
180
181
182
183
184
185 unsigned long
186 emul_flags_translate(tab, in, leftover)
187 const struct emul_flags_xtab *tab;
188 unsigned long in;
189 unsigned long *leftover;
190 {
191 unsigned long out;
192
193 for (out = 0; tab->omask != 0; tab++) {
194 if ((in & tab->omask) == tab->oval) {
195 in &= ~tab->omask;
196 out |= tab->nval;
197 }
198 }
199 if (leftover != NULL)
200 *leftover = in;
201 return (out);
202 }
203
204 caddr_t
205 stackgap_init(e)
206 struct emul *e;
207 {
208 return STACKGAPBASE;
209 }
210
211 void *
212 stackgap_alloc(sgp, sz)
213 caddr_t *sgp;
214 size_t sz;
215 {
216 void *n = (void *) *sgp;
217 caddr_t nsgp;
218
219 sz = ALIGN(sz);
220 nsgp = *sgp + sz;
221 #ifdef MACHINE_STACK_GROWS_UP
222 if (nsgp > ((caddr_t)PS_STRINGS) + STACKGAPLEN)
223 return NULL;
224 #else
225 if (nsgp > ((caddr_t)PS_STRINGS))
226 return NULL;
227 #endif
228 *sgp = nsgp;
229 return n;
230 }