xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
1 /*-
2  * Copyright (c) 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley
6  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
7  * Support code is derived from software contributed to Berkeley
8  * by Atsushi Murai (amurai@spec.co.jp).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)cd9660_vnops.c	8.19 (Berkeley) 5/27/95
39  * $FreeBSD$
40  */
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/namei.h>
45 #include <sys/kernel.h>
46 #include <sys/stat.h>
47 #include <sys/bio.h>
48 #include <sys/buf.h>
49 #include <sys/mount.h>
50 #include <sys/vnode.h>
51 #include <miscfs/fifofs/fifo.h>
52 #include <sys/malloc.h>
53 #include <sys/dirent.h>
54 #include <sys/unistd.h>
55 #include <sys/filio.h>
56 
57 #include <vm/vm.h>
58 #include <vm/vm_zone.h>
59 #include <vm/vnode_pager.h>
60 
61 #include <isofs/cd9660/iso.h>
62 #include <isofs/cd9660/cd9660_node.h>
63 #include <isofs/cd9660/iso_rrip.h>
64 
65 static int cd9660_setattr __P((struct vop_setattr_args *));
66 static int cd9660_access __P((struct vop_access_args *));
67 static int cd9660_getattr __P((struct vop_getattr_args *));
68 static int cd9660_ioctl __P((struct vop_ioctl_args *));
69 static int cd9660_pathconf __P((struct vop_pathconf_args *));
70 static int cd9660_read __P((struct vop_read_args *));
71 struct isoreaddir;
72 static int iso_uiodir __P((struct isoreaddir *idp, struct dirent *dp,
73 			   off_t off));
74 static int iso_shipdir __P((struct isoreaddir *idp));
75 static int cd9660_readdir __P((struct vop_readdir_args *));
76 static int cd9660_readlink __P((struct vop_readlink_args *ap));
77 static int cd9660_strategy __P((struct vop_strategy_args *));
78 static int cd9660_print __P((struct vop_print_args *));
79 static int cd9660_getpages __P((struct vop_getpages_args *));
80 static int cd9660_putpages __P((struct vop_putpages_args *));
81 
82 /*
83  * Setattr call. Only allowed for block and character special devices.
84  */
85 int
86 cd9660_setattr(ap)
87 	struct vop_setattr_args /* {
88 		struct vnodeop_desc *a_desc;
89 		struct vnode *a_vp;
90 		struct vattr *a_vap;
91 		struct ucred *a_cred;
92 		struct proc *a_p;
93 	} */ *ap;
94 {
95 	struct vnode *vp = ap->a_vp;
96 	struct vattr *vap = ap->a_vap;
97 
98   	if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
99 	    vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
100 	    vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
101 		return (EROFS);
102 	if (vap->va_size != (u_quad_t)VNOVAL) {
103  		switch (vp->v_type) {
104  		case VDIR:
105  			return (EISDIR);
106 		case VLNK:
107 		case VREG:
108 			return (EROFS);
109  		case VCHR:
110  		case VBLK:
111  		case VSOCK:
112  		case VFIFO:
113 		case VNON:
114 		case VBAD:
115 			return (0);
116 		}
117 	}
118 	return (0);
119 }
120 
121 /*
122  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
123  * The mode is shifted to select the owner/group/other fields. The
124  * super user is granted all permissions.
125  */
126 /* ARGSUSED */
127 static int
128 cd9660_access(ap)
129 	struct vop_access_args /* {
130 		struct vnode *a_vp;
131 		int  a_mode;
132 		struct ucred *a_cred;
133 		struct proc *a_p;
134 	} */ *ap;
135 {
136 	struct vnode *vp = ap->a_vp;
137 	struct iso_node *ip = VTOI(vp);
138 	mode_t mode = ap->a_mode;
139 
140 	/*
141 	 * Disallow write attempts unless the file is a socket,
142 	 * fifo, or a block or character device resident on the
143 	 * file system.
144 	 */
145 	if (mode & VWRITE) {
146 		switch (vp->v_type) {
147 		case VDIR:
148 		case VLNK:
149 		case VREG:
150 			return (EROFS);
151 			/* NOT REACHED */
152 		default:
153 			break;
154 		}
155 	}
156 
157 	return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
158 	    ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL));
159 }
160 
161 static int
162 cd9660_getattr(ap)
163 	struct vop_getattr_args /* {
164 		struct vnode *a_vp;
165 		struct vattr *a_vap;
166 		struct ucred *a_cred;
167 		struct proc *a_p;
168 	} */ *ap;
169 
170 {
171 	struct vnode *vp = ap->a_vp;
172 	register struct vattr *vap = ap->a_vap;
173 	register struct iso_node *ip = VTOI(vp);
174 
175 	vap->va_fsid	= dev2udev(ip->i_dev);
176 	vap->va_fileid	= ip->i_number;
177 
178 	vap->va_mode	= ip->inode.iso_mode;
179 	vap->va_nlink	= ip->inode.iso_links;
180 	vap->va_uid	= ip->inode.iso_uid;
181 	vap->va_gid	= ip->inode.iso_gid;
182 	vap->va_atime	= ip->inode.iso_atime;
183 	vap->va_mtime	= ip->inode.iso_mtime;
184 	vap->va_ctime	= ip->inode.iso_ctime;
185 	vap->va_rdev	= ip->inode.iso_rdev;
186 
187 	vap->va_size	= (u_quad_t) ip->i_size;
188 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
189 		struct vop_readlink_args rdlnk;
190 		struct iovec aiov;
191 		struct uio auio;
192 		char *cp;
193 
194 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
195 		aiov.iov_base = cp;
196 		aiov.iov_len = MAXPATHLEN;
197 		auio.uio_iov = &aiov;
198 		auio.uio_iovcnt = 1;
199 		auio.uio_offset = 0;
200 		auio.uio_rw = UIO_READ;
201 		auio.uio_segflg = UIO_SYSSPACE;
202 		auio.uio_procp = ap->a_p;
203 		auio.uio_resid = MAXPATHLEN;
204 		rdlnk.a_uio = &auio;
205 		rdlnk.a_vp = ap->a_vp;
206 		rdlnk.a_cred = ap->a_cred;
207 		if (cd9660_readlink(&rdlnk) == 0)
208 			vap->va_size = MAXPATHLEN - auio.uio_resid;
209 		FREE(cp, M_TEMP);
210 	}
211 	vap->va_flags	= 0;
212 	vap->va_gen = 1;
213 	vap->va_blocksize = ip->i_mnt->logical_block_size;
214 	vap->va_bytes	= (u_quad_t) ip->i_size;
215 	vap->va_type	= vp->v_type;
216 	vap->va_filerev	= 0;
217 	return (0);
218 }
219 
220 /*
221  * Vnode op for ioctl.
222  */
223 static int
224 cd9660_ioctl(ap)
225 	struct vop_ioctl_args /* {
226 		struct vnode *a_vp;
227 		int  a_command;
228 		caddr_t  a_data;
229 		int  a_fflag;
230 		struct ucred *a_cred;
231 		struct proc *a_p;
232 	} */ *ap;
233 {
234 	struct vnode *vp = ap->a_vp;
235 	struct iso_node *ip = VTOI(vp);
236 
237         switch (ap->a_command) {
238 
239         case FIOGETLBA:
240 		*(int *)(ap->a_data) = ip->iso_start;
241 		return 0;
242         default:
243                 return (ENOTTY);
244         }
245 }
246 
247 /*
248  * Vnode op for reading.
249  */
250 static int
251 cd9660_read(ap)
252 	struct vop_read_args /* {
253 		struct vnode *a_vp;
254 		struct uio *a_uio;
255 		int a_ioflag;
256 		struct ucred *a_cred;
257 	} */ *ap;
258 {
259 	struct vnode *vp = ap->a_vp;
260 	register struct uio *uio = ap->a_uio;
261 	register struct iso_node *ip = VTOI(vp);
262 	register struct iso_mnt *imp;
263 	struct buf *bp;
264 	daddr_t lbn, rablock;
265 	off_t diff;
266 	int rasize, error = 0;
267 	int seqcount;
268 	long size, n, on;
269 
270 	seqcount = ap->a_ioflag >> 16;
271 
272 	if (uio->uio_resid == 0)
273 		return (0);
274 	if (uio->uio_offset < 0)
275 		return (EINVAL);
276 	ip->i_flag |= IN_ACCESS;
277 	imp = ip->i_mnt;
278 	do {
279 		lbn = lblkno(imp, uio->uio_offset);
280 		on = blkoff(imp, uio->uio_offset);
281 		n = min((u_int)(imp->logical_block_size - on),
282 			uio->uio_resid);
283 		diff = (off_t)ip->i_size - uio->uio_offset;
284 		if (diff <= 0)
285 			return (0);
286 		if (diff < n)
287 			n = diff;
288 		size = blksize(imp, ip, lbn);
289 		rablock = lbn + 1;
290 		if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
291 			if (lblktosize(imp, rablock) < ip->i_size)
292 				error = cluster_read(vp, (off_t)ip->i_size,
293 				         lbn, size, NOCRED, uio->uio_resid,
294 					 (ap->a_ioflag >> 16), &bp);
295 			else
296 				error = bread(vp, lbn, size, NOCRED, &bp);
297 		} else {
298 			if (seqcount > 1 &&
299 			    lblktosize(imp, rablock) < ip->i_size) {
300 				rasize = blksize(imp, ip, rablock);
301 				error = breadn(vp, lbn, size, &rablock,
302 					       &rasize, 1, NOCRED, &bp);
303 			} else
304 				error = bread(vp, lbn, size, NOCRED, &bp);
305 		}
306 		n = min(n, size - bp->b_resid);
307 		if (error) {
308 			brelse(bp);
309 			return (error);
310 		}
311 
312 		error = uiomove(bp->b_data + on, (int)n, uio);
313 		brelse(bp);
314 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
315 	return (error);
316 }
317 
318 /*
319  * Structure for reading directories
320  */
321 struct isoreaddir {
322 	struct dirent saveent;
323 	struct dirent assocent;
324 	struct dirent current;
325 	off_t saveoff;
326 	off_t assocoff;
327 	off_t curroff;
328 	struct uio *uio;
329 	off_t uio_off;
330 	int eofflag;
331 	u_long *cookies;
332 	int ncookies;
333 };
334 
335 int
336 iso_uiodir(idp,dp,off)
337 	struct isoreaddir *idp;
338 	struct dirent *dp;
339 	off_t off;
340 {
341 	int error;
342 
343 	dp->d_name[dp->d_namlen] = 0;
344 	dp->d_reclen = GENERIC_DIRSIZ(dp);
345 
346 	if (idp->uio->uio_resid < dp->d_reclen) {
347 		idp->eofflag = 0;
348 		return (-1);
349 	}
350 
351 	if (idp->cookies) {
352 		if (idp->ncookies <= 0) {
353 			idp->eofflag = 0;
354 			return (-1);
355 		}
356 
357 		*idp->cookies++ = off;
358 		--idp->ncookies;
359 	}
360 
361 	if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0)
362 		return (error);
363 	idp->uio_off = off;
364 	return (0);
365 }
366 
367 int
368 iso_shipdir(idp)
369 	struct isoreaddir *idp;
370 {
371 	struct dirent *dp;
372 	int cl, sl, assoc;
373 	int error;
374 	char *cname, *sname;
375 
376 	cl = idp->current.d_namlen;
377 	cname = idp->current.d_name;
378 assoc = (cl > 1) && (*cname == ASSOCCHAR);
379 	if (assoc) {
380 		cl--;
381 		cname++;
382 	}
383 
384 	dp = &idp->saveent;
385 	sname = dp->d_name;
386 	if (!(sl = dp->d_namlen)) {
387 		dp = &idp->assocent;
388 		sname = dp->d_name + 1;
389 		sl = dp->d_namlen - 1;
390 	}
391 	if (sl > 0) {
392 		if (sl != cl
393 		    || bcmp(sname,cname,sl)) {
394 			if (idp->assocent.d_namlen) {
395 				if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
396 					return (error);
397 				idp->assocent.d_namlen = 0;
398 			}
399 			if (idp->saveent.d_namlen) {
400 				if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
401 					return (error);
402 				idp->saveent.d_namlen = 0;
403 			}
404 		}
405 	}
406 	idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
407 	if (assoc) {
408 		idp->assocoff = idp->curroff;
409 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
410 	} else {
411 		idp->saveoff = idp->curroff;
412 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
413 	}
414 	return (0);
415 }
416 
417 /*
418  * Vnode op for readdir
419  */
420 static int
421 cd9660_readdir(ap)
422 	struct vop_readdir_args /* {
423 		struct vnode *a_vp;
424 		struct uio *a_uio;
425 		struct ucred *a_cred;
426 		int *a_eofflag;
427 		int *a_ncookies;
428 		u_long *a_cookies;
429 	} */ *ap;
430 {
431 	register struct uio *uio = ap->a_uio;
432 	struct isoreaddir *idp;
433 	struct vnode *vdp = ap->a_vp;
434 	struct iso_node *dp;
435 	struct iso_mnt *imp;
436 	struct buf *bp = NULL;
437 	struct iso_directory_record *ep;
438 	int entryoffsetinblock;
439 	doff_t endsearch;
440 	u_long bmask;
441 	int error = 0;
442 	int reclen;
443 	u_short namelen;
444 	int ncookies = 0;
445 	u_long *cookies = NULL;
446 
447 	dp = VTOI(vdp);
448 	imp = dp->i_mnt;
449 	bmask = imp->im_bmask;
450 
451 	MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
452 	idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
453 	/*
454 	 * XXX
455 	 * Is it worth trying to figure out the type?
456 	 */
457 	idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
458 	    DT_UNKNOWN;
459 	idp->uio = uio;
460 	if (ap->a_ncookies == NULL) {
461 		idp->cookies = NULL;
462 	} else {
463 		/*
464 		 * Guess the number of cookies needed.
465 		 */
466 		ncookies = uio->uio_resid / 16;
467 		MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
468 		    M_WAITOK);
469 		idp->cookies = cookies;
470 		idp->ncookies = ncookies;
471 	}
472 	idp->eofflag = 1;
473 	idp->curroff = uio->uio_offset;
474 
475 	if ((entryoffsetinblock = idp->curroff & bmask) &&
476 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
477 		FREE(idp, M_TEMP);
478 		return (error);
479 	}
480 	endsearch = dp->i_size;
481 
482 	while (idp->curroff < endsearch) {
483 		/*
484 		 * If offset is on a block boundary,
485 		 * read the next directory block.
486 		 * Release previous if it exists.
487 		 */
488 		if ((idp->curroff & bmask) == 0) {
489 			if (bp != NULL)
490 				brelse(bp);
491 			if ((error =
492 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
493 				break;
494 			entryoffsetinblock = 0;
495 		}
496 		/*
497 		 * Get pointer to next entry.
498 		 */
499 		ep = (struct iso_directory_record *)
500 			((char *)bp->b_data + entryoffsetinblock);
501 
502 		reclen = isonum_711(ep->length);
503 		if (reclen == 0) {
504 			/* skip to next block, if any */
505 			idp->curroff =
506 			    (idp->curroff & ~bmask) + imp->logical_block_size;
507 			continue;
508 		}
509 
510 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
511 			error = EINVAL;
512 			/* illegal entry, stop */
513 			break;
514 		}
515 
516 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
517 			error = EINVAL;
518 			/* illegal directory, so stop looking */
519 			break;
520 		}
521 
522 		idp->current.d_namlen = isonum_711(ep->name_len);
523 
524 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
525 			error = EINVAL;
526 			/* illegal entry, stop */
527 			break;
528 		}
529 
530 		if (isonum_711(ep->flags)&2)
531 			idp->current.d_fileno = isodirino(ep, imp);
532 		else
533 			idp->current.d_fileno = dbtob(bp->b_blkno) +
534 				entryoffsetinblock;
535 
536 		idp->curroff += reclen;
537 
538 		switch (imp->iso_ftype) {
539 		case ISO_FTYPE_RRIP:
540 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
541 					   &idp->current.d_fileno,imp);
542 			idp->current.d_namlen = (u_char)namelen;
543 			if (idp->current.d_namlen)
544 				error = iso_uiodir(idp,&idp->current,idp->curroff);
545 			break;
546 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
547 			strcpy(idp->current.d_name,"..");
548 			if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
549 				idp->current.d_namlen = 1;
550 				error = iso_uiodir(idp,&idp->current,idp->curroff);
551 			} else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
552 				idp->current.d_namlen = 2;
553 				error = iso_uiodir(idp,&idp->current,idp->curroff);
554 			} else {
555 				isofntrans(ep->name,idp->current.d_namlen,
556 					   idp->current.d_name, &namelen,
557 					   imp->iso_ftype == ISO_FTYPE_9660,
558 					   isonum_711(ep->flags)&4,
559 					   imp->joliet_level);
560 				idp->current.d_namlen = (u_char)namelen;
561 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
562 					error = iso_shipdir(idp);
563 				else
564 					error = iso_uiodir(idp,&idp->current,idp->curroff);
565 			}
566 		}
567 		if (error)
568 			break;
569 
570 		entryoffsetinblock += reclen;
571 	}
572 
573 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
574 		idp->current.d_namlen = 0;
575 		error = iso_shipdir(idp);
576 	}
577 	if (error < 0)
578 		error = 0;
579 
580 	if (ap->a_ncookies != NULL) {
581 		if (error)
582 			free(cookies, M_TEMP);
583 		else {
584 			/*
585 			 * Work out the number of cookies actually used.
586 			 */
587 			*ap->a_ncookies = ncookies - idp->ncookies;
588 			*ap->a_cookies = cookies;
589 		}
590 	}
591 
592 	if (bp)
593 		brelse (bp);
594 
595 	uio->uio_offset = idp->uio_off;
596 	*ap->a_eofflag = idp->eofflag;
597 
598 	FREE(idp, M_TEMP);
599 
600 	return (error);
601 }
602 
603 /*
604  * Return target name of a symbolic link
605  * Shouldn't we get the parent vnode and read the data from there?
606  * This could eventually result in deadlocks in cd9660_lookup.
607  * But otherwise the block read here is in the block buffer two times.
608  */
609 typedef struct iso_directory_record ISODIR;
610 typedef struct iso_node		    ISONODE;
611 typedef struct iso_mnt		    ISOMNT;
612 static int
613 cd9660_readlink(ap)
614 	struct vop_readlink_args /* {
615 		struct vnode *a_vp;
616 		struct uio *a_uio;
617 		struct ucred *a_cred;
618 	} */ *ap;
619 {
620 	ISONODE	*ip;
621 	ISODIR	*dirp;
622 	ISOMNT	*imp;
623 	struct	buf *bp;
624 	struct	uio *uio;
625 	u_short	symlen;
626 	int	error;
627 	char	*symname;
628 
629 	ip  = VTOI(ap->a_vp);
630 	imp = ip->i_mnt;
631 	uio = ap->a_uio;
632 
633 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
634 		return (EINVAL);
635 
636 	/*
637 	 * Get parents directory record block that this inode included.
638 	 */
639 	error = bread(imp->im_devvp,
640 		      (ip->i_number >> imp->im_bshift) <<
641 		      (imp->im_bshift - DEV_BSHIFT),
642 		      imp->logical_block_size, NOCRED, &bp);
643 	if (error) {
644 		brelse(bp);
645 		return (EINVAL);
646 	}
647 
648 	/*
649 	 * Setup the directory pointer for this inode
650 	 */
651 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
652 
653 	/*
654 	 * Just make sure, we have a right one....
655 	 *   1: Check not cross boundary on block
656 	 */
657 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
658 	    > (unsigned)imp->logical_block_size) {
659 		brelse(bp);
660 		return (EINVAL);
661 	}
662 
663 	/*
664 	 * Now get a buffer
665 	 * Abuse a namei buffer for now.
666 	 */
667 	if (uio->uio_segflg == UIO_SYSSPACE)
668 		symname = uio->uio_iov->iov_base;
669 	else
670 		symname = zalloc(namei_zone);
671 
672 	/*
673 	 * Ok, we just gathering a symbolic name in SL record.
674 	 */
675 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
676 		if (uio->uio_segflg != UIO_SYSSPACE)
677 			zfree(namei_zone, symname);
678 		brelse(bp);
679 		return (EINVAL);
680 	}
681 	/*
682 	 * Don't forget before you leave from home ;-)
683 	 */
684 	brelse(bp);
685 
686 	/*
687 	 * return with the symbolic name to caller's.
688 	 */
689 	if (uio->uio_segflg != UIO_SYSSPACE) {
690 		error = uiomove(symname, symlen, uio);
691 		zfree(namei_zone, symname);
692 		return (error);
693 	}
694 	uio->uio_resid -= symlen;
695 	uio->uio_iov->iov_base += symlen;
696 	uio->uio_iov->iov_len -= symlen;
697 	return (0);
698 }
699 
700 /*
701  * Calculate the logical to physical mapping if not done already,
702  * then call the device strategy routine.
703  */
704 static int
705 cd9660_strategy(ap)
706 	struct vop_strategy_args /* {
707 		struct buf *a_vp;
708 		struct buf *a_bp;
709 	} */ *ap;
710 {
711 	register struct buf *bp = ap->a_bp;
712 	register struct vnode *vp = bp->b_vp;
713 	register struct iso_node *ip;
714 	int error;
715 
716 	ip = VTOI(vp);
717 	if (vp->v_type == VBLK || vp->v_type == VCHR)
718 		panic("cd9660_strategy: spec");
719 	if (bp->b_blkno == bp->b_lblkno) {
720 		if ((error =
721 		    VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL))) {
722 			bp->b_error = error;
723 			bp->b_ioflags |= BIO_ERROR;
724 			bufdone(bp);
725 			return (error);
726 		}
727 		if ((long)bp->b_blkno == -1)
728 			clrbuf(bp);
729 	}
730 	if ((long)bp->b_blkno == -1) {
731 		bufdone(bp);
732 		return (0);
733 	}
734 	vp = ip->i_devvp;
735 	bp->b_dev = vp->v_rdev;
736 	VOP_STRATEGY(vp, bp);
737 	return (0);
738 }
739 
740 /*
741  * Print out the contents of an inode.
742  */
743 static int
744 cd9660_print(ap)
745 	struct vop_print_args /* {
746 		struct vnode *a_vp;
747 	} */ *ap;
748 {
749 
750 	printf("tag VT_ISOFS, isofs vnode\n");
751 	return (0);
752 }
753 
754 /*
755  * Return POSIX pathconf information applicable to cd9660 filesystems.
756  */
757 static int
758 cd9660_pathconf(ap)
759 	struct vop_pathconf_args /* {
760 		struct vnode *a_vp;
761 		int a_name;
762 		register_t *a_retval;
763 	} */ *ap;
764 {
765 
766 	switch (ap->a_name) {
767 	case _PC_LINK_MAX:
768 		*ap->a_retval = 1;
769 		return (0);
770 	case _PC_NAME_MAX:
771 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
772 			*ap->a_retval = NAME_MAX;
773 		else
774 			*ap->a_retval = 37;
775 		return (0);
776 	case _PC_PATH_MAX:
777 		*ap->a_retval = PATH_MAX;
778 		return (0);
779 	case _PC_PIPE_BUF:
780 		*ap->a_retval = PIPE_BUF;
781 		return (0);
782 	case _PC_CHOWN_RESTRICTED:
783 		*ap->a_retval = 1;
784 		return (0);
785 	case _PC_NO_TRUNC:
786 		*ap->a_retval = 1;
787 		return (0);
788 	default:
789 		return (EINVAL);
790 	}
791 	/* NOTREACHED */
792 }
793 
794 /*
795  * get page routine
796  *
797  * XXX By default, wimp out... note that a_offset is ignored (and always
798  * XXX has been).
799  */
800 int
801 cd9660_getpages(ap)
802 	struct vop_getpages_args *ap;
803 {
804 	return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
805 		ap->a_reqpage);
806 }
807 
808 /*
809  * put page routine
810  *
811  * XXX By default, wimp out... note that a_offset is ignored (and always
812  * XXX has been).
813  */
814 int
815 cd9660_putpages(ap)
816 	struct vop_putpages_args *ap;
817 {
818 	return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
819 		ap->a_sync, ap->a_rtvals);
820 }
821 
822 /*
823  * Global vfs data structures for cd9660
824  */
825 vop_t **cd9660_vnodeop_p;
826 static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
827 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
828 	{ &vop_access_desc,		(vop_t *) cd9660_access },
829 	{ &vop_bmap_desc,		(vop_t *) cd9660_bmap },
830 	{ &vop_cachedlookup_desc,	(vop_t *) cd9660_lookup },
831 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
832 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
833 	{ &vop_ioctl_desc,		(vop_t *) cd9660_ioctl },
834 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
835 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
836 	{ &vop_lookup_desc,		(vop_t *) vfs_cache_lookup },
837 	{ &vop_pathconf_desc,		(vop_t *) cd9660_pathconf },
838 	{ &vop_print_desc,		(vop_t *) cd9660_print },
839 	{ &vop_read_desc,		(vop_t *) cd9660_read },
840 	{ &vop_readdir_desc,		(vop_t *) cd9660_readdir },
841 	{ &vop_readlink_desc,		(vop_t *) cd9660_readlink },
842 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
843 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
844 	{ &vop_strategy_desc,		(vop_t *) cd9660_strategy },
845 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
846 	{ &vop_getpages_desc,		(vop_t *) cd9660_getpages },
847 	{ &vop_putpages_desc,		(vop_t *) cd9660_putpages },
848 	{ NULL, NULL }
849 };
850 static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
851 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
852 VNODEOP_SET(cd9660_vnodeop_opv_desc);
853 
854 /*
855  * Special device vnode ops
856  */
857 vop_t **cd9660_specop_p;
858 static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
859 	{ &vop_default_desc,		(vop_t *) spec_vnoperate },
860 	{ &vop_access_desc,		(vop_t *) cd9660_access },
861 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
862 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
863 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
864 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
865 	{ &vop_print_desc,		(vop_t *) cd9660_print },
866 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
867 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
868 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
869 	{ NULL, NULL }
870 };
871 static struct vnodeopv_desc cd9660_specop_opv_desc =
872 	{ &cd9660_specop_p, cd9660_specop_entries };
873 VNODEOP_SET(cd9660_specop_opv_desc);
874 
875 vop_t **cd9660_fifoop_p;
876 static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
877 	{ &vop_default_desc,		(vop_t *) fifo_vnoperate },
878 	{ &vop_access_desc,		(vop_t *) cd9660_access },
879 	{ &vop_getattr_desc,		(vop_t *) cd9660_getattr },
880 	{ &vop_inactive_desc,		(vop_t *) cd9660_inactive },
881 	{ &vop_islocked_desc,		(vop_t *) vop_stdislocked },
882 	{ &vop_lock_desc,		(vop_t *) vop_stdlock },
883 	{ &vop_print_desc,		(vop_t *) cd9660_print },
884 	{ &vop_reclaim_desc,		(vop_t *) cd9660_reclaim },
885 	{ &vop_setattr_desc,		(vop_t *) cd9660_setattr },
886 	{ &vop_unlock_desc,		(vop_t *) vop_stdunlock },
887 	{ NULL, NULL }
888 };
889 static struct vnodeopv_desc cd9660_fifoop_opv_desc =
890 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
891 
892 VNODEOP_SET(cd9660_fifoop_opv_desc);
893