diff options
author | bde <bde@FreeBSD.org> | 2007-07-20 16:21:47 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2007-07-20 16:21:47 +0000 |
commit | b2bdcce9e10d5055a3afbfebf98e0e05fcd67113 (patch) | |
tree | e4ec23a08ff01518cb0df4d35f6a8c85382b3337 | |
parent | fcbc18ed979a9e690e88b07c8dba4cd1f4f1cc5d (diff) | |
download | FreeBSD-src-b2bdcce9e10d5055a3afbfebf98e0e05fcd67113.zip FreeBSD-src-b2bdcce9e10d5055a3afbfebf98e0e05fcd67113.tar.gz |
Clean up before implementing vfs clustering for msdosfs:
In msdosfs_read(), mainly reorder the main loop to the same order as in
ffs_read().
In msdosfs_write() and extendfile(), use vfs_bio_clrbuf() instead of
clrbuf(). I think this just just a bogus optimization, but ffs always
does it and msdosfs already did it in one place, and it is what I've
tested.
In msdosfs_write(), merge good bits from a comment in ffs_write(), and
fix 1 style bug.
In the main comment for msdosfs_pcbmap(), improve wording and catch
up with 13 years of changes in the function. This comment belongs in
VOP_BMAP.9 but that doesn't exist.
In msdosfs_bmap(), return EFBIG if the requested cluster number is out
of bounds instead of blindly truncating it, and fix many style bugs.
Approved by: re (hrs)
-rw-r--r-- | sys/fs/msdosfs/msdosfs_fat.c | 2 | ||||
-rw-r--r-- | sys/fs/msdosfs/msdosfs_vnops.c | 78 |
2 files changed, 43 insertions, 37 deletions
diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c index b77f2d6..dcef681 100644 --- a/sys/fs/msdosfs/msdosfs_fat.c +++ b/sys/fs/msdosfs/msdosfs_fat.c @@ -1105,7 +1105,7 @@ extendfile(dep, count, bpp, ncp, flags) else bp->b_blkno = blkno; } - clrbuf(bp); + vfs_bio_clrbuf(bp); if (bpp) { *bpp = bp; bpp = NULL; diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 3231267..8fecdf9 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -579,6 +579,9 @@ msdosfs_read(ap) if (uio->uio_offset >= dep->de_FileSize) break; lbn = de_cluster(pmp, uio->uio_offset); + rablock = lbn + 1; + blsize = pmp->pm_bpcluster; + on = uio->uio_offset & pmp->pm_crbomask; /* * If we are operating on a directory file then be sure to * do i/o with the vnode for the filesystem instead of the @@ -593,23 +596,19 @@ msdosfs_read(ap) } else if (error) break; error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp); + } else if (de_cn2off(pmp, rablock) >= dep->de_FileSize) { + error = bread(vp, lbn, blsize, NOCRED, &bp); + } else if (seqcount > 1) { + rasize = blsize; + error = breadn(vp, lbn, + blsize, &rablock, &rasize, 1, NOCRED, &bp); } else { - blsize = pmp->pm_bpcluster; - rablock = lbn + 1; - if (seqcount > 1 && - de_cn2off(pmp, rablock) < dep->de_FileSize) { - rasize = pmp->pm_bpcluster; - error = breadn(vp, lbn, blsize, - &rablock, &rasize, 1, NOCRED, &bp); - } else { - error = bread(vp, lbn, blsize, NOCRED, &bp); - } + error = bread(vp, lbn, blsize, NOCRED, &bp); } if (error) { brelse(bp); break; } - on = uio->uio_offset & pmp->pm_crbomask; diff = pmp->pm_bpcluster - on; n = diff > uio->uio_resid ? uio->uio_resid : diff; diff = dep->de_FileSize - uio->uio_offset; @@ -755,7 +754,7 @@ msdosfs_write(ap) * then no need to read data from disk. */ bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0); - clrbuf(bp); + vfs_bio_clrbuf(bp); /* * Do the bmap now, since pcbmap needs buffers * for the fat table. (see msdosfs_strategy) @@ -799,14 +798,15 @@ msdosfs_write(ap) } /* - * If they want this synchronous then write it and wait for - * it. Otherwise, if on a cluster boundary write it - * asynchronously so we can move on to the next block - * without delay. Otherwise do a delayed write because we - * may want to write somemore into the block later. + * If IO_SYNC, then each buffer is written synchronously. + * Otherwise, if on a + * cluster boundary then write the buffer asynchronously, + * since we don't expect more writes into this + * buffer soon. Otherwise, do a delayed write because we + * expect more writes into this buffer soon. */ if (ioflag & IO_SYNC) - (void) bwrite(bp); + (void)bwrite(bp); else if (n + croffset == pmp->pm_bpcluster) bawrite(bp); else @@ -1755,12 +1755,16 @@ out: return (error); } -/* - * vp - address of vnode file the file - * bn - which cluster we are interested in mapping to a filesystem block number. - * vpp - returns the vnode for the block special file holding the filesystem - * containing the file of interest - * bnp - address of where to return the filesystem relative block number +/*- + * a_vp - pointer to the file's vnode + * a_bn - logical block number within the file (cluster number for us) + * a_bop - where to return the bufobj of the special file containing the fs + * a_bnp - where to return the "physical" block number corresponding to a_bn + * (relative to the special file; units are blocks of size DEV_BSIZE) + * a_runp - where to return the "run past" a_bn. This is the count of logical + * blocks whose physical blocks (together with a_bn's physical block) + * are contiguous. + * a_runb - where to return the "run before" a_bn. */ static int msdosfs_bmap(ap) @@ -1773,25 +1777,27 @@ msdosfs_bmap(ap) int *a_runb; } */ *ap; { - struct denode *dep = VTODE(ap->a_vp); - daddr_t blkno; + struct denode *dep; + struct msdosfsmount *pmp; + struct vnode *vp; + u_long cn; int error; + vp = ap->a_vp; + dep = VTODE(vp); + pmp = dep->de_pmp; if (ap->a_bop != NULL) - *ap->a_bop = &dep->de_pmp->pm_devvp->v_bufobj; + *ap->a_bop = &pmp->pm_devvp->v_bufobj; if (ap->a_bnp == NULL) return (0); - if (ap->a_runp) { - /* - * Sequential clusters should be counted here. - */ + if (ap->a_runp != NULL) *ap->a_runp = 0; - } - if (ap->a_runb) { + if (ap->a_runb != NULL) *ap->a_runb = 0; - } - error = pcbmap(dep, ap->a_bn, &blkno, 0, 0); - *ap->a_bnp = blkno; + cn = ap->a_bn; + if (cn != ap->a_bn) + return (EFBIG); + error = pcbmap(dep, cn, ap->a_bnp, NULL, NULL); return (error); } |