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.19 (Berkeley) 5/27/95 39 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vnops.c,v 1.62 1999/12/15 23:01:51 eivind Exp $ 40 * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.7 2003/08/20 09:56:32 rob Exp $ 41 */ 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/proc.h> 46 #include <sys/namei.h> 47 #include <sys/kernel.h> 48 #include <sys/stat.h> 49 #include <sys/buf.h> 50 #include <sys/mount.h> 51 #include <sys/vnode.h> 52 #include <vfs/fifofs/fifo.h> 53 #include <sys/malloc.h> 54 #include <sys/dirent.h> 55 #include <sys/unistd.h> 56 #include <sys/filio.h> 57 58 #include <vm/vm.h> 59 #include <vm/vm_zone.h> 60 #include <vm/vnode_pager.h> 61 62 #include "iso.h" 63 #include "cd9660_node.h" 64 #include "iso_rrip.h" 65 66 static int cd9660_setattr (struct vop_setattr_args *); 67 static int cd9660_access (struct vop_access_args *); 68 static int cd9660_getattr (struct vop_getattr_args *); 69 static int cd9660_ioctl (struct vop_ioctl_args *); 70 static int cd9660_pathconf (struct vop_pathconf_args *); 71 static int cd9660_read (struct vop_read_args *); 72 struct isoreaddir; 73 static int iso_uiodir (struct isoreaddir *idp, struct dirent *dp, 74 off_t off); 75 static int iso_shipdir (struct isoreaddir *idp); 76 static int cd9660_readdir (struct vop_readdir_args *); 77 static int cd9660_readlink (struct vop_readlink_args *ap); 78 static int cd9660_strategy (struct vop_strategy_args *); 79 static int cd9660_print (struct vop_print_args *); 80 static int cd9660_getpages (struct vop_getpages_args *); 81 static int cd9660_putpages (struct vop_putpages_args *); 82 83 /* 84 * Setattr call. Only allowed for block and character special devices. 85 */ 86 int 87 cd9660_setattr(ap) 88 struct vop_setattr_args /* { 89 struct vnodeop_desc *a_desc; 90 struct vnode *a_vp; 91 struct vattr *a_vap; 92 struct ucred *a_cred; 93 struct proc *a_p; 94 } */ *ap; 95 { 96 struct vnode *vp = ap->a_vp; 97 struct vattr *vap = ap->a_vap; 98 99 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL || 100 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL || 101 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) 102 return (EROFS); 103 if (vap->va_size != (u_quad_t)VNOVAL) { 104 switch (vp->v_type) { 105 case VDIR: 106 return (EISDIR); 107 case VLNK: 108 case VREG: 109 return (EROFS); 110 case VCHR: 111 case VBLK: 112 case VSOCK: 113 case VFIFO: 114 case VNON: 115 case VBAD: 116 return (0); 117 } 118 } 119 return (0); 120 } 121 122 /* 123 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 124 * The mode is shifted to select the owner/group/other fields. The 125 * super user is granted all permissions. 126 */ 127 /* ARGSUSED */ 128 static int 129 cd9660_access(ap) 130 struct vop_access_args /* { 131 struct vnode *a_vp; 132 int a_mode; 133 struct ucred *a_cred; 134 struct proc *a_p; 135 } */ *ap; 136 { 137 struct vnode *vp = ap->a_vp; 138 struct iso_node *ip = VTOI(vp); 139 struct ucred *cred = ap->a_cred; 140 mode_t mask, mode = ap->a_mode; 141 gid_t *gp; 142 int i; 143 144 /* 145 * Disallow write attempts unless the file is a socket, 146 * fifo, or a block or character device resident on the 147 * file system. 148 */ 149 if (mode & VWRITE) { 150 switch (vp->v_type) { 151 case VDIR: 152 case VLNK: 153 case VREG: 154 return (EROFS); 155 /* NOT REACHED */ 156 default: 157 break; 158 } 159 } 160 161 /* User id 0 always gets access. */ 162 if (cred->cr_uid == 0) 163 return (0); 164 165 mask = 0; 166 167 /* Otherwise, check the owner. */ 168 if (cred->cr_uid == ip->inode.iso_uid) { 169 if (mode & VEXEC) 170 mask |= S_IXUSR; 171 if (mode & VREAD) 172 mask |= S_IRUSR; 173 if (mode & VWRITE) 174 mask |= S_IWUSR; 175 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES); 176 } 177 178 /* Otherwise, check the groups. */ 179 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) 180 if (ip->inode.iso_gid == *gp) { 181 if (mode & VEXEC) 182 mask |= S_IXGRP; 183 if (mode & VREAD) 184 mask |= S_IRGRP; 185 if (mode & VWRITE) 186 mask |= S_IWGRP; 187 return ((ip->inode.iso_mode & mask) == mask ? 188 0 : EACCES); 189 } 190 191 /* Otherwise, check everyone else. */ 192 if (mode & VEXEC) 193 mask |= S_IXOTH; 194 if (mode & VREAD) 195 mask |= S_IROTH; 196 if (mode & VWRITE) 197 mask |= S_IWOTH; 198 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES); 199 } 200 201 static int 202 cd9660_getattr(ap) 203 struct vop_getattr_args /* { 204 struct vnode *a_vp; 205 struct vattr *a_vap; 206 struct thread *a_td; 207 } */ *ap; 208 209 { 210 struct vnode *vp = ap->a_vp; 211 struct vattr *vap = ap->a_vap; 212 struct iso_node *ip = VTOI(vp); 213 214 vap->va_fsid = dev2udev(ip->i_dev); 215 vap->va_fileid = ip->i_number; 216 217 vap->va_mode = ip->inode.iso_mode; 218 vap->va_nlink = ip->inode.iso_links; 219 vap->va_uid = ip->inode.iso_uid; 220 vap->va_gid = ip->inode.iso_gid; 221 vap->va_atime = ip->inode.iso_atime; 222 vap->va_mtime = ip->inode.iso_mtime; 223 vap->va_ctime = ip->inode.iso_ctime; 224 vap->va_rdev = ip->inode.iso_rdev; 225 226 vap->va_size = (u_quad_t) ip->i_size; 227 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) { 228 struct vop_readlink_args rdlnk; 229 struct iovec aiov; 230 struct uio auio; 231 char *cp; 232 233 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK); 234 aiov.iov_base = cp; 235 aiov.iov_len = MAXPATHLEN; 236 auio.uio_iov = &aiov; 237 auio.uio_iovcnt = 1; 238 auio.uio_offset = 0; 239 auio.uio_rw = UIO_READ; 240 auio.uio_segflg = UIO_SYSSPACE; 241 auio.uio_td = ap->a_td; 242 auio.uio_resid = MAXPATHLEN; 243 rdlnk.a_uio = &auio; 244 rdlnk.a_vp = ap->a_vp; 245 rdlnk.a_cred = proc0.p_ucred; /* use root cred */ 246 if (cd9660_readlink(&rdlnk) == 0) 247 vap->va_size = MAXPATHLEN - auio.uio_resid; 248 FREE(cp, M_TEMP); 249 } 250 vap->va_flags = 0; 251 vap->va_gen = 1; 252 vap->va_blocksize = ip->i_mnt->logical_block_size; 253 vap->va_bytes = (u_quad_t) ip->i_size; 254 vap->va_type = vp->v_type; 255 vap->va_filerev = 0; 256 return (0); 257 } 258 259 /* 260 * Vnode op for ioctl. 261 */ 262 static int 263 cd9660_ioctl(ap) 264 struct vop_ioctl_args /* { 265 struct vnode *a_vp; 266 int a_command; 267 caddr_t a_data; 268 int a_fflag; 269 struct ucred *a_cred; 270 struct proc *a_p; 271 } */ *ap; 272 { 273 struct vnode *vp = ap->a_vp; 274 struct iso_node *ip = VTOI(vp); 275 276 switch (ap->a_command) { 277 278 case FIOGETLBA: 279 *(int *)(ap->a_data) = ip->iso_start; 280 return 0; 281 default: 282 return (ENOTTY); 283 } 284 } 285 286 /* 287 * Vnode op for reading. 288 */ 289 static int 290 cd9660_read(ap) 291 struct vop_read_args /* { 292 struct vnode *a_vp; 293 struct uio *a_uio; 294 int a_ioflag; 295 struct ucred *a_cred; 296 } */ *ap; 297 { 298 struct vnode *vp = ap->a_vp; 299 struct uio *uio = ap->a_uio; 300 struct iso_node *ip = VTOI(vp); 301 struct iso_mnt *imp; 302 struct buf *bp; 303 daddr_t lbn, rablock; 304 off_t diff; 305 int rasize, error = 0; 306 int seqcount; 307 long size, n, on; 308 309 seqcount = ap->a_ioflag >> 16; 310 311 if (uio->uio_resid == 0) 312 return (0); 313 if (uio->uio_offset < 0) 314 return (EINVAL); 315 ip->i_flag |= IN_ACCESS; 316 imp = ip->i_mnt; 317 do { 318 lbn = lblkno(imp, uio->uio_offset); 319 on = blkoff(imp, uio->uio_offset); 320 n = min((u_int)(imp->logical_block_size - on), 321 uio->uio_resid); 322 diff = (off_t)ip->i_size - uio->uio_offset; 323 if (diff <= 0) 324 return (0); 325 if (diff < n) 326 n = diff; 327 size = blksize(imp, ip, lbn); 328 rablock = lbn + 1; 329 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) { 330 if (lblktosize(imp, rablock) < ip->i_size) 331 error = cluster_read(vp, (off_t)ip->i_size, 332 lbn, size, uio->uio_resid, 333 (ap->a_ioflag >> 16), &bp); 334 else 335 error = bread(vp, lbn, size, &bp); 336 } else { 337 if (seqcount > 1 && 338 lblktosize(imp, rablock) < ip->i_size) { 339 rasize = blksize(imp, ip, rablock); 340 error = breadn(vp, lbn, size, &rablock, 341 &rasize, 1, &bp); 342 } else 343 error = bread(vp, lbn, size, &bp); 344 } 345 n = min(n, size - bp->b_resid); 346 if (error) { 347 brelse(bp); 348 return (error); 349 } 350 351 error = uiomove(bp->b_data + on, (int)n, uio); 352 brelse(bp); 353 } while (error == 0 && uio->uio_resid > 0 && n != 0); 354 return (error); 355 } 356 357 /* 358 * Structure for reading directories 359 */ 360 struct isoreaddir { 361 struct dirent saveent; 362 struct dirent assocent; 363 struct dirent current; 364 off_t saveoff; 365 off_t assocoff; 366 off_t curroff; 367 struct uio *uio; 368 off_t uio_off; 369 int eofflag; 370 u_long *cookies; 371 int ncookies; 372 }; 373 374 int 375 iso_uiodir(idp,dp,off) 376 struct isoreaddir *idp; 377 struct dirent *dp; 378 off_t off; 379 { 380 int error; 381 382 dp->d_name[dp->d_namlen] = 0; 383 dp->d_reclen = GENERIC_DIRSIZ(dp); 384 385 if (idp->uio->uio_resid < dp->d_reclen) { 386 idp->eofflag = 0; 387 return (-1); 388 } 389 390 if (idp->cookies) { 391 if (idp->ncookies <= 0) { 392 idp->eofflag = 0; 393 return (-1); 394 } 395 396 *idp->cookies++ = off; 397 --idp->ncookies; 398 } 399 400 if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0) 401 return (error); 402 idp->uio_off = off; 403 return (0); 404 } 405 406 int 407 iso_shipdir(idp) 408 struct isoreaddir *idp; 409 { 410 struct dirent *dp; 411 int cl, sl, assoc; 412 int error; 413 char *cname, *sname; 414 415 cl = idp->current.d_namlen; 416 cname = idp->current.d_name; 417 assoc = (cl > 1) && (*cname == ASSOCCHAR); 418 if (assoc) { 419 cl--; 420 cname++; 421 } 422 423 dp = &idp->saveent; 424 sname = dp->d_name; 425 if (!(sl = dp->d_namlen)) { 426 dp = &idp->assocent; 427 sname = dp->d_name + 1; 428 sl = dp->d_namlen - 1; 429 } 430 if (sl > 0) { 431 if (sl != cl 432 || bcmp(sname,cname,sl)) { 433 if (idp->assocent.d_namlen) { 434 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0) 435 return (error); 436 idp->assocent.d_namlen = 0; 437 } 438 if (idp->saveent.d_namlen) { 439 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0) 440 return (error); 441 idp->saveent.d_namlen = 0; 442 } 443 } 444 } 445 idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current); 446 if (assoc) { 447 idp->assocoff = idp->curroff; 448 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen); 449 } else { 450 idp->saveoff = idp->curroff; 451 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen); 452 } 453 return (0); 454 } 455 456 /* 457 * Vnode op for readdir 458 */ 459 static int 460 cd9660_readdir(ap) 461 struct vop_readdir_args /* { 462 struct vnode *a_vp; 463 struct uio *a_uio; 464 struct ucred *a_cred; 465 int *a_eofflag; 466 int *a_ncookies; 467 u_long *a_cookies; 468 } */ *ap; 469 { 470 struct uio *uio = ap->a_uio; 471 struct isoreaddir *idp; 472 struct vnode *vdp = ap->a_vp; 473 struct iso_node *dp; 474 struct iso_mnt *imp; 475 struct buf *bp = NULL; 476 struct iso_directory_record *ep; 477 int entryoffsetinblock; 478 doff_t endsearch; 479 u_long bmask; 480 int error = 0; 481 int reclen; 482 u_short namelen; 483 int ncookies = 0; 484 u_long *cookies = NULL; 485 486 dp = VTOI(vdp); 487 imp = dp->i_mnt; 488 bmask = imp->im_bmask; 489 490 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK); 491 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 492 /* 493 * XXX 494 * Is it worth trying to figure out the type? 495 */ 496 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 497 DT_UNKNOWN; 498 idp->uio = uio; 499 if (ap->a_ncookies == NULL) { 500 idp->cookies = NULL; 501 } else { 502 /* 503 * Guess the number of cookies needed. 504 */ 505 ncookies = uio->uio_resid / 16; 506 MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP, 507 M_WAITOK); 508 idp->cookies = cookies; 509 idp->ncookies = ncookies; 510 } 511 idp->eofflag = 1; 512 idp->curroff = uio->uio_offset; 513 514 if ((entryoffsetinblock = idp->curroff & bmask) && 515 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 516 FREE(idp, M_TEMP); 517 return (error); 518 } 519 endsearch = dp->i_size; 520 521 while (idp->curroff < endsearch) { 522 /* 523 * If offset is on a block boundary, 524 * read the next directory block. 525 * Release previous if it exists. 526 */ 527 if ((idp->curroff & bmask) == 0) { 528 if (bp != NULL) 529 brelse(bp); 530 if ((error = 531 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0) 532 break; 533 entryoffsetinblock = 0; 534 } 535 /* 536 * Get pointer to next entry. 537 */ 538 ep = (struct iso_directory_record *) 539 ((char *)bp->b_data + entryoffsetinblock); 540 541 reclen = isonum_711(ep->length); 542 if (reclen == 0) { 543 /* skip to next block, if any */ 544 idp->curroff = 545 (idp->curroff & ~bmask) + imp->logical_block_size; 546 continue; 547 } 548 549 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 550 error = EINVAL; 551 /* illegal entry, stop */ 552 break; 553 } 554 555 if (entryoffsetinblock + reclen > imp->logical_block_size) { 556 error = EINVAL; 557 /* illegal directory, so stop looking */ 558 break; 559 } 560 561 idp->current.d_namlen = isonum_711(ep->name_len); 562 563 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 564 error = EINVAL; 565 /* illegal entry, stop */ 566 break; 567 } 568 569 if (isonum_711(ep->flags)&2) 570 idp->current.d_fileno = isodirino(ep, imp); 571 else 572 idp->current.d_fileno = dbtob(bp->b_blkno) + 573 entryoffsetinblock; 574 575 idp->curroff += reclen; 576 577 switch (imp->iso_ftype) { 578 case ISO_FTYPE_RRIP: 579 cd9660_rrip_getname(ep,idp->current.d_name, &namelen, 580 &idp->current.d_fileno,imp); 581 idp->current.d_namlen = (u_char)namelen; 582 if (idp->current.d_namlen) 583 error = iso_uiodir(idp,&idp->current,idp->curroff); 584 break; 585 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/ 586 strcpy(idp->current.d_name,".."); 587 if (idp->current.d_namlen == 1 && ep->name[0] == 0) { 588 idp->current.d_namlen = 1; 589 error = iso_uiodir(idp,&idp->current,idp->curroff); 590 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) { 591 idp->current.d_namlen = 2; 592 error = iso_uiodir(idp,&idp->current,idp->curroff); 593 } else { 594 isofntrans(ep->name,idp->current.d_namlen, 595 idp->current.d_name, &namelen, 596 imp->iso_ftype == ISO_FTYPE_9660, 597 isonum_711(ep->flags)&4, 598 imp->joliet_level); 599 idp->current.d_namlen = (u_char)namelen; 600 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 601 error = iso_shipdir(idp); 602 else 603 error = iso_uiodir(idp,&idp->current,idp->curroff); 604 } 605 } 606 if (error) 607 break; 608 609 entryoffsetinblock += reclen; 610 } 611 612 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 613 idp->current.d_namlen = 0; 614 error = iso_shipdir(idp); 615 } 616 if (error < 0) 617 error = 0; 618 619 if (ap->a_ncookies != NULL) { 620 if (error) 621 free(cookies, M_TEMP); 622 else { 623 /* 624 * Work out the number of cookies actually used. 625 */ 626 *ap->a_ncookies = ncookies - idp->ncookies; 627 *ap->a_cookies = cookies; 628 } 629 } 630 631 if (bp) 632 brelse (bp); 633 634 uio->uio_offset = idp->uio_off; 635 *ap->a_eofflag = idp->eofflag; 636 637 FREE(idp, M_TEMP); 638 639 return (error); 640 } 641 642 /* 643 * Return target name of a symbolic link 644 * Shouldn't we get the parent vnode and read the data from there? 645 * This could eventually result in deadlocks in cd9660_lookup. 646 * But otherwise the block read here is in the block buffer two times. 647 */ 648 typedef struct iso_directory_record ISODIR; 649 typedef struct iso_node ISONODE; 650 typedef struct iso_mnt ISOMNT; 651 static int 652 cd9660_readlink(ap) 653 struct vop_readlink_args /* { 654 struct vnode *a_vp; 655 struct uio *a_uio; 656 struct ucred *a_cred; 657 } */ *ap; 658 { 659 ISONODE *ip; 660 ISODIR *dirp; 661 ISOMNT *imp; 662 struct buf *bp; 663 struct uio *uio; 664 u_short symlen; 665 int error; 666 char *symname; 667 668 ip = VTOI(ap->a_vp); 669 imp = ip->i_mnt; 670 uio = ap->a_uio; 671 672 if (imp->iso_ftype != ISO_FTYPE_RRIP) 673 return (EINVAL); 674 675 /* 676 * Get parents directory record block that this inode included. 677 */ 678 error = bread(imp->im_devvp, 679 (ip->i_number >> imp->im_bshift) << 680 (imp->im_bshift - DEV_BSHIFT), 681 imp->logical_block_size, &bp); 682 if (error) { 683 brelse(bp); 684 return (EINVAL); 685 } 686 687 /* 688 * Setup the directory pointer for this inode 689 */ 690 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask)); 691 692 /* 693 * Just make sure, we have a right one.... 694 * 1: Check not cross boundary on block 695 */ 696 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 697 > (unsigned)imp->logical_block_size) { 698 brelse(bp); 699 return (EINVAL); 700 } 701 702 /* 703 * Now get a buffer 704 * Abuse a namei buffer for now. 705 */ 706 if (uio->uio_segflg == UIO_SYSSPACE) 707 symname = uio->uio_iov->iov_base; 708 else 709 symname = zalloc(namei_zone); 710 711 /* 712 * Ok, we just gathering a symbolic name in SL record. 713 */ 714 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 715 if (uio->uio_segflg != UIO_SYSSPACE) 716 zfree(namei_zone, symname); 717 brelse(bp); 718 return (EINVAL); 719 } 720 /* 721 * Don't forget before you leave from home ;-) 722 */ 723 brelse(bp); 724 725 /* 726 * return with the symbolic name to caller's. 727 */ 728 if (uio->uio_segflg != UIO_SYSSPACE) { 729 error = uiomove(symname, symlen, uio); 730 zfree(namei_zone, symname); 731 return (error); 732 } 733 uio->uio_resid -= symlen; 734 uio->uio_iov->iov_base += symlen; 735 uio->uio_iov->iov_len -= symlen; 736 return (0); 737 } 738 739 /* 740 * Calculate the logical to physical mapping if not done already, 741 * then call the device strategy routine. 742 */ 743 static int 744 cd9660_strategy(ap) 745 struct vop_strategy_args /* { 746 struct buf *a_vp; 747 struct buf *a_bp; 748 } */ *ap; 749 { 750 struct buf *bp = ap->a_bp; 751 struct vnode *vp = bp->b_vp; 752 struct iso_node *ip; 753 int error; 754 755 ip = VTOI(vp); 756 if (vp->v_type == VBLK || vp->v_type == VCHR) 757 panic("cd9660_strategy: spec"); 758 if (bp->b_blkno == bp->b_lblkno) { 759 if ((error = 760 VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL))) { 761 bp->b_error = error; 762 bp->b_flags |= B_ERROR; 763 biodone(bp); 764 return (error); 765 } 766 if ((long)bp->b_blkno == -1) 767 clrbuf(bp); 768 } 769 if ((long)bp->b_blkno == -1) { 770 biodone(bp); 771 return (0); 772 } 773 vp = ip->i_devvp; 774 bp->b_dev = vp->v_rdev; 775 VOP_STRATEGY(vp, bp); 776 return (0); 777 } 778 779 /* 780 * Print out the contents of an inode. 781 */ 782 static int 783 cd9660_print(ap) 784 struct vop_print_args /* { 785 struct vnode *a_vp; 786 } */ *ap; 787 { 788 789 printf("tag VT_ISOFS, isofs vnode\n"); 790 return (0); 791 } 792 793 /* 794 * Return POSIX pathconf information applicable to cd9660 filesystems. 795 */ 796 static int 797 cd9660_pathconf(ap) 798 struct vop_pathconf_args /* { 799 struct vnode *a_vp; 800 int a_name; 801 register_t *a_retval; 802 } */ *ap; 803 { 804 805 switch (ap->a_name) { 806 case _PC_LINK_MAX: 807 *ap->a_retval = 1; 808 return (0); 809 case _PC_NAME_MAX: 810 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 811 *ap->a_retval = NAME_MAX; 812 else 813 *ap->a_retval = 37; 814 return (0); 815 case _PC_PATH_MAX: 816 *ap->a_retval = PATH_MAX; 817 return (0); 818 case _PC_PIPE_BUF: 819 *ap->a_retval = PIPE_BUF; 820 return (0); 821 case _PC_CHOWN_RESTRICTED: 822 *ap->a_retval = 1; 823 return (0); 824 case _PC_NO_TRUNC: 825 *ap->a_retval = 1; 826 return (0); 827 default: 828 return (EINVAL); 829 } 830 /* NOTREACHED */ 831 } 832 833 /* 834 * get page routine 835 * 836 * XXX By default, wimp out... note that a_offset is ignored (and always 837 * XXX has been). 838 */ 839 int 840 cd9660_getpages(ap) 841 struct vop_getpages_args *ap; 842 { 843 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count, 844 ap->a_reqpage); 845 } 846 847 /* 848 * put page routine 849 * 850 * XXX By default, wimp out... note that a_offset is ignored (and always 851 * XXX has been). 852 */ 853 int 854 cd9660_putpages(ap) 855 struct vop_putpages_args *ap; 856 { 857 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count, 858 ap->a_sync, ap->a_rtvals); 859 } 860 861 /* 862 * Global vfs data structures for cd9660 863 */ 864 vop_t **cd9660_vnodeop_p; 865 static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { 866 { &vop_default_desc, (vop_t *) vop_defaultop }, 867 { &vop_access_desc, (vop_t *) cd9660_access }, 868 { &vop_bmap_desc, (vop_t *) cd9660_bmap }, 869 { &vop_cachedlookup_desc, (vop_t *) cd9660_lookup }, 870 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 871 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 872 { &vop_ioctl_desc, (vop_t *) cd9660_ioctl }, 873 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 874 { &vop_lock_desc, (vop_t *) vop_stdlock }, 875 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup }, 876 { &vop_pathconf_desc, (vop_t *) cd9660_pathconf }, 877 { &vop_print_desc, (vop_t *) cd9660_print }, 878 { &vop_read_desc, (vop_t *) cd9660_read }, 879 { &vop_readdir_desc, (vop_t *) cd9660_readdir }, 880 { &vop_readlink_desc, (vop_t *) cd9660_readlink }, 881 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 882 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 883 { &vop_strategy_desc, (vop_t *) cd9660_strategy }, 884 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 885 { &vop_getpages_desc, (vop_t *) cd9660_getpages }, 886 { &vop_putpages_desc, (vop_t *) cd9660_putpages }, 887 { NULL, NULL } 888 }; 889 static struct vnodeopv_desc cd9660_vnodeop_opv_desc = 890 { &cd9660_vnodeop_p, cd9660_vnodeop_entries }; 891 VNODEOP_SET(cd9660_vnodeop_opv_desc); 892 893 /* 894 * Special device vnode ops 895 */ 896 vop_t **cd9660_specop_p; 897 static struct vnodeopv_entry_desc cd9660_specop_entries[] = { 898 { &vop_default_desc, (vop_t *) spec_vnoperate }, 899 { &vop_access_desc, (vop_t *) cd9660_access }, 900 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 901 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 902 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 903 { &vop_lock_desc, (vop_t *) vop_stdlock }, 904 { &vop_print_desc, (vop_t *) cd9660_print }, 905 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 906 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 907 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 908 { NULL, NULL } 909 }; 910 static struct vnodeopv_desc cd9660_specop_opv_desc = 911 { &cd9660_specop_p, cd9660_specop_entries }; 912 VNODEOP_SET(cd9660_specop_opv_desc); 913 914 vop_t **cd9660_fifoop_p; 915 static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { 916 { &vop_default_desc, (vop_t *) fifo_vnoperate }, 917 { &vop_access_desc, (vop_t *) cd9660_access }, 918 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 919 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 920 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 921 { &vop_lock_desc, (vop_t *) vop_stdlock }, 922 { &vop_print_desc, (vop_t *) cd9660_print }, 923 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 924 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 925 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 926 { NULL, NULL } 927 }; 928 static struct vnodeopv_desc cd9660_fifoop_opv_desc = 929 { &cd9660_fifoop_p, cd9660_fifoop_entries }; 930 931 VNODEOP_SET(cd9660_fifoop_opv_desc); 932