From e8a28f87d8534128f64ea89d9e5e4493d8175581 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 25 Apr 2001 10:33:09 +0000 Subject: [PATCH] MFffs ffs_balloc.c 1.5. Long ago, bread() set b_blkno to the disk block number as a side effect of doing physical i/o (or it just retained the setting from when the i/o was done). The setting is lost when buffers go away and then are reconsituted from VM. bread() originally compensated by doing a VOP_BMAP() to recover b_blkno, but this was no good since it sometimes caused extra i/o or even deadlock for bread()ing metadata to do the bmap. This was fixed in vfs_bio.c 1.33 (1995/03/03) and ffs_balloc.c 1.5, etc., by removing the VOP_BMAP() from bread() and breadn(), and changing all (?) places that used b_blkno to set it if necessary. ext2fs was not imported until later in 1995 and was still depending on the old behaviour of bread() in at least ext2_balloc(). This caused filesystem and file corruption by clobbering direct block numbers in inodes. --- sys/gnu/ext2fs/ext2_balloc.c | 2 ++ sys/gnu/fs/ext2fs/ext2_balloc.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sys/gnu/ext2fs/ext2_balloc.c b/sys/gnu/ext2fs/ext2_balloc.c index 75c17e5ad97..559f4a61730 100644 --- a/sys/gnu/ext2fs/ext2_balloc.c +++ b/sys/gnu/ext2fs/ext2_balloc.c @@ -111,6 +111,7 @@ ext2_debug("ext2_balloc called (%d, %d, %d)\n", brelse(bp); return (error); } + bp->b_blkno = fsbtodb(fs, nb); *bpp = bp; return (0); } @@ -126,6 +127,7 @@ ext2_debug("ext2_balloc called (%d, %d, %d)\n", brelse(bp); return (error); } + bp->b_blkno = fsbtodb(fs, nb); } else { /* Godmar thinks: this shouldn't happen w/o fragments */ printf("nsize %d(%d) > osize %d(%d) nb %d\n", diff --git a/sys/gnu/fs/ext2fs/ext2_balloc.c b/sys/gnu/fs/ext2fs/ext2_balloc.c index 75c17e5ad97..559f4a61730 100644 --- a/sys/gnu/fs/ext2fs/ext2_balloc.c +++ b/sys/gnu/fs/ext2fs/ext2_balloc.c @@ -111,6 +111,7 @@ ext2_debug("ext2_balloc called (%d, %d, %d)\n", brelse(bp); return (error); } + bp->b_blkno = fsbtodb(fs, nb); *bpp = bp; return (0); } @@ -126,6 +127,7 @@ ext2_debug("ext2_balloc called (%d, %d, %d)\n", brelse(bp); return (error); } + bp->b_blkno = fsbtodb(fs, nb); } else { /* Godmar thinks: this shouldn't happen w/o fragments */ printf("nsize %d(%d) > osize %d(%d) nb %d\n",