linux_misc_notalpha.c revision 1.93 1 1.93 dsl /* $NetBSD: linux_misc_notalpha.c,v 1.93 2007/06/23 09:09:56 dsl Exp $ */
2 1.47 erh
3 1.47 erh /*-
4 1.49 fvdl * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5 1.47 erh * All rights reserved.
6 1.47 erh *
7 1.47 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.51 thorpej * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 1.51 thorpej * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 1.47 erh *
11 1.47 erh * Redistribution and use in source and binary forms, with or without
12 1.47 erh * modification, are permitted provided that the following conditions
13 1.47 erh * are met:
14 1.47 erh * 1. Redistributions of source code must retain the above copyright
15 1.47 erh * notice, this list of conditions and the following disclaimer.
16 1.47 erh * 2. Redistributions in binary form must reproduce the above copyright
17 1.47 erh * notice, this list of conditions and the following disclaimer in the
18 1.47 erh * documentation and/or other materials provided with the distribution.
19 1.47 erh * 3. All advertising materials mentioning features or use of this software
20 1.47 erh * must display the following acknowledgement:
21 1.47 erh * This product includes software developed by the NetBSD
22 1.47 erh * Foundation, Inc. and its contributors.
23 1.47 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.47 erh * contributors may be used to endorse or promote products derived
25 1.47 erh * from this software without specific prior written permission.
26 1.47 erh *
27 1.47 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.47 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.47 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.47 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.47 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.47 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.47 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.47 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.47 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.47 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.47 erh * POSSIBILITY OF SUCH DAMAGE.
38 1.1 fvdl */
39 1.61 lukem
40 1.61 lukem #include <sys/cdefs.h>
41 1.93 dsl __KERNEL_RCSID(0, "$NetBSD: linux_misc_notalpha.c,v 1.93 2007/06/23 09:09:56 dsl Exp $");
42 1.1 fvdl
43 1.1 fvdl #include <sys/param.h>
44 1.1 fvdl #include <sys/systm.h>
45 1.1 fvdl #include <sys/kernel.h>
46 1.47 erh #include <sys/mman.h>
47 1.47 erh #include <sys/mount.h>
48 1.1 fvdl #include <sys/malloc.h>
49 1.1 fvdl #include <sys/mbuf.h>
50 1.47 erh #include <sys/namei.h>
51 1.57 itohy #include <sys/proc.h>
52 1.93 dsl #include <sys/prot.h>
53 1.1 fvdl #include <sys/ptrace.h>
54 1.1 fvdl #include <sys/resource.h>
55 1.1 fvdl #include <sys/resourcevar.h>
56 1.64 thorpej #include <sys/time.h>
57 1.91 dsl #include <sys/vfs_syscalls.h>
58 1.1 fvdl #include <sys/wait.h>
59 1.79 elad #include <sys/kauth.h>
60 1.1 fvdl
61 1.1 fvdl #include <sys/syscallargs.h>
62 1.1 fvdl
63 1.48 christos #include <compat/linux/common/linux_types.h>
64 1.48 christos #include <compat/linux/common/linux_fcntl.h>
65 1.48 christos #include <compat/linux/common/linux_misc.h>
66 1.48 christos #include <compat/linux/common/linux_mmap.h>
67 1.48 christos #include <compat/linux/common/linux_signal.h>
68 1.48 christos #include <compat/linux/common/linux_util.h>
69 1.48 christos
70 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
71 1.26 christos
72 1.1 fvdl /*
73 1.47 erh * This file contains routines which are used
74 1.47 erh * on every linux architechture except the Alpha.
75 1.1 fvdl */
76 1.21 mycroft
77 1.47 erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
78 1.47 erh /* Not used on: alpha */
79 1.1 fvdl
80 1.70 jdolecek #ifdef DEBUG_LINUX
81 1.70 jdolecek #define DPRINTF(a) uprintf a
82 1.70 jdolecek #else
83 1.70 jdolecek #define DPRINTF(a)
84 1.70 jdolecek #endif
85 1.70 jdolecek
86 1.77 manu #ifndef COMPAT_LINUX32
87 1.87 njoly #if !defined(__m68k__) && !defined(__amd64__)
88 1.70 jdolecek static void bsd_to_linux_statfs64(const struct statvfs *,
89 1.70 jdolecek struct linux_statfs64 *);
90 1.71 he #endif
91 1.70 jdolecek
92 1.1 fvdl /*
93 1.47 erh * Alarm. This is a libc call which uses setitimer(2) in NetBSD.
94 1.47 erh * Fiddle with the timers to make it work.
95 1.1 fvdl */
96 1.1 fvdl int
97 1.64 thorpej linux_sys_alarm(l, v, retval)
98 1.64 thorpej struct lwp *l;
99 1.20 thorpej void *v;
100 1.20 thorpej register_t *retval;
101 1.20 thorpej {
102 1.47 erh struct linux_sys_alarm_args /* {
103 1.47 erh syscallarg(unsigned int) secs;
104 1.20 thorpej } */ *uap = v;
105 1.64 thorpej struct proc *p = l->l_proc;
106 1.80 kardel struct timeval now;
107 1.47 erh struct itimerval *itp, it;
108 1.64 thorpej struct ptimer *ptp;
109 1.80 kardel int s;
110 1.1 fvdl
111 1.64 thorpej if (p->p_timers && p->p_timers->pts_timers[ITIMER_REAL])
112 1.64 thorpej itp = &p->p_timers->pts_timers[ITIMER_REAL]->pt_time;
113 1.64 thorpej else
114 1.64 thorpej itp = NULL;
115 1.47 erh s = splclock();
116 1.47 erh /*
117 1.47 erh * Clear any pending timer alarms.
118 1.47 erh */
119 1.64 thorpej if (itp) {
120 1.64 thorpej callout_stop(&p->p_timers->pts_timers[ITIMER_REAL]->pt_ch);
121 1.64 thorpej timerclear(&itp->it_interval);
122 1.80 kardel getmicrotime(&now);
123 1.64 thorpej if (timerisset(&itp->it_value) &&
124 1.80 kardel timercmp(&itp->it_value, &now, >))
125 1.80 kardel timersub(&itp->it_value, &now, &itp->it_value);
126 1.64 thorpej /*
127 1.64 thorpej * Return how many seconds were left (rounded up)
128 1.64 thorpej */
129 1.64 thorpej retval[0] = itp->it_value.tv_sec;
130 1.64 thorpej if (itp->it_value.tv_usec)
131 1.64 thorpej retval[0]++;
132 1.64 thorpej } else {
133 1.64 thorpej retval[0] = 0;
134 1.73 perry }
135 1.1 fvdl
136 1.47 erh /*
137 1.47 erh * alarm(0) just resets the timer.
138 1.47 erh */
139 1.47 erh if (SCARG(uap, secs) == 0) {
140 1.64 thorpej if (itp)
141 1.64 thorpej timerclear(&itp->it_value);
142 1.47 erh splx(s);
143 1.47 erh return 0;
144 1.47 erh }
145 1.1 fvdl
146 1.47 erh /*
147 1.47 erh * Check the new alarm time for sanity, and set it.
148 1.47 erh */
149 1.47 erh timerclear(&it.it_interval);
150 1.47 erh it.it_value.tv_sec = SCARG(uap, secs);
151 1.47 erh it.it_value.tv_usec = 0;
152 1.47 erh if (itimerfix(&it.it_value) || itimerfix(&it.it_interval)) {
153 1.47 erh splx(s);
154 1.47 erh return (EINVAL);
155 1.16 fvdl }
156 1.1 fvdl
157 1.64 thorpej if (p->p_timers == NULL)
158 1.64 thorpej timers_alloc(p);
159 1.64 thorpej ptp = p->p_timers->pts_timers[ITIMER_REAL];
160 1.64 thorpej if (ptp == NULL) {
161 1.64 thorpej ptp = pool_get(&ptimer_pool, PR_WAITOK);
162 1.64 thorpej ptp->pt_ev.sigev_notify = SIGEV_SIGNAL;
163 1.64 thorpej ptp->pt_ev.sigev_signo = SIGALRM;
164 1.65 jdolecek ptp->pt_overruns = 0;
165 1.65 jdolecek ptp->pt_proc = p;
166 1.64 thorpej ptp->pt_type = CLOCK_REALTIME;
167 1.65 jdolecek ptp->pt_entry = CLOCK_REALTIME;
168 1.64 thorpej callout_init(&ptp->pt_ch);
169 1.66 enami p->p_timers->pts_timers[ITIMER_REAL] = ptp;
170 1.64 thorpej }
171 1.64 thorpej
172 1.47 erh if (timerisset(&it.it_value)) {
173 1.56 thorpej /*
174 1.56 thorpej * Don't need to check hzto() return value, here.
175 1.56 thorpej * callout_reset() does it for us.
176 1.56 thorpej */
177 1.80 kardel getmicrotime(&now);
178 1.80 kardel timeradd(&it.it_value, &now, &it.it_value);
179 1.64 thorpej callout_reset(&ptp->pt_ch, hzto(&it.it_value),
180 1.64 thorpej realtimerexpire, ptp);
181 1.16 fvdl }
182 1.64 thorpej ptp->pt_time = it;
183 1.47 erh splx(s);
184 1.1 fvdl
185 1.16 fvdl return 0;
186 1.1 fvdl }
187 1.77 manu #endif /* !COMPAT_LINUX32 */
188 1.1 fvdl
189 1.77 manu #if !defined(__amd64__) || defined(COMPAT_LINUX32)
190 1.1 fvdl int
191 1.64 thorpej linux_sys_nice(l, v, retval)
192 1.64 thorpej struct lwp *l;
193 1.20 thorpej void *v;
194 1.20 thorpej register_t *retval;
195 1.20 thorpej {
196 1.47 erh struct linux_sys_nice_args /* {
197 1.47 erh syscallarg(int) incr;
198 1.20 thorpej } */ *uap = v;
199 1.47 erh struct sys_setpriority_args bsa;
200 1.20 thorpej
201 1.47 erh SCARG(&bsa, which) = PRIO_PROCESS;
202 1.47 erh SCARG(&bsa, who) = 0;
203 1.47 erh SCARG(&bsa, prio) = SCARG(uap, incr);
204 1.64 thorpej return sys_setpriority(l, &bsa, retval);
205 1.1 fvdl }
206 1.77 manu #endif /* !__amd64__ || COMPAT_LINUX32 */
207 1.1 fvdl
208 1.77 manu #ifndef COMPAT_LINUX32
209 1.74 manu #ifndef __amd64__
210 1.1 fvdl /*
211 1.47 erh * The old Linux readdir was only able to read one entry at a time,
212 1.47 erh * even though it had a 'count' argument. In fact, the emulation
213 1.47 erh * of the old call was better than the original, because it did handle
214 1.47 erh * the count arg properly. Don't bother with it anymore now, and use
215 1.47 erh * it to distinguish between old and new. The difference is that the
216 1.47 erh * newer one actually does multiple entries, and the reclen field
217 1.47 erh * really is the reclen, not the namelength.
218 1.1 fvdl */
219 1.1 fvdl int
220 1.64 thorpej linux_sys_readdir(l, v, retval)
221 1.64 thorpej struct lwp *l;
222 1.20 thorpej void *v;
223 1.20 thorpej register_t *retval;
224 1.20 thorpej {
225 1.47 erh struct linux_sys_readdir_args /* {
226 1.47 erh syscallarg(int) fd;
227 1.47 erh syscallarg(struct linux_dirent *) dent;
228 1.47 erh syscallarg(unsigned int) count;
229 1.20 thorpej } */ *uap = v;
230 1.1 fvdl
231 1.47 erh SCARG(uap, count) = 1;
232 1.64 thorpej return linux_sys_getdents(l, uap, retval);
233 1.1 fvdl }
234 1.74 manu #endif /* !amd64 */
235 1.1 fvdl
236 1.1 fvdl /*
237 1.1 fvdl * I wonder why Linux has gettimeofday() _and_ time().. Still, we
238 1.1 fvdl * need to deal with it.
239 1.1 fvdl */
240 1.1 fvdl int
241 1.84 christos linux_sys_time(struct lwp *l, void *v, register_t *retval)
242 1.20 thorpej {
243 1.21 mycroft struct linux_sys_time_args /* {
244 1.1 fvdl linux_time_t *t;
245 1.20 thorpej } */ *uap = v;
246 1.1 fvdl struct timeval atv;
247 1.1 fvdl linux_time_t tt;
248 1.1 fvdl int error;
249 1.1 fvdl
250 1.1 fvdl microtime(&atv);
251 1.1 fvdl
252 1.1 fvdl tt = atv.tv_sec;
253 1.1 fvdl if (SCARG(uap, t) && (error = copyout(&tt, SCARG(uap, t), sizeof tt)))
254 1.1 fvdl return error;
255 1.1 fvdl
256 1.1 fvdl retval[0] = tt;
257 1.1 fvdl return 0;
258 1.1 fvdl }
259 1.1 fvdl
260 1.1 fvdl /*
261 1.73 perry * utime(). Do conversion to things that utimes() understands,
262 1.47 erh * and pass it on.
263 1.1 fvdl */
264 1.1 fvdl int
265 1.64 thorpej linux_sys_utime(l, v, retval)
266 1.64 thorpej struct lwp *l;
267 1.20 thorpej void *v;
268 1.20 thorpej register_t *retval;
269 1.20 thorpej {
270 1.47 erh struct linux_sys_utime_args /* {
271 1.50 christos syscallarg(const char *) path;
272 1.47 erh syscallarg(struct linux_utimbuf *)times;
273 1.20 thorpej } */ *uap = v;
274 1.2 fvdl int error;
275 1.47 erh struct timeval tv[2], *tvp;
276 1.47 erh struct linux_utimbuf lut;
277 1.2 fvdl
278 1.47 erh if (SCARG(uap, times) != NULL) {
279 1.47 erh if ((error = copyin(SCARG(uap, times), &lut, sizeof lut)))
280 1.47 erh return error;
281 1.47 erh tv[0].tv_usec = tv[1].tv_usec = 0;
282 1.47 erh tv[0].tv_sec = lut.l_actime;
283 1.47 erh tv[1].tv_sec = lut.l_modtime;
284 1.92 dsl tvp = tv;
285 1.92 dsl } else
286 1.92 dsl tvp = NULL;
287 1.2 fvdl
288 1.92 dsl return do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
289 1.92 dsl tvp, UIO_SYSSPACE);
290 1.1 fvdl }
291 1.1 fvdl
292 1.74 manu #ifndef __amd64__
293 1.47 erh /*
294 1.72 erh * waitpid(2). Just forward on to linux_sys_wait4 with a NULL rusage.
295 1.47 erh */
296 1.1 fvdl int
297 1.64 thorpej linux_sys_waitpid(l, v, retval)
298 1.64 thorpej struct lwp *l;
299 1.20 thorpej void *v;
300 1.20 thorpej register_t *retval;
301 1.20 thorpej {
302 1.47 erh struct linux_sys_waitpid_args /* {
303 1.47 erh syscallarg(int) pid;
304 1.47 erh syscallarg(int *) status;
305 1.47 erh syscallarg(int) options;
306 1.20 thorpej } */ *uap = v;
307 1.72 erh struct linux_sys_wait4_args linux_w4a;
308 1.2 fvdl
309 1.72 erh SCARG(&linux_w4a, pid) = SCARG(uap, pid);
310 1.72 erh SCARG(&linux_w4a, status) = SCARG(uap, status);
311 1.72 erh SCARG(&linux_w4a, options) = SCARG(uap, options);
312 1.72 erh SCARG(&linux_w4a, rusage) = NULL;
313 1.2 fvdl
314 1.72 erh return linux_sys_wait4(l, &linux_w4a, retval);
315 1.51 thorpej }
316 1.74 manu #endif /* !amd64 */
317 1.51 thorpej
318 1.51 thorpej int
319 1.84 christos linux_sys_setresgid(struct lwp *l, void *v, register_t *retval)
320 1.51 thorpej {
321 1.51 thorpej struct linux_sys_setresgid_args /* {
322 1.51 thorpej syscallarg(gid_t) rgid;
323 1.51 thorpej syscallarg(gid_t) egid;
324 1.51 thorpej syscallarg(gid_t) sgid;
325 1.51 thorpej } */ *uap = v;
326 1.51 thorpej
327 1.51 thorpej /*
328 1.51 thorpej * Note: These checks are a little different than the NetBSD
329 1.51 thorpej * setregid(2) call performs. This precisely follows the
330 1.51 thorpej * behavior of the Linux kernel.
331 1.51 thorpej */
332 1.67 dsl return do_setresgid(l, SCARG(uap,rgid), SCARG(uap, egid),
333 1.67 dsl SCARG(uap, sgid),
334 1.67 dsl ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
335 1.67 dsl ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
336 1.67 dsl ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
337 1.51 thorpej }
338 1.51 thorpej
339 1.51 thorpej int
340 1.84 christos linux_sys_getresgid(struct lwp *l, void *v, register_t *retval)
341 1.51 thorpej {
342 1.51 thorpej struct linux_sys_getresgid_args /* {
343 1.51 thorpej syscallarg(gid_t *) rgid;
344 1.51 thorpej syscallarg(gid_t *) egid;
345 1.51 thorpej syscallarg(gid_t *) sgid;
346 1.51 thorpej } */ *uap = v;
347 1.81 ad kauth_cred_t pc = l->l_cred;
348 1.51 thorpej int error;
349 1.79 elad gid_t gid;
350 1.51 thorpej
351 1.51 thorpej /*
352 1.51 thorpej * Linux copies these values out to userspace like so:
353 1.51 thorpej *
354 1.51 thorpej * 1. Copy out rgid.
355 1.51 thorpej * 2. If that succeeds, copy out egid.
356 1.51 thorpej * 3. If both of those succeed, copy out sgid.
357 1.51 thorpej */
358 1.79 elad gid = kauth_cred_getgid(pc);
359 1.79 elad if ((error = copyout(&gid, SCARG(uap, rgid), sizeof(gid_t))) != 0)
360 1.51 thorpej return (error);
361 1.51 thorpej
362 1.79 elad gid = kauth_cred_getegid(pc);
363 1.79 elad if ((error = copyout(&gid, SCARG(uap, egid), sizeof(gid_t))) != 0)
364 1.51 thorpej return (error);
365 1.51 thorpej
366 1.79 elad gid = kauth_cred_getsvgid(pc);
367 1.79 elad
368 1.79 elad return (copyout(&gid, SCARG(uap, sgid), sizeof(gid_t)));
369 1.52 tron }
370 1.52 tron
371 1.74 manu #ifndef __amd64__
372 1.52 tron /*
373 1.52 tron * I wonder why Linux has settimeofday() _and_ stime().. Still, we
374 1.52 tron * need to deal with it.
375 1.52 tron */
376 1.52 tron int
377 1.84 christos linux_sys_stime(struct lwp *l, void *v, register_t *retval)
378 1.52 tron {
379 1.52 tron struct linux_sys_time_args /* {
380 1.52 tron linux_time_t *t;
381 1.52 tron } */ *uap = v;
382 1.75 christos struct timespec ats;
383 1.52 tron linux_time_t tt;
384 1.52 tron int error;
385 1.52 tron
386 1.83 elad if ((error = kauth_authorize_system(l->l_cred,
387 1.83 elad KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, NULL, NULL,
388 1.83 elad NULL)) != 0)
389 1.52 tron return (error);
390 1.52 tron
391 1.52 tron if ((error = copyin(&tt, SCARG(uap, t), sizeof tt)) != 0)
392 1.52 tron return error;
393 1.52 tron
394 1.75 christos ats.tv_sec = tt;
395 1.75 christos ats.tv_nsec = 0;
396 1.52 tron
397 1.81 ad if ((error = settime(l->l_proc, &ats)))
398 1.52 tron return (error);
399 1.52 tron
400 1.52 tron return 0;
401 1.1 fvdl }
402 1.74 manu #endif /* !amd64 */
403 1.70 jdolecek
404 1.87 njoly #if !defined(__m68k__) && !defined(__amd64__)
405 1.70 jdolecek /*
406 1.70 jdolecek * Convert NetBSD statvfs structure to Linux statfs64 structure.
407 1.70 jdolecek * See comments in bsd_to_linux_statfs() for further background.
408 1.70 jdolecek * We can safely pass correct bsize and frsize here, since Linux glibc
409 1.70 jdolecek * statvfs() doesn't use statfs64().
410 1.70 jdolecek */
411 1.70 jdolecek static void
412 1.70 jdolecek bsd_to_linux_statfs64(bsp, lsp)
413 1.70 jdolecek const struct statvfs *bsp;
414 1.70 jdolecek struct linux_statfs64 *lsp;
415 1.70 jdolecek {
416 1.70 jdolecek int i, div;
417 1.70 jdolecek
418 1.70 jdolecek for (i = 0; i < linux_fstypes_cnt; i++) {
419 1.70 jdolecek if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
420 1.70 jdolecek lsp->l_ftype = linux_fstypes[i].linux;
421 1.70 jdolecek break;
422 1.70 jdolecek }
423 1.70 jdolecek }
424 1.70 jdolecek
425 1.70 jdolecek if (i == linux_fstypes_cnt) {
426 1.70 jdolecek DPRINTF(("unhandled fstype in linux emulation: %s\n",
427 1.70 jdolecek bsp->f_fstypename));
428 1.70 jdolecek lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
429 1.70 jdolecek }
430 1.70 jdolecek
431 1.89 christos div = bsp->f_frsize ? (bsp->f_bsize / bsp->f_frsize) : 1;
432 1.89 christos if (div == 0)
433 1.89 christos div = 1;
434 1.70 jdolecek lsp->l_fbsize = bsp->f_bsize;
435 1.70 jdolecek lsp->l_ffrsize = bsp->f_frsize;
436 1.70 jdolecek lsp->l_fblocks = bsp->f_blocks / div;
437 1.70 jdolecek lsp->l_fbfree = bsp->f_bfree / div;
438 1.70 jdolecek lsp->l_fbavail = bsp->f_bavail / div;
439 1.70 jdolecek lsp->l_ffiles = bsp->f_files;
440 1.70 jdolecek lsp->l_fffree = bsp->f_ffree / div;
441 1.70 jdolecek /* Linux sets the fsid to 0..., we don't */
442 1.70 jdolecek lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
443 1.70 jdolecek lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
444 1.70 jdolecek lsp->l_fnamelen = bsp->f_namemax;
445 1.70 jdolecek (void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
446 1.70 jdolecek }
447 1.70 jdolecek
448 1.70 jdolecek /*
449 1.70 jdolecek * Implement the fs stat functions. Straightforward.
450 1.70 jdolecek */
451 1.70 jdolecek int
452 1.70 jdolecek linux_sys_statfs64(l, v, retval)
453 1.70 jdolecek struct lwp *l;
454 1.70 jdolecek void *v;
455 1.70 jdolecek register_t *retval;
456 1.70 jdolecek {
457 1.70 jdolecek struct linux_sys_statfs64_args /* {
458 1.70 jdolecek syscallarg(const char *) path;
459 1.70 jdolecek syscallarg(size_t) sz;
460 1.70 jdolecek syscallarg(struct linux_statfs64 *) sp;
461 1.70 jdolecek } */ *uap = v;
462 1.90 dsl struct statvfs *sb;
463 1.70 jdolecek struct linux_statfs64 ltmp;
464 1.70 jdolecek int error;
465 1.70 jdolecek
466 1.70 jdolecek if (SCARG(uap, sz) != sizeof ltmp)
467 1.70 jdolecek return (EINVAL);
468 1.70 jdolecek
469 1.90 dsl sb = STATVFSBUF_GET();
470 1.90 dsl error = do_sys_pstatvfs(l, SCARG(uap, path), ST_WAIT, sb);
471 1.90 dsl if (error == 0) {
472 1.90 dsl bsd_to_linux_statfs64(sb, <mp);
473 1.90 dsl error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
474 1.78 yamt }
475 1.90 dsl STATVFSBUF_PUT(sb);
476 1.78 yamt return error;
477 1.70 jdolecek }
478 1.70 jdolecek
479 1.70 jdolecek int
480 1.70 jdolecek linux_sys_fstatfs64(l, v, retval)
481 1.70 jdolecek struct lwp *l;
482 1.70 jdolecek void *v;
483 1.70 jdolecek register_t *retval;
484 1.70 jdolecek {
485 1.70 jdolecek struct linux_sys_fstatfs64_args /* {
486 1.70 jdolecek syscallarg(int) fd;
487 1.70 jdolecek syscallarg(size_t) sz;
488 1.70 jdolecek syscallarg(struct linux_statfs64 *) sp;
489 1.70 jdolecek } */ *uap = v;
490 1.90 dsl struct statvfs *sb;
491 1.70 jdolecek struct linux_statfs64 ltmp;
492 1.70 jdolecek int error;
493 1.70 jdolecek
494 1.70 jdolecek if (SCARG(uap, sz) != sizeof ltmp)
495 1.70 jdolecek return (EINVAL);
496 1.70 jdolecek
497 1.90 dsl sb = STATVFSBUF_GET();
498 1.90 dsl error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
499 1.90 dsl if (error == 0) {
500 1.90 dsl bsd_to_linux_statfs64(sb, <mp);
501 1.90 dsl error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
502 1.78 yamt }
503 1.90 dsl STATVFSBUF_PUT(sb);
504 1.78 yamt return error;
505 1.70 jdolecek }
506 1.87 njoly #endif /* !__m68k__ && !__amd64__ */
507 1.77 manu #endif /* !COMPAT_LINUX32 */
508