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