xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision fd5d1124e25f9996b0bfbf17156d850d106b27b4)
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
39fd5d1124SJulian Elischer  * $Id: cd9660_vnops.c,v 1.52 1998/03/06 09:46:14 msmith 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:
112de8583ceSDavid Greenman 			return (0);
113de8583ceSDavid Greenman 		}
114de8583ceSDavid Greenman 	}
115996c772fSJohn Dyson 	return (0);
116de8583ceSDavid Greenman }
117de8583ceSDavid Greenman 
118de8583ceSDavid Greenman /*
119df8bae1dSRodney W. Grimes  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
120df8bae1dSRodney W. Grimes  * The mode is shifted to select the owner/group/other fields. The
121df8bae1dSRodney W. Grimes  * super user is granted all permissions.
122df8bae1dSRodney W. Grimes  */
123df8bae1dSRodney W. Grimes /* ARGSUSED */
124605e9724SPoul-Henning Kamp static int
125df8bae1dSRodney W. Grimes cd9660_access(ap)
126df8bae1dSRodney W. Grimes 	struct vop_access_args /* {
127df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
128df8bae1dSRodney W. Grimes 		int  a_mode;
129df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
130df8bae1dSRodney W. Grimes 		struct proc *a_p;
131df8bae1dSRodney W. Grimes 	} */ *ap;
132df8bae1dSRodney W. Grimes {
133996c772fSJohn Dyson 	struct vnode *vp = ap->a_vp;
134996c772fSJohn Dyson 	struct iso_node *ip = VTOI(vp);
135996c772fSJohn Dyson 	struct ucred *cred = ap->a_cred;
136996c772fSJohn Dyson 	mode_t mask, mode = ap->a_mode;
137996c772fSJohn Dyson 	gid_t *gp;
138996c772fSJohn Dyson 	int i;
139996c772fSJohn Dyson 
140ba14c327SDavid Greenman 	/*
141996c772fSJohn Dyson 	 * Disallow write attempts unless the file is a socket,
142996c772fSJohn Dyson 	 * fifo, or a block or character device resident on the
143996c772fSJohn Dyson 	 * file system.
144ba14c327SDavid Greenman 	 */
145996c772fSJohn Dyson 	if (mode & VWRITE) {
146996c772fSJohn Dyson 		switch (vp->v_type) {
147ba14c327SDavid Greenman 		case VDIR:
148ba14c327SDavid Greenman 		case VLNK:
149ba14c327SDavid Greenman 		case VREG:
150ba14c327SDavid Greenman 			return (EROFS);
151ba14c327SDavid Greenman 		}
152ba14c327SDavid Greenman 	}
153ba14c327SDavid Greenman 
154996c772fSJohn Dyson 	/* User id 0 always gets access. */
155996c772fSJohn Dyson 	if (cred->cr_uid == 0)
156df8bae1dSRodney W. Grimes 		return (0);
157996c772fSJohn Dyson 
158996c772fSJohn Dyson 	mask = 0;
159996c772fSJohn Dyson 
160996c772fSJohn Dyson 	/* Otherwise, check the owner. */
161996c772fSJohn Dyson 	if (cred->cr_uid == ip->inode.iso_uid) {
162996c772fSJohn Dyson 		if (mode & VEXEC)
163996c772fSJohn Dyson 			mask |= S_IXUSR;
164996c772fSJohn Dyson 		if (mode & VREAD)
165996c772fSJohn Dyson 			mask |= S_IRUSR;
166996c772fSJohn Dyson 		if (mode & VWRITE)
167996c772fSJohn Dyson 			mask |= S_IWUSR;
168996c772fSJohn Dyson 		return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
169996c772fSJohn Dyson 	}
170996c772fSJohn Dyson 
171996c772fSJohn Dyson 	/* Otherwise, check the groups. */
172996c772fSJohn Dyson 	for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
173996c772fSJohn Dyson 		if (ip->inode.iso_gid == *gp) {
174996c772fSJohn Dyson 			if (mode & VEXEC)
175996c772fSJohn Dyson 				mask |= S_IXGRP;
176996c772fSJohn Dyson 			if (mode & VREAD)
177996c772fSJohn Dyson 				mask |= S_IRGRP;
178996c772fSJohn Dyson 			if (mode & VWRITE)
179996c772fSJohn Dyson 				mask |= S_IWGRP;
180996c772fSJohn Dyson 			return ((ip->inode.iso_mode & mask) == mask ?
181996c772fSJohn Dyson 			    0 : EACCES);
182996c772fSJohn Dyson 		}
183996c772fSJohn Dyson 
184996c772fSJohn Dyson 	/* Otherwise, check everyone else. */
185996c772fSJohn Dyson 	if (mode & VEXEC)
186996c772fSJohn Dyson 		mask |= S_IXOTH;
187996c772fSJohn Dyson 	if (mode & VREAD)
188996c772fSJohn Dyson 		mask |= S_IROTH;
189996c772fSJohn Dyson 	if (mode & VWRITE)
190996c772fSJohn Dyson 		mask |= S_IWOTH;
191996c772fSJohn Dyson 	return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
192df8bae1dSRodney W. Grimes }
193df8bae1dSRodney W. Grimes 
194605e9724SPoul-Henning Kamp static int
195df8bae1dSRodney W. Grimes cd9660_getattr(ap)
196df8bae1dSRodney W. Grimes 	struct vop_getattr_args /* {
197df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
198df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
199df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
200df8bae1dSRodney W. Grimes 		struct proc *a_p;
201df8bae1dSRodney W. Grimes 	} */ *ap;
202df8bae1dSRodney W. Grimes 
203df8bae1dSRodney W. Grimes {
204df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
205df8bae1dSRodney W. Grimes 	register struct vattr *vap = ap->a_vap;
206df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
207df8bae1dSRodney W. Grimes 
208df8bae1dSRodney W. Grimes 	vap->va_fsid	= ip->i_dev;
209df8bae1dSRodney W. Grimes 	vap->va_fileid	= ip->i_number;
210df8bae1dSRodney W. Grimes 
211df8bae1dSRodney W. Grimes 	vap->va_mode	= ip->inode.iso_mode;
212df8bae1dSRodney W. Grimes 	vap->va_nlink	= ip->inode.iso_links;
213df8bae1dSRodney W. Grimes 	vap->va_uid	= ip->inode.iso_uid;
214df8bae1dSRodney W. Grimes 	vap->va_gid	= ip->inode.iso_gid;
215df8bae1dSRodney W. Grimes 	vap->va_atime	= ip->inode.iso_atime;
216df8bae1dSRodney W. Grimes 	vap->va_mtime	= ip->inode.iso_mtime;
217df8bae1dSRodney W. Grimes 	vap->va_ctime	= ip->inode.iso_ctime;
218df8bae1dSRodney W. Grimes 	vap->va_rdev	= ip->inode.iso_rdev;
219df8bae1dSRodney W. Grimes 
220df8bae1dSRodney W. Grimes 	vap->va_size	= (u_quad_t) ip->i_size;
221996c772fSJohn Dyson 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
222996c772fSJohn Dyson 		struct vop_readlink_args rdlnk;
223996c772fSJohn Dyson 		struct iovec aiov;
224996c772fSJohn Dyson 		struct uio auio;
225996c772fSJohn Dyson 		char *cp;
226996c772fSJohn Dyson 
227996c772fSJohn Dyson 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
228996c772fSJohn Dyson 		aiov.iov_base = cp;
229996c772fSJohn Dyson 		aiov.iov_len = MAXPATHLEN;
230996c772fSJohn Dyson 		auio.uio_iov = &aiov;
231996c772fSJohn Dyson 		auio.uio_iovcnt = 1;
232996c772fSJohn Dyson 		auio.uio_offset = 0;
233996c772fSJohn Dyson 		auio.uio_rw = UIO_READ;
234996c772fSJohn Dyson 		auio.uio_segflg = UIO_SYSSPACE;
235996c772fSJohn Dyson 		auio.uio_procp = ap->a_p;
236996c772fSJohn Dyson 		auio.uio_resid = MAXPATHLEN;
237996c772fSJohn Dyson 		rdlnk.a_uio = &auio;
238996c772fSJohn Dyson 		rdlnk.a_vp = ap->a_vp;
239996c772fSJohn Dyson 		rdlnk.a_cred = ap->a_cred;
240996c772fSJohn Dyson 		if (cd9660_readlink(&rdlnk) == 0)
241996c772fSJohn Dyson 			vap->va_size = MAXPATHLEN - auio.uio_resid;
242996c772fSJohn Dyson 		FREE(cp, M_TEMP);
243996c772fSJohn Dyson 	}
244df8bae1dSRodney W. Grimes 	vap->va_flags	= 0;
245df8bae1dSRodney W. Grimes 	vap->va_gen = 1;
246df8bae1dSRodney W. Grimes 	vap->va_blocksize = ip->i_mnt->logical_block_size;
247df8bae1dSRodney W. Grimes 	vap->va_bytes	= (u_quad_t) ip->i_size;
248df8bae1dSRodney W. Grimes 	vap->va_type	= vp->v_type;
24994a8606fSDoug Rabson 	vap->va_filerev	= 0;
250df8bae1dSRodney W. Grimes 	return (0);
251df8bae1dSRodney W. Grimes }
252df8bae1dSRodney W. Grimes 
253df8bae1dSRodney W. Grimes /*
254df8bae1dSRodney W. Grimes  * Vnode op for reading.
255df8bae1dSRodney W. Grimes  */
256605e9724SPoul-Henning Kamp static int
257df8bae1dSRodney W. Grimes cd9660_read(ap)
258df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
259df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
260df8bae1dSRodney W. Grimes 		struct uio *a_uio;
261df8bae1dSRodney W. Grimes 		int a_ioflag;
262df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
263df8bae1dSRodney W. Grimes 	} */ *ap;
264df8bae1dSRodney W. Grimes {
265df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
266df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
267df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
268df8bae1dSRodney W. Grimes 	register struct iso_mnt *imp;
269df8bae1dSRodney W. Grimes 	struct buf *bp;
2701295d82eSGary Palmer 	daddr_t lbn, rablock;
271df8bae1dSRodney W. Grimes 	off_t diff;
272df8bae1dSRodney W. Grimes 	int rasize, error = 0;
273df8bae1dSRodney W. Grimes 	long size, n, on;
274df8bae1dSRodney W. Grimes 
275df8bae1dSRodney W. Grimes 	if (uio->uio_resid == 0)
276df8bae1dSRodney W. Grimes 		return (0);
277df8bae1dSRodney W. Grimes 	if (uio->uio_offset < 0)
278df8bae1dSRodney W. Grimes 		return (EINVAL);
279996c772fSJohn Dyson 	ip->i_flag |= IN_ACCESS;
280df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
281df8bae1dSRodney W. Grimes 	do {
282996c772fSJohn Dyson 		lbn = lblkno(imp, uio->uio_offset);
283996c772fSJohn Dyson 		on = blkoff(imp, uio->uio_offset);
284996c772fSJohn Dyson 		n = min((u_int)(imp->logical_block_size - on),
285df8bae1dSRodney W. Grimes 			uio->uio_resid);
286df8bae1dSRodney W. Grimes 		diff = (off_t)ip->i_size - uio->uio_offset;
287df8bae1dSRodney W. Grimes 		if (diff <= 0)
288df8bae1dSRodney W. Grimes 			return (0);
289df8bae1dSRodney W. Grimes 		if (diff < n)
290df8bae1dSRodney W. Grimes 			n = diff;
291996c772fSJohn Dyson 		size = blksize(imp, ip, lbn);
292df8bae1dSRodney W. Grimes 		rablock = lbn + 1;
29381bca6ddSKATO Takenori 		if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
2945a5573fdSBruce Evans 			if (lblktosize(imp, rablock) < ip->i_size)
295996c772fSJohn Dyson 				error = cluster_read(vp, (off_t)ip->i_size,
2968b612c4bSJohn Dyson 				         lbn, size, NOCRED, uio->uio_resid,
2978b612c4bSJohn Dyson 					 (ap->a_ioflag >> 16), &bp);
298df8bae1dSRodney W. Grimes 			else
299df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
300df8bae1dSRodney W. Grimes 		} else {
301df8bae1dSRodney W. Grimes 			if (vp->v_lastr + 1 == lbn &&
302996c772fSJohn Dyson 			    lblktosize(imp, rablock) < ip->i_size) {
303996c772fSJohn Dyson 				rasize = blksize(imp, ip, rablock);
304df8bae1dSRodney W. Grimes 				error = breadn(vp, lbn, size, &rablock,
305df8bae1dSRodney W. Grimes 					       &rasize, 1, NOCRED, &bp);
306df8bae1dSRodney W. Grimes 			} else
307df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
308df8bae1dSRodney W. Grimes 		}
309df8bae1dSRodney W. Grimes 		vp->v_lastr = lbn;
310df8bae1dSRodney W. Grimes 		n = min(n, size - bp->b_resid);
311df8bae1dSRodney W. Grimes 		if (error) {
312df8bae1dSRodney W. Grimes 			brelse(bp);
313df8bae1dSRodney W. Grimes 			return (error);
314df8bae1dSRodney W. Grimes 		}
315df8bae1dSRodney W. Grimes 
316996c772fSJohn Dyson 		error = uiomove(bp->b_data + on, (int)n, uio);
317df8bae1dSRodney W. Grimes 		brelse(bp);
318df8bae1dSRodney W. Grimes 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
319df8bae1dSRodney W. Grimes 	return (error);
320df8bae1dSRodney W. Grimes }
321df8bae1dSRodney W. Grimes 
322df8bae1dSRodney W. Grimes /*
323df8bae1dSRodney W. Grimes  * Structure for reading directories
324df8bae1dSRodney W. Grimes  */
325df8bae1dSRodney W. Grimes struct isoreaddir {
326df8bae1dSRodney W. Grimes 	struct dirent saveent;
327df8bae1dSRodney W. Grimes 	struct dirent assocent;
328df8bae1dSRodney W. Grimes 	struct dirent current;
329df8bae1dSRodney W. Grimes 	off_t saveoff;
330df8bae1dSRodney W. Grimes 	off_t assocoff;
331df8bae1dSRodney W. Grimes 	off_t curroff;
332df8bae1dSRodney W. Grimes 	struct uio *uio;
333df8bae1dSRodney W. Grimes 	off_t uio_off;
334996c772fSJohn Dyson 	int eofflag;
335996c772fSJohn Dyson 	u_long *cookies;
336df8bae1dSRodney W. Grimes 	int ncookies;
337df8bae1dSRodney W. Grimes };
338df8bae1dSRodney W. Grimes 
339996c772fSJohn Dyson int
340df8bae1dSRodney W. Grimes iso_uiodir(idp,dp,off)
341df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
342df8bae1dSRodney W. Grimes 	struct dirent *dp;
343df8bae1dSRodney W. Grimes 	off_t off;
344df8bae1dSRodney W. Grimes {
345df8bae1dSRodney W. Grimes 	int error;
346df8bae1dSRodney W. Grimes 
347df8bae1dSRodney W. Grimes 	dp->d_name[dp->d_namlen] = 0;
348c90607baSBruce Evans 	dp->d_reclen = GENERIC_DIRSIZ(dp);
349df8bae1dSRodney W. Grimes 
350df8bae1dSRodney W. Grimes 	if (idp->uio->uio_resid < dp->d_reclen) {
351996c772fSJohn Dyson 		idp->eofflag = 0;
352996c772fSJohn Dyson 		return (-1);
353df8bae1dSRodney W. Grimes 	}
354df8bae1dSRodney W. Grimes 
355996c772fSJohn Dyson 	if (idp->cookies) {
356df8bae1dSRodney W. Grimes 		if (idp->ncookies <= 0) {
357996c772fSJohn Dyson 			idp->eofflag = 0;
358996c772fSJohn Dyson 			return (-1);
359df8bae1dSRodney W. Grimes 		}
360df8bae1dSRodney W. Grimes 
361996c772fSJohn Dyson 		*idp->cookies++ = off;
362df8bae1dSRodney W. Grimes 		--idp->ncookies;
363df8bae1dSRodney W. Grimes 	}
364df8bae1dSRodney W. Grimes 
365996c772fSJohn Dyson 	if (error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio))
366996c772fSJohn Dyson 		return (error);
367df8bae1dSRodney W. Grimes 	idp->uio_off = off;
368996c772fSJohn Dyson 	return (0);
369df8bae1dSRodney W. Grimes }
370df8bae1dSRodney W. Grimes 
371996c772fSJohn Dyson int
372df8bae1dSRodney W. Grimes iso_shipdir(idp)
373df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
374df8bae1dSRodney W. Grimes {
375df8bae1dSRodney W. Grimes 	struct dirent *dp;
376df8bae1dSRodney W. Grimes 	int cl, sl, assoc;
377df8bae1dSRodney W. Grimes 	int error;
378df8bae1dSRodney W. Grimes 	char *cname, *sname;
379df8bae1dSRodney W. Grimes 
380df8bae1dSRodney W. Grimes 	cl = idp->current.d_namlen;
381df8bae1dSRodney W. Grimes 	cname = idp->current.d_name;
3821295d82eSGary Palmer assoc = (cl > 1) && (*cname == ASSOCCHAR);
3831295d82eSGary Palmer 	if (assoc) {
384df8bae1dSRodney W. Grimes 		cl--;
385df8bae1dSRodney W. Grimes 		cname++;
386df8bae1dSRodney W. Grimes 	}
387df8bae1dSRodney W. Grimes 
388df8bae1dSRodney W. Grimes 	dp = &idp->saveent;
389df8bae1dSRodney W. Grimes 	sname = dp->d_name;
390df8bae1dSRodney W. Grimes 	if (!(sl = dp->d_namlen)) {
391df8bae1dSRodney W. Grimes 		dp = &idp->assocent;
392df8bae1dSRodney W. Grimes 		sname = dp->d_name + 1;
393df8bae1dSRodney W. Grimes 		sl = dp->d_namlen - 1;
394df8bae1dSRodney W. Grimes 	}
395df8bae1dSRodney W. Grimes 	if (sl > 0) {
396df8bae1dSRodney W. Grimes 		if (sl != cl
397df8bae1dSRodney W. Grimes 		    || bcmp(sname,cname,sl)) {
398df8bae1dSRodney W. Grimes 			if (idp->assocent.d_namlen) {
399996c772fSJohn Dyson 				if (error = iso_uiodir(idp,&idp->assocent,idp->assocoff))
400996c772fSJohn Dyson 					return (error);
401df8bae1dSRodney W. Grimes 				idp->assocent.d_namlen = 0;
402df8bae1dSRodney W. Grimes 			}
403df8bae1dSRodney W. Grimes 			if (idp->saveent.d_namlen) {
404996c772fSJohn Dyson 				if (error = iso_uiodir(idp,&idp->saveent,idp->saveoff))
405996c772fSJohn Dyson 					return (error);
406df8bae1dSRodney W. Grimes 				idp->saveent.d_namlen = 0;
407df8bae1dSRodney W. Grimes 			}
408df8bae1dSRodney W. Grimes 		}
409df8bae1dSRodney W. Grimes 	}
410c90607baSBruce Evans 	idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
411df8bae1dSRodney W. Grimes 	if (assoc) {
412df8bae1dSRodney W. Grimes 		idp->assocoff = idp->curroff;
413df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
414df8bae1dSRodney W. Grimes 	} else {
415df8bae1dSRodney W. Grimes 		idp->saveoff = idp->curroff;
416df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
417df8bae1dSRodney W. Grimes 	}
418996c772fSJohn Dyson 	return (0);
419df8bae1dSRodney W. Grimes }
420df8bae1dSRodney W. Grimes 
421df8bae1dSRodney W. Grimes /*
422df8bae1dSRodney W. Grimes  * Vnode op for readdir
423df8bae1dSRodney W. Grimes  */
424605e9724SPoul-Henning Kamp static int
425df8bae1dSRodney W. Grimes cd9660_readdir(ap)
426df8bae1dSRodney W. Grimes 	struct vop_readdir_args /* {
427df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
428df8bae1dSRodney W. Grimes 		struct uio *a_uio;
429df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
430996c772fSJohn Dyson 		int *a_eofflag;
431996c772fSJohn Dyson 		int *a_ncookies;
432996c772fSJohn Dyson 		u_long *a_cookies;
433df8bae1dSRodney W. Grimes 	} */ *ap;
434df8bae1dSRodney W. Grimes {
435df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
436df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
437996c772fSJohn Dyson 	struct vnode *vdp = ap->a_vp;
438996c772fSJohn Dyson 	struct iso_node *dp;
439df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
440df8bae1dSRodney W. Grimes 	struct buf *bp = NULL;
441996c772fSJohn Dyson 	struct iso_directory_record *ep;
442996c772fSJohn Dyson 	int entryoffsetinblock;
443996c772fSJohn Dyson 	doff_t endsearch;
444996c772fSJohn Dyson 	u_long bmask;
445996c772fSJohn Dyson 	int error = 0;
446996c772fSJohn Dyson 	int reclen;
447996c772fSJohn Dyson 	u_short namelen;
4489abf4d6eSDoug Rabson 	int ncookies = 0;
449996c772fSJohn Dyson 	u_long *cookies = NULL;
450df8bae1dSRodney W. Grimes 
451996c772fSJohn Dyson 	dp = VTOI(vdp);
452996c772fSJohn Dyson 	imp = dp->i_mnt;
453996c772fSJohn Dyson 	bmask = imp->im_bmask;
454df8bae1dSRodney W. Grimes 
455df8bae1dSRodney W. Grimes 	MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
456996c772fSJohn Dyson 	idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
457996c772fSJohn Dyson 	/*
458996c772fSJohn Dyson 	 * XXX
459996c772fSJohn Dyson 	 * Is it worth trying to figure out the type?
460996c772fSJohn Dyson 	 */
461996c772fSJohn Dyson 	idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
462996c772fSJohn Dyson 	    DT_UNKNOWN;
463df8bae1dSRodney W. Grimes 	idp->uio = uio;
464996c772fSJohn Dyson 	if (ap->a_ncookies == NULL) {
465996c772fSJohn Dyson 		idp->cookies = NULL;
466996c772fSJohn Dyson 	} else {
4679abf4d6eSDoug Rabson 		/*
4689abf4d6eSDoug Rabson 		 * Guess the number of cookies needed.
4699abf4d6eSDoug Rabson 		 */
4709abf4d6eSDoug Rabson 		ncookies = uio->uio_resid / 16;
471996c772fSJohn Dyson 		MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
472996c772fSJohn Dyson 		    M_WAITOK);
473996c772fSJohn Dyson 		idp->cookies = cookies;
474df8bae1dSRodney W. Grimes 		idp->ncookies = ncookies;
475996c772fSJohn Dyson 	}
476996c772fSJohn Dyson 	idp->eofflag = 1;
477df8bae1dSRodney W. Grimes 	idp->curroff = uio->uio_offset;
478df8bae1dSRodney W. Grimes 
479996c772fSJohn Dyson 	if ((entryoffsetinblock = idp->curroff & bmask) &&
480cec0f20cSPoul-Henning Kamp 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
481df8bae1dSRodney W. Grimes 		FREE(idp, M_TEMP);
482df8bae1dSRodney W. Grimes 		return (error);
483df8bae1dSRodney W. Grimes 	}
484996c772fSJohn Dyson 	endsearch = dp->i_size;
485df8bae1dSRodney W. Grimes 
486df8bae1dSRodney W. Grimes 	while (idp->curroff < endsearch) {
487df8bae1dSRodney W. Grimes 		/*
488df8bae1dSRodney W. Grimes 		 * If offset is on a block boundary,
489df8bae1dSRodney W. Grimes 		 * read the next directory block.
490df8bae1dSRodney W. Grimes 		 * Release previous if it exists.
491df8bae1dSRodney W. Grimes 		 */
492996c772fSJohn Dyson 		if ((idp->curroff & bmask) == 0) {
493df8bae1dSRodney W. Grimes 			if (bp != NULL)
494df8bae1dSRodney W. Grimes 				brelse(bp);
495996c772fSJohn Dyson 			if (error =
496cec0f20cSPoul-Henning Kamp 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))
497df8bae1dSRodney W. Grimes 				break;
498df8bae1dSRodney W. Grimes 			entryoffsetinblock = 0;
499df8bae1dSRodney W. Grimes 		}
500df8bae1dSRodney W. Grimes 		/*
501df8bae1dSRodney W. Grimes 		 * Get pointer to next entry.
502df8bae1dSRodney W. Grimes 		 */
503df8bae1dSRodney W. Grimes 		ep = (struct iso_directory_record *)
504996c772fSJohn Dyson 			((char *)bp->b_data + entryoffsetinblock);
505df8bae1dSRodney W. Grimes 
506df8bae1dSRodney W. Grimes 		reclen = isonum_711(ep->length);
507df8bae1dSRodney W. Grimes 		if (reclen == 0) {
508df8bae1dSRodney W. Grimes 			/* skip to next block, if any */
509996c772fSJohn Dyson 			idp->curroff =
510996c772fSJohn Dyson 			    (idp->curroff & ~bmask) + imp->logical_block_size;
511df8bae1dSRodney W. Grimes 			continue;
512df8bae1dSRodney W. Grimes 		}
513df8bae1dSRodney W. Grimes 
514df8bae1dSRodney W. Grimes 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
515df8bae1dSRodney W. Grimes 			error = EINVAL;
516df8bae1dSRodney W. Grimes 			/* illegal entry, stop */
517df8bae1dSRodney W. Grimes 			break;
518df8bae1dSRodney W. Grimes 		}
519df8bae1dSRodney W. Grimes 
520df8bae1dSRodney W. Grimes 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
521df8bae1dSRodney W. Grimes 			error = EINVAL;
522df8bae1dSRodney W. Grimes 			/* illegal directory, so stop looking */
523df8bae1dSRodney W. Grimes 			break;
524df8bae1dSRodney W. Grimes 		}
525df8bae1dSRodney W. Grimes 
526996c772fSJohn Dyson 		idp->current.d_namlen = isonum_711(ep->name_len);
527996c772fSJohn Dyson 
528996c772fSJohn Dyson 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
52981ec856aSJoerg Wunsch 			error = EINVAL;
53081ec856aSJoerg Wunsch 			/* illegal entry, stop */
53181ec856aSJoerg Wunsch 			break;
53281ec856aSJoerg Wunsch 		}
53381ec856aSJoerg Wunsch 
534996c772fSJohn Dyson 		if (isonum_711(ep->flags)&2)
535996c772fSJohn Dyson 			idp->current.d_fileno = isodirino(ep, imp);
536df8bae1dSRodney W. Grimes 		else
537df8bae1dSRodney W. Grimes 			idp->current.d_fileno = dbtob(bp->b_blkno) +
538996c772fSJohn Dyson 				entryoffsetinblock;
539df8bae1dSRodney W. Grimes 
540df8bae1dSRodney W. Grimes 		idp->curroff += reclen;
541996c772fSJohn Dyson 
542df8bae1dSRodney W. Grimes 		switch (imp->iso_ftype) {
543df8bae1dSRodney W. Grimes 		case ISO_FTYPE_RRIP:
544996c772fSJohn Dyson 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
545df8bae1dSRodney W. Grimes 					   &idp->current.d_fileno,imp);
546996c772fSJohn Dyson 			idp->current.d_namlen = (u_char)namelen;
547df8bae1dSRodney W. Grimes 			if (idp->current.d_namlen)
548df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
549df8bae1dSRodney W. Grimes 			break;
550988fa8efSJoerg Wunsch 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
551df8bae1dSRodney W. Grimes 			strcpy(idp->current.d_name,"..");
552df8bae1dSRodney W. Grimes 			switch (ep->name[0]) {
553df8bae1dSRodney W. Grimes 			case 0:
554df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 1;
555df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
556df8bae1dSRodney W. Grimes 				break;
557df8bae1dSRodney W. Grimes 			case 1:
558df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 2;
559df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
560df8bae1dSRodney W. Grimes 				break;
561df8bae1dSRodney W. Grimes 			default:
562df8bae1dSRodney W. Grimes 				isofntrans(ep->name,idp->current.d_namlen,
563996c772fSJohn Dyson 					   idp->current.d_name, &namelen,
564df8bae1dSRodney W. Grimes 					   imp->iso_ftype == ISO_FTYPE_9660,
565996c772fSJohn Dyson 					   isonum_711(ep->flags)&4);
566996c772fSJohn Dyson 				idp->current.d_namlen = (u_char)namelen;
567df8bae1dSRodney W. Grimes 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
568df8bae1dSRodney W. Grimes 					error = iso_shipdir(idp);
569df8bae1dSRodney W. Grimes 				else
570df8bae1dSRodney W. Grimes 					error = iso_uiodir(idp,&idp->current,idp->curroff);
571df8bae1dSRodney W. Grimes 				break;
572df8bae1dSRodney W. Grimes 			}
573df8bae1dSRodney W. Grimes 		}
574df8bae1dSRodney W. Grimes 		if (error)
575df8bae1dSRodney W. Grimes 			break;
576df8bae1dSRodney W. Grimes 
577df8bae1dSRodney W. Grimes 		entryoffsetinblock += reclen;
578df8bae1dSRodney W. Grimes 	}
579df8bae1dSRodney W. Grimes 
580df8bae1dSRodney W. Grimes 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
581df8bae1dSRodney W. Grimes 		idp->current.d_namlen = 0;
582df8bae1dSRodney W. Grimes 		error = iso_shipdir(idp);
583df8bae1dSRodney W. Grimes 	}
584df8bae1dSRodney W. Grimes 	if (error < 0)
585df8bae1dSRodney W. Grimes 		error = 0;
586df8bae1dSRodney W. Grimes 
5879abf4d6eSDoug Rabson 	if (ap->a_ncookies != NULL) {
5889abf4d6eSDoug Rabson 		if (error)
589996c772fSJohn Dyson 			free(cookies, M_TEMP);
5909abf4d6eSDoug Rabson 		else {
5919abf4d6eSDoug Rabson 			/*
5929abf4d6eSDoug Rabson 			 * Work out the number of cookies actually used.
5939abf4d6eSDoug Rabson 			 */
5949abf4d6eSDoug Rabson 			*ap->a_ncookies = ncookies - idp->ncookies;
5959abf4d6eSDoug Rabson 			*ap->a_cookies = cookies;
5969abf4d6eSDoug Rabson 		}
5979abf4d6eSDoug Rabson 	}
5989abf4d6eSDoug Rabson 
599df8bae1dSRodney W. Grimes 	if (bp)
600df8bae1dSRodney W. Grimes 		brelse (bp);
601df8bae1dSRodney W. Grimes 
602df8bae1dSRodney W. Grimes 	uio->uio_offset = idp->uio_off;
603996c772fSJohn Dyson 	*ap->a_eofflag = idp->eofflag;
604df8bae1dSRodney W. Grimes 
605df8bae1dSRodney W. Grimes 	FREE(idp, M_TEMP);
606df8bae1dSRodney W. Grimes 
607df8bae1dSRodney W. Grimes 	return (error);
608df8bae1dSRodney W. Grimes }
609df8bae1dSRodney W. Grimes 
610df8bae1dSRodney W. Grimes /*
611df8bae1dSRodney W. Grimes  * Return target name of a symbolic link
612df8bae1dSRodney W. Grimes  * Shouldn't we get the parent vnode and read the data from there?
613df8bae1dSRodney W. Grimes  * This could eventually result in deadlocks in cd9660_lookup.
614df8bae1dSRodney W. Grimes  * But otherwise the block read here is in the block buffer two times.
615df8bae1dSRodney W. Grimes  */
616df8bae1dSRodney W. Grimes typedef struct iso_directory_record ISODIR;
617df8bae1dSRodney W. Grimes typedef struct iso_node		    ISONODE;
618df8bae1dSRodney W. Grimes typedef struct iso_mnt		    ISOMNT;
619605e9724SPoul-Henning Kamp static int
620df8bae1dSRodney W. Grimes cd9660_readlink(ap)
621df8bae1dSRodney W. Grimes 	struct vop_readlink_args /* {
622df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
623df8bae1dSRodney W. Grimes 		struct uio *a_uio;
624df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
625df8bae1dSRodney W. Grimes 	} */ *ap;
626df8bae1dSRodney W. Grimes {
627df8bae1dSRodney W. Grimes 	ISONODE	*ip;
628df8bae1dSRodney W. Grimes 	ISODIR	*dirp;
629df8bae1dSRodney W. Grimes 	ISOMNT	*imp;
630df8bae1dSRodney W. Grimes 	struct	buf *bp;
631996c772fSJohn Dyson 	struct	uio *uio;
632df8bae1dSRodney W. Grimes 	u_short	symlen;
633df8bae1dSRodney W. Grimes 	int	error;
634df8bae1dSRodney W. Grimes 	char	*symname;
635df8bae1dSRodney W. Grimes 
636df8bae1dSRodney W. Grimes 	ip  = VTOI(ap->a_vp);
637df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
638996c772fSJohn Dyson 	uio = ap->a_uio;
639df8bae1dSRodney W. Grimes 
640df8bae1dSRodney W. Grimes 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
641996c772fSJohn Dyson 		return (EINVAL);
642df8bae1dSRodney W. Grimes 
643df8bae1dSRodney W. Grimes 	/*
644df8bae1dSRodney W. Grimes 	 * Get parents directory record block that this inode included.
645df8bae1dSRodney W. Grimes 	 */
646df8bae1dSRodney W. Grimes 	error = bread(imp->im_devvp,
647996c772fSJohn Dyson 		      (ip->i_number >> imp->im_bshift) <<
648996c772fSJohn Dyson 		      (imp->im_bshift - DEV_BSHIFT),
649996c772fSJohn Dyson 		      imp->logical_block_size, NOCRED, &bp);
650df8bae1dSRodney W. Grimes 	if (error) {
651df8bae1dSRodney W. Grimes 		brelse(bp);
652996c772fSJohn Dyson 		return (EINVAL);
653df8bae1dSRodney W. Grimes 	}
654df8bae1dSRodney W. Grimes 
655df8bae1dSRodney W. Grimes 	/*
656df8bae1dSRodney W. Grimes 	 * Setup the directory pointer for this inode
657df8bae1dSRodney W. Grimes 	 */
658996c772fSJohn Dyson 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
659df8bae1dSRodney W. Grimes 
660df8bae1dSRodney W. Grimes 	/*
661df8bae1dSRodney W. Grimes 	 * Just make sure, we have a right one....
662df8bae1dSRodney W. Grimes 	 *   1: Check not cross boundary on block
663df8bae1dSRodney W. Grimes 	 */
664df8bae1dSRodney W. Grimes 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
66592579404SAlexander Langer 	    > (unsigned)imp->logical_block_size) {
666df8bae1dSRodney W. Grimes 		brelse(bp);
667996c772fSJohn Dyson 		return (EINVAL);
668df8bae1dSRodney W. Grimes 	}
669df8bae1dSRodney W. Grimes 
670df8bae1dSRodney W. Grimes 	/*
671df8bae1dSRodney W. Grimes 	 * Now get a buffer
672df8bae1dSRodney W. Grimes 	 * Abuse a namei buffer for now.
673df8bae1dSRodney W. Grimes 	 */
674996c772fSJohn Dyson 	if (uio->uio_segflg == UIO_SYSSPACE)
675996c772fSJohn Dyson 		symname = uio->uio_iov->iov_base;
676996c772fSJohn Dyson 	else
67799448ed1SJohn Dyson 		symname = zalloc(namei_zone);
678df8bae1dSRodney W. Grimes 
679df8bae1dSRodney W. Grimes 	/*
680df8bae1dSRodney W. Grimes 	 * Ok, we just gathering a symbolic name in SL record.
681df8bae1dSRodney W. Grimes 	 */
682df8bae1dSRodney W. Grimes 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
683996c772fSJohn Dyson 		if (uio->uio_segflg != UIO_SYSSPACE)
68499448ed1SJohn Dyson 			zfree(namei_zone, symname);
685df8bae1dSRodney W. Grimes 		brelse(bp);
686996c772fSJohn Dyson 		return (EINVAL);
687df8bae1dSRodney W. Grimes 	}
688df8bae1dSRodney W. Grimes 	/*
689df8bae1dSRodney W. Grimes 	 * Don't forget before you leave from home ;-)
690df8bae1dSRodney W. Grimes 	 */
691df8bae1dSRodney W. Grimes 	brelse(bp);
692df8bae1dSRodney W. Grimes 
693df8bae1dSRodney W. Grimes 	/*
694df8bae1dSRodney W. Grimes 	 * return with the symbolic name to caller's.
695df8bae1dSRodney W. Grimes 	 */
696996c772fSJohn Dyson 	if (uio->uio_segflg != UIO_SYSSPACE) {
697996c772fSJohn Dyson 		error = uiomove(symname, symlen, uio);
69899448ed1SJohn Dyson 		zfree(namei_zone, symname);
699996c772fSJohn Dyson 		return (error);
700996c772fSJohn Dyson 	}
701996c772fSJohn Dyson 	uio->uio_resid -= symlen;
702996c772fSJohn Dyson 	uio->uio_iov->iov_base += symlen;
703996c772fSJohn Dyson 	uio->uio_iov->iov_len -= symlen;
704996c772fSJohn Dyson 	return (0);
705df8bae1dSRodney W. Grimes }
706df8bae1dSRodney W. Grimes 
707df8bae1dSRodney W. Grimes /*
708df8bae1dSRodney W. Grimes  * Ufs abort op, called after namei() when a CREATE/DELETE isn't actually
709df8bae1dSRodney W. Grimes  * done. If a buffer has been saved in anticipation of a CREATE, delete it.
710df8bae1dSRodney W. Grimes  */
711605e9724SPoul-Henning Kamp static int
712df8bae1dSRodney W. Grimes cd9660_abortop(ap)
713df8bae1dSRodney W. Grimes 	struct vop_abortop_args /* {
714df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
715df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
716df8bae1dSRodney W. Grimes 	} */ *ap;
717df8bae1dSRodney W. Grimes {
718df8bae1dSRodney W. Grimes 	if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
71999448ed1SJohn Dyson 		zfree(namei_zone, ap->a_cnp->cn_pnbuf);
720996c772fSJohn Dyson 	return (0);
721df8bae1dSRodney W. Grimes }
722df8bae1dSRodney W. Grimes 
723df8bae1dSRodney W. Grimes /*
724df8bae1dSRodney W. Grimes  * Calculate the logical to physical mapping if not done already,
725df8bae1dSRodney W. Grimes  * then call the device strategy routine.
726df8bae1dSRodney W. Grimes  */
727605e9724SPoul-Henning Kamp static int
728df8bae1dSRodney W. Grimes cd9660_strategy(ap)
729df8bae1dSRodney W. Grimes 	struct vop_strategy_args /* {
730fd5d1124SJulian Elischer 		struct buf *a_vp;
731df8bae1dSRodney W. Grimes 		struct buf *a_bp;
732df8bae1dSRodney W. Grimes 	} */ *ap;
733df8bae1dSRodney W. Grimes {
734df8bae1dSRodney W. Grimes 	register struct buf *bp = ap->a_bp;
735df8bae1dSRodney W. Grimes 	register struct vnode *vp = bp->b_vp;
736df8bae1dSRodney W. Grimes 	register struct iso_node *ip;
737df8bae1dSRodney W. Grimes 	int error;
738df8bae1dSRodney W. Grimes 
739df8bae1dSRodney W. Grimes 	ip = VTOI(vp);
740df8bae1dSRodney W. Grimes 	if (vp->v_type == VBLK || vp->v_type == VCHR)
741df8bae1dSRodney W. Grimes 		panic("cd9660_strategy: spec");
742df8bae1dSRodney W. Grimes 	if (bp->b_blkno == bp->b_lblkno) {
7431295d82eSGary Palmer 		if ((error =
744c83ebe77SJohn Dyson 		    VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL))) {
745df8bae1dSRodney W. Grimes 			bp->b_error = error;
746df8bae1dSRodney W. Grimes 			bp->b_flags |= B_ERROR;
747df8bae1dSRodney W. Grimes 			biodone(bp);
748df8bae1dSRodney W. Grimes 			return (error);
749df8bae1dSRodney W. Grimes 		}
750df8bae1dSRodney W. Grimes 		if ((long)bp->b_blkno == -1)
751df8bae1dSRodney W. Grimes 			clrbuf(bp);
752df8bae1dSRodney W. Grimes 	}
753df8bae1dSRodney W. Grimes 	if ((long)bp->b_blkno == -1) {
754df8bae1dSRodney W. Grimes 		biodone(bp);
755df8bae1dSRodney W. Grimes 		return (0);
756df8bae1dSRodney W. Grimes 	}
757df8bae1dSRodney W. Grimes 	vp = ip->i_devvp;
758df8bae1dSRodney W. Grimes 	bp->b_dev = vp->v_rdev;
759fd5d1124SJulian Elischer 	VOP_STRATEGY(vp, bp);
760df8bae1dSRodney W. Grimes 	return (0);
761df8bae1dSRodney W. Grimes }
762df8bae1dSRodney W. Grimes 
763df8bae1dSRodney W. Grimes /*
764df8bae1dSRodney W. Grimes  * Print out the contents of an inode.
765df8bae1dSRodney W. Grimes  */
766605e9724SPoul-Henning Kamp static int
767df8bae1dSRodney W. Grimes cd9660_print(ap)
768df8bae1dSRodney W. Grimes 	struct vop_print_args /* {
769df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
770df8bae1dSRodney W. Grimes 	} */ *ap;
771df8bae1dSRodney W. Grimes {
772996c772fSJohn Dyson 
773df8bae1dSRodney W. Grimes 	printf("tag VT_ISOFS, isofs vnode\n");
774996c772fSJohn Dyson 	return (0);
775df8bae1dSRodney W. Grimes }
776df8bae1dSRodney W. Grimes 
777df8bae1dSRodney W. Grimes /*
778996c772fSJohn Dyson  * Return POSIX pathconf information applicable to cd9660 filesystems.
779996c772fSJohn Dyson  */
780f041a9bdSPoul-Henning Kamp static int
781996c772fSJohn Dyson cd9660_pathconf(ap)
782996c772fSJohn Dyson 	struct vop_pathconf_args /* {
783996c772fSJohn Dyson 		struct vnode *a_vp;
784996c772fSJohn Dyson 		int a_name;
785996c772fSJohn Dyson 		register_t *a_retval;
786996c772fSJohn Dyson 	} */ *ap;
787996c772fSJohn Dyson {
788996c772fSJohn Dyson 
789996c772fSJohn Dyson 	switch (ap->a_name) {
790996c772fSJohn Dyson 	case _PC_LINK_MAX:
791996c772fSJohn Dyson 		*ap->a_retval = 1;
792996c772fSJohn Dyson 		return (0);
793996c772fSJohn Dyson 	case _PC_NAME_MAX:
794996c772fSJohn Dyson 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
795996c772fSJohn Dyson 			*ap->a_retval = NAME_MAX;
796996c772fSJohn Dyson 		else
797996c772fSJohn Dyson 			*ap->a_retval = 37;
798996c772fSJohn Dyson 		return (0);
799996c772fSJohn Dyson 	case _PC_PATH_MAX:
800996c772fSJohn Dyson 		*ap->a_retval = PATH_MAX;
801996c772fSJohn Dyson 		return (0);
802996c772fSJohn Dyson 	case _PC_PIPE_BUF:
803996c772fSJohn Dyson 		*ap->a_retval = PIPE_BUF;
804996c772fSJohn Dyson 		return (0);
805996c772fSJohn Dyson 	case _PC_CHOWN_RESTRICTED:
806996c772fSJohn Dyson 		*ap->a_retval = 1;
807996c772fSJohn Dyson 		return (0);
808996c772fSJohn Dyson 	case _PC_NO_TRUNC:
809996c772fSJohn Dyson 		*ap->a_retval = 1;
810996c772fSJohn Dyson 		return (0);
811996c772fSJohn Dyson 	default:
812996c772fSJohn Dyson 		return (EINVAL);
813996c772fSJohn Dyson 	}
814996c772fSJohn Dyson 	/* NOTREACHED */
815df8bae1dSRodney W. Grimes }
816df8bae1dSRodney W. Grimes 
817df8bae1dSRodney W. Grimes /*
818651ae11eSMike Smith  * get page routine
819651ae11eSMike Smith  *
820651ae11eSMike Smith  * XXX By default, wimp out... note that a_offset is ignored (and always
821651ae11eSMike Smith  * XXX has been).
822651ae11eSMike Smith  */
823651ae11eSMike Smith int
824651ae11eSMike Smith cd9660_getpages(ap)
825651ae11eSMike Smith 	struct vop_getpages_args *ap;
826651ae11eSMike Smith {
827651ae11eSMike Smith 	return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
828651ae11eSMike Smith 		ap->a_reqpage);
829651ae11eSMike Smith }
830651ae11eSMike Smith 
831651ae11eSMike Smith /*
832651ae11eSMike Smith  * put page routine
833651ae11eSMike Smith  *
834651ae11eSMike Smith  * XXX By default, wimp out... note that a_offset is ignored (and always
835651ae11eSMike Smith  * XXX has been).
836651ae11eSMike Smith  */
837651ae11eSMike Smith int
838651ae11eSMike Smith cd9660_putpages(ap)
839651ae11eSMike Smith 	struct vop_putpages_args *ap;
840651ae11eSMike Smith {
841651ae11eSMike Smith 	return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
842651ae11eSMike Smith 		ap->a_sync, ap->a_rtvals);
843651ae11eSMike Smith }
844651ae11eSMike Smith 
845651ae11eSMike Smith /*
846996c772fSJohn Dyson  * Global vfs data structures for cd9660
847df8bae1dSRodney W. Grimes  */
848f57e6547SBruce Evans vop_t **cd9660_vnodeop_p;
849f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
850dba3870cSPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
851539ef70cSPoul-Henning Kamp 	{ &vop_abortop_desc,		(vop_t *) cd9660_abortop },
852539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
853539ef70cSPoul-Henning Kamp 	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
854539ef70cSPoul-Henning Kamp 	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
855539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
856539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
857d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
858d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
859539ef70cSPoul-Henning Kamp 	{ &vop_lookup_desc,		(vop_t *) vfs_cache_lookup },
860539ef70cSPoul-Henning Kamp 	{ &vop_pathconf_desc,		(vop_t *) cd9660_pathconf },
861539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
862539ef70cSPoul-Henning Kamp 	{ &vop_read_desc,		(vop_t *) cd9660_read },
863539ef70cSPoul-Henning Kamp 	{ &vop_readdir_desc,		(vop_t *) cd9660_readdir },
864539ef70cSPoul-Henning Kamp 	{ &vop_readlink_desc,		(vop_t *) cd9660_readlink },
865539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
866539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
867539ef70cSPoul-Henning Kamp 	{ &vop_strategy_desc,		(vop_t *) cd9660_strategy },
868d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
869651ae11eSMike Smith 	{ &vop_getpages_desc,		(vop_t *) cd9660_getpages },
870651ae11eSMike Smith 	{ &vop_putpages_desc,		(vop_t *) cd9660_putpages },
871f57e6547SBruce Evans 	{ NULL, NULL }
872df8bae1dSRodney W. Grimes };
873605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
874df8bae1dSRodney W. Grimes 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
875c901836cSGarrett Wollman VNODEOP_SET(cd9660_vnodeop_opv_desc);
876df8bae1dSRodney W. Grimes 
877df8bae1dSRodney W. Grimes /*
878df8bae1dSRodney W. Grimes  * Special device vnode ops
879df8bae1dSRodney W. Grimes  */
880f57e6547SBruce Evans vop_t **cd9660_specop_p;
881f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
882138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) spec_vnoperate },
883539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
884539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
885539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
886d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
887d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
888539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
889539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
890539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
891d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
892f57e6547SBruce Evans 	{ NULL, NULL }
893df8bae1dSRodney W. Grimes };
894605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_specop_opv_desc =
895df8bae1dSRodney W. Grimes 	{ &cd9660_specop_p, cd9660_specop_entries };
896c901836cSGarrett Wollman VNODEOP_SET(cd9660_specop_opv_desc);
897df8bae1dSRodney W. Grimes 
898f57e6547SBruce Evans vop_t **cd9660_fifoop_p;
899f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
900138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) fifo_vnoperate },
901539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
902539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
903539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
904d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
905d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
906539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
907539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
908539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
909d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
910f57e6547SBruce Evans 	{ NULL, NULL }
911df8bae1dSRodney W. Grimes };
912605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_fifoop_opv_desc =
913df8bae1dSRodney W. Grimes 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
914c901836cSGarrett Wollman 
915c901836cSGarrett Wollman VNODEOP_SET(cd9660_fifoop_opv_desc);
916