diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-05-21 18:05:59 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-05-21 18:05:59 +0000 |
commit | 46b230207cc84bc82f0cd18d81d2c57e55ea8a4f (patch) | |
tree | bbbf59576a521b87a654fb29aa46846b63ceca14 /sys | |
parent | 404f35f676d5df1450f030d77a5f18c465333703 (diff) |
- use MIN()/MAX() rather than min()/max(), to avoid possible truncation
of 64bit values to 'int'
- read always single cluster of data, to avoid confusing the buffer
cache; this appears to fix the random file content corruption which
happens when more than one cluster is read at the same time, i.e. for
files > 3*cluster_size
- fix some questionable pointer arithmetics; gcc-3.4.x didn't like it
- g/c redundant debug printf
- remove all traces of non-working quota support
add quota support to TODO - makes sense only once writing support
would be implemented, and only once NTFS would support notion of file 'owner'
- use 64bit local variable for free space computation
From NetBSD
- Comment fixes from joris@
ok millert@ joris@ pedro@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/ntfs/TODO | 3 | ||||
-rw-r--r-- | sys/ntfs/ntfs_subr.c | 58 | ||||
-rw-r--r-- | sys/ntfs/ntfs_vfsops.c | 10 | ||||
-rw-r--r-- | sys/ntfs/ntfs_vnops.c | 25 |
4 files changed, 46 insertions, 50 deletions
diff --git a/sys/ntfs/TODO b/sys/ntfs/TODO index d0909c37502..f31e318810b 100644 --- a/sys/ntfs/TODO +++ b/sys/ntfs/TODO @@ -1,4 +1,4 @@ -$OpenBSD: TODO,v 1.2 2003/05/20 03:23:11 mickey Exp $ +$OpenBSD: TODO,v 1.3 2005/05/21 18:05:58 brad Exp $ $NetBSD: TODO,v 1.1 2002/12/23 17:38:31 jdolecek Exp $ - convert the code to do caching in buffer cache indexed by @@ -27,6 +27,7 @@ $NetBSD: TODO,v 1.1 2002/12/23 17:38:31 jdolecek Exp $ (from Semen Ustimenko <semenu@FreeBSD.org>) generally, better write support +- once writing would work, consider quota support - support mount update diff --git a/sys/ntfs/ntfs_subr.c b/sys/ntfs/ntfs_subr.c index 8589f4f786a..9ee4b857d1f 100644 --- a/sys/ntfs/ntfs_subr.c +++ b/sys/ntfs/ntfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntfs_subr.c,v 1.4 2005/03/08 15:45:20 pat Exp $ */ +/* $OpenBSD: ntfs_subr.c,v 1.5 2005/05/21 18:05:58 brad Exp $ */ /* $NetBSD: ntfs_subr.c,v 1.4 2003/04/10 21:37:32 jdolecek Exp $ */ /*- @@ -980,9 +980,6 @@ ntfs_ntlookupfile( rdbuf = (caddr_t) malloc(blsize, M_TEMP, M_WAITOK); - dprintf(("ntfs_ntlookupfile: blksz: %d\n", blsize, rdsize)); - - loop: rdsize = vap->va_datalen; dprintf(("ntfs_ntlookupfile: rdsz: %d\n", rdsize)); @@ -1273,7 +1270,7 @@ ntfs_ntreaddir( if (fp->f_dirblbuf == NULL) { fp->f_dirblsz = vap->va_a_iroot->ir_size; fp->f_dirblbuf = (caddr_t) malloc( - max(vap->va_datalen,fp->f_dirblsz), M_NTFSDIR, M_WAITOK); + MAX(vap->va_datalen,fp->f_dirblsz), M_NTFSDIR, M_WAITOK); } blsize = fp->f_dirblsz; @@ -1494,7 +1491,7 @@ ntfs_filesize( } /* - * This is one of write routine. + * This is one of the write routines. */ int ntfs_writeattr_plain( @@ -1520,7 +1517,7 @@ ntfs_writeattr_plain( ntfs_btocn(off), &vap); if (error) return (error); - towrite = min(left, ntfs_cntob(vap->va_vcnend + 1) - off); + towrite = MIN(left, ntfs_cntob(vap->va_vcnend + 1) - off); ddprintf(("ntfs_writeattr_plain: o: %d, s: %d (%d - %d)\n", (u_int32_t) off, (u_int32_t) towrite, (u_int32_t) vap->va_vcnstart, @@ -1549,7 +1546,7 @@ ntfs_writeattr_plain( } /* - * This is one of write routine. + * This is one of the write routines. * * ntnode should be locked. */ @@ -1609,9 +1606,15 @@ ntfs_writentvattr_plain( off = ntfs_btocnoff(off); while (left && ccl) { - tocopy = min(left, - min(ntfs_cntob(ccl) - off, MAXBSIZE - off)); + /* + * 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%x cl: %d, off: %d len: %d, left: %d\n", (u_int32_t) cn, (u_int32_t) cl, @@ -1653,7 +1656,7 @@ ntfs_writentvattr_plain( } /* - * This is one of read routines. + * This is one of the read routines. * * ntnode should be locked. */ @@ -1707,23 +1710,18 @@ ntfs_readntvattr_plain( off = ntfs_btocnoff(off); while (left && ccl) { - tocopy = min(left, - min(ntfs_cntob(ccl) - off, - MAXBSIZE - off)); - cl = ntfs_btocl(tocopy + off); - /* - * If 'off' pushes us to next - * block, don't attempt to read whole - * 'tocopy' at once. This is to avoid - * bread() with varying 'size' for - * same 'blkno', which is not good. + * Always read single clusters at a + * time - we need to avoid reading + * differently-sized blocks at the + * same disk offsets to avoid + * confusing the buffer cache. */ - if (cl > ntfs_btocl(tocopy)) { - tocopy -= - ntfs_btocnoff(tocopy + off); - cl--; - } + tocopy = MIN(left, + ntfs_cntob(1) - off); + cl = ntfs_btocl(tocopy + off); + KASSERT(cl == 1 && + tocopy <= ntfs_cntob(1)); ddprintf(("ntfs_readntvattr_plain: " \ "read: cn: 0x%x cl: %d, " \ @@ -1757,7 +1755,7 @@ ntfs_readntvattr_plain( ccl -= cl; } } else { - tocopy = min(left, ntfs_cntob(ccl) - off); + tocopy = MIN(left, ntfs_cntob(ccl) - off); ddprintf(("ntfs_readntvattr_plain: " "hole: ccn: 0x%x ccl: %d, off: %d, " \ " len: %d, left: %d\n", @@ -1819,7 +1817,7 @@ ntfs_readattr_plain( ntfs_btocn(off), &vap); if (error) return (error); - toread = min(left, ntfs_cntob(vap->va_vcnend + 1) - off); + toread = MIN(left, ntfs_cntob(vap->va_vcnend + 1) - off); ddprintf(("ntfs_readattr_plain: o: %d, s: %d (%d - %d)\n", (u_int32_t) off, (u_int32_t) toread, (u_int32_t) vap->va_vcnstart, @@ -1906,7 +1904,7 @@ ntfs_readattr( if (error) break; - tocopy = min(left, ntfs_cntob(NTFS_COMPUNIT_CL) - off); + tocopy = MIN(left, ntfs_cntob(NTFS_COMPUNIT_CL) - off); if (init == ntfs_cntob(NTFS_COMPUNIT_CL)) { if (uio) @@ -2031,7 +2029,7 @@ ntfs_procfixups( return (EINVAL); } *cfxp = *fxp; - ((caddr_t) cfxp) += ntmp->ntm_bps; + cfxp = (u_int16_t *)((caddr_t)cfxp + ntmp->ntm_bps); } return (0); } diff --git a/sys/ntfs/ntfs_vfsops.c b/sys/ntfs/ntfs_vfsops.c index 5423e75c0d1..fb33ac2fa0a 100644 --- a/sys/ntfs/ntfs_vfsops.c +++ b/sys/ntfs/ntfs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntfs_vfsops.c,v 1.8 2005/03/08 15:45:20 pat Exp $ */ +/* $OpenBSD: ntfs_vfsops.c,v 1.9 2005/05/21 18:05:58 brad Exp $ */ /* $NetBSD: ntfs_vfsops.c,v 1.7 2003/04/24 07:50:19 christos Exp $ */ /*- @@ -819,6 +819,10 @@ ntfs_root( return (0); } +/* + * Do operations associated with quotas, not supported + */ +/* ARGSUSED */ static int ntfs_quotactl ( struct mount *mp, @@ -827,7 +831,7 @@ ntfs_quotactl ( caddr_t arg, struct proc *p) { - printf("\nntfs_quotactl():\n"); + return EOPNOTSUPP; } @@ -839,7 +843,7 @@ ntfs_calccfree( struct vnode *vp; u_int8_t *tmp; int j, error; - long cfree = 0; + cn_t cfree = 0; size_t bmsize, i; vp = ntmp->ntm_sysvn[NTFS_BITMAPINO]; diff --git a/sys/ntfs/ntfs_vnops.c b/sys/ntfs/ntfs_vnops.c index 383dfbf2fe6..fcf7b110781 100644 --- a/sys/ntfs/ntfs_vnops.c +++ b/sys/ntfs/ntfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntfs_vnops.c,v 1.6 2005/04/16 16:28:42 joris Exp $ */ +/* $OpenBSD: ntfs_vnops.c,v 1.7 2005/05/21 18:05:58 brad Exp $ */ /* $NetBSD: ntfs_vnops.c,v 1.6 2003/04/10 21:57:26 jdolecek Exp $ */ /* @@ -176,7 +176,7 @@ ntfs_read(ap) if (uio->uio_offset > fp->f_size) toread = 0; else - toread = min( uio->uio_resid, fp->f_size - uio->uio_offset ); + toread = MIN(uio->uio_resid, fp->f_size - uio->uio_offset ); dprintf((", toread: %d\n",(u_int32_t)toread)); @@ -367,7 +367,7 @@ ntfs_strategy(ap) (u_int32_t)bp->b_lblkno)); #endif - dprintf(("strategy: bcount: %d flags: 0x%lx\n", + dprintf(("strategy: bcount: %u flags: 0x%x\n", (u_int32_t)bp->b_bcount,bp->b_flags)); if (bp->b_flags & B_READ) { @@ -377,8 +377,8 @@ ntfs_strategy(ap) clrbuf(bp); error = 0; } else { - toread = min(bp->b_bcount, - fp->f_size-ntfs_cntob(bp->b_blkno)); + toread = MIN(bp->b_bcount, + fp->f_size - ntfs_cntob(bp->b_blkno)); dprintf(("ntfs_strategy: toread: %d, fsize: %d\n", toread,(u_int32_t)fp->f_size)); @@ -403,8 +403,8 @@ ntfs_strategy(ap) bp->b_error = error = EFBIG; bp->b_flags |= B_ERROR; } else { - towrite = min(bp->b_bcount, - fp->f_size-ntfs_cntob(bp->b_blkno)); + towrite = MIN(bp->b_bcount, + fp->f_size - ntfs_cntob(bp->b_blkno)); dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n", towrite,(u_int32_t)fp->f_size)); @@ -449,7 +449,7 @@ ntfs_write(ap) return (EFBIG); } - towrite = min(uio->uio_resid, fp->f_size - uio->uio_offset); + towrite = MIN(uio->uio_resid, fp->f_size - uio->uio_offset); dprintf((", towrite: %d\n",(u_int32_t)towrite)); @@ -478,9 +478,6 @@ ntfs_access(ap) mode_t mask, mode = ap->a_mode; gid_t *gp; int i; -#if defined(__NetBSD__) && defined(QUOTA) - int error; -#endif dprintf(("ntfs_access: %d\n",ip->i_number)); @@ -496,10 +493,6 @@ ntfs_access(ap) case VREG: if (vp->v_mount->mnt_flag & MNT_RDONLY) return (EROFS); -#if defined(__NetBSD__) && defined(QUOTA) - if (error = getinoquota(ip)) - return (error); -#endif break; } } @@ -724,7 +717,7 @@ ntfs_readdir(ap) off_t *cookiep; #endif - printf("ntfs_readdir: %d cookies\n",ncookies); + dprintf("ntfs_readdir: %d cookies\n",ncookies); if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) panic("ntfs_readdir: unexpected uio from NFS server"); dpStart = (struct dirent *) |