Merge branch 'master' into kiconv2
[dragonfly.git] / sys / vfs / isofs / cd9660 / cd9660_vnops.c
index 0baa47f..c59ec54 100644 (file)
@@ -131,66 +131,10 @@ cd9660_access(struct vop_access_args *ap)
 {
        struct vnode *vp = ap->a_vp;
        struct iso_node *ip = VTOI(vp);
-       struct ucred *cred = ap->a_cred;
-       mode_t mask, mode = ap->a_mode;
-       gid_t *gp;
-       int i;
 
-       /*
-        * Disallow write attempts unless the file is a socket,
-        * fifo, or a block or character device resident on the
-        * file system.
-        */
-       if (mode & VWRITE) {
-               switch (vp->v_type) {
-               case VDIR:
-               case VLNK:
-               case VREG:
-                       return (EROFS);
-                       /* NOT REACHED */
-               default:
-                       break;
-               }
-       }
-
-       /* User id 0 always gets access. */
-       if (cred->cr_uid == 0)
-               return (0);
-
-       mask = 0;
-
-       /* Otherwise, check the owner. */
-       if (cred->cr_uid == ip->inode.iso_uid) {
-               if (mode & VEXEC)
-                       mask |= S_IXUSR;
-               if (mode & VREAD)
-                       mask |= S_IRUSR;
-               if (mode & VWRITE)
-                       mask |= S_IWUSR;
-               return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
-       }
-
-       /* Otherwise, check the groups. */
-       for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
-               if (ip->inode.iso_gid == *gp) {
-                       if (mode & VEXEC)
-                               mask |= S_IXGRP;
-                       if (mode & VREAD)
-                               mask |= S_IRGRP;
-                       if (mode & VWRITE)
-                               mask |= S_IWGRP;
-                       return ((ip->inode.iso_mode & mask) == mask ?
-                           0 : EACCES);
-               }
-
-       /* Otherwise, check everyone else. */
-       if (mode & VEXEC)
-               mask |= S_IXOTH;
-       if (mode & VREAD)
-               mask |= S_IROTH;
-       if (mode & VWRITE)
-               mask |= S_IWOTH;
-       return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
+       KKASSERT(vp->v_mount->mnt_flag & MNT_RDONLY);
+       return (vop_helper_access(ap, ip->inode.iso_uid, ip->inode.iso_gid,
+                       ip->inode.iso_mode, 0));
 }
 
 /*
@@ -314,8 +258,8 @@ cd9660_read(struct vop_read_args *ap)
                lbn = lblkno(imp, uio->uio_offset);
                loffset = lblktooff(imp, lbn);
                on = blkoff(imp, uio->uio_offset);
-               n = min((u_int)(imp->logical_block_size - on),
-                       uio->uio_resid);
+               n = szmin((u_int)(imp->logical_block_size - on),
+                         uio->uio_resid);
                diff = (off_t)ip->i_size - uio->uio_offset;
                if (diff <= 0)
                        return (0);
@@ -325,13 +269,15 @@ cd9660_read(struct vop_read_args *ap)
                rablock = lbn + 1;
                raoffset = lblktooff(imp, rablock);
                if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
-                       if (raoffset < ip->i_size)
+                       if (raoffset < ip->i_size) {
                                error = cluster_read(vp, (off_t)ip->i_size,
-                                        loffset, size,
-                                        uio->uio_resid,
-                                        (ap->a_ioflag >> 16), &bp);
-                       else
+                                                    loffset, size,
+                                                    uio->uio_resid,
+                                                    (ap->a_ioflag >> 16),
+                                                    &bp);
+                       } else {
                                error = bread(vp, loffset, size, &bp);
+                       }
                } else {
                        if (seqcount > 1 &&
                            lblktosize(imp, rablock) < ip->i_size) {
@@ -341,7 +287,7 @@ cd9660_read(struct vop_read_args *ap)
                        } else
                                error = bread(vp, loffset, size, &bp);
                }
-               n = min(n, size - bp->b_resid);
+               n = imin(n, size - bp->b_resid);
                if (error) {
                        brelse(bp);
                        return (error);
@@ -874,7 +820,8 @@ struct vop_ops cd9660_vnode_vops = {
  * Special device vnode ops
  */
 struct vop_ops cd9660_spec_vops = {
-       .vop_default =          spec_vnoperate,
+       .vop_default =          vop_defaultop,
+       .vop_read =             vop_stdnoread,
        .vop_access =           cd9660_access,
        .vop_getattr =          cd9660_getattr,
        .vop_inactive =         cd9660_inactive,