xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision bfbb9ce67005673c7b7c8b2267024adef44f7d1d)
1df8bae1dSRodney W. Grimes /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1994
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley
6df8bae1dSRodney W. Grimes  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
7df8bae1dSRodney W. Grimes  * Support code is derived from software contributed to Berkeley
8df8bae1dSRodney W. Grimes  * by Atsushi Murai (amurai@spec.co.jp).
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
38996c772fSJohn Dyson  *	@(#)cd9660_vnops.c	8.19 (Berkeley) 5/27/95
39bfbb9ce6SPoul-Henning Kamp  * $Id: cd9660_vnops.c,v 1.55 1999/04/18 10:58:02 dcs Exp $
40df8bae1dSRodney W. Grimes  */
41df8bae1dSRodney W. Grimes 
42df8bae1dSRodney W. Grimes #include <sys/param.h>
43df8bae1dSRodney W. Grimes #include <sys/systm.h>
44df8bae1dSRodney W. Grimes #include <sys/namei.h>
45df8bae1dSRodney W. Grimes #include <sys/kernel.h>
46df8bae1dSRodney W. Grimes #include <sys/stat.h>
47df8bae1dSRodney W. Grimes #include <sys/buf.h>
48df8bae1dSRodney W. Grimes #include <sys/mount.h>
49df8bae1dSRodney W. Grimes #include <sys/vnode.h>
50df8bae1dSRodney W. Grimes #include <miscfs/specfs/specdev.h>
51df8bae1dSRodney W. Grimes #include <miscfs/fifofs/fifo.h>
52df8bae1dSRodney W. Grimes #include <sys/malloc.h>
53c90607baSBruce Evans #include <sys/dirent.h>
54996c772fSJohn Dyson #include <sys/unistd.h>
55df8bae1dSRodney W. Grimes 
56651ae11eSMike Smith #include <vm/vm.h>
57675ea6f0SBruce Evans #include <vm/vm_zone.h>
58651ae11eSMike Smith #include <vm/vnode_pager.h>
59675ea6f0SBruce Evans 
60df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso.h>
61df8bae1dSRodney W. Grimes #include <isofs/cd9660/cd9660_node.h>
62df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso_rrip.h>
63df8bae1dSRodney W. Grimes 
6410dd32cdSBruce Evans static int cd9660_setattr __P((struct vop_setattr_args *));
65605e9724SPoul-Henning Kamp static int cd9660_access __P((struct vop_access_args *));
66605e9724SPoul-Henning Kamp static int cd9660_getattr __P((struct vop_getattr_args *));
67f041a9bdSPoul-Henning Kamp static int cd9660_pathconf __P((struct vop_pathconf_args *));
68605e9724SPoul-Henning Kamp static int cd9660_read __P((struct vop_read_args *));
6910dd32cdSBruce Evans struct isoreaddir;
7010dd32cdSBruce Evans static int iso_uiodir __P((struct isoreaddir *idp, struct dirent *dp,
7110dd32cdSBruce Evans 			   off_t off));
7210dd32cdSBruce Evans static int iso_shipdir __P((struct isoreaddir *idp));
73605e9724SPoul-Henning Kamp static int cd9660_readdir __P((struct vop_readdir_args *));
7410dd32cdSBruce Evans static int cd9660_readlink __P((struct vop_readlink_args *ap));
75605e9724SPoul-Henning Kamp static int cd9660_abortop __P((struct vop_abortop_args *));
76605e9724SPoul-Henning Kamp static int cd9660_strategy __P((struct vop_strategy_args *));
77605e9724SPoul-Henning Kamp static int cd9660_print __P((struct vop_print_args *));
78651ae11eSMike Smith static int cd9660_getpages __P((struct vop_getpages_args *));
79651ae11eSMike Smith static int cd9660_putpages __P((struct vop_putpages_args *));
8010dd32cdSBruce Evans 
81df8bae1dSRodney W. Grimes /*
82de8583ceSDavid Greenman  * Setattr call. Only allowed for block and character special devices.
83de8583ceSDavid Greenman  */
84996c772fSJohn Dyson int
85de8583ceSDavid Greenman cd9660_setattr(ap)
86de8583ceSDavid Greenman 	struct vop_setattr_args /* {
87de8583ceSDavid Greenman 		struct vnodeop_desc *a_desc;
88de8583ceSDavid Greenman 		struct vnode *a_vp;
89de8583ceSDavid Greenman 		struct vattr *a_vap;
90de8583ceSDavid Greenman 		struct ucred *a_cred;
91de8583ceSDavid Greenman 		struct proc *a_p;
92de8583ceSDavid Greenman 	} */ *ap;
93de8583ceSDavid Greenman {
94de8583ceSDavid Greenman 	struct vnode *vp = ap->a_vp;
95de8583ceSDavid Greenman 	struct vattr *vap = ap->a_vap;
96de8583ceSDavid Greenman 
9792579404SAlexander Langer   	if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
9895a1574eSNate Williams 	    vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
9995a1574eSNate Williams 	    vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
100de8583ceSDavid Greenman 		return (EROFS);
10192579404SAlexander Langer 	if (vap->va_size != (u_quad_t)VNOVAL) {
102de8583ceSDavid Greenman  		switch (vp->v_type) {
103de8583ceSDavid Greenman  		case VDIR:
104de8583ceSDavid Greenman  			return (EISDIR);
105de8583ceSDavid Greenman 		case VLNK:
106de8583ceSDavid Greenman 		case VREG:
107de8583ceSDavid Greenman 			return (EROFS);
108de8583ceSDavid Greenman  		case VCHR:
109de8583ceSDavid Greenman  		case VBLK:
110de8583ceSDavid Greenman  		case VSOCK:
111de8583ceSDavid Greenman  		case VFIFO:
112d254af07SMatthew Dillon 		case VNON:
113d254af07SMatthew Dillon 		case VBAD:
114de8583ceSDavid Greenman 			return (0);
115de8583ceSDavid Greenman 		}
116de8583ceSDavid Greenman 	}
117996c772fSJohn Dyson 	return (0);
118de8583ceSDavid Greenman }
119de8583ceSDavid Greenman 
120de8583ceSDavid Greenman /*
121df8bae1dSRodney W. Grimes  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
122df8bae1dSRodney W. Grimes  * The mode is shifted to select the owner/group/other fields. The
123df8bae1dSRodney W. Grimes  * super user is granted all permissions.
124df8bae1dSRodney W. Grimes  */
125df8bae1dSRodney W. Grimes /* ARGSUSED */
126605e9724SPoul-Henning Kamp static int
127df8bae1dSRodney W. Grimes cd9660_access(ap)
128df8bae1dSRodney W. Grimes 	struct vop_access_args /* {
129df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
130df8bae1dSRodney W. Grimes 		int  a_mode;
131df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
132df8bae1dSRodney W. Grimes 		struct proc *a_p;
133df8bae1dSRodney W. Grimes 	} */ *ap;
134df8bae1dSRodney W. Grimes {
135996c772fSJohn Dyson 	struct vnode *vp = ap->a_vp;
136996c772fSJohn Dyson 	struct iso_node *ip = VTOI(vp);
137996c772fSJohn Dyson 	struct ucred *cred = ap->a_cred;
138996c772fSJohn Dyson 	mode_t mask, mode = ap->a_mode;
139996c772fSJohn Dyson 	gid_t *gp;
140996c772fSJohn Dyson 	int i;
141996c772fSJohn Dyson 
142ba14c327SDavid Greenman 	/*
143996c772fSJohn Dyson 	 * Disallow write attempts unless the file is a socket,
144996c772fSJohn Dyson 	 * fifo, or a block or character device resident on the
145996c772fSJohn Dyson 	 * file system.
146ba14c327SDavid Greenman 	 */
147996c772fSJohn Dyson 	if (mode & VWRITE) {
148996c772fSJohn Dyson 		switch (vp->v_type) {
149ba14c327SDavid Greenman 		case VDIR:
150ba14c327SDavid Greenman 		case VLNK:
151ba14c327SDavid Greenman 		case VREG:
152ba14c327SDavid Greenman 			return (EROFS);
153d254af07SMatthew Dillon 			/* NOT REACHED */
154d254af07SMatthew Dillon 		default:
155d254af07SMatthew Dillon 			break;
156ba14c327SDavid Greenman 		}
157ba14c327SDavid Greenman 	}
158ba14c327SDavid Greenman 
159996c772fSJohn Dyson 	/* User id 0 always gets access. */
160996c772fSJohn Dyson 	if (cred->cr_uid == 0)
161df8bae1dSRodney W. Grimes 		return (0);
162996c772fSJohn Dyson 
163996c772fSJohn Dyson 	mask = 0;
164996c772fSJohn Dyson 
165996c772fSJohn Dyson 	/* Otherwise, check the owner. */
166996c772fSJohn Dyson 	if (cred->cr_uid == ip->inode.iso_uid) {
167996c772fSJohn Dyson 		if (mode & VEXEC)
168996c772fSJohn Dyson 			mask |= S_IXUSR;
169996c772fSJohn Dyson 		if (mode & VREAD)
170996c772fSJohn Dyson 			mask |= S_IRUSR;
171996c772fSJohn Dyson 		if (mode & VWRITE)
172996c772fSJohn Dyson 			mask |= S_IWUSR;
173996c772fSJohn Dyson 		return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
174996c772fSJohn Dyson 	}
175996c772fSJohn Dyson 
176996c772fSJohn Dyson 	/* Otherwise, check the groups. */
177996c772fSJohn Dyson 	for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
178996c772fSJohn Dyson 		if (ip->inode.iso_gid == *gp) {
179996c772fSJohn Dyson 			if (mode & VEXEC)
180996c772fSJohn Dyson 				mask |= S_IXGRP;
181996c772fSJohn Dyson 			if (mode & VREAD)
182996c772fSJohn Dyson 				mask |= S_IRGRP;
183996c772fSJohn Dyson 			if (mode & VWRITE)
184996c772fSJohn Dyson 				mask |= S_IWGRP;
185996c772fSJohn Dyson 			return ((ip->inode.iso_mode & mask) == mask ?
186996c772fSJohn Dyson 			    0 : EACCES);
187996c772fSJohn Dyson 		}
188996c772fSJohn Dyson 
189996c772fSJohn Dyson 	/* Otherwise, check everyone else. */
190996c772fSJohn Dyson 	if (mode & VEXEC)
191996c772fSJohn Dyson 		mask |= S_IXOTH;
192996c772fSJohn Dyson 	if (mode & VREAD)
193996c772fSJohn Dyson 		mask |= S_IROTH;
194996c772fSJohn Dyson 	if (mode & VWRITE)
195996c772fSJohn Dyson 		mask |= S_IWOTH;
196996c772fSJohn Dyson 	return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
197df8bae1dSRodney W. Grimes }
198df8bae1dSRodney W. Grimes 
199605e9724SPoul-Henning Kamp static int
200df8bae1dSRodney W. Grimes cd9660_getattr(ap)
201df8bae1dSRodney W. Grimes 	struct vop_getattr_args /* {
202df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
203df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
204df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
205df8bae1dSRodney W. Grimes 		struct proc *a_p;
206df8bae1dSRodney W. Grimes 	} */ *ap;
207df8bae1dSRodney W. Grimes 
208df8bae1dSRodney W. Grimes {
209df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
210df8bae1dSRodney W. Grimes 	register struct vattr *vap = ap->a_vap;
211df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
212df8bae1dSRodney W. Grimes 
213bfbb9ce6SPoul-Henning Kamp 	vap->va_fsid	= dev2udev(ip->i_dev);
214df8bae1dSRodney W. Grimes 	vap->va_fileid	= ip->i_number;
215df8bae1dSRodney W. Grimes 
216df8bae1dSRodney W. Grimes 	vap->va_mode	= ip->inode.iso_mode;
217df8bae1dSRodney W. Grimes 	vap->va_nlink	= ip->inode.iso_links;
218df8bae1dSRodney W. Grimes 	vap->va_uid	= ip->inode.iso_uid;
219df8bae1dSRodney W. Grimes 	vap->va_gid	= ip->inode.iso_gid;
220df8bae1dSRodney W. Grimes 	vap->va_atime	= ip->inode.iso_atime;
221df8bae1dSRodney W. Grimes 	vap->va_mtime	= ip->inode.iso_mtime;
222df8bae1dSRodney W. Grimes 	vap->va_ctime	= ip->inode.iso_ctime;
223df8bae1dSRodney W. Grimes 	vap->va_rdev	= ip->inode.iso_rdev;
224df8bae1dSRodney W. Grimes 
225df8bae1dSRodney W. Grimes 	vap->va_size	= (u_quad_t) ip->i_size;
226996c772fSJohn Dyson 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
227996c772fSJohn Dyson 		struct vop_readlink_args rdlnk;
228996c772fSJohn Dyson 		struct iovec aiov;
229996c772fSJohn Dyson 		struct uio auio;
230996c772fSJohn Dyson 		char *cp;
231996c772fSJohn Dyson 
232996c772fSJohn Dyson 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
233996c772fSJohn Dyson 		aiov.iov_base = cp;
234996c772fSJohn Dyson 		aiov.iov_len = MAXPATHLEN;
235996c772fSJohn Dyson 		auio.uio_iov = &aiov;
236996c772fSJohn Dyson 		auio.uio_iovcnt = 1;
237996c772fSJohn Dyson 		auio.uio_offset = 0;
238996c772fSJohn Dyson 		auio.uio_rw = UIO_READ;
239996c772fSJohn Dyson 		auio.uio_segflg = UIO_SYSSPACE;
240996c772fSJohn Dyson 		auio.uio_procp = ap->a_p;
241996c772fSJohn Dyson 		auio.uio_resid = MAXPATHLEN;
242996c772fSJohn Dyson 		rdlnk.a_uio = &auio;
243996c772fSJohn Dyson 		rdlnk.a_vp = ap->a_vp;
244996c772fSJohn Dyson 		rdlnk.a_cred = ap->a_cred;
245996c772fSJohn Dyson 		if (cd9660_readlink(&rdlnk) == 0)
246996c772fSJohn Dyson 			vap->va_size = MAXPATHLEN - auio.uio_resid;
247996c772fSJohn Dyson 		FREE(cp, M_TEMP);
248996c772fSJohn Dyson 	}
249df8bae1dSRodney W. Grimes 	vap->va_flags	= 0;
250df8bae1dSRodney W. Grimes 	vap->va_gen = 1;
251df8bae1dSRodney W. Grimes 	vap->va_blocksize = ip->i_mnt->logical_block_size;
252df8bae1dSRodney W. Grimes 	vap->va_bytes	= (u_quad_t) ip->i_size;
253df8bae1dSRodney W. Grimes 	vap->va_type	= vp->v_type;
25494a8606fSDoug Rabson 	vap->va_filerev	= 0;
255df8bae1dSRodney W. Grimes 	return (0);
256df8bae1dSRodney W. Grimes }
257df8bae1dSRodney W. Grimes 
258df8bae1dSRodney W. Grimes /*
259df8bae1dSRodney W. Grimes  * Vnode op for reading.
260df8bae1dSRodney W. Grimes  */
261605e9724SPoul-Henning Kamp static int
262df8bae1dSRodney W. Grimes cd9660_read(ap)
263df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
264df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
265df8bae1dSRodney W. Grimes 		struct uio *a_uio;
266df8bae1dSRodney W. Grimes 		int a_ioflag;
267df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
268df8bae1dSRodney W. Grimes 	} */ *ap;
269df8bae1dSRodney W. Grimes {
270df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
271df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
272df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
273df8bae1dSRodney W. Grimes 	register struct iso_mnt *imp;
274df8bae1dSRodney W. Grimes 	struct buf *bp;
2751295d82eSGary Palmer 	daddr_t lbn, rablock;
276df8bae1dSRodney W. Grimes 	off_t diff;
277df8bae1dSRodney W. Grimes 	int rasize, error = 0;
278df8bae1dSRodney W. Grimes 	long size, n, on;
279df8bae1dSRodney W. Grimes 
280df8bae1dSRodney W. Grimes 	if (uio->uio_resid == 0)
281df8bae1dSRodney W. Grimes 		return (0);
282df8bae1dSRodney W. Grimes 	if (uio->uio_offset < 0)
283df8bae1dSRodney W. Grimes 		return (EINVAL);
284996c772fSJohn Dyson 	ip->i_flag |= IN_ACCESS;
285df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
286df8bae1dSRodney W. Grimes 	do {
287996c772fSJohn Dyson 		lbn = lblkno(imp, uio->uio_offset);
288996c772fSJohn Dyson 		on = blkoff(imp, uio->uio_offset);
289996c772fSJohn Dyson 		n = min((u_int)(imp->logical_block_size - on),
290df8bae1dSRodney W. Grimes 			uio->uio_resid);
291df8bae1dSRodney W. Grimes 		diff = (off_t)ip->i_size - uio->uio_offset;
292df8bae1dSRodney W. Grimes 		if (diff <= 0)
293df8bae1dSRodney W. Grimes 			return (0);
294df8bae1dSRodney W. Grimes 		if (diff < n)
295df8bae1dSRodney W. Grimes 			n = diff;
296996c772fSJohn Dyson 		size = blksize(imp, ip, lbn);
297df8bae1dSRodney W. Grimes 		rablock = lbn + 1;
29881bca6ddSKATO Takenori 		if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
2995a5573fdSBruce Evans 			if (lblktosize(imp, rablock) < ip->i_size)
300996c772fSJohn Dyson 				error = cluster_read(vp, (off_t)ip->i_size,
3018b612c4bSJohn Dyson 				         lbn, size, NOCRED, uio->uio_resid,
3028b612c4bSJohn Dyson 					 (ap->a_ioflag >> 16), &bp);
303df8bae1dSRodney W. Grimes 			else
304df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
305df8bae1dSRodney W. Grimes 		} else {
306df8bae1dSRodney W. Grimes 			if (vp->v_lastr + 1 == lbn &&
307996c772fSJohn Dyson 			    lblktosize(imp, rablock) < ip->i_size) {
308996c772fSJohn Dyson 				rasize = blksize(imp, ip, rablock);
309df8bae1dSRodney W. Grimes 				error = breadn(vp, lbn, size, &rablock,
310df8bae1dSRodney W. Grimes 					       &rasize, 1, NOCRED, &bp);
311df8bae1dSRodney W. Grimes 			} else
312df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
313df8bae1dSRodney W. Grimes 		}
314df8bae1dSRodney W. Grimes 		vp->v_lastr = lbn;
315df8bae1dSRodney W. Grimes 		n = min(n, size - bp->b_resid);
316df8bae1dSRodney W. Grimes 		if (error) {
317df8bae1dSRodney W. Grimes 			brelse(bp);
318df8bae1dSRodney W. Grimes 			return (error);
319df8bae1dSRodney W. Grimes 		}
320df8bae1dSRodney W. Grimes 
321996c772fSJohn Dyson 		error = uiomove(bp->b_data + on, (int)n, uio);
322df8bae1dSRodney W. Grimes 		brelse(bp);
323df8bae1dSRodney W. Grimes 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
324df8bae1dSRodney W. Grimes 	return (error);
325df8bae1dSRodney W. Grimes }
326df8bae1dSRodney W. Grimes 
327df8bae1dSRodney W. Grimes /*
328df8bae1dSRodney W. Grimes  * Structure for reading directories
329df8bae1dSRodney W. Grimes  */
330df8bae1dSRodney W. Grimes struct isoreaddir {
331df8bae1dSRodney W. Grimes 	struct dirent saveent;
332df8bae1dSRodney W. Grimes 	struct dirent assocent;
333df8bae1dSRodney W. Grimes 	struct dirent current;
334df8bae1dSRodney W. Grimes 	off_t saveoff;
335df8bae1dSRodney W. Grimes 	off_t assocoff;
336df8bae1dSRodney W. Grimes 	off_t curroff;
337df8bae1dSRodney W. Grimes 	struct uio *uio;
338df8bae1dSRodney W. Grimes 	off_t uio_off;
339996c772fSJohn Dyson 	int eofflag;
340996c772fSJohn Dyson 	u_long *cookies;
341df8bae1dSRodney W. Grimes 	int ncookies;
342df8bae1dSRodney W. Grimes };
343df8bae1dSRodney W. Grimes 
344996c772fSJohn Dyson int
345df8bae1dSRodney W. Grimes iso_uiodir(idp,dp,off)
346df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
347df8bae1dSRodney W. Grimes 	struct dirent *dp;
348df8bae1dSRodney W. Grimes 	off_t off;
349df8bae1dSRodney W. Grimes {
350df8bae1dSRodney W. Grimes 	int error;
351df8bae1dSRodney W. Grimes 
352df8bae1dSRodney W. Grimes 	dp->d_name[dp->d_namlen] = 0;
353c90607baSBruce Evans 	dp->d_reclen = GENERIC_DIRSIZ(dp);
354df8bae1dSRodney W. Grimes 
355df8bae1dSRodney W. Grimes 	if (idp->uio->uio_resid < dp->d_reclen) {
356996c772fSJohn Dyson 		idp->eofflag = 0;
357996c772fSJohn Dyson 		return (-1);
358df8bae1dSRodney W. Grimes 	}
359df8bae1dSRodney W. Grimes 
360996c772fSJohn Dyson 	if (idp->cookies) {
361df8bae1dSRodney W. Grimes 		if (idp->ncookies <= 0) {
362996c772fSJohn Dyson 			idp->eofflag = 0;
363996c772fSJohn Dyson 			return (-1);
364df8bae1dSRodney W. Grimes 		}
365df8bae1dSRodney W. Grimes 
366996c772fSJohn Dyson 		*idp->cookies++ = off;
367df8bae1dSRodney W. Grimes 		--idp->ncookies;
368df8bae1dSRodney W. Grimes 	}
369df8bae1dSRodney W. Grimes 
370d254af07SMatthew Dillon 	if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0)
371996c772fSJohn Dyson 		return (error);
372df8bae1dSRodney W. Grimes 	idp->uio_off = off;
373996c772fSJohn Dyson 	return (0);
374df8bae1dSRodney W. Grimes }
375df8bae1dSRodney W. Grimes 
376996c772fSJohn Dyson int
377df8bae1dSRodney W. Grimes iso_shipdir(idp)
378df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
379df8bae1dSRodney W. Grimes {
380df8bae1dSRodney W. Grimes 	struct dirent *dp;
381df8bae1dSRodney W. Grimes 	int cl, sl, assoc;
382df8bae1dSRodney W. Grimes 	int error;
383df8bae1dSRodney W. Grimes 	char *cname, *sname;
384df8bae1dSRodney W. Grimes 
385df8bae1dSRodney W. Grimes 	cl = idp->current.d_namlen;
386df8bae1dSRodney W. Grimes 	cname = idp->current.d_name;
3871295d82eSGary Palmer assoc = (cl > 1) && (*cname == ASSOCCHAR);
3881295d82eSGary Palmer 	if (assoc) {
389df8bae1dSRodney W. Grimes 		cl--;
390df8bae1dSRodney W. Grimes 		cname++;
391df8bae1dSRodney W. Grimes 	}
392df8bae1dSRodney W. Grimes 
393df8bae1dSRodney W. Grimes 	dp = &idp->saveent;
394df8bae1dSRodney W. Grimes 	sname = dp->d_name;
395df8bae1dSRodney W. Grimes 	if (!(sl = dp->d_namlen)) {
396df8bae1dSRodney W. Grimes 		dp = &idp->assocent;
397df8bae1dSRodney W. Grimes 		sname = dp->d_name + 1;
398df8bae1dSRodney W. Grimes 		sl = dp->d_namlen - 1;
399df8bae1dSRodney W. Grimes 	}
400df8bae1dSRodney W. Grimes 	if (sl > 0) {
401df8bae1dSRodney W. Grimes 		if (sl != cl
402df8bae1dSRodney W. Grimes 		    || bcmp(sname,cname,sl)) {
403df8bae1dSRodney W. Grimes 			if (idp->assocent.d_namlen) {
404d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
405996c772fSJohn Dyson 					return (error);
406df8bae1dSRodney W. Grimes 				idp->assocent.d_namlen = 0;
407df8bae1dSRodney W. Grimes 			}
408df8bae1dSRodney W. Grimes 			if (idp->saveent.d_namlen) {
409d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
410996c772fSJohn Dyson 					return (error);
411df8bae1dSRodney W. Grimes 				idp->saveent.d_namlen = 0;
412df8bae1dSRodney W. Grimes 			}
413df8bae1dSRodney W. Grimes 		}
414df8bae1dSRodney W. Grimes 	}
415c90607baSBruce Evans 	idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
416df8bae1dSRodney W. Grimes 	if (assoc) {
417df8bae1dSRodney W. Grimes 		idp->assocoff = idp->curroff;
418df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
419df8bae1dSRodney W. Grimes 	} else {
420df8bae1dSRodney W. Grimes 		idp->saveoff = idp->curroff;
421df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
422df8bae1dSRodney W. Grimes 	}
423996c772fSJohn Dyson 	return (0);
424df8bae1dSRodney W. Grimes }
425df8bae1dSRodney W. Grimes 
426df8bae1dSRodney W. Grimes /*
427df8bae1dSRodney W. Grimes  * Vnode op for readdir
428df8bae1dSRodney W. Grimes  */
429605e9724SPoul-Henning Kamp static int
430df8bae1dSRodney W. Grimes cd9660_readdir(ap)
431df8bae1dSRodney W. Grimes 	struct vop_readdir_args /* {
432df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
433df8bae1dSRodney W. Grimes 		struct uio *a_uio;
434df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
435996c772fSJohn Dyson 		int *a_eofflag;
436996c772fSJohn Dyson 		int *a_ncookies;
437996c772fSJohn Dyson 		u_long *a_cookies;
438df8bae1dSRodney W. Grimes 	} */ *ap;
439df8bae1dSRodney W. Grimes {
440df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
441df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
442996c772fSJohn Dyson 	struct vnode *vdp = ap->a_vp;
443996c772fSJohn Dyson 	struct iso_node *dp;
444df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
445df8bae1dSRodney W. Grimes 	struct buf *bp = NULL;
446996c772fSJohn Dyson 	struct iso_directory_record *ep;
447996c772fSJohn Dyson 	int entryoffsetinblock;
448996c772fSJohn Dyson 	doff_t endsearch;
449996c772fSJohn Dyson 	u_long bmask;
450996c772fSJohn Dyson 	int error = 0;
451996c772fSJohn Dyson 	int reclen;
452996c772fSJohn Dyson 	u_short namelen;
4539abf4d6eSDoug Rabson 	int ncookies = 0;
454996c772fSJohn Dyson 	u_long *cookies = NULL;
455df8bae1dSRodney W. Grimes 
456996c772fSJohn Dyson 	dp = VTOI(vdp);
457996c772fSJohn Dyson 	imp = dp->i_mnt;
458996c772fSJohn Dyson 	bmask = imp->im_bmask;
459df8bae1dSRodney W. Grimes 
460df8bae1dSRodney W. Grimes 	MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
461996c772fSJohn Dyson 	idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
462996c772fSJohn Dyson 	/*
463996c772fSJohn Dyson 	 * XXX
464996c772fSJohn Dyson 	 * Is it worth trying to figure out the type?
465996c772fSJohn Dyson 	 */
466996c772fSJohn Dyson 	idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
467996c772fSJohn Dyson 	    DT_UNKNOWN;
468df8bae1dSRodney W. Grimes 	idp->uio = uio;
469996c772fSJohn Dyson 	if (ap->a_ncookies == NULL) {
470996c772fSJohn Dyson 		idp->cookies = NULL;
471996c772fSJohn Dyson 	} else {
4729abf4d6eSDoug Rabson 		/*
4739abf4d6eSDoug Rabson 		 * Guess the number of cookies needed.
4749abf4d6eSDoug Rabson 		 */
4759abf4d6eSDoug Rabson 		ncookies = uio->uio_resid / 16;
476996c772fSJohn Dyson 		MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
477996c772fSJohn Dyson 		    M_WAITOK);
478996c772fSJohn Dyson 		idp->cookies = cookies;
479df8bae1dSRodney W. Grimes 		idp->ncookies = ncookies;
480996c772fSJohn Dyson 	}
481996c772fSJohn Dyson 	idp->eofflag = 1;
482df8bae1dSRodney W. Grimes 	idp->curroff = uio->uio_offset;
483df8bae1dSRodney W. Grimes 
484996c772fSJohn Dyson 	if ((entryoffsetinblock = idp->curroff & bmask) &&
485cec0f20cSPoul-Henning Kamp 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
486df8bae1dSRodney W. Grimes 		FREE(idp, M_TEMP);
487df8bae1dSRodney W. Grimes 		return (error);
488df8bae1dSRodney W. Grimes 	}
489996c772fSJohn Dyson 	endsearch = dp->i_size;
490df8bae1dSRodney W. Grimes 
491df8bae1dSRodney W. Grimes 	while (idp->curroff < endsearch) {
492df8bae1dSRodney W. Grimes 		/*
493df8bae1dSRodney W. Grimes 		 * If offset is on a block boundary,
494df8bae1dSRodney W. Grimes 		 * read the next directory block.
495df8bae1dSRodney W. Grimes 		 * Release previous if it exists.
496df8bae1dSRodney W. Grimes 		 */
497996c772fSJohn Dyson 		if ((idp->curroff & bmask) == 0) {
498df8bae1dSRodney W. Grimes 			if (bp != NULL)
499df8bae1dSRodney W. Grimes 				brelse(bp);
500d254af07SMatthew Dillon 			if ((error =
501d254af07SMatthew Dillon 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
502df8bae1dSRodney W. Grimes 				break;
503df8bae1dSRodney W. Grimes 			entryoffsetinblock = 0;
504df8bae1dSRodney W. Grimes 		}
505df8bae1dSRodney W. Grimes 		/*
506df8bae1dSRodney W. Grimes 		 * Get pointer to next entry.
507df8bae1dSRodney W. Grimes 		 */
508df8bae1dSRodney W. Grimes 		ep = (struct iso_directory_record *)
509996c772fSJohn Dyson 			((char *)bp->b_data + entryoffsetinblock);
510df8bae1dSRodney W. Grimes 
511df8bae1dSRodney W. Grimes 		reclen = isonum_711(ep->length);
512df8bae1dSRodney W. Grimes 		if (reclen == 0) {
513df8bae1dSRodney W. Grimes 			/* skip to next block, if any */
514996c772fSJohn Dyson 			idp->curroff =
515996c772fSJohn Dyson 			    (idp->curroff & ~bmask) + imp->logical_block_size;
516df8bae1dSRodney W. Grimes 			continue;
517df8bae1dSRodney W. Grimes 		}
518df8bae1dSRodney W. Grimes 
519df8bae1dSRodney W. Grimes 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
520df8bae1dSRodney W. Grimes 			error = EINVAL;
521df8bae1dSRodney W. Grimes 			/* illegal entry, stop */
522df8bae1dSRodney W. Grimes 			break;
523df8bae1dSRodney W. Grimes 		}
524df8bae1dSRodney W. Grimes 
525df8bae1dSRodney W. Grimes 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
526df8bae1dSRodney W. Grimes 			error = EINVAL;
527df8bae1dSRodney W. Grimes 			/* illegal directory, so stop looking */
528df8bae1dSRodney W. Grimes 			break;
529df8bae1dSRodney W. Grimes 		}
530df8bae1dSRodney W. Grimes 
531996c772fSJohn Dyson 		idp->current.d_namlen = isonum_711(ep->name_len);
532996c772fSJohn Dyson 
533996c772fSJohn Dyson 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
53481ec856aSJoerg Wunsch 			error = EINVAL;
53581ec856aSJoerg Wunsch 			/* illegal entry, stop */
53681ec856aSJoerg Wunsch 			break;
53781ec856aSJoerg Wunsch 		}
53881ec856aSJoerg Wunsch 
539996c772fSJohn Dyson 		if (isonum_711(ep->flags)&2)
540996c772fSJohn Dyson 			idp->current.d_fileno = isodirino(ep, imp);
541df8bae1dSRodney W. Grimes 		else
542df8bae1dSRodney W. Grimes 			idp->current.d_fileno = dbtob(bp->b_blkno) +
543996c772fSJohn Dyson 				entryoffsetinblock;
544df8bae1dSRodney W. Grimes 
545df8bae1dSRodney W. Grimes 		idp->curroff += reclen;
546996c772fSJohn Dyson 
547df8bae1dSRodney W. Grimes 		switch (imp->iso_ftype) {
548df8bae1dSRodney W. Grimes 		case ISO_FTYPE_RRIP:
549996c772fSJohn Dyson 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
550df8bae1dSRodney W. Grimes 					   &idp->current.d_fileno,imp);
551996c772fSJohn Dyson 			idp->current.d_namlen = (u_char)namelen;
552df8bae1dSRodney W. Grimes 			if (idp->current.d_namlen)
553df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
554df8bae1dSRodney W. Grimes 			break;
555988fa8efSJoerg Wunsch 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
556df8bae1dSRodney W. Grimes 			strcpy(idp->current.d_name,"..");
55744e568e2SDaniel C. Sobral 			if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
558df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 1;
559df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
56044e568e2SDaniel C. Sobral 			} else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
561df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 2;
562df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
56344e568e2SDaniel C. Sobral 			} else {
564df8bae1dSRodney W. Grimes 				isofntrans(ep->name,idp->current.d_namlen,
565996c772fSJohn Dyson 					   idp->current.d_name, &namelen,
566df8bae1dSRodney W. Grimes 					   imp->iso_ftype == ISO_FTYPE_9660,
56744e568e2SDaniel C. Sobral 					   isonum_711(ep->flags)&4,
56844e568e2SDaniel C. Sobral 					   imp->joliet_level);
569996c772fSJohn Dyson 				idp->current.d_namlen = (u_char)namelen;
570df8bae1dSRodney W. Grimes 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
571df8bae1dSRodney W. Grimes 					error = iso_shipdir(idp);
572df8bae1dSRodney W. Grimes 				else
573df8bae1dSRodney W. Grimes 					error = iso_uiodir(idp,&idp->current,idp->curroff);
574df8bae1dSRodney W. Grimes 			}
575df8bae1dSRodney W. Grimes 		}
576df8bae1dSRodney W. Grimes 		if (error)
577df8bae1dSRodney W. Grimes 			break;
578df8bae1dSRodney W. Grimes 
579df8bae1dSRodney W. Grimes 		entryoffsetinblock += reclen;
580df8bae1dSRodney W. Grimes 	}
581df8bae1dSRodney W. Grimes 
582df8bae1dSRodney W. Grimes 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
583df8bae1dSRodney W. Grimes 		idp->current.d_namlen = 0;
584df8bae1dSRodney W. Grimes 		error = iso_shipdir(idp);
585df8bae1dSRodney W. Grimes 	}
586df8bae1dSRodney W. Grimes 	if (error < 0)
587df8bae1dSRodney W. Grimes 		error = 0;
588df8bae1dSRodney W. Grimes 
5899abf4d6eSDoug Rabson 	if (ap->a_ncookies != NULL) {
5909abf4d6eSDoug Rabson 		if (error)
591996c772fSJohn Dyson 			free(cookies, M_TEMP);
5929abf4d6eSDoug Rabson 		else {
5939abf4d6eSDoug Rabson 			/*
5949abf4d6eSDoug Rabson 			 * Work out the number of cookies actually used.
5959abf4d6eSDoug Rabson 			 */
5969abf4d6eSDoug Rabson 			*ap->a_ncookies = ncookies - idp->ncookies;
5979abf4d6eSDoug Rabson 			*ap->a_cookies = cookies;
5989abf4d6eSDoug Rabson 		}
5999abf4d6eSDoug Rabson 	}
6009abf4d6eSDoug Rabson 
601df8bae1dSRodney W. Grimes 	if (bp)
602df8bae1dSRodney W. Grimes 		brelse (bp);
603df8bae1dSRodney W. Grimes 
604df8bae1dSRodney W. Grimes 	uio->uio_offset = idp->uio_off;
605996c772fSJohn Dyson 	*ap->a_eofflag = idp->eofflag;
606df8bae1dSRodney W. Grimes 
607df8bae1dSRodney W. Grimes 	FREE(idp, M_TEMP);
608df8bae1dSRodney W. Grimes 
609df8bae1dSRodney W. Grimes 	return (error);
610df8bae1dSRodney W. Grimes }
611df8bae1dSRodney W. Grimes 
612df8bae1dSRodney W. Grimes /*
613df8bae1dSRodney W. Grimes  * Return target name of a symbolic link
614df8bae1dSRodney W. Grimes  * Shouldn't we get the parent vnode and read the data from there?
615df8bae1dSRodney W. Grimes  * This could eventually result in deadlocks in cd9660_lookup.
616df8bae1dSRodney W. Grimes  * But otherwise the block read here is in the block buffer two times.
617df8bae1dSRodney W. Grimes  */
618df8bae1dSRodney W. Grimes typedef struct iso_directory_record ISODIR;
619df8bae1dSRodney W. Grimes typedef struct iso_node		    ISONODE;
620df8bae1dSRodney W. Grimes typedef struct iso_mnt		    ISOMNT;
621605e9724SPoul-Henning Kamp static int
622df8bae1dSRodney W. Grimes cd9660_readlink(ap)
623df8bae1dSRodney W. Grimes 	struct vop_readlink_args /* {
624df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
625df8bae1dSRodney W. Grimes 		struct uio *a_uio;
626df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
627df8bae1dSRodney W. Grimes 	} */ *ap;
628df8bae1dSRodney W. Grimes {
629df8bae1dSRodney W. Grimes 	ISONODE	*ip;
630df8bae1dSRodney W. Grimes 	ISODIR	*dirp;
631df8bae1dSRodney W. Grimes 	ISOMNT	*imp;
632df8bae1dSRodney W. Grimes 	struct	buf *bp;
633996c772fSJohn Dyson 	struct	uio *uio;
634df8bae1dSRodney W. Grimes 	u_short	symlen;
635df8bae1dSRodney W. Grimes 	int	error;
636df8bae1dSRodney W. Grimes 	char	*symname;
637df8bae1dSRodney W. Grimes 
638df8bae1dSRodney W. Grimes 	ip  = VTOI(ap->a_vp);
639df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
640996c772fSJohn Dyson 	uio = ap->a_uio;
641df8bae1dSRodney W. Grimes 
642df8bae1dSRodney W. Grimes 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
643996c772fSJohn Dyson 		return (EINVAL);
644df8bae1dSRodney W. Grimes 
645df8bae1dSRodney W. Grimes 	/*
646df8bae1dSRodney W. Grimes 	 * Get parents directory record block that this inode included.
647df8bae1dSRodney W. Grimes 	 */
648df8bae1dSRodney W. Grimes 	error = bread(imp->im_devvp,
649996c772fSJohn Dyson 		      (ip->i_number >> imp->im_bshift) <<
650996c772fSJohn Dyson 		      (imp->im_bshift - DEV_BSHIFT),
651996c772fSJohn Dyson 		      imp->logical_block_size, NOCRED, &bp);
652df8bae1dSRodney W. Grimes 	if (error) {
653df8bae1dSRodney W. Grimes 		brelse(bp);
654996c772fSJohn Dyson 		return (EINVAL);
655df8bae1dSRodney W. Grimes 	}
656df8bae1dSRodney W. Grimes 
657df8bae1dSRodney W. Grimes 	/*
658df8bae1dSRodney W. Grimes 	 * Setup the directory pointer for this inode
659df8bae1dSRodney W. Grimes 	 */
660996c772fSJohn Dyson 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
661df8bae1dSRodney W. Grimes 
662df8bae1dSRodney W. Grimes 	/*
663df8bae1dSRodney W. Grimes 	 * Just make sure, we have a right one....
664df8bae1dSRodney W. Grimes 	 *   1: Check not cross boundary on block
665df8bae1dSRodney W. Grimes 	 */
666df8bae1dSRodney W. Grimes 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
66792579404SAlexander Langer 	    > (unsigned)imp->logical_block_size) {
668df8bae1dSRodney W. Grimes 		brelse(bp);
669996c772fSJohn Dyson 		return (EINVAL);
670df8bae1dSRodney W. Grimes 	}
671df8bae1dSRodney W. Grimes 
672df8bae1dSRodney W. Grimes 	/*
673df8bae1dSRodney W. Grimes 	 * Now get a buffer
674df8bae1dSRodney W. Grimes 	 * Abuse a namei buffer for now.
675df8bae1dSRodney W. Grimes 	 */
676996c772fSJohn Dyson 	if (uio->uio_segflg == UIO_SYSSPACE)
677996c772fSJohn Dyson 		symname = uio->uio_iov->iov_base;
678996c772fSJohn Dyson 	else
67999448ed1SJohn Dyson 		symname = zalloc(namei_zone);
680df8bae1dSRodney W. Grimes 
681df8bae1dSRodney W. Grimes 	/*
682df8bae1dSRodney W. Grimes 	 * Ok, we just gathering a symbolic name in SL record.
683df8bae1dSRodney W. Grimes 	 */
684df8bae1dSRodney W. Grimes 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
685996c772fSJohn Dyson 		if (uio->uio_segflg != UIO_SYSSPACE)
68699448ed1SJohn Dyson 			zfree(namei_zone, symname);
687df8bae1dSRodney W. Grimes 		brelse(bp);
688996c772fSJohn Dyson 		return (EINVAL);
689df8bae1dSRodney W. Grimes 	}
690df8bae1dSRodney W. Grimes 	/*
691df8bae1dSRodney W. Grimes 	 * Don't forget before you leave from home ;-)
692df8bae1dSRodney W. Grimes 	 */
693df8bae1dSRodney W. Grimes 	brelse(bp);
694df8bae1dSRodney W. Grimes 
695df8bae1dSRodney W. Grimes 	/*
696df8bae1dSRodney W. Grimes 	 * return with the symbolic name to caller's.
697df8bae1dSRodney W. Grimes 	 */
698996c772fSJohn Dyson 	if (uio->uio_segflg != UIO_SYSSPACE) {
699996c772fSJohn Dyson 		error = uiomove(symname, symlen, uio);
70099448ed1SJohn Dyson 		zfree(namei_zone, symname);
701996c772fSJohn Dyson 		return (error);
702996c772fSJohn Dyson 	}
703996c772fSJohn Dyson 	uio->uio_resid -= symlen;
704996c772fSJohn Dyson 	uio->uio_iov->iov_base += symlen;
705996c772fSJohn Dyson 	uio->uio_iov->iov_len -= symlen;
706996c772fSJohn Dyson 	return (0);
707df8bae1dSRodney W. Grimes }
708df8bae1dSRodney W. Grimes 
709df8bae1dSRodney W. Grimes /*
710df8bae1dSRodney W. Grimes  * Ufs abort op, called after namei() when a CREATE/DELETE isn't actually
711df8bae1dSRodney W. Grimes  * done. If a buffer has been saved in anticipation of a CREATE, delete it.
712df8bae1dSRodney W. Grimes  */
713605e9724SPoul-Henning Kamp static int
714df8bae1dSRodney W. Grimes cd9660_abortop(ap)
715df8bae1dSRodney W. Grimes 	struct vop_abortop_args /* {
716df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
717df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
718df8bae1dSRodney W. Grimes 	} */ *ap;
719df8bae1dSRodney W. Grimes {
720df8bae1dSRodney W. Grimes 	if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
72199448ed1SJohn Dyson 		zfree(namei_zone, ap->a_cnp->cn_pnbuf);
722996c772fSJohn Dyson 	return (0);
723df8bae1dSRodney W. Grimes }
724df8bae1dSRodney W. Grimes 
725df8bae1dSRodney W. Grimes /*
726df8bae1dSRodney W. Grimes  * Calculate the logical to physical mapping if not done already,
727df8bae1dSRodney W. Grimes  * then call the device strategy routine.
728df8bae1dSRodney W. Grimes  */
729605e9724SPoul-Henning Kamp static int
730df8bae1dSRodney W. Grimes cd9660_strategy(ap)
731df8bae1dSRodney W. Grimes 	struct vop_strategy_args /* {
732fd5d1124SJulian Elischer 		struct buf *a_vp;
733df8bae1dSRodney W. Grimes 		struct buf *a_bp;
734df8bae1dSRodney W. Grimes 	} */ *ap;
735df8bae1dSRodney W. Grimes {
736df8bae1dSRodney W. Grimes 	register struct buf *bp = ap->a_bp;
737df8bae1dSRodney W. Grimes 	register struct vnode *vp = bp->b_vp;
738df8bae1dSRodney W. Grimes 	register struct iso_node *ip;
739df8bae1dSRodney W. Grimes 	int error;
740df8bae1dSRodney W. Grimes 
741df8bae1dSRodney W. Grimes 	ip = VTOI(vp);
742df8bae1dSRodney W. Grimes 	if (vp->v_type == VBLK || vp->v_type == VCHR)
743df8bae1dSRodney W. Grimes 		panic("cd9660_strategy: spec");
744df8bae1dSRodney W. Grimes 	if (bp->b_blkno == bp->b_lblkno) {
7451295d82eSGary Palmer 		if ((error =
746c83ebe77SJohn Dyson 		    VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL))) {
747df8bae1dSRodney W. Grimes 			bp->b_error = error;
748df8bae1dSRodney W. Grimes 			bp->b_flags |= B_ERROR;
749df8bae1dSRodney W. Grimes 			biodone(bp);
750df8bae1dSRodney W. Grimes 			return (error);
751df8bae1dSRodney W. Grimes 		}
752df8bae1dSRodney W. Grimes 		if ((long)bp->b_blkno == -1)
753df8bae1dSRodney W. Grimes 			clrbuf(bp);
754df8bae1dSRodney W. Grimes 	}
755df8bae1dSRodney W. Grimes 	if ((long)bp->b_blkno == -1) {
756df8bae1dSRodney W. Grimes 		biodone(bp);
757df8bae1dSRodney W. Grimes 		return (0);
758df8bae1dSRodney W. Grimes 	}
759df8bae1dSRodney W. Grimes 	vp = ip->i_devvp;
760df8bae1dSRodney W. Grimes 	bp->b_dev = vp->v_rdev;
761fd5d1124SJulian Elischer 	VOP_STRATEGY(vp, bp);
762df8bae1dSRodney W. Grimes 	return (0);
763df8bae1dSRodney W. Grimes }
764df8bae1dSRodney W. Grimes 
765df8bae1dSRodney W. Grimes /*
766df8bae1dSRodney W. Grimes  * Print out the contents of an inode.
767df8bae1dSRodney W. Grimes  */
768605e9724SPoul-Henning Kamp static int
769df8bae1dSRodney W. Grimes cd9660_print(ap)
770df8bae1dSRodney W. Grimes 	struct vop_print_args /* {
771df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
772df8bae1dSRodney W. Grimes 	} */ *ap;
773df8bae1dSRodney W. Grimes {
774996c772fSJohn Dyson 
775df8bae1dSRodney W. Grimes 	printf("tag VT_ISOFS, isofs vnode\n");
776996c772fSJohn Dyson 	return (0);
777df8bae1dSRodney W. Grimes }
778df8bae1dSRodney W. Grimes 
779df8bae1dSRodney W. Grimes /*
780996c772fSJohn Dyson  * Return POSIX pathconf information applicable to cd9660 filesystems.
781996c772fSJohn Dyson  */
782f041a9bdSPoul-Henning Kamp static int
783996c772fSJohn Dyson cd9660_pathconf(ap)
784996c772fSJohn Dyson 	struct vop_pathconf_args /* {
785996c772fSJohn Dyson 		struct vnode *a_vp;
786996c772fSJohn Dyson 		int a_name;
787996c772fSJohn Dyson 		register_t *a_retval;
788996c772fSJohn Dyson 	} */ *ap;
789996c772fSJohn Dyson {
790996c772fSJohn Dyson 
791996c772fSJohn Dyson 	switch (ap->a_name) {
792996c772fSJohn Dyson 	case _PC_LINK_MAX:
793996c772fSJohn Dyson 		*ap->a_retval = 1;
794996c772fSJohn Dyson 		return (0);
795996c772fSJohn Dyson 	case _PC_NAME_MAX:
796996c772fSJohn Dyson 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
797996c772fSJohn Dyson 			*ap->a_retval = NAME_MAX;
798996c772fSJohn Dyson 		else
799996c772fSJohn Dyson 			*ap->a_retval = 37;
800996c772fSJohn Dyson 		return (0);
801996c772fSJohn Dyson 	case _PC_PATH_MAX:
802996c772fSJohn Dyson 		*ap->a_retval = PATH_MAX;
803996c772fSJohn Dyson 		return (0);
804996c772fSJohn Dyson 	case _PC_PIPE_BUF:
805996c772fSJohn Dyson 		*ap->a_retval = PIPE_BUF;
806996c772fSJohn Dyson 		return (0);
807996c772fSJohn Dyson 	case _PC_CHOWN_RESTRICTED:
808996c772fSJohn Dyson 		*ap->a_retval = 1;
809996c772fSJohn Dyson 		return (0);
810996c772fSJohn Dyson 	case _PC_NO_TRUNC:
811996c772fSJohn Dyson 		*ap->a_retval = 1;
812996c772fSJohn Dyson 		return (0);
813996c772fSJohn Dyson 	default:
814996c772fSJohn Dyson 		return (EINVAL);
815996c772fSJohn Dyson 	}
816996c772fSJohn Dyson 	/* NOTREACHED */
817df8bae1dSRodney W. Grimes }
818df8bae1dSRodney W. Grimes 
819df8bae1dSRodney W. Grimes /*
820651ae11eSMike Smith  * get page routine
821651ae11eSMike Smith  *
822651ae11eSMike Smith  * XXX By default, wimp out... note that a_offset is ignored (and always
823651ae11eSMike Smith  * XXX has been).
824651ae11eSMike Smith  */
825651ae11eSMike Smith int
826651ae11eSMike Smith cd9660_getpages(ap)
827651ae11eSMike Smith 	struct vop_getpages_args *ap;
828651ae11eSMike Smith {
829651ae11eSMike Smith 	return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
830651ae11eSMike Smith 		ap->a_reqpage);
831651ae11eSMike Smith }
832651ae11eSMike Smith 
833651ae11eSMike Smith /*
834651ae11eSMike Smith  * put page routine
835651ae11eSMike Smith  *
836651ae11eSMike Smith  * XXX By default, wimp out... note that a_offset is ignored (and always
837651ae11eSMike Smith  * XXX has been).
838651ae11eSMike Smith  */
839651ae11eSMike Smith int
840651ae11eSMike Smith cd9660_putpages(ap)
841651ae11eSMike Smith 	struct vop_putpages_args *ap;
842651ae11eSMike Smith {
843651ae11eSMike Smith 	return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
844651ae11eSMike Smith 		ap->a_sync, ap->a_rtvals);
845651ae11eSMike Smith }
846651ae11eSMike Smith 
847651ae11eSMike Smith /*
848996c772fSJohn Dyson  * Global vfs data structures for cd9660
849df8bae1dSRodney W. Grimes  */
850f57e6547SBruce Evans vop_t **cd9660_vnodeop_p;
851f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
852dba3870cSPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
853539ef70cSPoul-Henning Kamp 	{ &vop_abortop_desc,		(vop_t *) cd9660_abortop },
854539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
855539ef70cSPoul-Henning Kamp 	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
856539ef70cSPoul-Henning Kamp 	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
857539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
858539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
859d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
860d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
861539ef70cSPoul-Henning Kamp 	{ &vop_lookup_desc,		(vop_t *) vfs_cache_lookup },
862539ef70cSPoul-Henning Kamp 	{ &vop_pathconf_desc,		(vop_t *) cd9660_pathconf },
863539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
864539ef70cSPoul-Henning Kamp 	{ &vop_read_desc,		(vop_t *) cd9660_read },
865539ef70cSPoul-Henning Kamp 	{ &vop_readdir_desc,		(vop_t *) cd9660_readdir },
866539ef70cSPoul-Henning Kamp 	{ &vop_readlink_desc,		(vop_t *) cd9660_readlink },
867539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
868539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
869539ef70cSPoul-Henning Kamp 	{ &vop_strategy_desc,		(vop_t *) cd9660_strategy },
870d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
871651ae11eSMike Smith 	{ &vop_getpages_desc,		(vop_t *) cd9660_getpages },
872651ae11eSMike Smith 	{ &vop_putpages_desc,		(vop_t *) cd9660_putpages },
873f57e6547SBruce Evans 	{ NULL, NULL }
874df8bae1dSRodney W. Grimes };
875605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
876df8bae1dSRodney W. Grimes 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
877c901836cSGarrett Wollman VNODEOP_SET(cd9660_vnodeop_opv_desc);
878df8bae1dSRodney W. Grimes 
879df8bae1dSRodney W. Grimes /*
880df8bae1dSRodney W. Grimes  * Special device vnode ops
881df8bae1dSRodney W. Grimes  */
882f57e6547SBruce Evans vop_t **cd9660_specop_p;
883f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
884138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) spec_vnoperate },
885539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
886539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
887539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
888d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
889d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
890539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
891539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
892539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
893d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
894f57e6547SBruce Evans 	{ NULL, NULL }
895df8bae1dSRodney W. Grimes };
896605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_specop_opv_desc =
897df8bae1dSRodney W. Grimes 	{ &cd9660_specop_p, cd9660_specop_entries };
898c901836cSGarrett Wollman VNODEOP_SET(cd9660_specop_opv_desc);
899df8bae1dSRodney W. Grimes 
900f57e6547SBruce Evans vop_t **cd9660_fifoop_p;
901f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
902138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) fifo_vnoperate },
903539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
904539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
905539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
906d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
907d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
908539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
909539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
910539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
911d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
912f57e6547SBruce Evans 	{ NULL, NULL }
913df8bae1dSRodney W. Grimes };
914605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_fifoop_opv_desc =
915df8bae1dSRodney W. Grimes 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
916c901836cSGarrett Wollman 
917c901836cSGarrett Wollman VNODEOP_SET(cd9660_fifoop_opv_desc);
918