1 #include <linux/module.h>
2 #include <linux/buffer_head.h>
4 #include <linux/pagemap.h>
5 #include <linux/highmem.h>
6 #include <linux/time.h>
7 #include <linux/init.h>
8 #include <linux/string.h>
9 #include <linux/smp_lock.h>
10 #include <linux/backing-dev.h>
11 #include <linux/mpage.h>
12 #include <linux/swap.h>
13 #include <linux/writeback.h>
14 #include <linux/statfs.h>
15 #include <linux/compat.h>
18 #include "transaction.h"
19 #include "btrfs_inode.h"
21 #include "print-tree.h"
23 #define BTRFS_SUPER_MAGIC 0x9123682E
25 static struct super_operations btrfs_super_ops
;
27 static void btrfs_put_super (struct super_block
* sb
)
29 struct btrfs_root
*root
= btrfs_sb(sb
);
32 ret
= close_ctree(root
);
34 printk("close ctree returns %d\n", ret
);
39 static int btrfs_fill_super(struct super_block
* sb
, void * data
, int silent
)
42 struct dentry
* root_dentry
;
43 struct btrfs_super_block
*disk_super
;
44 struct btrfs_root
*tree_root
;
45 struct btrfs_inode
*bi
;
48 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
49 sb
->s_magic
= BTRFS_SUPER_MAGIC
;
50 sb
->s_op
= &btrfs_super_ops
;
53 tree_root
= open_ctree(sb
);
55 if (!tree_root
|| IS_ERR(tree_root
)) {
56 printk("btrfs: open_ctree failed\n");
59 sb
->s_fs_info
= tree_root
;
60 disk_super
= tree_root
->fs_info
->disk_super
;
61 inode
= btrfs_iget_locked(sb
, btrfs_super_root_dir(disk_super
),
64 bi
->location
.objectid
= inode
->i_ino
;
65 bi
->location
.offset
= 0;
66 bi
->location
.flags
= 0;
68 btrfs_set_key_type(&bi
->location
, BTRFS_INODE_ITEM_KEY
);
74 if (inode
->i_state
& I_NEW
) {
75 btrfs_read_locked_inode(inode
);
76 unlock_new_inode(inode
);
79 root_dentry
= d_alloc_root(inode
);
85 sb
->s_root
= root_dentry
;
86 btrfs_transaction_queue_work(tree_root
, HZ
* 30);
90 close_ctree(tree_root
);
94 static int btrfs_sync_fs(struct super_block
*sb
, int wait
)
96 struct btrfs_trans_handle
*trans
;
97 struct btrfs_root
*root
;
103 filemap_flush(root
->fs_info
->btree_inode
->i_mapping
);
106 mutex_lock(&root
->fs_info
->fs_mutex
);
107 trans
= btrfs_start_transaction(root
, 1);
108 ret
= btrfs_commit_transaction(trans
, root
);
111 mutex_unlock(&root
->fs_info
->fs_mutex
);
115 static void btrfs_write_super(struct super_block
*sb
)
120 static int btrfs_get_sb(struct file_system_type
*fs_type
,
121 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
123 return get_sb_bdev(fs_type
, flags
, dev_name
, data
,
124 btrfs_fill_super
, mnt
);
127 static int btrfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
129 struct btrfs_root
*root
= btrfs_sb(dentry
->d_sb
);
130 struct btrfs_super_block
*disk_super
= root
->fs_info
->disk_super
;
132 buf
->f_namelen
= BTRFS_NAME_LEN
;
133 buf
->f_blocks
= btrfs_super_total_blocks(disk_super
);
134 buf
->f_bfree
= buf
->f_blocks
- btrfs_super_blocks_used(disk_super
);
135 buf
->f_bavail
= buf
->f_bfree
;
136 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
137 buf
->f_type
= BTRFS_SUPER_MAGIC
;
141 static struct file_system_type btrfs_fs_type
= {
142 .owner
= THIS_MODULE
,
144 .get_sb
= btrfs_get_sb
,
145 .kill_sb
= kill_block_super
,
146 .fs_flags
= FS_REQUIRES_DEV
,
149 static struct super_operations btrfs_super_ops
= {
150 .delete_inode
= btrfs_delete_inode
,
151 .put_super
= btrfs_put_super
,
152 .read_inode
= btrfs_read_locked_inode
,
153 .write_super
= btrfs_write_super
,
154 .sync_fs
= btrfs_sync_fs
,
155 .write_inode
= btrfs_write_inode
,
156 .dirty_inode
= btrfs_dirty_inode
,
157 .alloc_inode
= btrfs_alloc_inode
,
158 .destroy_inode
= btrfs_destroy_inode
,
159 .statfs
= btrfs_statfs
,
162 static int __init
init_btrfs_fs(void)
165 btrfs_init_transaction_sys();
166 err
= btrfs_init_cachep();
169 return register_filesystem(&btrfs_fs_type
);
172 static void __exit
exit_btrfs_fs(void)
174 btrfs_exit_transaction_sys();
175 btrfs_destroy_cachep();
176 unregister_filesystem(&btrfs_fs_type
);
179 module_init(init_btrfs_fs
)
180 module_exit(exit_btrfs_fs
)
182 MODULE_LICENSE("GPL");