xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision 99d300a1ecab368a3f1aab2273c07e5040c27d35)
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
39c3aac50fSPeter Wemm  * $FreeBSD$
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>
479626b608SPoul-Henning Kamp #include <sys/bio.h>
48df8bae1dSRodney W. Grimes #include <sys/buf.h>
49df8bae1dSRodney W. Grimes #include <sys/mount.h>
50df8bae1dSRodney W. Grimes #include <sys/vnode.h>
5199d300a1SRuslan Ermilov #include <fs/fifofs/fifo.h>
52df8bae1dSRodney W. Grimes #include <sys/malloc.h>
53c90607baSBruce Evans #include <sys/dirent.h>
54996c772fSJohn Dyson #include <sys/unistd.h>
55cb2a8dffSSøren Schmidt #include <sys/filio.h>
56df8bae1dSRodney W. Grimes 
57651ae11eSMike Smith #include <vm/vm.h>
58675ea6f0SBruce Evans #include <vm/vm_zone.h>
59651ae11eSMike Smith #include <vm/vnode_pager.h>
60675ea6f0SBruce Evans 
61df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso.h>
62df8bae1dSRodney W. Grimes #include <isofs/cd9660/cd9660_node.h>
63df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso_rrip.h>
64df8bae1dSRodney W. Grimes 
6510dd32cdSBruce Evans static int cd9660_setattr __P((struct vop_setattr_args *));
66605e9724SPoul-Henning Kamp static int cd9660_access __P((struct vop_access_args *));
67605e9724SPoul-Henning Kamp static int cd9660_getattr __P((struct vop_getattr_args *));
68cb2a8dffSSøren Schmidt static int cd9660_ioctl __P((struct vop_ioctl_args *));
69f041a9bdSPoul-Henning Kamp static int cd9660_pathconf __P((struct vop_pathconf_args *));
70605e9724SPoul-Henning Kamp static int cd9660_read __P((struct vop_read_args *));
7110dd32cdSBruce Evans struct isoreaddir;
7210dd32cdSBruce Evans static int iso_uiodir __P((struct isoreaddir *idp, struct dirent *dp,
7310dd32cdSBruce Evans 			   off_t off));
7410dd32cdSBruce Evans static int iso_shipdir __P((struct isoreaddir *idp));
75605e9724SPoul-Henning Kamp static int cd9660_readdir __P((struct vop_readdir_args *));
7610dd32cdSBruce Evans static int cd9660_readlink __P((struct vop_readlink_args *ap));
77605e9724SPoul-Henning Kamp static int cd9660_strategy __P((struct vop_strategy_args *));
78605e9724SPoul-Henning Kamp static int cd9660_print __P((struct vop_print_args *));
7910dd32cdSBruce Evans 
80df8bae1dSRodney W. Grimes /*
81de8583ceSDavid Greenman  * Setattr call. Only allowed for block and character special devices.
82de8583ceSDavid Greenman  */
83996c772fSJohn Dyson int
84de8583ceSDavid Greenman cd9660_setattr(ap)
85de8583ceSDavid Greenman 	struct vop_setattr_args /* {
86de8583ceSDavid Greenman 		struct vnodeop_desc *a_desc;
87de8583ceSDavid Greenman 		struct vnode *a_vp;
88de8583ceSDavid Greenman 		struct vattr *a_vap;
89de8583ceSDavid Greenman 		struct ucred *a_cred;
90de8583ceSDavid Greenman 		struct proc *a_p;
91de8583ceSDavid Greenman 	} */ *ap;
92de8583ceSDavid Greenman {
93de8583ceSDavid Greenman 	struct vnode *vp = ap->a_vp;
94de8583ceSDavid Greenman 	struct vattr *vap = ap->a_vap;
95de8583ceSDavid Greenman 
9692579404SAlexander Langer   	if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
9795a1574eSNate Williams 	    vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
9895a1574eSNate Williams 	    vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
99de8583ceSDavid Greenman 		return (EROFS);
10092579404SAlexander Langer 	if (vap->va_size != (u_quad_t)VNOVAL) {
101de8583ceSDavid Greenman  		switch (vp->v_type) {
102de8583ceSDavid Greenman  		case VDIR:
103de8583ceSDavid Greenman  			return (EISDIR);
104de8583ceSDavid Greenman 		case VLNK:
105de8583ceSDavid Greenman 		case VREG:
106de8583ceSDavid Greenman 			return (EROFS);
107de8583ceSDavid Greenman  		case VCHR:
108de8583ceSDavid Greenman  		case VBLK:
109de8583ceSDavid Greenman  		case VSOCK:
110de8583ceSDavid Greenman  		case VFIFO:
111d254af07SMatthew Dillon 		case VNON:
112d254af07SMatthew Dillon 		case VBAD:
113de8583ceSDavid Greenman 			return (0);
114de8583ceSDavid Greenman 		}
115de8583ceSDavid Greenman 	}
116996c772fSJohn Dyson 	return (0);
117de8583ceSDavid Greenman }
118de8583ceSDavid Greenman 
119de8583ceSDavid Greenman /*
120df8bae1dSRodney W. Grimes  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
121df8bae1dSRodney W. Grimes  * The mode is shifted to select the owner/group/other fields. The
122df8bae1dSRodney W. Grimes  * super user is granted all permissions.
123df8bae1dSRodney W. Grimes  */
124df8bae1dSRodney W. Grimes /* ARGSUSED */
125605e9724SPoul-Henning Kamp static int
126df8bae1dSRodney W. Grimes cd9660_access(ap)
127df8bae1dSRodney W. Grimes 	struct vop_access_args /* {
128df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
129df8bae1dSRodney W. Grimes 		int  a_mode;
130df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
131df8bae1dSRodney W. Grimes 		struct proc *a_p;
132df8bae1dSRodney W. Grimes 	} */ *ap;
133df8bae1dSRodney W. Grimes {
134996c772fSJohn Dyson 	struct vnode *vp = ap->a_vp;
135996c772fSJohn Dyson 	struct iso_node *ip = VTOI(vp);
136e39c53edSPoul-Henning Kamp 	mode_t mode = ap->a_mode;
137996c772fSJohn Dyson 
138ba14c327SDavid Greenman 	/*
139996c772fSJohn Dyson 	 * Disallow write attempts unless the file is a socket,
140996c772fSJohn Dyson 	 * fifo, or a block or character device resident on the
141996c772fSJohn Dyson 	 * file system.
142ba14c327SDavid Greenman 	 */
143996c772fSJohn Dyson 	if (mode & VWRITE) {
144996c772fSJohn Dyson 		switch (vp->v_type) {
145ba14c327SDavid Greenman 		case VDIR:
146ba14c327SDavid Greenman 		case VLNK:
147ba14c327SDavid Greenman 		case VREG:
148ba14c327SDavid Greenman 			return (EROFS);
149d254af07SMatthew Dillon 			/* NOT REACHED */
150d254af07SMatthew Dillon 		default:
151d254af07SMatthew Dillon 			break;
152ba14c327SDavid Greenman 		}
153ba14c327SDavid Greenman 	}
154ba14c327SDavid Greenman 
155e39c53edSPoul-Henning Kamp 	return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
156012c643dSRobert Watson 	    ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL));
157df8bae1dSRodney W. Grimes }
158df8bae1dSRodney W. Grimes 
159605e9724SPoul-Henning Kamp static int
160df8bae1dSRodney W. Grimes cd9660_getattr(ap)
161df8bae1dSRodney W. Grimes 	struct vop_getattr_args /* {
162df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
163df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
164df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
165df8bae1dSRodney W. Grimes 		struct proc *a_p;
166df8bae1dSRodney W. Grimes 	} */ *ap;
167df8bae1dSRodney W. Grimes 
168df8bae1dSRodney W. Grimes {
169df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
170df8bae1dSRodney W. Grimes 	register struct vattr *vap = ap->a_vap;
171df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
172df8bae1dSRodney W. Grimes 
173bfbb9ce6SPoul-Henning Kamp 	vap->va_fsid	= dev2udev(ip->i_dev);
174df8bae1dSRodney W. Grimes 	vap->va_fileid	= ip->i_number;
175df8bae1dSRodney W. Grimes 
176df8bae1dSRodney W. Grimes 	vap->va_mode	= ip->inode.iso_mode;
177df8bae1dSRodney W. Grimes 	vap->va_nlink	= ip->inode.iso_links;
178df8bae1dSRodney W. Grimes 	vap->va_uid	= ip->inode.iso_uid;
179df8bae1dSRodney W. Grimes 	vap->va_gid	= ip->inode.iso_gid;
180df8bae1dSRodney W. Grimes 	vap->va_atime	= ip->inode.iso_atime;
181df8bae1dSRodney W. Grimes 	vap->va_mtime	= ip->inode.iso_mtime;
182df8bae1dSRodney W. Grimes 	vap->va_ctime	= ip->inode.iso_ctime;
183df8bae1dSRodney W. Grimes 	vap->va_rdev	= ip->inode.iso_rdev;
184df8bae1dSRodney W. Grimes 
185df8bae1dSRodney W. Grimes 	vap->va_size	= (u_quad_t) ip->i_size;
186996c772fSJohn Dyson 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
187996c772fSJohn Dyson 		struct vop_readlink_args rdlnk;
188996c772fSJohn Dyson 		struct iovec aiov;
189996c772fSJohn Dyson 		struct uio auio;
190996c772fSJohn Dyson 		char *cp;
191996c772fSJohn Dyson 
192996c772fSJohn Dyson 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
193996c772fSJohn Dyson 		aiov.iov_base = cp;
194996c772fSJohn Dyson 		aiov.iov_len = MAXPATHLEN;
195996c772fSJohn Dyson 		auio.uio_iov = &aiov;
196996c772fSJohn Dyson 		auio.uio_iovcnt = 1;
197996c772fSJohn Dyson 		auio.uio_offset = 0;
198996c772fSJohn Dyson 		auio.uio_rw = UIO_READ;
199996c772fSJohn Dyson 		auio.uio_segflg = UIO_SYSSPACE;
200996c772fSJohn Dyson 		auio.uio_procp = ap->a_p;
201996c772fSJohn Dyson 		auio.uio_resid = MAXPATHLEN;
202996c772fSJohn Dyson 		rdlnk.a_uio = &auio;
203996c772fSJohn Dyson 		rdlnk.a_vp = ap->a_vp;
204996c772fSJohn Dyson 		rdlnk.a_cred = ap->a_cred;
205996c772fSJohn Dyson 		if (cd9660_readlink(&rdlnk) == 0)
206996c772fSJohn Dyson 			vap->va_size = MAXPATHLEN - auio.uio_resid;
207996c772fSJohn Dyson 		FREE(cp, M_TEMP);
208996c772fSJohn Dyson 	}
209df8bae1dSRodney W. Grimes 	vap->va_flags	= 0;
210df8bae1dSRodney W. Grimes 	vap->va_gen = 1;
211df8bae1dSRodney W. Grimes 	vap->va_blocksize = ip->i_mnt->logical_block_size;
212df8bae1dSRodney W. Grimes 	vap->va_bytes	= (u_quad_t) ip->i_size;
213df8bae1dSRodney W. Grimes 	vap->va_type	= vp->v_type;
21494a8606fSDoug Rabson 	vap->va_filerev	= 0;
215df8bae1dSRodney W. Grimes 	return (0);
216df8bae1dSRodney W. Grimes }
217df8bae1dSRodney W. Grimes 
218df8bae1dSRodney W. Grimes /*
219cb2a8dffSSøren Schmidt  * Vnode op for ioctl.
220cb2a8dffSSøren Schmidt  */
221cb2a8dffSSøren Schmidt static int
222cb2a8dffSSøren Schmidt cd9660_ioctl(ap)
223cb2a8dffSSøren Schmidt 	struct vop_ioctl_args /* {
224cb2a8dffSSøren Schmidt 		struct vnode *a_vp;
225cb2a8dffSSøren Schmidt 		int  a_command;
226cb2a8dffSSøren Schmidt 		caddr_t  a_data;
227cb2a8dffSSøren Schmidt 		int  a_fflag;
228cb2a8dffSSøren Schmidt 		struct ucred *a_cred;
229cb2a8dffSSøren Schmidt 		struct proc *a_p;
230cb2a8dffSSøren Schmidt 	} */ *ap;
231cb2a8dffSSøren Schmidt {
232cb2a8dffSSøren Schmidt 	struct vnode *vp = ap->a_vp;
233cb2a8dffSSøren Schmidt 	struct iso_node *ip = VTOI(vp);
234cb2a8dffSSøren Schmidt 
235cb2a8dffSSøren Schmidt         switch (ap->a_command) {
236cb2a8dffSSøren Schmidt 
237cb2a8dffSSøren Schmidt         case FIOGETLBA:
238cb2a8dffSSøren Schmidt 		*(int *)(ap->a_data) = ip->iso_start;
239cb2a8dffSSøren Schmidt 		return 0;
240cb2a8dffSSøren Schmidt         default:
241cb2a8dffSSøren Schmidt                 return (ENOTTY);
242cb2a8dffSSøren Schmidt         }
243cb2a8dffSSøren Schmidt }
244cb2a8dffSSøren Schmidt 
245cb2a8dffSSøren Schmidt /*
246df8bae1dSRodney W. Grimes  * Vnode op for reading.
247df8bae1dSRodney W. Grimes  */
248605e9724SPoul-Henning Kamp static int
249df8bae1dSRodney W. Grimes cd9660_read(ap)
250df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
251df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
252df8bae1dSRodney W. Grimes 		struct uio *a_uio;
253df8bae1dSRodney W. Grimes 		int a_ioflag;
254df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
255df8bae1dSRodney W. Grimes 	} */ *ap;
256df8bae1dSRodney W. Grimes {
257df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
258df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
259df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
260df8bae1dSRodney W. Grimes 	register struct iso_mnt *imp;
261df8bae1dSRodney W. Grimes 	struct buf *bp;
2621295d82eSGary Palmer 	daddr_t lbn, rablock;
263df8bae1dSRodney W. Grimes 	off_t diff;
264df8bae1dSRodney W. Grimes 	int rasize, error = 0;
26567ddfcafSMatthew Dillon 	int seqcount;
266df8bae1dSRodney W. Grimes 	long size, n, on;
267df8bae1dSRodney W. Grimes 
26867ddfcafSMatthew Dillon 	seqcount = ap->a_ioflag >> 16;
26967ddfcafSMatthew Dillon 
270df8bae1dSRodney W. Grimes 	if (uio->uio_resid == 0)
271df8bae1dSRodney W. Grimes 		return (0);
272df8bae1dSRodney W. Grimes 	if (uio->uio_offset < 0)
273df8bae1dSRodney W. Grimes 		return (EINVAL);
274996c772fSJohn Dyson 	ip->i_flag |= IN_ACCESS;
275df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
276df8bae1dSRodney W. Grimes 	do {
277996c772fSJohn Dyson 		lbn = lblkno(imp, uio->uio_offset);
278996c772fSJohn Dyson 		on = blkoff(imp, uio->uio_offset);
279996c772fSJohn Dyson 		n = min((u_int)(imp->logical_block_size - on),
280df8bae1dSRodney W. Grimes 			uio->uio_resid);
281df8bae1dSRodney W. Grimes 		diff = (off_t)ip->i_size - uio->uio_offset;
282df8bae1dSRodney W. Grimes 		if (diff <= 0)
283df8bae1dSRodney W. Grimes 			return (0);
284df8bae1dSRodney W. Grimes 		if (diff < n)
285df8bae1dSRodney W. Grimes 			n = diff;
286996c772fSJohn Dyson 		size = blksize(imp, ip, lbn);
287df8bae1dSRodney W. Grimes 		rablock = lbn + 1;
28881bca6ddSKATO Takenori 		if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
2895a5573fdSBruce Evans 			if (lblktosize(imp, rablock) < ip->i_size)
290996c772fSJohn Dyson 				error = cluster_read(vp, (off_t)ip->i_size,
2918b612c4bSJohn Dyson 				         lbn, size, NOCRED, uio->uio_resid,
2928b612c4bSJohn Dyson 					 (ap->a_ioflag >> 16), &bp);
293df8bae1dSRodney W. Grimes 			else
294df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
295df8bae1dSRodney W. Grimes 		} else {
29667ddfcafSMatthew Dillon 			if (seqcount > 1 &&
297996c772fSJohn Dyson 			    lblktosize(imp, rablock) < ip->i_size) {
298996c772fSJohn Dyson 				rasize = blksize(imp, ip, rablock);
299df8bae1dSRodney W. Grimes 				error = breadn(vp, lbn, size, &rablock,
300df8bae1dSRodney W. Grimes 					       &rasize, 1, NOCRED, &bp);
301df8bae1dSRodney W. Grimes 			} else
302df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
303df8bae1dSRodney W. Grimes 		}
304df8bae1dSRodney W. Grimes 		n = min(n, size - bp->b_resid);
305df8bae1dSRodney W. Grimes 		if (error) {
306df8bae1dSRodney W. Grimes 			brelse(bp);
307df8bae1dSRodney W. Grimes 			return (error);
308df8bae1dSRodney W. Grimes 		}
309df8bae1dSRodney W. Grimes 
310996c772fSJohn Dyson 		error = uiomove(bp->b_data + on, (int)n, uio);
311df8bae1dSRodney W. Grimes 		brelse(bp);
312df8bae1dSRodney W. Grimes 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
313df8bae1dSRodney W. Grimes 	return (error);
314df8bae1dSRodney W. Grimes }
315df8bae1dSRodney W. Grimes 
316df8bae1dSRodney W. Grimes /*
317df8bae1dSRodney W. Grimes  * Structure for reading directories
318df8bae1dSRodney W. Grimes  */
319df8bae1dSRodney W. Grimes struct isoreaddir {
320df8bae1dSRodney W. Grimes 	struct dirent saveent;
321df8bae1dSRodney W. Grimes 	struct dirent assocent;
322df8bae1dSRodney W. Grimes 	struct dirent current;
323df8bae1dSRodney W. Grimes 	off_t saveoff;
324df8bae1dSRodney W. Grimes 	off_t assocoff;
325df8bae1dSRodney W. Grimes 	off_t curroff;
326df8bae1dSRodney W. Grimes 	struct uio *uio;
327df8bae1dSRodney W. Grimes 	off_t uio_off;
328996c772fSJohn Dyson 	int eofflag;
329996c772fSJohn Dyson 	u_long *cookies;
330df8bae1dSRodney W. Grimes 	int ncookies;
331df8bae1dSRodney W. Grimes };
332df8bae1dSRodney W. Grimes 
333996c772fSJohn Dyson int
334df8bae1dSRodney W. Grimes iso_uiodir(idp,dp,off)
335df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
336df8bae1dSRodney W. Grimes 	struct dirent *dp;
337df8bae1dSRodney W. Grimes 	off_t off;
338df8bae1dSRodney W. Grimes {
339df8bae1dSRodney W. Grimes 	int error;
340df8bae1dSRodney W. Grimes 
341df8bae1dSRodney W. Grimes 	dp->d_name[dp->d_namlen] = 0;
342c90607baSBruce Evans 	dp->d_reclen = GENERIC_DIRSIZ(dp);
343df8bae1dSRodney W. Grimes 
344df8bae1dSRodney W. Grimes 	if (idp->uio->uio_resid < dp->d_reclen) {
345996c772fSJohn Dyson 		idp->eofflag = 0;
346996c772fSJohn Dyson 		return (-1);
347df8bae1dSRodney W. Grimes 	}
348df8bae1dSRodney W. Grimes 
349996c772fSJohn Dyson 	if (idp->cookies) {
350df8bae1dSRodney W. Grimes 		if (idp->ncookies <= 0) {
351996c772fSJohn Dyson 			idp->eofflag = 0;
352996c772fSJohn Dyson 			return (-1);
353df8bae1dSRodney W. Grimes 		}
354df8bae1dSRodney W. Grimes 
355996c772fSJohn Dyson 		*idp->cookies++ = off;
356df8bae1dSRodney W. Grimes 		--idp->ncookies;
357df8bae1dSRodney W. Grimes 	}
358df8bae1dSRodney W. Grimes 
359d254af07SMatthew Dillon 	if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0)
360996c772fSJohn Dyson 		return (error);
361df8bae1dSRodney W. Grimes 	idp->uio_off = off;
362996c772fSJohn Dyson 	return (0);
363df8bae1dSRodney W. Grimes }
364df8bae1dSRodney W. Grimes 
365996c772fSJohn Dyson int
366df8bae1dSRodney W. Grimes iso_shipdir(idp)
367df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
368df8bae1dSRodney W. Grimes {
369df8bae1dSRodney W. Grimes 	struct dirent *dp;
370df8bae1dSRodney W. Grimes 	int cl, sl, assoc;
371df8bae1dSRodney W. Grimes 	int error;
372df8bae1dSRodney W. Grimes 	char *cname, *sname;
373df8bae1dSRodney W. Grimes 
374df8bae1dSRodney W. Grimes 	cl = idp->current.d_namlen;
375df8bae1dSRodney W. Grimes 	cname = idp->current.d_name;
3761295d82eSGary Palmer assoc = (cl > 1) && (*cname == ASSOCCHAR);
3771295d82eSGary Palmer 	if (assoc) {
378df8bae1dSRodney W. Grimes 		cl--;
379df8bae1dSRodney W. Grimes 		cname++;
380df8bae1dSRodney W. Grimes 	}
381df8bae1dSRodney W. Grimes 
382df8bae1dSRodney W. Grimes 	dp = &idp->saveent;
383df8bae1dSRodney W. Grimes 	sname = dp->d_name;
384df8bae1dSRodney W. Grimes 	if (!(sl = dp->d_namlen)) {
385df8bae1dSRodney W. Grimes 		dp = &idp->assocent;
386df8bae1dSRodney W. Grimes 		sname = dp->d_name + 1;
387df8bae1dSRodney W. Grimes 		sl = dp->d_namlen - 1;
388df8bae1dSRodney W. Grimes 	}
389df8bae1dSRodney W. Grimes 	if (sl > 0) {
390df8bae1dSRodney W. Grimes 		if (sl != cl
391df8bae1dSRodney W. Grimes 		    || bcmp(sname,cname,sl)) {
392df8bae1dSRodney W. Grimes 			if (idp->assocent.d_namlen) {
393d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
394996c772fSJohn Dyson 					return (error);
395df8bae1dSRodney W. Grimes 				idp->assocent.d_namlen = 0;
396df8bae1dSRodney W. Grimes 			}
397df8bae1dSRodney W. Grimes 			if (idp->saveent.d_namlen) {
398d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
399996c772fSJohn Dyson 					return (error);
400df8bae1dSRodney W. Grimes 				idp->saveent.d_namlen = 0;
401df8bae1dSRodney W. Grimes 			}
402df8bae1dSRodney W. Grimes 		}
403df8bae1dSRodney W. Grimes 	}
404c90607baSBruce Evans 	idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
405df8bae1dSRodney W. Grimes 	if (assoc) {
406df8bae1dSRodney W. Grimes 		idp->assocoff = idp->curroff;
407df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
408df8bae1dSRodney W. Grimes 	} else {
409df8bae1dSRodney W. Grimes 		idp->saveoff = idp->curroff;
410df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
411df8bae1dSRodney W. Grimes 	}
412996c772fSJohn Dyson 	return (0);
413df8bae1dSRodney W. Grimes }
414df8bae1dSRodney W. Grimes 
415df8bae1dSRodney W. Grimes /*
416df8bae1dSRodney W. Grimes  * Vnode op for readdir
417df8bae1dSRodney W. Grimes  */
418605e9724SPoul-Henning Kamp static int
419df8bae1dSRodney W. Grimes cd9660_readdir(ap)
420df8bae1dSRodney W. Grimes 	struct vop_readdir_args /* {
421df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
422df8bae1dSRodney W. Grimes 		struct uio *a_uio;
423df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
424996c772fSJohn Dyson 		int *a_eofflag;
425996c772fSJohn Dyson 		int *a_ncookies;
426996c772fSJohn Dyson 		u_long *a_cookies;
427df8bae1dSRodney W. Grimes 	} */ *ap;
428df8bae1dSRodney W. Grimes {
429df8bae1dSRodney W. Grimes 	register struct uio *uio = ap->a_uio;
430df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
431996c772fSJohn Dyson 	struct vnode *vdp = ap->a_vp;
432996c772fSJohn Dyson 	struct iso_node *dp;
433df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
434df8bae1dSRodney W. Grimes 	struct buf *bp = NULL;
435996c772fSJohn Dyson 	struct iso_directory_record *ep;
436996c772fSJohn Dyson 	int entryoffsetinblock;
437996c772fSJohn Dyson 	doff_t endsearch;
438996c772fSJohn Dyson 	u_long bmask;
439996c772fSJohn Dyson 	int error = 0;
440996c772fSJohn Dyson 	int reclen;
441996c772fSJohn Dyson 	u_short namelen;
4429abf4d6eSDoug Rabson 	int ncookies = 0;
443996c772fSJohn Dyson 	u_long *cookies = NULL;
444df8bae1dSRodney W. Grimes 
445996c772fSJohn Dyson 	dp = VTOI(vdp);
446996c772fSJohn Dyson 	imp = dp->i_mnt;
447996c772fSJohn Dyson 	bmask = imp->im_bmask;
448df8bae1dSRodney W. Grimes 
449df8bae1dSRodney W. Grimes 	MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
450996c772fSJohn Dyson 	idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
451996c772fSJohn Dyson 	/*
452996c772fSJohn Dyson 	 * XXX
453996c772fSJohn Dyson 	 * Is it worth trying to figure out the type?
454996c772fSJohn Dyson 	 */
455996c772fSJohn Dyson 	idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
456996c772fSJohn Dyson 	    DT_UNKNOWN;
457df8bae1dSRodney W. Grimes 	idp->uio = uio;
458996c772fSJohn Dyson 	if (ap->a_ncookies == NULL) {
459996c772fSJohn Dyson 		idp->cookies = NULL;
460996c772fSJohn Dyson 	} else {
4619abf4d6eSDoug Rabson 		/*
4629abf4d6eSDoug Rabson 		 * Guess the number of cookies needed.
4639abf4d6eSDoug Rabson 		 */
4649abf4d6eSDoug Rabson 		ncookies = uio->uio_resid / 16;
465996c772fSJohn Dyson 		MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
466996c772fSJohn Dyson 		    M_WAITOK);
467996c772fSJohn Dyson 		idp->cookies = cookies;
468df8bae1dSRodney W. Grimes 		idp->ncookies = ncookies;
469996c772fSJohn Dyson 	}
470996c772fSJohn Dyson 	idp->eofflag = 1;
471df8bae1dSRodney W. Grimes 	idp->curroff = uio->uio_offset;
472df8bae1dSRodney W. Grimes 
473996c772fSJohn Dyson 	if ((entryoffsetinblock = idp->curroff & bmask) &&
474cec0f20cSPoul-Henning Kamp 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
475df8bae1dSRodney W. Grimes 		FREE(idp, M_TEMP);
476df8bae1dSRodney W. Grimes 		return (error);
477df8bae1dSRodney W. Grimes 	}
478996c772fSJohn Dyson 	endsearch = dp->i_size;
479df8bae1dSRodney W. Grimes 
480df8bae1dSRodney W. Grimes 	while (idp->curroff < endsearch) {
481df8bae1dSRodney W. Grimes 		/*
482df8bae1dSRodney W. Grimes 		 * If offset is on a block boundary,
483df8bae1dSRodney W. Grimes 		 * read the next directory block.
484df8bae1dSRodney W. Grimes 		 * Release previous if it exists.
485df8bae1dSRodney W. Grimes 		 */
486996c772fSJohn Dyson 		if ((idp->curroff & bmask) == 0) {
487df8bae1dSRodney W. Grimes 			if (bp != NULL)
488df8bae1dSRodney W. Grimes 				brelse(bp);
489d254af07SMatthew Dillon 			if ((error =
490d254af07SMatthew Dillon 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
491df8bae1dSRodney W. Grimes 				break;
492df8bae1dSRodney W. Grimes 			entryoffsetinblock = 0;
493df8bae1dSRodney W. Grimes 		}
494df8bae1dSRodney W. Grimes 		/*
495df8bae1dSRodney W. Grimes 		 * Get pointer to next entry.
496df8bae1dSRodney W. Grimes 		 */
497df8bae1dSRodney W. Grimes 		ep = (struct iso_directory_record *)
498996c772fSJohn Dyson 			((char *)bp->b_data + entryoffsetinblock);
499df8bae1dSRodney W. Grimes 
500df8bae1dSRodney W. Grimes 		reclen = isonum_711(ep->length);
501df8bae1dSRodney W. Grimes 		if (reclen == 0) {
502df8bae1dSRodney W. Grimes 			/* skip to next block, if any */
503996c772fSJohn Dyson 			idp->curroff =
504996c772fSJohn Dyson 			    (idp->curroff & ~bmask) + imp->logical_block_size;
505df8bae1dSRodney W. Grimes 			continue;
506df8bae1dSRodney W. Grimes 		}
507df8bae1dSRodney W. Grimes 
508df8bae1dSRodney W. Grimes 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
509df8bae1dSRodney W. Grimes 			error = EINVAL;
510df8bae1dSRodney W. Grimes 			/* illegal entry, stop */
511df8bae1dSRodney W. Grimes 			break;
512df8bae1dSRodney W. Grimes 		}
513df8bae1dSRodney W. Grimes 
514df8bae1dSRodney W. Grimes 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
515df8bae1dSRodney W. Grimes 			error = EINVAL;
516df8bae1dSRodney W. Grimes 			/* illegal directory, so stop looking */
517df8bae1dSRodney W. Grimes 			break;
518df8bae1dSRodney W. Grimes 		}
519df8bae1dSRodney W. Grimes 
520996c772fSJohn Dyson 		idp->current.d_namlen = isonum_711(ep->name_len);
521996c772fSJohn Dyson 
522996c772fSJohn Dyson 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
52381ec856aSJoerg Wunsch 			error = EINVAL;
52481ec856aSJoerg Wunsch 			/* illegal entry, stop */
52581ec856aSJoerg Wunsch 			break;
52681ec856aSJoerg Wunsch 		}
52781ec856aSJoerg Wunsch 
528996c772fSJohn Dyson 		if (isonum_711(ep->flags)&2)
529996c772fSJohn Dyson 			idp->current.d_fileno = isodirino(ep, imp);
530df8bae1dSRodney W. Grimes 		else
531df8bae1dSRodney W. Grimes 			idp->current.d_fileno = dbtob(bp->b_blkno) +
532996c772fSJohn Dyson 				entryoffsetinblock;
533df8bae1dSRodney W. Grimes 
534df8bae1dSRodney W. Grimes 		idp->curroff += reclen;
535996c772fSJohn Dyson 
536df8bae1dSRodney W. Grimes 		switch (imp->iso_ftype) {
537df8bae1dSRodney W. Grimes 		case ISO_FTYPE_RRIP:
538996c772fSJohn Dyson 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
539df8bae1dSRodney W. Grimes 					   &idp->current.d_fileno,imp);
540996c772fSJohn Dyson 			idp->current.d_namlen = (u_char)namelen;
541df8bae1dSRodney W. Grimes 			if (idp->current.d_namlen)
542df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
543df8bae1dSRodney W. Grimes 			break;
544988fa8efSJoerg Wunsch 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
545df8bae1dSRodney W. Grimes 			strcpy(idp->current.d_name,"..");
54644e568e2SDaniel C. Sobral 			if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
547df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 1;
548df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
54944e568e2SDaniel C. Sobral 			} else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
550df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 2;
551df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
55244e568e2SDaniel C. Sobral 			} else {
553df8bae1dSRodney W. Grimes 				isofntrans(ep->name,idp->current.d_namlen,
554996c772fSJohn Dyson 					   idp->current.d_name, &namelen,
555df8bae1dSRodney W. Grimes 					   imp->iso_ftype == ISO_FTYPE_9660,
55644e568e2SDaniel C. Sobral 					   isonum_711(ep->flags)&4,
55744e568e2SDaniel C. Sobral 					   imp->joliet_level);
558996c772fSJohn Dyson 				idp->current.d_namlen = (u_char)namelen;
559df8bae1dSRodney W. Grimes 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
560df8bae1dSRodney W. Grimes 					error = iso_shipdir(idp);
561df8bae1dSRodney W. Grimes 				else
562df8bae1dSRodney W. Grimes 					error = iso_uiodir(idp,&idp->current,idp->curroff);
563df8bae1dSRodney W. Grimes 			}
564df8bae1dSRodney W. Grimes 		}
565df8bae1dSRodney W. Grimes 		if (error)
566df8bae1dSRodney W. Grimes 			break;
567df8bae1dSRodney W. Grimes 
568df8bae1dSRodney W. Grimes 		entryoffsetinblock += reclen;
569df8bae1dSRodney W. Grimes 	}
570df8bae1dSRodney W. Grimes 
571df8bae1dSRodney W. Grimes 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
572df8bae1dSRodney W. Grimes 		idp->current.d_namlen = 0;
573df8bae1dSRodney W. Grimes 		error = iso_shipdir(idp);
574df8bae1dSRodney W. Grimes 	}
575df8bae1dSRodney W. Grimes 	if (error < 0)
576df8bae1dSRodney W. Grimes 		error = 0;
577df8bae1dSRodney W. Grimes 
5789abf4d6eSDoug Rabson 	if (ap->a_ncookies != NULL) {
5799abf4d6eSDoug Rabson 		if (error)
580996c772fSJohn Dyson 			free(cookies, M_TEMP);
5819abf4d6eSDoug Rabson 		else {
5829abf4d6eSDoug Rabson 			/*
5839abf4d6eSDoug Rabson 			 * Work out the number of cookies actually used.
5849abf4d6eSDoug Rabson 			 */
5859abf4d6eSDoug Rabson 			*ap->a_ncookies = ncookies - idp->ncookies;
5869abf4d6eSDoug Rabson 			*ap->a_cookies = cookies;
5879abf4d6eSDoug Rabson 		}
5889abf4d6eSDoug Rabson 	}
5899abf4d6eSDoug Rabson 
590df8bae1dSRodney W. Grimes 	if (bp)
591df8bae1dSRodney W. Grimes 		brelse (bp);
592df8bae1dSRodney W. Grimes 
593df8bae1dSRodney W. Grimes 	uio->uio_offset = idp->uio_off;
594996c772fSJohn Dyson 	*ap->a_eofflag = idp->eofflag;
595df8bae1dSRodney W. Grimes 
596df8bae1dSRodney W. Grimes 	FREE(idp, M_TEMP);
597df8bae1dSRodney W. Grimes 
598df8bae1dSRodney W. Grimes 	return (error);
599df8bae1dSRodney W. Grimes }
600df8bae1dSRodney W. Grimes 
601df8bae1dSRodney W. Grimes /*
602df8bae1dSRodney W. Grimes  * Return target name of a symbolic link
603df8bae1dSRodney W. Grimes  * Shouldn't we get the parent vnode and read the data from there?
604df8bae1dSRodney W. Grimes  * This could eventually result in deadlocks in cd9660_lookup.
605df8bae1dSRodney W. Grimes  * But otherwise the block read here is in the block buffer two times.
606df8bae1dSRodney W. Grimes  */
607df8bae1dSRodney W. Grimes typedef struct iso_directory_record ISODIR;
608df8bae1dSRodney W. Grimes typedef struct iso_node		    ISONODE;
609df8bae1dSRodney W. Grimes typedef struct iso_mnt		    ISOMNT;
610605e9724SPoul-Henning Kamp static int
611df8bae1dSRodney W. Grimes cd9660_readlink(ap)
612df8bae1dSRodney W. Grimes 	struct vop_readlink_args /* {
613df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
614df8bae1dSRodney W. Grimes 		struct uio *a_uio;
615df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
616df8bae1dSRodney W. Grimes 	} */ *ap;
617df8bae1dSRodney W. Grimes {
618df8bae1dSRodney W. Grimes 	ISONODE	*ip;
619df8bae1dSRodney W. Grimes 	ISODIR	*dirp;
620df8bae1dSRodney W. Grimes 	ISOMNT	*imp;
621df8bae1dSRodney W. Grimes 	struct	buf *bp;
622996c772fSJohn Dyson 	struct	uio *uio;
623df8bae1dSRodney W. Grimes 	u_short	symlen;
624df8bae1dSRodney W. Grimes 	int	error;
625df8bae1dSRodney W. Grimes 	char	*symname;
626df8bae1dSRodney W. Grimes 
627df8bae1dSRodney W. Grimes 	ip  = VTOI(ap->a_vp);
628df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
629996c772fSJohn Dyson 	uio = ap->a_uio;
630df8bae1dSRodney W. Grimes 
631df8bae1dSRodney W. Grimes 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
632996c772fSJohn Dyson 		return (EINVAL);
633df8bae1dSRodney W. Grimes 
634df8bae1dSRodney W. Grimes 	/*
635df8bae1dSRodney W. Grimes 	 * Get parents directory record block that this inode included.
636df8bae1dSRodney W. Grimes 	 */
637df8bae1dSRodney W. Grimes 	error = bread(imp->im_devvp,
638996c772fSJohn Dyson 		      (ip->i_number >> imp->im_bshift) <<
639996c772fSJohn Dyson 		      (imp->im_bshift - DEV_BSHIFT),
640996c772fSJohn Dyson 		      imp->logical_block_size, NOCRED, &bp);
641df8bae1dSRodney W. Grimes 	if (error) {
642df8bae1dSRodney W. Grimes 		brelse(bp);
643996c772fSJohn Dyson 		return (EINVAL);
644df8bae1dSRodney W. Grimes 	}
645df8bae1dSRodney W. Grimes 
646df8bae1dSRodney W. Grimes 	/*
647df8bae1dSRodney W. Grimes 	 * Setup the directory pointer for this inode
648df8bae1dSRodney W. Grimes 	 */
649996c772fSJohn Dyson 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
650df8bae1dSRodney W. Grimes 
651df8bae1dSRodney W. Grimes 	/*
652df8bae1dSRodney W. Grimes 	 * Just make sure, we have a right one....
653df8bae1dSRodney W. Grimes 	 *   1: Check not cross boundary on block
654df8bae1dSRodney W. Grimes 	 */
655df8bae1dSRodney W. Grimes 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
65692579404SAlexander Langer 	    > (unsigned)imp->logical_block_size) {
657df8bae1dSRodney W. Grimes 		brelse(bp);
658996c772fSJohn Dyson 		return (EINVAL);
659df8bae1dSRodney W. Grimes 	}
660df8bae1dSRodney W. Grimes 
661df8bae1dSRodney W. Grimes 	/*
662df8bae1dSRodney W. Grimes 	 * Now get a buffer
663df8bae1dSRodney W. Grimes 	 * Abuse a namei buffer for now.
664df8bae1dSRodney W. Grimes 	 */
665996c772fSJohn Dyson 	if (uio->uio_segflg == UIO_SYSSPACE)
666996c772fSJohn Dyson 		symname = uio->uio_iov->iov_base;
667996c772fSJohn Dyson 	else
66899448ed1SJohn Dyson 		symname = zalloc(namei_zone);
669df8bae1dSRodney W. Grimes 
670df8bae1dSRodney W. Grimes 	/*
671df8bae1dSRodney W. Grimes 	 * Ok, we just gathering a symbolic name in SL record.
672df8bae1dSRodney W. Grimes 	 */
673df8bae1dSRodney W. Grimes 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
674996c772fSJohn Dyson 		if (uio->uio_segflg != UIO_SYSSPACE)
67599448ed1SJohn Dyson 			zfree(namei_zone, symname);
676df8bae1dSRodney W. Grimes 		brelse(bp);
677996c772fSJohn Dyson 		return (EINVAL);
678df8bae1dSRodney W. Grimes 	}
679df8bae1dSRodney W. Grimes 	/*
680df8bae1dSRodney W. Grimes 	 * Don't forget before you leave from home ;-)
681df8bae1dSRodney W. Grimes 	 */
682df8bae1dSRodney W. Grimes 	brelse(bp);
683df8bae1dSRodney W. Grimes 
684df8bae1dSRodney W. Grimes 	/*
685df8bae1dSRodney W. Grimes 	 * return with the symbolic name to caller's.
686df8bae1dSRodney W. Grimes 	 */
687996c772fSJohn Dyson 	if (uio->uio_segflg != UIO_SYSSPACE) {
688996c772fSJohn Dyson 		error = uiomove(symname, symlen, uio);
68999448ed1SJohn Dyson 		zfree(namei_zone, symname);
690996c772fSJohn Dyson 		return (error);
691996c772fSJohn Dyson 	}
692996c772fSJohn Dyson 	uio->uio_resid -= symlen;
693996c772fSJohn Dyson 	uio->uio_iov->iov_base += symlen;
694996c772fSJohn Dyson 	uio->uio_iov->iov_len -= symlen;
695996c772fSJohn Dyson 	return (0);
696df8bae1dSRodney W. Grimes }
697df8bae1dSRodney W. Grimes 
698df8bae1dSRodney W. Grimes /*
699df8bae1dSRodney W. Grimes  * Calculate the logical to physical mapping if not done already,
700df8bae1dSRodney W. Grimes  * then call the device strategy routine.
701df8bae1dSRodney W. Grimes  */
702605e9724SPoul-Henning Kamp static int
703df8bae1dSRodney W. Grimes cd9660_strategy(ap)
704df8bae1dSRodney W. Grimes 	struct vop_strategy_args /* {
705fd5d1124SJulian Elischer 		struct buf *a_vp;
706df8bae1dSRodney W. Grimes 		struct buf *a_bp;
707df8bae1dSRodney W. Grimes 	} */ *ap;
708df8bae1dSRodney W. Grimes {
709df8bae1dSRodney W. Grimes 	register struct buf *bp = ap->a_bp;
710df8bae1dSRodney W. Grimes 	register struct vnode *vp = bp->b_vp;
711df8bae1dSRodney W. Grimes 	register struct iso_node *ip;
712df8bae1dSRodney W. Grimes 
713df8bae1dSRodney W. Grimes 	ip = VTOI(vp);
714df8bae1dSRodney W. Grimes 	if (vp->v_type == VBLK || vp->v_type == VCHR)
715df8bae1dSRodney W. Grimes 		panic("cd9660_strategy: spec");
716df8bae1dSRodney W. Grimes 	if (bp->b_blkno == bp->b_lblkno) {
717e9d19a11SPoul-Henning Kamp 		bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
718e9d19a11SPoul-Henning Kamp 		    (ip->i_mnt->im_bshift - DEV_BSHIFT);
719e9d19a11SPoul-Henning Kamp 		if ((long)bp->b_blkno == -1)	/* XXX: cut&paste junk ? */
720df8bae1dSRodney W. Grimes 			clrbuf(bp);
721df8bae1dSRodney W. Grimes 	}
722e9d19a11SPoul-Henning Kamp 	if ((long)bp->b_blkno == -1) {	/* XXX: cut&paste junk ? */
7238177437dSPoul-Henning Kamp 		bufdone(bp);
724df8bae1dSRodney W. Grimes 		return (0);
725df8bae1dSRodney W. Grimes 	}
726df8bae1dSRodney W. Grimes 	vp = ip->i_devvp;
727df8bae1dSRodney W. Grimes 	bp->b_dev = vp->v_rdev;
728fd5d1124SJulian Elischer 	VOP_STRATEGY(vp, bp);
729df8bae1dSRodney W. Grimes 	return (0);
730df8bae1dSRodney W. Grimes }
731df8bae1dSRodney W. Grimes 
732df8bae1dSRodney W. Grimes /*
733df8bae1dSRodney W. Grimes  * Print out the contents of an inode.
734df8bae1dSRodney W. Grimes  */
735605e9724SPoul-Henning Kamp static int
736df8bae1dSRodney W. Grimes cd9660_print(ap)
737df8bae1dSRodney W. Grimes 	struct vop_print_args /* {
738df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
739df8bae1dSRodney W. Grimes 	} */ *ap;
740df8bae1dSRodney W. Grimes {
741996c772fSJohn Dyson 
742df8bae1dSRodney W. Grimes 	printf("tag VT_ISOFS, isofs vnode\n");
743996c772fSJohn Dyson 	return (0);
744df8bae1dSRodney W. Grimes }
745df8bae1dSRodney W. Grimes 
746df8bae1dSRodney W. Grimes /*
747996c772fSJohn Dyson  * Return POSIX pathconf information applicable to cd9660 filesystems.
748996c772fSJohn Dyson  */
749f041a9bdSPoul-Henning Kamp static int
750996c772fSJohn Dyson cd9660_pathconf(ap)
751996c772fSJohn Dyson 	struct vop_pathconf_args /* {
752996c772fSJohn Dyson 		struct vnode *a_vp;
753996c772fSJohn Dyson 		int a_name;
754996c772fSJohn Dyson 		register_t *a_retval;
755996c772fSJohn Dyson 	} */ *ap;
756996c772fSJohn Dyson {
757996c772fSJohn Dyson 
758996c772fSJohn Dyson 	switch (ap->a_name) {
759996c772fSJohn Dyson 	case _PC_LINK_MAX:
760996c772fSJohn Dyson 		*ap->a_retval = 1;
761996c772fSJohn Dyson 		return (0);
762996c772fSJohn Dyson 	case _PC_NAME_MAX:
763996c772fSJohn Dyson 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
764996c772fSJohn Dyson 			*ap->a_retval = NAME_MAX;
765996c772fSJohn Dyson 		else
766996c772fSJohn Dyson 			*ap->a_retval = 37;
767996c772fSJohn Dyson 		return (0);
768996c772fSJohn Dyson 	case _PC_PATH_MAX:
769996c772fSJohn Dyson 		*ap->a_retval = PATH_MAX;
770996c772fSJohn Dyson 		return (0);
771996c772fSJohn Dyson 	case _PC_PIPE_BUF:
772996c772fSJohn Dyson 		*ap->a_retval = PIPE_BUF;
773996c772fSJohn Dyson 		return (0);
774996c772fSJohn Dyson 	case _PC_CHOWN_RESTRICTED:
775996c772fSJohn Dyson 		*ap->a_retval = 1;
776996c772fSJohn Dyson 		return (0);
777996c772fSJohn Dyson 	case _PC_NO_TRUNC:
778996c772fSJohn Dyson 		*ap->a_retval = 1;
779996c772fSJohn Dyson 		return (0);
780996c772fSJohn Dyson 	default:
781996c772fSJohn Dyson 		return (EINVAL);
782996c772fSJohn Dyson 	}
783996c772fSJohn Dyson 	/* NOTREACHED */
784df8bae1dSRodney W. Grimes }
785df8bae1dSRodney W. Grimes 
786df8bae1dSRodney W. Grimes /*
787996c772fSJohn Dyson  * Global vfs data structures for cd9660
788df8bae1dSRodney W. Grimes  */
789f57e6547SBruce Evans vop_t **cd9660_vnodeop_p;
790f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
791dba3870cSPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
792539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
793539ef70cSPoul-Henning Kamp 	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
794539ef70cSPoul-Henning Kamp 	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
795539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
796539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
797cb2a8dffSSøren Schmidt 	{ &vop_ioctl_desc,		(vop_t *) cd9660_ioctl },
798d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
799d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
800539ef70cSPoul-Henning Kamp 	{ &vop_lookup_desc,		(vop_t *) vfs_cache_lookup },
801539ef70cSPoul-Henning Kamp 	{ &vop_pathconf_desc,		(vop_t *) cd9660_pathconf },
802539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
803539ef70cSPoul-Henning Kamp 	{ &vop_read_desc,		(vop_t *) cd9660_read },
804539ef70cSPoul-Henning Kamp 	{ &vop_readdir_desc,		(vop_t *) cd9660_readdir },
805539ef70cSPoul-Henning Kamp 	{ &vop_readlink_desc,		(vop_t *) cd9660_readlink },
806539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
807539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
808539ef70cSPoul-Henning Kamp 	{ &vop_strategy_desc,		(vop_t *) cd9660_strategy },
809d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
810f57e6547SBruce Evans 	{ NULL, NULL }
811df8bae1dSRodney W. Grimes };
812605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
813df8bae1dSRodney W. Grimes 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
814c901836cSGarrett Wollman VNODEOP_SET(cd9660_vnodeop_opv_desc);
815df8bae1dSRodney W. Grimes 
816df8bae1dSRodney W. Grimes /*
817df8bae1dSRodney W. Grimes  * Special device vnode ops
818df8bae1dSRodney W. Grimes  */
819f57e6547SBruce Evans vop_t **cd9660_specop_p;
820f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
821138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) spec_vnoperate },
822539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
823539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
824539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
825d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
826d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
827539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
828539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
829539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
830d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
831f57e6547SBruce Evans 	{ NULL, NULL }
832df8bae1dSRodney W. Grimes };
833605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_specop_opv_desc =
834df8bae1dSRodney W. Grimes 	{ &cd9660_specop_p, cd9660_specop_entries };
835c901836cSGarrett Wollman VNODEOP_SET(cd9660_specop_opv_desc);
836df8bae1dSRodney W. Grimes 
837f57e6547SBruce Evans vop_t **cd9660_fifoop_p;
838f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
839138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) fifo_vnoperate },
840539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
841539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
842539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
843d54d34b5SPoul-Henning Kamp 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
844d54d34b5SPoul-Henning Kamp 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
845539ef70cSPoul-Henning Kamp 	{ &vop_print_desc,		(vop_t *) cd9660_print },
846539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
847539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
848d54d34b5SPoul-Henning Kamp 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
849f57e6547SBruce Evans 	{ NULL, NULL }
850df8bae1dSRodney W. Grimes };
851605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_fifoop_opv_desc =
852df8bae1dSRodney W. Grimes 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
853c901836cSGarrett Wollman 
854c901836cSGarrett Wollman VNODEOP_SET(cd9660_fifoop_opv_desc);
855