vfs_syscalls_43.c revision 1.20 1 1.20 lukem /* $NetBSD: vfs_syscalls_43.c,v 1.20 2001/11/13 02:08:05 lukem Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1989, 1993
5 1.1 christos * The Regents of the University of California. All rights reserved.
6 1.1 christos * (c) UNIX System Laboratories, Inc.
7 1.1 christos * All or some portions of this file are derived from material licensed
8 1.1 christos * to the University of California by American Telephone and Telegraph
9 1.1 christos * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.1 christos * the permission of UNIX System Laboratories, Inc.
11 1.1 christos *
12 1.1 christos * Redistribution and use in source and binary forms, with or without
13 1.1 christos * modification, are permitted provided that the following conditions
14 1.1 christos * are met:
15 1.1 christos * 1. Redistributions of source code must retain the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer.
17 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 christos * notice, this list of conditions and the following disclaimer in the
19 1.1 christos * documentation and/or other materials provided with the distribution.
20 1.1 christos * 3. All advertising materials mentioning features or use of this software
21 1.1 christos * must display the following acknowledgement:
22 1.1 christos * This product includes software developed by the University of
23 1.1 christos * California, Berkeley and its contributors.
24 1.1 christos * 4. Neither the name of the University nor the names of its contributors
25 1.1 christos * may be used to endorse or promote products derived from this software
26 1.1 christos * without specific prior written permission.
27 1.1 christos *
28 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 christos * SUCH DAMAGE.
39 1.1 christos *
40 1.1 christos * @(#)vfs_syscalls.c 8.28 (Berkeley) 12/10/94
41 1.1 christos */
42 1.20 lukem
43 1.20 lukem #include <sys/cdefs.h>
44 1.20 lukem __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.20 2001/11/13 02:08:05 lukem Exp $");
45 1.9 thorpej
46 1.18 mrg #if defined(_KERNEL_OPT)
47 1.9 thorpej #include "fs_union.h"
48 1.15 jdolecek #endif
49 1.1 christos
50 1.1 christos #include <sys/param.h>
51 1.1 christos #include <sys/systm.h>
52 1.1 christos #include <sys/filedesc.h>
53 1.1 christos #include <sys/kernel.h>
54 1.1 christos #include <sys/proc.h>
55 1.1 christos #include <sys/file.h>
56 1.1 christos #include <sys/vnode.h>
57 1.1 christos #include <sys/namei.h>
58 1.1 christos #include <sys/dirent.h>
59 1.1 christos #include <sys/socket.h>
60 1.1 christos #include <sys/socketvar.h>
61 1.1 christos #include <sys/stat.h>
62 1.1 christos #include <sys/ioctl.h>
63 1.1 christos #include <sys/fcntl.h>
64 1.1 christos #include <sys/malloc.h>
65 1.1 christos #include <sys/syslog.h>
66 1.1 christos #include <sys/unistd.h>
67 1.1 christos #include <sys/resourcevar.h>
68 1.1 christos
69 1.1 christos #include <sys/mount.h>
70 1.1 christos #include <sys/syscallargs.h>
71 1.1 christos
72 1.8 christos static void cvtstat __P((struct stat *, struct stat43 *));
73 1.4 christos
74 1.1 christos /*
75 1.1 christos * Convert from an old to a new stat structure.
76 1.1 christos */
77 1.4 christos static void
78 1.1 christos cvtstat(st, ost)
79 1.1 christos struct stat *st;
80 1.8 christos struct stat43 *ost;
81 1.1 christos {
82 1.1 christos
83 1.1 christos ost->st_dev = st->st_dev;
84 1.1 christos ost->st_ino = st->st_ino;
85 1.11 wrstuden ost->st_mode = st->st_mode & 0xffff;
86 1.1 christos ost->st_nlink = st->st_nlink;
87 1.1 christos ost->st_uid = st->st_uid;
88 1.1 christos ost->st_gid = st->st_gid;
89 1.1 christos ost->st_rdev = st->st_rdev;
90 1.1 christos if (st->st_size < (quad_t)1 << 32)
91 1.1 christos ost->st_size = st->st_size;
92 1.1 christos else
93 1.1 christos ost->st_size = -2;
94 1.1 christos ost->st_atime = st->st_atime;
95 1.1 christos ost->st_mtime = st->st_mtime;
96 1.1 christos ost->st_ctime = st->st_ctime;
97 1.1 christos ost->st_blksize = st->st_blksize;
98 1.1 christos ost->st_blocks = st->st_blocks;
99 1.1 christos ost->st_flags = st->st_flags;
100 1.1 christos ost->st_gen = st->st_gen;
101 1.1 christos }
102 1.1 christos
103 1.1 christos /*
104 1.1 christos * Get file status; this version follows links.
105 1.1 christos */
106 1.1 christos /* ARGSUSED */
107 1.1 christos int
108 1.3 mycroft compat_43_sys_stat(p, v, retval)
109 1.1 christos struct proc *p;
110 1.2 thorpej void *v;
111 1.2 thorpej register_t *retval;
112 1.2 thorpej {
113 1.13 augustss struct compat_43_sys_stat_args /* {
114 1.1 christos syscallarg(char *) path;
115 1.8 christos syscallarg(struct stat43 *) ub;
116 1.2 thorpej } */ *uap = v;
117 1.1 christos struct stat sb;
118 1.8 christos struct stat43 osb;
119 1.1 christos int error;
120 1.1 christos struct nameidata nd;
121 1.1 christos
122 1.1 christos NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
123 1.1 christos SCARG(uap, path), p);
124 1.4 christos if ((error = namei(&nd)) != 0)
125 1.1 christos return (error);
126 1.1 christos error = vn_stat(nd.ni_vp, &sb, p);
127 1.1 christos vput(nd.ni_vp);
128 1.1 christos if (error)
129 1.1 christos return (error);
130 1.1 christos cvtstat(&sb, &osb);
131 1.1 christos error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb));
132 1.1 christos return (error);
133 1.1 christos }
134 1.1 christos
135 1.1 christos /*
136 1.1 christos * Get file status; this version does not follow links.
137 1.1 christos */
138 1.1 christos /* ARGSUSED */
139 1.1 christos int
140 1.3 mycroft compat_43_sys_lstat(p, v, retval)
141 1.1 christos struct proc *p;
142 1.2 thorpej void *v;
143 1.2 thorpej register_t *retval;
144 1.2 thorpej {
145 1.13 augustss struct compat_43_sys_lstat_args /* {
146 1.1 christos syscallarg(char *) path;
147 1.10 fvdl syscallarg(struct ostat *) ub;
148 1.2 thorpej } */ *uap = v;
149 1.10 fvdl struct vnode *vp, *dvp;
150 1.10 fvdl struct stat sb, sb1;
151 1.8 christos struct stat43 osb;
152 1.1 christos int error;
153 1.1 christos struct nameidata nd;
154 1.14 pk int ndflags;
155 1.1 christos
156 1.14 pk ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT;
157 1.14 pk again:
158 1.14 pk NDINIT(&nd, LOOKUP, ndflags, UIO_USERSPACE, SCARG(uap, path), p);
159 1.14 pk if ((error = namei(&nd))) {
160 1.14 pk if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
161 1.14 pk /*
162 1.14 pk * Should only happen on '/'. Retry without LOCKPARENT;
163 1.14 pk * this is safe since the vnode won't be a VLNK.
164 1.14 pk */
165 1.14 pk ndflags &= ~LOCKPARENT;
166 1.14 pk goto again;
167 1.14 pk }
168 1.5 christos return (error);
169 1.14 pk }
170 1.10 fvdl /*
171 1.10 fvdl * For symbolic links, always return the attributes of its
172 1.10 fvdl * containing directory, except for mode, size, and links.
173 1.10 fvdl */
174 1.10 fvdl vp = nd.ni_vp;
175 1.10 fvdl dvp = nd.ni_dvp;
176 1.10 fvdl if (vp->v_type != VLNK) {
177 1.14 pk if ((ndflags & LOCKPARENT) != 0) {
178 1.14 pk if (dvp == vp)
179 1.14 pk vrele(dvp);
180 1.14 pk else
181 1.14 pk vput(dvp);
182 1.14 pk }
183 1.10 fvdl error = vn_stat(vp, &sb, p);
184 1.10 fvdl vput(vp);
185 1.10 fvdl if (error)
186 1.10 fvdl return (error);
187 1.10 fvdl } else {
188 1.10 fvdl error = vn_stat(dvp, &sb, p);
189 1.10 fvdl vput(dvp);
190 1.10 fvdl if (error) {
191 1.10 fvdl vput(vp);
192 1.10 fvdl return (error);
193 1.10 fvdl }
194 1.10 fvdl error = vn_stat(vp, &sb1, p);
195 1.10 fvdl vput(vp);
196 1.10 fvdl if (error)
197 1.10 fvdl return (error);
198 1.10 fvdl sb.st_mode &= ~S_IFDIR;
199 1.10 fvdl sb.st_mode |= S_IFLNK;
200 1.10 fvdl sb.st_nlink = sb1.st_nlink;
201 1.10 fvdl sb.st_size = sb1.st_size;
202 1.10 fvdl sb.st_blocks = sb1.st_blocks;
203 1.10 fvdl }
204 1.1 christos cvtstat(&sb, &osb);
205 1.10 fvdl error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb));
206 1.1 christos return (error);
207 1.1 christos }
208 1.1 christos
209 1.1 christos /*
210 1.1 christos * Return status information about a file descriptor.
211 1.1 christos */
212 1.1 christos /* ARGSUSED */
213 1.4 christos int
214 1.3 mycroft compat_43_sys_fstat(p, v, retval)
215 1.1 christos struct proc *p;
216 1.2 thorpej void *v;
217 1.2 thorpej register_t *retval;
218 1.2 thorpej {
219 1.13 augustss struct compat_43_sys_fstat_args /* {
220 1.1 christos syscallarg(int) fd;
221 1.8 christos syscallarg(struct stat43 *) sb;
222 1.2 thorpej } */ *uap = v;
223 1.1 christos int fd = SCARG(uap, fd);
224 1.13 augustss struct filedesc *fdp = p->p_fd;
225 1.13 augustss struct file *fp;
226 1.1 christos struct stat ub;
227 1.8 christos struct stat43 oub;
228 1.1 christos int error;
229 1.1 christos
230 1.19 thorpej if ((fp = fd_getfile(fdp, fd)) == NULL)
231 1.1 christos return (EBADF);
232 1.1 christos
233 1.16 jdolecek FILE_USE(fp);
234 1.17 jdolecek error = (*fp->f_ops->fo_stat)(fp, &ub, p);
235 1.16 jdolecek FILE_UNUSE(fp, p);
236 1.16 jdolecek
237 1.16 jdolecek if (error == 0) {
238 1.16 jdolecek cvtstat(&ub, &oub);
239 1.1 christos error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb),
240 1.1 christos sizeof (oub));
241 1.16 jdolecek }
242 1.16 jdolecek
243 1.16 jdolecek
244 1.1 christos return (error);
245 1.1 christos }
246 1.1 christos
247 1.1 christos
248 1.1 christos /*
249 1.1 christos * Truncate a file given a file descriptor.
250 1.1 christos */
251 1.1 christos /* ARGSUSED */
252 1.1 christos int
253 1.3 mycroft compat_43_sys_ftruncate(p, v, retval)
254 1.1 christos struct proc *p;
255 1.2 thorpej void *v;
256 1.2 thorpej register_t *retval;
257 1.2 thorpej {
258 1.13 augustss struct compat_43_sys_ftruncate_args /* {
259 1.1 christos syscallarg(int) fd;
260 1.1 christos syscallarg(long) length;
261 1.2 thorpej } */ *uap = v;
262 1.3 mycroft struct sys_ftruncate_args /* {
263 1.1 christos syscallarg(int) fd;
264 1.1 christos syscallarg(int) pad;
265 1.1 christos syscallarg(off_t) length;
266 1.1 christos } */ nuap;
267 1.1 christos
268 1.1 christos SCARG(&nuap, fd) = SCARG(uap, fd);
269 1.1 christos SCARG(&nuap, length) = SCARG(uap, length);
270 1.3 mycroft return (sys_ftruncate(p, &nuap, retval));
271 1.1 christos }
272 1.1 christos
273 1.1 christos /*
274 1.1 christos * Truncate a file given its path name.
275 1.1 christos */
276 1.1 christos /* ARGSUSED */
277 1.1 christos int
278 1.3 mycroft compat_43_sys_truncate(p, v, retval)
279 1.1 christos struct proc *p;
280 1.2 thorpej void *v;
281 1.2 thorpej register_t *retval;
282 1.2 thorpej {
283 1.13 augustss struct compat_43_sys_truncate_args /* {
284 1.1 christos syscallarg(char *) path;
285 1.1 christos syscallarg(long) length;
286 1.2 thorpej } */ *uap = v;
287 1.3 mycroft struct sys_truncate_args /* {
288 1.1 christos syscallarg(char *) path;
289 1.1 christos syscallarg(int) pad;
290 1.1 christos syscallarg(off_t) length;
291 1.1 christos } */ nuap;
292 1.1 christos
293 1.1 christos SCARG(&nuap, path) = SCARG(uap, path);
294 1.1 christos SCARG(&nuap, length) = SCARG(uap, length);
295 1.3 mycroft return (sys_truncate(p, &nuap, retval));
296 1.1 christos }
297 1.1 christos
298 1.1 christos
299 1.1 christos /*
300 1.1 christos * Reposition read/write file offset.
301 1.1 christos */
302 1.1 christos int
303 1.3 mycroft compat_43_sys_lseek(p, v, retval)
304 1.1 christos struct proc *p;
305 1.2 thorpej void *v;
306 1.2 thorpej register_t *retval;
307 1.2 thorpej {
308 1.13 augustss struct compat_43_sys_lseek_args /* {
309 1.1 christos syscallarg(int) fd;
310 1.1 christos syscallarg(long) offset;
311 1.1 christos syscallarg(int) whence;
312 1.2 thorpej } */ *uap = v;
313 1.3 mycroft struct sys_lseek_args /* {
314 1.1 christos syscallarg(int) fd;
315 1.1 christos syscallarg(int) pad;
316 1.1 christos syscallarg(off_t) offset;
317 1.1 christos syscallarg(int) whence;
318 1.1 christos } */ nuap;
319 1.1 christos off_t qret;
320 1.1 christos int error;
321 1.1 christos
322 1.1 christos SCARG(&nuap, fd) = SCARG(uap, fd);
323 1.1 christos SCARG(&nuap, offset) = SCARG(uap, offset);
324 1.1 christos SCARG(&nuap, whence) = SCARG(uap, whence);
325 1.3 mycroft error = sys_lseek(p, &nuap, (register_t *)&qret);
326 1.1 christos *(long *)retval = qret;
327 1.1 christos return (error);
328 1.1 christos }
329 1.1 christos
330 1.1 christos
331 1.1 christos /*
332 1.1 christos * Create a file.
333 1.1 christos */
334 1.1 christos int
335 1.3 mycroft compat_43_sys_creat(p, v, retval)
336 1.1 christos struct proc *p;
337 1.2 thorpej void *v;
338 1.2 thorpej register_t *retval;
339 1.2 thorpej {
340 1.13 augustss struct compat_43_sys_creat_args /* {
341 1.1 christos syscallarg(char *) path;
342 1.1 christos syscallarg(int) mode;
343 1.2 thorpej } */ *uap = v;
344 1.3 mycroft struct sys_open_args /* {
345 1.1 christos syscallarg(char *) path;
346 1.1 christos syscallarg(int) flags;
347 1.1 christos syscallarg(int) mode;
348 1.1 christos } */ nuap;
349 1.1 christos
350 1.1 christos SCARG(&nuap, path) = SCARG(uap, path);
351 1.1 christos SCARG(&nuap, mode) = SCARG(uap, mode);
352 1.1 christos SCARG(&nuap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
353 1.3 mycroft return (sys_open(p, &nuap, retval));
354 1.1 christos }
355 1.1 christos
356 1.1 christos /*ARGSUSED*/
357 1.1 christos int
358 1.3 mycroft compat_43_sys_quota(p, v, retval)
359 1.1 christos struct proc *p;
360 1.3 mycroft void *v;
361 1.1 christos register_t *retval;
362 1.1 christos {
363 1.1 christos
364 1.1 christos return (ENOSYS);
365 1.1 christos }
366 1.1 christos
367 1.1 christos
368 1.1 christos /*
369 1.1 christos * Read a block of directory entries in a file system independent format.
370 1.1 christos */
371 1.1 christos int
372 1.3 mycroft compat_43_sys_getdirentries(p, v, retval)
373 1.1 christos struct proc *p;
374 1.2 thorpej void *v;
375 1.2 thorpej register_t *retval;
376 1.2 thorpej {
377 1.13 augustss struct compat_43_sys_getdirentries_args /* {
378 1.1 christos syscallarg(int) fd;
379 1.1 christos syscallarg(char *) buf;
380 1.1 christos syscallarg(u_int) count;
381 1.1 christos syscallarg(long *) basep;
382 1.2 thorpej } */ *uap = v;
383 1.13 augustss struct vnode *vp;
384 1.1 christos struct file *fp;
385 1.1 christos struct uio auio, kuio;
386 1.1 christos struct iovec aiov, kiov;
387 1.1 christos struct dirent *dp, *edp;
388 1.1 christos caddr_t dirbuf;
389 1.1 christos int error, eofflag, readcnt;
390 1.1 christos long loff;
391 1.1 christos
392 1.12 thorpej /* getvnode() will use the descriptor for us */
393 1.4 christos if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
394 1.1 christos return (error);
395 1.12 thorpej if ((fp->f_flag & FREAD) == 0) {
396 1.12 thorpej error = EBADF;
397 1.12 thorpej goto out;
398 1.12 thorpej }
399 1.1 christos vp = (struct vnode *)fp->f_data;
400 1.1 christos unionread:
401 1.12 thorpej if (vp->v_type != VDIR) {
402 1.12 thorpej error = EINVAL;
403 1.12 thorpej goto out;
404 1.12 thorpej }
405 1.1 christos aiov.iov_base = SCARG(uap, buf);
406 1.1 christos aiov.iov_len = SCARG(uap, count);
407 1.1 christos auio.uio_iov = &aiov;
408 1.1 christos auio.uio_iovcnt = 1;
409 1.1 christos auio.uio_rw = UIO_READ;
410 1.1 christos auio.uio_segflg = UIO_USERSPACE;
411 1.1 christos auio.uio_procp = p;
412 1.1 christos auio.uio_resid = SCARG(uap, count);
413 1.10 fvdl vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
414 1.1 christos loff = auio.uio_offset = fp->f_offset;
415 1.1 christos # if (BYTE_ORDER != LITTLE_ENDIAN)
416 1.1 christos if (vp->v_mount->mnt_maxsymlinklen <= 0) {
417 1.1 christos error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
418 1.10 fvdl (off_t **)0, (int *)0);
419 1.1 christos fp->f_offset = auio.uio_offset;
420 1.1 christos } else
421 1.1 christos # endif
422 1.1 christos {
423 1.1 christos kuio = auio;
424 1.1 christos kuio.uio_iov = &kiov;
425 1.1 christos kuio.uio_segflg = UIO_SYSSPACE;
426 1.1 christos kiov.iov_len = SCARG(uap, count);
427 1.1 christos MALLOC(dirbuf, caddr_t, SCARG(uap, count), M_TEMP, M_WAITOK);
428 1.1 christos kiov.iov_base = dirbuf;
429 1.1 christos error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
430 1.10 fvdl (off_t **)0, (int *)0);
431 1.1 christos fp->f_offset = kuio.uio_offset;
432 1.1 christos if (error == 0) {
433 1.1 christos readcnt = SCARG(uap, count) - kuio.uio_resid;
434 1.1 christos edp = (struct dirent *)&dirbuf[readcnt];
435 1.1 christos for (dp = (struct dirent *)dirbuf; dp < edp; ) {
436 1.1 christos # if (BYTE_ORDER == LITTLE_ENDIAN)
437 1.1 christos /*
438 1.1 christos * The expected low byte of
439 1.1 christos * dp->d_namlen is our dp->d_type.
440 1.1 christos * The high MBZ byte of dp->d_namlen
441 1.1 christos * is our dp->d_namlen.
442 1.1 christos */
443 1.1 christos dp->d_type = dp->d_namlen;
444 1.1 christos dp->d_namlen = 0;
445 1.1 christos # else
446 1.1 christos /*
447 1.1 christos * The dp->d_type is the high byte
448 1.1 christos * of the expected dp->d_namlen,
449 1.1 christos * so must be zero'ed.
450 1.1 christos */
451 1.1 christos dp->d_type = 0;
452 1.1 christos # endif
453 1.1 christos if (dp->d_reclen > 0) {
454 1.1 christos dp = (struct dirent *)
455 1.1 christos ((char *)dp + dp->d_reclen);
456 1.1 christos } else {
457 1.1 christos error = EIO;
458 1.1 christos break;
459 1.1 christos }
460 1.1 christos }
461 1.1 christos if (dp >= edp)
462 1.1 christos error = uiomove(dirbuf, readcnt, &auio);
463 1.1 christos }
464 1.1 christos FREE(dirbuf, M_TEMP);
465 1.1 christos }
466 1.10 fvdl VOP_UNLOCK(vp, 0);
467 1.1 christos if (error)
468 1.12 thorpej goto out;
469 1.1 christos
470 1.1 christos #ifdef UNION
471 1.1 christos {
472 1.4 christos extern int (**union_vnodeop_p) __P((void *));
473 1.1 christos extern struct vnode *union_dircache __P((struct vnode *));
474 1.1 christos
475 1.1 christos if ((SCARG(uap, count) == auio.uio_resid) &&
476 1.1 christos (vp->v_op == union_vnodeop_p)) {
477 1.1 christos struct vnode *lvp;
478 1.1 christos
479 1.1 christos lvp = union_dircache(vp);
480 1.1 christos if (lvp != NULLVP) {
481 1.1 christos struct vattr va;
482 1.1 christos
483 1.1 christos /*
484 1.1 christos * If the directory is opaque,
485 1.1 christos * then don't show lower entries
486 1.1 christos */
487 1.1 christos error = VOP_GETATTR(vp, &va, fp->f_cred, p);
488 1.1 christos if (va.va_flags & OPAQUE) {
489 1.1 christos vput(lvp);
490 1.1 christos lvp = NULL;
491 1.1 christos }
492 1.1 christos }
493 1.1 christos
494 1.1 christos if (lvp != NULLVP) {
495 1.1 christos error = VOP_OPEN(lvp, FREAD, fp->f_cred, p);
496 1.10 fvdl VOP_UNLOCK(lvp, 0);
497 1.1 christos
498 1.1 christos if (error) {
499 1.1 christos vrele(lvp);
500 1.12 thorpej goto out;
501 1.1 christos }
502 1.1 christos fp->f_data = (caddr_t) lvp;
503 1.1 christos fp->f_offset = 0;
504 1.1 christos error = vn_close(vp, FREAD, fp->f_cred, p);
505 1.1 christos if (error)
506 1.12 thorpej goto out;
507 1.1 christos vp = lvp;
508 1.1 christos goto unionread;
509 1.1 christos }
510 1.1 christos }
511 1.1 christos }
512 1.1 christos #endif /* UNION */
513 1.1 christos
514 1.1 christos if ((SCARG(uap, count) == auio.uio_resid) &&
515 1.1 christos (vp->v_flag & VROOT) &&
516 1.1 christos (vp->v_mount->mnt_flag & MNT_UNION)) {
517 1.1 christos struct vnode *tvp = vp;
518 1.1 christos vp = vp->v_mount->mnt_vnodecovered;
519 1.1 christos VREF(vp);
520 1.1 christos fp->f_data = (caddr_t) vp;
521 1.1 christos fp->f_offset = 0;
522 1.1 christos vrele(tvp);
523 1.1 christos goto unionread;
524 1.1 christos }
525 1.1 christos error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
526 1.1 christos sizeof(long));
527 1.1 christos *retval = SCARG(uap, count) - auio.uio_resid;
528 1.12 thorpej out:
529 1.12 thorpej FILE_UNUSE(fp, p);
530 1.1 christos return (error);
531 1.1 christos }
532