minix: replace inode uid,gid,mode init with helper
[safe/jmp/linux-2.6] / fs / bfs / inode.c
index 3a9a136..f22a7d3 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
 #include <linux/vfs.h>
+#include <linux/writeback.h>
 #include <asm/uaccess.h>
 #include "bfs.h"
 
@@ -98,14 +99,15 @@ error:
        return ERR_PTR(-EIO);
 }
 
-static int bfs_write_inode(struct inode *inode, int unused)
+static int bfs_write_inode(struct inode *inode, struct writeback_control *wbc)
 {
+       struct bfs_sb_info *info = BFS_SB(inode->i_sb);
        unsigned int ino = (u16)inode->i_ino;
         unsigned long i_sblock;
        struct bfs_inode *di;
        struct buffer_head *bh;
        int block, off;
-       struct bfs_sb_info *info = BFS_SB(inode->i_sb);
+       int err = 0;
 
         dprintf("ino=%08x\n", ino);
 
@@ -146,9 +148,14 @@ static int bfs_write_inode(struct inode *inode, int unused)
        di->i_eoffset = cpu_to_le32(i_sblock * BFS_BSIZE + inode->i_size - 1);
 
        mark_buffer_dirty(bh);
+       if (wbc->sync_mode == WB_SYNC_ALL) {
+               sync_dirty_buffer(bh);
+               if (buffer_req(bh) && !buffer_uptodate(bh))
+                       err = -EIO;
+       }
        brelse(bh);
        mutex_unlock(&info->bfs_lock);
-       return 0;
+       return err;
 }
 
 static void bfs_delete_inode(struct inode *inode)
@@ -210,6 +217,26 @@ static void bfs_delete_inode(struct inode *inode)
        clear_inode(inode);
 }
 
+static int bfs_sync_fs(struct super_block *sb, int wait)
+{
+       struct bfs_sb_info *info = BFS_SB(sb);
+
+       mutex_lock(&info->bfs_lock);
+       mark_buffer_dirty(info->si_sbh);
+       sb->s_dirt = 0;
+       mutex_unlock(&info->bfs_lock);
+
+       return 0;
+}
+
+static void bfs_write_super(struct super_block *sb)
+{
+       if (!(sb->s_flags & MS_RDONLY))
+               bfs_sync_fs(sb, 1);
+       else
+               sb->s_dirt = 0;
+}
+
 static void bfs_put_super(struct super_block *s)
 {
        struct bfs_sb_info *info = BFS_SB(s);
@@ -248,17 +275,6 @@ static int bfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        return 0;
 }
 
-static void bfs_write_super(struct super_block *s)
-{
-       struct bfs_sb_info *info = BFS_SB(s);
-
-       mutex_lock(&info->bfs_lock);
-       if (!(s->s_flags & MS_RDONLY))
-               mark_buffer_dirty(info->si_sbh);
-       s->s_dirt = 0;
-       mutex_unlock(&info->bfs_lock);
-}
-
 static struct kmem_cache *bfs_inode_cachep;
 
 static struct inode *bfs_alloc_inode(struct super_block *sb)
@@ -306,6 +322,7 @@ static const struct super_operations bfs_sops = {
        .delete_inode   = bfs_delete_inode,
        .put_super      = bfs_put_super,
        .write_super    = bfs_write_super,
+       .sync_fs        = bfs_sync_fs,
        .statfs         = bfs_statfs,
 };
 
@@ -337,35 +354,35 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
        struct inode *inode;
        unsigned i, imap_len;
        struct bfs_sb_info *info;
-       long ret = -EINVAL;
+       int ret = -EINVAL;
        unsigned long i_sblock, i_eblock, i_eoff, s_size;
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
                return -ENOMEM;
+       mutex_init(&info->bfs_lock);
        s->s_fs_info = info;
 
        sb_set_blocksize(s, BFS_BSIZE);
 
-       bh = sb_bread(s, 0);
-       if(!bh)
+       info->si_sbh = sb_bread(s, 0);
+       if (!info->si_sbh)
                goto out;
-       bfs_sb = (struct bfs_super_block *)bh->b_data;
+       bfs_sb = (struct bfs_super_block *)info->si_sbh->b_data;
        if (le32_to_cpu(bfs_sb->s_magic) != BFS_MAGIC) {
                if (!silent)
                        printf("No BFS filesystem on %s (magic=%08x)\n", 
                                s->s_id,  le32_to_cpu(bfs_sb->s_magic));
-               goto out;
+               goto out1;
        }
        if (BFS_UNCLEAN(bfs_sb, s) && !silent)
                printf("%s is unclean, continuing\n", s->s_id);
 
        s->s_magic = BFS_MAGIC;
-       info->si_sbh = bh;
 
        if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end)) {
                printf("Superblock is corrupted\n");
-               goto out;
+               goto out1;
        }
 
        info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) /
@@ -374,7 +391,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
        imap_len = (info->si_lasti / 8) + 1;
        info->si_imap = kzalloc(imap_len, GFP_KERNEL);
        if (!info->si_imap)
-               goto out;
+               goto out1;
        for (i = 0; i < BFS_ROOT_INO; i++)
                set_bit(i, info->si_imap);
 
@@ -382,15 +399,13 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
        inode = bfs_iget(s, BFS_ROOT_INO);
        if (IS_ERR(inode)) {
                ret = PTR_ERR(inode);
-               kfree(info->si_imap);
-               goto out;
+               goto out2;
        }
        s->s_root = d_alloc_root(inode);
        if (!s->s_root) {
                iput(inode);
                ret = -ENOMEM;
-               kfree(info->si_imap);
-               goto out;
+               goto out2;
        }
 
        info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1) >> BFS_BSIZE_BITS;
@@ -403,10 +418,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
        bh = sb_bread(s, info->si_blocks - 1);
        if (!bh) {
                printf("Last block not available: %lu\n", info->si_blocks - 1);
-               iput(inode);
                ret = -EIO;
-               kfree(info->si_imap);
-               goto out;
+               goto out3;
        }
        brelse(bh);
 
@@ -443,11 +456,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
                        printf("Inode 0x%08x corrupted\n", i);
 
                        brelse(bh);
-                       s->s_root = NULL;
-                       kfree(info->si_imap);
-                       kfree(info);
-                       s->s_fs_info = NULL;
-                       return -EIO;
+                       ret = -EIO;
+                       goto out3;
                }
 
                if (!di->i_ino) {
@@ -467,11 +477,17 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
                s->s_dirt = 1;
        } 
        dump_imap("read_super", s);
-       mutex_init(&info->bfs_lock);
        return 0;
 
+out3:
+       dput(s->s_root);
+       s->s_root = NULL;
+out2:
+       kfree(info->si_imap);
+out1:
+       brelse(info->si_sbh);
 out:
-       brelse(bh);
+       mutex_destroy(&info->bfs_lock);
        kfree(info);
        s->s_fs_info = NULL;
        return ret;