xref: /minix3/sys/fs/udf/udf_vnops.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: udf_vnops.c,v 1.101 2015/04/20 23:03:08 riastradh Exp $ */
29f988b79SJean-Baptiste Boric 
39f988b79SJean-Baptiste Boric /*
49f988b79SJean-Baptiste Boric  * Copyright (c) 2006, 2008 Reinoud Zandijk
59f988b79SJean-Baptiste Boric  * All rights reserved.
69f988b79SJean-Baptiste Boric  *
79f988b79SJean-Baptiste Boric  * Redistribution and use in source and binary forms, with or without
89f988b79SJean-Baptiste Boric  * modification, are permitted provided that the following conditions
99f988b79SJean-Baptiste Boric  * are met:
109f988b79SJean-Baptiste Boric  * 1. Redistributions of source code must retain the above copyright
119f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer.
129f988b79SJean-Baptiste Boric  * 2. Redistributions in binary form must reproduce the above copyright
139f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer in the
149f988b79SJean-Baptiste Boric  *    documentation and/or other materials provided with the distribution.
159f988b79SJean-Baptiste Boric  *
169f988b79SJean-Baptiste Boric  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
179f988b79SJean-Baptiste Boric  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189f988b79SJean-Baptiste Boric  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199f988b79SJean-Baptiste Boric  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
209f988b79SJean-Baptiste Boric  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
219f988b79SJean-Baptiste Boric  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
229f988b79SJean-Baptiste Boric  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239f988b79SJean-Baptiste Boric  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
249f988b79SJean-Baptiste Boric  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
259f988b79SJean-Baptiste Boric  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
269f988b79SJean-Baptiste Boric  *
279f988b79SJean-Baptiste Boric  * Generic parts are derived from software contributed to The NetBSD Foundation
289f988b79SJean-Baptiste Boric  * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
299f988b79SJean-Baptiste Boric  * 2005 program.
309f988b79SJean-Baptiste Boric  *
319f988b79SJean-Baptiste Boric  */
329f988b79SJean-Baptiste Boric 
339f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
349f988b79SJean-Baptiste Boric #ifndef lint
35*0a6a1f1dSLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.101 2015/04/20 23:03:08 riastradh Exp $");
369f988b79SJean-Baptiste Boric #endif /* not lint */
379f988b79SJean-Baptiste Boric 
389f988b79SJean-Baptiste Boric 
399f988b79SJean-Baptiste Boric #include <sys/param.h>
409f988b79SJean-Baptiste Boric #include <sys/systm.h>
419f988b79SJean-Baptiste Boric #include <sys/namei.h>
429f988b79SJean-Baptiste Boric #include <sys/resourcevar.h>	/* defines plimit structure in proc struct */
439f988b79SJean-Baptiste Boric #include <sys/kernel.h>
449f988b79SJean-Baptiste Boric #include <sys/file.h>		/* define FWRITE ... */
459f988b79SJean-Baptiste Boric #include <sys/stat.h>
469f988b79SJean-Baptiste Boric #include <sys/buf.h>
479f988b79SJean-Baptiste Boric #include <sys/proc.h>
489f988b79SJean-Baptiste Boric #include <sys/mount.h>
499f988b79SJean-Baptiste Boric #include <sys/vnode.h>
509f988b79SJean-Baptiste Boric #include <sys/signalvar.h>
519f988b79SJean-Baptiste Boric #include <sys/malloc.h>
529f988b79SJean-Baptiste Boric #include <sys/dirent.h>
539f988b79SJean-Baptiste Boric #include <sys/lockf.h>
549f988b79SJean-Baptiste Boric #include <sys/kauth.h>
559f988b79SJean-Baptiste Boric 
569f988b79SJean-Baptiste Boric #include <miscfs/genfs/genfs.h>
579f988b79SJean-Baptiste Boric #include <uvm/uvm_extern.h>
589f988b79SJean-Baptiste Boric 
599f988b79SJean-Baptiste Boric #include <fs/udf/ecma167-udf.h>
609f988b79SJean-Baptiste Boric #include <fs/udf/udf_mount.h>
619f988b79SJean-Baptiste Boric #include <sys/dirhash.h>
629f988b79SJean-Baptiste Boric 
639f988b79SJean-Baptiste Boric #include "udf.h"
649f988b79SJean-Baptiste Boric #include "udf_subr.h"
659f988b79SJean-Baptiste Boric #include "udf_bswap.h"
669f988b79SJean-Baptiste Boric 
679f988b79SJean-Baptiste Boric 
689f988b79SJean-Baptiste Boric #define VTOI(vnode) ((struct udf_node *) (vnode)->v_data)
699f988b79SJean-Baptiste Boric 
70*0a6a1f1dSLionel Sambuc /* forward declarations */
71*0a6a1f1dSLionel Sambuc static int udf_do_readlink(struct udf_node *udf_node, uint64_t filesize,
72*0a6a1f1dSLionel Sambuc 	uint8_t *targetbuf, int *length);
739f988b79SJean-Baptiste Boric 
749f988b79SJean-Baptiste Boric /* externs */
759f988b79SJean-Baptiste Boric extern int prtactive;
769f988b79SJean-Baptiste Boric 
779f988b79SJean-Baptiste Boric /* implementations of vnode functions; table follows at end */
789f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
799f988b79SJean-Baptiste Boric 
809f988b79SJean-Baptiste Boric int
udf_inactive(void * v)819f988b79SJean-Baptiste Boric udf_inactive(void *v)
829f988b79SJean-Baptiste Boric {
839f988b79SJean-Baptiste Boric 	struct vop_inactive_args /* {
849f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
859f988b79SJean-Baptiste Boric 		bool         *a_recycle;
869f988b79SJean-Baptiste Boric 	} */ *ap = v;
879f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
889f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
899f988b79SJean-Baptiste Boric 	int refcnt;
909f988b79SJean-Baptiste Boric 
919f988b79SJean-Baptiste Boric 	DPRINTF(NODE, ("udf_inactive called for udf_node %p\n", VTOI(vp)));
929f988b79SJean-Baptiste Boric 
939f988b79SJean-Baptiste Boric 	if (udf_node == NULL) {
949f988b79SJean-Baptiste Boric 		DPRINTF(NODE, ("udf_inactive: inactive NULL UDF node\n"));
959f988b79SJean-Baptiste Boric 		VOP_UNLOCK(vp);
969f988b79SJean-Baptiste Boric 		return 0;
979f988b79SJean-Baptiste Boric 	}
989f988b79SJean-Baptiste Boric 
999f988b79SJean-Baptiste Boric 	/*
100*0a6a1f1dSLionel Sambuc 	 * Optionally flush metadata to disc.
1019f988b79SJean-Baptiste Boric 	 */
1029f988b79SJean-Baptiste Boric 	if (udf_node->fe) {
1039f988b79SJean-Baptiste Boric 		refcnt = udf_rw16(udf_node->fe->link_cnt);
1049f988b79SJean-Baptiste Boric 	} else {
1059f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
1069f988b79SJean-Baptiste Boric 		refcnt = udf_rw16(udf_node->efe->link_cnt);
1079f988b79SJean-Baptiste Boric 	}
1089f988b79SJean-Baptiste Boric 
1099f988b79SJean-Baptiste Boric 	if ((refcnt == 0) && (vp->v_vflag & VV_SYSTEM)) {
1109f988b79SJean-Baptiste Boric 		DPRINTF(VOLUMES, ("UDF_INACTIVE deleting VV_SYSTEM\n"));
1119f988b79SJean-Baptiste Boric 		/* system nodes are not writen out on inactive, so flush */
1129f988b79SJean-Baptiste Boric 		udf_node->i_flags = 0;
1139f988b79SJean-Baptiste Boric 	}
1149f988b79SJean-Baptiste Boric 
1159f988b79SJean-Baptiste Boric 	*ap->a_recycle = false;
1169f988b79SJean-Baptiste Boric 	if ((refcnt == 0) && ((vp->v_vflag & VV_SYSTEM) == 0)) {
1179f988b79SJean-Baptiste Boric 		*ap->a_recycle = true;
1189f988b79SJean-Baptiste Boric 		VOP_UNLOCK(vp);
1199f988b79SJean-Baptiste Boric 		return 0;
1209f988b79SJean-Baptiste Boric 	}
1219f988b79SJean-Baptiste Boric 
1229f988b79SJean-Baptiste Boric 	/* write out its node */
1239f988b79SJean-Baptiste Boric 	if (udf_node->i_flags & (IN_CHANGE | IN_UPDATE | IN_MODIFIED))
1249f988b79SJean-Baptiste Boric 		udf_update(vp, NULL, NULL, NULL, 0);
1259f988b79SJean-Baptiste Boric 	VOP_UNLOCK(vp);
1269f988b79SJean-Baptiste Boric 
1279f988b79SJean-Baptiste Boric 	return 0;
1289f988b79SJean-Baptiste Boric }
1299f988b79SJean-Baptiste Boric 
1309f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
1319f988b79SJean-Baptiste Boric 
1329f988b79SJean-Baptiste Boric int
udf_reclaim(void * v)1339f988b79SJean-Baptiste Boric udf_reclaim(void *v)
1349f988b79SJean-Baptiste Boric {
1359f988b79SJean-Baptiste Boric 	struct vop_reclaim_args /* {
1369f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
1379f988b79SJean-Baptiste Boric 	} */ *ap = v;
1389f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
1399f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
140*0a6a1f1dSLionel Sambuc 	int refcnt;
1419f988b79SJean-Baptiste Boric 
1429f988b79SJean-Baptiste Boric 	DPRINTF(NODE, ("udf_reclaim called for node %p\n", udf_node));
1439f988b79SJean-Baptiste Boric 	if (prtactive && vp->v_usecount > 1)
1449f988b79SJean-Baptiste Boric 		vprint("udf_reclaim(): pushing active", vp);
1459f988b79SJean-Baptiste Boric 
1469f988b79SJean-Baptiste Boric 	if (udf_node == NULL) {
1479f988b79SJean-Baptiste Boric 		DPRINTF(NODE, ("udf_reclaim(): null udfnode\n"));
1489f988b79SJean-Baptiste Boric 		return 0;
1499f988b79SJean-Baptiste Boric 	}
1509f988b79SJean-Baptiste Boric 
151*0a6a1f1dSLionel Sambuc 	/*
152*0a6a1f1dSLionel Sambuc 	 * If the file has not been referenced anymore in a directory
153*0a6a1f1dSLionel Sambuc 	 * we ought to free up the resources on disc if applicable.
154*0a6a1f1dSLionel Sambuc 	 */
155*0a6a1f1dSLionel Sambuc 	if (udf_node->fe) {
156*0a6a1f1dSLionel Sambuc 		refcnt = udf_rw16(udf_node->fe->link_cnt);
157*0a6a1f1dSLionel Sambuc 	} else {
158*0a6a1f1dSLionel Sambuc 		assert(udf_node->efe);
159*0a6a1f1dSLionel Sambuc 		refcnt = udf_rw16(udf_node->efe->link_cnt);
160*0a6a1f1dSLionel Sambuc 	}
161*0a6a1f1dSLionel Sambuc 
162*0a6a1f1dSLionel Sambuc 	if ((refcnt == 0) && ((vp->v_vflag & VV_SYSTEM) == 0)) {
163*0a6a1f1dSLionel Sambuc 	 	/* remove this file's allocation */
164*0a6a1f1dSLionel Sambuc 		DPRINTF(NODE, ("udf_inactive deleting unlinked file\n"));
165*0a6a1f1dSLionel Sambuc 		udf_delete_node(udf_node);
166*0a6a1f1dSLionel Sambuc 	}
167*0a6a1f1dSLionel Sambuc 
1689f988b79SJean-Baptiste Boric 	/* update note for closure */
1699f988b79SJean-Baptiste Boric 	udf_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
1709f988b79SJean-Baptiste Boric 
1719f988b79SJean-Baptiste Boric 	/* async check to see if all node descriptors are written out */
1729f988b79SJean-Baptiste Boric 	while ((volatile int) udf_node->outstanding_nodedscr > 0) {
1739f988b79SJean-Baptiste Boric 		vprint("udf_reclaim(): waiting for writeout\n", vp);
1749f988b79SJean-Baptiste Boric 		tsleep(&udf_node->outstanding_nodedscr, PRIBIO, "recl wait", hz/8);
1759f988b79SJean-Baptiste Boric 	}
1769f988b79SJean-Baptiste Boric 
177*0a6a1f1dSLionel Sambuc 	vcache_remove(vp->v_mount, &udf_node->loc.loc,
178*0a6a1f1dSLionel Sambuc 	    sizeof(udf_node->loc.loc));
179*0a6a1f1dSLionel Sambuc 
1809f988b79SJean-Baptiste Boric 	/* dispose all node knowledge */
1819f988b79SJean-Baptiste Boric 	udf_dispose_node(udf_node);
1829f988b79SJean-Baptiste Boric 
1839f988b79SJean-Baptiste Boric 	return 0;
1849f988b79SJean-Baptiste Boric }
1859f988b79SJean-Baptiste Boric 
1869f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
1879f988b79SJean-Baptiste Boric 
1889f988b79SJean-Baptiste Boric int
udf_read(void * v)1899f988b79SJean-Baptiste Boric udf_read(void *v)
1909f988b79SJean-Baptiste Boric {
1919f988b79SJean-Baptiste Boric 	struct vop_read_args /* {
1929f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
1939f988b79SJean-Baptiste Boric 		struct uio *a_uio;
1949f988b79SJean-Baptiste Boric 		int a_ioflag;
1959f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
1969f988b79SJean-Baptiste Boric 	} */ *ap = v;
1979f988b79SJean-Baptiste Boric 	struct vnode *vp     = ap->a_vp;
1989f988b79SJean-Baptiste Boric 	struct uio   *uio    = ap->a_uio;
1999f988b79SJean-Baptiste Boric 	int           ioflag = ap->a_ioflag;
2009f988b79SJean-Baptiste Boric 	int           advice = IO_ADV_DECODE(ap->a_ioflag);
2019f988b79SJean-Baptiste Boric 	struct uvm_object    *uobj;
2029f988b79SJean-Baptiste Boric 	struct udf_node      *udf_node = VTOI(vp);
2039f988b79SJean-Baptiste Boric 	struct file_entry    *fe;
2049f988b79SJean-Baptiste Boric 	struct extfile_entry *efe;
2059f988b79SJean-Baptiste Boric 	uint64_t file_size;
2069f988b79SJean-Baptiste Boric 	vsize_t len;
2079f988b79SJean-Baptiste Boric 	int error;
2089f988b79SJean-Baptiste Boric 
2099f988b79SJean-Baptiste Boric 	/*
2109f988b79SJean-Baptiste Boric 	 * XXX reading from extended attributes not yet implemented. FreeBSD
2119f988b79SJean-Baptiste Boric 	 * has it in mind to forward the IO_EXT read call to the
2129f988b79SJean-Baptiste Boric 	 * VOP_READEXTATTR().
2139f988b79SJean-Baptiste Boric 	 */
2149f988b79SJean-Baptiste Boric 
2159f988b79SJean-Baptiste Boric 	DPRINTF(READ, ("udf_read called\n"));
2169f988b79SJean-Baptiste Boric 
2179f988b79SJean-Baptiste Boric 	/* can this happen? some filingsystems have this check */
2189f988b79SJean-Baptiste Boric 	if (uio->uio_offset < 0)
2199f988b79SJean-Baptiste Boric 		return EINVAL;
2209f988b79SJean-Baptiste Boric 	if (uio->uio_resid == 0)
2219f988b79SJean-Baptiste Boric 		return 0;
2229f988b79SJean-Baptiste Boric 
2239f988b79SJean-Baptiste Boric 	/* protect against rogue programs reading raw directories and links */
2249f988b79SJean-Baptiste Boric 	if ((ioflag & IO_ALTSEMANTICS) == 0) {
2259f988b79SJean-Baptiste Boric 		if (vp->v_type == VDIR)
2269f988b79SJean-Baptiste Boric 			return EISDIR;
2279f988b79SJean-Baptiste Boric 		/* all but regular files just give EINVAL */
2289f988b79SJean-Baptiste Boric 		if (vp->v_type != VREG)
2299f988b79SJean-Baptiste Boric 			return EINVAL;
2309f988b79SJean-Baptiste Boric 	}
2319f988b79SJean-Baptiste Boric 
2329f988b79SJean-Baptiste Boric 	assert(udf_node);
2339f988b79SJean-Baptiste Boric 	assert(udf_node->fe || udf_node->efe);
2349f988b79SJean-Baptiste Boric 
2359f988b79SJean-Baptiste Boric 	/* get file/directory filesize */
2369f988b79SJean-Baptiste Boric 	if (udf_node->fe) {
2379f988b79SJean-Baptiste Boric 		fe = udf_node->fe;
2389f988b79SJean-Baptiste Boric 		file_size = udf_rw64(fe->inf_len);
2399f988b79SJean-Baptiste Boric 	} else {
2409f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
2419f988b79SJean-Baptiste Boric 		efe = udf_node->efe;
2429f988b79SJean-Baptiste Boric 		file_size = udf_rw64(efe->inf_len);
2439f988b79SJean-Baptiste Boric 	}
2449f988b79SJean-Baptiste Boric 
2459f988b79SJean-Baptiste Boric 	/* read contents using buffercache */
2469f988b79SJean-Baptiste Boric 	uobj = &vp->v_uobj;
2479f988b79SJean-Baptiste Boric 	error = 0;
2489f988b79SJean-Baptiste Boric 	while (uio->uio_resid > 0) {
2499f988b79SJean-Baptiste Boric 		/* reached end? */
2509f988b79SJean-Baptiste Boric 		if (file_size <= uio->uio_offset)
2519f988b79SJean-Baptiste Boric 			break;
2529f988b79SJean-Baptiste Boric 
2539f988b79SJean-Baptiste Boric 		/* maximise length to file extremity */
2549f988b79SJean-Baptiste Boric 		len = MIN(file_size - uio->uio_offset, uio->uio_resid);
2559f988b79SJean-Baptiste Boric 		if (len == 0)
2569f988b79SJean-Baptiste Boric 			break;
2579f988b79SJean-Baptiste Boric 
2589f988b79SJean-Baptiste Boric 		/* ubc, here we come, prepare to trap */
2599f988b79SJean-Baptiste Boric 		error = ubc_uiomove(uobj, uio, len, advice,
2609f988b79SJean-Baptiste Boric 		    UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
2619f988b79SJean-Baptiste Boric 		if (error)
2629f988b79SJean-Baptiste Boric 			break;
2639f988b79SJean-Baptiste Boric 	}
2649f988b79SJean-Baptiste Boric 
2659f988b79SJean-Baptiste Boric 	/* note access time unless not requested */
2669f988b79SJean-Baptiste Boric 	if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) {
2679f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_ACCESS;
268*0a6a1f1dSLionel Sambuc 		if ((ioflag & IO_SYNC) == IO_SYNC) {
269*0a6a1f1dSLionel Sambuc 			int uerror;
270*0a6a1f1dSLionel Sambuc 
271*0a6a1f1dSLionel Sambuc 			uerror = udf_update(vp, NULL, NULL, NULL, UPDATE_WAIT);
272*0a6a1f1dSLionel Sambuc 			if (error == 0)
273*0a6a1f1dSLionel Sambuc 				error = uerror;
274*0a6a1f1dSLionel Sambuc 		}
2759f988b79SJean-Baptiste Boric 	}
2769f988b79SJean-Baptiste Boric 
2779f988b79SJean-Baptiste Boric 	return error;
2789f988b79SJean-Baptiste Boric }
2799f988b79SJean-Baptiste Boric 
2809f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
2819f988b79SJean-Baptiste Boric 
2829f988b79SJean-Baptiste Boric int
udf_write(void * v)2839f988b79SJean-Baptiste Boric udf_write(void *v)
2849f988b79SJean-Baptiste Boric {
2859f988b79SJean-Baptiste Boric 	struct vop_write_args /* {
2869f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
2879f988b79SJean-Baptiste Boric 		struct uio *a_uio;
2889f988b79SJean-Baptiste Boric 		int a_ioflag;
2899f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
2909f988b79SJean-Baptiste Boric 	} */ *ap = v;
2919f988b79SJean-Baptiste Boric 	struct vnode *vp     = ap->a_vp;
2929f988b79SJean-Baptiste Boric 	struct uio   *uio    = ap->a_uio;
2939f988b79SJean-Baptiste Boric 	int           ioflag = ap->a_ioflag;
2949f988b79SJean-Baptiste Boric 	kauth_cred_t  cred   = ap->a_cred;
2959f988b79SJean-Baptiste Boric 	int           advice = IO_ADV_DECODE(ap->a_ioflag);
2969f988b79SJean-Baptiste Boric 	struct uvm_object    *uobj;
2979f988b79SJean-Baptiste Boric 	struct udf_node      *udf_node = VTOI(vp);
2989f988b79SJean-Baptiste Boric 	struct file_entry    *fe;
2999f988b79SJean-Baptiste Boric 	struct extfile_entry *efe;
3009f988b79SJean-Baptiste Boric 	uint64_t file_size, old_size, old_offset;
3019f988b79SJean-Baptiste Boric 	vsize_t len;
3029f988b79SJean-Baptiste Boric 	int aflag = ioflag & IO_SYNC ? B_SYNC : 0;
3039f988b79SJean-Baptiste Boric 	int error;
3049f988b79SJean-Baptiste Boric 	int resid, extended;
3059f988b79SJean-Baptiste Boric 
3069f988b79SJean-Baptiste Boric 	/*
3079f988b79SJean-Baptiste Boric 	 * XXX writing to extended attributes not yet implemented. FreeBSD has
3089f988b79SJean-Baptiste Boric 	 * it in mind to forward the IO_EXT read call to the
3099f988b79SJean-Baptiste Boric 	 * VOP_READEXTATTR().
3109f988b79SJean-Baptiste Boric 	 */
3119f988b79SJean-Baptiste Boric 
3129f988b79SJean-Baptiste Boric 	DPRINTF(WRITE, ("udf_write called\n"));
3139f988b79SJean-Baptiste Boric 
3149f988b79SJean-Baptiste Boric 	/* can this happen? some filingsystems have this check */
3159f988b79SJean-Baptiste Boric 	if (uio->uio_offset < 0)
3169f988b79SJean-Baptiste Boric 		return EINVAL;
3179f988b79SJean-Baptiste Boric 	if (uio->uio_resid == 0)
3189f988b79SJean-Baptiste Boric 		return 0;
3199f988b79SJean-Baptiste Boric 
3209f988b79SJean-Baptiste Boric 	/* protect against rogue programs writing raw directories or links */
3219f988b79SJean-Baptiste Boric 	if ((ioflag & IO_ALTSEMANTICS) == 0) {
3229f988b79SJean-Baptiste Boric 		if (vp->v_type == VDIR)
3239f988b79SJean-Baptiste Boric 			return EISDIR;
3249f988b79SJean-Baptiste Boric 		/* all but regular files just give EINVAL for now */
3259f988b79SJean-Baptiste Boric 		if (vp->v_type != VREG)
3269f988b79SJean-Baptiste Boric 			return EINVAL;
3279f988b79SJean-Baptiste Boric 	}
3289f988b79SJean-Baptiste Boric 
3299f988b79SJean-Baptiste Boric 	assert(udf_node);
3309f988b79SJean-Baptiste Boric 	assert(udf_node->fe || udf_node->efe);
3319f988b79SJean-Baptiste Boric 
3329f988b79SJean-Baptiste Boric 	/* get file/directory filesize */
3339f988b79SJean-Baptiste Boric 	if (udf_node->fe) {
3349f988b79SJean-Baptiste Boric 		fe = udf_node->fe;
3359f988b79SJean-Baptiste Boric 		file_size = udf_rw64(fe->inf_len);
3369f988b79SJean-Baptiste Boric 	} else {
3379f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
3389f988b79SJean-Baptiste Boric 		efe = udf_node->efe;
3399f988b79SJean-Baptiste Boric 		file_size = udf_rw64(efe->inf_len);
3409f988b79SJean-Baptiste Boric 	}
3419f988b79SJean-Baptiste Boric 	old_size = file_size;
3429f988b79SJean-Baptiste Boric 
3439f988b79SJean-Baptiste Boric 	/* if explicitly asked to append, uio_offset can be wrong? */
3449f988b79SJean-Baptiste Boric 	if (ioflag & IO_APPEND)
3459f988b79SJean-Baptiste Boric 		uio->uio_offset = file_size;
3469f988b79SJean-Baptiste Boric 
3479f988b79SJean-Baptiste Boric 	extended = (uio->uio_offset + uio->uio_resid > file_size);
3489f988b79SJean-Baptiste Boric 	if (extended) {
3499f988b79SJean-Baptiste Boric 		DPRINTF(WRITE, ("extending file from %"PRIu64" to %"PRIu64"\n",
3509f988b79SJean-Baptiste Boric 			file_size, uio->uio_offset + uio->uio_resid));
3519f988b79SJean-Baptiste Boric 		error = udf_grow_node(udf_node, uio->uio_offset + uio->uio_resid);
3529f988b79SJean-Baptiste Boric 		if (error)
3539f988b79SJean-Baptiste Boric 			return error;
3549f988b79SJean-Baptiste Boric 		file_size = uio->uio_offset + uio->uio_resid;
3559f988b79SJean-Baptiste Boric 	}
3569f988b79SJean-Baptiste Boric 
3579f988b79SJean-Baptiste Boric 	/* write contents using buffercache */
3589f988b79SJean-Baptiste Boric 	uobj = &vp->v_uobj;
3599f988b79SJean-Baptiste Boric 	resid = uio->uio_resid;
3609f988b79SJean-Baptiste Boric 	error = 0;
3619f988b79SJean-Baptiste Boric 
3629f988b79SJean-Baptiste Boric 	uvm_vnp_setwritesize(vp, file_size);
3639f988b79SJean-Baptiste Boric 	old_offset = uio->uio_offset;
3649f988b79SJean-Baptiste Boric 	while (uio->uio_resid > 0) {
3659f988b79SJean-Baptiste Boric 		/* maximise length to file extremity */
3669f988b79SJean-Baptiste Boric 		len = MIN(file_size - uio->uio_offset, uio->uio_resid);
3679f988b79SJean-Baptiste Boric 		if (len == 0)
3689f988b79SJean-Baptiste Boric 			break;
3699f988b79SJean-Baptiste Boric 
3709f988b79SJean-Baptiste Boric 		genfs_node_wrlock(vp);
3719f988b79SJean-Baptiste Boric 		error = GOP_ALLOC(vp, uio->uio_offset, len, aflag, cred);
3729f988b79SJean-Baptiste Boric 		genfs_node_unlock(vp);
3739f988b79SJean-Baptiste Boric 		if (error)
3749f988b79SJean-Baptiste Boric 			break;
3759f988b79SJean-Baptiste Boric 
3769f988b79SJean-Baptiste Boric 		/* ubc, here we come, prepare to trap */
3779f988b79SJean-Baptiste Boric 		error = ubc_uiomove(uobj, uio, len, advice,
3789f988b79SJean-Baptiste Boric 		    UBC_WRITE | UBC_UNMAP_FLAG(vp));
3799f988b79SJean-Baptiste Boric 		if (error)
3809f988b79SJean-Baptiste Boric 			break;
3819f988b79SJean-Baptiste Boric 
3829f988b79SJean-Baptiste Boric 		/*
3839f988b79SJean-Baptiste Boric 		 * flush what we just wrote if necessary.
3849f988b79SJean-Baptiste Boric 		 * XXXUBC simplistic async flushing.
3859f988b79SJean-Baptiste Boric 		 *
3869f988b79SJean-Baptiste Boric 		 * Directories are excluded since its file data that we want
3879f988b79SJean-Baptiste Boric 		 * to purge.
3889f988b79SJean-Baptiste Boric 		 */
3899f988b79SJean-Baptiste Boric 		if ((vp->v_type != VDIR) &&
3909f988b79SJean-Baptiste Boric 		  (old_offset >> 16 != uio->uio_offset >> 16)) {
3919f988b79SJean-Baptiste Boric 			mutex_enter(vp->v_interlock);
3929f988b79SJean-Baptiste Boric 			error = VOP_PUTPAGES(vp, (old_offset >> 16) << 16,
3939f988b79SJean-Baptiste Boric 			    (uio->uio_offset >> 16) << 16,
3949f988b79SJean-Baptiste Boric 			    PGO_CLEANIT | PGO_LAZY);
3959f988b79SJean-Baptiste Boric 			old_offset = uio->uio_offset;
3969f988b79SJean-Baptiste Boric 		}
3979f988b79SJean-Baptiste Boric 	}
3989f988b79SJean-Baptiste Boric 	uvm_vnp_setsize(vp, file_size);
3999f988b79SJean-Baptiste Boric 
4009f988b79SJean-Baptiste Boric 	/* mark node changed and request update */
4019f988b79SJean-Baptiste Boric 	udf_node->i_flags |= IN_CHANGE | IN_UPDATE;
4029f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RELATIME)
4039f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_ACCESS;
4049f988b79SJean-Baptiste Boric 
4059f988b79SJean-Baptiste Boric 	/*
4069f988b79SJean-Baptiste Boric 	 * XXX TODO FFS has code here to reset setuid & setgid when we're not
4079f988b79SJean-Baptiste Boric 	 * the superuser as a precaution against tampering.
4089f988b79SJean-Baptiste Boric 	 */
4099f988b79SJean-Baptiste Boric 
4109f988b79SJean-Baptiste Boric 	/* if we wrote a thing, note write action on vnode */
4119f988b79SJean-Baptiste Boric 	if (resid > uio->uio_resid)
4129f988b79SJean-Baptiste Boric 		VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
4139f988b79SJean-Baptiste Boric 
4149f988b79SJean-Baptiste Boric 	if (error) {
4159f988b79SJean-Baptiste Boric 		/* bring back file size to its former size */
4169f988b79SJean-Baptiste Boric 		/* take notice of its errors? */
4179f988b79SJean-Baptiste Boric 		(void) udf_chsize(vp, (u_quad_t) old_size, cred);
4189f988b79SJean-Baptiste Boric 
4199f988b79SJean-Baptiste Boric 		/* roll back uio */
4209f988b79SJean-Baptiste Boric 		uio->uio_offset -= resid - uio->uio_resid;
4219f988b79SJean-Baptiste Boric 		uio->uio_resid = resid;
4229f988b79SJean-Baptiste Boric 	} else {
4239f988b79SJean-Baptiste Boric 		/* if we write and we're synchronous, update node */
4249f988b79SJean-Baptiste Boric 		if ((resid > uio->uio_resid) && ((ioflag & IO_SYNC) == IO_SYNC))
4259f988b79SJean-Baptiste Boric 			error = udf_update(vp, NULL, NULL, NULL, UPDATE_WAIT);
4269f988b79SJean-Baptiste Boric 	}
4279f988b79SJean-Baptiste Boric 
4289f988b79SJean-Baptiste Boric 	return error;
4299f988b79SJean-Baptiste Boric }
4309f988b79SJean-Baptiste Boric 
4319f988b79SJean-Baptiste Boric 
4329f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
4339f988b79SJean-Baptiste Boric 
4349f988b79SJean-Baptiste Boric /*
4359f988b79SJean-Baptiste Boric  * `Special' bmap functionality that translates all incomming requests to
4369f988b79SJean-Baptiste Boric  * translate to vop_strategy() calls with the same blocknumbers effectively
4379f988b79SJean-Baptiste Boric  * not translating at all.
4389f988b79SJean-Baptiste Boric  */
4399f988b79SJean-Baptiste Boric 
4409f988b79SJean-Baptiste Boric int
udf_trivial_bmap(void * v)4419f988b79SJean-Baptiste Boric udf_trivial_bmap(void *v)
4429f988b79SJean-Baptiste Boric {
4439f988b79SJean-Baptiste Boric 	struct vop_bmap_args /* {
4449f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
4459f988b79SJean-Baptiste Boric 		daddr_t a_bn;
4469f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
4479f988b79SJean-Baptiste Boric 		daddr_t *a_bnp;
4489f988b79SJean-Baptiste Boric 		int *a_runp;
4499f988b79SJean-Baptiste Boric 	} */ *ap = v;
4509f988b79SJean-Baptiste Boric 	struct vnode  *vp  = ap->a_vp;	/* our node	*/
4519f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;	/* return node	*/
4529f988b79SJean-Baptiste Boric 	daddr_t *bnp  = ap->a_bnp;	/* translated	*/
4539f988b79SJean-Baptiste Boric 	daddr_t  bn   = ap->a_bn;	/* origional	*/
4549f988b79SJean-Baptiste Boric 	int     *runp = ap->a_runp;
4559f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
4569f988b79SJean-Baptiste Boric 	uint32_t lb_size;
4579f988b79SJean-Baptiste Boric 
4589f988b79SJean-Baptiste Boric 	/* get logical block size */
4599f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
4609f988b79SJean-Baptiste Boric 
4619f988b79SJean-Baptiste Boric 	/* could return `-1' to indicate holes/zeros */
4629f988b79SJean-Baptiste Boric 	/* translate 1:1 */
4639f988b79SJean-Baptiste Boric 	*bnp = bn;
4649f988b79SJean-Baptiste Boric 
4659f988b79SJean-Baptiste Boric 	/* set the vnode to read the data from with strategy on itself */
4669f988b79SJean-Baptiste Boric 	if (vpp)
4679f988b79SJean-Baptiste Boric 		*vpp = vp;
4689f988b79SJean-Baptiste Boric 
4699f988b79SJean-Baptiste Boric 	/* set runlength of maximum block size */
4709f988b79SJean-Baptiste Boric 	if (runp)
4719f988b79SJean-Baptiste Boric 		*runp = MAXPHYS / lb_size;	/* or with -1 ? */
4729f988b79SJean-Baptiste Boric 
4739f988b79SJean-Baptiste Boric 	/* return success */
4749f988b79SJean-Baptiste Boric 	return 0;
4759f988b79SJean-Baptiste Boric }
4769f988b79SJean-Baptiste Boric 
4779f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
4789f988b79SJean-Baptiste Boric 
4799f988b79SJean-Baptiste Boric int
udf_vfsstrategy(void * v)4809f988b79SJean-Baptiste Boric udf_vfsstrategy(void *v)
4819f988b79SJean-Baptiste Boric {
4829f988b79SJean-Baptiste Boric 	struct vop_strategy_args /* {
4839f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
4849f988b79SJean-Baptiste Boric 		struct buf *a_bp;
4859f988b79SJean-Baptiste Boric 	} */ *ap = v;
4869f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
4879f988b79SJean-Baptiste Boric 	struct buf   *bp = ap->a_bp;
4889f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
4899f988b79SJean-Baptiste Boric 	uint32_t lb_size, sectors;
4909f988b79SJean-Baptiste Boric 
4919f988b79SJean-Baptiste Boric 	DPRINTF(STRATEGY, ("udf_strategy called\n"));
4929f988b79SJean-Baptiste Boric 
4939f988b79SJean-Baptiste Boric 	/* check if we ought to be here */
4949f988b79SJean-Baptiste Boric 	if (vp->v_type == VBLK || vp->v_type == VCHR)
4959f988b79SJean-Baptiste Boric 		panic("udf_strategy: spec");
4969f988b79SJean-Baptiste Boric 
4979f988b79SJean-Baptiste Boric 	/* only filebuffers ought to be read/write by this, no descriptors */
4989f988b79SJean-Baptiste Boric 	assert(bp->b_blkno >= 0);
4999f988b79SJean-Baptiste Boric 
5009f988b79SJean-Baptiste Boric 	/* get sector size */
5019f988b79SJean-Baptiste Boric 	lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
5029f988b79SJean-Baptiste Boric 
5039f988b79SJean-Baptiste Boric 	/* calculate length to fetch/store in sectors */
5049f988b79SJean-Baptiste Boric 	sectors = bp->b_bcount / lb_size;
5059f988b79SJean-Baptiste Boric 	assert(bp->b_bcount > 0);
5069f988b79SJean-Baptiste Boric 
5079f988b79SJean-Baptiste Boric 	/* NEVER assume later that this buffer is already translated */
5089f988b79SJean-Baptiste Boric 	/* bp->b_lblkno = bp->b_blkno; */
5099f988b79SJean-Baptiste Boric 
5109f988b79SJean-Baptiste Boric 	/* check assertions: we OUGHT to always get multiples of this */
5119f988b79SJean-Baptiste Boric 	assert(sectors * lb_size == bp->b_bcount);
512*0a6a1f1dSLionel Sambuc 	__USE(sectors);
5139f988b79SJean-Baptiste Boric 
5149f988b79SJean-Baptiste Boric 	/* issue buffer */
5159f988b79SJean-Baptiste Boric 	if (bp->b_flags & B_READ) {
5169f988b79SJean-Baptiste Boric 		DPRINTF(STRATEGY, ("\tread vp %p buf %p (blk no %"PRIu64")"
5179f988b79SJean-Baptiste Boric 		    ", for %d sectors\n",
5189f988b79SJean-Baptiste Boric 		    vp, bp, bp->b_blkno, sectors));
5199f988b79SJean-Baptiste Boric 
5209f988b79SJean-Baptiste Boric 		/* read buffer from the udf_node, translate vtop on the way*/
5219f988b79SJean-Baptiste Boric 		udf_read_filebuf(udf_node, bp);
5229f988b79SJean-Baptiste Boric 	} else {
5239f988b79SJean-Baptiste Boric 		DPRINTF(STRATEGY, ("\twrite vp %p buf %p (blk no %"PRIu64")"
5249f988b79SJean-Baptiste Boric 		    ", for %d sectors\n",
5259f988b79SJean-Baptiste Boric 		    vp, bp, bp->b_blkno, sectors));
5269f988b79SJean-Baptiste Boric 
5279f988b79SJean-Baptiste Boric 		/* write buffer to the udf_node, translate vtop on the way*/
5289f988b79SJean-Baptiste Boric 		udf_write_filebuf(udf_node, bp);
5299f988b79SJean-Baptiste Boric 	}
5309f988b79SJean-Baptiste Boric 
5319f988b79SJean-Baptiste Boric 	return bp->b_error;
5329f988b79SJean-Baptiste Boric }
5339f988b79SJean-Baptiste Boric 
5349f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
5359f988b79SJean-Baptiste Boric 
5369f988b79SJean-Baptiste Boric int
udf_readdir(void * v)5379f988b79SJean-Baptiste Boric udf_readdir(void *v)
5389f988b79SJean-Baptiste Boric {
5399f988b79SJean-Baptiste Boric 	struct vop_readdir_args /* {
5409f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
5419f988b79SJean-Baptiste Boric 		struct uio *a_uio;
5429f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
5439f988b79SJean-Baptiste Boric 		int *a_eofflag;
5449f988b79SJean-Baptiste Boric 		off_t **a_cookies;
5459f988b79SJean-Baptiste Boric 		int *a_ncookies;
5469f988b79SJean-Baptiste Boric 	} */ *ap = v;
5479f988b79SJean-Baptiste Boric 	struct uio *uio = ap->a_uio;
5489f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
5499f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
5509f988b79SJean-Baptiste Boric 	struct file_entry    *fe;
5519f988b79SJean-Baptiste Boric 	struct extfile_entry *efe;
5529f988b79SJean-Baptiste Boric 	struct fileid_desc *fid;
5539f988b79SJean-Baptiste Boric 	struct dirent *dirent;
5549f988b79SJean-Baptiste Boric 	uint64_t file_size, diroffset, transoffset;
5559f988b79SJean-Baptiste Boric 	uint32_t lb_size;
5569f988b79SJean-Baptiste Boric 	int error;
5579f988b79SJean-Baptiste Boric 
5589f988b79SJean-Baptiste Boric 	DPRINTF(READDIR, ("udf_readdir called\n"));
5599f988b79SJean-Baptiste Boric 
5609f988b79SJean-Baptiste Boric 	/* This operation only makes sense on directory nodes. */
5619f988b79SJean-Baptiste Boric 	if (vp->v_type != VDIR)
5629f988b79SJean-Baptiste Boric 		return ENOTDIR;
5639f988b79SJean-Baptiste Boric 
5649f988b79SJean-Baptiste Boric 	/* get directory filesize */
5659f988b79SJean-Baptiste Boric 	if (udf_node->fe) {
5669f988b79SJean-Baptiste Boric 		fe = udf_node->fe;
5679f988b79SJean-Baptiste Boric 		file_size = udf_rw64(fe->inf_len);
5689f988b79SJean-Baptiste Boric 	} else {
5699f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
5709f988b79SJean-Baptiste Boric 		efe = udf_node->efe;
5719f988b79SJean-Baptiste Boric 		file_size = udf_rw64(efe->inf_len);
5729f988b79SJean-Baptiste Boric 	}
5739f988b79SJean-Baptiste Boric 
5749f988b79SJean-Baptiste Boric 	dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO);
5759f988b79SJean-Baptiste Boric 
5769f988b79SJean-Baptiste Boric 	/*
5779f988b79SJean-Baptiste Boric 	 * Add `.' pseudo entry if at offset zero since its not in the fid
5789f988b79SJean-Baptiste Boric 	 * stream
5799f988b79SJean-Baptiste Boric 	 */
5809f988b79SJean-Baptiste Boric 	if (uio->uio_offset == 0) {
5819f988b79SJean-Baptiste Boric 		DPRINTF(READDIR, ("\t'.' inserted\n"));
5829f988b79SJean-Baptiste Boric 		strcpy(dirent->d_name, ".");
5839f988b79SJean-Baptiste Boric 		dirent->d_fileno = udf_get_node_id(&udf_node->loc);
5849f988b79SJean-Baptiste Boric 		dirent->d_type = DT_DIR;
5859f988b79SJean-Baptiste Boric 		dirent->d_namlen = strlen(dirent->d_name);
5869f988b79SJean-Baptiste Boric 		dirent->d_reclen = _DIRENT_SIZE(dirent);
5879f988b79SJean-Baptiste Boric 		uiomove(dirent, _DIRENT_SIZE(dirent), uio);
5889f988b79SJean-Baptiste Boric 
5899f988b79SJean-Baptiste Boric 		/* mark with magic value that we have done the dummy */
5909f988b79SJean-Baptiste Boric 		uio->uio_offset = UDF_DIRCOOKIE_DOT;
5919f988b79SJean-Baptiste Boric 	}
5929f988b79SJean-Baptiste Boric 
5939f988b79SJean-Baptiste Boric 	/* we are called just as long as we keep on pushing data in */
5949f988b79SJean-Baptiste Boric 	error = 0;
5959f988b79SJean-Baptiste Boric 	if (uio->uio_offset < file_size) {
5969f988b79SJean-Baptiste Boric 		/* allocate temporary space for fid */
5979f988b79SJean-Baptiste Boric 		lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
5989f988b79SJean-Baptiste Boric 		fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
5999f988b79SJean-Baptiste Boric 
6009f988b79SJean-Baptiste Boric 		if (uio->uio_offset == UDF_DIRCOOKIE_DOT)
6019f988b79SJean-Baptiste Boric 			uio->uio_offset = 0;
6029f988b79SJean-Baptiste Boric 
6039f988b79SJean-Baptiste Boric 		diroffset   = uio->uio_offset;
6049f988b79SJean-Baptiste Boric 		transoffset = diroffset;
6059f988b79SJean-Baptiste Boric 		while (diroffset < file_size) {
6069f988b79SJean-Baptiste Boric 			DPRINTF(READDIR, ("\tread in fid stream\n"));
6079f988b79SJean-Baptiste Boric 			/* transfer a new fid/dirent */
6089f988b79SJean-Baptiste Boric 			error = udf_read_fid_stream(vp, &diroffset, fid, dirent);
6099f988b79SJean-Baptiste Boric 			DPRINTFIF(READDIR, error, ("read error in read fid "
6109f988b79SJean-Baptiste Boric 			    "stream : %d\n", error));
6119f988b79SJean-Baptiste Boric 			if (error)
6129f988b79SJean-Baptiste Boric 				break;
6139f988b79SJean-Baptiste Boric 
6149f988b79SJean-Baptiste Boric 			/*
6159f988b79SJean-Baptiste Boric 			 * If there isn't enough space in the uio to return a
6169f988b79SJean-Baptiste Boric 			 * whole dirent, break off read
6179f988b79SJean-Baptiste Boric 			 */
6189f988b79SJean-Baptiste Boric 			if (uio->uio_resid < _DIRENT_SIZE(dirent))
6199f988b79SJean-Baptiste Boric 				break;
6209f988b79SJean-Baptiste Boric 
6219f988b79SJean-Baptiste Boric 			/* remember the last entry we transfered */
6229f988b79SJean-Baptiste Boric 			transoffset = diroffset;
6239f988b79SJean-Baptiste Boric 
6249f988b79SJean-Baptiste Boric 			/* skip deleted entries */
6259f988b79SJean-Baptiste Boric 			if (fid->file_char & UDF_FILE_CHAR_DEL)
6269f988b79SJean-Baptiste Boric 				continue;
6279f988b79SJean-Baptiste Boric 
6289f988b79SJean-Baptiste Boric 			/* skip not visible files */
6299f988b79SJean-Baptiste Boric 			if (fid->file_char & UDF_FILE_CHAR_VIS)
6309f988b79SJean-Baptiste Boric 				continue;
6319f988b79SJean-Baptiste Boric 
6329f988b79SJean-Baptiste Boric 			/* copy dirent to the caller */
6339f988b79SJean-Baptiste Boric 			DPRINTF(READDIR, ("\tread dirent `%s', type %d\n",
6349f988b79SJean-Baptiste Boric 			    dirent->d_name, dirent->d_type));
6359f988b79SJean-Baptiste Boric 			uiomove(dirent, _DIRENT_SIZE(dirent), uio);
6369f988b79SJean-Baptiste Boric 		}
6379f988b79SJean-Baptiste Boric 
6389f988b79SJean-Baptiste Boric 		/* pass on last transfered offset */
6399f988b79SJean-Baptiste Boric 		uio->uio_offset = transoffset;
6409f988b79SJean-Baptiste Boric 		free(fid, M_UDFTEMP);
6419f988b79SJean-Baptiste Boric 	}
6429f988b79SJean-Baptiste Boric 
6439f988b79SJean-Baptiste Boric 	if (ap->a_eofflag)
6449f988b79SJean-Baptiste Boric 		*ap->a_eofflag = (uio->uio_offset >= file_size);
6459f988b79SJean-Baptiste Boric 
6469f988b79SJean-Baptiste Boric #ifdef DEBUG
6479f988b79SJean-Baptiste Boric 	if (udf_verbose & UDF_DEBUG_READDIR) {
6489f988b79SJean-Baptiste Boric 		printf("returning offset %d\n", (uint32_t) uio->uio_offset);
6499f988b79SJean-Baptiste Boric 		if (ap->a_eofflag)
6509f988b79SJean-Baptiste Boric 			printf("returning EOF ? %d\n", *ap->a_eofflag);
6519f988b79SJean-Baptiste Boric 		if (error)
6529f988b79SJean-Baptiste Boric 			printf("readdir returning error %d\n", error);
6539f988b79SJean-Baptiste Boric 	}
6549f988b79SJean-Baptiste Boric #endif
6559f988b79SJean-Baptiste Boric 
6569f988b79SJean-Baptiste Boric 	free(dirent, M_UDFTEMP);
6579f988b79SJean-Baptiste Boric 	return error;
6589f988b79SJean-Baptiste Boric }
6599f988b79SJean-Baptiste Boric 
6609f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
6619f988b79SJean-Baptiste Boric 
6629f988b79SJean-Baptiste Boric int
udf_lookup(void * v)6639f988b79SJean-Baptiste Boric udf_lookup(void *v)
6649f988b79SJean-Baptiste Boric {
665*0a6a1f1dSLionel Sambuc 	struct vop_lookup_v2_args /* {
6669f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
6679f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
6689f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
6699f988b79SJean-Baptiste Boric 	} */ *ap = v;
6709f988b79SJean-Baptiste Boric 	struct vnode *dvp = ap->a_dvp;
6719f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;
6729f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
6739f988b79SJean-Baptiste Boric 	struct udf_node  *dir_node, *res_node;
6749f988b79SJean-Baptiste Boric 	struct udf_mount *ump;
6759f988b79SJean-Baptiste Boric 	struct long_ad    icb_loc;
6769f988b79SJean-Baptiste Boric 	mode_t mode;
6779f988b79SJean-Baptiste Boric 	uid_t d_uid;
6789f988b79SJean-Baptiste Boric 	gid_t d_gid;
6799f988b79SJean-Baptiste Boric 	const char *name;
6809f988b79SJean-Baptiste Boric 	int namelen, nameiop, islastcn, mounted_ro;
6819f988b79SJean-Baptiste Boric 	int error, found;
6829f988b79SJean-Baptiste Boric 
6839f988b79SJean-Baptiste Boric 	dir_node = VTOI(dvp);
6849f988b79SJean-Baptiste Boric 	ump = dir_node->ump;
6859f988b79SJean-Baptiste Boric 	*vpp = NULL;
6869f988b79SJean-Baptiste Boric 
6879f988b79SJean-Baptiste Boric 	DPRINTF(LOOKUP, ("udf_lookup called, lookup `%s`\n",
6889f988b79SJean-Baptiste Boric 		cnp->cn_nameptr));
6899f988b79SJean-Baptiste Boric 
6909f988b79SJean-Baptiste Boric 	/* simplify/clarification flags */
6919f988b79SJean-Baptiste Boric 	nameiop     = cnp->cn_nameiop;
6929f988b79SJean-Baptiste Boric 	islastcn    = cnp->cn_flags & ISLASTCN;
6939f988b79SJean-Baptiste Boric 	mounted_ro  = dvp->v_mount->mnt_flag & MNT_RDONLY;
6949f988b79SJean-Baptiste Boric 
6959f988b79SJean-Baptiste Boric 	/* check exec/dirread permissions first */
6969f988b79SJean-Baptiste Boric 	error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred);
6979f988b79SJean-Baptiste Boric 	if (error)
6989f988b79SJean-Baptiste Boric 		return error;
6999f988b79SJean-Baptiste Boric 
7009f988b79SJean-Baptiste Boric 	DPRINTF(LOOKUP, ("\taccess ok\n"));
7019f988b79SJean-Baptiste Boric 
7029f988b79SJean-Baptiste Boric 	/*
7039f988b79SJean-Baptiste Boric 	 * If requesting a modify on the last path element on a read-only
7049f988b79SJean-Baptiste Boric 	 * filingsystem, reject lookup; XXX why is this repeated in every FS ?
7059f988b79SJean-Baptiste Boric 	 */
7069f988b79SJean-Baptiste Boric 	if (islastcn && mounted_ro && (nameiop == DELETE || nameiop == RENAME))
7079f988b79SJean-Baptiste Boric 		return EROFS;
7089f988b79SJean-Baptiste Boric 
7099f988b79SJean-Baptiste Boric 	DPRINTF(LOOKUP, ("\tlooking up cnp->cn_nameptr '%s'\n",
7109f988b79SJean-Baptiste Boric 	    cnp->cn_nameptr));
7119f988b79SJean-Baptiste Boric 	/* look in the namecache */
7129f988b79SJean-Baptiste Boric 	if (cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
7139f988b79SJean-Baptiste Boric 			 cnp->cn_nameiop, cnp->cn_flags, NULL, vpp)) {
7149f988b79SJean-Baptiste Boric 		return *vpp == NULLVP ? ENOENT : 0;
7159f988b79SJean-Baptiste Boric 	}
7169f988b79SJean-Baptiste Boric 
7179f988b79SJean-Baptiste Boric 	DPRINTF(LOOKUP, ("\tNOT found in cache\n"));
7189f988b79SJean-Baptiste Boric 
7199f988b79SJean-Baptiste Boric 	/*
7209f988b79SJean-Baptiste Boric 	 * Obviously, the file is not (anymore) in the namecache, we have to
7219f988b79SJean-Baptiste Boric 	 * search for it. There are three basic cases: '.', '..' and others.
7229f988b79SJean-Baptiste Boric 	 *
7239f988b79SJean-Baptiste Boric 	 * Following the guidelines of VOP_LOOKUP manpage and tmpfs.
7249f988b79SJean-Baptiste Boric 	 */
7259f988b79SJean-Baptiste Boric 	error = 0;
7269f988b79SJean-Baptiste Boric 	if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) {
7279f988b79SJean-Baptiste Boric 		DPRINTF(LOOKUP, ("\tlookup '.'\n"));
7289f988b79SJean-Baptiste Boric 		/* special case 1 '.' */
7299f988b79SJean-Baptiste Boric 		if (islastcn && cnp->cn_nameiop == RENAME) {
7309f988b79SJean-Baptiste Boric 			error = EISDIR;
7319f988b79SJean-Baptiste Boric 			goto out;
7329f988b79SJean-Baptiste Boric 		}
7339f988b79SJean-Baptiste Boric 		vref(dvp);
7349f988b79SJean-Baptiste Boric 		*vpp = dvp;
7359f988b79SJean-Baptiste Boric 		/* done */
7369f988b79SJean-Baptiste Boric 		goto done;
7379f988b79SJean-Baptiste Boric 	} else if (cnp->cn_flags & ISDOTDOT) {
7389f988b79SJean-Baptiste Boric 		/* special case 2 '..' */
7399f988b79SJean-Baptiste Boric 		DPRINTF(LOOKUP, ("\tlookup '..'\n"));
7409f988b79SJean-Baptiste Boric 
7419f988b79SJean-Baptiste Boric 		if (islastcn && cnp->cn_nameiop == RENAME) {
7429f988b79SJean-Baptiste Boric 			error = EINVAL;
7439f988b79SJean-Baptiste Boric 			goto out;
7449f988b79SJean-Baptiste Boric 		}
7459f988b79SJean-Baptiste Boric 
7469f988b79SJean-Baptiste Boric 		/* get our node */
7479f988b79SJean-Baptiste Boric 		name    = "..";
7489f988b79SJean-Baptiste Boric 		namelen = 2;
7499f988b79SJean-Baptiste Boric 		error = udf_lookup_name_in_dir(dvp, name, namelen,
7509f988b79SJean-Baptiste Boric 				&icb_loc, &found);
7519f988b79SJean-Baptiste Boric 		if (error)
7529f988b79SJean-Baptiste Boric 			goto out;
7539f988b79SJean-Baptiste Boric 		if (!found)
7549f988b79SJean-Baptiste Boric 			error = ENOENT;
7559f988b79SJean-Baptiste Boric 
7569f988b79SJean-Baptiste Boric 		/* first unlock parent */
7579f988b79SJean-Baptiste Boric 		VOP_UNLOCK(dvp);
7589f988b79SJean-Baptiste Boric 
7599f988b79SJean-Baptiste Boric 		if (error == 0) {
7609f988b79SJean-Baptiste Boric 			DPRINTF(LOOKUP, ("\tfound '..'\n"));
7619f988b79SJean-Baptiste Boric 			/* try to create/reuse the node */
7629f988b79SJean-Baptiste Boric 			error = udf_get_node(ump, &icb_loc, &res_node);
7639f988b79SJean-Baptiste Boric 
7649f988b79SJean-Baptiste Boric 			if (!error) {
7659f988b79SJean-Baptiste Boric 				DPRINTF(LOOKUP,
7669f988b79SJean-Baptiste Boric 					("\tnode retrieved/created OK\n"));
7679f988b79SJean-Baptiste Boric 				*vpp = res_node->vnode;
7689f988b79SJean-Baptiste Boric 			}
7699f988b79SJean-Baptiste Boric 		}
7709f988b79SJean-Baptiste Boric 
7719f988b79SJean-Baptiste Boric 		/* try to relock parent */
7729f988b79SJean-Baptiste Boric 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
7739f988b79SJean-Baptiste Boric 		goto out;
7749f988b79SJean-Baptiste Boric 	}
7759f988b79SJean-Baptiste Boric 
7769f988b79SJean-Baptiste Boric 	/* all other files */
7779f988b79SJean-Baptiste Boric 	DPRINTF(LOOKUP, ("\tlookup file/dir in directory\n"));
7789f988b79SJean-Baptiste Boric 
7799f988b79SJean-Baptiste Boric 	/* lookup filename in the directory; location icb_loc */
7809f988b79SJean-Baptiste Boric 	name    = cnp->cn_nameptr;
7819f988b79SJean-Baptiste Boric 	namelen = cnp->cn_namelen;
7829f988b79SJean-Baptiste Boric 	error = udf_lookup_name_in_dir(dvp, name, namelen,
7839f988b79SJean-Baptiste Boric 			&icb_loc, &found);
7849f988b79SJean-Baptiste Boric 	if (error)
7859f988b79SJean-Baptiste Boric 		goto out;
7869f988b79SJean-Baptiste Boric 	if (!found) {
7879f988b79SJean-Baptiste Boric 		DPRINTF(LOOKUP, ("\tNOT found\n"));
7889f988b79SJean-Baptiste Boric 		/*
7899f988b79SJean-Baptiste Boric 		 * The entry was not found in the directory.  This is
7909f988b79SJean-Baptiste Boric 		 * valid if we are creating or renaming an entry and
7919f988b79SJean-Baptiste Boric 		 * are working on the last component of the path name.
7929f988b79SJean-Baptiste Boric 		 */
7939f988b79SJean-Baptiste Boric 		if (islastcn && (cnp->cn_nameiop == CREATE ||
7949f988b79SJean-Baptiste Boric 				 cnp->cn_nameiop == RENAME)) {
7959f988b79SJean-Baptiste Boric 			error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
7969f988b79SJean-Baptiste Boric 			if (error) {
7979f988b79SJean-Baptiste Boric 				goto out;
7989f988b79SJean-Baptiste Boric 			}
7999f988b79SJean-Baptiste Boric 			error = EJUSTRETURN;
8009f988b79SJean-Baptiste Boric 		} else {
8019f988b79SJean-Baptiste Boric 			error = ENOENT;
8029f988b79SJean-Baptiste Boric 		}
8039f988b79SJean-Baptiste Boric 		/* done */
8049f988b79SJean-Baptiste Boric 		goto done;
8059f988b79SJean-Baptiste Boric 	}
8069f988b79SJean-Baptiste Boric 
8079f988b79SJean-Baptiste Boric 	/*
8089f988b79SJean-Baptiste Boric 	 * XXX NOTE tmpfs has a test here that tests that intermediate
8099f988b79SJean-Baptiste Boric 	 * components i.e. not the last one ought to be either a directory or
8109f988b79SJean-Baptiste Boric 	 * a link. It seems to function well without this code.
8119f988b79SJean-Baptiste Boric 	 */
8129f988b79SJean-Baptiste Boric 
8139f988b79SJean-Baptiste Boric 	/* try to create/reuse the node */
8149f988b79SJean-Baptiste Boric 	error = udf_get_node(ump, &icb_loc, &res_node);
8159f988b79SJean-Baptiste Boric 	if (error)
8169f988b79SJean-Baptiste Boric 		goto out;
8179f988b79SJean-Baptiste Boric 
8189f988b79SJean-Baptiste Boric 	/* check permissions */
8199f988b79SJean-Baptiste Boric 	if (islastcn && (cnp->cn_nameiop == DELETE ||
8209f988b79SJean-Baptiste Boric 			 cnp->cn_nameiop == RENAME)  ) {
8219f988b79SJean-Baptiste Boric 		error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
8229f988b79SJean-Baptiste Boric 		if (error) {
8239f988b79SJean-Baptiste Boric 			vput(res_node->vnode);
8249f988b79SJean-Baptiste Boric 			goto out;
8259f988b79SJean-Baptiste Boric 		}
8269f988b79SJean-Baptiste Boric 
8279f988b79SJean-Baptiste Boric 		/*
8289f988b79SJean-Baptiste Boric 		 * Check if the directory has its sticky bit set. If so, ask
8299f988b79SJean-Baptiste Boric 		 * for clearance since only the owner of a file or directory
8309f988b79SJean-Baptiste Boric 		 * can remove/rename from taht directory.
8319f988b79SJean-Baptiste Boric 		 */
8329f988b79SJean-Baptiste Boric 		mode = udf_getaccessmode(dir_node);
8339f988b79SJean-Baptiste Boric 		if ((mode & S_ISTXT) != 0) {
8349f988b79SJean-Baptiste Boric 			udf_getownership(dir_node, &d_uid, &d_gid);
8359f988b79SJean-Baptiste Boric 			error = kauth_authorize_vnode(cnp->cn_cred,
8369f988b79SJean-Baptiste Boric 			    KAUTH_VNODE_DELETE, res_node->vnode,
8379f988b79SJean-Baptiste Boric 			    dir_node->vnode, genfs_can_sticky(cnp->cn_cred,
8389f988b79SJean-Baptiste Boric 			    d_uid, d_uid));
8399f988b79SJean-Baptiste Boric 			if (error) {
8409f988b79SJean-Baptiste Boric 				error = EPERM;
8419f988b79SJean-Baptiste Boric 				vput(res_node->vnode);
8429f988b79SJean-Baptiste Boric 				goto out;
8439f988b79SJean-Baptiste Boric 			}
8449f988b79SJean-Baptiste Boric 		}
8459f988b79SJean-Baptiste Boric 	}
8469f988b79SJean-Baptiste Boric 
8479f988b79SJean-Baptiste Boric 	*vpp = res_node->vnode;
8489f988b79SJean-Baptiste Boric 
8499f988b79SJean-Baptiste Boric done:
8509f988b79SJean-Baptiste Boric 	/*
8519f988b79SJean-Baptiste Boric 	 * Store result in the cache if requested. If we are creating a file,
8529f988b79SJean-Baptiste Boric 	 * the file might not be found and thus putting it into the namecache
8539f988b79SJean-Baptiste Boric 	 * might be seen as negative caching.
8549f988b79SJean-Baptiste Boric 	 */
8559f988b79SJean-Baptiste Boric 	if (nameiop != CREATE)
8569f988b79SJean-Baptiste Boric 		cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen,
8579f988b79SJean-Baptiste Boric 			    cnp->cn_flags);
8589f988b79SJean-Baptiste Boric 
8599f988b79SJean-Baptiste Boric out:
860*0a6a1f1dSLionel Sambuc 	if (error == 0 && *vpp != dvp)
861*0a6a1f1dSLionel Sambuc 		VOP_UNLOCK(*vpp);
8629f988b79SJean-Baptiste Boric 	DPRINTFIF(LOOKUP, error, ("udf_lookup returing error %d\n", error));
8639f988b79SJean-Baptiste Boric 
8649f988b79SJean-Baptiste Boric 	return error;
8659f988b79SJean-Baptiste Boric }
8669f988b79SJean-Baptiste Boric 
8679f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
8689f988b79SJean-Baptiste Boric 
8699f988b79SJean-Baptiste Boric int
udf_getattr(void * v)8709f988b79SJean-Baptiste Boric udf_getattr(void *v)
8719f988b79SJean-Baptiste Boric {
8729f988b79SJean-Baptiste Boric 	struct vop_getattr_args /* {
8739f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
8749f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
8759f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
8769f988b79SJean-Baptiste Boric 		struct lwp   *a_l;
8779f988b79SJean-Baptiste Boric 	} */ *ap = v;
8789f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
8799f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
8809f988b79SJean-Baptiste Boric 	struct udf_mount *ump = udf_node->ump;
8819f988b79SJean-Baptiste Boric 	struct file_entry    *fe  = udf_node->fe;
8829f988b79SJean-Baptiste Boric 	struct extfile_entry *efe = udf_node->efe;
8839f988b79SJean-Baptiste Boric 	struct filetimes_extattr_entry *ft_extattr;
8849f988b79SJean-Baptiste Boric 	struct device_extattr_entry *devattr;
8859f988b79SJean-Baptiste Boric 	struct vattr *vap = ap->a_vap;
8869f988b79SJean-Baptiste Boric 	struct timestamp *atime, *mtime, *attrtime, *creatime;
8879f988b79SJean-Baptiste Boric 	uint64_t filesize, blkssize;
8889f988b79SJean-Baptiste Boric 	uint32_t nlink;
8899f988b79SJean-Baptiste Boric 	uint32_t offset, a_l;
890*0a6a1f1dSLionel Sambuc 	uint8_t *filedata, *targetbuf;
8919f988b79SJean-Baptiste Boric 	uid_t uid;
8929f988b79SJean-Baptiste Boric 	gid_t gid;
893*0a6a1f1dSLionel Sambuc 	int length, error;
8949f988b79SJean-Baptiste Boric 
8959f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_getattr called\n"));
8969f988b79SJean-Baptiste Boric 
8979f988b79SJean-Baptiste Boric 	/* update times before we returning values */
8989f988b79SJean-Baptiste Boric 	udf_itimes(udf_node, NULL, NULL, NULL);
8999f988b79SJean-Baptiste Boric 
9009f988b79SJean-Baptiste Boric 	/* get descriptor information */
9019f988b79SJean-Baptiste Boric 	if (fe) {
9029f988b79SJean-Baptiste Boric 		nlink    = udf_rw16(fe->link_cnt);
9039f988b79SJean-Baptiste Boric 		uid      = (uid_t)udf_rw32(fe->uid);
9049f988b79SJean-Baptiste Boric 		gid      = (gid_t)udf_rw32(fe->gid);
9059f988b79SJean-Baptiste Boric 		filesize = udf_rw64(fe->inf_len);
9069f988b79SJean-Baptiste Boric 		blkssize = udf_rw64(fe->logblks_rec);
9079f988b79SJean-Baptiste Boric 		atime    = &fe->atime;
9089f988b79SJean-Baptiste Boric 		mtime    = &fe->mtime;
9099f988b79SJean-Baptiste Boric 		attrtime = &fe->attrtime;
9109f988b79SJean-Baptiste Boric 		filedata = fe->data;
9119f988b79SJean-Baptiste Boric 
9129f988b79SJean-Baptiste Boric 		/* initial guess */
9139f988b79SJean-Baptiste Boric 		creatime = mtime;
9149f988b79SJean-Baptiste Boric 
9159f988b79SJean-Baptiste Boric 		/* check our extended attribute if present */
9169f988b79SJean-Baptiste Boric 		error = udf_extattr_search_intern(udf_node,
9179f988b79SJean-Baptiste Boric 			UDF_FILETIMES_ATTR_NO, "", &offset, &a_l);
9189f988b79SJean-Baptiste Boric 		if (!error) {
9199f988b79SJean-Baptiste Boric 			ft_extattr = (struct filetimes_extattr_entry *)
9209f988b79SJean-Baptiste Boric 				(filedata + offset);
9219f988b79SJean-Baptiste Boric 			if (ft_extattr->existence & UDF_FILETIMES_FILE_CREATION)
9229f988b79SJean-Baptiste Boric 				creatime = &ft_extattr->times[0];
9239f988b79SJean-Baptiste Boric 		}
9249f988b79SJean-Baptiste Boric 	} else {
9259f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
9269f988b79SJean-Baptiste Boric 		nlink    = udf_rw16(efe->link_cnt);
9279f988b79SJean-Baptiste Boric 		uid      = (uid_t)udf_rw32(efe->uid);
9289f988b79SJean-Baptiste Boric 		gid      = (gid_t)udf_rw32(efe->gid);
9299f988b79SJean-Baptiste Boric 		filesize = udf_rw64(efe->inf_len);	/* XXX or obj_size? */
9309f988b79SJean-Baptiste Boric 		blkssize = udf_rw64(efe->logblks_rec);
9319f988b79SJean-Baptiste Boric 		atime    = &efe->atime;
9329f988b79SJean-Baptiste Boric 		mtime    = &efe->mtime;
9339f988b79SJean-Baptiste Boric 		attrtime = &efe->attrtime;
9349f988b79SJean-Baptiste Boric 		creatime = &efe->ctime;
9359f988b79SJean-Baptiste Boric 		filedata = efe->data;
9369f988b79SJean-Baptiste Boric 	}
9379f988b79SJean-Baptiste Boric 
9389f988b79SJean-Baptiste Boric 	/* do the uid/gid translation game */
9399f988b79SJean-Baptiste Boric 	if (uid == (uid_t) -1)
9409f988b79SJean-Baptiste Boric 		uid = ump->mount_args.anon_uid;
9419f988b79SJean-Baptiste Boric 	if (gid == (gid_t) -1)
9429f988b79SJean-Baptiste Boric 		gid = ump->mount_args.anon_gid;
9439f988b79SJean-Baptiste Boric 
9449f988b79SJean-Baptiste Boric 	/* fill in struct vattr with values from the node */
9459f988b79SJean-Baptiste Boric 	vattr_null(vap);
9469f988b79SJean-Baptiste Boric 	vap->va_type      = vp->v_type;
9479f988b79SJean-Baptiste Boric 	vap->va_mode      = udf_getaccessmode(udf_node);
9489f988b79SJean-Baptiste Boric 	vap->va_nlink     = nlink;
9499f988b79SJean-Baptiste Boric 	vap->va_uid       = uid;
9509f988b79SJean-Baptiste Boric 	vap->va_gid       = gid;
9519f988b79SJean-Baptiste Boric 	vap->va_fsid      = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
9529f988b79SJean-Baptiste Boric 	vap->va_fileid    = udf_get_node_id(&udf_node->loc);   /* inode hash XXX */
9539f988b79SJean-Baptiste Boric 	vap->va_size      = filesize;
9549f988b79SJean-Baptiste Boric 	vap->va_blocksize = udf_node->ump->discinfo.sector_size;  /* wise? */
9559f988b79SJean-Baptiste Boric 
9569f988b79SJean-Baptiste Boric 	/*
9579f988b79SJean-Baptiste Boric 	 * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to add
9589f988b79SJean-Baptiste Boric 	 * 1 to the link count if its a directory we're requested attributes
9599f988b79SJean-Baptiste Boric 	 * of.
9609f988b79SJean-Baptiste Boric 	 */
9619f988b79SJean-Baptiste Boric 	if (vap->va_type == VDIR)
9629f988b79SJean-Baptiste Boric 		vap->va_nlink++;
9639f988b79SJean-Baptiste Boric 
964*0a6a1f1dSLionel Sambuc 	/*
965*0a6a1f1dSLionel Sambuc 	 * BUG-ALERT: Posix requires the va_size to be pathlength for symbolic
966*0a6a1f1dSLionel Sambuc 	 * links.
967*0a6a1f1dSLionel Sambuc 	 */
968*0a6a1f1dSLionel Sambuc 	if (vap->va_type == VLNK) {
969*0a6a1f1dSLionel Sambuc 		/* claim temporary buffers for translation */
970*0a6a1f1dSLionel Sambuc 		targetbuf = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK);
971*0a6a1f1dSLionel Sambuc 		error = udf_do_readlink(udf_node, filesize, targetbuf, &length);
972*0a6a1f1dSLionel Sambuc 		if (!error) {
973*0a6a1f1dSLionel Sambuc 			vap->va_size = length;
974*0a6a1f1dSLionel Sambuc 			KASSERT(length == strlen(targetbuf));
975*0a6a1f1dSLionel Sambuc 		}
976*0a6a1f1dSLionel Sambuc 		free(targetbuf, M_UDFTEMP);
977*0a6a1f1dSLionel Sambuc 		/* XXX return error? */
978*0a6a1f1dSLionel Sambuc 	}
979*0a6a1f1dSLionel Sambuc 
9809f988b79SJean-Baptiste Boric 	/* access times */
9819f988b79SJean-Baptiste Boric 	udf_timestamp_to_timespec(ump, atime,    &vap->va_atime);
9829f988b79SJean-Baptiste Boric 	udf_timestamp_to_timespec(ump, mtime,    &vap->va_mtime);
9839f988b79SJean-Baptiste Boric 	udf_timestamp_to_timespec(ump, attrtime, &vap->va_ctime);
9849f988b79SJean-Baptiste Boric 	udf_timestamp_to_timespec(ump, creatime, &vap->va_birthtime);
9859f988b79SJean-Baptiste Boric 
9869f988b79SJean-Baptiste Boric 	vap->va_gen       = 1;		/* no multiple generations yes (!?) */
9879f988b79SJean-Baptiste Boric 	vap->va_flags     = 0;		/* no flags */
9889f988b79SJean-Baptiste Boric 	vap->va_bytes     = blkssize * udf_node->ump->discinfo.sector_size;
9899f988b79SJean-Baptiste Boric 	vap->va_filerev   = 1;		/* TODO file revision numbers? */
9909f988b79SJean-Baptiste Boric 	vap->va_vaflags   = 0;
9919f988b79SJean-Baptiste Boric 	/* TODO get vaflags from the extended attributes? */
9929f988b79SJean-Baptiste Boric 
9939f988b79SJean-Baptiste Boric 	if ((vap->va_type == VBLK) || (vap->va_type == VCHR)) {
9949f988b79SJean-Baptiste Boric 		error = udf_extattr_search_intern(udf_node,
9959f988b79SJean-Baptiste Boric 				UDF_DEVICESPEC_ATTR_NO, "",
9969f988b79SJean-Baptiste Boric 				&offset, &a_l);
9979f988b79SJean-Baptiste Boric 		/* if error, deny access */
9989f988b79SJean-Baptiste Boric 		if (error || (filedata == NULL)) {
9999f988b79SJean-Baptiste Boric 			vap->va_mode = 0;	/* or v_type = VNON?  */
10009f988b79SJean-Baptiste Boric 		} else {
10019f988b79SJean-Baptiste Boric 			devattr = (struct device_extattr_entry *)
10029f988b79SJean-Baptiste Boric 				filedata + offset;
10039f988b79SJean-Baptiste Boric 			vap->va_rdev = makedev(
10049f988b79SJean-Baptiste Boric 				udf_rw32(devattr->major),
10059f988b79SJean-Baptiste Boric 				udf_rw32(devattr->minor)
10069f988b79SJean-Baptiste Boric 				);
10079f988b79SJean-Baptiste Boric 			/* TODO we could check the implementator */
10089f988b79SJean-Baptiste Boric 		}
10099f988b79SJean-Baptiste Boric 	}
10109f988b79SJean-Baptiste Boric 
10119f988b79SJean-Baptiste Boric 	return 0;
10129f988b79SJean-Baptiste Boric }
10139f988b79SJean-Baptiste Boric 
10149f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
10159f988b79SJean-Baptiste Boric 
10169f988b79SJean-Baptiste Boric static int
udf_chown(struct vnode * vp,uid_t new_uid,gid_t new_gid,kauth_cred_t cred)10179f988b79SJean-Baptiste Boric udf_chown(struct vnode *vp, uid_t new_uid, gid_t new_gid,
10189f988b79SJean-Baptiste Boric 	  kauth_cred_t cred)
10199f988b79SJean-Baptiste Boric {
10209f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = VTOI(vp);
10219f988b79SJean-Baptiste Boric 	uid_t uid;
10229f988b79SJean-Baptiste Boric 	gid_t gid;
10239f988b79SJean-Baptiste Boric 	int error;
10249f988b79SJean-Baptiste Boric 
10259f988b79SJean-Baptiste Boric #ifdef notyet
10269f988b79SJean-Baptiste Boric 	/* TODO get vaflags from the extended attributes? */
10279f988b79SJean-Baptiste Boric 	/* Immutable or append-only files cannot be modified, either. */
10289f988b79SJean-Baptiste Boric 	if (udf_node->flags & (IMMUTABLE | APPEND))
10299f988b79SJean-Baptiste Boric 		return EPERM;
10309f988b79SJean-Baptiste Boric #endif
10319f988b79SJean-Baptiste Boric 
10329f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
10339f988b79SJean-Baptiste Boric 		return EROFS;
10349f988b79SJean-Baptiste Boric 
10359f988b79SJean-Baptiste Boric 	/* retrieve old values */
10369f988b79SJean-Baptiste Boric 	udf_getownership(udf_node, &uid, &gid);
10379f988b79SJean-Baptiste Boric 
10389f988b79SJean-Baptiste Boric 	/* only one could be specified */
10399f988b79SJean-Baptiste Boric 	if (new_uid == VNOVAL)
10409f988b79SJean-Baptiste Boric 		new_uid = uid;
10419f988b79SJean-Baptiste Boric 	if (new_gid == VNOVAL)
10429f988b79SJean-Baptiste Boric 		new_gid = gid;
10439f988b79SJean-Baptiste Boric 
10449f988b79SJean-Baptiste Boric 	/* check if we can fit it in an 32 bits */
10459f988b79SJean-Baptiste Boric 	if ((uid_t) ((uint32_t) new_uid) != new_uid)
10469f988b79SJean-Baptiste Boric 		return EINVAL;
10479f988b79SJean-Baptiste Boric 	if ((gid_t) ((uint32_t) new_gid) != new_gid)
10489f988b79SJean-Baptiste Boric 		return EINVAL;
10499f988b79SJean-Baptiste Boric 
10509f988b79SJean-Baptiste Boric 	/* check permissions */
10519f988b79SJean-Baptiste Boric 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP,
10529f988b79SJean-Baptiste Boric 	    vp, NULL, genfs_can_chown(cred, uid, gid, new_uid, new_gid));
10539f988b79SJean-Baptiste Boric 	if (error)
10549f988b79SJean-Baptiste Boric 		return (error);
10559f988b79SJean-Baptiste Boric 
10569f988b79SJean-Baptiste Boric 	/* change the ownership */
10579f988b79SJean-Baptiste Boric 	udf_setownership(udf_node, new_uid, new_gid);
10589f988b79SJean-Baptiste Boric 
10599f988b79SJean-Baptiste Boric 	/* mark node changed */
10609f988b79SJean-Baptiste Boric 	udf_node->i_flags |= IN_CHANGE;
10619f988b79SJean-Baptiste Boric 
10629f988b79SJean-Baptiste Boric 	return 0;
10639f988b79SJean-Baptiste Boric }
10649f988b79SJean-Baptiste Boric 
10659f988b79SJean-Baptiste Boric 
10669f988b79SJean-Baptiste Boric static int
udf_chmod(struct vnode * vp,mode_t mode,kauth_cred_t cred)10679f988b79SJean-Baptiste Boric udf_chmod(struct vnode *vp, mode_t mode, kauth_cred_t cred)
10689f988b79SJean-Baptiste Boric {
10699f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = VTOI(vp);
10709f988b79SJean-Baptiste Boric 	uid_t uid;
10719f988b79SJean-Baptiste Boric 	gid_t gid;
10729f988b79SJean-Baptiste Boric 	int error;
10739f988b79SJean-Baptiste Boric 
10749f988b79SJean-Baptiste Boric #ifdef notyet
10759f988b79SJean-Baptiste Boric 	/* TODO get vaflags from the extended attributes? */
10769f988b79SJean-Baptiste Boric 	/* Immutable or append-only files cannot be modified, either. */
10779f988b79SJean-Baptiste Boric 	if (udf_node->flags & (IMMUTABLE | APPEND))
10789f988b79SJean-Baptiste Boric 		return EPERM;
10799f988b79SJean-Baptiste Boric #endif
10809f988b79SJean-Baptiste Boric 
10819f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
10829f988b79SJean-Baptiste Boric 		return EROFS;
10839f988b79SJean-Baptiste Boric 
10849f988b79SJean-Baptiste Boric 	/* retrieve uid/gid values */
10859f988b79SJean-Baptiste Boric 	udf_getownership(udf_node, &uid, &gid);
10869f988b79SJean-Baptiste Boric 
10879f988b79SJean-Baptiste Boric 	/* check permissions */
10889f988b79SJean-Baptiste Boric 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp,
10899f988b79SJean-Baptiste Boric 	    NULL, genfs_can_chmod(vp->v_type, cred, uid, gid, mode));
10909f988b79SJean-Baptiste Boric 	if (error)
10919f988b79SJean-Baptiste Boric 		return (error);
10929f988b79SJean-Baptiste Boric 
10939f988b79SJean-Baptiste Boric 	/* change mode */
10949f988b79SJean-Baptiste Boric 	udf_setaccessmode(udf_node, mode);
10959f988b79SJean-Baptiste Boric 
10969f988b79SJean-Baptiste Boric 	/* mark node changed */
10979f988b79SJean-Baptiste Boric 	udf_node->i_flags |= IN_CHANGE;
10989f988b79SJean-Baptiste Boric 
10999f988b79SJean-Baptiste Boric 	return 0;
11009f988b79SJean-Baptiste Boric }
11019f988b79SJean-Baptiste Boric 
11029f988b79SJean-Baptiste Boric 
11039f988b79SJean-Baptiste Boric /* exported */
11049f988b79SJean-Baptiste Boric int
udf_chsize(struct vnode * vp,u_quad_t newsize,kauth_cred_t cred)11059f988b79SJean-Baptiste Boric udf_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred)
11069f988b79SJean-Baptiste Boric {
11079f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = VTOI(vp);
11089f988b79SJean-Baptiste Boric 	int error, extended;
11099f988b79SJean-Baptiste Boric 
11109f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
11119f988b79SJean-Baptiste Boric 		return EROFS;
11129f988b79SJean-Baptiste Boric 
11139f988b79SJean-Baptiste Boric 	/* Decide whether this is a valid operation based on the file type. */
11149f988b79SJean-Baptiste Boric 	switch (vp->v_type) {
11159f988b79SJean-Baptiste Boric 	case VDIR:
11169f988b79SJean-Baptiste Boric 		return EISDIR;
11179f988b79SJean-Baptiste Boric 	case VREG:
11189f988b79SJean-Baptiste Boric 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
11199f988b79SJean-Baptiste Boric 			return EROFS;
11209f988b79SJean-Baptiste Boric 		break;
11219f988b79SJean-Baptiste Boric 	case VBLK:
11229f988b79SJean-Baptiste Boric 		/* FALLTHROUGH */
11239f988b79SJean-Baptiste Boric 	case VCHR:
11249f988b79SJean-Baptiste Boric 		/* FALLTHROUGH */
11259f988b79SJean-Baptiste Boric 	case VFIFO:
11269f988b79SJean-Baptiste Boric 		/* Allow modifications of special files even if in the file
11279f988b79SJean-Baptiste Boric 		 * system is mounted read-only (we are not modifying the
11289f988b79SJean-Baptiste Boric 		 * files themselves, but the objects they represent). */
11299f988b79SJean-Baptiste Boric 		return 0;
11309f988b79SJean-Baptiste Boric 	default:
11319f988b79SJean-Baptiste Boric 		/* Anything else is unsupported. */
11329f988b79SJean-Baptiste Boric 		return EOPNOTSUPP;
11339f988b79SJean-Baptiste Boric 	}
11349f988b79SJean-Baptiste Boric 
11359f988b79SJean-Baptiste Boric #if notyet
11369f988b79SJean-Baptiste Boric 	/* TODO get vaflags from the extended attributes? */
11379f988b79SJean-Baptiste Boric 	/* Immutable or append-only files cannot be modified, either. */
11389f988b79SJean-Baptiste Boric 	if (node->flags & (IMMUTABLE | APPEND))
11399f988b79SJean-Baptiste Boric 		return EPERM;
11409f988b79SJean-Baptiste Boric #endif
11419f988b79SJean-Baptiste Boric 
11429f988b79SJean-Baptiste Boric 	/* resize file to the requested size */
11439f988b79SJean-Baptiste Boric 	error = udf_resize_node(udf_node, newsize, &extended);
11449f988b79SJean-Baptiste Boric 
11459f988b79SJean-Baptiste Boric 	if (error == 0) {
11469f988b79SJean-Baptiste Boric 		/* mark change */
11479f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_CHANGE | IN_MODIFY;
11489f988b79SJean-Baptiste Boric 		if (vp->v_mount->mnt_flag & MNT_RELATIME)
11499f988b79SJean-Baptiste Boric 			udf_node->i_flags |= IN_ACCESS;
11509f988b79SJean-Baptiste Boric 		VN_KNOTE(vp, NOTE_ATTRIB | (extended ? NOTE_EXTEND : 0));
11519f988b79SJean-Baptiste Boric 		udf_update(vp, NULL, NULL, NULL, 0);
11529f988b79SJean-Baptiste Boric 	}
11539f988b79SJean-Baptiste Boric 
11549f988b79SJean-Baptiste Boric 	return error;
11559f988b79SJean-Baptiste Boric }
11569f988b79SJean-Baptiste Boric 
11579f988b79SJean-Baptiste Boric 
11589f988b79SJean-Baptiste Boric static int
udf_chflags(struct vnode * vp,mode_t mode,kauth_cred_t cred)11599f988b79SJean-Baptiste Boric udf_chflags(struct vnode *vp, mode_t mode, kauth_cred_t cred)
11609f988b79SJean-Baptiste Boric {
11619f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
11629f988b79SJean-Baptiste Boric 		return EROFS;
11639f988b79SJean-Baptiste Boric 
11649f988b79SJean-Baptiste Boric 	/*
11659f988b79SJean-Baptiste Boric 	 * XXX we can't do this yet, as its not described in the standard yet
11669f988b79SJean-Baptiste Boric 	 */
11679f988b79SJean-Baptiste Boric 
11689f988b79SJean-Baptiste Boric 	return EOPNOTSUPP;
11699f988b79SJean-Baptiste Boric }
11709f988b79SJean-Baptiste Boric 
11719f988b79SJean-Baptiste Boric 
11729f988b79SJean-Baptiste Boric static int
udf_chtimes(struct vnode * vp,struct timespec * atime,struct timespec * mtime,struct timespec * birthtime,int setattrflags,kauth_cred_t cred)11739f988b79SJean-Baptiste Boric udf_chtimes(struct vnode *vp,
11749f988b79SJean-Baptiste Boric 	struct timespec *atime, struct timespec *mtime,
11759f988b79SJean-Baptiste Boric 	struct timespec *birthtime, int setattrflags,
11769f988b79SJean-Baptiste Boric 	kauth_cred_t cred)
11779f988b79SJean-Baptiste Boric {
11789f988b79SJean-Baptiste Boric 	struct udf_node  *udf_node = VTOI(vp);
11799f988b79SJean-Baptiste Boric 	uid_t uid;
11809f988b79SJean-Baptiste Boric 	gid_t gid;
11819f988b79SJean-Baptiste Boric 	int error;
11829f988b79SJean-Baptiste Boric 
11839f988b79SJean-Baptiste Boric #ifdef notyet
11849f988b79SJean-Baptiste Boric 	/* TODO get vaflags from the extended attributes? */
11859f988b79SJean-Baptiste Boric 	/* Immutable or append-only files cannot be modified, either. */
11869f988b79SJean-Baptiste Boric 	if (udf_node->flags & (IMMUTABLE | APPEND))
11879f988b79SJean-Baptiste Boric 		return EPERM;
11889f988b79SJean-Baptiste Boric #endif
11899f988b79SJean-Baptiste Boric 
11909f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
11919f988b79SJean-Baptiste Boric 		return EROFS;
11929f988b79SJean-Baptiste Boric 
11939f988b79SJean-Baptiste Boric 	/* retrieve uid/gid values */
11949f988b79SJean-Baptiste Boric 	udf_getownership(udf_node, &uid, &gid);
11959f988b79SJean-Baptiste Boric 
11969f988b79SJean-Baptiste Boric 	/* check permissions */
11979f988b79SJean-Baptiste Boric 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
11989f988b79SJean-Baptiste Boric 	    NULL, genfs_can_chtimes(vp, setattrflags, uid, cred));
11999f988b79SJean-Baptiste Boric 	if (error)
12009f988b79SJean-Baptiste Boric 		return (error);
12019f988b79SJean-Baptiste Boric 
12029f988b79SJean-Baptiste Boric 	/* update node flags depending on what times are passed */
12039f988b79SJean-Baptiste Boric 	if (atime->tv_sec != VNOVAL)
12049f988b79SJean-Baptiste Boric 		if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
12059f988b79SJean-Baptiste Boric 			udf_node->i_flags |= IN_ACCESS;
12069f988b79SJean-Baptiste Boric 	if ((mtime->tv_sec != VNOVAL) || (birthtime->tv_sec != VNOVAL)) {
12079f988b79SJean-Baptiste Boric 		udf_node->i_flags |= IN_CHANGE | IN_UPDATE;
12089f988b79SJean-Baptiste Boric 		if (vp->v_mount->mnt_flag & MNT_RELATIME)
12099f988b79SJean-Baptiste Boric 			udf_node->i_flags |= IN_ACCESS;
12109f988b79SJean-Baptiste Boric 	}
12119f988b79SJean-Baptiste Boric 
12129f988b79SJean-Baptiste Boric 	return udf_update(vp, atime, mtime, birthtime, 0);
12139f988b79SJean-Baptiste Boric }
12149f988b79SJean-Baptiste Boric 
12159f988b79SJean-Baptiste Boric 
12169f988b79SJean-Baptiste Boric int
udf_setattr(void * v)12179f988b79SJean-Baptiste Boric udf_setattr(void *v)
12189f988b79SJean-Baptiste Boric {
12199f988b79SJean-Baptiste Boric 	struct vop_setattr_args /* {
12209f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
12219f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
12229f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
12239f988b79SJean-Baptiste Boric 		struct lwp   *a_l;
12249f988b79SJean-Baptiste Boric 	} */ *ap = v;
12259f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
12269f988b79SJean-Baptiste Boric /*	struct udf_node  *udf_node = VTOI(vp); */
12279f988b79SJean-Baptiste Boric /*	struct udf_mount *ump = udf_node->ump; */
12289f988b79SJean-Baptiste Boric 	kauth_cred_t cred = ap->a_cred;
12299f988b79SJean-Baptiste Boric 	struct vattr *vap = ap->a_vap;
12309f988b79SJean-Baptiste Boric 	int error;
12319f988b79SJean-Baptiste Boric 
12329f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_setattr called\n"));
12339f988b79SJean-Baptiste Boric 
12349f988b79SJean-Baptiste Boric 	/* Abort if any unsettable attribute is given. */
12359f988b79SJean-Baptiste Boric 	error = 0;
12369f988b79SJean-Baptiste Boric 	if (vap->va_type != VNON ||
12379f988b79SJean-Baptiste Boric 	    vap->va_nlink != VNOVAL ||
12389f988b79SJean-Baptiste Boric 	    vap->va_fsid != VNOVAL ||
12399f988b79SJean-Baptiste Boric 	    vap->va_fileid != VNOVAL ||
12409f988b79SJean-Baptiste Boric 	    vap->va_blocksize != VNOVAL ||
12419f988b79SJean-Baptiste Boric #ifdef notyet
12429f988b79SJean-Baptiste Boric 	    /* checks are debated */
12439f988b79SJean-Baptiste Boric 	    vap->va_ctime.tv_sec != VNOVAL ||
12449f988b79SJean-Baptiste Boric 	    vap->va_ctime.tv_nsec != VNOVAL ||
12459f988b79SJean-Baptiste Boric 	    vap->va_birthtime.tv_sec != VNOVAL ||
12469f988b79SJean-Baptiste Boric 	    vap->va_birthtime.tv_nsec != VNOVAL ||
12479f988b79SJean-Baptiste Boric #endif
12489f988b79SJean-Baptiste Boric 	    vap->va_gen != VNOVAL ||
12499f988b79SJean-Baptiste Boric 	    vap->va_rdev != VNOVAL ||
12509f988b79SJean-Baptiste Boric 	    vap->va_bytes != VNOVAL)
12519f988b79SJean-Baptiste Boric 		error = EINVAL;
12529f988b79SJean-Baptiste Boric 
12539f988b79SJean-Baptiste Boric 	DPRINTF(ATTR, ("setattr changing:\n"));
12549f988b79SJean-Baptiste Boric 	if (error == 0 && (vap->va_flags != VNOVAL)) {
12559f988b79SJean-Baptiste Boric 		DPRINTF(ATTR, ("\tchflags\n"));
12569f988b79SJean-Baptiste Boric 	 	error = udf_chflags(vp, vap->va_flags, cred);
12579f988b79SJean-Baptiste Boric 	}
12589f988b79SJean-Baptiste Boric 
12599f988b79SJean-Baptiste Boric 	if (error == 0 && (vap->va_size != VNOVAL)) {
12609f988b79SJean-Baptiste Boric 		DPRINTF(ATTR, ("\tchsize\n"));
12619f988b79SJean-Baptiste Boric 		error = udf_chsize(vp, vap->va_size, cred);
12629f988b79SJean-Baptiste Boric 	}
12639f988b79SJean-Baptiste Boric 
12649f988b79SJean-Baptiste Boric 	if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) {
12659f988b79SJean-Baptiste Boric 		DPRINTF(ATTR, ("\tchown\n"));
12669f988b79SJean-Baptiste Boric 		error = udf_chown(vp, vap->va_uid, vap->va_gid, cred);
12679f988b79SJean-Baptiste Boric 	}
12689f988b79SJean-Baptiste Boric 
12699f988b79SJean-Baptiste Boric 	if (error == 0 && (vap->va_mode != VNOVAL)) {
12709f988b79SJean-Baptiste Boric 		DPRINTF(ATTR, ("\tchmod\n"));
12719f988b79SJean-Baptiste Boric 		error = udf_chmod(vp, vap->va_mode, cred);
12729f988b79SJean-Baptiste Boric 	}
12739f988b79SJean-Baptiste Boric 
12749f988b79SJean-Baptiste Boric 	if (error == 0 &&
12759f988b79SJean-Baptiste Boric 	    ((vap->va_atime.tv_sec != VNOVAL &&
12769f988b79SJean-Baptiste Boric 	      vap->va_atime.tv_nsec != VNOVAL)   ||
12779f988b79SJean-Baptiste Boric 	     (vap->va_mtime.tv_sec != VNOVAL &&
12789f988b79SJean-Baptiste Boric 	      vap->va_mtime.tv_nsec != VNOVAL))
12799f988b79SJean-Baptiste Boric 	    ) {
12809f988b79SJean-Baptiste Boric 		DPRINTF(ATTR, ("\tchtimes\n"));
12819f988b79SJean-Baptiste Boric 		error = udf_chtimes(vp, &vap->va_atime, &vap->va_mtime,
12829f988b79SJean-Baptiste Boric 		    &vap->va_birthtime, vap->va_vaflags, cred);
12839f988b79SJean-Baptiste Boric 	}
12849f988b79SJean-Baptiste Boric 	VN_KNOTE(vp, NOTE_ATTRIB);
12859f988b79SJean-Baptiste Boric 
12869f988b79SJean-Baptiste Boric 	return error;
12879f988b79SJean-Baptiste Boric }
12889f988b79SJean-Baptiste Boric 
12899f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
12909f988b79SJean-Baptiste Boric 
12919f988b79SJean-Baptiste Boric /*
12929f988b79SJean-Baptiste Boric  * Return POSIX pathconf information for UDF file systems.
12939f988b79SJean-Baptiste Boric  */
12949f988b79SJean-Baptiste Boric int
udf_pathconf(void * v)12959f988b79SJean-Baptiste Boric udf_pathconf(void *v)
12969f988b79SJean-Baptiste Boric {
12979f988b79SJean-Baptiste Boric 	struct vop_pathconf_args /* {
12989f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
12999f988b79SJean-Baptiste Boric 		int a_name;
13009f988b79SJean-Baptiste Boric 		register_t *a_retval;
13019f988b79SJean-Baptiste Boric 	} */ *ap = v;
13029f988b79SJean-Baptiste Boric 	uint32_t bits;
13039f988b79SJean-Baptiste Boric 
13049f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_pathconf called\n"));
13059f988b79SJean-Baptiste Boric 
13069f988b79SJean-Baptiste Boric 	switch (ap->a_name) {
13079f988b79SJean-Baptiste Boric 	case _PC_LINK_MAX:
13089f988b79SJean-Baptiste Boric 		*ap->a_retval = (1<<16)-1;	/* 16 bits */
13099f988b79SJean-Baptiste Boric 		return 0;
13109f988b79SJean-Baptiste Boric 	case _PC_NAME_MAX:
13119f988b79SJean-Baptiste Boric 		*ap->a_retval = UDF_MAXNAMLEN;
13129f988b79SJean-Baptiste Boric 		return 0;
13139f988b79SJean-Baptiste Boric 	case _PC_PATH_MAX:
13149f988b79SJean-Baptiste Boric 		*ap->a_retval = PATH_MAX;
13159f988b79SJean-Baptiste Boric 		return 0;
13169f988b79SJean-Baptiste Boric 	case _PC_PIPE_BUF:
13179f988b79SJean-Baptiste Boric 		*ap->a_retval = PIPE_BUF;
13189f988b79SJean-Baptiste Boric 		return 0;
13199f988b79SJean-Baptiste Boric 	case _PC_CHOWN_RESTRICTED:
13209f988b79SJean-Baptiste Boric 		*ap->a_retval = 1;
13219f988b79SJean-Baptiste Boric 		return 0;
13229f988b79SJean-Baptiste Boric 	case _PC_NO_TRUNC:
13239f988b79SJean-Baptiste Boric 		*ap->a_retval = 1;
13249f988b79SJean-Baptiste Boric 		return 0;
13259f988b79SJean-Baptiste Boric 	case _PC_SYNC_IO:
13269f988b79SJean-Baptiste Boric 		*ap->a_retval = 0;     /* synchronised is off for performance */
13279f988b79SJean-Baptiste Boric 		return 0;
13289f988b79SJean-Baptiste Boric 	case _PC_FILESIZEBITS:
13299f988b79SJean-Baptiste Boric 		/* 64 bit file offsets -> 2+floor(2log(2^64-1)) = 2 + 63 = 65 */
13309f988b79SJean-Baptiste Boric 		bits = 64; /* XXX ought to deliver 65 */
13319f988b79SJean-Baptiste Boric #if 0
13329f988b79SJean-Baptiste Boric 		if (udf_node)
13339f988b79SJean-Baptiste Boric 			bits = 64 * vp->v_mount->mnt_dev_bshift;
13349f988b79SJean-Baptiste Boric #endif
13359f988b79SJean-Baptiste Boric 		*ap->a_retval = bits;
13369f988b79SJean-Baptiste Boric 		return 0;
13379f988b79SJean-Baptiste Boric 	}
13389f988b79SJean-Baptiste Boric 
13399f988b79SJean-Baptiste Boric 	return EINVAL;
13409f988b79SJean-Baptiste Boric }
13419f988b79SJean-Baptiste Boric 
13429f988b79SJean-Baptiste Boric 
13439f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
13449f988b79SJean-Baptiste Boric 
13459f988b79SJean-Baptiste Boric int
udf_open(void * v)13469f988b79SJean-Baptiste Boric udf_open(void *v)
13479f988b79SJean-Baptiste Boric {
13489f988b79SJean-Baptiste Boric 	struct vop_open_args /* {
13499f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
13509f988b79SJean-Baptiste Boric 		int a_mode;
13519f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
13529f988b79SJean-Baptiste Boric 		struct proc *a_p;
13539f988b79SJean-Baptiste Boric 	} */ *ap = v;
13549f988b79SJean-Baptiste Boric 	int flags;
13559f988b79SJean-Baptiste Boric 
13569f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_open called\n"));
13579f988b79SJean-Baptiste Boric 
13589f988b79SJean-Baptiste Boric 	/*
13599f988b79SJean-Baptiste Boric 	 * Files marked append-only must be opened for appending.
13609f988b79SJean-Baptiste Boric 	 * TODO: get chflags(2) flags from extened attribute.
13619f988b79SJean-Baptiste Boric 	 */
13629f988b79SJean-Baptiste Boric 	flags = 0;
13639f988b79SJean-Baptiste Boric 	if ((flags & APPEND) && (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
13649f988b79SJean-Baptiste Boric 		return (EPERM);
13659f988b79SJean-Baptiste Boric 
13669f988b79SJean-Baptiste Boric 	return 0;
13679f988b79SJean-Baptiste Boric }
13689f988b79SJean-Baptiste Boric 
13699f988b79SJean-Baptiste Boric 
13709f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
13719f988b79SJean-Baptiste Boric 
13729f988b79SJean-Baptiste Boric int
udf_close(void * v)13739f988b79SJean-Baptiste Boric udf_close(void *v)
13749f988b79SJean-Baptiste Boric {
13759f988b79SJean-Baptiste Boric 	struct vop_close_args /* {
13769f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
13779f988b79SJean-Baptiste Boric 		int a_fflag;
13789f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
13799f988b79SJean-Baptiste Boric 		struct proc *a_p;
13809f988b79SJean-Baptiste Boric 	} */ *ap = v;
13819f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
13829f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
13839f988b79SJean-Baptiste Boric 	int async = vp->v_mount->mnt_flag & MNT_ASYNC;
13849f988b79SJean-Baptiste Boric 	int error;
13859f988b79SJean-Baptiste Boric 
13869f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_close called\n"));
13879f988b79SJean-Baptiste Boric 	udf_node = udf_node;	/* shut up gcc */
13889f988b79SJean-Baptiste Boric 
13899f988b79SJean-Baptiste Boric 	if (!async && (vp->v_type != VDIR)) {
13909f988b79SJean-Baptiste Boric 		mutex_enter(vp->v_interlock);
13919f988b79SJean-Baptiste Boric 		error = VOP_PUTPAGES(vp, 0, 0, PGO_CLEANIT);
13929f988b79SJean-Baptiste Boric 		if (error)
13939f988b79SJean-Baptiste Boric 			return error;
13949f988b79SJean-Baptiste Boric 	}
13959f988b79SJean-Baptiste Boric 
13969f988b79SJean-Baptiste Boric 	mutex_enter(vp->v_interlock);
13979f988b79SJean-Baptiste Boric 		if (vp->v_usecount > 1)
13989f988b79SJean-Baptiste Boric 			udf_itimes(udf_node, NULL, NULL, NULL);
13999f988b79SJean-Baptiste Boric 	mutex_exit(vp->v_interlock);
14009f988b79SJean-Baptiste Boric 
14019f988b79SJean-Baptiste Boric 	return 0;
14029f988b79SJean-Baptiste Boric }
14039f988b79SJean-Baptiste Boric 
14049f988b79SJean-Baptiste Boric 
14059f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
14069f988b79SJean-Baptiste Boric 
14079f988b79SJean-Baptiste Boric static int
udf_check_possible(struct vnode * vp,struct vattr * vap,mode_t mode)14089f988b79SJean-Baptiste Boric udf_check_possible(struct vnode *vp, struct vattr *vap, mode_t mode)
14099f988b79SJean-Baptiste Boric {
14109f988b79SJean-Baptiste Boric 	int flags;
14119f988b79SJean-Baptiste Boric 
14129f988b79SJean-Baptiste Boric 	/* check if we are allowed to write */
14139f988b79SJean-Baptiste Boric 	switch (vap->va_type) {
14149f988b79SJean-Baptiste Boric 	case VDIR:
14159f988b79SJean-Baptiste Boric 	case VLNK:
14169f988b79SJean-Baptiste Boric 	case VREG:
14179f988b79SJean-Baptiste Boric 		/*
14189f988b79SJean-Baptiste Boric 		 * normal nodes: check if we're on a read-only mounted
14199f988b79SJean-Baptiste Boric 		 * filingsystem and bomb out if we're trying to write.
14209f988b79SJean-Baptiste Boric 		 */
14219f988b79SJean-Baptiste Boric 		if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY))
14229f988b79SJean-Baptiste Boric 			return EROFS;
14239f988b79SJean-Baptiste Boric 		break;
14249f988b79SJean-Baptiste Boric 	case VBLK:
14259f988b79SJean-Baptiste Boric 	case VCHR:
14269f988b79SJean-Baptiste Boric 	case VSOCK:
14279f988b79SJean-Baptiste Boric 	case VFIFO:
14289f988b79SJean-Baptiste Boric 		/*
14299f988b79SJean-Baptiste Boric 		 * special nodes: even on read-only mounted filingsystems
14309f988b79SJean-Baptiste Boric 		 * these are allowed to be written to if permissions allow.
14319f988b79SJean-Baptiste Boric 		 */
14329f988b79SJean-Baptiste Boric 		break;
14339f988b79SJean-Baptiste Boric 	default:
14349f988b79SJean-Baptiste Boric 		/* no idea what this is */
14359f988b79SJean-Baptiste Boric 		return EINVAL;
14369f988b79SJean-Baptiste Boric 	}
14379f988b79SJean-Baptiste Boric 
14389f988b79SJean-Baptiste Boric 	/* noone may write immutable files */
14399f988b79SJean-Baptiste Boric 	/* TODO: get chflags(2) flags from extened attribute. */
14409f988b79SJean-Baptiste Boric 	flags = 0;
14419f988b79SJean-Baptiste Boric 	if ((mode & VWRITE) && (flags & IMMUTABLE))
14429f988b79SJean-Baptiste Boric 		return EPERM;
14439f988b79SJean-Baptiste Boric 
14449f988b79SJean-Baptiste Boric 	return 0;
14459f988b79SJean-Baptiste Boric }
14469f988b79SJean-Baptiste Boric 
14479f988b79SJean-Baptiste Boric static int
udf_check_permitted(struct vnode * vp,struct vattr * vap,mode_t mode,kauth_cred_t cred)14489f988b79SJean-Baptiste Boric udf_check_permitted(struct vnode *vp, struct vattr *vap, mode_t mode,
14499f988b79SJean-Baptiste Boric     kauth_cred_t cred)
14509f988b79SJean-Baptiste Boric {
14519f988b79SJean-Baptiste Boric 	/* ask the generic genfs_can_access to advice on security */
14529f988b79SJean-Baptiste Boric 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode,
14539f988b79SJean-Baptiste Boric 	    vp->v_type, vap->va_mode), vp, NULL, genfs_can_access(vp->v_type,
14549f988b79SJean-Baptiste Boric 	    vap->va_mode, vap->va_uid, vap->va_gid, mode, cred));
14559f988b79SJean-Baptiste Boric }
14569f988b79SJean-Baptiste Boric 
14579f988b79SJean-Baptiste Boric int
udf_access(void * v)14589f988b79SJean-Baptiste Boric udf_access(void *v)
14599f988b79SJean-Baptiste Boric {
14609f988b79SJean-Baptiste Boric 	struct vop_access_args /* {
14619f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
14629f988b79SJean-Baptiste Boric 		int a_mode;
14639f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
14649f988b79SJean-Baptiste Boric 		struct proc *a_p;
14659f988b79SJean-Baptiste Boric 	} */ *ap = v;
14669f988b79SJean-Baptiste Boric 	struct vnode    *vp   = ap->a_vp;
14679f988b79SJean-Baptiste Boric 	mode_t	         mode = ap->a_mode;
14689f988b79SJean-Baptiste Boric 	kauth_cred_t     cred = ap->a_cred;
14699f988b79SJean-Baptiste Boric 	/* struct udf_node *udf_node = VTOI(vp); */
14709f988b79SJean-Baptiste Boric 	struct vattr vap;
14719f988b79SJean-Baptiste Boric 	int error;
14729f988b79SJean-Baptiste Boric 
14739f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_access called\n"));
14749f988b79SJean-Baptiste Boric 
14759f988b79SJean-Baptiste Boric 	error = VOP_GETATTR(vp, &vap, NULL);
14769f988b79SJean-Baptiste Boric 	if (error)
14779f988b79SJean-Baptiste Boric 		return error;
14789f988b79SJean-Baptiste Boric 
14799f988b79SJean-Baptiste Boric 	error = udf_check_possible(vp, &vap, mode);
14809f988b79SJean-Baptiste Boric 	if (error)
14819f988b79SJean-Baptiste Boric 		return error;
14829f988b79SJean-Baptiste Boric 
14839f988b79SJean-Baptiste Boric 	error = udf_check_permitted(vp, &vap, mode, cred);
14849f988b79SJean-Baptiste Boric 
14859f988b79SJean-Baptiste Boric 	return error;
14869f988b79SJean-Baptiste Boric }
14879f988b79SJean-Baptiste Boric 
14889f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
14899f988b79SJean-Baptiste Boric 
14909f988b79SJean-Baptiste Boric int
udf_create(void * v)14919f988b79SJean-Baptiste Boric udf_create(void *v)
14929f988b79SJean-Baptiste Boric {
1493*0a6a1f1dSLionel Sambuc 	struct vop_create_v3_args /* {
14949f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
14959f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
14969f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
14979f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
14989f988b79SJean-Baptiste Boric 	} */ *ap = v;
14999f988b79SJean-Baptiste Boric 	struct vnode  *dvp = ap->a_dvp;
15009f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;
15019f988b79SJean-Baptiste Boric 	struct vattr  *vap  = ap->a_vap;
15029f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
15039f988b79SJean-Baptiste Boric 	int error;
15049f988b79SJean-Baptiste Boric 
15059f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_create called\n"));
15069f988b79SJean-Baptiste Boric 	error = udf_create_node(dvp, vpp, vap, cnp);
15079f988b79SJean-Baptiste Boric 
15089f988b79SJean-Baptiste Boric 	return error;
15099f988b79SJean-Baptiste Boric }
15109f988b79SJean-Baptiste Boric 
15119f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
15129f988b79SJean-Baptiste Boric 
15139f988b79SJean-Baptiste Boric int
udf_mknod(void * v)15149f988b79SJean-Baptiste Boric udf_mknod(void *v)
15159f988b79SJean-Baptiste Boric {
1516*0a6a1f1dSLionel Sambuc 	struct vop_mknod_v3_args /* {
15179f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
15189f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
15199f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
15209f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
15219f988b79SJean-Baptiste Boric 	} */ *ap = v;
15229f988b79SJean-Baptiste Boric 	struct vnode  *dvp = ap->a_dvp;
15239f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;
15249f988b79SJean-Baptiste Boric 	struct vattr  *vap  = ap->a_vap;
15259f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
15269f988b79SJean-Baptiste Boric 	int error;
15279f988b79SJean-Baptiste Boric 
15289f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_mknod called\n"));
15299f988b79SJean-Baptiste Boric 	error = udf_create_node(dvp, vpp, vap, cnp);
15309f988b79SJean-Baptiste Boric 
15319f988b79SJean-Baptiste Boric 	return error;
15329f988b79SJean-Baptiste Boric }
15339f988b79SJean-Baptiste Boric 
15349f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
15359f988b79SJean-Baptiste Boric 
15369f988b79SJean-Baptiste Boric int
udf_mkdir(void * v)15379f988b79SJean-Baptiste Boric udf_mkdir(void *v)
15389f988b79SJean-Baptiste Boric {
1539*0a6a1f1dSLionel Sambuc 	struct vop_mkdir_v3_args /* {
15409f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
15419f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
15429f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
15439f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
15449f988b79SJean-Baptiste Boric 	} */ *ap = v;
15459f988b79SJean-Baptiste Boric 	struct vnode  *dvp = ap->a_dvp;
15469f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;
15479f988b79SJean-Baptiste Boric 	struct vattr  *vap  = ap->a_vap;
15489f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
15499f988b79SJean-Baptiste Boric 	int error;
15509f988b79SJean-Baptiste Boric 
15519f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_mkdir called\n"));
15529f988b79SJean-Baptiste Boric 	error = udf_create_node(dvp, vpp, vap, cnp);
15539f988b79SJean-Baptiste Boric 
15549f988b79SJean-Baptiste Boric 	return error;
15559f988b79SJean-Baptiste Boric }
15569f988b79SJean-Baptiste Boric 
15579f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
15589f988b79SJean-Baptiste Boric 
15599f988b79SJean-Baptiste Boric static int
udf_do_link(struct vnode * dvp,struct vnode * vp,struct componentname * cnp)15609f988b79SJean-Baptiste Boric udf_do_link(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
15619f988b79SJean-Baptiste Boric {
15629f988b79SJean-Baptiste Boric 	struct udf_node *udf_node, *dir_node;
15639f988b79SJean-Baptiste Boric 	struct vattr vap;
15649f988b79SJean-Baptiste Boric 	int error;
15659f988b79SJean-Baptiste Boric 
15669f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_link called\n"));
15679f988b79SJean-Baptiste Boric 	KASSERT(dvp != vp);
15689f988b79SJean-Baptiste Boric 	KASSERT(vp->v_type != VDIR);
15699f988b79SJean-Baptiste Boric 	KASSERT(dvp->v_mount == vp->v_mount);
15709f988b79SJean-Baptiste Boric 
15719f988b79SJean-Baptiste Boric 	/* get attributes */
15729f988b79SJean-Baptiste Boric 	dir_node = VTOI(dvp);
15739f988b79SJean-Baptiste Boric 	udf_node = VTOI(vp);
15749f988b79SJean-Baptiste Boric 
15759f988b79SJean-Baptiste Boric 	error = VOP_GETATTR(vp, &vap, FSCRED);
15769f988b79SJean-Baptiste Boric 	if (error) {
15779f988b79SJean-Baptiste Boric 		VOP_UNLOCK(vp);
15789f988b79SJean-Baptiste Boric 		return error;
15799f988b79SJean-Baptiste Boric 	}
15809f988b79SJean-Baptiste Boric 
15819f988b79SJean-Baptiste Boric 	/* check link count overflow */
15829f988b79SJean-Baptiste Boric 	if (vap.va_nlink >= (1<<16)-1) {	/* uint16_t */
15839f988b79SJean-Baptiste Boric 		VOP_UNLOCK(vp);
15849f988b79SJean-Baptiste Boric 		return EMLINK;
15859f988b79SJean-Baptiste Boric 	}
15869f988b79SJean-Baptiste Boric 
15879f988b79SJean-Baptiste Boric 	error = udf_dir_attach(dir_node->ump, dir_node, udf_node, &vap, cnp);
15889f988b79SJean-Baptiste Boric 	if (error)
15899f988b79SJean-Baptiste Boric 		VOP_UNLOCK(vp);
15909f988b79SJean-Baptiste Boric 	return error;
15919f988b79SJean-Baptiste Boric }
15929f988b79SJean-Baptiste Boric 
15939f988b79SJean-Baptiste Boric int
udf_link(void * v)15949f988b79SJean-Baptiste Boric udf_link(void *v)
15959f988b79SJean-Baptiste Boric {
1596*0a6a1f1dSLionel Sambuc 	struct vop_link_v2_args /* {
15979f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
15989f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
15999f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
16009f988b79SJean-Baptiste Boric 	} */ *ap = v;
16019f988b79SJean-Baptiste Boric 	struct vnode *dvp = ap->a_dvp;
16029f988b79SJean-Baptiste Boric 	struct vnode *vp  = ap->a_vp;
16039f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
16049f988b79SJean-Baptiste Boric 	int error;
16059f988b79SJean-Baptiste Boric 
16069f988b79SJean-Baptiste Boric 	error = udf_do_link(dvp, vp, cnp);
16079f988b79SJean-Baptiste Boric 	if (error)
16089f988b79SJean-Baptiste Boric 		VOP_ABORTOP(dvp, cnp);
16099f988b79SJean-Baptiste Boric 
16109f988b79SJean-Baptiste Boric 	VN_KNOTE(vp, NOTE_LINK);
16119f988b79SJean-Baptiste Boric 	VN_KNOTE(dvp, NOTE_WRITE);
16129f988b79SJean-Baptiste Boric 
16139f988b79SJean-Baptiste Boric 	return error;
16149f988b79SJean-Baptiste Boric }
16159f988b79SJean-Baptiste Boric 
16169f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
16179f988b79SJean-Baptiste Boric 
16189f988b79SJean-Baptiste Boric static int
udf_do_symlink(struct udf_node * udf_node,char * target)16199f988b79SJean-Baptiste Boric udf_do_symlink(struct udf_node *udf_node, char *target)
16209f988b79SJean-Baptiste Boric {
16219f988b79SJean-Baptiste Boric 	struct pathcomp pathcomp;
16229f988b79SJean-Baptiste Boric 	uint8_t *pathbuf, *pathpos, *compnamepos;
16239f988b79SJean-Baptiste Boric 	char *mntonname;
16249f988b79SJean-Baptiste Boric 	int pathlen, len, compnamelen, mntonnamelen;
16259f988b79SJean-Baptiste Boric 	int error;
16269f988b79SJean-Baptiste Boric 
16279f988b79SJean-Baptiste Boric 	/* process `target' to an UDF structure */
16289f988b79SJean-Baptiste Boric 	pathbuf = malloc(UDF_SYMLINKBUFLEN, M_UDFTEMP, M_WAITOK);
16299f988b79SJean-Baptiste Boric 	pathpos = pathbuf;
16309f988b79SJean-Baptiste Boric 	pathlen = 0;
16319f988b79SJean-Baptiste Boric 
16329f988b79SJean-Baptiste Boric 	if (*target == '/') {
16339f988b79SJean-Baptiste Boric 		/* symlink starts from the root */
16349f988b79SJean-Baptiste Boric 		len = UDF_PATH_COMP_SIZE;
16359f988b79SJean-Baptiste Boric 		memset(&pathcomp, 0, len);
16369f988b79SJean-Baptiste Boric 		pathcomp.type = UDF_PATH_COMP_ROOT;
16379f988b79SJean-Baptiste Boric 
16389f988b79SJean-Baptiste Boric 		/* check if its mount-point relative! */
16399f988b79SJean-Baptiste Boric 		mntonname    = udf_node->ump->vfs_mountp->mnt_stat.f_mntonname;
16409f988b79SJean-Baptiste Boric 		mntonnamelen = strlen(mntonname);
16419f988b79SJean-Baptiste Boric 		if (strlen(target) >= mntonnamelen) {
16429f988b79SJean-Baptiste Boric 			if (strncmp(target, mntonname, mntonnamelen) == 0) {
16439f988b79SJean-Baptiste Boric 				pathcomp.type = UDF_PATH_COMP_MOUNTROOT;
16449f988b79SJean-Baptiste Boric 				target += mntonnamelen;
16459f988b79SJean-Baptiste Boric 			}
16469f988b79SJean-Baptiste Boric 		} else {
16479f988b79SJean-Baptiste Boric 			target++;
16489f988b79SJean-Baptiste Boric 		}
16499f988b79SJean-Baptiste Boric 
16509f988b79SJean-Baptiste Boric 		memcpy(pathpos, &pathcomp, len);
16519f988b79SJean-Baptiste Boric 		pathpos += len;
16529f988b79SJean-Baptiste Boric 		pathlen += len;
16539f988b79SJean-Baptiste Boric 	}
16549f988b79SJean-Baptiste Boric 
16559f988b79SJean-Baptiste Boric 	error = 0;
16569f988b79SJean-Baptiste Boric 	while (*target) {
16579f988b79SJean-Baptiste Boric 		/* ignore multiple '/' */
16589f988b79SJean-Baptiste Boric 		while (*target == '/') {
16599f988b79SJean-Baptiste Boric 			target++;
16609f988b79SJean-Baptiste Boric 		}
16619f988b79SJean-Baptiste Boric 		if (!*target)
16629f988b79SJean-Baptiste Boric 			break;
16639f988b79SJean-Baptiste Boric 
16649f988b79SJean-Baptiste Boric 		/* extract component name */
16659f988b79SJean-Baptiste Boric 		compnamelen = 0;
16669f988b79SJean-Baptiste Boric 		compnamepos = target;
16679f988b79SJean-Baptiste Boric 		while ((*target) && (*target != '/')) {
16689f988b79SJean-Baptiste Boric 			target++;
16699f988b79SJean-Baptiste Boric 			compnamelen++;
16709f988b79SJean-Baptiste Boric 		}
16719f988b79SJean-Baptiste Boric 
16729f988b79SJean-Baptiste Boric 		/* just trunc if too long ?? (security issue) */
16739f988b79SJean-Baptiste Boric 		if (compnamelen >= 127) {
16749f988b79SJean-Baptiste Boric 			error = ENAMETOOLONG;
16759f988b79SJean-Baptiste Boric 			break;
16769f988b79SJean-Baptiste Boric 		}
16779f988b79SJean-Baptiste Boric 
16789f988b79SJean-Baptiste Boric 		/* convert unix name to UDF name */
16799f988b79SJean-Baptiste Boric 		len = sizeof(struct pathcomp);
16809f988b79SJean-Baptiste Boric 		memset(&pathcomp, 0, len);
16819f988b79SJean-Baptiste Boric 		pathcomp.type = UDF_PATH_COMP_NAME;
16829f988b79SJean-Baptiste Boric 		len = UDF_PATH_COMP_SIZE;
16839f988b79SJean-Baptiste Boric 
16849f988b79SJean-Baptiste Boric 		if ((compnamelen == 2) && (strncmp(compnamepos, "..", 2) == 0))
16859f988b79SJean-Baptiste Boric 			pathcomp.type = UDF_PATH_COMP_PARENTDIR;
16869f988b79SJean-Baptiste Boric 		if ((compnamelen == 1) && (*compnamepos == '.'))
16879f988b79SJean-Baptiste Boric 			pathcomp.type = UDF_PATH_COMP_CURDIR;
16889f988b79SJean-Baptiste Boric 
16899f988b79SJean-Baptiste Boric 		if (pathcomp.type == UDF_PATH_COMP_NAME) {
16909f988b79SJean-Baptiste Boric 			unix_to_udf_name(
16919f988b79SJean-Baptiste Boric 				(char *) &pathcomp.ident, &pathcomp.l_ci,
16929f988b79SJean-Baptiste Boric 				compnamepos, compnamelen,
16939f988b79SJean-Baptiste Boric 				&udf_node->ump->logical_vol->desc_charset);
16949f988b79SJean-Baptiste Boric 			len = UDF_PATH_COMP_SIZE + pathcomp.l_ci;
16959f988b79SJean-Baptiste Boric 		}
16969f988b79SJean-Baptiste Boric 
16979f988b79SJean-Baptiste Boric 		if (pathlen + len >= UDF_SYMLINKBUFLEN) {
16989f988b79SJean-Baptiste Boric 			error = ENAMETOOLONG;
16999f988b79SJean-Baptiste Boric 			break;
17009f988b79SJean-Baptiste Boric 		}
17019f988b79SJean-Baptiste Boric 
17029f988b79SJean-Baptiste Boric 		memcpy(pathpos, &pathcomp, len);
17039f988b79SJean-Baptiste Boric 		pathpos += len;
17049f988b79SJean-Baptiste Boric 		pathlen += len;
17059f988b79SJean-Baptiste Boric 	}
17069f988b79SJean-Baptiste Boric 
17079f988b79SJean-Baptiste Boric 	if (error) {
17089f988b79SJean-Baptiste Boric 		/* aparently too big */
17099f988b79SJean-Baptiste Boric 		free(pathbuf, M_UDFTEMP);
17109f988b79SJean-Baptiste Boric 		return error;
17119f988b79SJean-Baptiste Boric 	}
17129f988b79SJean-Baptiste Boric 
17139f988b79SJean-Baptiste Boric 	error = udf_grow_node(udf_node, pathlen);
17149f988b79SJean-Baptiste Boric 	if (error) {
17159f988b79SJean-Baptiste Boric 		/* failed to pregrow node */
17169f988b79SJean-Baptiste Boric 		free(pathbuf, M_UDFTEMP);
17179f988b79SJean-Baptiste Boric 		return error;
17189f988b79SJean-Baptiste Boric 	}
17199f988b79SJean-Baptiste Boric 
17209f988b79SJean-Baptiste Boric 	/* write out structure on the new file */
17219f988b79SJean-Baptiste Boric 	error = vn_rdwr(UIO_WRITE, udf_node->vnode,
17229f988b79SJean-Baptiste Boric 		pathbuf, pathlen, 0,
17239f988b79SJean-Baptiste Boric 		UIO_SYSSPACE, IO_NODELOCKED | IO_ALTSEMANTICS,
17249f988b79SJean-Baptiste Boric 		FSCRED, NULL, NULL);
17259f988b79SJean-Baptiste Boric 
17269f988b79SJean-Baptiste Boric 	/* return status of symlink contents writeout */
17279f988b79SJean-Baptiste Boric 	free(pathbuf, M_UDFTEMP);
17289f988b79SJean-Baptiste Boric 	return error;
17299f988b79SJean-Baptiste Boric }
17309f988b79SJean-Baptiste Boric 
17319f988b79SJean-Baptiste Boric 
17329f988b79SJean-Baptiste Boric int
udf_symlink(void * v)17339f988b79SJean-Baptiste Boric udf_symlink(void *v)
17349f988b79SJean-Baptiste Boric {
1735*0a6a1f1dSLionel Sambuc 	struct vop_symlink_v3_args /* {
17369f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
17379f988b79SJean-Baptiste Boric 		struct vnode **a_vpp;
17389f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
17399f988b79SJean-Baptiste Boric 		struct vattr *a_vap;
17409f988b79SJean-Baptiste Boric 		char *a_target;
17419f988b79SJean-Baptiste Boric 	} */ *ap = v;
17429f988b79SJean-Baptiste Boric 	struct vnode  *dvp = ap->a_dvp;
17439f988b79SJean-Baptiste Boric 	struct vnode **vpp = ap->a_vpp;
17449f988b79SJean-Baptiste Boric 	struct vattr  *vap  = ap->a_vap;
17459f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
17469f988b79SJean-Baptiste Boric 	struct udf_node *dir_node;
17479f988b79SJean-Baptiste Boric 	struct udf_node *udf_node;
17489f988b79SJean-Baptiste Boric 	int error;
17499f988b79SJean-Baptiste Boric 
17509f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_symlink called\n"));
17519f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("\tlinking to `%s`\n",  ap->a_target));
17529f988b79SJean-Baptiste Boric 	error = udf_create_node(dvp, vpp, vap, cnp);
17539f988b79SJean-Baptiste Boric 	KASSERT(((error == 0) && (*vpp != NULL)) || ((error && (*vpp == NULL))));
17549f988b79SJean-Baptiste Boric 	if (!error) {
17559f988b79SJean-Baptiste Boric 		dir_node = VTOI(dvp);
17569f988b79SJean-Baptiste Boric 		udf_node = VTOI(*vpp);
17579f988b79SJean-Baptiste Boric 		KASSERT(udf_node);
17589f988b79SJean-Baptiste Boric 		error = udf_do_symlink(udf_node, ap->a_target);
17599f988b79SJean-Baptiste Boric 		if (error) {
17609f988b79SJean-Baptiste Boric 			/* remove node */
17619f988b79SJean-Baptiste Boric 			udf_dir_detach(udf_node->ump, dir_node, udf_node, cnp);
1762*0a6a1f1dSLionel Sambuc 			vrele(*vpp);
1763*0a6a1f1dSLionel Sambuc 			*vpp = NULL;
17649f988b79SJean-Baptiste Boric 		}
17659f988b79SJean-Baptiste Boric 	}
17669f988b79SJean-Baptiste Boric 	return error;
17679f988b79SJean-Baptiste Boric }
17689f988b79SJean-Baptiste Boric 
17699f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
17709f988b79SJean-Baptiste Boric 
1771*0a6a1f1dSLionel Sambuc static int
udf_do_readlink(struct udf_node * udf_node,uint64_t filesize,uint8_t * targetbuf,int * length)1772*0a6a1f1dSLionel Sambuc udf_do_readlink(struct udf_node *udf_node, uint64_t filesize,
1773*0a6a1f1dSLionel Sambuc 	uint8_t *targetbuf, int *length)
17749f988b79SJean-Baptiste Boric {
17759f988b79SJean-Baptiste Boric 	struct pathcomp pathcomp;
1776*0a6a1f1dSLionel Sambuc 	uint8_t *pathbuf, *tmpname;
17779f988b79SJean-Baptiste Boric 	uint8_t *pathpos, *targetpos;
17789f988b79SJean-Baptiste Boric 	char *mntonname;
17799f988b79SJean-Baptiste Boric 	int pathlen, targetlen, namelen, mntonnamelen, len, l_ci;
17809f988b79SJean-Baptiste Boric 	int first, error;
17819f988b79SJean-Baptiste Boric 
17829f988b79SJean-Baptiste Boric 	pathbuf   = malloc(UDF_SYMLINKBUFLEN, M_UDFTEMP, M_WAITOK);
17839f988b79SJean-Baptiste Boric 	tmpname   = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK);
17849f988b79SJean-Baptiste Boric 	memset(pathbuf, 0, UDF_SYMLINKBUFLEN);
17859f988b79SJean-Baptiste Boric 	memset(targetbuf, 0, PATH_MAX);
17869f988b79SJean-Baptiste Boric 
17879f988b79SJean-Baptiste Boric 	/* read contents of file in our temporary buffer */
17889f988b79SJean-Baptiste Boric 	error = vn_rdwr(UIO_READ, udf_node->vnode,
1789*0a6a1f1dSLionel Sambuc 		pathbuf, filesize, 0,
17909f988b79SJean-Baptiste Boric 		UIO_SYSSPACE, IO_NODELOCKED | IO_ALTSEMANTICS,
17919f988b79SJean-Baptiste Boric 		FSCRED, NULL, NULL);
17929f988b79SJean-Baptiste Boric 	if (error) {
17939f988b79SJean-Baptiste Boric 		/* failed to read in symlink contents */
17949f988b79SJean-Baptiste Boric 		free(pathbuf, M_UDFTEMP);
17959f988b79SJean-Baptiste Boric 		free(tmpname, M_UDFTEMP);
17969f988b79SJean-Baptiste Boric 		return error;
17979f988b79SJean-Baptiste Boric 	}
17989f988b79SJean-Baptiste Boric 
17999f988b79SJean-Baptiste Boric 	/* convert to a unix path */
18009f988b79SJean-Baptiste Boric 	pathpos   = pathbuf;
18019f988b79SJean-Baptiste Boric 	pathlen   = 0;
18029f988b79SJean-Baptiste Boric 	targetpos = targetbuf;
18039f988b79SJean-Baptiste Boric 	targetlen = PATH_MAX;
18049f988b79SJean-Baptiste Boric 	mntonname    = udf_node->ump->vfs_mountp->mnt_stat.f_mntonname;
18059f988b79SJean-Baptiste Boric 	mntonnamelen = strlen(mntonname);
18069f988b79SJean-Baptiste Boric 
18079f988b79SJean-Baptiste Boric 	error = 0;
18089f988b79SJean-Baptiste Boric 	first = 1;
1809*0a6a1f1dSLionel Sambuc 	while (filesize - pathlen >= UDF_PATH_COMP_SIZE) {
18109f988b79SJean-Baptiste Boric 		len = UDF_PATH_COMP_SIZE;
18119f988b79SJean-Baptiste Boric 		memcpy(&pathcomp, pathpos, len);
18129f988b79SJean-Baptiste Boric 		l_ci = pathcomp.l_ci;
18139f988b79SJean-Baptiste Boric 		switch (pathcomp.type) {
18149f988b79SJean-Baptiste Boric 		case UDF_PATH_COMP_ROOT :
18159f988b79SJean-Baptiste Boric 			/* XXX should check for l_ci; bugcompatible now */
18169f988b79SJean-Baptiste Boric 			if ((targetlen < 1) || !first) {
18179f988b79SJean-Baptiste Boric 				error = EINVAL;
18189f988b79SJean-Baptiste Boric 				break;
18199f988b79SJean-Baptiste Boric 			}
18209f988b79SJean-Baptiste Boric 			*targetpos++ = '/'; targetlen--;
18219f988b79SJean-Baptiste Boric 			break;
18229f988b79SJean-Baptiste Boric 		case UDF_PATH_COMP_MOUNTROOT :
18239f988b79SJean-Baptiste Boric 			/* XXX what should it be if l_ci > 0 ? [4/48.16.1.2] */
18249f988b79SJean-Baptiste Boric 			if (l_ci || (targetlen < mntonnamelen+1) || !first) {
18259f988b79SJean-Baptiste Boric 				error = EINVAL;
18269f988b79SJean-Baptiste Boric 				break;
18279f988b79SJean-Baptiste Boric 			}
18289f988b79SJean-Baptiste Boric 			memcpy(targetpos, mntonname, mntonnamelen);
18299f988b79SJean-Baptiste Boric 			targetpos += mntonnamelen; targetlen -= mntonnamelen;
1830*0a6a1f1dSLionel Sambuc 			if (filesize-pathlen > UDF_PATH_COMP_SIZE+l_ci) {
18319f988b79SJean-Baptiste Boric 				/* more follows, so must be directory */
18329f988b79SJean-Baptiste Boric 				*targetpos++ = '/'; targetlen--;
18339f988b79SJean-Baptiste Boric 			}
18349f988b79SJean-Baptiste Boric 			break;
18359f988b79SJean-Baptiste Boric 		case UDF_PATH_COMP_PARENTDIR :
18369f988b79SJean-Baptiste Boric 			/* XXX should check for l_ci; bugcompatible now */
18379f988b79SJean-Baptiste Boric 			if (targetlen < 3) {
18389f988b79SJean-Baptiste Boric 				error = EINVAL;
18399f988b79SJean-Baptiste Boric 				break;
18409f988b79SJean-Baptiste Boric 			}
18419f988b79SJean-Baptiste Boric 			*targetpos++ = '.'; targetlen--;
18429f988b79SJean-Baptiste Boric 			*targetpos++ = '.'; targetlen--;
18439f988b79SJean-Baptiste Boric 			*targetpos++ = '/'; targetlen--;
18449f988b79SJean-Baptiste Boric 			break;
18459f988b79SJean-Baptiste Boric 		case UDF_PATH_COMP_CURDIR :
18469f988b79SJean-Baptiste Boric 			/* XXX should check for l_ci; bugcompatible now */
18479f988b79SJean-Baptiste Boric 			if (targetlen < 2) {
18489f988b79SJean-Baptiste Boric 				error = EINVAL;
18499f988b79SJean-Baptiste Boric 				break;
18509f988b79SJean-Baptiste Boric 			}
18519f988b79SJean-Baptiste Boric 			*targetpos++ = '.'; targetlen--;
18529f988b79SJean-Baptiste Boric 			*targetpos++ = '/'; targetlen--;
18539f988b79SJean-Baptiste Boric 			break;
18549f988b79SJean-Baptiste Boric 		case UDF_PATH_COMP_NAME :
18559f988b79SJean-Baptiste Boric 			if (l_ci == 0) {
18569f988b79SJean-Baptiste Boric 				error = EINVAL;
18579f988b79SJean-Baptiste Boric 				break;
18589f988b79SJean-Baptiste Boric 			}
18599f988b79SJean-Baptiste Boric 			memset(tmpname, 0, PATH_MAX);
18609f988b79SJean-Baptiste Boric 			memcpy(&pathcomp, pathpos, len + l_ci);
18619f988b79SJean-Baptiste Boric 			udf_to_unix_name(tmpname, MAXPATHLEN,
18629f988b79SJean-Baptiste Boric 				pathcomp.ident, l_ci,
18639f988b79SJean-Baptiste Boric 				&udf_node->ump->logical_vol->desc_charset);
18649f988b79SJean-Baptiste Boric 			namelen = strlen(tmpname);
18659f988b79SJean-Baptiste Boric 			if (targetlen < namelen + 1) {
18669f988b79SJean-Baptiste Boric 				error = EINVAL;
18679f988b79SJean-Baptiste Boric 				break;
18689f988b79SJean-Baptiste Boric 			}
18699f988b79SJean-Baptiste Boric 			memcpy(targetpos, tmpname, namelen);
18709f988b79SJean-Baptiste Boric 			targetpos += namelen; targetlen -= namelen;
1871*0a6a1f1dSLionel Sambuc 			if (filesize-pathlen > UDF_PATH_COMP_SIZE+l_ci) {
18729f988b79SJean-Baptiste Boric 				/* more follows, so must be directory */
18739f988b79SJean-Baptiste Boric 				*targetpos++ = '/'; targetlen--;
18749f988b79SJean-Baptiste Boric 			}
18759f988b79SJean-Baptiste Boric 			break;
18769f988b79SJean-Baptiste Boric 		default :
18779f988b79SJean-Baptiste Boric 			error = EINVAL;
18789f988b79SJean-Baptiste Boric 			break;
18799f988b79SJean-Baptiste Boric 		}
18809f988b79SJean-Baptiste Boric 		first = 0;
18819f988b79SJean-Baptiste Boric 		if (error)
18829f988b79SJean-Baptiste Boric 			break;
18839f988b79SJean-Baptiste Boric 		pathpos += UDF_PATH_COMP_SIZE + l_ci;
18849f988b79SJean-Baptiste Boric 		pathlen += UDF_PATH_COMP_SIZE + l_ci;
18859f988b79SJean-Baptiste Boric 
18869f988b79SJean-Baptiste Boric 	}
18879f988b79SJean-Baptiste Boric 	/* all processed? */
1888*0a6a1f1dSLionel Sambuc 	if (filesize - pathlen > 0)
18899f988b79SJean-Baptiste Boric 		error = EINVAL;
18909f988b79SJean-Baptiste Boric 
1891*0a6a1f1dSLionel Sambuc 	free(pathbuf, M_UDFTEMP);
1892*0a6a1f1dSLionel Sambuc 	free(tmpname, M_UDFTEMP);
1893*0a6a1f1dSLionel Sambuc 
1894*0a6a1f1dSLionel Sambuc 	*length = PATH_MAX - targetlen;
1895*0a6a1f1dSLionel Sambuc 	return error;
1896*0a6a1f1dSLionel Sambuc }
1897*0a6a1f1dSLionel Sambuc 
1898*0a6a1f1dSLionel Sambuc 
1899*0a6a1f1dSLionel Sambuc int
udf_readlink(void * v)1900*0a6a1f1dSLionel Sambuc udf_readlink(void *v)
1901*0a6a1f1dSLionel Sambuc {
1902*0a6a1f1dSLionel Sambuc 	struct vop_readlink_args /* {
1903*0a6a1f1dSLionel Sambuc 		struct vnode *a_vp;
1904*0a6a1f1dSLionel Sambuc 		struct uio *a_uio;
1905*0a6a1f1dSLionel Sambuc 		kauth_cred_t a_cred;
1906*0a6a1f1dSLionel Sambuc 	} */ *ap = v;
1907*0a6a1f1dSLionel Sambuc 	struct vnode *vp = ap->a_vp;
1908*0a6a1f1dSLionel Sambuc 	struct udf_node *udf_node = VTOI(vp);
1909*0a6a1f1dSLionel Sambuc 	struct file_entry    *fe  = udf_node->fe;
1910*0a6a1f1dSLionel Sambuc 	struct extfile_entry *efe = udf_node->efe;
1911*0a6a1f1dSLionel Sambuc 	struct uio *uio = ap->a_uio;
1912*0a6a1f1dSLionel Sambuc 	uint64_t filesize;
1913*0a6a1f1dSLionel Sambuc 	uint8_t *targetbuf;
1914*0a6a1f1dSLionel Sambuc 	int length;
1915*0a6a1f1dSLionel Sambuc 	int error;
1916*0a6a1f1dSLionel Sambuc 
1917*0a6a1f1dSLionel Sambuc 	DPRINTF(CALL, ("udf_readlink called\n"));
1918*0a6a1f1dSLionel Sambuc 
1919*0a6a1f1dSLionel Sambuc 	if (fe) {
1920*0a6a1f1dSLionel Sambuc 		filesize = udf_rw64(fe->inf_len);
1921*0a6a1f1dSLionel Sambuc 	} else {
1922*0a6a1f1dSLionel Sambuc 		assert(udf_node->efe);
1923*0a6a1f1dSLionel Sambuc 		filesize = udf_rw64(efe->inf_len);
1924*0a6a1f1dSLionel Sambuc 	}
1925*0a6a1f1dSLionel Sambuc 
1926*0a6a1f1dSLionel Sambuc 	/* claim temporary buffers for translation */
1927*0a6a1f1dSLionel Sambuc 	targetbuf = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK);
1928*0a6a1f1dSLionel Sambuc 
1929*0a6a1f1dSLionel Sambuc 	error = udf_do_readlink(udf_node, filesize, targetbuf, &length);
1930*0a6a1f1dSLionel Sambuc 
19319f988b79SJean-Baptiste Boric 	/* uiomove() to destination */
19329f988b79SJean-Baptiste Boric 	if (!error)
1933*0a6a1f1dSLionel Sambuc 		uiomove(targetbuf, length, uio);
19349f988b79SJean-Baptiste Boric 
19359f988b79SJean-Baptiste Boric 	free(targetbuf, M_UDFTEMP);
19369f988b79SJean-Baptiste Boric 	return error;
19379f988b79SJean-Baptiste Boric }
19389f988b79SJean-Baptiste Boric 
19399f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
19409f988b79SJean-Baptiste Boric 
19419f988b79SJean-Baptiste Boric /*
19429f988b79SJean-Baptiste Boric  * udf_rename() moved to udf_rename.c
19439f988b79SJean-Baptiste Boric  */
19449f988b79SJean-Baptiste Boric 
19459f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
19469f988b79SJean-Baptiste Boric 
19479f988b79SJean-Baptiste Boric int
udf_remove(void * v)19489f988b79SJean-Baptiste Boric udf_remove(void *v)
19499f988b79SJean-Baptiste Boric {
19509f988b79SJean-Baptiste Boric 	struct vop_remove_args /* {
19519f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
19529f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
19539f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
19549f988b79SJean-Baptiste Boric 	} */ *ap = v;
19559f988b79SJean-Baptiste Boric 	struct vnode *dvp = ap->a_dvp;
19569f988b79SJean-Baptiste Boric 	struct vnode *vp  = ap->a_vp;
19579f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
19589f988b79SJean-Baptiste Boric 	struct udf_node *dir_node = VTOI(dvp);
19599f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
19609f988b79SJean-Baptiste Boric 	struct udf_mount *ump = dir_node->ump;
19619f988b79SJean-Baptiste Boric 	int error;
19629f988b79SJean-Baptiste Boric 
19639f988b79SJean-Baptiste Boric 	DPRINTF(CALL, ("udf_remove called\n"));
19649f988b79SJean-Baptiste Boric 	if (vp->v_type != VDIR) {
19659f988b79SJean-Baptiste Boric 		error = udf_dir_detach(ump, dir_node, udf_node, cnp);
19669f988b79SJean-Baptiste Boric 		DPRINTFIF(NODE, error, ("\tgot error removing file\n"));
19679f988b79SJean-Baptiste Boric 	} else {
19689f988b79SJean-Baptiste Boric 		DPRINTF(NODE, ("\tis a directory: perm. denied\n"));
19699f988b79SJean-Baptiste Boric 		error = EPERM;
19709f988b79SJean-Baptiste Boric 	}
19719f988b79SJean-Baptiste Boric 
19729f988b79SJean-Baptiste Boric 	if (error == 0) {
19739f988b79SJean-Baptiste Boric 		VN_KNOTE(vp, NOTE_DELETE);
19749f988b79SJean-Baptiste Boric 		VN_KNOTE(dvp, NOTE_WRITE);
19759f988b79SJean-Baptiste Boric 	}
19769f988b79SJean-Baptiste Boric 
19779f988b79SJean-Baptiste Boric 	if (dvp == vp)
19789f988b79SJean-Baptiste Boric 		vrele(vp);
19799f988b79SJean-Baptiste Boric 	else
19809f988b79SJean-Baptiste Boric 		vput(vp);
19819f988b79SJean-Baptiste Boric 	vput(dvp);
19829f988b79SJean-Baptiste Boric 
19839f988b79SJean-Baptiste Boric 	return error;
19849f988b79SJean-Baptiste Boric }
19859f988b79SJean-Baptiste Boric 
19869f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
19879f988b79SJean-Baptiste Boric 
19889f988b79SJean-Baptiste Boric int
udf_rmdir(void * v)19899f988b79SJean-Baptiste Boric udf_rmdir(void *v)
19909f988b79SJean-Baptiste Boric {
19919f988b79SJean-Baptiste Boric 	struct vop_rmdir_args /* {
19929f988b79SJean-Baptiste Boric 		struct vnode *a_dvp;
19939f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
19949f988b79SJean-Baptiste Boric 		struct componentname *a_cnp;
19959f988b79SJean-Baptiste Boric 	} */ *ap = v;
19969f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
19979f988b79SJean-Baptiste Boric 	struct vnode *dvp = ap->a_dvp;
19989f988b79SJean-Baptiste Boric 	struct componentname *cnp = ap->a_cnp;
19999f988b79SJean-Baptiste Boric 	struct udf_node *dir_node = VTOI(dvp);
20009f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
20019f988b79SJean-Baptiste Boric 	struct udf_mount *ump = dir_node->ump;
20029f988b79SJean-Baptiste Boric 	int error, isempty;
20039f988b79SJean-Baptiste Boric 
20049f988b79SJean-Baptiste Boric 	DPRINTF(NOTIMPL, ("udf_rmdir '%s' called\n", cnp->cn_nameptr));
20059f988b79SJean-Baptiste Boric 
20069f988b79SJean-Baptiste Boric 	/* don't allow '.' to be deleted */
20079f988b79SJean-Baptiste Boric 	if (dir_node == udf_node) {
20089f988b79SJean-Baptiste Boric 		vrele(dvp);
20099f988b79SJean-Baptiste Boric 		vput(vp);
20109f988b79SJean-Baptiste Boric 		return EINVAL;
20119f988b79SJean-Baptiste Boric 	}
20129f988b79SJean-Baptiste Boric 
20139f988b79SJean-Baptiste Boric 	/* make sure our `leaf' node's hash is populated */
20149f988b79SJean-Baptiste Boric 	dirhash_get(&udf_node->dir_hash);
20159f988b79SJean-Baptiste Boric 	error = udf_dirhash_fill(udf_node);
20169f988b79SJean-Baptiste Boric 	if (error) {
20179f988b79SJean-Baptiste Boric 		dirhash_put(udf_node->dir_hash);
20189f988b79SJean-Baptiste Boric 		return error;
20199f988b79SJean-Baptiste Boric 	}
20209f988b79SJean-Baptiste Boric 
20219f988b79SJean-Baptiste Boric 	/* check to see if the directory is empty */
20229f988b79SJean-Baptiste Boric 	isempty = dirhash_dir_isempty(udf_node->dir_hash);
20239f988b79SJean-Baptiste Boric 	dirhash_put(udf_node->dir_hash);
20249f988b79SJean-Baptiste Boric 
20259f988b79SJean-Baptiste Boric 	if (!isempty) {
20269f988b79SJean-Baptiste Boric 		vput(dvp);
20279f988b79SJean-Baptiste Boric 		vput(vp);
20289f988b79SJean-Baptiste Boric 		return ENOTEMPTY;
20299f988b79SJean-Baptiste Boric 	}
20309f988b79SJean-Baptiste Boric 
20319f988b79SJean-Baptiste Boric 	/* detach the node from the directory, udf_node is an empty dir here */
20329f988b79SJean-Baptiste Boric 	error = udf_dir_detach(ump, dir_node, udf_node, cnp);
20339f988b79SJean-Baptiste Boric 	if (error == 0) {
20349f988b79SJean-Baptiste Boric 		cache_purge(vp);
20359f988b79SJean-Baptiste Boric //		cache_purge(dvp);	/* XXX from msdosfs, why? */
20369f988b79SJean-Baptiste Boric 		/*
20379f988b79SJean-Baptiste Boric 		 * Bug alert: we need to remove '..' from the detaching
20389f988b79SJean-Baptiste Boric 		 * udf_node so further lookups of this are not possible. This
20399f988b79SJean-Baptiste Boric 		 * prevents a process in a deleted directory from going to its
20409f988b79SJean-Baptiste Boric 		 * deleted parent. Since `udf_node' is garanteed to be empty
20419f988b79SJean-Baptiste Boric 		 * here, trunc it so no fids are there.
20429f988b79SJean-Baptiste Boric 		 */
20439f988b79SJean-Baptiste Boric 		dirhash_purge(&udf_node->dir_hash);
20449f988b79SJean-Baptiste Boric 		udf_shrink_node(udf_node, 0);
20459f988b79SJean-Baptiste Boric 		VN_KNOTE(vp, NOTE_DELETE);
20469f988b79SJean-Baptiste Boric 	}
20479f988b79SJean-Baptiste Boric 	DPRINTFIF(NODE, error, ("\tgot error removing dir\n"));
20489f988b79SJean-Baptiste Boric 
20499f988b79SJean-Baptiste Boric 	/* unput the nodes and exit */
20509f988b79SJean-Baptiste Boric 	vput(dvp);
20519f988b79SJean-Baptiste Boric 	vput(vp);
20529f988b79SJean-Baptiste Boric 
20539f988b79SJean-Baptiste Boric 	return error;
20549f988b79SJean-Baptiste Boric }
20559f988b79SJean-Baptiste Boric 
20569f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
20579f988b79SJean-Baptiste Boric 
20589f988b79SJean-Baptiste Boric int
udf_fsync(void * v)20599f988b79SJean-Baptiste Boric udf_fsync(void *v)
20609f988b79SJean-Baptiste Boric {
20619f988b79SJean-Baptiste Boric 	struct vop_fsync_args /* {
20629f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
20639f988b79SJean-Baptiste Boric 		kauth_cred_t a_cred;
20649f988b79SJean-Baptiste Boric 		int a_flags;
20659f988b79SJean-Baptiste Boric 		off_t offlo;
20669f988b79SJean-Baptiste Boric 		off_t offhi;
20679f988b79SJean-Baptiste Boric 		struct proc *a_p;
20689f988b79SJean-Baptiste Boric 	} */ *ap = v;
20699f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
20709f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
20719f988b79SJean-Baptiste Boric 	int error, flags, wait;
20729f988b79SJean-Baptiste Boric 
20739f988b79SJean-Baptiste Boric 	DPRINTF(SYNC, ("udf_fsync called on %p : %s, %s\n",
20749f988b79SJean-Baptiste Boric 		udf_node,
20759f988b79SJean-Baptiste Boric 		(ap->a_flags & FSYNC_WAIT)     ? "wait":"no wait",
20769f988b79SJean-Baptiste Boric 		(ap->a_flags & FSYNC_DATAONLY) ? "data_only":"complete"));
20779f988b79SJean-Baptiste Boric 
20789f988b79SJean-Baptiste Boric 	/* flush data and wait for it when requested */
20799f988b79SJean-Baptiste Boric 	wait = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
20809f988b79SJean-Baptiste Boric 	error = vflushbuf(vp, ap->a_flags);
20819f988b79SJean-Baptiste Boric 	if (error)
20829f988b79SJean-Baptiste Boric 		return error;
20839f988b79SJean-Baptiste Boric 
20849f988b79SJean-Baptiste Boric 	if (udf_node == NULL) {
20859f988b79SJean-Baptiste Boric 		printf("udf_fsync() called on NULL udf_node!\n");
20869f988b79SJean-Baptiste Boric 		return 0;
20879f988b79SJean-Baptiste Boric 	}
20889f988b79SJean-Baptiste Boric 	if (vp->v_tag != VT_UDF) {
20899f988b79SJean-Baptiste Boric 		printf("udf_fsync() called on node not tagged as UDF node!\n");
20909f988b79SJean-Baptiste Boric 		return 0;
20919f988b79SJean-Baptiste Boric 	}
20929f988b79SJean-Baptiste Boric 
20939f988b79SJean-Baptiste Boric 	/* set our times */
20949f988b79SJean-Baptiste Boric 	udf_itimes(udf_node, NULL, NULL, NULL);
20959f988b79SJean-Baptiste Boric 
20969f988b79SJean-Baptiste Boric 	/* if called when mounted readonly, never write back */
20979f988b79SJean-Baptiste Boric 	if (vp->v_mount->mnt_flag & MNT_RDONLY)
20989f988b79SJean-Baptiste Boric 		return 0;
20999f988b79SJean-Baptiste Boric 
21009f988b79SJean-Baptiste Boric 	/* if only data is requested, return */
21019f988b79SJean-Baptiste Boric 	if (ap->a_flags & FSYNC_DATAONLY)
21029f988b79SJean-Baptiste Boric 		return 0;
21039f988b79SJean-Baptiste Boric 
21049f988b79SJean-Baptiste Boric 	/* check if the node is dirty 'enough'*/
21059f988b79SJean-Baptiste Boric 	flags = udf_node->i_flags & (IN_MODIFIED | IN_ACCESSED);
21069f988b79SJean-Baptiste Boric 	if (flags == 0)
21079f988b79SJean-Baptiste Boric 		return 0;
21089f988b79SJean-Baptiste Boric 
21099f988b79SJean-Baptiste Boric 	/* if we don't have to wait, check for IO pending */
21109f988b79SJean-Baptiste Boric 	if (!wait) {
21119f988b79SJean-Baptiste Boric 		if (vp->v_numoutput > 0) {
21129f988b79SJean-Baptiste Boric 			DPRINTF(SYNC, ("udf_fsync %p, rejecting on v_numoutput\n", udf_node));
21139f988b79SJean-Baptiste Boric 			return 0;
21149f988b79SJean-Baptiste Boric 		}
21159f988b79SJean-Baptiste Boric 		if (udf_node->outstanding_bufs > 0) {
21169f988b79SJean-Baptiste Boric 			DPRINTF(SYNC, ("udf_fsync %p, rejecting on outstanding_bufs\n", udf_node));
21179f988b79SJean-Baptiste Boric 			return 0;
21189f988b79SJean-Baptiste Boric 		}
21199f988b79SJean-Baptiste Boric 		if (udf_node->outstanding_nodedscr > 0) {
21209f988b79SJean-Baptiste Boric 			DPRINTF(SYNC, ("udf_fsync %p, rejecting on outstanding_nodedscr\n", udf_node));
21219f988b79SJean-Baptiste Boric 			return 0;
21229f988b79SJean-Baptiste Boric 		}
21239f988b79SJean-Baptiste Boric 	}
21249f988b79SJean-Baptiste Boric 
21259f988b79SJean-Baptiste Boric 	/* wait until vp->v_numoutput reaches zero i.e. is finished */
21269f988b79SJean-Baptiste Boric 	if (wait) {
21279f988b79SJean-Baptiste Boric 		DPRINTF(SYNC, ("udf_fsync %p, waiting\n", udf_node));
21289f988b79SJean-Baptiste Boric 		mutex_enter(vp->v_interlock);
21299f988b79SJean-Baptiste Boric 		while (vp->v_numoutput) {
21309f988b79SJean-Baptiste Boric 			DPRINTF(SYNC, ("udf_fsync %p, v_numoutput %d\n", udf_node, vp->v_numoutput));
21319f988b79SJean-Baptiste Boric 			cv_timedwait(&vp->v_cv, vp->v_interlock, hz/8);
21329f988b79SJean-Baptiste Boric 		}
21339f988b79SJean-Baptiste Boric 		mutex_exit(vp->v_interlock);
21349f988b79SJean-Baptiste Boric 		DPRINTF(SYNC, ("udf_fsync %p, fin wait\n", udf_node));
21359f988b79SJean-Baptiste Boric 	}
21369f988b79SJean-Baptiste Boric 
21379f988b79SJean-Baptiste Boric 	/* write out node and wait for it if requested */
21389f988b79SJean-Baptiste Boric 	DPRINTF(SYNC, ("udf_fsync %p, writeout node\n", udf_node));
21399f988b79SJean-Baptiste Boric 	error = udf_writeout_node(udf_node, wait);
21409f988b79SJean-Baptiste Boric 	if (error)
21419f988b79SJean-Baptiste Boric 		return error;
21429f988b79SJean-Baptiste Boric 
21439f988b79SJean-Baptiste Boric 	/* TODO/XXX if ap->a_flags & FSYNC_CACHE, we ought to do a disc sync */
21449f988b79SJean-Baptiste Boric 
21459f988b79SJean-Baptiste Boric 	return 0;
21469f988b79SJean-Baptiste Boric }
21479f988b79SJean-Baptiste Boric 
21489f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
21499f988b79SJean-Baptiste Boric 
21509f988b79SJean-Baptiste Boric int
udf_advlock(void * v)21519f988b79SJean-Baptiste Boric udf_advlock(void *v)
21529f988b79SJean-Baptiste Boric {
21539f988b79SJean-Baptiste Boric 	struct vop_advlock_args /* {
21549f988b79SJean-Baptiste Boric 		struct vnode *a_vp;
21559f988b79SJean-Baptiste Boric 		void *a_id;
21569f988b79SJean-Baptiste Boric 		int a_op;
21579f988b79SJean-Baptiste Boric 		struct flock *a_fl;
21589f988b79SJean-Baptiste Boric 		int a_flags;
21599f988b79SJean-Baptiste Boric 	} */ *ap = v;
21609f988b79SJean-Baptiste Boric 	struct vnode *vp = ap->a_vp;
21619f988b79SJean-Baptiste Boric 	struct udf_node *udf_node = VTOI(vp);
21629f988b79SJean-Baptiste Boric 	struct file_entry    *fe;
21639f988b79SJean-Baptiste Boric 	struct extfile_entry *efe;
21649f988b79SJean-Baptiste Boric 	uint64_t file_size;
21659f988b79SJean-Baptiste Boric 
21669f988b79SJean-Baptiste Boric 	DPRINTF(LOCKING, ("udf_advlock called\n"));
21679f988b79SJean-Baptiste Boric 
21689f988b79SJean-Baptiste Boric 	/* get directory filesize */
21699f988b79SJean-Baptiste Boric 	if (udf_node->fe) {
21709f988b79SJean-Baptiste Boric 		fe = udf_node->fe;
21719f988b79SJean-Baptiste Boric 		file_size = udf_rw64(fe->inf_len);
21729f988b79SJean-Baptiste Boric 	} else {
21739f988b79SJean-Baptiste Boric 		assert(udf_node->efe);
21749f988b79SJean-Baptiste Boric 		efe = udf_node->efe;
21759f988b79SJean-Baptiste Boric 		file_size = udf_rw64(efe->inf_len);
21769f988b79SJean-Baptiste Boric 	}
21779f988b79SJean-Baptiste Boric 
21789f988b79SJean-Baptiste Boric 	return lf_advlock(ap, &udf_node->lockf, file_size);
21799f988b79SJean-Baptiste Boric }
21809f988b79SJean-Baptiste Boric 
21819f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
21829f988b79SJean-Baptiste Boric 
21839f988b79SJean-Baptiste Boric /* Global vfs vnode data structures for udfs */
21849f988b79SJean-Baptiste Boric int (**udf_vnodeop_p)(void *);
21859f988b79SJean-Baptiste Boric 
21869f988b79SJean-Baptiste Boric const struct vnodeopv_entry_desc udf_vnodeop_entries[] = {
21879f988b79SJean-Baptiste Boric 	{ &vop_default_desc, vn_default_error },
21889f988b79SJean-Baptiste Boric 	{ &vop_lookup_desc, udf_lookup },	/* lookup */
21899f988b79SJean-Baptiste Boric 	{ &vop_create_desc, udf_create },	/* create */
21909f988b79SJean-Baptiste Boric 	{ &vop_mknod_desc, udf_mknod },		/* mknod */	/* TODO */
21919f988b79SJean-Baptiste Boric 	{ &vop_open_desc, udf_open },		/* open */
21929f988b79SJean-Baptiste Boric 	{ &vop_close_desc, udf_close },		/* close */
21939f988b79SJean-Baptiste Boric 	{ &vop_access_desc, udf_access },	/* access */
21949f988b79SJean-Baptiste Boric 	{ &vop_getattr_desc, udf_getattr },	/* getattr */
21959f988b79SJean-Baptiste Boric 	{ &vop_setattr_desc, udf_setattr },	/* setattr */	/* TODO chflags */
21969f988b79SJean-Baptiste Boric 	{ &vop_read_desc, udf_read },		/* read */
21979f988b79SJean-Baptiste Boric 	{ &vop_write_desc, udf_write },		/* write */	/* WRITE */
2198*0a6a1f1dSLionel Sambuc 	{ &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
2199*0a6a1f1dSLionel Sambuc 	{ &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
22009f988b79SJean-Baptiste Boric 	{ &vop_fcntl_desc, genfs_fcntl },	/* fcntl */	/* TODO? */
22019f988b79SJean-Baptiste Boric 	{ &vop_ioctl_desc, genfs_enoioctl },	/* ioctl */	/* TODO? */
22029f988b79SJean-Baptiste Boric 	{ &vop_poll_desc, genfs_poll },		/* poll */	/* TODO/OK? */
22039f988b79SJean-Baptiste Boric 	{ &vop_kqfilter_desc, genfs_kqfilter },	/* kqfilter */	/* ? */
22049f988b79SJean-Baptiste Boric 	{ &vop_revoke_desc, genfs_revoke },	/* revoke */	/* TODO? */
22059f988b79SJean-Baptiste Boric 	{ &vop_mmap_desc, genfs_mmap },		/* mmap */	/* OK? */
22069f988b79SJean-Baptiste Boric 	{ &vop_fsync_desc, udf_fsync },		/* fsync */
22079f988b79SJean-Baptiste Boric 	{ &vop_seek_desc, genfs_seek },		/* seek */
22089f988b79SJean-Baptiste Boric 	{ &vop_remove_desc, udf_remove },	/* remove */
22099f988b79SJean-Baptiste Boric 	{ &vop_link_desc, udf_link },		/* link */	/* TODO */
22109f988b79SJean-Baptiste Boric 	{ &vop_rename_desc, udf_rename },	/* rename */ 	/* TODO */
22119f988b79SJean-Baptiste Boric 	{ &vop_mkdir_desc, udf_mkdir },		/* mkdir */
22129f988b79SJean-Baptiste Boric 	{ &vop_rmdir_desc, udf_rmdir },		/* rmdir */
22139f988b79SJean-Baptiste Boric 	{ &vop_symlink_desc, udf_symlink },	/* symlink */	/* TODO */
22149f988b79SJean-Baptiste Boric 	{ &vop_readdir_desc, udf_readdir },	/* readdir */
22159f988b79SJean-Baptiste Boric 	{ &vop_readlink_desc, udf_readlink },	/* readlink */	/* TEST ME */
22169f988b79SJean-Baptiste Boric 	{ &vop_abortop_desc, genfs_abortop },	/* abortop */	/* TODO/OK? */
22179f988b79SJean-Baptiste Boric 	{ &vop_inactive_desc, udf_inactive },	/* inactive */
22189f988b79SJean-Baptiste Boric 	{ &vop_reclaim_desc, udf_reclaim },	/* reclaim */
22199f988b79SJean-Baptiste Boric 	{ &vop_lock_desc, genfs_lock },		/* lock */
22209f988b79SJean-Baptiste Boric 	{ &vop_unlock_desc, genfs_unlock },	/* unlock */
22219f988b79SJean-Baptiste Boric 	{ &vop_bmap_desc, udf_trivial_bmap },	/* bmap */	/* 1:1 bmap */
22229f988b79SJean-Baptiste Boric 	{ &vop_strategy_desc, udf_vfsstrategy },/* strategy */
22239f988b79SJean-Baptiste Boric /*	{ &vop_print_desc, udf_print },	*/	/* print */
22249f988b79SJean-Baptiste Boric 	{ &vop_islocked_desc, genfs_islocked },	/* islocked */
22259f988b79SJean-Baptiste Boric 	{ &vop_pathconf_desc, udf_pathconf },	/* pathconf */
22269f988b79SJean-Baptiste Boric 	{ &vop_advlock_desc, udf_advlock },	/* advlock */	/* TEST ME */
22279f988b79SJean-Baptiste Boric 	{ &vop_bwrite_desc, vn_bwrite },	/* bwrite */	/* ->strategy */
22289f988b79SJean-Baptiste Boric 	{ &vop_getpages_desc, genfs_getpages },	/* getpages */
22299f988b79SJean-Baptiste Boric 	{ &vop_putpages_desc, genfs_putpages },	/* putpages */
22309f988b79SJean-Baptiste Boric 	{ NULL, NULL }
22319f988b79SJean-Baptiste Boric };
22329f988b79SJean-Baptiste Boric 
22339f988b79SJean-Baptiste Boric 
22349f988b79SJean-Baptiste Boric const struct vnodeopv_desc udf_vnodeop_opv_desc = {
22359f988b79SJean-Baptiste Boric 	&udf_vnodeop_p, udf_vnodeop_entries
22369f988b79SJean-Baptiste Boric };
2237