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