mount_ntfs forces the mount point to be MNT_RDONLY, so the write parts in ntfs are never used. OK to remove?
natano Index: ntfs/ntfs_subr.c =================================================================== RCS file: /cvs/src/sys/ntfs/ntfs_subr.c,v retrieving revision 1.47 diff -u -p -r1.47 ntfs_subr.c --- ntfs/ntfs_subr.c 31 Aug 2016 15:13:57 -0000 1.47 +++ ntfs/ntfs_subr.c 31 Aug 2016 19:58:31 -0000 @@ -1336,152 +1336,6 @@ ntfs_filesize(struct ntfsmount *ntmp, st } /* - * This is one of the write routines. - */ -int -ntfs_writeattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, - u_int32_t attrnum, char *attrname, off_t roff, size_t rsize, void *rdata, - size_t *initp, struct uio *uio) -{ - size_t init; - int error = 0; - off_t off = roff; - size_t left = rsize, towrite; - caddr_t data = rdata; - struct ntvattr *vap; - *initp = 0; - - while (left) { - error = ntfs_ntvattrget(ntmp, ip, attrnum, attrname, - ntfs_btocn(off), &vap); - if (error) - return (error); - towrite = MIN(left, ntfs_cntob(vap->va_vcnend + 1) - off); - DDPRINTF("ntfs_writeattr_plain: o: %lld, s: %zu " - "(%llu - %llu)\n", off, towrite, - vap->va_vcnstart, vap->va_vcnend); - error = ntfs_writentvattr_plain(ntmp, ip, vap, - off - ntfs_cntob(vap->va_vcnstart), - towrite, data, &init, uio); - if (error) { - DPRINTF("ntfs_writeattr_plain: ntfs_writentvattr_plain " - "failed: o: %lld, s: %zu\n", off, towrite); - DPRINTF("ntfs_writeattr_plain: attrib: %llu - %llu\n", - vap->va_vcnstart, vap->va_vcnend); - ntfs_ntvattrrele(vap); - break; - } - ntfs_ntvattrrele(vap); - left -= towrite; - off += towrite; - data = data + towrite; - *initp += init; - } - - return (error); -} - -/* - * This is one of the write routines. - * - * ntnode should be locked. - */ -int -ntfs_writentvattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, - struct ntvattr *vap, off_t roff, size_t rsize, void *rdata, size_t *initp, - struct uio *uio) -{ - int error = 0; - off_t off; - int cnt; - cn_t ccn, ccl, cn, cl; - caddr_t data = rdata; - struct buf *bp; - size_t left, tocopy; - - *initp = 0; - - if ((vap->va_flag & NTFS_AF_INRUN) == 0) { - DPRINTF("ntfs_writevattr_plain: CAN'T WRITE RES. ATTRIBUTE\n"); - return ENOTTY; - } - - DDPRINTF("ntfs_writentvattr_plain: data in run: %lu chains\n", - vap->va_vruncnt); - - off = roff; - left = rsize; - - for (cnt = 0; left && (cnt < vap->va_vruncnt); cnt++) { - ccn = vap->va_vruncn[cnt]; - ccl = vap->va_vruncl[cnt]; - - DDPRINTF("ntfs_writentvattr_plain: left %zu, cn: 0x%llx, " - "cl: %llu, off: %lld\n", left, ccn, ccl, off); - - if (ntfs_cntob(ccl) < off) { - off -= ntfs_cntob(ccl); - cnt++; - continue; - } - if (!ccn && ip->i_number != NTFS_BOOTINO) - continue; /* XXX */ - - ccl -= ntfs_btocn(off); - cn = ccn + ntfs_btocn(off); - off = ntfs_btocnoff(off); - - while (left && ccl) { - /* - * Always read and write single clusters at a time - - * we need to avoid requesting differently-sized - * blocks at the same disk offsets to avoid - * confusing the buffer cache. - */ - tocopy = MIN(left, ntfs_cntob(1) - off); - cl = ntfs_btocl(tocopy + off); - KASSERT(cl == 1 && tocopy <= ntfs_cntob(1)); - DDPRINTF("ntfs_writentvattr_plain: write: cn: 0x%llx " - "cl: %llu, off: %lld len: %zu, left: %zu\n", - cn, cl, off, tocopy, left); - if ((off == 0) && (tocopy == ntfs_cntob(cl))) - { - bp = getblk(ntmp->ntm_devvp, ntfs_cntobn(cn), - ntfs_cntob(cl), 0, 0); - clrbuf(bp); - } else { - error = bread(ntmp->ntm_devvp, ntfs_cntobn(cn), - ntfs_cntob(cl), &bp); - if (error) { - brelse(bp); - return (error); - } - } - if (uio) { - error = uiomove(bp->b_data + off, tocopy, uio); - if (error != 0) - break; - } else - memcpy(bp->b_data + off, data, tocopy); - bawrite(bp); - data = data + tocopy; - *initp += tocopy; - off = 0; - left -= tocopy; - cn += cl; - ccl -= cl; - } - } - - if (left && error == 0) { - printf("ntfs_writentvattr_plain: POSSIBLE RUN ERROR\n"); - error = EINVAL; - } - - return (error); -} - -/* * This is one of the read routines. * * ntnode should be locked. Index: ntfs/ntfs_subr.h =================================================================== RCS file: /cvs/src/sys/ntfs/ntfs_subr.h,v retrieving revision 1.9 diff -u -p -r1.9 ntfs_subr.h --- ntfs/ntfs_subr.h 19 Jan 2014 18:35:45 -0000 1.9 +++ ntfs/ntfs_subr.h 31 Aug 2016 19:59:33 -0000 @@ -91,8 +91,6 @@ int ntfs_ntvattrget(struct ntfsmount *, void ntfs_ntref(struct ntnode *); void ntfs_ntrele(struct ntnode *); int ntfs_loadntnode( struct ntfsmount *, struct ntnode * ); -int ntfs_writentvattr_plain(struct ntfsmount *, struct ntnode *, struct ntvattr *, off_t, size_t, void *, size_t *, struct uio *); -int ntfs_writeattr_plain(struct ntfsmount *, struct ntnode *, u_int32_t, char *, off_t, size_t, void *, size_t *, struct uio *); int ntfs_fget(struct ntfsmount *, struct ntnode *, int, char *, struct fnode **); void ntfs_frele(struct fnode *); int ntfs_ntreaddir(struct ntfsmount *, struct fnode *, u_int32_t, struct attr_indexentry **, struct proc *); Index: ntfs/ntfs_vfsops.c =================================================================== RCS file: /cvs/src/sys/ntfs/ntfs_vfsops.c,v retrieving revision 1.53 diff -u -p -r1.53 ntfs_vfsops.c --- ntfs/ntfs_vfsops.c 13 Aug 2016 20:53:17 -0000 1.53 +++ ntfs/ntfs_vfsops.c 31 Aug 2016 20:34:41 -0000 @@ -122,7 +122,6 @@ ntfs_mount(struct mount *mp, const char struct ntfs_args args; char fname[MNAMELEN]; char fspec[MNAMELEN]; - mode_t amode; ntfs_nthashinit(); @@ -193,9 +192,8 @@ ntfs_mount(struct mount *mp, const char * requested device. */ if (p->p_ucred->cr_uid) { - amode = (mp->mnt_flag & MNT_RDONLY) ? VREAD : (VREAD | VWRITE); vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); - err = VOP_ACCESS(devvp, amode, p->p_ucred, p); + err = VOP_ACCESS(devvp, VREAD, p->p_ucred, p); VOP_UNLOCK(devvp, p); if (err) goto error_2; @@ -282,7 +280,7 @@ ntfs_mountfs(struct vnode *devvp, struct struct buf *bp; struct ntfsmount *ntmp = NULL; dev_t dev = devvp->v_rdev; - int error, ronly, ncount, i; + int error, ncount, i; struct vnode *vp; /* @@ -303,8 +301,7 @@ ntfs_mountfs(struct vnode *devvp, struct if (error) return (error); - ronly = (mp->mnt_flag & MNT_RDONLY) != 0; - error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p); + error = VOP_OPEN(devvp, FREAD, FSCRED, p); if (error) return (error); @@ -464,7 +461,7 @@ out: /* lock the device vnode before calling VOP_CLOSE() */ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); - (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p); + (void)VOP_CLOSE(devvp, FREAD, NOCRED, p); VOP_UNLOCK(devvp, p); return (error); @@ -480,7 +477,7 @@ int ntfs_unmount(struct mount *mp, int mntflags, struct proc *p) { struct ntfsmount *ntmp; - int error, ronly = 0, flags, i; + int error, flags, i; DPRINTF("ntfs_unmount: unmounting...\n"); ntmp = VFSTONTFS(mp); @@ -524,8 +521,7 @@ ntfs_unmount(struct mount *mp, int mntfl /* lock the device vnode before calling VOP_CLOSE() */ vn_lock(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY, p); vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, p, 0, 0); - (void)VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE, - NOCRED, p); + (void)VOP_CLOSE(ntmp->ntm_devvp, FREAD, NOCRED, p); vput(ntmp->ntm_devvp); /* free the toupper table, if this has been last mounted ntfs volume */ Index: ntfs/ntfs_vnops.c =================================================================== RCS file: /cvs/src/sys/ntfs/ntfs_vnops.c,v retrieving revision 1.41 diff -u -p -r1.41 ntfs_vnops.c --- ntfs/ntfs_vnops.c 19 Mar 2016 12:04:16 -0000 1.41 +++ ntfs/ntfs_vnops.c 31 Aug 2016 20:32:31 -0000 @@ -57,7 +57,6 @@ #include <sys/unistd.h> /* for pathconf(2) constants */ int ntfs_read(void *); -int ntfs_write(void *); int ntfs_getattr(void *); int ntfs_inactive(void *); int ntfs_print(void *); @@ -292,29 +291,8 @@ ntfs_strategy(void *v) bzero(bp->b_data + toread, bp->b_bcount - toread); } } else { - size_t tmp; - u_int32_t towrite; - - if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) { - printf("ntfs_strategy: CAN'T EXTEND FILE\n"); - bp->b_error = error = EFBIG; - bp->b_flags |= B_ERROR; - } else { - towrite = MIN(bp->b_bcount, - fp->f_size - ntfs_cntob(bp->b_blkno)); - DPRINTF("ntfs_strategy: towrite: %u, fsize: %llu\n", - towrite, fp->f_size); - - error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype, - fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite, - bp->b_data, &tmp, NULL); - - if (error) { - printf("ntfs_strategy: ntfs_writeattr fail\n"); - bp->b_error = error; - bp->b_flags |= B_ERROR; - } - } + bp->b_error = error = EROFS; + bp->b_flags |= B_ERROR; } s = splbio(); biodone(bp); @@ -323,42 +301,6 @@ ntfs_strategy(void *v) } int -ntfs_write(void *v) -{ - struct vop_write_args *ap = v; - struct vnode *vp = ap->a_vp; - struct fnode *fp = VTOF(vp); - struct ntnode *ip = FTONT(fp); - struct uio *uio = ap->a_uio; - struct ntfsmount *ntmp = ip->i_mp; - u_int64_t towrite; - size_t written; - int error; - - DPRINTF("ntfs_write: ino: %u, off: %lld resid: %zu, segflg: %d\n", - ip->i_number, uio->uio_offset, uio->uio_resid, uio->uio_segflg); - DPRINTF("ntfs_write: filesize: %llu", fp->f_size); - - if (uio->uio_resid + uio->uio_offset > fp->f_size) { - printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n"); - return (EFBIG); - } - - towrite = MIN(uio->uio_resid, fp->f_size - uio->uio_offset); - - DPRINTF(", towrite: %llu\n", towrite); - - error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype, - fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio); -#ifdef NTFS_DEBUG - if (error) - printf("ntfs_write: ntfs_writeattr failed: %d\n", error); -#endif - - return (error); -} - -int ntfs_access(void *v) { struct vop_access_args *ap = v; @@ -372,18 +314,15 @@ ntfs_access(void *v) DPRINTF("ntfs_access: %u\n", ip->i_number); /* - * Disallow write attempts on read-only file systems; - * unless the file is a socket, fifo, or a block or - * character device resident on the file system. + * 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 ((int)vp->v_type) { case VDIR: case VLNK: case VREG: - if (vp->v_mount->mnt_flag & MNT_RDONLY) - return (EROFS); - break; + return (EROFS); } } @@ -606,7 +545,6 @@ ntfs_lookup(void *v) return (error); if ((cnp->cn_flags & ISLASTCN) && - (dvp->v_mount->mnt_flag & MNT_RDONLY) && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) return (EROFS); @@ -746,5 +684,4 @@ struct vops ntfs_vops = { .vop_strategy = ntfs_strategy, .vop_bwrite = vop_generic_bwrite, .vop_read = ntfs_read, - .vop_write = ntfs_write, };