]> git.saurik.com Git - apple/xnu.git/blob - bsd/isofs/cd9660/cd9660_vnops.c
7dbfd69660490f66b14008d465111ae0441519d7
[apple/xnu.git] / bsd / isofs / cd9660 / cd9660_vnops.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* $NetBSD: cd9660_vnops.c,v 1.22 1994/12/27 19:05:12 mycroft Exp $ */
24
25 /*-
26 * Copyright (c) 1994
27 * The Regents of the University of California. All rights reserved.
28 *
29 * This code is derived from software contributed to Berkeley
30 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
31 * Support code is derived from software contributed to Berkeley
32 * by Atsushi Murai (amurai@spec.co.jp).
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)cd9660_vnops.c 8.15 (Berkeley) 12/5/94
63 *
64 * HISTORY
65 * 02-Feb-00 chw Add cd9660_copyfile to return error
66 * 29-Sep-98 djb Add cd9660_getattrlist VOP for VDI support.
67 * 15-sep-98 added cd9660_rmdir to do proper unlocking - chw
68 * 12-aug-98 added cd9660_remove which will do proper unlocking - chw
69 * 17-Feb-98 radar 1669467 - changed lock protocols to use the lock manager - chw
70 * 22-Jan-98 radar 1669467 - ISO 9660 CD support - jwc
71 */
72
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/vnode.h>
76 #include <sys/mount.h>
77 #include <sys/namei.h>
78 #include <sys/resourcevar.h>
79 #include <sys/kernel.h>
80 #include <sys/file.h>
81 #include <sys/stat.h>
82 #include <sys/buf.h>
83 #include <sys/proc.h>
84 #include <sys/kauth.h>
85 #include <sys/conf.h>
86 #include <miscfs/specfs/specdev.h>
87 #include <miscfs/fifofs/fifo.h>
88 #include <sys/malloc.h>
89 #include <sys/dir.h>
90 #include <sys/attr.h>
91 #include <vfs/vfs_support.h>
92 #include <vm/vm_kern.h>
93 #include <sys/ubc.h>
94 #include <sys/lock.h>
95 #include <sys/ubc_internal.h>
96 #include <sys/uio_internal.h>
97 #include <architecture/byte_order.h>
98
99 #include <vm/vm_map.h>
100 #include <vm/vm_kern.h> /* kmem_alloc, kmem_free */
101
102 #include <isofs/cd9660/iso.h>
103 #include <isofs/cd9660/cd9660_node.h>
104 #include <isofs/cd9660/iso_rrip.h>
105
106 /*
107 * Open called.
108 *
109 * Nothing to do.
110 */
111 int
112 cd9660_open(__unused struct vnop_open_args *ap)
113 {
114 return (0);
115 }
116
117 /*
118 * Close called
119 *
120 * Update the times on the inode on writeable file systems.
121 */
122 int
123 cd9660_close(__unused struct vnop_close_args *ap)
124 {
125 return (0);
126 }
127
128 int
129 cd9660_getattr(struct vnop_getattr_args *ap)
130 {
131 struct vnode *vp = ap->a_vp;
132 register struct vnode_attr *vap = ap->a_vap;
133 register struct iso_node *ip = VTOI(vp);
134
135 VATTR_RETURN(vap, va_fsid, ip->i_dev);
136 VATTR_RETURN(vap, va_fileid, ip->i_number);
137
138 VATTR_RETURN(vap, va_mode, ip->inode.iso_mode);
139 VATTR_RETURN(vap, va_nlink, ip->inode.iso_links);
140 VATTR_RETURN(vap, va_uid, ip->inode.iso_uid);
141 VATTR_RETURN(vap, va_gid, ip->inode.iso_gid);
142 VATTR_RETURN(vap, va_access_time, ip->inode.iso_atime);
143 VATTR_RETURN(vap, va_modify_time, ip->inode.iso_mtime);
144 VATTR_RETURN(vap, va_change_time, ip->inode.iso_ctime);
145 VATTR_RETURN(vap, va_rdev, ip->inode.iso_rdev);
146
147 VATTR_RETURN(vap, va_data_size, (off_t)ip->i_size);
148 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
149 struct vnop_readlink_args rdlnk;
150 uio_t auio;
151 char uio_buf[ UIO_SIZEOF(1) ];
152 char *cp;
153
154 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
155 auio = uio_createwithbuffer(1, 0, UIO_SYSSPACE, UIO_READ,
156 &uio_buf[0], sizeof(uio_buf));
157 uio_addiov(auio, CAST_USER_ADDR_T(cp), MAXPATHLEN);
158
159 rdlnk.a_uio = auio;
160 rdlnk.a_vp = ap->a_vp;
161 rdlnk.a_context = ap->a_context;
162 if (cd9660_readlink(&rdlnk) == 0)
163 // LP64todo - fix this!
164 VATTR_RETURN(vap, va_data_size, MAXPATHLEN - uio_resid(auio));
165 FREE(cp, M_TEMP);
166 }
167 VATTR_RETURN(vap, va_flags, 0);
168 VATTR_RETURN(vap, va_gen, 1);
169 VATTR_RETURN(vap, va_iosize, ip->i_mnt->logical_block_size);
170 VATTR_RETURN(vap, va_total_size, ip->i_size + ip->i_rsrcsize);
171
172 return (0);
173 }
174
175
176 /*
177 * Vnode op for reading.
178 */
179 int
180 cd9660_read(struct vnop_read_args *ap)
181 {
182 struct vnode *vp = ap->a_vp;
183 register struct uio *uio = ap->a_uio;
184 register struct iso_node *ip = VTOI(vp);
185 register struct iso_mnt *imp;
186 struct buf *bp;
187 daddr_t lbn;
188 daddr64_t rablock;
189 off_t diff;
190 int rasize, error = 0;
191 int32_t size, n, on;
192
193 if (uio_resid(uio) == 0)
194 return (0);
195 if (uio->uio_offset < 0)
196 return (EINVAL);
197
198 imp = ip->i_mnt;
199
200 if (UBCINFOEXISTS(vp)) {
201 /*
202 * Copy any part of the Apple Double header.
203 */
204 if ((ip->i_flag & ISO_ASSOCIATED) && (uio->uio_offset < ADH_SIZE)) {
205 apple_double_header_t header;
206 int bytes;
207
208 if (uio->uio_offset < sizeof(apple_double_header_t)) {
209 header.magic = APPLEDOUBLE_MAGIC;
210 header.version = APPLEDOUBLE_VERSION;
211 header.count = 2;
212 header.entries[0].entryID = APPLEDOUBLE_FINDERINFO;
213 header.entries[0].offset = offsetof(apple_double_header_t, finfo);
214 header.entries[0].length = 32;
215 header.entries[1].entryID = APPLEDOUBLE_RESFORK;
216 header.entries[1].offset = ADH_SIZE;
217 header.entries[1].length = ip->i_size - ADH_SIZE;
218 header.finfo.fdType = ip->i_FileType;
219 header.finfo.fdCreator = ip->i_Creator;
220 header.finfo.fdFlags = ip->i_FinderFlags;
221 header.finfo.fdLocation.v = -1;
222 header.finfo.fdLocation.h = -1;
223 header.finfo.fdReserved = 0;
224
225 bytes = min(uio_resid(uio), sizeof(apple_double_header_t) - uio->uio_offset);
226 error = uiomove(((char *) &header) + uio->uio_offset, bytes, uio);
227 if (error)
228 return error;
229 }
230 if (uio_resid(uio) && uio->uio_offset < ADH_SIZE) {
231 caddr_t buffer;
232
233 if (kmem_alloc(kernel_map, (vm_offset_t *)&buffer, ADH_SIZE)) {
234 return (ENOMEM);
235 }
236 bytes = min(uio_resid(uio), ADH_SIZE - uio->uio_offset);
237 error = uiomove(((char *) buffer) + uio->uio_offset, bytes, uio);
238 kmem_free(kernel_map, (vm_offset_t)buffer, ADH_SIZE);
239 if (error)
240 return error;
241 }
242 }
243 if (uio_resid(uio) > 0)
244 error = cluster_read(vp, uio, (off_t)ip->i_size, 0);
245 } else {
246
247 do {
248 lbn = lblkno(imp, uio->uio_offset);
249 on = blkoff(imp, uio->uio_offset);
250 n = min((u_int)(imp->logical_block_size - on),
251 uio_resid(uio));
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 = blksize(imp, ip, lbn);
258 rablock = (daddr64_t)lbn + 1;
259
260 if (ip->i_lastr + 1 == lbn &&
261 lblktosize(imp, rablock) < ip->i_size) {
262 rasize = blksize(imp, ip, (daddr_t)rablock);
263 error = (int)buf_breadn(vp, (daddr64_t)((unsigned)lbn), size, &rablock,
264 &rasize, 1, NOCRED, &bp);
265 } else
266 error = (int)buf_bread(vp, (daddr64_t)((unsigned)lbn), size, NOCRED, &bp);
267
268 ip->i_lastr = lbn;
269 n = min(n, size - buf_resid(bp));
270 if (error) {
271 buf_brelse(bp);
272 return (error);
273 }
274
275 error = uiomove((caddr_t)(buf_dataptr(bp) + on), (int)n, uio);
276 if (n + on == imp->logical_block_size ||
277 uio->uio_offset == (off_t)ip->i_size)
278 buf_markaged(bp);
279 buf_brelse(bp);
280 } while (error == 0 && uio_resid(uio) > 0 && n != 0);
281 }
282
283 return (error);
284 }
285
286 int
287 cd9660_ioctl(__unused struct vnop_ioctl_args *ap)
288 {
289 return (ENOTTY);
290 }
291
292 int
293 cd9660_select(__unused struct vnop_select_args *ap)
294 {
295 /*
296 * We should really check to see if I/O is possible.
297 */
298 return (1);
299 }
300
301 /*
302 * Mmap a file
303 *
304 * NB Currently unsupported.
305 */
306 int
307 cd9660_mmap(__unused struct vnop_mmap_args *ap)
308 {
309
310 return (EINVAL);
311 }
312
313 /*
314 * Structure for reading directories
315 */
316 struct isoreaddir {
317 struct dirent saveent;
318 struct dirent current;
319 off_t saveoff;
320 off_t curroff;
321 struct uio *uio;
322 off_t uio_off;
323 int eofflag;
324 // u_long **cookies;
325 // int *ncookies;
326 };
327
328 static int
329 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
330 {
331 int error;
332
333 dp->d_name[dp->d_namlen] = 0;
334 dp->d_reclen = DIRSIZ(dp);
335
336 if (uio_resid(idp->uio) < dp->d_reclen) {
337 idp->eofflag = 0;
338 return (-1);
339 }
340
341 #if 0
342 if (idp->cookies) {
343 if (*idp->ncookies <= 0) {
344 idp->eofflag = 0;
345 return (-1);
346 }
347
348 **idp->cookies++ = off;
349 --*idp->ncookies;
350 }
351 #endif
352
353 if ( (error = uiomove( (caddr_t)dp, dp->d_reclen, idp->uio )) )
354 return (error);
355 idp->uio_off = off;
356 return (0);
357 }
358
359 static int
360 iso_shipdir(struct isoreaddir *idp)
361 {
362 struct dirent *dp;
363 int cl, sl;
364 int error;
365 char *cname, *sname;
366
367 cl = idp->current.d_namlen;
368 cname = idp->current.d_name;
369
370 dp = &idp->saveent;
371 sname = dp->d_name;
372 sl = dp->d_namlen;
373 if (sl > 0) {
374 if (sl != cl
375 || bcmp(sname,cname,sl)) {
376 if (idp->saveent.d_namlen) {
377 if ( (error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) )
378 return (error);
379 idp->saveent.d_namlen = 0;
380 }
381 }
382 }
383 idp->current.d_reclen = DIRSIZ(&idp->current);
384 idp->saveoff = idp->curroff;
385 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
386 return (0);
387 }
388
389 /*
390 * Vnode op for readdir
391 *
392 * Note that directories are sector aligned (2K) and
393 * that an entry can cross a logical block but not
394 * a sector.
395 */
396 int
397 cd9660_readdir(struct vnop_readdir_args *ap)
398 {
399 register struct uio *uio = ap->a_uio;
400 off_t startingOffset = uio->uio_offset;
401 size_t lost = 0;
402 struct isoreaddir *idp;
403 struct vnode *vdp = ap->a_vp;
404 struct iso_node *dp;
405 struct iso_mnt *imp;
406 struct buf *bp = NULL;
407 struct iso_directory_record *ep;
408 int entryoffsetinblock;
409 doff_t endsearch;
410 uint32_t bmask;
411 int error = 0;
412 int reclen;
413 u_short namelen;
414
415 if (ap->a_flags & (VNODE_READDIR_EXTENDED | VNODE_READDIR_REQSEEKOFF))
416 return (EINVAL);
417
418 dp = VTOI(vdp);
419 imp = dp->i_mnt;
420 bmask = imp->im_sector_size - 1;
421
422 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
423 idp->saveent.d_namlen = 0;
424 /*
425 * XXX
426 * Is it worth trying to figure out the type?
427 */
428 idp->saveent.d_type = idp->current.d_type = DT_UNKNOWN;
429 idp->uio = uio;
430 idp->eofflag = 1;
431 idp->curroff = uio->uio_offset;
432
433 if ((entryoffsetinblock = idp->curroff & bmask) &&
434 (error = cd9660_blkatoff(vdp, SECTOFF(imp, idp->curroff), NULL, &bp))) {
435 FREE(idp, M_TEMP);
436 return (error);
437 }
438 endsearch = dp->i_size;
439
440 while (idp->curroff < endsearch) {
441 /*
442 * If offset is on a block boundary,
443 * read the next directory block.
444 * Release previous if it exists.
445 */
446 if ((idp->curroff & bmask) == 0) {
447 if (bp != NULL)
448 buf_brelse(bp);
449 if ((error = cd9660_blkatoff(vdp, SECTOFF(imp, idp->curroff), NULL, &bp)))
450 break;
451 entryoffsetinblock = 0;
452 }
453 /*
454 * Get pointer to next entry.
455 */
456 ep = (struct iso_directory_record *)
457 (buf_dataptr(bp) + entryoffsetinblock);
458
459 reclen = isonum_711(ep->length);
460 if (reclen == 0) {
461 /* skip to next block, if any */
462 idp->curroff =
463 (idp->curroff & ~bmask) + imp->im_sector_size;
464 continue;
465 }
466
467 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
468 error = EINVAL;
469 /* illegal entry, stop */
470 break;
471 }
472
473 if (entryoffsetinblock + reclen > imp->im_sector_size) {
474 error = EINVAL;
475 /* illegal directory, so stop looking */
476 break;
477 }
478
479 idp->current.d_namlen = isonum_711(ep->name_len);
480
481 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
482 error = EINVAL;
483 /* illegal entry, stop */
484 break;
485 }
486
487 /*
488 * Some poorly mastered discs have an incorrect directory
489 * file size. If the '.' entry has a better size (bigger)
490 * then use that instead.
491 */
492 if ((uio->uio_offset == 0) && (isonum_733(ep->size) > endsearch)) {
493 dp->i_size = endsearch = isonum_733(ep->size);
494 }
495
496 if ( isonum_711(ep->flags) & directoryBit )
497 idp->current.d_fileno = isodirino(ep, imp);
498 else {
499 idp->current.d_fileno = ((daddr_t)buf_blkno(bp) << imp->im_bshift) +
500 entryoffsetinblock;
501 }
502
503 idp->curroff += reclen;
504
505 switch (imp->iso_ftype) {
506 case ISO_FTYPE_RRIP:
507 cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
508 &idp->current.d_fileno,imp);
509 idp->current.d_namlen = (u_char)namelen;
510 if (idp->current.d_namlen)
511 error = iso_uiodir(idp,&idp->current,idp->curroff);
512 break;
513
514 case ISO_FTYPE_JOLIET:
515 ucsfntrans((u_int16_t *)ep->name, idp->current.d_namlen,
516 idp->current.d_name, &namelen,
517 isonum_711(ep->flags) & directoryBit,
518 isonum_711(ep->flags) & associatedBit);
519 idp->current.d_namlen = (u_char)namelen;
520 if (idp->current.d_namlen)
521 error = iso_uiodir(idp,&idp->current,idp->curroff);
522 break;
523
524 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */
525 strcpy(idp->current.d_name,"..");
526 switch (ep->name[0]) {
527 case 0:
528 idp->current.d_namlen = 1;
529 error = iso_uiodir(idp,&idp->current,idp->curroff);
530 break;
531 case 1:
532 idp->current.d_namlen = 2;
533 error = iso_uiodir(idp,&idp->current,idp->curroff);
534 break;
535 default:
536 isofntrans(ep->name,idp->current.d_namlen,
537 idp->current.d_name, &namelen,
538 imp->iso_ftype == ISO_FTYPE_9660,
539 isonum_711(ep->flags) & associatedBit);
540 idp->current.d_namlen = (u_char)namelen;
541 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
542 error = iso_shipdir(idp);
543 else
544 error = iso_uiodir(idp,&idp->current,idp->curroff);
545 break;
546 }
547 }
548 if (error)
549 break;
550
551 entryoffsetinblock += reclen;
552 }
553
554 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
555 idp->current.d_namlen = 0;
556 error = iso_shipdir(idp);
557 }
558 #if 0
559 if (!error && ap->a_ncookies) {
560 struct dirent *dirp, *dpstart;
561 off_t bufferOffset;
562 u_long *cookies;
563 int ncookies;
564
565 /*
566 * Only the NFS server uses cookies, and it loads the
567 * directory block into system space, so we can just look at
568 * it directly.
569 *
570 * We assume the entire transfer is done to a single contiguous buffer.
571 */
572 if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg) || uio->uio_iovcnt != 1)
573 panic("ufs_readdir: lost in space");
574
575 /*
576 * Make a first pass over the buffer just generated,
577 * counting the number of entries:
578 */
579 // LP64todo - fix this!
580 dpstart = (struct dirent *)
581 CAST_DOWN(caddr_t, (uio_iov_base(uio) - (uio->uio_offset - startingOffset)));
582 for (dirp = dpstart, bufferOffset = startingOffset, ncookies = 0;
583 bufferOffset < uio->uio_offset; ) {
584 if (dirp->d_reclen == 0)
585 break;
586 bufferOffset += dirp->d_reclen;
587 ncookies++;
588 dirp = (struct dirent *)((caddr_t)dirp + dirp->d_reclen);
589 }
590 lost += uio->uio_offset - bufferOffset;
591 uio->uio_offset = bufferOffset;
592
593 /*
594 * Allocate a buffer to hold the cookies requested:
595 */
596 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP, M_WAITOK);
597 *ap->a_ncookies = ncookies;
598 *ap->a_cookies = cookies;
599
600 /*
601 * Fill in the offsets for each entry in the buffer just allocated:
602 */
603 for (bufferOffset = startingOffset, dirp = dpstart; bufferOffset < uio->uio_offset; ) {
604 *(cookies++) = bufferOffset;
605 bufferOffset += dirp->d_reclen;
606 dirp = (struct dirent *)((caddr_t)dirp + dirp->d_reclen);
607 }
608 }
609 #endif
610 if (error < 0)
611 error = 0;
612
613 if (bp)
614 buf_brelse (bp);
615
616 uio->uio_offset = idp->uio_off;
617 *ap->a_eofflag = idp->eofflag;
618
619 FREE(idp, M_TEMP);
620
621 return (error);
622 }
623
624 /*
625 * Return target name of a symbolic link
626 * Shouldn't we get the parent vnode and read the data from there?
627 * This could eventually result in deadlocks in cd9660_lookup.
628 * But otherwise the block read here is in the block buffer two times.
629 */
630 typedef struct iso_directory_record ISODIR;
631 typedef struct iso_node ISONODE;
632 typedef struct iso_mnt ISOMNT;
633 int
634 cd9660_readlink(struct vnop_readlink_args *ap)
635 {
636 ISONODE *ip;
637 ISODIR *dirp;
638 ISOMNT *imp;
639 struct buf *bp;
640 struct uio *uio;
641 u_short symlen;
642 int error;
643 char *symname;
644
645 ip = VTOI(ap->a_vp);
646 imp = ip->i_mnt;
647 uio = ap->a_uio;
648
649 if (imp->iso_ftype != ISO_FTYPE_RRIP)
650 return (EINVAL);
651
652 /*
653 * Get parents directory record block that this inode included.
654 */
655 error = (int)buf_bread(imp->im_devvp,
656 (daddr64_t)((unsigned)(ip->i_number >> imp->im_bshift)),
657 imp->logical_block_size, NOCRED, &bp);
658 if (error) {
659 buf_brelse(bp);
660 return (EINVAL);
661 }
662
663 /*
664 * Setup the directory pointer for this inode
665 */
666 dirp = (ISODIR *)(buf_dataptr(bp) + (ip->i_number & imp->im_bmask));
667
668 /*
669 * Just make sure, we have a right one....
670 * 1: Check not cross boundary on block
671 */
672 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
673 > imp->logical_block_size) {
674 buf_brelse(bp);
675 return (EINVAL);
676 }
677
678 /*
679 * Now get a buffer
680 * Abuse a namei buffer for now.
681 */
682 if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg))
683 MALLOC_ZONE(symname, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
684 else
685 // LP64todo - fix this!
686 symname = CAST_DOWN(caddr_t, uio_iov_base(uio));
687
688 /*
689 * Ok, we just gathering a symbolic name in SL record.
690 */
691 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
692 if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg))
693 FREE_ZONE(symname, MAXPATHLEN, M_NAMEI);
694 buf_brelse(bp);
695 return (EINVAL);
696 }
697 /*
698 * Don't forget before you leave from home ;-)
699 */
700 buf_brelse(bp);
701
702 /*
703 * return with the symbolic name to caller's.
704 */
705 if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg)) {
706 error = uiomove(symname, symlen, uio);
707 FREE_ZONE(symname, MAXPATHLEN, M_NAMEI);
708 return (error);
709 }
710 #if LP64KERN
711 uio_setresid(uio, (uio_resid(uio) - symlen));
712 uio_iov_len_add(uio, -((int64_t)symlen));
713 #else
714 uio_setresid(uio, (uio_resid(uio) - symlen));
715 uio_iov_len_add(uio, -((int)symlen));
716 #endif
717 uio_iov_base_add(uio, symlen);
718 return (0);
719 }
720
721
722 /*
723 * prepare and issue the I/O
724 */
725 int
726 cd9660_strategy(struct vnop_strategy_args *ap)
727 {
728 buf_t bp = ap->a_bp;
729 vnode_t vp = buf_vnode(bp);
730 struct iso_node *ip = VTOI(vp);
731
732 return (buf_strategy(ip->i_devvp, ap));
733 }
734
735
736 /*
737 * Return POSIX pathconf information applicable to cd9660 filesystems.
738 */
739 int
740 cd9660_pathconf(struct vnop_pathconf_args *ap)
741 {
742
743 switch (ap->a_name) {
744 case _PC_LINK_MAX:
745 *ap->a_retval = 1;
746 return (0);
747 case _PC_NAME_MAX:
748 switch (VTOI(ap->a_vp)->i_mnt->iso_ftype) {
749 case ISO_FTYPE_RRIP:
750 *ap->a_retval = ISO_RRIP_NAMEMAX;
751 break;
752 case ISO_FTYPE_JOLIET:
753 *ap->a_retval = ISO_JOLIET_NAMEMAX;
754 break;
755 default:
756 *ap->a_retval = ISO_NAMEMAX;
757 }
758 return (0);
759 case _PC_PATH_MAX:
760 *ap->a_retval = PATH_MAX;
761 return (0);
762 case _PC_PIPE_BUF:
763 *ap->a_retval = PIPE_BUF;
764 return (0);
765 case _PC_CHOWN_RESTRICTED:
766 *ap->a_retval = 1;
767 return (0);
768 case _PC_NO_TRUNC:
769 *ap->a_retval = 1;
770 return (0);
771 default:
772 return (EINVAL);
773 }
774 /* NOTREACHED */
775 }
776
777 /*
778 * Unsupported operation
779 */
780 int
781 cd9660_enotsupp(void)
782 {
783 return (ENOTSUP);
784 }
785 /* Pagein. similar to read */
786 int
787 cd9660_pagein(struct vnop_pagein_args *ap)
788 {
789 struct vnode *vp = ap->a_vp;
790 upl_t pl = ap->a_pl;
791 size_t size = ap->a_size;
792 off_t f_offset = ap->a_f_offset;
793 vm_offset_t pl_offset = ap->a_pl_offset;
794 int flags = ap->a_flags;
795 register struct iso_node *ip = VTOI(vp);
796 int error = 0;
797
798 /*
799 * Copy the Apple Double header.
800 */
801 if ((ip->i_flag & ISO_ASSOCIATED) && (f_offset == 0) && (size == ADH_SIZE)) {
802 apple_double_header_t header;
803 kern_return_t kret;
804 vm_offset_t ioaddr;
805
806 kret = ubc_upl_map(pl, &ioaddr);
807 if (kret != KERN_SUCCESS)
808 panic("cd9660_xa_pagein: ubc_upl_map error = %d", kret);
809 ioaddr += pl_offset;
810 bzero((caddr_t)ioaddr, ADH_SIZE);
811
812 header.magic = APPLEDOUBLE_MAGIC;
813 header.version = APPLEDOUBLE_VERSION;
814 header.count = 2;
815 header.entries[0].entryID = APPLEDOUBLE_FINDERINFO;
816 header.entries[0].offset = offsetof(apple_double_header_t, finfo);
817 header.entries[0].length = 32;
818 header.entries[1].entryID = APPLEDOUBLE_RESFORK;
819 header.entries[1].offset = ADH_SIZE;
820 header.entries[1].length = ip->i_size - ADH_SIZE;
821 header.finfo.fdType = ip->i_FileType;
822 header.finfo.fdCreator = ip->i_Creator;
823 header.finfo.fdFlags = ip->i_FinderFlags;
824 header.finfo.fdLocation.v = -1;
825 header.finfo.fdLocation.h = -1;
826 header.finfo.fdReserved = 0;
827
828 bcopy((caddr_t)&header, (caddr_t)ioaddr, sizeof(apple_double_header_t));
829
830 kret = ubc_upl_unmap(pl);
831 if (kret != KERN_SUCCESS)
832 panic("cd9660_xa_pagein: ubc_upl_unmap error = %d", kret);
833
834 if ((flags & UPL_NOCOMMIT) == 0) {
835 ubc_upl_commit_range(pl, pl_offset, size, UPL_COMMIT_FREE_ON_EMPTY);
836 }
837 } else {
838 /* check pageouts are for reg file only and ubc info is present*/
839 if (UBCINVALID(vp))
840 panic("cd9660_pagein: Not a VREG");
841 UBCINFOCHECK("cd9660_pagein", vp);
842
843 error = cluster_pagein(vp, pl, pl_offset, f_offset, size,
844 (off_t)ip->i_size, flags);
845 }
846 return (error);
847 }
848
849 /*
850 * cd9660_remove - not possible to remove a file from iso cds
851 *
852 * Locking policy: a_dvp and vp locked on entry, unlocked on exit
853 */
854 int
855 cd9660_remove(__unused struct vnop_remove_args *ap)
856 {
857 return (EROFS);
858 }
859
860
861 /*
862 * cd9660_rmdir - not possible to remove a directory from iso cds
863 *
864 * Locking policy: a_dvp and vp locked on entry, unlocked on exit
865 */
866 int
867 cd9660_rmdir(struct vnop_rmdir_args *ap)
868 {
869 (void) nop_rmdir(ap);
870 return (EROFS);
871 }
872
873 /*
874
875 #
876 #% getattrlist vp = = =
877 #
878 vnop_getattrlist {
879 IN struct vnode *vp;
880 IN struct attrlist *alist;
881 INOUT struct uio *uio;
882 IN vfs_context_t context;
883 };
884
885 */
886 int
887 cd9660_getattrlist(struct vnop_getattrlist_args *ap)
888 {
889 struct attrlist *alist = ap->a_alist;
890 int fixedblocksize;
891 int attrblocksize;
892 int attrbufsize;
893 void *attrbufptr;
894 void *attrptr;
895 void *varptr;
896 int error = 0;
897
898 if ((alist->bitmapcount != ATTR_BIT_MAP_COUNT) ||
899 ((alist->commonattr & ~ATTR_CMN_VALIDMASK) != 0) ||
900 ((alist->volattr & ~ATTR_VOL_VALIDMASK) != 0) ||
901 ((alist->dirattr & ~ATTR_DIR_VALIDMASK) != 0) ||
902 ((alist->fileattr & ~ATTR_FILE_VALIDMASK) != 0) ||
903 ((alist->forkattr & ~ATTR_FORK_VALIDMASK) != 0)) {
904 return EINVAL;
905 };
906
907 /*
908 * Requesting volume information requires setting the ATTR_VOL_INFO bit and
909 * volume info requests are mutually exclusive with all other info requests:
910 */
911 if ((alist->volattr != 0) &&
912 (((alist->volattr & ATTR_VOL_INFO) == 0) ||
913 (alist->dirattr != 0) ||
914 (alist->fileattr != 0) ||
915 (alist->forkattr != 0) )) {
916 return EINVAL;
917 };
918
919 /*
920 * Reject requests for unsupported options for now:
921 */
922 if (alist->volattr & ATTR_VOL_MOUNTPOINT) return EINVAL;
923 if (alist->commonattr & (ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST)) return EINVAL;
924 if (alist->fileattr &
925 (ATTR_FILE_FILETYPE |
926 ATTR_FILE_FORKCOUNT |
927 ATTR_FILE_FORKLIST |
928 ATTR_FILE_DATAEXTENTS |
929 ATTR_FILE_RSRCEXTENTS)) {
930 return EINVAL;
931 };
932
933
934 fixedblocksize = attrcalcsize(alist);
935 attrblocksize = fixedblocksize + (sizeof(uint32_t)); /* uint32_t for length word */
936 if (alist->commonattr & ATTR_CMN_NAME) attrblocksize += NAME_MAX;
937 if (alist->commonattr & ATTR_CMN_NAMEDATTRLIST) attrblocksize += 0; /* XXX PPD */
938 if (alist->volattr & ATTR_VOL_MOUNTPOINT) attrblocksize += PATH_MAX;
939 if (alist->volattr & ATTR_VOL_NAME) attrblocksize += NAME_MAX;
940 if (alist->fileattr & ATTR_FILE_FORKLIST) attrblocksize += 0; /* XXX PPD */
941
942 attrbufsize = MIN(uio_resid(ap->a_uio), attrblocksize);
943 MALLOC(attrbufptr, void *, attrblocksize, M_TEMP, M_WAITOK);
944 attrptr = attrbufptr;
945 *((uint32_t *)attrptr) = 0; /* Set buffer length in case of errors */
946 ++((uint32_t *)attrptr); /* Reserve space for length field */
947 varptr = ((char *)attrptr) + fixedblocksize; /* Point to variable-length storage */
948
949 packattrblk(alist, ap->a_vp, &attrptr, &varptr);
950
951 /* Store length of fixed + var block */
952 *((uint32_t *)attrbufptr) = ((char*)varptr - (char*)attrbufptr);
953 /* Don't copy out more data than was generated */
954 attrbufsize = MIN(attrbufsize, (char*)varptr - (char*)attrbufptr);
955
956 error = uiomove((caddr_t)attrbufptr, attrbufsize, ap->a_uio);
957
958 FREE(attrbufptr, M_TEMP);
959
960 return error;
961 }
962
963 /*
964 * Make a RIFF file header for a CD-ROM XA media file.
965 */
966 __private_extern__ void
967 cd9660_xa_init(struct iso_node *ip, struct iso_directory_record *isodir)
968 {
969 uint32_t sectors;
970 struct riff_header *header;
971 u_char name_len;
972 char *cdxa;
973
974 MALLOC(header, struct riff_header *, sizeof(struct riff_header), M_TEMP, M_WAITOK);
975
976 sectors = ip->i_size / 2048;
977
978 strncpy(header->riff, "RIFF", 4);
979 header->fileSize = NXSwapHostLongToLittle(sectors * CDXA_SECTOR_SIZE + sizeof(struct riff_header) - 8);
980 strncpy(header->cdxa, "CDXA", 4);
981 strncpy(header->fmt, "fmt ", 4);
982 header->fmtSize = NXSwapHostLongToLittle(16);
983 strncpy(header->data, "data", 4);
984 header->dataSize = NXSwapHostLongToLittle(sectors * CDXA_SECTOR_SIZE);
985
986 /*
987 * Copy the CD-ROM XA extended directory information into the header. As far as
988 * I can tell, it's always 14 bytes in the directory record, but allocated 16 bytes
989 * in the header (the last two being zeroed pad bytes).
990 */
991 name_len = isonum_711(isodir->name_len);
992 cdxa = &isodir->name[name_len];
993 if ((name_len & 0x01) == 0)
994 ++cdxa; /* Skip pad byte */
995 bcopy(cdxa, header->fmtData, 14);
996 header->fmtData[14] = 0;
997 header->fmtData[15] = 0;
998
999 /*
1000 * Point this i-node to the "whole sector" device instead of the normal
1001 * device. This allows cd9660_strategy to be ignorant of the block
1002 * (sector) size.
1003 */
1004 ip->i_devvp = ip->i_mnt->phys_devvp;
1005
1006 ip->i_size = sectors * CDXA_SECTOR_SIZE + sizeof(struct riff_header);
1007 ip->i_riff = header;
1008 }
1009
1010 /*
1011 * Helper routine for vnop_read and vnop_pagein of CD-ROM XA multimedia files.
1012 * This routine determines the physical location of the file, then reads
1013 * sectors directly from the device into a buffer. It also handles inserting
1014 * the RIFF header at the beginning of the file.
1015 *
1016 * Exactly one of buffer or uio must be non-zero. It will either bcopy to
1017 * buffer, or uiomove via uio.
1018 *
1019 * XXX Should this code be using buf_breadn and ip->i_lastr to support single-block
1020 * read-ahead? Should we try more aggressive read-ahead like cluster_io does?
1021 *
1022 * XXX This could be made to do larger I/O to the device (reading all the
1023 * whole sectors directly into the buffer). That would make the code more
1024 * complex, and the current code only adds 2.5% overhead compared to reading
1025 * from the device directly (at least on my test machine).
1026 */
1027 static int
1028 cd9660_xa_read_common(
1029 struct vnode *vp,
1030 off_t offset,
1031 size_t amount,
1032 caddr_t buffer,
1033 struct uio *uio)
1034 {
1035 struct iso_node *ip = VTOI(vp);
1036 struct buf *bp;
1037 off_t diff; /* number of bytes from offset to file's EOF */
1038 daddr_t block; /* physical disk block containing offset */
1039 off_t sect_off; /* starting offset into current sector */
1040 u_int count; /* number of bytes to transfer in current block */
1041 int error=0;
1042
1043 /*
1044 * Copy any part of the RIFF header.
1045 */
1046 if (offset < sizeof(struct riff_header)) {
1047 char *p;
1048
1049 p = ((char *) ip->i_riff) + offset;
1050 count = min(amount, sizeof(struct riff_header) - offset);
1051 if (buffer) {
1052 bcopy(p, buffer, count);
1053 buffer += count;
1054 } else {
1055 error = uiomove(p, count, uio);
1056 }
1057 amount -= count;
1058 offset += count;
1059 }
1060 if (error)
1061 return error;
1062
1063 /*
1064 * Loop over (possibly partial) blocks to transfer.
1065 */
1066 while (error == 0 && amount > 0) {
1067 /*
1068 * Determine number of bytes until EOF. If we've hit
1069 * EOF then return.
1070 */
1071 diff = ip->i_size - offset;
1072 if (diff <= 0)
1073 return 0;
1074
1075 /* Get a block from the underlying device */
1076 block = ip->iso_start + (offset - sizeof(struct riff_header))/CDXA_SECTOR_SIZE;
1077 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)block), CDXA_SECTOR_SIZE, NOCRED, &bp);
1078 if (error) {
1079 buf_brelse(bp);
1080 return error;
1081 }
1082 if (buf_resid(bp)) {
1083 printf("isofs: cd9660_xa_read_common: buf_bread didn't read full sector\n");
1084 return EIO;
1085 }
1086
1087 /* Figure out which part of the block to copy, and copy it */
1088 sect_off = (offset - sizeof(struct riff_header)) % CDXA_SECTOR_SIZE;
1089 count = min(CDXA_SECTOR_SIZE-sect_off, amount);
1090 if (diff < count) /* Pin transfer amount to EOF */
1091 count = diff;
1092
1093 if (buffer) {
1094 bcopy(CAST_DOWN(caddr_t, (buf_dataptr(bp)+sect_off)), buffer, count);
1095 buffer += count;
1096 } else {
1097 error = uiomove(CAST_DOWN(caddr_t, (buf_dataptr(bp)+sect_off)), count, uio);
1098 }
1099 amount -= count;
1100 offset += count;
1101
1102 /*
1103 * If we copied through the end of the block, or the end of file, then
1104 * age the device block. This is optimized for sequential access.
1105 */
1106 if (sect_off+count == CDXA_SECTOR_SIZE || offset == (off_t)ip->i_size)
1107 buf_markaged(bp);
1108 buf_brelse(bp);
1109 }
1110
1111 return error;
1112 }
1113
1114 /*
1115 * Read from a CD-ROM XA multimedia file.
1116 *
1117 * This uses the same common routine as pagein for doing the actual read
1118 * from the device.
1119 *
1120 * This routine doesn't do any caching beyond what the block device does.
1121 * Even then, cd9660_xa_read_common ages the blocks once we read up to
1122 * the end.
1123 *
1124 * We don't even take advantage if the file has been memory mapped and has
1125 * valid pages already (in which case we could just uiomove from the page
1126 * to the caller). Since we're a read-only filesystem, there can't be
1127 * any cache coherency problems. Multimedia files are expected to be
1128 * large and streamed anyway, so caching file contents probably isn't
1129 * important.
1130 */
1131 int
1132 cd9660_xa_read(struct vnop_read_args *ap)
1133 {
1134 struct vnode *vp = ap->a_vp;
1135 register struct uio *uio = ap->a_uio;
1136 register struct iso_node *ip = VTOI(vp);
1137 off_t offset = uio->uio_offset;
1138 // LP64todo - fix this!
1139 size_t size = uio_resid(uio);
1140
1141 /* Check for some obvious parameter problems */
1142 if (offset < 0)
1143 return EINVAL;
1144 if (size == 0)
1145 return 0;
1146 if (offset >= ip->i_size)
1147 return 0;
1148
1149 /* Pin the size of the read to the file's EOF */
1150 if (offset + size > ip->i_size)
1151 size = ip->i_size - offset;
1152
1153 return cd9660_xa_read_common(vp, offset, size, NULL, uio);
1154 }
1155
1156 /*
1157 * Page in from a CD-ROM XA media file.
1158 *
1159 * Since our device block size isn't a power of two, we can't use
1160 * cluster_pagein. Instead, we have to map the page and read into it.
1161 */
1162 static int
1163 cd9660_xa_pagein(struct vnop_pagein_args *ap)
1164 {
1165 struct vnode *vp = ap->a_vp;
1166 upl_t pl = ap->a_pl;
1167 size_t size= ap->a_size;
1168 off_t f_offset = ap->a_f_offset;
1169 vm_offset_t pl_offset = ap->a_pl_offset;
1170 int flags = ap->a_flags;
1171 register struct iso_node *ip = VTOI(vp);
1172 int error;
1173 kern_return_t kret;
1174 vm_offset_t ioaddr;
1175
1176 /* check pageins are for reg file only and ubc info is present*/
1177 if (UBCINVALID(vp))
1178 panic("cd9660_xa_pagein: Not a VREG");
1179 UBCINFOCHECK("cd9660_xa_pagein", vp);
1180
1181 if (size <= 0)
1182 panic("cd9660_xa_pagein: size = %d", size);
1183
1184 kret = ubc_upl_map(pl, &ioaddr);
1185 if (kret != KERN_SUCCESS)
1186 panic("cd9660_xa_pagein: ubc_upl_map error = %d", kret);
1187
1188 ioaddr += pl_offset;
1189
1190 /* Make sure pagein doesn't extend past EOF */
1191 if (f_offset + size > ip->i_size)
1192 size = ip->i_size - f_offset; /* pin size to EOF */
1193
1194 /* Read the data in using the underlying device */
1195 error = cd9660_xa_read_common(vp, f_offset, size, (caddr_t)ioaddr, NULL);
1196
1197 /* Zero fill part of page past EOF */
1198 if (ap->a_size > size)
1199 bzero((caddr_t)ioaddr+size, ap->a_size-size);
1200
1201 kret = ubc_upl_unmap(pl);
1202 if (kret != KERN_SUCCESS)
1203 panic("cd9660_xa_pagein: ubc_upl_unmap error = %d", kret);
1204
1205 if ((flags & UPL_NOCOMMIT) == 0)
1206 {
1207 if (error)
1208 ubc_upl_abort_range(pl, pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY);
1209 else
1210 ubc_upl_commit_range(pl, pl_offset, ap->a_size, UPL_COMMIT_FREE_ON_EMPTY);
1211 }
1212
1213 return error;
1214 }
1215
1216 /*
1217 * Global vfs data structures for isofs
1218 */
1219 #define cd9660_create \
1220 ((int (*)(struct vnop_create_args *))err_create)
1221 #define cd9660_mknod ((int (*)(struct vnop_mknod_args *))err_mknod)
1222 #define cd9660_write ((int (*)(struct vnop_write_args *))cd9660_enotsupp)
1223 #define cd9660_fsync ((int (*)(struct vnop_fsync_args *))nullop)
1224 #define cd9660_rename \
1225 ((int (*)(struct vnop_rename_args *))err_rename)
1226 #define cd9660_copyfile \
1227 ((int (*)(struct vnop_copyfile_args *))err_copyfile)
1228 #define cd9660_link ((int (*)(struct vnop_link_args *))err_link)
1229 #define cd9660_mkdir ((int (*)(struct vnop_mkdir_args *))err_mkdir)
1230 #define cd9660_symlink \
1231 ((int (*)(struct vnop_symlink_args *))err_symlink)
1232 #define cd9660_advlock \
1233 ((int (*)(struct vnop_advlock_args *))cd9660_enotsupp)
1234 #define cd9660_bwrite \
1235 ((int (*)(struct vnop_bwrite_args *))cd9660_enotsupp)
1236 #define cd9660_pageout \
1237 ((int (*)(struct vnop_pageout_args *))cd9660_enotsupp)
1238 int cd9660_blktooff(struct vnop_blktooff_args *ap);
1239 int cd9660_offtoblk(struct vnop_offtoblk_args *ap);
1240 int cd9660_blockmap(struct vnop_blockmap_args *ap);
1241
1242 #define VOPFUNC int (*)(void *)
1243 /*
1244 * Global vfs data structures for cd9660
1245 */
1246 int (**cd9660_vnodeop_p)(void *);
1247 struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
1248 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1249 { &vnop_lookup_desc, (VOPFUNC)cd9660_lookup }, /* lookup */
1250 { &vnop_create_desc, (VOPFUNC)cd9660_create }, /* create */
1251 { &vnop_mknod_desc, (VOPFUNC)cd9660_mknod }, /* mknod */
1252 { &vnop_open_desc, (VOPFUNC)cd9660_open }, /* open */
1253 { &vnop_close_desc, (VOPFUNC)cd9660_close }, /* close */
1254 { &vnop_getattr_desc, (VOPFUNC)cd9660_getattr }, /* getattr */
1255 { &vnop_read_desc, (VOPFUNC)cd9660_read }, /* read */
1256 { &vnop_write_desc, (VOPFUNC)cd9660_write }, /* write */
1257 { &vnop_ioctl_desc, (VOPFUNC)cd9660_ioctl }, /* ioctl */
1258 { &vnop_select_desc, (VOPFUNC)cd9660_select }, /* select */
1259 { &vnop_mmap_desc, (VOPFUNC)cd9660_mmap }, /* mmap */
1260 { &vnop_fsync_desc, (VOPFUNC)cd9660_fsync }, /* fsync */
1261 { &vnop_remove_desc, (VOPFUNC)cd9660_remove }, /* remove */
1262 { &vnop_link_desc, (VOPFUNC)cd9660_link }, /* link */
1263 { &vnop_rename_desc, (VOPFUNC)cd9660_rename }, /* rename */
1264 { &vnop_copyfile_desc, (VOPFUNC)cd9660_copyfile },/* copyfile */
1265 { &vnop_mkdir_desc, (VOPFUNC)cd9660_mkdir }, /* mkdir */
1266 { &vnop_rmdir_desc, (VOPFUNC)cd9660_rmdir }, /* rmdir */
1267 { &vnop_symlink_desc, (VOPFUNC)cd9660_symlink }, /* symlink */
1268 { &vnop_readdir_desc, (VOPFUNC)cd9660_readdir }, /* readdir */
1269 { &vnop_readlink_desc, (VOPFUNC)cd9660_readlink },/* readlink */
1270 { &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },/* inactive */
1271 { &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim }, /* reclaim */
1272 { &vnop_strategy_desc, (VOPFUNC)cd9660_strategy },/* strategy */
1273 { &vnop_pathconf_desc, (VOPFUNC)cd9660_pathconf },/* pathconf */
1274 { &vnop_advlock_desc, (VOPFUNC)cd9660_advlock }, /* advlock */
1275 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
1276 { &vnop_pagein_desc, (VOPFUNC)cd9660_pagein }, /* Pagein */
1277 { &vnop_pageout_desc, (VOPFUNC)cd9660_pageout }, /* Pageout */
1278 { &vnop_getattrlist_desc, (VOPFUNC)cd9660_getattrlist }, /* getattrlist */
1279 { &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff }, /* blktooff */
1280 { &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk }, /* offtoblk */
1281 { &vnop_blockmap_desc, (VOPFUNC)cd9660_blockmap }, /* blockmap */
1282 { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
1283 };
1284 struct vnodeopv_desc cd9660_vnodeop_opv_desc =
1285 { &cd9660_vnodeop_p, cd9660_vnodeop_entries };
1286
1287 /*
1288 * The VOP table for CD-ROM XA (media) files is almost the same
1289 * as for ordinary files, except for read, and pagein.
1290 * Note that cd9660_xa_read doesn't use cluster I/O, so blockmap
1291 * isn't needed, and isn't implemented. Similarly, it doesn't
1292 * do buf_bread() on CD XA vnodes, so bmap, blktooff, offtoblk
1293 * aren't needed.
1294 */
1295 int (**cd9660_cdxaop_p)(void *);
1296 struct vnodeopv_entry_desc cd9660_cdxaop_entries[] = {
1297 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1298 { &vnop_lookup_desc, (VOPFUNC)cd9660_lookup }, /* lookup */
1299 { &vnop_create_desc, (VOPFUNC)cd9660_create }, /* create */
1300 { &vnop_mknod_desc, (VOPFUNC)cd9660_mknod }, /* mknod */
1301 { &vnop_open_desc, (VOPFUNC)cd9660_open }, /* open */
1302 { &vnop_close_desc, (VOPFUNC)cd9660_close }, /* close */
1303 { &vnop_getattr_desc, (VOPFUNC)cd9660_getattr }, /* getattr */
1304 { &vnop_read_desc, (VOPFUNC)cd9660_xa_read }, /* read */
1305 { &vnop_write_desc, (VOPFUNC)cd9660_write }, /* write */
1306 { &vnop_ioctl_desc, (VOPFUNC)cd9660_ioctl }, /* ioctl */
1307 { &vnop_select_desc, (VOPFUNC)cd9660_select }, /* select */
1308 { &vnop_mmap_desc, (VOPFUNC)cd9660_mmap }, /* mmap */
1309 { &vnop_fsync_desc, (VOPFUNC)cd9660_fsync }, /* fsync */
1310 { &vnop_remove_desc, (VOPFUNC)cd9660_remove }, /* remove */
1311 { &vnop_link_desc, (VOPFUNC)cd9660_link }, /* link */
1312 { &vnop_rename_desc, (VOPFUNC)cd9660_rename }, /* rename */
1313 { &vnop_copyfile_desc, (VOPFUNC)cd9660_copyfile },/* copyfile */
1314 { &vnop_mkdir_desc, (VOPFUNC)cd9660_mkdir }, /* mkdir */
1315 { &vnop_rmdir_desc, (VOPFUNC)cd9660_rmdir }, /* rmdir */
1316 { &vnop_symlink_desc, (VOPFUNC)cd9660_symlink }, /* symlink */
1317 { &vnop_readdir_desc, (VOPFUNC)cd9660_readdir }, /* readdir */
1318 { &vnop_readlink_desc, (VOPFUNC)cd9660_readlink },/* readlink */
1319 { &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },/* inactive */
1320 { &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim }, /* reclaim */
1321 { &vnop_strategy_desc, (VOPFUNC)cd9660_strategy },/* strategy */
1322 { &vnop_pathconf_desc, (VOPFUNC)cd9660_pathconf },/* pathconf */
1323 { &vnop_advlock_desc, (VOPFUNC)cd9660_advlock }, /* advlock */
1324 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
1325 { &vnop_pagein_desc, (VOPFUNC)cd9660_xa_pagein }, /* Pagein */
1326 { &vnop_pageout_desc, (VOPFUNC)cd9660_pageout }, /* Pageout */
1327 { &vnop_getattrlist_desc, (VOPFUNC)cd9660_getattrlist }, /* getattrlist */
1328 { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
1329 };
1330 struct vnodeopv_desc cd9660_cdxaop_opv_desc =
1331 { &cd9660_cdxaop_p, cd9660_cdxaop_entries };
1332
1333 /*
1334 * Special device vnode ops
1335 */
1336 int (**cd9660_specop_p)(void *);
1337 struct vnodeopv_entry_desc cd9660_specop_entries[] = {
1338 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1339 { &vnop_lookup_desc, (VOPFUNC)spec_lookup }, /* lookup */
1340 { &vnop_create_desc, (VOPFUNC)spec_create }, /* create */
1341 { &vnop_mknod_desc, (VOPFUNC)spec_mknod }, /* mknod */
1342 { &vnop_open_desc, (VOPFUNC)spec_open }, /* open */
1343 { &vnop_close_desc, (VOPFUNC)spec_close }, /* close */
1344 { &vnop_getattr_desc, (VOPFUNC)cd9660_getattr }, /* getattr */
1345 { &vnop_read_desc, (VOPFUNC)spec_read }, /* read */
1346 { &vnop_write_desc, (VOPFUNC)spec_write }, /* write */
1347 { &vnop_ioctl_desc, (VOPFUNC)spec_ioctl }, /* ioctl */
1348 { &vnop_select_desc, (VOPFUNC)spec_select }, /* select */
1349 { &vnop_mmap_desc, (VOPFUNC)spec_mmap }, /* mmap */
1350 { &vnop_fsync_desc, (VOPFUNC)spec_fsync }, /* fsync */
1351 { &vnop_remove_desc, (VOPFUNC)spec_remove }, /* remove */
1352 { &vnop_link_desc, (VOPFUNC)spec_link }, /* link */
1353 { &vnop_rename_desc, (VOPFUNC)spec_rename }, /* rename */
1354 { &vnop_mkdir_desc, (VOPFUNC)spec_mkdir }, /* mkdir */
1355 { &vnop_rmdir_desc, (VOPFUNC)spec_rmdir }, /* rmdir */
1356 { &vnop_symlink_desc, (VOPFUNC)spec_symlink }, /* symlink */
1357 { &vnop_readdir_desc, (VOPFUNC)spec_readdir }, /* readdir */
1358 { &vnop_readlink_desc, (VOPFUNC)spec_readlink }, /* readlink */
1359 { &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },/* inactive */
1360 { &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim }, /* reclaim */
1361 { &vnop_strategy_desc, (VOPFUNC)spec_strategy }, /* strategy */
1362 { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf }, /* pathconf */
1363 { &vnop_advlock_desc, (VOPFUNC)spec_advlock }, /* advlock */
1364 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
1365 { &vnop_devblocksize_desc, (VOPFUNC)spec_devblocksize }, /* devblocksize */
1366 { &vnop_pagein_desc, (VOPFUNC)cd9660_pagein }, /* Pagein */
1367 { &vnop_pageout_desc, (VOPFUNC)cd9660_pageout }, /* Pageout */
1368 { &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff }, /* blktooff */
1369 { &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk }, /* offtoblk */
1370 { &vnop_blockmap_desc, (VOPFUNC)cd9660_blockmap }, /* blockmap */
1371 { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
1372 };
1373 struct vnodeopv_desc cd9660_specop_opv_desc =
1374 { &cd9660_specop_p, cd9660_specop_entries };
1375
1376 #if FIFO
1377 int (**cd9660_fifoop_p)(void *);
1378 struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
1379 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1380 { &vnop_lookup_desc, (VOPFUNC)fifo_lookup }, /* lookup */
1381 { &vnop_create_desc, (VOPFUNC)fifo_create }, /* create */
1382 { &vnop_mknod_desc, (VOPFUNC)fifo_mknod }, /* mknod */
1383 { &vnop_open_desc, (VOPFUNC)fifo_open }, /* open */
1384 { &vnop_close_desc, (VOPFUNC)fifo_close }, /* close */
1385 { &vnop_getattr_desc, (VOPFUNC)cd9660_getattr }, /* getattr */
1386 { &vnop_read_desc, (VOPFUNC)fifo_read }, /* read */
1387 { &vnop_write_desc, (VOPFUNC)fifo_write }, /* write */
1388 { &vnop_ioctl_desc, (VOPFUNC)fifo_ioctl }, /* ioctl */
1389 { &vnop_select_desc, (VOPFUNC)fifo_select }, /* select */
1390 { &vnop_mmap_desc, (VOPFUNC)fifo_mmap }, /* mmap */
1391 { &vnop_fsync_desc, (VOPFUNC)fifo_fsync }, /* fsync */
1392 { &vnop_remove_desc, (VOPFUNC)fifo_remove }, /* remove */
1393 { &vnop_link_desc, (VOPFUNC)fifo_link } , /* link */
1394 { &vnop_rename_desc, (VOPFUNC)fifo_rename }, /* rename */
1395 { &vnop_mkdir_desc, (VOPFUNC)fifo_mkdir }, /* mkdir */
1396 { &vnop_rmdir_desc, (VOPFUNC)fifo_rmdir }, /* rmdir */
1397 { &vnop_symlink_desc, (VOPFUNC)fifo_symlink }, /* symlink */
1398 { &vnop_readdir_desc, (VOPFUNC)fifo_readdir }, /* readdir */
1399 { &vnop_readlink_desc, (VOPFUNC)fifo_readlink }, /* readlink */
1400 { &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },/* inactive */
1401 { &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim }, /* reclaim */
1402 { &vnop_strategy_desc, (VOPFUNC)fifo_strategy }, /* strategy */
1403 { &vnop_pathconf_desc, (VOPFUNC)fifo_pathconf }, /* pathconf */
1404 { &vnop_advlock_desc, (VOPFUNC)fifo_advlock }, /* advlock */
1405 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
1406 { &vnop_pagein_desc, (VOPFUNC)cd9660_pagein }, /* Pagein */
1407 { &vnop_pageout_desc, (VOPFUNC)cd9660_pageout }, /* Pageout */
1408 { &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff }, /* blktooff */
1409 { &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk }, /* offtoblk */
1410 { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
1411 };
1412 struct vnodeopv_desc cd9660_fifoop_opv_desc =
1413 { &cd9660_fifoop_p, cd9660_fifoop_entries };
1414 #endif /* FIFO */