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