/* * Return buffer with the contents of block "offset" from the beginning of * directory "ip". If "res" is non-zero, fill it in with a pointer to the * remaining space in the directory. */ int cd9660_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp) { struct iso_node *ip; struct iso_mnt *imp; struct buf *bp; daddr_t lbn; int bsize, error; ip = VTOI(vp); imp = ip->i_mnt; lbn = cd9660_lblkno(imp, offset); bsize = cd9660_blksize(imp, ip, lbn); if ((error = bread(vp, lbn, bsize, NOCRED, 0, &bp)) != 0) { *bpp = NULL; return (error); } if (res) *res = (char *)bp->b_data + cd9660_blkoff(imp, offset); *bpp = bp; return (0); }
/* * Vnode op for reading. */ int cd9660_read(void *v) { struct vop_read_args /* { struct vnode *a_vp; struct uio *a_uio; int a_ioflag; kauth_cred_t a_cred; } */ *ap = v; struct vnode *vp = ap->a_vp; struct uio *uio = ap->a_uio; struct iso_node *ip = VTOI(vp); struct iso_mnt *imp; struct buf *bp; daddr_t lbn, rablock; off_t diff; int rasize, error = 0; long size, n, on; if (uio->uio_resid == 0) return (0); if (uio->uio_offset < 0) return (EINVAL); if (uio->uio_offset >= ip->i_size) return 0; ip->i_flag |= IN_ACCESS; imp = ip->i_mnt; if (vp->v_type == VREG) { const int advice = IO_ADV_DECODE(ap->a_ioflag); error = 0; while (uio->uio_resid > 0) { vsize_t bytelen = MIN(ip->i_size - uio->uio_offset, uio->uio_resid); if (bytelen == 0) break; error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice, UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp)); if (error) break; } goto out; } do { lbn = cd9660_lblkno(imp, uio->uio_offset); on = cd9660_blkoff(imp, uio->uio_offset); n = MIN(imp->logical_block_size - on, uio->uio_resid); diff = (off_t)ip->i_size - uio->uio_offset; if (diff <= 0) return (0); if (diff < n) n = diff; size = cd9660_blksize(imp, ip, lbn); rablock = lbn + 1; if (cd9660_lblktosize(imp, rablock) < ip->i_size) { rasize = cd9660_blksize(imp, ip, rablock); error = breadn(vp, lbn, size, &rablock, &rasize, 1, NOCRED, 0, &bp); } else { error = bread(vp, lbn, size, NOCRED, 0, &bp); } if (error) { return (error); } n = MIN(n, size - bp->b_resid); error = uiomove((char *)bp->b_data + on, (int)n, uio); brelse(bp, 0); } while (error == 0 && uio->uio_resid > 0 && n != 0); out: return (error); }
int cd9660_vget_internal(struct mount *mp, ino_t ino, struct vnode **vpp, int relocated, struct iso_directory_record *isodir) { struct iso_mnt *imp; struct iso_node *ip; struct buf *bp; struct vnode *vp; dev_t dev; int error; imp = VFSTOISOFS(mp); dev = imp->im_dev; retry: if ((*vpp = cd9660_ihashget(dev, ino, LK_EXCLUSIVE)) != NULLVP) return (0); /* Allocate a new vnode/iso_node. */ error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, NULL, &vp); if (error) { *vpp = NULLVP; return (error); } ip = pool_get(&cd9660_node_pool, PR_WAITOK); /* * If someone beat us to it, put back the freshly allocated * vnode/inode pair and retry. */ mutex_enter(&cd9660_hashlock); if (cd9660_ihashget(dev, ino, 0) != NULL) { mutex_exit(&cd9660_hashlock); ungetnewvnode(vp); pool_put(&cd9660_node_pool, ip); goto retry; } memset(ip, 0, sizeof(struct iso_node)); vp->v_data = ip; ip->i_vnode = vp; ip->i_dev = dev; ip->i_number = ino; ip->i_mnt = imp; ip->i_devvp = imp->im_devvp; genfs_node_init(vp, &cd9660_genfsops); /* * Put it onto its hash chain and lock it so that other requests for * this inode will block if they arrive while we are sleeping waiting * for old data structures to be purged or for the contents of the * disk portion of this inode to be read. */ cd9660_ihashins(ip); mutex_exit(&cd9660_hashlock); if (isodir == 0) { int lbn, off; lbn = cd9660_lblkno(imp, ino); if (lbn >= imp->volume_space_size) { vput(vp); printf("fhtovp: lbn exceed volume space %d\n", lbn); return (ESTALE); } off = cd9660_blkoff(imp, ino); if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) { vput(vp); printf("fhtovp: crosses block boundary %d\n", off + ISO_DIRECTORY_RECORD_SIZE); return (ESTALE); } error = bread(imp->im_devvp, lbn << (imp->im_bshift - DEV_BSHIFT), imp->logical_block_size, NOCRED, 0, &bp); if (error) { vput(vp); printf("fhtovp: bread error %d\n",error); return (error); } isodir = (struct iso_directory_record *)((char *)bp->b_data + off); if (off + isonum_711(isodir->length) > imp->logical_block_size) { vput(vp); if (bp != 0) brelse(bp, 0); printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n", off +isonum_711(isodir->length), off, isonum_711(isodir->length)); return (ESTALE); } #if 0 if (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) { if (bp != 0) brelse(bp, 0); printf("fhtovp: file start miss %d vs %d\n", isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length), ifhp->ifid_start); return (ESTALE); } #endif } else bp = 0; vref(ip->i_devvp); if (relocated) { /* * On relocated directories we must * read the `.' entry out of a dir. */ ip->iso_start = ino >> imp->im_bshift; if (bp != 0) brelse(bp, 0); if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) { vput(vp); return (error); } isodir = (struct iso_directory_record *)bp->b_data; } ip->iso_extent = isonum_733(isodir->extent); ip->i_size = isonum_733(isodir->size); ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent; /* * Setup time stamp, attribute */ vp->v_type = VNON; switch (imp->iso_ftype) { default: /* ISO_FTYPE_9660 */ { struct buf *bp2; int off; if ((imp->im_flags & ISOFSMNT_EXTATT) && (off = isonum_711(isodir->ext_attr_length))) cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift), NULL, &bp2); else bp2 = NULL; cd9660_defattr(isodir, ip, bp2); cd9660_deftstamp(isodir, ip, bp2); if (bp2) brelse(bp2, 0); break; } case ISO_FTYPE_RRIP: cd9660_rrip_analyze(isodir, ip, imp); break; } if (bp != 0) brelse(bp, 0); /* * Initialize the associated vnode */ switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) { case VFIFO: vp->v_op = cd9660_fifoop_p; break; case VCHR: case VBLK: /* * if device, look at device number table for translation */ vp->v_op = cd9660_specop_p; spec_node_init(vp, ip->inode.iso_rdev); break; case VLNK: case VNON: case VSOCK: case VDIR: case VBAD: break; case VREG: uvm_vnp_setsize(vp, ip->i_size); break; } if (vp->v_type != VREG) uvm_vnp_setsize(vp, 0); if (ip->iso_extent == imp->root_extent) vp->v_vflag |= VV_ROOT; /* * XXX need generation number? */ *vpp = vp; return (0); }