xref: /freebsd/sys/fs/tarfs/tarfs_vnops.c (revision 18a870751b036f1dc78b36084ccb993d139a11bb)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2013 Juniper Networks, Inc.
5  * Copyright (c) 2022-2023 Klara, Inc.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include "opt_tarfs.h"
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bio.h>
34 #include <sys/buf.h>
35 #include <sys/dirent.h>
36 #include <sys/fcntl.h>
37 #include <sys/limits.h>
38 #include <sys/mount.h>
39 #include <sys/namei.h>
40 #include <sys/proc.h>
41 #include <sys/vnode.h>
42 
43 #include <fs/tarfs/tarfs.h>
44 #include <fs/tarfs/tarfs_dbg.h>
45 
46 static int
47 tarfs_open(struct vop_open_args *ap)
48 {
49 	struct tarfs_node *tnp;
50 	struct vnode *vp;
51 
52 	vp = ap->a_vp;
53 	MPASS(VOP_ISLOCKED(vp));
54 	tnp = VP_TO_TARFS_NODE(vp);
55 
56 	TARFS_DPF(VNODE, "%s(%p=%s, %o)\n", __func__,
57 	    tnp, tnp->name, ap->a_mode);
58 
59 	if (vp->v_type != VREG && vp->v_type != VDIR)
60 		return (EOPNOTSUPP);
61 
62 	vnode_create_vobject(vp, tnp->size, ap->a_td);
63 	return (0);
64 }
65 
66 static int
67 tarfs_close(struct vop_close_args *ap)
68 {
69 #ifdef TARFS_DEBUG
70 	struct tarfs_node *tnp;
71 	struct vnode *vp;
72 
73 	vp = ap->a_vp;
74 
75 	MPASS(VOP_ISLOCKED(vp));
76 	tnp = VP_TO_TARFS_NODE(vp);
77 
78 	TARFS_DPF(VNODE, "%s(%p=%s)\n", __func__,
79 	    tnp, tnp->name);
80 #else
81 	(void)ap;
82 #endif
83 	return (0);
84 }
85 
86 static int
87 tarfs_access(struct vop_access_args *ap)
88 {
89 	struct tarfs_node *tnp;
90 	struct vnode *vp;
91 	accmode_t accmode;
92 	struct ucred *cred;
93 	int error;
94 
95 	vp = ap->a_vp;
96 	accmode = ap->a_accmode;
97 	cred = ap->a_cred;
98 
99 	MPASS(VOP_ISLOCKED(vp));
100 	tnp = VP_TO_TARFS_NODE(vp);
101 
102 	TARFS_DPF(VNODE, "%s(%p=%s, %o)\n", __func__,
103 	    tnp, tnp->name, accmode);
104 
105 	switch (vp->v_type) {
106 	case VDIR:
107 	case VLNK:
108 	case VREG:
109 		if ((accmode & VWRITE) != 0)
110 			return (EROFS);
111 		break;
112 	case VBLK:
113 	case VCHR:
114 	case VFIFO:
115 		break;
116 	default:
117 		return (EINVAL);
118 	}
119 
120 	if ((accmode & VWRITE) != 0)
121 		return (EPERM);
122 
123 	error = vaccess(vp->v_type, tnp->mode, tnp->uid,
124 	    tnp->gid, accmode, cred);
125 	return (error);
126 }
127 
128 static int
129 tarfs_bmap(struct vop_bmap_args *ap)
130 {
131 	struct tarfs_node *tnp;
132 	struct vnode *vp;
133 	off_t off;
134 	uint64_t iosize;
135 	int ra, rb, rmax;
136 
137 	vp = ap->a_vp;
138 	iosize = vp->v_mount->mnt_stat.f_iosize;
139 
140 	if (ap->a_bop != NULL)
141 		*ap->a_bop = &vp->v_bufobj;
142 	if (ap->a_bnp != NULL)
143 		*ap->a_bnp = ap->a_bn * btodb(iosize);
144 	if (ap->a_runp == NULL)
145 		return (0);
146 
147 	tnp = VP_TO_TARFS_NODE(vp);
148 	off = ap->a_bn * iosize;
149 
150 	ra = rb = 0;
151 	for (u_int i = 0; i < tnp->nblk; i++) {
152 		off_t bs, be;
153 
154 		bs = tnp->blk[i].o;
155 		be = tnp->blk[i].o + tnp->blk[i].l;
156 		if (off > be)
157 			continue;
158 		else if (off < bs) {
159 			/* We're in a hole. */
160 			ra = bs - off < iosize ?
161 			    0 : howmany(bs - (off + iosize), iosize);
162 			rb = howmany(off - (i == 0 ?
163 			    0 : tnp->blk[i - 1].o + tnp->blk[i - 1].l),
164 			    iosize);
165 			break;
166 		} else {
167 			/* We'll be reading from the backing file. */
168 			ra = be - off < iosize ?
169 			    0 : howmany(be - (off + iosize), iosize);
170 			rb = howmany(off - bs, iosize);
171 			break;
172 		}
173 	}
174 
175 	rmax = vp->v_mount->mnt_iosize_max / iosize - 1;
176 	*ap->a_runp = imin(ra, rmax);
177 	if (ap->a_runb != NULL)
178 		*ap->a_runb = imin(rb, rmax);
179 	return (0);
180 }
181 
182 static int
183 tarfs_getattr(struct vop_getattr_args *ap)
184 {
185 	struct tarfs_node *tnp;
186 	struct vnode *vp;
187 	struct vattr *vap;
188 
189 	vp = ap->a_vp;
190 	vap = ap->a_vap;
191 	tnp = VP_TO_TARFS_NODE(vp);
192 
193 	TARFS_DPF(VNODE, "%s(%p=%s)\n", __func__,
194 	    tnp, tnp->name);
195 
196 	vap->va_type = vp->v_type;
197 	vap->va_mode = tnp->mode;
198 	vap->va_nlink = tnp->nlink;
199 	vap->va_gid = tnp->gid;
200 	vap->va_uid = tnp->uid;
201 	vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
202 	vap->va_fileid = tnp->ino;
203 	vap->va_size = tnp->size;
204 	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
205 	vap->va_atime = tnp->atime;
206 	vap->va_ctime = tnp->ctime;
207 	vap->va_mtime = tnp->mtime;
208 	vap->va_birthtime = tnp->birthtime;
209 	vap->va_gen = tnp->gen;
210 	vap->va_flags = tnp->flags;
211 	vap->va_rdev = VN_ISDEV(vp) ? tnp->rdev : NODEV;
212 	vap->va_bytes = round_page(tnp->physize);
213 	vap->va_filerev = 0;
214 
215 	return (0);
216 }
217 
218 static int
219 tarfs_lookup(struct vop_cachedlookup_args *ap)
220 {
221 	struct tarfs_mount *tmp;
222 	struct tarfs_node *dirnode, *parent, *tnp;
223 	struct componentname *cnp;
224 	struct vnode *dvp, **vpp;
225 #ifdef TARFS_DEBUG
226 	struct vnode *vp;
227 #endif
228 	int error;
229 
230 	dvp = ap->a_dvp;
231 	vpp = ap->a_vpp;
232 	cnp = ap->a_cnp;
233 
234 	*vpp = NULLVP;
235 	dirnode = VP_TO_TARFS_NODE(dvp);
236 	parent = dirnode->parent;
237 	tmp = dirnode->tmp;
238 	tnp = NULL;
239 
240 	TARFS_DPF(LOOKUP, "%s(%p=%s, %.*s)\n", __func__,
241 	    dirnode, dirnode->name,
242 	    (int)cnp->cn_namelen, cnp->cn_nameptr);
243 
244 	error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, curthread);
245 	if (error != 0)
246 		return (error);
247 
248 	if (cnp->cn_flags & ISDOTDOT) {
249 		/* Do not allow .. on the root node */
250 		if (parent == NULL || parent == dirnode)
251 			return (ENOENT);
252 
253 		/* Allocate a new vnode on the matching entry */
254 		error = vn_vget_ino(dvp, parent->ino, cnp->cn_lkflags,
255 		    vpp);
256 		if (error != 0)
257 			return (error);
258 	} else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
259 		VREF(dvp);
260 		*vpp = dvp;
261 #ifdef TARFS_DEBUG
262 	} else if (dirnode == dirnode->tmp->root &&
263 	    (vp = dirnode->tmp->znode) != NULL &&
264 	    cnp->cn_namelen == TARFS_ZIO_NAMELEN &&
265 	    memcmp(cnp->cn_nameptr, TARFS_ZIO_NAME, TARFS_ZIO_NAMELEN) == 0) {
266 		error = vn_lock(vp, cnp->cn_lkflags);
267 		if (error != 0)
268 			return (error);
269 		vref(vp);
270 		*vpp = vp;
271 		return (0);
272 #endif
273 	} else {
274 		tnp = tarfs_lookup_node(dirnode, NULL, cnp);
275 		if (tnp == NULL) {
276 			TARFS_DPF(LOOKUP, "%s(%p=%s, %.*s): file not found\n", __func__,
277 			    dirnode, dirnode->name,
278 			    (int)cnp->cn_namelen, cnp->cn_nameptr);
279 			return (ENOENT);
280 		}
281 
282 		if ((cnp->cn_flags & ISLASTCN) == 0 &&
283 		    (tnp->type != VDIR && tnp->type != VLNK))
284 			return (ENOTDIR);
285 
286 		error = VFS_VGET(tmp->vfs, tnp->ino, cnp->cn_lkflags, vpp);
287 		if (error != 0)
288 			return (error);
289 	}
290 
291 #ifdef	TARFS_DEBUG
292 	if (tnp == NULL)
293 		tnp = VP_TO_TARFS_NODE(*vpp);
294 	TARFS_DPF(LOOKUP, "%s: found vnode %p, tarfs_node %p\n", __func__,
295 	    *vpp, tnp);
296 #endif	/* TARFS_DEBUG */
297 
298 	/* Store the result of the cache if MAKEENTRY is specified in flags */
299 	if ((cnp->cn_flags & MAKEENTRY) != 0 && cnp->cn_nameiop != CREATE)
300 		cache_enter(dvp, *vpp, cnp);
301 
302 	return (error);
303 }
304 
305 static int
306 tarfs_readdir(struct vop_readdir_args *ap)
307 {
308 	struct dirent cde = { };
309 	struct tarfs_node *current, *tnp;
310 	struct vnode *vp;
311 	struct uio *uio;
312 	int *eofflag;
313 	uint64_t **cookies;
314 	int *ncookies;
315 	off_t off;
316 	u_int idx, ndirents;
317 	int error;
318 
319 	vp = ap->a_vp;
320 	uio = ap->a_uio;
321 	eofflag = ap->a_eofflag;
322 	cookies = ap->a_cookies;
323 	ncookies = ap->a_ncookies;
324 
325 	if (vp->v_type != VDIR)
326 		return (ENOTDIR);
327 
328 	tnp = VP_TO_TARFS_NODE(vp);
329 	off = uio->uio_offset;
330 	current = NULL;
331 	ndirents = 0;
332 
333 	TARFS_DPF(VNODE, "%s(%p=%s, %zu, %zd)\n", __func__,
334 	    tnp, tnp->name, uio->uio_offset, uio->uio_resid);
335 
336 	if (uio->uio_offset == TARFS_COOKIE_EOF) {
337 		TARFS_DPF(VNODE, "%s: EOF\n", __func__);
338 		return (0);
339 	}
340 
341 	if (uio->uio_offset == TARFS_COOKIE_DOT) {
342 		TARFS_DPF(VNODE, "%s: Generating . entry\n", __func__);
343 		/* fake . entry */
344 		cde.d_fileno = tnp->ino;
345 		cde.d_type = DT_DIR;
346 		cde.d_namlen = 1;
347 		cde.d_name[0] = '.';
348 		cde.d_name[1] = '\0';
349 		cde.d_reclen = GENERIC_DIRSIZ(&cde);
350 		if (cde.d_reclen > uio->uio_resid)
351 			goto full;
352 		dirent_terminate(&cde);
353 		error = uiomove(&cde, cde.d_reclen, uio);
354 		if (error)
355 			return (error);
356 		/* next is .. */
357 		uio->uio_offset = TARFS_COOKIE_DOTDOT;
358 		ndirents++;
359 	}
360 
361 	if (uio->uio_offset == TARFS_COOKIE_DOTDOT) {
362 		TARFS_DPF(VNODE, "%s: Generating .. entry\n", __func__);
363 		/* fake .. entry */
364 		MPASS(tnp->parent != NULL);
365 		TARFS_NODE_LOCK(tnp->parent);
366 		cde.d_fileno = tnp->parent->ino;
367 		TARFS_NODE_UNLOCK(tnp->parent);
368 		cde.d_type = DT_DIR;
369 		cde.d_namlen = 2;
370 		cde.d_name[0] = '.';
371 		cde.d_name[1] = '.';
372 		cde.d_name[2] = '\0';
373 		cde.d_reclen = GENERIC_DIRSIZ(&cde);
374 		if (cde.d_reclen > uio->uio_resid)
375 			goto full;
376 		dirent_terminate(&cde);
377 		error = uiomove(&cde, cde.d_reclen, uio);
378 		if (error)
379 			return (error);
380 		/* next is first child */
381 		current = TAILQ_FIRST(&tnp->dir.dirhead);
382 		if (current == NULL)
383 			goto done;
384 		uio->uio_offset = current->ino;
385 		TARFS_DPF(VNODE, "%s: [%u] setting current node to %p=%s\n",
386 		    __func__, ndirents, current, current->name);
387 		ndirents++;
388 	}
389 
390 	/* resuming previous call */
391 	if (current == NULL) {
392 		current = tarfs_lookup_dir(tnp, uio->uio_offset);
393 		if (current == NULL) {
394 			error = EINVAL;
395 			goto done;
396 		}
397 		uio->uio_offset = current->ino;
398 		TARFS_DPF(VNODE, "%s: [%u] setting current node to %p=%s\n",
399 		    __func__, ndirents, current, current->name);
400 	}
401 
402 	for (;;) {
403 		cde.d_fileno = current->ino;
404 		switch (current->type) {
405 		case VBLK:
406 			cde.d_type = DT_BLK;
407 			break;
408 		case VCHR:
409 			cde.d_type = DT_CHR;
410 			break;
411 		case VDIR:
412 			cde.d_type = DT_DIR;
413 			break;
414 		case VFIFO:
415 			cde.d_type = DT_FIFO;
416 			break;
417 		case VLNK:
418 			cde.d_type = DT_LNK;
419 			break;
420 		case VREG:
421 			cde.d_type = DT_REG;
422 			break;
423 		default:
424 			panic("%s: tarfs_node %p, type %d\n", __func__,
425 			    current, current->type);
426 		}
427 		cde.d_namlen = current->namelen;
428 		MPASS(tnp->namelen < sizeof(cde.d_name));
429 		(void)memcpy(cde.d_name, current->name, current->namelen);
430 		cde.d_name[current->namelen] = '\0';
431 		cde.d_reclen = GENERIC_DIRSIZ(&cde);
432 		if (cde.d_reclen > uio->uio_resid)
433 			goto full;
434 		dirent_terminate(&cde);
435 		error = uiomove(&cde, cde.d_reclen, uio);
436 		if (error != 0)
437 			goto done;
438 		ndirents++;
439 		/* next sibling */
440 		current = TAILQ_NEXT(current, dirents);
441 		if (current == NULL)
442 			goto done;
443 		uio->uio_offset = current->ino;
444 		TARFS_DPF(VNODE, "%s: [%u] setting current node to %p=%s\n",
445 		    __func__, ndirents, current, current->name);
446 	}
447 full:
448 	if (cde.d_reclen > uio->uio_resid) {
449 		TARFS_DPF(VNODE, "%s: out of space, returning\n",
450 		    __func__);
451 		error = (ndirents == 0) ? EINVAL : 0;
452 	}
453 done:
454 	TARFS_DPF(VNODE, "%s: %u entries written\n", __func__, ndirents);
455 	TARFS_DPF(VNODE, "%s: saving cache information\n", __func__);
456 	if (current == NULL) {
457 		uio->uio_offset = TARFS_COOKIE_EOF;
458 		tnp->dir.lastcookie = 0;
459 		tnp->dir.lastnode = NULL;
460 	} else {
461 		tnp->dir.lastcookie = current->ino;
462 		tnp->dir.lastnode = current;
463 	}
464 
465 	if (eofflag != NULL) {
466 		TARFS_DPF(VNODE, "%s: Setting EOF flag\n", __func__);
467 		*eofflag = (error == 0 && current == NULL);
468 	}
469 
470 	/* Update for NFS */
471 	if (error == 0 && cookies != NULL && ncookies != NULL) {
472 		TARFS_DPF(VNODE, "%s: Updating NFS cookies\n", __func__);
473 		current = NULL;
474 		*cookies = malloc(ndirents * sizeof(off_t), M_TEMP, M_WAITOK);
475 		*ncookies = ndirents;
476 		for (idx = 0; idx < ndirents; idx++) {
477 			if (off == TARFS_COOKIE_DOT)
478 				off = TARFS_COOKIE_DOTDOT;
479 			else {
480 				if (off == TARFS_COOKIE_DOTDOT) {
481 					current = TAILQ_FIRST(&tnp->dir.dirhead);
482 				} else if (current != NULL) {
483 					current = TAILQ_NEXT(current, dirents);
484 				} else {
485 					current = tarfs_lookup_dir(tnp, off);
486 					current = TAILQ_NEXT(current, dirents);
487 				}
488 				if (current == NULL)
489 					off = TARFS_COOKIE_EOF;
490 				else
491 					off = current->ino;
492 			}
493 
494 			TARFS_DPF(VNODE, "%s: [%u] offset %zu\n", __func__,
495 			    idx, off);
496 			(*cookies)[idx] = off;
497 		}
498 		MPASS(uio->uio_offset == off);
499 	}
500 
501 	return (error);
502 }
503 
504 static int
505 tarfs_read(struct vop_read_args *ap)
506 {
507 	struct tarfs_node *tnp;
508 	struct uio *uiop;
509 	struct vnode *vp;
510 	size_t len;
511 	off_t resid;
512 	int error;
513 
514 	uiop = ap->a_uio;
515 	vp = ap->a_vp;
516 
517 	if (VN_ISDEV(vp))
518 		return (EOPNOTSUPP);
519 
520 	if (vp->v_type != VREG)
521 		return (EISDIR);
522 
523 	if (uiop->uio_offset < 0)
524 		return (EINVAL);
525 
526 	tnp = VP_TO_TARFS_NODE(vp);
527 	error = 0;
528 
529 	TARFS_DPF(VNODE, "%s(%p=%s, %zu, %zd)\n", __func__,
530 	    tnp, tnp->name, uiop->uio_offset, uiop->uio_resid);
531 
532 	while ((resid = uiop->uio_resid) > 0) {
533 		if (tnp->size <= uiop->uio_offset)
534 			break;
535 		len = MIN(tnp->size - uiop->uio_offset, resid);
536 		if (len == 0)
537 			break;
538 
539 		error = tarfs_read_file(tnp, len, uiop);
540 		if (error != 0 || resid == uiop->uio_resid)
541 			break;
542 	}
543 
544 	return (error);
545 }
546 
547 static int
548 tarfs_readlink(struct vop_readlink_args *ap)
549 {
550 	struct tarfs_node *tnp;
551 	struct uio *uiop;
552 	struct vnode *vp;
553 	int error;
554 
555 	uiop = ap->a_uio;
556 	vp = ap->a_vp;
557 
558 	MPASS(uiop->uio_offset == 0);
559 	MPASS(vp->v_type == VLNK);
560 
561 	tnp = VP_TO_TARFS_NODE(vp);
562 
563 	TARFS_DPF(VNODE, "%s(%p=%s)\n", __func__,
564 	    tnp, tnp->name);
565 
566 	error = uiomove(tnp->link.name,
567 	    MIN(tnp->size, uiop->uio_resid), uiop);
568 
569 	return (error);
570 }
571 
572 static int
573 tarfs_reclaim(struct vop_reclaim_args *ap)
574 {
575 	struct tarfs_node *tnp;
576 	struct vnode *vp;
577 
578 	vp = ap->a_vp;
579 	tnp = VP_TO_TARFS_NODE(vp);
580 
581 	vfs_hash_remove(vp);
582 
583 	TARFS_NODE_LOCK(tnp);
584 	tnp->vnode = NULLVP;
585 	vp->v_data = NULL;
586 	TARFS_NODE_UNLOCK(tnp);
587 
588 	return (0);
589 }
590 
591 static int
592 tarfs_print(struct vop_print_args *ap)
593 {
594 	struct tarfs_node *tnp;
595 	struct vnode *vp;
596 
597 	vp = ap->a_vp;
598 	tnp = VP_TO_TARFS_NODE(vp);
599 
600 	printf("tag tarfs, tarfs_node %p, links %lu\n",
601 	    tnp, (unsigned long)tnp->nlink);
602 	printf("\tmode 0%o, owner %d, group %d, size %zd\n",
603 	    tnp->mode, tnp->uid, tnp->gid,
604 	    tnp->size);
605 
606 	if (vp->v_type == VFIFO)
607 		fifo_printinfo(vp);
608 
609 	printf("\n");
610 
611 	return (0);
612 }
613 
614 static int
615 tarfs_strategy(struct vop_strategy_args *ap)
616 {
617 	struct uio auio;
618 	struct iovec iov;
619 	struct tarfs_node *tnp;
620 	struct buf *bp;
621 	off_t off;
622 	size_t len;
623 	int error;
624 
625 	tnp = VP_TO_TARFS_NODE(ap->a_vp);
626 	bp = ap->a_bp;
627 	MPASS(bp->b_iocmd == BIO_READ);
628 	MPASS(bp->b_iooffset >= 0);
629 	MPASS(bp->b_bcount > 0);
630 	MPASS(bp->b_bufsize >= bp->b_bcount);
631 	TARFS_DPF(VNODE, "%s(%p=%s, %zu, %ld/%ld)\n", __func__, tnp,
632 	    tnp->name, (size_t)bp->b_iooffset, bp->b_bcount, bp->b_bufsize);
633 	iov.iov_base = bp->b_data;
634 	iov.iov_len = bp->b_bcount;
635 	off = bp->b_iooffset;
636 	len = bp->b_bcount;
637 	bp->b_resid = len;
638 	if (off > tnp->size) {
639 		/* XXX read beyond EOF - figure out correct handling */
640 		error = EIO;
641 		goto out;
642 	}
643 	if (off + len > tnp->size) {
644 		/* clip to file length */
645 		len = tnp->size - off;
646 	}
647 	auio.uio_iov = &iov;
648 	auio.uio_iovcnt = 1;
649 	auio.uio_offset = off;
650 	auio.uio_resid = len;
651 	auio.uio_segflg = UIO_SYSSPACE;
652 	auio.uio_rw = UIO_READ;
653 	auio.uio_td = curthread;
654 	error = tarfs_read_file(tnp, len, &auio);
655 	bp->b_resid -= len - auio.uio_resid;
656 out:
657 	if (error != 0) {
658 		bp->b_ioflags |= BIO_ERROR;
659 		bp->b_error = error;
660 	}
661 	bp->b_flags |= B_DONE;
662 	return (0);
663 }
664 
665 static int
666 tarfs_vptofh(struct vop_vptofh_args *ap)
667 {
668 	struct tarfs_fid *tfp;
669 	struct tarfs_node *tnp;
670 	_Static_assert(sizeof(struct tarfs_fid) <= sizeof(struct fid),
671 	    "struct tarfs_fid cannot be larger than struct fid");
672 
673 	tfp = (struct tarfs_fid *)ap->a_fhp;
674 	tnp = VP_TO_TARFS_NODE(ap->a_vp);
675 
676 	tfp->len = sizeof(struct tarfs_fid);
677 	tfp->ino = tnp->ino;
678 	tfp->gen = tnp->gen;
679 
680 	return (0);
681 }
682 
683 struct vop_vector tarfs_vnodeops = {
684 	.vop_default =		&default_vnodeops,
685 
686 	.vop_access =		tarfs_access,
687 	.vop_bmap =		tarfs_bmap,
688 	.vop_cachedlookup =	tarfs_lookup,
689 	.vop_close =		tarfs_close,
690 	.vop_getattr =		tarfs_getattr,
691 	.vop_lookup =		vfs_cache_lookup,
692 	.vop_open =		tarfs_open,
693 	.vop_print =		tarfs_print,
694 	.vop_read =		tarfs_read,
695 	.vop_readdir =		tarfs_readdir,
696 	.vop_readlink =		tarfs_readlink,
697 	.vop_reclaim =		tarfs_reclaim,
698 	.vop_strategy =		tarfs_strategy,
699 	.vop_vptofh =		tarfs_vptofh,
700 };
701 VFS_VOP_VECTOR_REGISTER(tarfs_vnodeops);
702