xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision 2c18019f141eab7862508c732bed94aa42238813)
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
39df8bae1dSRodney W. Grimes  */
40df8bae1dSRodney W. Grimes 
418c9bbf48SDavid E. O'Brien #include <sys/cdefs.h>
428c9bbf48SDavid E. O'Brien __FBSDID("$FreeBSD$");
438c9bbf48SDavid E. O'Brien 
44df8bae1dSRodney W. Grimes #include <sys/param.h>
45df8bae1dSRodney W. Grimes #include <sys/systm.h>
46df8bae1dSRodney W. Grimes #include <sys/namei.h>
47df8bae1dSRodney W. Grimes #include <sys/kernel.h>
48df8bae1dSRodney W. Grimes #include <sys/stat.h>
499626b608SPoul-Henning Kamp #include <sys/bio.h>
50df8bae1dSRodney W. Grimes #include <sys/buf.h>
51df8bae1dSRodney W. Grimes #include <sys/mount.h>
52df8bae1dSRodney W. Grimes #include <sys/vnode.h>
5399d300a1SRuslan Ermilov #include <fs/fifofs/fifo.h>
54df8bae1dSRodney W. Grimes #include <sys/malloc.h>
55c90607baSBruce Evans #include <sys/dirent.h>
56996c772fSJohn Dyson #include <sys/unistd.h>
57cb2a8dffSSøren Schmidt #include <sys/filio.h>
58df8bae1dSRodney W. Grimes 
59651ae11eSMike Smith #include <vm/vm.h>
60651ae11eSMike Smith #include <vm/vnode_pager.h>
612684b6afSJeff Roberson #include <vm/uma.h>
62675ea6f0SBruce Evans 
63df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso.h>
64df8bae1dSRodney W. Grimes #include <isofs/cd9660/cd9660_node.h>
65df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso_rrip.h>
66df8bae1dSRodney W. Grimes 
6789c9a483SAlfred Perlstein static int cd9660_setattr(struct vop_setattr_args *);
6889c9a483SAlfred Perlstein static int cd9660_access(struct vop_access_args *);
6989c9a483SAlfred Perlstein static int cd9660_getattr(struct vop_getattr_args *);
7089c9a483SAlfred Perlstein static int cd9660_ioctl(struct vop_ioctl_args *);
7189c9a483SAlfred Perlstein static int cd9660_pathconf(struct vop_pathconf_args *);
7289c9a483SAlfred Perlstein static int cd9660_read(struct vop_read_args *);
7310dd32cdSBruce Evans struct isoreaddir;
7489c9a483SAlfred Perlstein static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off);
7589c9a483SAlfred Perlstein static int iso_shipdir(struct isoreaddir *idp);
7689c9a483SAlfred Perlstein static int cd9660_readdir(struct vop_readdir_args *);
7789c9a483SAlfred Perlstein static int cd9660_readlink(struct vop_readlink_args *ap);
7889c9a483SAlfred Perlstein static int cd9660_strategy(struct vop_strategy_args *);
7910dd32cdSBruce Evans 
80df8bae1dSRodney W. Grimes /*
81de8583ceSDavid Greenman  * Setattr call. Only allowed for block and character special devices.
82de8583ceSDavid Greenman  */
8337c84183SPoul-Henning Kamp static 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;
90b40ce416SJulian Elischer 		struct thread *a_td;
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;
131b40ce416SJulian Elischer 		struct thread *a_td;
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 	 * filesystem.
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;
165b40ce416SJulian Elischer 		struct thread *a_td;
166df8bae1dSRodney W. Grimes 	} */ *ap;
167df8bae1dSRodney W. Grimes 
168df8bae1dSRodney W. Grimes {
169df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
1708994a245SDag-Erling Smørgrav 	struct vattr *vap = ap->a_vap;
1718994a245SDag-Erling Smørgrav 	struct iso_node *ip = VTOI(vp);
172df8bae1dSRodney W. Grimes 
173bfbb9ce6SPoul-Henning Kamp 	vap->va_fsid	= dev2udev(ip->i_dev);
174fba2e610SBruce Evans 
175fba2e610SBruce Evans 	/*
176fba2e610SBruce Evans 	 * Don't use ip->i_ino for this since it is wrong for hard links.
177fba2e610SBruce Evans 	 * ip->i_ino should be the same as ip->iso_start (or not exist),
178fba2e610SBruce Evans 	 * but this currently doesn't work since we abuse it to look up
179fba2e610SBruce Evans 	 * parent directories from inodes.
180fba2e610SBruce Evans 	 */
181fba2e610SBruce Evans 	vap->va_fileid	= ip->iso_start;
182df8bae1dSRodney W. Grimes 
183df8bae1dSRodney W. Grimes 	vap->va_mode	= ip->inode.iso_mode;
184df8bae1dSRodney W. Grimes 	vap->va_nlink	= ip->inode.iso_links;
185df8bae1dSRodney W. Grimes 	vap->va_uid	= ip->inode.iso_uid;
186df8bae1dSRodney W. Grimes 	vap->va_gid	= ip->inode.iso_gid;
187df8bae1dSRodney W. Grimes 	vap->va_atime	= ip->inode.iso_atime;
188df8bae1dSRodney W. Grimes 	vap->va_mtime	= ip->inode.iso_mtime;
189df8bae1dSRodney W. Grimes 	vap->va_ctime	= ip->inode.iso_ctime;
190df8bae1dSRodney W. Grimes 	vap->va_rdev	= ip->inode.iso_rdev;
191df8bae1dSRodney W. Grimes 
192df8bae1dSRodney W. Grimes 	vap->va_size	= (u_quad_t) ip->i_size;
193996c772fSJohn Dyson 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
194996c772fSJohn Dyson 		struct vop_readlink_args rdlnk;
195996c772fSJohn Dyson 		struct iovec aiov;
196996c772fSJohn Dyson 		struct uio auio;
197996c772fSJohn Dyson 		char *cp;
198996c772fSJohn Dyson 
199a163d034SWarner Losh 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
200996c772fSJohn Dyson 		aiov.iov_base = cp;
201996c772fSJohn Dyson 		aiov.iov_len = MAXPATHLEN;
202996c772fSJohn Dyson 		auio.uio_iov = &aiov;
203996c772fSJohn Dyson 		auio.uio_iovcnt = 1;
204996c772fSJohn Dyson 		auio.uio_offset = 0;
205996c772fSJohn Dyson 		auio.uio_rw = UIO_READ;
206996c772fSJohn Dyson 		auio.uio_segflg = UIO_SYSSPACE;
207b40ce416SJulian Elischer 		auio.uio_td = ap->a_td;
208996c772fSJohn Dyson 		auio.uio_resid = MAXPATHLEN;
209996c772fSJohn Dyson 		rdlnk.a_uio = &auio;
210996c772fSJohn Dyson 		rdlnk.a_vp = ap->a_vp;
211996c772fSJohn Dyson 		rdlnk.a_cred = ap->a_cred;
212996c772fSJohn Dyson 		if (cd9660_readlink(&rdlnk) == 0)
213996c772fSJohn Dyson 			vap->va_size = MAXPATHLEN - auio.uio_resid;
214996c772fSJohn Dyson 		FREE(cp, M_TEMP);
215996c772fSJohn Dyson 	}
216df8bae1dSRodney W. Grimes 	vap->va_flags	= 0;
217df8bae1dSRodney W. Grimes 	vap->va_gen = 1;
218df8bae1dSRodney W. Grimes 	vap->va_blocksize = ip->i_mnt->logical_block_size;
219df8bae1dSRodney W. Grimes 	vap->va_bytes	= (u_quad_t) ip->i_size;
220df8bae1dSRodney W. Grimes 	vap->va_type	= vp->v_type;
22194a8606fSDoug Rabson 	vap->va_filerev	= 0;
222df8bae1dSRodney W. Grimes 	return (0);
223df8bae1dSRodney W. Grimes }
224df8bae1dSRodney W. Grimes 
225df8bae1dSRodney W. Grimes /*
226cb2a8dffSSøren Schmidt  * Vnode op for ioctl.
227cb2a8dffSSøren Schmidt  */
228cb2a8dffSSøren Schmidt static int
229cb2a8dffSSøren Schmidt cd9660_ioctl(ap)
230cb2a8dffSSøren Schmidt 	struct vop_ioctl_args /* {
231cb2a8dffSSøren Schmidt 		struct vnode *a_vp;
232bc9d8a9aSPoul-Henning Kamp 		u_long  a_command;
233cb2a8dffSSøren Schmidt 		caddr_t  a_data;
234cb2a8dffSSøren Schmidt 		int  a_fflag;
235cb2a8dffSSøren Schmidt 		struct ucred *a_cred;
236b40ce416SJulian Elischer 		struct thread *a_td;
237cb2a8dffSSøren Schmidt 	} */ *ap;
238cb2a8dffSSøren Schmidt {
239cb2a8dffSSøren Schmidt 	struct vnode *vp = ap->a_vp;
240cb2a8dffSSøren Schmidt 	struct iso_node *ip = VTOI(vp);
241cb2a8dffSSøren Schmidt 
242cb2a8dffSSøren Schmidt 	switch (ap->a_command) {
243cb2a8dffSSøren Schmidt 
244cb2a8dffSSøren Schmidt 	case FIOGETLBA:
245cb2a8dffSSøren Schmidt 		*(int *)(ap->a_data) = ip->iso_start;
246cb2a8dffSSøren Schmidt 		return 0;
247cb2a8dffSSøren Schmidt 	default:
248cb2a8dffSSøren Schmidt 		return (ENOTTY);
249cb2a8dffSSøren Schmidt 	}
250cb2a8dffSSøren Schmidt }
251cb2a8dffSSøren Schmidt 
252cb2a8dffSSøren Schmidt /*
253df8bae1dSRodney W. Grimes  * Vnode op for reading.
254df8bae1dSRodney W. Grimes  */
255605e9724SPoul-Henning Kamp static int
256df8bae1dSRodney W. Grimes cd9660_read(ap)
257df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
258df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
259df8bae1dSRodney W. Grimes 		struct uio *a_uio;
260df8bae1dSRodney W. Grimes 		int a_ioflag;
261df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
262df8bae1dSRodney W. Grimes 	} */ *ap;
263df8bae1dSRodney W. Grimes {
264df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
2658994a245SDag-Erling Smørgrav 	struct uio *uio = ap->a_uio;
2668994a245SDag-Erling Smørgrav 	struct iso_node *ip = VTOI(vp);
2678994a245SDag-Erling Smørgrav 	struct iso_mnt *imp;
268df8bae1dSRodney W. Grimes 	struct buf *bp;
2691295d82eSGary Palmer 	daddr_t lbn, rablock;
270df8bae1dSRodney W. Grimes 	off_t diff;
271df8bae1dSRodney W. Grimes 	int rasize, error = 0;
27267ddfcafSMatthew Dillon 	int seqcount;
273df8bae1dSRodney W. Grimes 	long size, n, on;
274df8bae1dSRodney W. Grimes 
27567ddfcafSMatthew Dillon 	seqcount = ap->a_ioflag >> 16;
27667ddfcafSMatthew Dillon 
277df8bae1dSRodney W. Grimes 	if (uio->uio_resid == 0)
278df8bae1dSRodney W. Grimes 		return (0);
279df8bae1dSRodney W. Grimes 	if (uio->uio_offset < 0)
280df8bae1dSRodney W. Grimes 		return (EINVAL);
281996c772fSJohn Dyson 	ip->i_flag |= IN_ACCESS;
282df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
283df8bae1dSRodney W. Grimes 	do {
284996c772fSJohn Dyson 		lbn = lblkno(imp, uio->uio_offset);
285996c772fSJohn Dyson 		on = blkoff(imp, uio->uio_offset);
286996c772fSJohn Dyson 		n = min((u_int)(imp->logical_block_size - on),
287df8bae1dSRodney W. Grimes 			uio->uio_resid);
288df8bae1dSRodney W. Grimes 		diff = (off_t)ip->i_size - uio->uio_offset;
289df8bae1dSRodney W. Grimes 		if (diff <= 0)
290df8bae1dSRodney W. Grimes 			return (0);
291df8bae1dSRodney W. Grimes 		if (diff < n)
292df8bae1dSRodney W. Grimes 			n = diff;
293996c772fSJohn Dyson 		size = blksize(imp, ip, lbn);
294df8bae1dSRodney W. Grimes 		rablock = lbn + 1;
29581bca6ddSKATO Takenori 		if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
2965a5573fdSBruce Evans 			if (lblktosize(imp, rablock) < ip->i_size)
297996c772fSJohn Dyson 				error = cluster_read(vp, (off_t)ip->i_size,
2988b612c4bSJohn Dyson 					 lbn, size, NOCRED, uio->uio_resid,
2998b612c4bSJohn Dyson 					 (ap->a_ioflag >> 16), &bp);
300df8bae1dSRodney W. Grimes 			else
301df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
302df8bae1dSRodney W. Grimes 		} else {
30367ddfcafSMatthew Dillon 			if (seqcount > 1 &&
304996c772fSJohn Dyson 			    lblktosize(imp, rablock) < ip->i_size) {
305996c772fSJohn Dyson 				rasize = blksize(imp, ip, rablock);
306df8bae1dSRodney W. Grimes 				error = breadn(vp, lbn, size, &rablock,
307df8bae1dSRodney W. Grimes 					       &rasize, 1, NOCRED, &bp);
308df8bae1dSRodney W. Grimes 			} else
309df8bae1dSRodney W. Grimes 				error = bread(vp, lbn, size, NOCRED, &bp);
310df8bae1dSRodney W. Grimes 		}
311df8bae1dSRodney W. Grimes 		n = min(n, size - bp->b_resid);
312df8bae1dSRodney W. Grimes 		if (error) {
313df8bae1dSRodney W. Grimes 			brelse(bp);
314df8bae1dSRodney W. Grimes 			return (error);
315df8bae1dSRodney W. Grimes 		}
316df8bae1dSRodney W. Grimes 
317996c772fSJohn Dyson 		error = uiomove(bp->b_data + on, (int)n, uio);
318df8bae1dSRodney W. Grimes 		brelse(bp);
319df8bae1dSRodney W. Grimes 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
320df8bae1dSRodney W. Grimes 	return (error);
321df8bae1dSRodney W. Grimes }
322df8bae1dSRodney W. Grimes 
323df8bae1dSRodney W. Grimes /*
324df8bae1dSRodney W. Grimes  * Structure for reading directories
325df8bae1dSRodney W. Grimes  */
326df8bae1dSRodney W. Grimes struct isoreaddir {
327df8bae1dSRodney W. Grimes 	struct dirent saveent;
328df8bae1dSRodney W. Grimes 	struct dirent assocent;
329df8bae1dSRodney W. Grimes 	struct dirent current;
330df8bae1dSRodney W. Grimes 	off_t saveoff;
331df8bae1dSRodney W. Grimes 	off_t assocoff;
332df8bae1dSRodney W. Grimes 	off_t curroff;
333df8bae1dSRodney W. Grimes 	struct uio *uio;
334df8bae1dSRodney W. Grimes 	off_t uio_off;
335996c772fSJohn Dyson 	int eofflag;
336996c772fSJohn Dyson 	u_long *cookies;
337df8bae1dSRodney W. Grimes 	int ncookies;
338df8bae1dSRodney W. Grimes };
339df8bae1dSRodney W. Grimes 
34037c84183SPoul-Henning Kamp static int
341df8bae1dSRodney W. Grimes iso_uiodir(idp,dp,off)
342df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
343df8bae1dSRodney W. Grimes 	struct dirent *dp;
344df8bae1dSRodney W. Grimes 	off_t off;
345df8bae1dSRodney W. Grimes {
346df8bae1dSRodney W. Grimes 	int error;
347df8bae1dSRodney W. Grimes 
348df8bae1dSRodney W. Grimes 	dp->d_name[dp->d_namlen] = 0;
349c90607baSBruce Evans 	dp->d_reclen = GENERIC_DIRSIZ(dp);
350df8bae1dSRodney W. Grimes 
351df8bae1dSRodney W. Grimes 	if (idp->uio->uio_resid < dp->d_reclen) {
352996c772fSJohn Dyson 		idp->eofflag = 0;
353996c772fSJohn Dyson 		return (-1);
354df8bae1dSRodney W. Grimes 	}
355df8bae1dSRodney W. Grimes 
356996c772fSJohn Dyson 	if (idp->cookies) {
357df8bae1dSRodney W. Grimes 		if (idp->ncookies <= 0) {
358996c772fSJohn Dyson 			idp->eofflag = 0;
359996c772fSJohn Dyson 			return (-1);
360df8bae1dSRodney W. Grimes 		}
361df8bae1dSRodney W. Grimes 
362996c772fSJohn Dyson 		*idp->cookies++ = off;
363df8bae1dSRodney W. Grimes 		--idp->ncookies;
364df8bae1dSRodney W. Grimes 	}
365df8bae1dSRodney W. Grimes 
366c9524588SDag-Erling Smørgrav 	if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0)
367996c772fSJohn Dyson 		return (error);
368df8bae1dSRodney W. Grimes 	idp->uio_off = off;
369996c772fSJohn Dyson 	return (0);
370df8bae1dSRodney W. Grimes }
371df8bae1dSRodney W. Grimes 
37237c84183SPoul-Henning Kamp static int
373df8bae1dSRodney W. Grimes iso_shipdir(idp)
374df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
375df8bae1dSRodney W. Grimes {
376df8bae1dSRodney W. Grimes 	struct dirent *dp;
377df8bae1dSRodney W. Grimes 	int cl, sl, assoc;
378df8bae1dSRodney W. Grimes 	int error;
379df8bae1dSRodney W. Grimes 	char *cname, *sname;
380df8bae1dSRodney W. Grimes 
381df8bae1dSRodney W. Grimes 	cl = idp->current.d_namlen;
382df8bae1dSRodney W. Grimes 	cname = idp->current.d_name;
3831295d82eSGary Palmer assoc = (cl > 1) && (*cname == ASSOCCHAR);
3841295d82eSGary Palmer 	if (assoc) {
385df8bae1dSRodney W. Grimes 		cl--;
386df8bae1dSRodney W. Grimes 		cname++;
387df8bae1dSRodney W. Grimes 	}
388df8bae1dSRodney W. Grimes 
389df8bae1dSRodney W. Grimes 	dp = &idp->saveent;
390df8bae1dSRodney W. Grimes 	sname = dp->d_name;
391df8bae1dSRodney W. Grimes 	if (!(sl = dp->d_namlen)) {
392df8bae1dSRodney W. Grimes 		dp = &idp->assocent;
393df8bae1dSRodney W. Grimes 		sname = dp->d_name + 1;
394df8bae1dSRodney W. Grimes 		sl = dp->d_namlen - 1;
395df8bae1dSRodney W. Grimes 	}
396df8bae1dSRodney W. Grimes 	if (sl > 0) {
397df8bae1dSRodney W. Grimes 		if (sl != cl
398df8bae1dSRodney W. Grimes 		    || bcmp(sname,cname,sl)) {
399df8bae1dSRodney W. Grimes 			if (idp->assocent.d_namlen) {
400d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
401996c772fSJohn Dyson 					return (error);
402df8bae1dSRodney W. Grimes 				idp->assocent.d_namlen = 0;
403df8bae1dSRodney W. Grimes 			}
404df8bae1dSRodney W. Grimes 			if (idp->saveent.d_namlen) {
405d254af07SMatthew Dillon 				if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
406996c772fSJohn Dyson 					return (error);
407df8bae1dSRodney W. Grimes 				idp->saveent.d_namlen = 0;
408df8bae1dSRodney W. Grimes 			}
409df8bae1dSRodney W. Grimes 		}
410df8bae1dSRodney W. Grimes 	}
411c90607baSBruce Evans 	idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
412df8bae1dSRodney W. Grimes 	if (assoc) {
413df8bae1dSRodney W. Grimes 		idp->assocoff = idp->curroff;
414df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
415df8bae1dSRodney W. Grimes 	} else {
416df8bae1dSRodney W. Grimes 		idp->saveoff = idp->curroff;
417df8bae1dSRodney W. Grimes 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
418df8bae1dSRodney W. Grimes 	}
419996c772fSJohn Dyson 	return (0);
420df8bae1dSRodney W. Grimes }
421df8bae1dSRodney W. Grimes 
422df8bae1dSRodney W. Grimes /*
423df8bae1dSRodney W. Grimes  * Vnode op for readdir
424df8bae1dSRodney W. Grimes  */
425605e9724SPoul-Henning Kamp static int
426df8bae1dSRodney W. Grimes cd9660_readdir(ap)
427df8bae1dSRodney W. Grimes 	struct vop_readdir_args /* {
428df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
429df8bae1dSRodney W. Grimes 		struct uio *a_uio;
430df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
431996c772fSJohn Dyson 		int *a_eofflag;
432996c772fSJohn Dyson 		int *a_ncookies;
433996c772fSJohn Dyson 		u_long *a_cookies;
434df8bae1dSRodney W. Grimes 	} */ *ap;
435df8bae1dSRodney W. Grimes {
4368994a245SDag-Erling Smørgrav 	struct uio *uio = ap->a_uio;
437df8bae1dSRodney W. Grimes 	struct isoreaddir *idp;
438996c772fSJohn Dyson 	struct vnode *vdp = ap->a_vp;
439996c772fSJohn Dyson 	struct iso_node *dp;
440df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
441df8bae1dSRodney W. Grimes 	struct buf *bp = NULL;
442996c772fSJohn Dyson 	struct iso_directory_record *ep;
443996c772fSJohn Dyson 	int entryoffsetinblock;
444996c772fSJohn Dyson 	doff_t endsearch;
445996c772fSJohn Dyson 	u_long bmask;
446996c772fSJohn Dyson 	int error = 0;
447996c772fSJohn Dyson 	int reclen;
448996c772fSJohn Dyson 	u_short namelen;
4499abf4d6eSDoug Rabson 	int ncookies = 0;
450996c772fSJohn Dyson 	u_long *cookies = NULL;
451df8bae1dSRodney W. Grimes 
452996c772fSJohn Dyson 	dp = VTOI(vdp);
453996c772fSJohn Dyson 	imp = dp->i_mnt;
454996c772fSJohn Dyson 	bmask = imp->im_bmask;
455df8bae1dSRodney W. Grimes 
456a163d034SWarner Losh 	MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
457996c772fSJohn Dyson 	idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
458996c772fSJohn Dyson 	/*
459996c772fSJohn Dyson 	 * XXX
460996c772fSJohn Dyson 	 * Is it worth trying to figure out the type?
461996c772fSJohn Dyson 	 */
462996c772fSJohn Dyson 	idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
463996c772fSJohn Dyson 	    DT_UNKNOWN;
464df8bae1dSRodney W. Grimes 	idp->uio = uio;
465996c772fSJohn Dyson 	if (ap->a_ncookies == NULL) {
466996c772fSJohn Dyson 		idp->cookies = NULL;
467996c772fSJohn Dyson 	} else {
4689abf4d6eSDoug Rabson 		/*
4699abf4d6eSDoug Rabson 		 * Guess the number of cookies needed.
4709abf4d6eSDoug Rabson 		 */
4719abf4d6eSDoug Rabson 		ncookies = uio->uio_resid / 16;
472996c772fSJohn Dyson 		MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
473a163d034SWarner Losh 		    M_WAITOK);
474996c772fSJohn Dyson 		idp->cookies = cookies;
475df8bae1dSRodney W. Grimes 		idp->ncookies = ncookies;
476996c772fSJohn Dyson 	}
477996c772fSJohn Dyson 	idp->eofflag = 1;
478df8bae1dSRodney W. Grimes 	idp->curroff = uio->uio_offset;
479df8bae1dSRodney W. Grimes 
480996c772fSJohn Dyson 	if ((entryoffsetinblock = idp->curroff & bmask) &&
481cec0f20cSPoul-Henning Kamp 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
482df8bae1dSRodney W. Grimes 		FREE(idp, M_TEMP);
483df8bae1dSRodney W. Grimes 		return (error);
484df8bae1dSRodney W. Grimes 	}
485996c772fSJohn Dyson 	endsearch = dp->i_size;
486df8bae1dSRodney W. Grimes 
487df8bae1dSRodney W. Grimes 	while (idp->curroff < endsearch) {
488df8bae1dSRodney W. Grimes 		/*
489df8bae1dSRodney W. Grimes 		 * If offset is on a block boundary,
490df8bae1dSRodney W. Grimes 		 * read the next directory block.
491df8bae1dSRodney W. Grimes 		 * Release previous if it exists.
492df8bae1dSRodney W. Grimes 		 */
493996c772fSJohn Dyson 		if ((idp->curroff & bmask) == 0) {
494df8bae1dSRodney W. Grimes 			if (bp != NULL)
495df8bae1dSRodney W. Grimes 				brelse(bp);
496d254af07SMatthew Dillon 			if ((error =
497d254af07SMatthew Dillon 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
498df8bae1dSRodney W. Grimes 				break;
499df8bae1dSRodney W. Grimes 			entryoffsetinblock = 0;
500df8bae1dSRodney W. Grimes 		}
501df8bae1dSRodney W. Grimes 		/*
502df8bae1dSRodney W. Grimes 		 * Get pointer to next entry.
503df8bae1dSRodney W. Grimes 		 */
504df8bae1dSRodney W. Grimes 		ep = (struct iso_directory_record *)
505996c772fSJohn Dyson 			((char *)bp->b_data + entryoffsetinblock);
506df8bae1dSRodney W. Grimes 
507df8bae1dSRodney W. Grimes 		reclen = isonum_711(ep->length);
508df8bae1dSRodney W. Grimes 		if (reclen == 0) {
509df8bae1dSRodney W. Grimes 			/* skip to next block, if any */
510996c772fSJohn Dyson 			idp->curroff =
511996c772fSJohn Dyson 			    (idp->curroff & ~bmask) + imp->logical_block_size;
512df8bae1dSRodney W. Grimes 			continue;
513df8bae1dSRodney W. Grimes 		}
514df8bae1dSRodney W. Grimes 
515df8bae1dSRodney W. Grimes 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
516df8bae1dSRodney W. Grimes 			error = EINVAL;
517df8bae1dSRodney W. Grimes 			/* illegal entry, stop */
518df8bae1dSRodney W. Grimes 			break;
519df8bae1dSRodney W. Grimes 		}
520df8bae1dSRodney W. Grimes 
521df8bae1dSRodney W. Grimes 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
522df8bae1dSRodney W. Grimes 			error = EINVAL;
523df8bae1dSRodney W. Grimes 			/* illegal directory, so stop looking */
524df8bae1dSRodney W. Grimes 			break;
525df8bae1dSRodney W. Grimes 		}
526df8bae1dSRodney W. Grimes 
527996c772fSJohn Dyson 		idp->current.d_namlen = isonum_711(ep->name_len);
528996c772fSJohn Dyson 
529996c772fSJohn Dyson 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
53081ec856aSJoerg Wunsch 			error = EINVAL;
53181ec856aSJoerg Wunsch 			/* illegal entry, stop */
53281ec856aSJoerg Wunsch 			break;
53381ec856aSJoerg Wunsch 		}
53481ec856aSJoerg Wunsch 
535fba2e610SBruce Evans 		/*
536fba2e610SBruce Evans 		 * The "inode number" is iso_start, not i_ino, as in
537fba2e610SBruce Evans 		 * cd9660_getattr().
538fba2e610SBruce Evans 		 */
539fba2e610SBruce Evans 		idp->current.d_fileno = isonum_711(ep->ext_attr_length) +
540fba2e610SBruce Evans 		    isonum_733(ep->extent);
541df8bae1dSRodney W. Grimes 
542df8bae1dSRodney W. Grimes 		idp->curroff += reclen;
543996c772fSJohn Dyson 
544df8bae1dSRodney W. Grimes 		switch (imp->iso_ftype) {
545df8bae1dSRodney W. Grimes 		case ISO_FTYPE_RRIP:
546996c772fSJohn Dyson 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
547df8bae1dSRodney W. Grimes 					   &idp->current.d_fileno,imp);
548996c772fSJohn Dyson 			idp->current.d_namlen = (u_char)namelen;
549df8bae1dSRodney W. Grimes 			if (idp->current.d_namlen)
550df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
551df8bae1dSRodney W. Grimes 			break;
552988fa8efSJoerg Wunsch 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
553df8bae1dSRodney W. Grimes 			strcpy(idp->current.d_name,"..");
55444e568e2SDaniel C. Sobral 			if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
555df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 1;
556df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
55744e568e2SDaniel C. Sobral 			} else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
558df8bae1dSRodney W. Grimes 				idp->current.d_namlen = 2;
559df8bae1dSRodney W. Grimes 				error = iso_uiodir(idp,&idp->current,idp->curroff);
56044e568e2SDaniel C. Sobral 			} else {
561df8bae1dSRodney W. Grimes 				isofntrans(ep->name,idp->current.d_namlen,
562996c772fSJohn Dyson 					   idp->current.d_name, &namelen,
563df8bae1dSRodney W. Grimes 					   imp->iso_ftype == ISO_FTYPE_9660,
56444e568e2SDaniel C. Sobral 					   isonum_711(ep->flags)&4,
565c4f02a89SMax Khon 					   imp->joliet_level,
566c4f02a89SMax Khon 					   imp->im_flags,
567c4f02a89SMax Khon 					   imp->im_d2l);
568996c772fSJohn Dyson 				idp->current.d_namlen = (u_char)namelen;
569df8bae1dSRodney W. Grimes 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
570df8bae1dSRodney W. Grimes 					error = iso_shipdir(idp);
571df8bae1dSRodney W. Grimes 				else
572df8bae1dSRodney W. Grimes 					error = iso_uiodir(idp,&idp->current,idp->curroff);
573df8bae1dSRodney W. Grimes 			}
574df8bae1dSRodney W. Grimes 		}
575df8bae1dSRodney W. Grimes 		if (error)
576df8bae1dSRodney W. Grimes 			break;
577df8bae1dSRodney W. Grimes 
578df8bae1dSRodney W. Grimes 		entryoffsetinblock += reclen;
579df8bae1dSRodney W. Grimes 	}
580df8bae1dSRodney W. Grimes 
581df8bae1dSRodney W. Grimes 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
582df8bae1dSRodney W. Grimes 		idp->current.d_namlen = 0;
583df8bae1dSRodney W. Grimes 		error = iso_shipdir(idp);
584df8bae1dSRodney W. Grimes 	}
585df8bae1dSRodney W. Grimes 	if (error < 0)
586df8bae1dSRodney W. Grimes 		error = 0;
587df8bae1dSRodney W. Grimes 
5889abf4d6eSDoug Rabson 	if (ap->a_ncookies != NULL) {
5899abf4d6eSDoug Rabson 		if (error)
590996c772fSJohn Dyson 			free(cookies, M_TEMP);
5919abf4d6eSDoug Rabson 		else {
5929abf4d6eSDoug Rabson 			/*
5939abf4d6eSDoug Rabson 			 * Work out the number of cookies actually used.
5949abf4d6eSDoug Rabson 			 */
5959abf4d6eSDoug Rabson 			*ap->a_ncookies = ncookies - idp->ncookies;
5969abf4d6eSDoug Rabson 			*ap->a_cookies = cookies;
5979abf4d6eSDoug Rabson 		}
5989abf4d6eSDoug Rabson 	}
5999abf4d6eSDoug Rabson 
600df8bae1dSRodney W. Grimes 	if (bp)
601df8bae1dSRodney W. Grimes 		brelse (bp);
602df8bae1dSRodney W. Grimes 
603df8bae1dSRodney W. Grimes 	uio->uio_offset = idp->uio_off;
604996c772fSJohn Dyson 	*ap->a_eofflag = idp->eofflag;
605df8bae1dSRodney W. Grimes 
606df8bae1dSRodney W. Grimes 	FREE(idp, M_TEMP);
607df8bae1dSRodney W. Grimes 
608df8bae1dSRodney W. Grimes 	return (error);
609df8bae1dSRodney W. Grimes }
610df8bae1dSRodney W. Grimes 
611df8bae1dSRodney W. Grimes /*
612df8bae1dSRodney W. Grimes  * Return target name of a symbolic link
613df8bae1dSRodney W. Grimes  * Shouldn't we get the parent vnode and read the data from there?
614df8bae1dSRodney W. Grimes  * This could eventually result in deadlocks in cd9660_lookup.
615df8bae1dSRodney W. Grimes  * But otherwise the block read here is in the block buffer two times.
616df8bae1dSRodney W. Grimes  */
617df8bae1dSRodney W. Grimes typedef struct iso_directory_record ISODIR;
618df8bae1dSRodney W. Grimes typedef struct iso_node		    ISONODE;
619df8bae1dSRodney W. Grimes typedef struct iso_mnt		    ISOMNT;
620605e9724SPoul-Henning Kamp static int
621df8bae1dSRodney W. Grimes cd9660_readlink(ap)
622df8bae1dSRodney W. Grimes 	struct vop_readlink_args /* {
623df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
624df8bae1dSRodney W. Grimes 		struct uio *a_uio;
625df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
626df8bae1dSRodney W. Grimes 	} */ *ap;
627df8bae1dSRodney W. Grimes {
628df8bae1dSRodney W. Grimes 	ISONODE	*ip;
629df8bae1dSRodney W. Grimes 	ISODIR	*dirp;
630df8bae1dSRodney W. Grimes 	ISOMNT	*imp;
631df8bae1dSRodney W. Grimes 	struct	buf *bp;
632996c772fSJohn Dyson 	struct	uio *uio;
633df8bae1dSRodney W. Grimes 	u_short	symlen;
634df8bae1dSRodney W. Grimes 	int	error;
635df8bae1dSRodney W. Grimes 	char	*symname;
636df8bae1dSRodney W. Grimes 
637df8bae1dSRodney W. Grimes 	ip  = VTOI(ap->a_vp);
638df8bae1dSRodney W. Grimes 	imp = ip->i_mnt;
639996c772fSJohn Dyson 	uio = ap->a_uio;
640df8bae1dSRodney W. Grimes 
641df8bae1dSRodney W. Grimes 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
642996c772fSJohn Dyson 		return (EINVAL);
643df8bae1dSRodney W. Grimes 
644df8bae1dSRodney W. Grimes 	/*
645df8bae1dSRodney W. Grimes 	 * Get parents directory record block that this inode included.
646df8bae1dSRodney W. Grimes 	 */
647df8bae1dSRodney W. Grimes 	error = bread(imp->im_devvp,
648996c772fSJohn Dyson 		      (ip->i_number >> imp->im_bshift) <<
649996c772fSJohn Dyson 		      (imp->im_bshift - DEV_BSHIFT),
650996c772fSJohn Dyson 		      imp->logical_block_size, NOCRED, &bp);
651df8bae1dSRodney W. Grimes 	if (error) {
652df8bae1dSRodney W. Grimes 		brelse(bp);
653996c772fSJohn Dyson 		return (EINVAL);
654df8bae1dSRodney W. Grimes 	}
655df8bae1dSRodney W. Grimes 
656df8bae1dSRodney W. Grimes 	/*
657df8bae1dSRodney W. Grimes 	 * Setup the directory pointer for this inode
658df8bae1dSRodney W. Grimes 	 */
659996c772fSJohn Dyson 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
660df8bae1dSRodney W. Grimes 
661df8bae1dSRodney W. Grimes 	/*
662df8bae1dSRodney W. Grimes 	 * Just make sure, we have a right one....
663df8bae1dSRodney W. Grimes 	 *   1: Check not cross boundary on block
664df8bae1dSRodney W. Grimes 	 */
665df8bae1dSRodney W. Grimes 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
66692579404SAlexander Langer 	    > (unsigned)imp->logical_block_size) {
667df8bae1dSRodney W. Grimes 		brelse(bp);
668996c772fSJohn Dyson 		return (EINVAL);
669df8bae1dSRodney W. Grimes 	}
670df8bae1dSRodney W. Grimes 
671df8bae1dSRodney W. Grimes 	/*
672df8bae1dSRodney W. Grimes 	 * Now get a buffer
673df8bae1dSRodney W. Grimes 	 * Abuse a namei buffer for now.
674df8bae1dSRodney W. Grimes 	 */
675996c772fSJohn Dyson 	if (uio->uio_segflg == UIO_SYSSPACE)
676996c772fSJohn Dyson 		symname = uio->uio_iov->iov_base;
677996c772fSJohn Dyson 	else
678a163d034SWarner Losh 		symname = uma_zalloc(namei_zone, M_WAITOK);
679df8bae1dSRodney W. Grimes 
680df8bae1dSRodney W. Grimes 	/*
681df8bae1dSRodney W. Grimes 	 * Ok, we just gathering a symbolic name in SL record.
682df8bae1dSRodney W. Grimes 	 */
683df8bae1dSRodney W. Grimes 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
684996c772fSJohn Dyson 		if (uio->uio_segflg != UIO_SYSSPACE)
6852684b6afSJeff Roberson 			uma_zfree(namei_zone, symname);
686df8bae1dSRodney W. Grimes 		brelse(bp);
687996c772fSJohn Dyson 		return (EINVAL);
688df8bae1dSRodney W. Grimes 	}
689df8bae1dSRodney W. Grimes 	/*
690df8bae1dSRodney W. Grimes 	 * Don't forget before you leave from home ;-)
691df8bae1dSRodney W. Grimes 	 */
692df8bae1dSRodney W. Grimes 	brelse(bp);
693df8bae1dSRodney W. Grimes 
694df8bae1dSRodney W. Grimes 	/*
695df8bae1dSRodney W. Grimes 	 * return with the symbolic name to caller's.
696df8bae1dSRodney W. Grimes 	 */
697996c772fSJohn Dyson 	if (uio->uio_segflg != UIO_SYSSPACE) {
698996c772fSJohn Dyson 		error = uiomove(symname, symlen, uio);
6992684b6afSJeff Roberson 		uma_zfree(namei_zone, symname);
700996c772fSJohn Dyson 		return (error);
701996c772fSJohn Dyson 	}
702996c772fSJohn Dyson 	uio->uio_resid -= symlen;
7032b7f24d2SMike Barcroft 	uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
704996c772fSJohn Dyson 	uio->uio_iov->iov_len -= symlen;
705996c772fSJohn Dyson 	return (0);
706df8bae1dSRodney W. Grimes }
707df8bae1dSRodney W. Grimes 
708df8bae1dSRodney W. Grimes /*
709df8bae1dSRodney W. Grimes  * Calculate the logical to physical mapping if not done already,
710df8bae1dSRodney W. Grimes  * then call the device strategy routine.
711df8bae1dSRodney W. Grimes  */
712605e9724SPoul-Henning Kamp static int
713df8bae1dSRodney W. Grimes cd9660_strategy(ap)
714df8bae1dSRodney W. Grimes 	struct vop_strategy_args /* {
715fd5d1124SJulian Elischer 		struct buf *a_vp;
716df8bae1dSRodney W. Grimes 		struct buf *a_bp;
717df8bae1dSRodney W. Grimes 	} */ *ap;
718df8bae1dSRodney W. Grimes {
7198994a245SDag-Erling Smørgrav 	struct buf *bp = ap->a_bp;
7208994a245SDag-Erling Smørgrav 	struct vnode *vp = bp->b_vp;
7218994a245SDag-Erling Smørgrav 	struct iso_node *ip;
722df8bae1dSRodney W. Grimes 
723cefb5754SPoul-Henning Kamp 	KASSERT(ap->a_vp == ap->a_bp->b_vp, ("%s(%p != %p)",
724cefb5754SPoul-Henning Kamp 	    __func__, ap->a_vp, ap->a_bp->b_vp));
725df8bae1dSRodney W. Grimes 	ip = VTOI(vp);
726df8bae1dSRodney W. Grimes 	if (vp->v_type == VBLK || vp->v_type == VCHR)
727df8bae1dSRodney W. Grimes 		panic("cd9660_strategy: spec");
728df8bae1dSRodney W. Grimes 	if (bp->b_blkno == bp->b_lblkno) {
729e9d19a11SPoul-Henning Kamp 		bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
730e9d19a11SPoul-Henning Kamp 		    (ip->i_mnt->im_bshift - DEV_BSHIFT);
731e9d19a11SPoul-Henning Kamp 		if ((long)bp->b_blkno == -1)	/* XXX: cut&paste junk ? */
732df8bae1dSRodney W. Grimes 			clrbuf(bp);
733df8bae1dSRodney W. Grimes 	}
734e9d19a11SPoul-Henning Kamp 	if ((long)bp->b_blkno == -1) {	/* XXX: cut&paste junk ? */
7358177437dSPoul-Henning Kamp 		bufdone(bp);
736df8bae1dSRodney W. Grimes 		return (0);
737df8bae1dSRodney W. Grimes 	}
738df8bae1dSRodney W. Grimes 	vp = ip->i_devvp;
739df8bae1dSRodney W. Grimes 	bp->b_dev = vp->v_rdev;
7402c18019fSPoul-Henning Kamp 	bp->b_iooffset = dbtob(bp->b_blkno);
741f5b11b6eSPoul-Henning Kamp 	VOP_SPECSTRATEGY(vp, bp);
742df8bae1dSRodney W. Grimes 	return (0);
743df8bae1dSRodney W. Grimes }
744df8bae1dSRodney W. Grimes 
745df8bae1dSRodney W. Grimes /*
746996c772fSJohn Dyson  * Return POSIX pathconf information applicable to cd9660 filesystems.
747996c772fSJohn Dyson  */
748f041a9bdSPoul-Henning Kamp static int
749996c772fSJohn Dyson cd9660_pathconf(ap)
750996c772fSJohn Dyson 	struct vop_pathconf_args /* {
751996c772fSJohn Dyson 		struct vnode *a_vp;
752996c772fSJohn Dyson 		int a_name;
753996c772fSJohn Dyson 		register_t *a_retval;
754996c772fSJohn Dyson 	} */ *ap;
755996c772fSJohn Dyson {
756996c772fSJohn Dyson 
757996c772fSJohn Dyson 	switch (ap->a_name) {
758996c772fSJohn Dyson 	case _PC_LINK_MAX:
759996c772fSJohn Dyson 		*ap->a_retval = 1;
760996c772fSJohn Dyson 		return (0);
761996c772fSJohn Dyson 	case _PC_NAME_MAX:
762996c772fSJohn Dyson 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
763996c772fSJohn Dyson 			*ap->a_retval = NAME_MAX;
764996c772fSJohn Dyson 		else
765996c772fSJohn Dyson 			*ap->a_retval = 37;
766996c772fSJohn Dyson 		return (0);
767996c772fSJohn Dyson 	case _PC_PATH_MAX:
768996c772fSJohn Dyson 		*ap->a_retval = PATH_MAX;
769996c772fSJohn Dyson 		return (0);
770996c772fSJohn Dyson 	case _PC_PIPE_BUF:
771996c772fSJohn Dyson 		*ap->a_retval = PIPE_BUF;
772996c772fSJohn Dyson 		return (0);
773996c772fSJohn Dyson 	case _PC_CHOWN_RESTRICTED:
774996c772fSJohn Dyson 		*ap->a_retval = 1;
775996c772fSJohn Dyson 		return (0);
776996c772fSJohn Dyson 	case _PC_NO_TRUNC:
777996c772fSJohn Dyson 		*ap->a_retval = 1;
778996c772fSJohn Dyson 		return (0);
779996c772fSJohn Dyson 	default:
780996c772fSJohn Dyson 		return (EINVAL);
781996c772fSJohn Dyson 	}
782996c772fSJohn Dyson 	/* NOTREACHED */
783df8bae1dSRodney W. Grimes }
784df8bae1dSRodney W. Grimes 
785df8bae1dSRodney W. Grimes /*
786996c772fSJohn Dyson  * Global vfs data structures for cd9660
787df8bae1dSRodney W. Grimes  */
788f57e6547SBruce Evans vop_t **cd9660_vnodeop_p;
789f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
790dba3870cSPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
791539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
792539ef70cSPoul-Henning Kamp 	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
793539ef70cSPoul-Henning Kamp 	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
794539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
795539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
796cb2a8dffSSøren Schmidt 	{ &vop_ioctl_desc,		(vop_t *) cd9660_ioctl },
797539ef70cSPoul-Henning Kamp 	{ &vop_lookup_desc,		(vop_t *) vfs_cache_lookup },
798539ef70cSPoul-Henning Kamp 	{ &vop_pathconf_desc,		(vop_t *) cd9660_pathconf },
799539ef70cSPoul-Henning Kamp 	{ &vop_read_desc,		(vop_t *) cd9660_read },
800539ef70cSPoul-Henning Kamp 	{ &vop_readdir_desc,		(vop_t *) cd9660_readdir },
801539ef70cSPoul-Henning Kamp 	{ &vop_readlink_desc,		(vop_t *) cd9660_readlink },
802539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
803539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
804539ef70cSPoul-Henning Kamp 	{ &vop_strategy_desc,		(vop_t *) cd9660_strategy },
805f57e6547SBruce Evans 	{ NULL, NULL }
806df8bae1dSRodney W. Grimes };
807605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
808df8bae1dSRodney W. Grimes 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
809c901836cSGarrett Wollman VNODEOP_SET(cd9660_vnodeop_opv_desc);
810df8bae1dSRodney W. Grimes 
811df8bae1dSRodney W. Grimes /*
812df8bae1dSRodney W. Grimes  * Special device vnode ops
813df8bae1dSRodney W. Grimes  */
814f57e6547SBruce Evans vop_t **cd9660_specop_p;
815f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
816138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) spec_vnoperate },
817539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
818539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
819539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
820539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
821539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
822f57e6547SBruce Evans 	{ NULL, NULL }
823df8bae1dSRodney W. Grimes };
824605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_specop_opv_desc =
825df8bae1dSRodney W. Grimes 	{ &cd9660_specop_p, cd9660_specop_entries };
826c901836cSGarrett Wollman VNODEOP_SET(cd9660_specop_opv_desc);
827df8bae1dSRodney W. Grimes 
828f57e6547SBruce Evans vop_t **cd9660_fifoop_p;
829f041a9bdSPoul-Henning Kamp static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
830138ec1f7SPoul-Henning Kamp 	{ &vop_default_desc,		(vop_t *) fifo_vnoperate },
831539ef70cSPoul-Henning Kamp 	{ &vop_access_desc,		(vop_t *) cd9660_access },
832539ef70cSPoul-Henning Kamp 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
833539ef70cSPoul-Henning Kamp 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
834539ef70cSPoul-Henning Kamp 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
835539ef70cSPoul-Henning Kamp 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
836f57e6547SBruce Evans 	{ NULL, NULL }
837df8bae1dSRodney W. Grimes };
838605e9724SPoul-Henning Kamp static struct vnodeopv_desc cd9660_fifoop_opv_desc =
839df8bae1dSRodney W. Grimes 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
840c901836cSGarrett Wollman 
841c901836cSGarrett Wollman VNODEOP_SET(cd9660_fifoop_opv_desc);
842