Hi Linus,

I just noticed that BFS did not update the number of free blocks correctly
on extending the file (in some circumstances) so after running bonnie on
BFS (although showing it's a lot faster than ext2! :) one could see some
very strange numbers in df(1) output. The patch below fixes this bug (also
updates my email address, while I was there).

Regards,
Tigran

diff -urN -X dontdiff linux/fs/bfs/dir.c bfs/fs/bfs/dir.c
--- linux/fs/bfs/dir.c  Tue Sep  5 22:07:29 2000
+++ bfs/fs/bfs/dir.c    Sun Oct 15 23:31:06 2000
@@ -1,7 +1,7 @@
 /*
  *     fs/bfs/dir.c
  *     BFS directory operations.
- *     Copyright (C) 1999  Tigran Aivazian <[EMAIL PROTECTED]>
+ *     Copyright (C) 1999,2000  Tigran Aivazian <[EMAIL PROTECTED]>
  */
 
 #include <linux/sched.h>
diff -urN -X dontdiff linux/fs/bfs/file.c bfs/fs/bfs/file.c
--- linux/fs/bfs/file.c Tue Sep  5 22:07:29 2000
+++ bfs/fs/bfs/file.c   Mon Oct 16 12:04:47 2000
@@ -1,7 +1,7 @@
 /*
  *     fs/bfs/file.c
  *     BFS file operations.
- *     Copyright (C) 1999 Tigran Aivazian <[EMAIL PROTECTED]>
+ *     Copyright (C) 1999,2000 Tigran Aivazian <[EMAIL PROTECTED]>
  */
 
 #include <linux/fs.h>
@@ -26,7 +26,7 @@
 
 static int bfs_move_block(unsigned long from, unsigned long to, kdev_t dev)
 {
-       struct buffer_head *bh, *new = NULL;
+       struct buffer_head *bh, *new;
 
        bh = bread(dev, from, BFS_BSIZE);
        if (!bh)
@@ -56,11 +56,12 @@
 static int bfs_get_block(struct inode * inode, long block, 
        struct buffer_head * bh_result, int create)
 {
-       long phys, next_free_block;
+       long phys;
        int err;
-       struct super_block *s = inode->i_sb;
+       struct super_block *sb = inode->i_sb;
+       struct buffer_head *sbh = sb->su_sbh;
 
-       if (block < 0 || block > s->su_blocks)
+       if (block < 0 || block > sb->su_blocks)
                return -EIO;
 
        phys = inode->iu_sblock + block;
@@ -90,24 +91,25 @@
 
        /* if the last data block for this file is the last allocated block, we can
           extend the file trivially, without moving it anywhere */
-       if (inode->iu_eblock == s->su_lf_eblk) {
+       if (inode->iu_eblock == sb->su_lf_eblk) {
                dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n", 
                                create, block, phys);
                bh_result->b_dev = inode->i_dev;
                bh_result->b_blocknr = phys;
                bh_result->b_state |= (1UL << BH_Mapped);
-               s->su_lf_eblk = inode->iu_eblock = inode->iu_sblock + block;
+               sb->su_freeb -= phys - inode->iu_eblock;
+               sb->su_lf_eblk = inode->iu_eblock = phys;
                mark_inode_dirty(inode);
-               mark_buffer_dirty(s->su_sbh);
+               mark_buffer_dirty(sbh);
                err = 0;
                goto out;
        }
 
        /* Ok, we have to move this entire file to the next free block */
-       next_free_block = s->su_lf_eblk + 1;
+       phys = sb->su_lf_eblk + 1;
        if (inode->iu_sblock) { /* if data starts on block 0 then there is no data */
                err = bfs_move_blocks(inode->i_dev, inode->iu_sblock, 
-                               inode->iu_eblock, next_free_block);
+                               inode->iu_eblock, phys);
                if (err) {
                        dprintf("failed to move ino=%08lx -> fs corruption\n", 
inode->i_ino);
                        goto out;
@@ -115,12 +117,18 @@
        } else
                err = 0;
 
-       inode->iu_sblock = next_free_block;
-       s->su_lf_eblk = inode->iu_eblock = next_free_block + block;
+       dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n", create, block, phys);
+       inode->iu_sblock = phys;
+       phys += block;
+       sb->su_lf_eblk = inode->iu_eblock = phys;
+
+       /* this assumes nothing can write the inode back while we are here
+        * and thus update inode->i_blocks! (XXX)*/
+       sb->su_freeb -= inode->iu_eblock - inode->iu_sblock + 1 - inode->i_blocks;
        mark_inode_dirty(inode);
-       mark_buffer_dirty(s->su_sbh);
+       mark_buffer_dirty(sbh);
        bh_result->b_dev = inode->i_dev;
-       bh_result->b_blocknr = inode->iu_sblock + block;
+       bh_result->b_blocknr = phys;
        bh_result->b_state |= (1UL << BH_Mapped);
 out:
        unlock_kernel();
@@ -153,8 +161,7 @@
        sync_page:      block_sync_page,
        prepare_write:  bfs_prepare_write,
        commit_write:   generic_commit_write,
-       bmap:           bfs_bmap
+       bmap:           bfs_bmap,
 };
 
-struct inode_operations bfs_file_inops = {
-};
+struct inode_operations bfs_file_inops;
diff -urN -X dontdiff linux/fs/bfs/inode.c bfs/fs/bfs/inode.c
--- linux/fs/bfs/inode.c        Sun Sep 17 17:51:57 2000
+++ bfs/fs/bfs/inode.c  Sun Oct 15 23:30:37 2000
@@ -1,7 +1,7 @@
 /*
  *     fs/bfs/inode.c
  *     BFS superblock and inode operations.
- *     Copyright (C) 1999 Tigran Aivazian <[EMAIL PROTECTED]>
+ *     Copyright (C) 1999,2000 Tigran Aivazian <[EMAIL PROTECTED]>
  *     From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds.
  */
 
@@ -325,7 +325,7 @@
        return NULL;
 }
 
-static DECLARE_FSTYPE_DEV( bfs_fs_type, "bfs", bfs_read_super);
+static DECLARE_FSTYPE_DEV(bfs_fs_type, "bfs", bfs_read_super);
 
 static int __init init_bfs_fs(void)
 {

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to