1 /*- 2 * Copyright (c) 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley 6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 7 * Support code is derived from software contributed to Berkeley 8 * by Atsushi Murai (amurai@spec.co.jp). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95 35 */ 36 37 #include <sys/cdefs.h> 38 __FBSDID("$FreeBSD$"); 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/namei.h> 43 #include <sys/kernel.h> 44 #include <sys/conf.h> 45 #include <sys/stat.h> 46 #include <sys/bio.h> 47 #include <sys/buf.h> 48 #include <sys/mount.h> 49 #include <sys/vnode.h> 50 #include <sys/malloc.h> 51 #include <sys/dirent.h> 52 #include <sys/unistd.h> 53 #include <sys/filio.h> 54 55 #include <vm/vm.h> 56 #include <vm/vnode_pager.h> 57 #include <vm/uma.h> 58 59 #include <fs/cd9660/iso.h> 60 #include <fs/cd9660/cd9660_node.h> 61 #include <fs/cd9660/iso_rrip.h> 62 63 static vop_setattr_t cd9660_setattr; 64 static vop_open_t cd9660_open; 65 static vop_access_t cd9660_access; 66 static vop_getattr_t cd9660_getattr; 67 static vop_ioctl_t cd9660_ioctl; 68 static vop_pathconf_t cd9660_pathconf; 69 static vop_read_t cd9660_read; 70 struct isoreaddir; 71 static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off); 72 static int iso_shipdir(struct isoreaddir *idp); 73 static vop_readdir_t cd9660_readdir; 74 static vop_readlink_t cd9660_readlink; 75 static vop_strategy_t cd9660_strategy; 76 static vop_vptofh_t cd9660_vptofh; 77 78 /* 79 * Setattr call. Only allowed for block and character special devices. 80 */ 81 static int 82 cd9660_setattr(ap) 83 struct vop_setattr_args /* { 84 struct vnodeop_desc *a_desc; 85 struct vnode *a_vp; 86 struct vattr *a_vap; 87 struct ucred *a_cred; 88 } */ *ap; 89 { 90 struct vnode *vp = ap->a_vp; 91 struct vattr *vap = ap->a_vap; 92 93 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL || 94 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL || 95 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) 96 return (EROFS); 97 if (vap->va_size != (u_quad_t)VNOVAL) { 98 switch (vp->v_type) { 99 case VDIR: 100 return (EISDIR); 101 case VLNK: 102 case VREG: 103 return (EROFS); 104 case VCHR: 105 case VBLK: 106 case VSOCK: 107 case VFIFO: 108 case VNON: 109 case VBAD: 110 case VMARKER: 111 return (0); 112 } 113 } 114 return (0); 115 } 116 117 /* 118 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 119 * The mode is shifted to select the owner/group/other fields. The 120 * super user is granted all permissions. 121 */ 122 /* ARGSUSED */ 123 static int 124 cd9660_access(ap) 125 struct vop_access_args /* { 126 struct vnode *a_vp; 127 accmode_t a_accmode; 128 struct ucred *a_cred; 129 struct thread *a_td; 130 } */ *ap; 131 { 132 struct vnode *vp = ap->a_vp; 133 struct iso_node *ip = VTOI(vp); 134 accmode_t accmode = ap->a_accmode; 135 136 if (vp->v_type == VCHR || vp->v_type == VBLK) 137 return (EOPNOTSUPP); 138 139 /* 140 * Disallow write attempts unless the file is a socket, 141 * fifo, or a block or character device resident on the 142 * filesystem. 143 */ 144 if (accmode & VWRITE) { 145 switch (vp->v_type) { 146 case VDIR: 147 case VLNK: 148 case VREG: 149 return (EROFS); 150 /* NOT REACHED */ 151 default: 152 break; 153 } 154 } 155 156 return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid, 157 ip->inode.iso_gid, ap->a_accmode, ap->a_cred, NULL)); 158 } 159 160 static int 161 cd9660_open(ap) 162 struct vop_open_args /* { 163 struct vnode *a_vp; 164 int a_mode; 165 struct ucred *a_cred; 166 struct thread *a_td; 167 struct file *a_fp; 168 } */ *ap; 169 { 170 struct vnode *vp = ap->a_vp; 171 struct iso_node *ip = VTOI(vp); 172 173 if (vp->v_type == VCHR || vp->v_type == VBLK) 174 return (EOPNOTSUPP); 175 176 vnode_create_vobject(vp, ip->i_size, ap->a_td); 177 return (0); 178 } 179 180 181 static int 182 cd9660_getattr(ap) 183 struct vop_getattr_args /* { 184 struct vnode *a_vp; 185 struct vattr *a_vap; 186 struct ucred *a_cred; 187 } */ *ap; 188 189 { 190 struct vnode *vp = ap->a_vp; 191 struct vattr *vap = ap->a_vap; 192 struct iso_node *ip = VTOI(vp); 193 194 vap->va_fsid = dev2udev(ip->i_mnt->im_dev); 195 vap->va_fileid = ip->i_number; 196 197 vap->va_mode = ip->inode.iso_mode; 198 vap->va_nlink = ip->inode.iso_links; 199 vap->va_uid = ip->inode.iso_uid; 200 vap->va_gid = ip->inode.iso_gid; 201 vap->va_atime = ip->inode.iso_atime; 202 vap->va_mtime = ip->inode.iso_mtime; 203 vap->va_ctime = ip->inode.iso_ctime; 204 vap->va_rdev = ip->inode.iso_rdev; 205 206 vap->va_size = (u_quad_t) ip->i_size; 207 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) { 208 struct vop_readlink_args rdlnk; 209 struct iovec aiov; 210 struct uio auio; 211 char *cp; 212 213 cp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 214 aiov.iov_base = cp; 215 aiov.iov_len = MAXPATHLEN; 216 auio.uio_iov = &aiov; 217 auio.uio_iovcnt = 1; 218 auio.uio_offset = 0; 219 auio.uio_rw = UIO_READ; 220 auio.uio_segflg = UIO_SYSSPACE; 221 auio.uio_td = curthread; 222 auio.uio_resid = MAXPATHLEN; 223 rdlnk.a_uio = &auio; 224 rdlnk.a_vp = ap->a_vp; 225 rdlnk.a_cred = ap->a_cred; 226 if (cd9660_readlink(&rdlnk) == 0) 227 vap->va_size = MAXPATHLEN - auio.uio_resid; 228 free(cp, M_TEMP); 229 } 230 vap->va_flags = 0; 231 vap->va_gen = 1; 232 vap->va_blocksize = ip->i_mnt->logical_block_size; 233 vap->va_bytes = (u_quad_t) ip->i_size; 234 vap->va_type = vp->v_type; 235 vap->va_filerev = 0; 236 return (0); 237 } 238 239 /* 240 * Vnode op for ioctl. 241 */ 242 static int 243 cd9660_ioctl(ap) 244 struct vop_ioctl_args /* { 245 struct vnode *a_vp; 246 u_long a_command; 247 caddr_t a_data; 248 int a_fflag; 249 struct ucred *a_cred; 250 struct thread *a_td; 251 } */ *ap; 252 { 253 struct vnode *vp; 254 struct iso_node *ip; 255 int error; 256 257 vp = ap->a_vp; 258 vn_lock(vp, LK_SHARED | LK_RETRY); 259 if (vp->v_iflag & VI_DOOMED) { 260 VOP_UNLOCK(vp, 0); 261 return (EBADF); 262 } 263 if (vp->v_type == VCHR || vp->v_type == VBLK) { 264 VOP_UNLOCK(vp, 0); 265 return (EOPNOTSUPP); 266 } 267 268 ip = VTOI(vp); 269 error = 0; 270 271 switch (ap->a_command) { 272 case FIOGETLBA: 273 *(int *)(ap->a_data) = ip->iso_start; 274 break; 275 default: 276 error = ENOTTY; 277 break; 278 } 279 280 VOP_UNLOCK(vp, 0); 281 return (error); 282 } 283 284 /* 285 * Vnode op for reading. 286 */ 287 static int 288 cd9660_read(ap) 289 struct vop_read_args /* { 290 struct vnode *a_vp; 291 struct uio *a_uio; 292 int a_ioflag; 293 struct ucred *a_cred; 294 } */ *ap; 295 { 296 struct vnode *vp = ap->a_vp; 297 struct uio *uio = ap->a_uio; 298 struct iso_node *ip = VTOI(vp); 299 struct iso_mnt *imp; 300 struct buf *bp; 301 daddr_t lbn, rablock; 302 off_t diff; 303 int rasize, error = 0; 304 int seqcount; 305 long size, n, on; 306 307 if (vp->v_type == VCHR || vp->v_type == VBLK) 308 return (EOPNOTSUPP); 309 310 seqcount = ap->a_ioflag >> IO_SEQSHIFT; 311 312 if (uio->uio_resid == 0) 313 return (0); 314 if (uio->uio_offset < 0) 315 return (EINVAL); 316 imp = ip->i_mnt; 317 do { 318 lbn = lblkno(imp, uio->uio_offset); 319 on = blkoff(imp, uio->uio_offset); 320 n = MIN(imp->logical_block_size - on, uio->uio_resid); 321 diff = (off_t)ip->i_size - uio->uio_offset; 322 if (diff <= 0) 323 return (0); 324 if (diff < n) 325 n = diff; 326 size = blksize(imp, ip, lbn); 327 rablock = lbn + 1; 328 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) { 329 if (lblktosize(imp, rablock) < ip->i_size) 330 error = cluster_read(vp, (off_t)ip->i_size, 331 lbn, size, NOCRED, uio->uio_resid, 332 (ap->a_ioflag >> 16), 0, &bp); 333 else 334 error = bread(vp, lbn, size, NOCRED, &bp); 335 } else { 336 if (seqcount > 1 && 337 lblktosize(imp, rablock) < ip->i_size) { 338 rasize = blksize(imp, ip, rablock); 339 error = breadn(vp, lbn, size, &rablock, 340 &rasize, 1, NOCRED, &bp); 341 } else 342 error = bread(vp, lbn, size, NOCRED, &bp); 343 } 344 if (error != 0) 345 return (error); 346 n = MIN(n, size - bp->b_resid); 347 348 error = uiomove(bp->b_data + on, (int)n, uio); 349 brelse(bp); 350 } while (error == 0 && uio->uio_resid > 0 && n != 0); 351 return (error); 352 } 353 354 /* 355 * Structure for reading directories 356 */ 357 struct isoreaddir { 358 struct dirent saveent; 359 struct dirent assocent; 360 struct dirent current; 361 off_t saveoff; 362 off_t assocoff; 363 off_t curroff; 364 struct uio *uio; 365 off_t uio_off; 366 int eofflag; 367 u_long *cookies; 368 int ncookies; 369 }; 370 371 static int 372 iso_uiodir(idp,dp,off) 373 struct isoreaddir *idp; 374 struct dirent *dp; 375 off_t off; 376 { 377 int error; 378 379 dp->d_name[dp->d_namlen] = 0; 380 dp->d_reclen = GENERIC_DIRSIZ(dp); 381 382 if (idp->uio->uio_resid < dp->d_reclen) { 383 idp->eofflag = 0; 384 return (-1); 385 } 386 387 if (idp->cookies) { 388 if (idp->ncookies <= 0) { 389 idp->eofflag = 0; 390 return (-1); 391 } 392 393 *idp->cookies++ = off; 394 --idp->ncookies; 395 } 396 397 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0) 398 return (error); 399 idp->uio_off = off; 400 return (0); 401 } 402 403 static int 404 iso_shipdir(idp) 405 struct isoreaddir *idp; 406 { 407 struct dirent *dp; 408 int cl, sl, assoc; 409 int error; 410 char *cname, *sname; 411 412 cl = idp->current.d_namlen; 413 cname = idp->current.d_name; 414 assoc = (cl > 1) && (*cname == ASSOCCHAR); 415 if (assoc) { 416 cl--; 417 cname++; 418 } 419 420 dp = &idp->saveent; 421 sname = dp->d_name; 422 if (!(sl = dp->d_namlen)) { 423 dp = &idp->assocent; 424 sname = dp->d_name + 1; 425 sl = dp->d_namlen - 1; 426 } 427 if (sl > 0) { 428 if (sl != cl 429 || bcmp(sname,cname,sl)) { 430 if (idp->assocent.d_namlen) { 431 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0) 432 return (error); 433 idp->assocent.d_namlen = 0; 434 } 435 if (idp->saveent.d_namlen) { 436 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0) 437 return (error); 438 idp->saveent.d_namlen = 0; 439 } 440 } 441 } 442 idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current); 443 if (assoc) { 444 idp->assocoff = idp->curroff; 445 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen); 446 } else { 447 idp->saveoff = idp->curroff; 448 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen); 449 } 450 return (0); 451 } 452 453 /* 454 * Vnode op for readdir 455 */ 456 static int 457 cd9660_readdir(ap) 458 struct vop_readdir_args /* { 459 struct vnode *a_vp; 460 struct uio *a_uio; 461 struct ucred *a_cred; 462 int *a_eofflag; 463 int *a_ncookies; 464 u_long **a_cookies; 465 } */ *ap; 466 { 467 struct uio *uio = ap->a_uio; 468 struct isoreaddir *idp; 469 struct vnode *vdp = ap->a_vp; 470 struct iso_node *dp; 471 struct iso_mnt *imp; 472 struct buf *bp = NULL; 473 struct iso_directory_record *ep; 474 int entryoffsetinblock; 475 doff_t endsearch; 476 u_long bmask; 477 int error = 0; 478 int reclen; 479 u_short namelen; 480 int ncookies = 0; 481 u_long *cookies = NULL; 482 483 dp = VTOI(vdp); 484 imp = dp->i_mnt; 485 bmask = imp->im_bmask; 486 487 idp = malloc(sizeof(*idp), M_TEMP, M_WAITOK); 488 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 489 /* 490 * XXX 491 * Is it worth trying to figure out the type? 492 */ 493 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 494 DT_UNKNOWN; 495 idp->uio = uio; 496 if (ap->a_ncookies == NULL) { 497 idp->cookies = NULL; 498 } else { 499 /* 500 * Guess the number of cookies needed. 501 */ 502 ncookies = uio->uio_resid / 16; 503 cookies = malloc(ncookies * sizeof(u_long), 504 M_TEMP, M_WAITOK); 505 idp->cookies = cookies; 506 idp->ncookies = ncookies; 507 } 508 idp->eofflag = 1; 509 idp->curroff = uio->uio_offset; 510 idp->uio_off = uio->uio_offset; 511 512 if ((entryoffsetinblock = idp->curroff & bmask) && 513 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 514 free(idp, M_TEMP); 515 return (error); 516 } 517 endsearch = dp->i_size; 518 519 while (idp->curroff < endsearch) { 520 /* 521 * If offset is on a block boundary, 522 * read the next directory block. 523 * Release previous if it exists. 524 */ 525 if ((idp->curroff & bmask) == 0) { 526 if (bp != NULL) 527 brelse(bp); 528 if ((error = 529 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0) 530 break; 531 entryoffsetinblock = 0; 532 } 533 /* 534 * Get pointer to next entry. 535 */ 536 ep = (struct iso_directory_record *) 537 ((char *)bp->b_data + entryoffsetinblock); 538 539 reclen = isonum_711(ep->length); 540 if (reclen == 0) { 541 /* skip to next block, if any */ 542 idp->curroff = 543 (idp->curroff & ~bmask) + imp->logical_block_size; 544 continue; 545 } 546 547 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 548 error = EINVAL; 549 /* illegal entry, stop */ 550 break; 551 } 552 553 if (entryoffsetinblock + reclen > imp->logical_block_size) { 554 error = EINVAL; 555 /* illegal directory, so stop looking */ 556 break; 557 } 558 559 idp->current.d_namlen = isonum_711(ep->name_len); 560 561 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 562 error = EINVAL; 563 /* illegal entry, stop */ 564 break; 565 } 566 567 if (isonum_711(ep->flags)&2) 568 idp->current.d_fileno = isodirino(ep, imp); 569 else 570 idp->current.d_fileno = dbtob(bp->b_blkno) + 571 entryoffsetinblock; 572 573 idp->curroff += reclen; 574 575 switch (imp->iso_ftype) { 576 case ISO_FTYPE_RRIP: 577 cd9660_rrip_getname(ep,idp->current.d_name, &namelen, 578 &idp->current.d_fileno,imp); 579 idp->current.d_namlen = (u_char)namelen; 580 if (idp->current.d_namlen) 581 error = iso_uiodir(idp,&idp->current,idp->curroff); 582 break; 583 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/ 584 strcpy(idp->current.d_name,".."); 585 if (idp->current.d_namlen == 1 && ep->name[0] == 0) { 586 idp->current.d_namlen = 1; 587 error = iso_uiodir(idp,&idp->current,idp->curroff); 588 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) { 589 idp->current.d_namlen = 2; 590 error = iso_uiodir(idp,&idp->current,idp->curroff); 591 } else { 592 isofntrans(ep->name,idp->current.d_namlen, 593 idp->current.d_name, &namelen, 594 imp->iso_ftype == ISO_FTYPE_9660, 595 isonum_711(ep->flags)&4, 596 imp->joliet_level, 597 imp->im_flags, 598 imp->im_d2l); 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, NOCRED, &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 = uma_zalloc(namei_zone, M_WAITOK); 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 uma_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 uma_zfree(namei_zone, symname); 731 return (error); 732 } 733 uio->uio_resid -= symlen; 734 uio->uio_iov->iov_base = (char *)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 = ap->a_vp; 752 struct iso_node *ip; 753 struct bufobj *bo; 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 bp->b_blkno = (ip->iso_start + bp->b_lblkno) << 760 (ip->i_mnt->im_bshift - DEV_BSHIFT); 761 } 762 bp->b_iooffset = dbtob(bp->b_blkno); 763 bo = ip->i_mnt->im_bo; 764 BO_STRATEGY(bo, bp); 765 return (0); 766 } 767 768 /* 769 * Return POSIX pathconf information applicable to cd9660 filesystems. 770 */ 771 static int 772 cd9660_pathconf(ap) 773 struct vop_pathconf_args /* { 774 struct vnode *a_vp; 775 int a_name; 776 register_t *a_retval; 777 } */ *ap; 778 { 779 780 switch (ap->a_name) { 781 case _PC_LINK_MAX: 782 *ap->a_retval = 1; 783 return (0); 784 case _PC_NAME_MAX: 785 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 786 *ap->a_retval = NAME_MAX; 787 else 788 *ap->a_retval = 37; 789 return (0); 790 case _PC_PATH_MAX: 791 *ap->a_retval = PATH_MAX; 792 return (0); 793 case _PC_PIPE_BUF: 794 *ap->a_retval = PIPE_BUF; 795 return (0); 796 case _PC_CHOWN_RESTRICTED: 797 *ap->a_retval = 1; 798 return (0); 799 case _PC_NO_TRUNC: 800 *ap->a_retval = 1; 801 return (0); 802 default: 803 return (EINVAL); 804 } 805 /* NOTREACHED */ 806 } 807 808 /* 809 * Vnode pointer to File handle 810 */ 811 static int 812 cd9660_vptofh(ap) 813 struct vop_vptofh_args /* { 814 struct vnode *a_vp; 815 struct fid *a_fhp; 816 } */ *ap; 817 { 818 struct ifid ifh; 819 struct iso_node *ip = VTOI(ap->a_vp); 820 821 ifh.ifid_len = sizeof(struct ifid); 822 823 ifh.ifid_ino = ip->i_number; 824 ifh.ifid_start = ip->iso_start; 825 /* 826 * This intentionally uses sizeof(ifh) in order to not copy stack 827 * garbage on ILP32. 828 */ 829 memcpy(ap->a_fhp, &ifh, sizeof(ifh)); 830 831 #ifdef ISOFS_DBG 832 printf("vptofh: ino %d, start %ld\n", 833 ifh.ifid_ino, ifh.ifid_start); 834 #endif 835 836 return (0); 837 } 838 839 /* 840 * Global vfs data structures for cd9660 841 */ 842 struct vop_vector cd9660_vnodeops = { 843 .vop_default = &default_vnodeops, 844 .vop_open = cd9660_open, 845 .vop_access = cd9660_access, 846 .vop_bmap = cd9660_bmap, 847 .vop_cachedlookup = cd9660_lookup, 848 .vop_getattr = cd9660_getattr, 849 .vop_inactive = cd9660_inactive, 850 .vop_ioctl = cd9660_ioctl, 851 .vop_lookup = vfs_cache_lookup, 852 .vop_pathconf = cd9660_pathconf, 853 .vop_read = cd9660_read, 854 .vop_readdir = cd9660_readdir, 855 .vop_readlink = cd9660_readlink, 856 .vop_reclaim = cd9660_reclaim, 857 .vop_setattr = cd9660_setattr, 858 .vop_strategy = cd9660_strategy, 859 .vop_vptofh = cd9660_vptofh, 860 }; 861 862 /* 863 * Special device vnode ops 864 */ 865 866 struct vop_vector cd9660_fifoops = { 867 .vop_default = &fifo_specops, 868 .vop_access = cd9660_access, 869 .vop_getattr = cd9660_getattr, 870 .vop_inactive = cd9660_inactive, 871 .vop_reclaim = cd9660_reclaim, 872 .vop_setattr = cd9660_setattr, 873 .vop_vptofh = cd9660_vptofh, 874 }; 875