xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision 6af83ee0d2941d18880b6aaa2b4facd1d30c6106)
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/stat.h>
45 #include <sys/bio.h>
46 #include <sys/buf.h>
47 #include <sys/mount.h>
48 #include <sys/vnode.h>
49 #include <fs/fifofs/fifo.h>
50 #include <sys/malloc.h>
51 #include <sys/dirent.h>
52 #include <sys/unistd.h>
53 #include <sys/filio.h>
54 
55 #include <vm/vm.h>
56 #include <vm/vnode_pager.h>
57 #include <vm/uma.h>
58 
59 #include <isofs/cd9660/iso.h>
60 #include <isofs/cd9660/cd9660_node.h>
61 #include <isofs/cd9660/iso_rrip.h>
62 
63 static vop_setattr_t	cd9660_setattr;
64 static vop_open_t	cd9660_open;
65 static vop_access_t	cd9660_access;
66 static vop_getattr_t	cd9660_getattr;
67 static vop_ioctl_t	cd9660_ioctl;
68 static vop_pathconf_t	cd9660_pathconf;
69 static vop_read_t	cd9660_read;
70 struct isoreaddir;
71 static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off);
72 static int iso_shipdir(struct isoreaddir *idp);
73 static vop_readdir_t	cd9660_readdir;
74 static vop_readlink_t	cd9660_readlink;
75 static vop_strategy_t	cd9660_strategy;
76 
77 /*
78  * Setattr call. Only allowed for block and character special devices.
79  */
80 static int
81 cd9660_setattr(ap)
82 	struct vop_setattr_args /* {
83 		struct vnodeop_desc *a_desc;
84 		struct vnode *a_vp;
85 		struct vattr *a_vap;
86 		struct ucred *a_cred;
87 		struct thread *a_td;
88 	} */ *ap;
89 {
90 	struct vnode *vp = ap->a_vp;
91 	struct vattr *vap = ap->a_vap;
92 
93 	if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
94 	    vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
95 	    vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
96 		return (EROFS);
97 	if (vap->va_size != (u_quad_t)VNOVAL) {
98 		switch (vp->v_type) {
99 		case VDIR:
100 			return (EISDIR);
101 		case VLNK:
102 		case VREG:
103 			return (EROFS);
104 		case VCHR:
105 		case VBLK:
106 		case VSOCK:
107 		case VFIFO:
108 		case VNON:
109 		case VBAD:
110 			return (0);
111 		}
112 	}
113 	return (0);
114 }
115 
116 /*
117  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
118  * The mode is shifted to select the owner/group/other fields. The
119  * super user is granted all permissions.
120  */
121 /* ARGSUSED */
122 static int
123 cd9660_access(ap)
124 	struct vop_access_args /* {
125 		struct vnode *a_vp;
126 		int  a_mode;
127 		struct ucred *a_cred;
128 		struct thread *a_td;
129 	} */ *ap;
130 {
131 	struct vnode *vp = ap->a_vp;
132 	struct iso_node *ip = VTOI(vp);
133 	mode_t mode = ap->a_mode;
134 
135 	if (vp->v_type == VCHR || vp->v_type == VBLK)
136 		return (EOPNOTSUPP);
137 
138 	/*
139 	 * Disallow write attempts unless the file is a socket,
140 	 * fifo, or a block or character device resident on the
141 	 * filesystem.
142 	 */
143 	if (mode & VWRITE) {
144 		switch (vp->v_type) {
145 		case VDIR:
146 		case VLNK:
147 		case VREG:
148 			return (EROFS);
149 			/* NOT REACHED */
150 		default:
151 			break;
152 		}
153 	}
154 
155 	return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
156 	    ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL));
157 }
158 
159 static int
160 cd9660_open(ap)
161 	struct vop_open_args /* {
162 		struct vnode *a_vp;
163 		int a_mode;
164 		struct ucred *a_cred;
165 		struct thread *a_td;
166 		int a_fdidx;
167 	} */ *ap;
168 {
169 	struct iso_node *ip = VTOI(ap->a_vp);
170 
171 	vnode_create_vobject(ap->a_vp, ip->i_size, ap->a_td);
172 	return 0;
173 }
174 
175 
176 static int
177 cd9660_getattr(ap)
178 	struct vop_getattr_args /* {
179 		struct vnode *a_vp;
180 		struct vattr *a_vap;
181 		struct ucred *a_cred;
182 		struct thread *a_td;
183 	} */ *ap;
184 
185 {
186 	struct vnode *vp = ap->a_vp;
187 	struct vattr *vap = ap->a_vap;
188 	struct iso_node *ip = VTOI(vp);
189 
190 	vap->va_fsid	= dev2udev(ip->i_dev);
191 	vap->va_fileid	= ip->i_number;
192 
193 	vap->va_mode	= ip->inode.iso_mode;
194 	vap->va_nlink	= ip->inode.iso_links;
195 	vap->va_uid	= ip->inode.iso_uid;
196 	vap->va_gid	= ip->inode.iso_gid;
197 	vap->va_atime	= ip->inode.iso_atime;
198 	vap->va_mtime	= ip->inode.iso_mtime;
199 	vap->va_ctime	= ip->inode.iso_ctime;
200 	vap->va_rdev	= ip->inode.iso_rdev;
201 
202 	vap->va_size	= (u_quad_t) ip->i_size;
203 	if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
204 		struct vop_readlink_args rdlnk;
205 		struct iovec aiov;
206 		struct uio auio;
207 		char *cp;
208 
209 		MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
210 		aiov.iov_base = cp;
211 		aiov.iov_len = MAXPATHLEN;
212 		auio.uio_iov = &aiov;
213 		auio.uio_iovcnt = 1;
214 		auio.uio_offset = 0;
215 		auio.uio_rw = UIO_READ;
216 		auio.uio_segflg = UIO_SYSSPACE;
217 		auio.uio_td = ap->a_td;
218 		auio.uio_resid = MAXPATHLEN;
219 		rdlnk.a_uio = &auio;
220 		rdlnk.a_vp = ap->a_vp;
221 		rdlnk.a_cred = ap->a_cred;
222 		if (cd9660_readlink(&rdlnk) == 0)
223 			vap->va_size = MAXPATHLEN - auio.uio_resid;
224 		FREE(cp, M_TEMP);
225 	}
226 	vap->va_flags	= 0;
227 	vap->va_gen = 1;
228 	vap->va_blocksize = ip->i_mnt->logical_block_size;
229 	vap->va_bytes	= (u_quad_t) ip->i_size;
230 	vap->va_type	= vp->v_type;
231 	vap->va_filerev	= 0;
232 	return (0);
233 }
234 
235 /*
236  * Vnode op for ioctl.
237  */
238 static int
239 cd9660_ioctl(ap)
240 	struct vop_ioctl_args /* {
241 		struct vnode *a_vp;
242 		u_long  a_command;
243 		caddr_t  a_data;
244 		int  a_fflag;
245 		struct ucred *a_cred;
246 		struct thread *a_td;
247 	} */ *ap;
248 {
249 	struct vnode *vp = ap->a_vp;
250 	struct iso_node *ip = VTOI(vp);
251 
252 	if (vp->v_type == VCHR || vp->v_type == VBLK)
253 		return (EOPNOTSUPP);
254 
255 	switch (ap->a_command) {
256 
257 	case FIOGETLBA:
258 		*(int *)(ap->a_data) = ip->iso_start;
259 		return 0;
260 	default:
261 		return (ENOTTY);
262 	}
263 }
264 
265 /*
266  * Vnode op for reading.
267  */
268 static int
269 cd9660_read(ap)
270 	struct vop_read_args /* {
271 		struct vnode *a_vp;
272 		struct uio *a_uio;
273 		int a_ioflag;
274 		struct ucred *a_cred;
275 	} */ *ap;
276 {
277 	struct vnode *vp = ap->a_vp;
278 	struct uio *uio = ap->a_uio;
279 	struct iso_node *ip = VTOI(vp);
280 	struct iso_mnt *imp;
281 	struct buf *bp;
282 	daddr_t lbn, rablock;
283 	off_t diff;
284 	int rasize, error = 0;
285 	int seqcount;
286 	long size, n, on;
287 
288 	if (vp->v_type == VCHR || vp->v_type == VBLK)
289 		return (EOPNOTSUPP);
290 
291 	seqcount = ap->a_ioflag >> IO_SEQSHIFT;
292 
293 	if (uio->uio_resid == 0)
294 		return (0);
295 	if (uio->uio_offset < 0)
296 		return (EINVAL);
297 	ip->i_flag |= IN_ACCESS;
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 	MALLOC(idp, struct isoreaddir *, 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 		MALLOC(cookies, u_long *, 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 
496 	if ((entryoffsetinblock = idp->curroff & bmask) &&
497 	    (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
498 		FREE(idp, M_TEMP);
499 		return (error);
500 	}
501 	endsearch = dp->i_size;
502 
503 	while (idp->curroff < endsearch) {
504 		/*
505 		 * If offset is on a block boundary,
506 		 * read the next directory block.
507 		 * Release previous if it exists.
508 		 */
509 		if ((idp->curroff & bmask) == 0) {
510 			if (bp != NULL)
511 				brelse(bp);
512 			if ((error =
513 			    cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
514 				break;
515 			entryoffsetinblock = 0;
516 		}
517 		/*
518 		 * Get pointer to next entry.
519 		 */
520 		ep = (struct iso_directory_record *)
521 			((char *)bp->b_data + entryoffsetinblock);
522 
523 		reclen = isonum_711(ep->length);
524 		if (reclen == 0) {
525 			/* skip to next block, if any */
526 			idp->curroff =
527 			    (idp->curroff & ~bmask) + imp->logical_block_size;
528 			continue;
529 		}
530 
531 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
532 			error = EINVAL;
533 			/* illegal entry, stop */
534 			break;
535 		}
536 
537 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
538 			error = EINVAL;
539 			/* illegal directory, so stop looking */
540 			break;
541 		}
542 
543 		idp->current.d_namlen = isonum_711(ep->name_len);
544 
545 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
546 			error = EINVAL;
547 			/* illegal entry, stop */
548 			break;
549 		}
550 
551 		if (isonum_711(ep->flags)&2)
552 			idp->current.d_fileno = isodirino(ep, imp);
553 		else
554 			idp->current.d_fileno = dbtob(bp->b_blkno) +
555 				entryoffsetinblock;
556 
557 		idp->curroff += reclen;
558 
559 		switch (imp->iso_ftype) {
560 		case ISO_FTYPE_RRIP:
561 			cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
562 					   &idp->current.d_fileno,imp);
563 			idp->current.d_namlen = (u_char)namelen;
564 			if (idp->current.d_namlen)
565 				error = iso_uiodir(idp,&idp->current,idp->curroff);
566 			break;
567 		default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
568 			strcpy(idp->current.d_name,"..");
569 			if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
570 				idp->current.d_namlen = 1;
571 				error = iso_uiodir(idp,&idp->current,idp->curroff);
572 			} else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
573 				idp->current.d_namlen = 2;
574 				error = iso_uiodir(idp,&idp->current,idp->curroff);
575 			} else {
576 				isofntrans(ep->name,idp->current.d_namlen,
577 					   idp->current.d_name, &namelen,
578 					   imp->iso_ftype == ISO_FTYPE_9660,
579 					   isonum_711(ep->flags)&4,
580 					   imp->joliet_level,
581 					   imp->im_flags,
582 					   imp->im_d2l);
583 				idp->current.d_namlen = (u_char)namelen;
584 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
585 					error = iso_shipdir(idp);
586 				else
587 					error = iso_uiodir(idp,&idp->current,idp->curroff);
588 			}
589 		}
590 		if (error)
591 			break;
592 
593 		entryoffsetinblock += reclen;
594 	}
595 
596 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
597 		idp->current.d_namlen = 0;
598 		error = iso_shipdir(idp);
599 	}
600 	if (error < 0)
601 		error = 0;
602 
603 	if (ap->a_ncookies != NULL) {
604 		if (error)
605 			free(cookies, M_TEMP);
606 		else {
607 			/*
608 			 * Work out the number of cookies actually used.
609 			 */
610 			*ap->a_ncookies = ncookies - idp->ncookies;
611 			*ap->a_cookies = cookies;
612 		}
613 	}
614 
615 	if (bp)
616 		brelse (bp);
617 
618 	uio->uio_offset = idp->uio_off;
619 	*ap->a_eofflag = idp->eofflag;
620 
621 	FREE(idp, M_TEMP);
622 
623 	return (error);
624 }
625 
626 /*
627  * Return target name of a symbolic link
628  * Shouldn't we get the parent vnode and read the data from there?
629  * This could eventually result in deadlocks in cd9660_lookup.
630  * But otherwise the block read here is in the block buffer two times.
631  */
632 typedef struct iso_directory_record ISODIR;
633 typedef struct iso_node		    ISONODE;
634 typedef struct iso_mnt		    ISOMNT;
635 static int
636 cd9660_readlink(ap)
637 	struct vop_readlink_args /* {
638 		struct vnode *a_vp;
639 		struct uio *a_uio;
640 		struct ucred *a_cred;
641 	} */ *ap;
642 {
643 	ISONODE	*ip;
644 	ISODIR	*dirp;
645 	ISOMNT	*imp;
646 	struct	buf *bp;
647 	struct	uio *uio;
648 	u_short	symlen;
649 	int	error;
650 	char	*symname;
651 
652 	ip  = VTOI(ap->a_vp);
653 	imp = ip->i_mnt;
654 	uio = ap->a_uio;
655 
656 	if (imp->iso_ftype != ISO_FTYPE_RRIP)
657 		return (EINVAL);
658 
659 	/*
660 	 * Get parents directory record block that this inode included.
661 	 */
662 	error = bread(imp->im_devvp,
663 		      (ip->i_number >> imp->im_bshift) <<
664 		      (imp->im_bshift - DEV_BSHIFT),
665 		      imp->logical_block_size, NOCRED, &bp);
666 	if (error) {
667 		brelse(bp);
668 		return (EINVAL);
669 	}
670 
671 	/*
672 	 * Setup the directory pointer for this inode
673 	 */
674 	dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
675 
676 	/*
677 	 * Just make sure, we have a right one....
678 	 *   1: Check not cross boundary on block
679 	 */
680 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
681 	    > (unsigned)imp->logical_block_size) {
682 		brelse(bp);
683 		return (EINVAL);
684 	}
685 
686 	/*
687 	 * Now get a buffer
688 	 * Abuse a namei buffer for now.
689 	 */
690 	if (uio->uio_segflg == UIO_SYSSPACE)
691 		symname = uio->uio_iov->iov_base;
692 	else
693 		symname = uma_zalloc(namei_zone, M_WAITOK);
694 
695 	/*
696 	 * Ok, we just gathering a symbolic name in SL record.
697 	 */
698 	if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
699 		if (uio->uio_segflg != UIO_SYSSPACE)
700 			uma_zfree(namei_zone, symname);
701 		brelse(bp);
702 		return (EINVAL);
703 	}
704 	/*
705 	 * Don't forget before you leave from home ;-)
706 	 */
707 	brelse(bp);
708 
709 	/*
710 	 * return with the symbolic name to caller's.
711 	 */
712 	if (uio->uio_segflg != UIO_SYSSPACE) {
713 		error = uiomove(symname, symlen, uio);
714 		uma_zfree(namei_zone, symname);
715 		return (error);
716 	}
717 	uio->uio_resid -= symlen;
718 	uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
719 	uio->uio_iov->iov_len -= symlen;
720 	return (0);
721 }
722 
723 /*
724  * Calculate the logical to physical mapping if not done already,
725  * then call the device strategy routine.
726  */
727 static int
728 cd9660_strategy(ap)
729 	struct vop_strategy_args /* {
730 		struct buf *a_vp;
731 		struct buf *a_bp;
732 	} */ *ap;
733 {
734 	struct buf *bp = ap->a_bp;
735 	struct vnode *vp = ap->a_vp;
736 	struct iso_node *ip;
737 	struct bufobj *bo;
738 
739 	ip = VTOI(vp);
740 	if (vp->v_type == VBLK || vp->v_type == VCHR)
741 		panic("cd9660_strategy: spec");
742 	if (bp->b_blkno == bp->b_lblkno) {
743 		bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
744 		    (ip->i_mnt->im_bshift - DEV_BSHIFT);
745 		if ((long)bp->b_blkno == -1)	/* XXX: cut&paste junk ? */
746 			clrbuf(bp);
747 	}
748 	if ((long)bp->b_blkno == -1) {	/* XXX: cut&paste junk ? */
749 		bufdone(bp);
750 		return (0);
751 	}
752 	bp->b_iooffset = dbtob(bp->b_blkno);
753 	bo = ip->i_mnt->im_bo;
754 	BO_STRATEGY(bo, bp);
755 	return (0);
756 }
757 
758 /*
759  * Return POSIX pathconf information applicable to cd9660 filesystems.
760  */
761 static int
762 cd9660_pathconf(ap)
763 	struct vop_pathconf_args /* {
764 		struct vnode *a_vp;
765 		int a_name;
766 		register_t *a_retval;
767 	} */ *ap;
768 {
769 
770 	switch (ap->a_name) {
771 	case _PC_LINK_MAX:
772 		*ap->a_retval = 1;
773 		return (0);
774 	case _PC_NAME_MAX:
775 		if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
776 			*ap->a_retval = NAME_MAX;
777 		else
778 			*ap->a_retval = 37;
779 		return (0);
780 	case _PC_PATH_MAX:
781 		*ap->a_retval = PATH_MAX;
782 		return (0);
783 	case _PC_PIPE_BUF:
784 		*ap->a_retval = PIPE_BUF;
785 		return (0);
786 	case _PC_CHOWN_RESTRICTED:
787 		*ap->a_retval = 1;
788 		return (0);
789 	case _PC_NO_TRUNC:
790 		*ap->a_retval = 1;
791 		return (0);
792 	default:
793 		return (EINVAL);
794 	}
795 	/* NOTREACHED */
796 }
797 
798 /*
799  * Global vfs data structures for cd9660
800  */
801 struct vop_vector cd9660_vnodeops = {
802 	.vop_default =		&default_vnodeops,
803 	.vop_open =		cd9660_open,
804 	.vop_access =		cd9660_access,
805 	.vop_bmap =		cd9660_bmap,
806 	.vop_cachedlookup =	cd9660_lookup,
807 	.vop_getattr =		cd9660_getattr,
808 	.vop_inactive =		cd9660_inactive,
809 	.vop_ioctl =		cd9660_ioctl,
810 	.vop_lookup =		vfs_cache_lookup,
811 	.vop_pathconf =		cd9660_pathconf,
812 	.vop_read =		cd9660_read,
813 	.vop_readdir =		cd9660_readdir,
814 	.vop_readlink =		cd9660_readlink,
815 	.vop_reclaim =		cd9660_reclaim,
816 	.vop_setattr =		cd9660_setattr,
817 	.vop_strategy =		cd9660_strategy,
818 };
819 
820 /*
821  * Special device vnode ops
822  */
823 
824 struct vop_vector cd9660_fifoops = {
825 	.vop_default =		&fifo_specops,
826 	.vop_access =		cd9660_access,
827 	.vop_getattr =		cd9660_getattr,
828 	.vop_inactive =		cd9660_inactive,
829 	.vop_reclaim =		cd9660_reclaim,
830 	.vop_setattr =		cd9660_setattr,
831 };
832