xref: /freebsd/sys/fs/cd9660/cd9660_vnops.c (revision afe61c15161c324a7af299a9b8457aba5afc92db)
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.3 (Berkeley) 1/23/94
39  */
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/namei.h>
44 #include <sys/resourcevar.h>
45 #include <sys/kernel.h>
46 #include <sys/file.h>
47 #include <sys/stat.h>
48 #include <sys/buf.h>
49 #include <sys/proc.h>
50 #include <sys/conf.h>
51 #include <sys/mount.h>
52 #include <sys/vnode.h>
53 #include <miscfs/specfs/specdev.h>
54 #include <miscfs/fifofs/fifo.h>
55 #include <sys/malloc.h>
56 #include <sys/dir.h>
57 
58 #include <isofs/cd9660/iso.h>
59 #include <isofs/cd9660/cd9660_node.h>
60 #include <isofs/cd9660/iso_rrip.h>
61 
62 #if 0
63 /*
64  * Mknod vnode call
65  *  Actually remap the device number
66  */
67 cd9660_mknod(ndp, vap, cred, p)
68 	struct nameidata *ndp;
69 	struct ucred *cred;
70 	struct vattr *vap;
71 	struct proc *p;
72 {
73 #ifndef	ISODEVMAP
74 	free(ndp->ni_pnbuf, M_NAMEI);
75 	vput(ndp->ni_dvp);
76 	vput(ndp->ni_vp);
77 	return EINVAL;
78 #else
79 	register struct vnode *vp;
80 	struct iso_node *ip;
81 	struct iso_dnode *dp;
82 	int error;
83 
84 	vp = ndp->ni_vp;
85 	ip = VTOI(vp);
86 
87 	if (ip->i_mnt->iso_ftype != ISO_FTYPE_RRIP
88 	    || vap->va_type != vp->v_type
89 	    || (vap->va_type != VCHR && vap->va_type != VBLK)) {
90 		free(ndp->ni_pnbuf, M_NAMEI);
91 		vput(ndp->ni_dvp);
92 		vput(ndp->ni_vp);
93 		return EINVAL;
94 	}
95 
96 	dp = iso_dmap(ip->i_dev,ip->i_number,1);
97 	if (ip->inode.iso_rdev == vap->va_rdev || vap->va_rdev == VNOVAL) {
98 		/* same as the unmapped one, delete the mapping */
99 		remque(dp);
100 		FREE(dp,M_CACHE);
101 	} else
102 		/* enter new mapping */
103 		dp->d_dev = vap->va_rdev;
104 
105 	/*
106 	 * Remove inode so that it will be reloaded by iget and
107 	 * checked to see if it is an alias of an existing entry
108 	 * in the inode cache.
109 	 */
110 	vput(vp);
111 	vp->v_type = VNON;
112 	vgone(vp);
113 	return (0);
114 #endif
115 }
116 #endif
117 
118 /*
119  * Open called.
120  *
121  * Nothing to do.
122  */
123 /* ARGSUSED */
124 int
125 cd9660_open(ap)
126 	struct vop_open_args /* {
127 		struct vnode *a_vp;
128 		int  a_mode;
129 		struct ucred *a_cred;
130 		struct proc *a_p;
131 	} */ *ap;
132 {
133 	return (0);
134 }
135 
136 /*
137  * Close called
138  *
139  * Update the times on the inode on writeable file systems.
140  */
141 /* ARGSUSED */
142 int
143 cd9660_close(ap)
144 	struct vop_close_args /* {
145 		struct vnode *a_vp;
146 		int  a_fflag;
147 		struct ucred *a_cred;
148 		struct proc *a_p;
149 	} */ *ap;
150 {
151 	return (0);
152 }
153 
154 /*
155  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
156  * The mode is shifted to select the owner/group/other fields. The
157  * super user is granted all permissions.
158  */
159 /* ARGSUSED */
160 int
161 cd9660_access(ap)
162 	struct vop_access_args /* {
163 		struct vnode *a_vp;
164 		int  a_mode;
165 		struct ucred *a_cred;
166 		struct proc *a_p;
167 	} */ *ap;
168 {
169 	return (0);
170 }
171 
172 int
173 cd9660_getattr(ap)
174 	struct vop_getattr_args /* {
175 		struct vnode *a_vp;
176 		struct vattr *a_vap;
177 		struct ucred *a_cred;
178 		struct proc *a_p;
179 	} */ *ap;
180 
181 {
182 	struct vnode *vp = ap->a_vp;
183 	register struct vattr *vap = ap->a_vap;
184 	register struct iso_node *ip = VTOI(vp);
185 	int i;
186 
187 	vap->va_fsid	= ip->i_dev;
188 	vap->va_fileid	= ip->i_number;
189 
190 	vap->va_mode	= ip->inode.iso_mode;
191 	vap->va_nlink	= ip->inode.iso_links;
192 	vap->va_uid	= ip->inode.iso_uid;
193 	vap->va_gid	= ip->inode.iso_gid;
194 	vap->va_atime	= ip->inode.iso_atime;
195 	vap->va_mtime	= ip->inode.iso_mtime;
196 	vap->va_ctime	= ip->inode.iso_ctime;
197 	vap->va_rdev	= ip->inode.iso_rdev;
198 
199 	vap->va_size	= (u_quad_t) ip->i_size;
200 	vap->va_flags	= 0;
201 	vap->va_gen = 1;
202 	vap->va_blocksize = ip->i_mnt->logical_block_size;
203 	vap->va_bytes	= (u_quad_t) ip->i_size;
204 	vap->va_type	= vp->v_type;
205 	return (0);
206 }
207 
208 #if ISO_DEFAULT_BLOCK_SIZE >= NBPG
209 #ifdef DEBUG
210 extern int doclusterread;
211 #else
212 #define doclusterread 1
213 #endif
214 #else
215 /* XXX until cluster routines can handle block sizes less than one page */
216 #define doclusterread 0
217 #endif
218 
219 /*
220  * Vnode op for reading.
221  */
222 int
223 cd9660_read(ap)
224 	struct vop_read_args /* {
225 		struct vnode *a_vp;
226 		struct uio *a_uio;
227 		int a_ioflag;
228 		struct ucred *a_cred;
229 	} */ *ap;
230 {
231 	struct vnode *vp = ap->a_vp;
232 	register struct uio *uio = ap->a_uio;
233 	register struct iso_node *ip = VTOI(vp);
234 	register struct iso_mnt *imp;
235 	struct buf *bp;
236 	daddr_t lbn, bn, rablock;
237 	off_t diff;
238 	int rasize, error = 0;
239 	long size, n, on;
240 
241 	if (uio->uio_resid == 0)
242 		return (0);
243 	if (uio->uio_offset < 0)
244 		return (EINVAL);
245 	ip->i_flag |= IACC;
246 	imp = ip->i_mnt;
247 	do {
248 		lbn = iso_lblkno(imp, uio->uio_offset);
249 		on = iso_blkoff(imp, uio->uio_offset);
250 		n = min((unsigned)(imp->logical_block_size - on),
251 			uio->uio_resid);
252 		diff = (off_t)ip->i_size - uio->uio_offset;
253 		if (diff <= 0)
254 			return (0);
255 		if (diff < n)
256 			n = diff;
257 		size = iso_blksize(imp, ip, lbn);
258 		rablock = lbn + 1;
259 		if (doclusterread) {
260 			if (iso_lblktosize(imp, rablock) <= ip->i_size)
261 				error = cluster_read(vp, (off_t)ip->i_size,
262 						     lbn, size, NOCRED, &bp);
263 			else
264 				error = bread(vp, lbn, size, NOCRED, &bp);
265 		} else {
266 			if (vp->v_lastr + 1 == lbn &&
267 			    iso_lblktosize(imp, rablock) < ip->i_size) {
268 				rasize = iso_blksize(imp, ip, rablock);
269 				error = breadn(vp, lbn, size, &rablock,
270 					       &rasize, 1, NOCRED, &bp);
271 			} else
272 				error = bread(vp, lbn, size, NOCRED, &bp);
273 		}
274 		vp->v_lastr = lbn;
275 		n = min(n, size - bp->b_resid);
276 		if (error) {
277 			brelse(bp);
278 			return (error);
279 		}
280 
281 		error = uiomove(bp->b_un.b_addr + on, (int)n, uio);
282 		if (n + on == imp->logical_block_size ||
283 		    uio->uio_offset == (off_t)ip->i_size)
284 			bp->b_flags |= B_AGE;
285 		brelse(bp);
286 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
287 	return (error);
288 }
289 
290 /* ARGSUSED */
291 int
292 cd9660_ioctl(ap)
293 	struct vop_ioctl_args /* {
294 		struct vnode *a_vp;
295 		int  a_command;
296 		caddr_t  a_data;
297 		int  a_fflag;
298 		struct ucred *a_cred;
299 		struct proc *a_p;
300 	} */ *ap;
301 {
302 	printf("You did ioctl for isofs !!\n");
303 	return (ENOTTY);
304 }
305 
306 /* ARGSUSED */
307 int
308 cd9660_select(ap)
309 	struct vop_select_args /* {
310 		struct vnode *a_vp;
311 		int  a_which;
312 		int  a_fflags;
313 		struct ucred *a_cred;
314 		struct proc *a_p;
315 	} */ *ap;
316 {
317 
318 	/*
319 	 * We should really check to see if I/O is possible.
320 	 */
321 	return (1);
322 }
323 
324 /*
325  * Mmap a file
326  *
327  * NB Currently unsupported.
328  */
329 /* ARGSUSED */
330 int
331 cd9660_mmap(ap)
332 	struct vop_mmap_args /* {
333 		struct vnode *a_vp;
334 		int  a_fflags;
335 		struct ucred *a_cred;
336 		struct proc *a_p;
337 	} */ *ap;
338 {
339 
340 	return (EINVAL);
341 }
342 
343 /*
344  * Seek on a file
345  *
346  * Nothing to do, so just return.
347  */
348 /* ARGSUSED */
349 int
350 cd9660_seek(ap)
351 	struct vop_seek_args /* {
352 		struct vnode *a_vp;
353 		off_t  a_oldoff;
354 		off_t  a_newoff;
355 		struct ucred *a_cred;
356 	} */ *ap;
357 {
358 
359 	return (0);
360 }
361 
362 /*
363  * Structure for reading directories
364  */
365 struct isoreaddir {
366 	struct dirent saveent;
367 	struct dirent assocent;
368 	struct dirent current;
369 	off_t saveoff;
370 	off_t assocoff;
371 	off_t curroff;
372 	struct uio *uio;
373 	off_t uio_off;
374 	u_int *cookiep;
375 	int ncookies;
376 	int eof;
377 };
378 
379 static int
380 iso_uiodir(idp,dp,off)
381 	struct isoreaddir *idp;
382 	struct dirent *dp;
383 	off_t off;
384 {
385 	int error;
386 
387 	dp->d_name[dp->d_namlen] = 0;
388 	dp->d_reclen = DIRSIZ(dp);
389 
390 	if (idp->uio->uio_resid < dp->d_reclen) {
391 		idp->eof = 0;
392 		return -1;
393 	}
394 
395 	if (idp->cookiep) {
396 		if (idp->ncookies <= 0) {
397 			idp->eof = 0;
398 			return -1;
399 		}
400 
401 		*idp->cookiep++ = off;
402 		--idp->ncookies;
403 	}
404 
405 	if (error = uiomove(dp,dp->d_reclen,idp->uio))
406 		return error;
407 	idp->uio_off = off;
408 	return 0;
409 }
410 
411 static int
412 iso_shipdir(idp)
413 	struct isoreaddir *idp;
414 {
415 	struct dirent *dp;
416 	int cl, sl, assoc;
417 	int error;
418 	char *cname, *sname;
419 
420 	cl = idp->current.d_namlen;
421 	cname = idp->current.d_name;
422 	if (assoc = cl > 1 && *cname == ASSOCCHAR) {
423 		cl--;
424 		cname++;
425 	}
426 
427 	dp = &idp->saveent;
428 	sname = dp->d_name;
429 	if (!(sl = dp->d_namlen)) {
430 		dp = &idp->assocent;
431 		sname = dp->d_name + 1;
432 		sl = dp->d_namlen - 1;
433 	}
434 	if (sl > 0) {
435 		if (sl != cl
436 		    || bcmp(sname,cname,sl)) {
437 			if (idp->assocent.d_namlen) {
438 				if (error = iso_uiodir(idp,&idp->assocent,idp->assocoff))
439 					return error;
440 				idp->assocent.d_namlen = 0;
441 			}
442 			if (idp->saveent.d_namlen) {
443 				if (error = iso_uiodir(idp,&idp->saveent,idp->saveoff))
444 					return error;
445 				idp->saveent.d_namlen = 0;
446 			}
447 		}
448 	}
449 	idp->current.d_reclen = DIRSIZ(&idp->current);
450 	if (assoc) {
451 		idp->assocoff = idp->curroff;
452 		bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
453 	} else {
454 		idp->saveoff = idp->curroff;
455 		bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
456 	}
457 	return 0;
458 }
459 
460 /*
461  * Vnode op for readdir
462  * XXX make sure everything still works now that eofflagp and cookiep
463  * are no longer args.
464  */
465 int
466 cd9660_readdir(ap)
467 	struct vop_readdir_args /* {
468 		struct vnode *a_vp;
469 		struct uio *a_uio;
470 		struct ucred *a_cred;
471 	} */ *ap;
472 {
473 	register struct uio *uio = ap->a_uio;
474 	struct isoreaddir *idp;
475 	int entryoffsetinblock;
476 	int error = 0;
477 	int endsearch;
478 	struct iso_directory_record *ep;
479 	u_short elen;
480 	int reclen;
481 	struct iso_mnt *imp;
482 	struct iso_node *ip;
483 	struct buf *bp = NULL;
484 
485 	ip = VTOI(ap->a_vp);
486 	imp = ip->i_mnt;
487 
488 	MALLOC(idp,struct isoreaddir *,sizeof(*idp),M_TEMP,M_WAITOK);
489 	idp->saveent.d_namlen = 0;
490 	idp->assocent.d_namlen = 0;
491 	idp->uio = uio;
492 #if 0
493 	idp->cookiep = cookies;
494 	idp->ncookies = ncookies;
495 	idp->eof = 1;
496 #else
497 	idp->cookiep = 0;
498 #endif
499 	idp->curroff = uio->uio_offset;
500 
501 	entryoffsetinblock = iso_blkoff(imp, idp->curroff);
502 	if (entryoffsetinblock != 0) {
503 		if (error = iso_blkatoff(ip, idp->curroff, &bp)) {
504 			FREE(idp,M_TEMP);
505 			return (error);
506 		}
507 	}
508 
509 	endsearch = ip->i_size;
510 
511 	while (idp->curroff < endsearch) {
512 		/*
513 		 * If offset is on a block boundary,
514 		 * read the next directory block.
515 		 * Release previous if it exists.
516 		 */
517 
518 		if (iso_blkoff(imp, idp->curroff) == 0) {
519 			if (bp != NULL)
520 				brelse(bp);
521 			if (error = iso_blkatoff(ip, idp->curroff, &bp))
522 				break;
523 			entryoffsetinblock = 0;
524 		}
525 		/*
526 		 * Get pointer to next entry.
527 		 */
528 
529 		ep = (struct iso_directory_record *)
530 			(bp->b_un.b_addr + entryoffsetinblock);
531 
532 		reclen = isonum_711 (ep->length);
533 		if (reclen == 0) {
534 			/* skip to next block, if any */
535 			idp->curroff = roundup (idp->curroff,
536 						imp->logical_block_size);
537 			continue;
538 		}
539 
540 		if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
541 			error = EINVAL;
542 			/* illegal entry, stop */
543 			break;
544 		}
545 
546 		if (entryoffsetinblock + reclen > imp->logical_block_size) {
547 			error = EINVAL;
548 			/* illegal directory, so stop looking */
549 			break;
550 		}
551 
552 		idp->current.d_namlen = isonum_711 (ep->name_len);
553 		if (isonum_711(ep->flags)&2)
554 			isodirino(&idp->current.d_fileno,ep,imp);
555 		else
556 			idp->current.d_fileno = dbtob(bp->b_blkno) +
557 				idp->curroff;
558 
559 		if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
560 			error = EINVAL;
561 			/* illegal entry, stop */
562 			break;
563 		}
564 
565 		idp->curroff += reclen;
566 		/*
567 		 *
568 		 */
569 		switch (imp->iso_ftype) {
570 		case ISO_FTYPE_RRIP:
571 			cd9660_rrip_getname(ep,idp->current.d_name,
572 					   (u_short *)&idp->current.d_namlen,
573 					   &idp->current.d_fileno,imp);
574 			if (idp->current.d_namlen)
575 				error = iso_uiodir(idp,&idp->current,idp->curroff);
576 			break;
577 		default:	/* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */
578 			strcpy(idp->current.d_name,"..");
579 			switch (ep->name[0]) {
580 			case 0:
581 				idp->current.d_namlen = 1;
582 				error = iso_uiodir(idp,&idp->current,idp->curroff);
583 				break;
584 			case 1:
585 				idp->current.d_namlen = 2;
586 				error = iso_uiodir(idp,&idp->current,idp->curroff);
587 				break;
588 			default:
589 				isofntrans(ep->name,idp->current.d_namlen,
590 					   idp->current.d_name, &elen,
591 					   imp->iso_ftype == ISO_FTYPE_9660,
592 					   isonum_711(ep->flags)&4);
593 				idp->current.d_namlen = (u_char)elen;
594 				if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
595 					error = iso_shipdir(idp);
596 				else
597 					error = iso_uiodir(idp,&idp->current,idp->curroff);
598 				break;
599 			}
600 		}
601 		if (error)
602 			break;
603 
604 		entryoffsetinblock += reclen;
605 	}
606 
607 	if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
608 		idp->current.d_namlen = 0;
609 		error = iso_shipdir(idp);
610 	}
611 	if (error < 0)
612 		error = 0;
613 
614 	if (bp)
615 		brelse (bp);
616 
617 	uio->uio_offset = idp->uio_off;
618 #if 0
619 	*eofflagp = idp->eof;
620 #endif
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 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 	u_short	symlen;
649 	int	error;
650 	char	*symname;
651 	ino_t	ino;
652 
653 	ip  = VTOI(ap->a_vp);
654 	imp = ip->i_mnt;
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 		      (daddr_t)(ip->i_number / DEV_BSIZE),
664 		      imp->logical_block_size,
665 		      NOCRED,
666 		      &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_un.b_addr + (ip->i_number & imp->im_bmask));
676 #ifdef DEBUG
677 	printf("lbn=%d,off=%d,bsize=%d,DEV_BSIZE=%d, dirp= %08x, b_addr=%08x, offset=%08x(%08x)\n",
678 	       (daddr_t)(ip->i_number >> imp->im_bshift),
679 	       ip->i_number & imp->im_bmask,
680 	       imp->logical_block_size,
681 	       DEV_BSIZE,
682 	       dirp,
683 	       bp->b_un.b_addr,
684 	       ip->i_number,
685 	       ip->i_number & imp->im_bmask );
686 #endif
687 
688 	/*
689 	 * Just make sure, we have a right one....
690 	 *   1: Check not cross boundary on block
691 	 */
692 	if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
693 	    > imp->logical_block_size) {
694 		brelse(bp);
695 		return EINVAL;
696 	}
697 
698 	/*
699 	 * Now get a buffer
700 	 * Abuse a namei buffer for now.
701 	 */
702 	MALLOC(symname,char *,MAXPATHLEN,M_NAMEI,M_WAITOK);
703 
704 	/*
705 	 * Ok, we just gathering a symbolic name in SL record.
706 	 */
707 	if (cd9660_rrip_getsymname(dirp,symname,&symlen,imp) == 0) {
708 		FREE(symname,M_NAMEI);
709 		brelse(bp);
710 		return EINVAL;
711 	}
712 	/*
713 	 * Don't forget before you leave from home ;-)
714 	 */
715 	brelse(bp);
716 
717 	/*
718 	 * return with the symbolic name to caller's.
719 	 */
720 	error = uiomove(symname,symlen,ap->a_uio);
721 
722 	FREE(symname,M_NAMEI);
723 
724 	return error;
725 }
726 
727 /*
728  * Ufs abort op, called after namei() when a CREATE/DELETE isn't actually
729  * done. If a buffer has been saved in anticipation of a CREATE, delete it.
730  */
731 int
732 cd9660_abortop(ap)
733 	struct vop_abortop_args /* {
734 		struct vnode *a_dvp;
735 		struct componentname *a_cnp;
736 	} */ *ap;
737 {
738 	if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
739 		FREE(ap->a_cnp->cn_pnbuf, M_NAMEI);
740 	return 0;
741 }
742 
743 /*
744  * Lock an inode.
745  */
746 int
747 cd9660_lock(ap)
748 	struct vop_lock_args /* {
749 		struct vnode *a_vp;
750 	} */ *ap;
751 {
752 	register struct iso_node *ip = VTOI(ap->a_vp);
753 
754 	ISO_ILOCK(ip);
755 	return 0;
756 }
757 
758 /*
759  * Unlock an inode.
760  */
761 int
762 cd9660_unlock(ap)
763 	struct vop_unlock_args /* {
764 		struct vnode *a_vp;
765 	} */ *ap;
766 {
767 	register struct iso_node *ip = VTOI(ap->a_vp);
768 
769 	if (!(ip->i_flag & ILOCKED))
770 		panic("cd9660_unlock NOT LOCKED");
771 	ISO_IUNLOCK(ip);
772 	return 0;
773 }
774 
775 /*
776  * Check for a locked inode.
777  */
778 int
779 cd9660_islocked(ap)
780 	struct vop_islocked_args /* {
781 		struct vnode *a_vp;
782 	} */ *ap;
783 {
784 
785 	if (VTOI(ap->a_vp)->i_flag & ILOCKED)
786 		return 1;
787 	return 0;
788 }
789 
790 /*
791  * Calculate the logical to physical mapping if not done already,
792  * then call the device strategy routine.
793  */
794 int
795 cd9660_strategy(ap)
796 	struct vop_strategy_args /* {
797 		struct buf *a_bp;
798 	} */ *ap;
799 {
800 	register struct buf *bp = ap->a_bp;
801 	register struct vnode *vp = bp->b_vp;
802 	register struct iso_node *ip;
803 	int error;
804 
805 	ip = VTOI(vp);
806 	if (vp->v_type == VBLK || vp->v_type == VCHR)
807 		panic("cd9660_strategy: spec");
808 	if (bp->b_blkno == bp->b_lblkno) {
809 		if (error =
810 		    VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL)) {
811 			bp->b_error = error;
812 			bp->b_flags |= B_ERROR;
813 			biodone(bp);
814 			return (error);
815 		}
816 		if ((long)bp->b_blkno == -1)
817 			clrbuf(bp);
818 	}
819 	if ((long)bp->b_blkno == -1) {
820 		biodone(bp);
821 		return (0);
822 	}
823 	vp = ip->i_devvp;
824 	bp->b_dev = vp->v_rdev;
825 	VOCALL (vp->v_op, VOFFSET(vop_strategy), ap);
826 	return (0);
827 }
828 
829 /*
830  * Print out the contents of an inode.
831  */
832 int
833 cd9660_print(ap)
834 	struct vop_print_args /* {
835 		struct vnode *a_vp;
836 	} */ *ap;
837 {
838 	printf("tag VT_ISOFS, isofs vnode\n");
839 	return 0;
840 }
841 
842 /*
843  * Unsupported operation
844  */
845 int
846 cd9660_enotsupp()
847 {
848 
849 	return (EOPNOTSUPP);
850 }
851 
852 /*
853  * Global vfs data structures for isofs
854  */
855 #define cd9660_create \
856 	((int (*) __P((struct  vop_create_args *)))cd9660_enotsupp)
857 #define cd9660_mknod ((int (*) __P((struct  vop_mknod_args *)))cd9660_enotsupp)
858 #define cd9660_setattr \
859 	((int (*) __P((struct  vop_setattr_args *)))cd9660_enotsupp)
860 #define cd9660_write ((int (*) __P((struct  vop_write_args *)))cd9660_enotsupp)
861 #define cd9660_fsync ((int (*) __P((struct  vop_fsync_args *)))nullop)
862 #define cd9660_remove \
863 	((int (*) __P((struct  vop_remove_args *)))cd9660_enotsupp)
864 #define cd9660_link ((int (*) __P((struct  vop_link_args *)))cd9660_enotsupp)
865 #define cd9660_rename \
866 	((int (*) __P((struct  vop_rename_args *)))cd9660_enotsupp)
867 #define cd9660_mkdir ((int (*) __P((struct  vop_mkdir_args *)))cd9660_enotsupp)
868 #define cd9660_rmdir ((int (*) __P((struct  vop_rmdir_args *)))cd9660_enotsupp)
869 #define cd9660_symlink \
870 	((int (*) __P((struct vop_symlink_args *)))cd9660_enotsupp)
871 #define cd9660_pathconf \
872 	((int (*) __P((struct vop_pathconf_args *)))cd9660_enotsupp)
873 #define cd9660_advlock \
874 	((int (*) __P((struct vop_advlock_args *)))cd9660_enotsupp)
875 #define cd9660_blkatoff \
876 	((int (*) __P((struct  vop_blkatoff_args *)))cd9660_enotsupp)
877 #define cd9660_valloc ((int(*) __P(( \
878 		struct vnode *pvp, \
879 		int mode, \
880 		struct ucred *cred, \
881 		struct vnode **vpp))) cd9660_enotsupp)
882 #define cd9660_vfree ((int (*) __P((struct  vop_vfree_args *)))cd9660_enotsupp)
883 #define cd9660_truncate \
884 	((int (*) __P((struct  vop_truncate_args *)))cd9660_enotsupp)
885 #define cd9660_update \
886 	((int (*) __P((struct  vop_update_args *)))cd9660_enotsupp)
887 #define cd9660_bwrite \
888 	((int (*) __P((struct  vop_bwrite_args *)))cd9660_enotsupp)
889 
890 /*
891  * Global vfs data structures for nfs
892  */
893 int (**cd9660_vnodeop_p)();
894 struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
895 	{ &vop_default_desc, vn_default_error },
896 	{ &vop_lookup_desc, cd9660_lookup },	/* lookup */
897 	{ &vop_create_desc, cd9660_create },	/* create */
898 	{ &vop_mknod_desc, cd9660_mknod },	/* mknod */
899 	{ &vop_open_desc, cd9660_open },	/* open */
900 	{ &vop_close_desc, cd9660_close },	/* close */
901 	{ &vop_access_desc, cd9660_access },	/* access */
902 	{ &vop_getattr_desc, cd9660_getattr },	/* getattr */
903 	{ &vop_setattr_desc, cd9660_setattr },	/* setattr */
904 	{ &vop_read_desc, cd9660_read },	/* read */
905 	{ &vop_write_desc, cd9660_write },	/* write */
906 	{ &vop_ioctl_desc, cd9660_ioctl },	/* ioctl */
907 	{ &vop_select_desc, cd9660_select },	/* select */
908 	{ &vop_mmap_desc, cd9660_mmap },	/* mmap */
909 	{ &vop_fsync_desc, cd9660_fsync },	/* fsync */
910 	{ &vop_seek_desc, cd9660_seek },	/* seek */
911 	{ &vop_remove_desc, cd9660_remove },	/* remove */
912 	{ &vop_link_desc, cd9660_link },	/* link */
913 	{ &vop_rename_desc, cd9660_rename },	/* rename */
914 	{ &vop_mkdir_desc, cd9660_mkdir },	/* mkdir */
915 	{ &vop_rmdir_desc, cd9660_rmdir },	/* rmdir */
916 	{ &vop_symlink_desc, cd9660_symlink },	/* symlink */
917 	{ &vop_readdir_desc, cd9660_readdir },	/* readdir */
918 	{ &vop_readlink_desc, cd9660_readlink },/* readlink */
919 	{ &vop_abortop_desc, cd9660_abortop },	/* abortop */
920 	{ &vop_inactive_desc, cd9660_inactive },/* inactive */
921 	{ &vop_reclaim_desc, cd9660_reclaim },	/* reclaim */
922 	{ &vop_lock_desc, cd9660_lock },	/* lock */
923 	{ &vop_unlock_desc, cd9660_unlock },	/* unlock */
924 	{ &vop_bmap_desc, cd9660_bmap },	/* bmap */
925 	{ &vop_strategy_desc, cd9660_strategy },/* strategy */
926 	{ &vop_print_desc, cd9660_print },	/* print */
927 	{ &vop_islocked_desc, cd9660_islocked },/* islocked */
928 	{ &vop_pathconf_desc, cd9660_pathconf },/* pathconf */
929 	{ &vop_advlock_desc, cd9660_advlock },	/* advlock */
930 	{ &vop_blkatoff_desc, cd9660_blkatoff },/* blkatoff */
931 	{ &vop_valloc_desc, cd9660_valloc },	/* valloc */
932 	{ &vop_vfree_desc, cd9660_vfree },	/* vfree */
933 	{ &vop_truncate_desc, cd9660_truncate },/* truncate */
934 	{ &vop_update_desc, cd9660_update },	/* update */
935 	{ &vop_bwrite_desc, vn_bwrite },
936 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
937 };
938 struct vnodeopv_desc cd9660_vnodeop_opv_desc =
939 	{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
940 
941 /*
942  * Special device vnode ops
943  */
944 int (**cd9660_specop_p)();
945 struct vnodeopv_entry_desc cd9660_specop_entries[] = {
946 	{ &vop_default_desc, vn_default_error },
947 	{ &vop_lookup_desc, spec_lookup },	/* lookup */
948 	{ &vop_create_desc, cd9660_create },	/* create */
949 	{ &vop_mknod_desc, cd9660_mknod },	/* mknod */
950 	{ &vop_open_desc, spec_open },		/* open */
951 	{ &vop_close_desc, spec_close },	/* close */
952 	{ &vop_access_desc, cd9660_access },	/* access */
953 	{ &vop_getattr_desc, cd9660_getattr },	/* getattr */
954 	{ &vop_setattr_desc, cd9660_setattr },	/* setattr */
955 	{ &vop_read_desc, spec_read },		/* read */
956 	{ &vop_write_desc, spec_write },	/* write */
957 	{ &vop_ioctl_desc, spec_ioctl },	/* ioctl */
958 	{ &vop_select_desc, spec_select },	/* select */
959 	{ &vop_mmap_desc, spec_mmap },		/* mmap */
960 	{ &vop_fsync_desc, spec_fsync },	/* fsync */
961 	{ &vop_seek_desc, spec_seek },		/* seek */
962 	{ &vop_remove_desc, cd9660_remove },	/* remove */
963 	{ &vop_link_desc, cd9660_link },	/* link */
964 	{ &vop_rename_desc, cd9660_rename },	/* rename */
965 	{ &vop_mkdir_desc, cd9660_mkdir },	/* mkdir */
966 	{ &vop_rmdir_desc, cd9660_rmdir },	/* rmdir */
967 	{ &vop_symlink_desc, cd9660_symlink },	/* symlink */
968 	{ &vop_readdir_desc, spec_readdir },	/* readdir */
969 	{ &vop_readlink_desc, spec_readlink },	/* readlink */
970 	{ &vop_abortop_desc, spec_abortop },	/* abortop */
971 	{ &vop_inactive_desc, cd9660_inactive },/* inactive */
972 	{ &vop_reclaim_desc, cd9660_reclaim },	/* reclaim */
973 	{ &vop_lock_desc, cd9660_lock },	/* lock */
974 	{ &vop_unlock_desc, cd9660_unlock },	/* unlock */
975 	{ &vop_bmap_desc, spec_bmap },		/* bmap */
976 		/* XXX strategy: panics, should be notsupp instead? */
977 	{ &vop_strategy_desc, cd9660_strategy },/* strategy */
978 	{ &vop_print_desc, cd9660_print },	/* print */
979 	{ &vop_islocked_desc, cd9660_islocked },/* islocked */
980 	{ &vop_pathconf_desc, spec_pathconf },	/* pathconf */
981 	{ &vop_advlock_desc, spec_advlock },	/* advlock */
982 	{ &vop_blkatoff_desc, spec_blkatoff },	/* blkatoff */
983 	{ &vop_valloc_desc, spec_valloc },	/* valloc */
984 	{ &vop_vfree_desc, spec_vfree },	/* vfree */
985 	{ &vop_truncate_desc, spec_truncate },	/* truncate */
986 	{ &vop_update_desc, cd9660_update },	/* update */
987 	{ &vop_bwrite_desc, vn_bwrite },
988 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
989 };
990 struct vnodeopv_desc cd9660_specop_opv_desc =
991 	{ &cd9660_specop_p, cd9660_specop_entries };
992 
993 #ifdef FIFO
994 int (**cd9660_fifoop_p)();
995 struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
996 	{ &vop_default_desc, vn_default_error },
997 	{ &vop_lookup_desc, fifo_lookup },	/* lookup */
998 	{ &vop_create_desc, cd9660_create },	/* create */
999 	{ &vop_mknod_desc, cd9660_mknod },	/* mknod */
1000 	{ &vop_open_desc, fifo_open },		/* open */
1001 	{ &vop_close_desc, fifo_close },	/* close */
1002 	{ &vop_access_desc, cd9660_access },	/* access */
1003 	{ &vop_getattr_desc, cd9660_getattr },	/* getattr */
1004 	{ &vop_setattr_desc, cd9660_setattr },	/* setattr */
1005 	{ &vop_read_desc, fifo_read },		/* read */
1006 	{ &vop_write_desc, fifo_write },	/* write */
1007 	{ &vop_ioctl_desc, fifo_ioctl },	/* ioctl */
1008 	{ &vop_select_desc, fifo_select },	/* select */
1009 	{ &vop_mmap_desc, fifo_mmap },		/* mmap */
1010 	{ &vop_fsync_desc, fifo_fsync },	/* fsync */
1011 	{ &vop_seek_desc, fifo_seek },		/* seek */
1012 	{ &vop_remove_desc, cd9660_remove },	/* remove */
1013 	{ &vop_link_desc, cd9660_link },	/* link */
1014 	{ &vop_rename_desc, cd9660_rename },	/* rename */
1015 	{ &vop_mkdir_desc, cd9660_mkdir },	/* mkdir */
1016 	{ &vop_rmdir_desc, cd9660_rmdir },	/* rmdir */
1017 	{ &vop_symlink_desc, cd9660_symlink },	/* symlink */
1018 	{ &vop_readdir_desc, fifo_readdir },	/* readdir */
1019 	{ &vop_readlink_desc, fifo_readlink },	/* readlink */
1020 	{ &vop_abortop_desc, fifo_abortop },	/* abortop */
1021 	{ &vop_inactive_desc, cd9660_inactive },/* inactive */
1022 	{ &vop_reclaim_desc, cd9660_reclaim },	/* reclaim */
1023 	{ &vop_lock_desc, cd9660_lock },	/* lock */
1024 	{ &vop_unlock_desc, cd9660_unlock },	/* unlock */
1025 	{ &vop_bmap_desc, fifo_bmap },		/* bmap */
1026 	{ &vop_strategy_desc, fifo_badop },	/* strategy */
1027 	{ &vop_print_desc, cd9660_print },	/* print */
1028 	{ &vop_islocked_desc, cd9660_islocked },/* islocked */
1029 	{ &vop_pathconf_desc, fifo_pathconf },	/* pathconf */
1030 	{ &vop_advlock_desc, fifo_advlock },	/* advlock */
1031 	{ &vop_blkatoff_desc, fifo_blkatoff },	/* blkatoff */
1032 	{ &vop_valloc_desc, fifo_valloc },	/* valloc */
1033 	{ &vop_vfree_desc, fifo_vfree },	/* vfree */
1034 	{ &vop_truncate_desc, fifo_truncate },	/* truncate */
1035 	{ &vop_update_desc, cd9660_update },	/* update */
1036 	{ &vop_bwrite_desc, vn_bwrite },
1037 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
1038 };
1039 struct vnodeopv_desc cd9660_fifoop_opv_desc =
1040 	{ &cd9660_fifoop_p, cd9660_fifoop_entries };
1041 #endif /* FIFO */
1042