diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 5346f70..5af2426 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -4,7 +4,7 @@
 obj-m  := btrfs.o
 btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   hash.o file-item.o inode-item.o inode-map.o disk-io.o \
-	   transaction.o bit-radix.o
+	   transaction.o bit-radix.o inode.o file.o
 
 #btrfs-y := ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
 #	  root-tree.o dir-item.o hash.o file-item.o inode-item.o \
@@ -16,7 +16,7 @@
 
 KERNELDIR := /lib/modules/`uname -r`/build
 all::
-	$(MAKE) C=1 -C $(KERNELDIR) M=`pwd` modules
+	$(MAKE) -C $(KERNELDIR) M=`pwd` modules
 clean::
 	rm *.o btrfs.ko
 endif
diff --git a/fs/btrfs/TODO b/fs/btrfs/TODO
index d9b6d38..4a48a23 100644
--- a/fs/btrfs/TODO
+++ b/fs/btrfs/TODO
@@ -1,3 +1,4 @@
+* fix printk warnings
 * cleanup, add more error checking, get rid of BUG_ONs
 * Fix ENOSPC handling
 * Make allocator smarter
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 4e136b7..24410d4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1123,5 +1123,28 @@
 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
 			struct btrfs_root *root, struct btrfs_path *path,
 			u64 isize);
-/* super.c */
+/* inode.c */
+void btrfs_delete_inode(struct inode *inode);
+void btrfs_read_locked_inode(struct inode *inode);
+int btrfs_write_inode(struct inode *inode, int wait);
+void btrfs_dirty_inode(struct inode *inode);
+struct inode *btrfs_alloc_inode(struct super_block *sb);
+void btrfs_destroy_inode(struct inode *inode);
+int btrfs_init_cachep(void);
+void btrfs_destroy_cachep(void);
+int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+		unsigned long arg);
+long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
+			       unsigned long arg);
+struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
+				struct btrfs_root *root);
+int btrfs_commit_write(struct file *file, struct page *page,
+		       unsigned from, unsigned to);
+int btrfs_get_block(struct inode *inode, sector_t iblock,
+		    struct buffer_head *result, int create);
+/* file.c */
+extern struct file_operations btrfs_file_operations;
+int btrfs_drop_extents(struct btrfs_trans_handle *trans,
+		       struct btrfs_root *root, struct inode *inode,
+		       u64 start, u64 end, u64 *hint_block);
 #endif
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8a88404..96bf3ef 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -22,7 +22,7 @@
 	if (bh_blocknr(buf) != btrfs_header_blocknr(&node->header)) {
 		printk(KERN_CRIT "bh_blocknr(buf) is %Lu, header is %Lu\n",
 		       bh_blocknr(buf), btrfs_header_blocknr(&node->header));
-		BUG();
+		return 1;
 	}
 	return 0;
 }
@@ -253,7 +253,7 @@
 		set_buffer_checked(bh);
 	}
 	if (check_tree_block(root, bh))
-		BUG();
+		goto fail;
 	return bh;
 fail:
 	brelse(bh);
@@ -398,8 +398,13 @@
 	struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
 						GFP_NOFS);
 	int ret;
+	int err = -EIO;
 	struct btrfs_super_block *disk_super;
 
+	if (!extent_root || !tree_root || !fs_info) {
+		err = -ENOMEM;
+		goto fail;
+	}
 	init_bit_radix(&fs_info->pinned_radix);
 	init_bit_radix(&fs_info->pending_del_radix);
 	init_bit_radix(&fs_info->extent_map_radix);
@@ -431,9 +436,11 @@
 	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
 	fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC);
 	spin_lock_init(&fs_info->hash_lock);
+
 	if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
-		printk("failed to allocate digest hash\n");
-		return NULL;
+		printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
+		err = -ENOMEM;
+		goto fail_iput;
 	}
 	mutex_init(&fs_info->trans_mutex);
 	mutex_init(&fs_info->fs_mutex);
@@ -446,30 +453,53 @@
 					     sb->s_blocksize);
 
 	if (!fs_info->sb_buffer)
-		return NULL;
+		goto fail_iput;
 	disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data;
+
 	if (!btrfs_super_root(disk_super))
-		return NULL;
+		goto fail_sb_buffer;
 
 	i_size_write(fs_info->btree_inode,
 		     btrfs_super_total_blocks(disk_super) <<
 		     fs_info->btree_inode->i_blkbits);
 
 	fs_info->disk_super = disk_super;
+
+	if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
+		    sizeof(disk_super->magic))) {
+		printk("btrfs: valid FS not found on %s\n", sb->s_id);
+		goto fail_sb_buffer;
+	}
 	tree_root->node = read_tree_block(tree_root,
 					  btrfs_super_root(disk_super));
-	BUG_ON(!tree_root->node);
+	if (!tree_root->node)
+		goto fail_sb_buffer;
 
 	mutex_lock(&fs_info->fs_mutex);
 	ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
 				  BTRFS_EXTENT_TREE_OBJECTID, extent_root);
-	BUG_ON(ret);
+	if (ret) {
+		mutex_unlock(&fs_info->fs_mutex);
+		goto fail_tree_root;
+	}
 
 	btrfs_read_block_groups(extent_root);
 
 	fs_info->generation = btrfs_super_generation(disk_super) + 1;
 	mutex_unlock(&fs_info->fs_mutex);
 	return tree_root;
+
+fail_tree_root:
+	btrfs_block_release(tree_root, tree_root->node);
+fail_sb_buffer:
+	btrfs_block_release(tree_root, fs_info->sb_buffer);
+fail_iput:
+	iput(fs_info->btree_inode);
+fail:
+	kfree(extent_root);
+	kfree(tree_root);
+	kfree(fs_info);
+	return ERR_PTR(err);
 }
 
 int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
new file mode 100644
index 0000000..7f8e303
--- /dev/null
+++ b/fs/btrfs/file.c
@@ -0,0 +1,783 @@
+#include <linux/module.h>
+#include <linux/buffer_head.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/highmem.h>
+#include <linux/time.h>
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/smp_lock.h>
+#include <linux/backing-dev.h>
+#include <linux/mpage.h>
+#include <linux/swap.h>
+#include <linux/writeback.h>
+#include <linux/statfs.h>
+#include <linux/compat.h>
+#include "ctree.h"
+#include "disk-io.h"
+#include "transaction.h"
+#include "btrfs_inode.h"
+#include "ioctl.h"
+#include "print-tree.h"
+
+
+static int btrfs_copy_from_user(loff_t pos, int num_pages, int write_bytes,
+				struct page **prepared_pages,
+				const char __user * buf)
+{
+	long page_fault = 0;
+	int i;
+	int offset = pos & (PAGE_CACHE_SIZE - 1);
+
+	for (i = 0; i < num_pages && write_bytes > 0; i++, offset = 0) {
+		size_t count = min_t(size_t,
+				     PAGE_CACHE_SIZE - offset, write_bytes);
+		struct page *page = prepared_pages[i];
+		fault_in_pages_readable(buf, count);
+
+		/* Copy data from userspace to the current page */
+		kmap(page);
+		page_fault = __copy_from_user(page_address(page) + offset,
+					      buf, count);
+		/* Flush processor's dcache for this page */
+		flush_dcache_page(page);
+		kunmap(page);
+		buf += count;
+		write_bytes -= count;
+
+		if (page_fault)
+			break;
+	}
+	return page_fault ? -EFAULT : 0;
+}
+
+static void btrfs_drop_pages(struct page **pages, size_t num_pages)
+{
+	size_t i;
+	for (i = 0; i < num_pages; i++) {
+		if (!pages[i])
+			break;
+		unlock_page(pages[i]);
+		mark_page_accessed(pages[i]);
+		page_cache_release(pages[i]);
+	}
+}
+
+static int dirty_and_release_pages(struct btrfs_trans_handle *trans,
+				   struct btrfs_root *root,
+				   struct file *file,
+				   struct page **pages,
+				   size_t num_pages,
+				   loff_t pos,
+				   size_t write_bytes)
+{
+	int i;
+	int offset;
+	int err = 0;
+	int ret;
+	int this_write;
+	struct inode *inode = file->f_path.dentry->d_inode;
+	struct buffer_head *bh;
+	struct btrfs_file_extent_item *ei;
+
+	for (i = 0; i < num_pages; i++) {
+		offset = pos & (PAGE_CACHE_SIZE -1);
+		this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
+		/* FIXME, one block at a time */
+
+		mutex_lock(&root->fs_info->fs_mutex);
+		trans = btrfs_start_transaction(root, 1);
+		btrfs_set_trans_block_group(trans, inode);
+
+		bh = page_buffers(pages[i]);
+
+		if (buffer_mapped(bh) && bh->b_blocknr == 0) {
+			struct btrfs_key key;
+			struct btrfs_path *path;
+			char *ptr;
+			u32 datasize;
+
+			/* create an inline extent, and copy the data in */
+			path = btrfs_alloc_path();
+			BUG_ON(!path);
+			key.objectid = inode->i_ino;
+			key.offset = pages[i]->index << PAGE_CACHE_SHIFT;
+			key.flags = 0;
+			btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
+			BUG_ON(write_bytes >= PAGE_CACHE_SIZE);
+			datasize = offset +
+				btrfs_file_extent_calc_inline_size(write_bytes);
+
+			ret = btrfs_insert_empty_item(trans, root, path, &key,
+						      datasize);
+			BUG_ON(ret);
+			ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+			       path->slots[0], struct btrfs_file_extent_item);
+			btrfs_set_file_extent_generation(ei, trans->transid);
+			btrfs_set_file_extent_type(ei,
+						   BTRFS_FILE_EXTENT_INLINE);
+			ptr = btrfs_file_extent_inline_start(ei);
+			btrfs_memcpy(root, path->nodes[0]->b_data,
+				     ptr, bh->b_data, offset + write_bytes);
+			mark_buffer_dirty(path->nodes[0]);
+			btrfs_free_path(path);
+		} else if (buffer_mapped(bh)) {
+			/* csum the file data */
+			btrfs_csum_file_block(trans, root, inode->i_ino,
+				      pages[i]->index << PAGE_CACHE_SHIFT,
+				      kmap(pages[i]), PAGE_CACHE_SIZE);
+			kunmap(pages[i]);
+		}
+		SetPageChecked(pages[i]);
+		ret = btrfs_end_transaction(trans, root);
+		BUG_ON(ret);
+		mutex_unlock(&root->fs_info->fs_mutex);
+
+		ret = btrfs_commit_write(file, pages[i], offset,
+					 offset + this_write);
+		pos += this_write;
+		if (ret) {
+			err = ret;
+			goto failed;
+		}
+		WARN_ON(this_write > write_bytes);
+		write_bytes -= this_write;
+	}
+failed:
+	return err;
+}
+
+/*
+ * this is very complex, but the basic idea is to drop all extents
+ * in the range start - end.  hint_block is filled in with a block number
+ * that would be a good hint to the block allocator for this file.
+ *
+ * If an extent intersects the range but is not entirely inside the range
+ * it is either truncated or split.  Anything entirely inside the range
+ * is deleted from the tree.
+ */
+int btrfs_drop_extents(struct btrfs_trans_handle *trans,
+		       struct btrfs_root *root, struct inode *inode,
+		       u64 start, u64 end, u64 *hint_block)
+{
+	int ret;
+	struct btrfs_key key;
+	struct btrfs_leaf *leaf;
+	int slot;
+	struct btrfs_file_extent_item *extent;
+	u64 extent_end = 0;
+	int keep;
+	struct btrfs_file_extent_item old;
+	struct btrfs_path *path;
+	u64 search_start = start;
+	int bookend;
+	int found_type;
+	int found_extent;
+	int found_inline;
+
+	path = btrfs_alloc_path();
+	if (!path)
+		return -ENOMEM;
+	while(1) {
+		btrfs_release_path(root, path);
+		ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
+					       search_start, -1);
+		if (ret < 0)
+			goto out;
+		if (ret > 0) {
+			if (path->slots[0] == 0) {
+				ret = 0;
+				goto out;
+			}
+			path->slots[0]--;
+		}
+		keep = 0;
+		bookend = 0;
+		found_extent = 0;
+		found_inline = 0;
+		extent = NULL;
+		leaf = btrfs_buffer_leaf(path->nodes[0]);
+		slot = path->slots[0];
+		btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
+		if (key.offset >= end || key.objectid != inode->i_ino) {
+			ret = 0;
+			goto out;
+		}
+		if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY) {
+			ret = 0;
+			goto out;
+		}
+		extent = btrfs_item_ptr(leaf, slot,
+					struct btrfs_file_extent_item);
+		found_type = btrfs_file_extent_type(extent);
+		if (found_type == BTRFS_FILE_EXTENT_REG) {
+			extent_end = key.offset +
+				(btrfs_file_extent_num_blocks(extent) <<
+				 inode->i_blkbits);
+			found_extent = 1;
+		} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
+			found_inline = 1;
+			extent_end = key.offset +
+			     btrfs_file_extent_inline_len(leaf->items + slot);
+		}
+
+		/* we found nothing we can drop */
+		if (!found_extent && !found_inline) {
+			ret = 0;
+			goto out;
+		}
+
+		/* we found nothing inside the range */
+		if (search_start >= extent_end) {
+			ret = 0;
+			goto out;
+		}
+
+		/* FIXME, there's only one inline extent allowed right now */
+		if (found_inline) {
+			u64 mask = root->blocksize - 1;
+			search_start = (extent_end + mask) & ~mask;
+		} else
+			search_start = extent_end;
+
+		if (end < extent_end && end >= key.offset) {
+			if (found_extent) {
+				u64 disk_blocknr =
+					btrfs_file_extent_disk_blocknr(extent);
+				u64 disk_num_blocks =
+				      btrfs_file_extent_disk_num_blocks(extent);
+				memcpy(&old, extent, sizeof(old));
+				if (disk_blocknr != 0) {
+					ret = btrfs_inc_extent_ref(trans, root,
+					         disk_blocknr, disk_num_blocks);
+					BUG_ON(ret);
+				}
+			}
+			WARN_ON(found_inline);
+			bookend = 1;
+		}
+
+		/* truncate existing extent */
+		if (start > key.offset) {
+			u64 new_num;
+			u64 old_num;
+			keep = 1;
+			WARN_ON(start & (root->blocksize - 1));
+			if (found_extent) {
+				new_num = (start - key.offset) >>
+					inode->i_blkbits;
+				old_num = btrfs_file_extent_num_blocks(extent);
+				*hint_block =
+					btrfs_file_extent_disk_blocknr(extent);
+				if (btrfs_file_extent_disk_blocknr(extent)) {
+					inode->i_blocks -=
+						(old_num - new_num) << 3;
+				}
+				btrfs_set_file_extent_num_blocks(extent,
+								 new_num);
+				mark_buffer_dirty(path->nodes[0]);
+			} else {
+				WARN_ON(1);
+			}
+		}
+		/* delete the entire extent */
+		if (!keep) {
+			u64 disk_blocknr = 0;
+			u64 disk_num_blocks = 0;
+			u64 extent_num_blocks = 0;
+			if (found_extent) {
+				disk_blocknr =
+				      btrfs_file_extent_disk_blocknr(extent);
+				disk_num_blocks =
+				      btrfs_file_extent_disk_num_blocks(extent);
+				extent_num_blocks =
+				      btrfs_file_extent_num_blocks(extent);
+				*hint_block =
+					btrfs_file_extent_disk_blocknr(extent);
+			}
+			ret = btrfs_del_item(trans, root, path);
+			BUG_ON(ret);
+			btrfs_release_path(root, path);
+			extent = NULL;
+			if (found_extent && disk_blocknr != 0) {
+				inode->i_blocks -= extent_num_blocks << 3;
+				ret = btrfs_free_extent(trans, root,
+							disk_blocknr,
+							disk_num_blocks, 0);
+			}
+
+			BUG_ON(ret);
+			if (!bookend && search_start >= end) {
+				ret = 0;
+				goto out;
+			}
+			if (!bookend)
+				continue;
+		}
+		/* create bookend, splitting the extent in two */
+		if (bookend && found_extent) {
+			struct btrfs_key ins;
+			ins.objectid = inode->i_ino;
+			ins.offset = end;
+			ins.flags = 0;
+			btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY);
+
+			btrfs_release_path(root, path);
+			ret = btrfs_insert_empty_item(trans, root, path, &ins,
+						      sizeof(*extent));
+			BUG_ON(ret);
+			extent = btrfs_item_ptr(
+				    btrfs_buffer_leaf(path->nodes[0]),
+				    path->slots[0],
+				    struct btrfs_file_extent_item);
+			btrfs_set_file_extent_disk_blocknr(extent,
+				    btrfs_file_extent_disk_blocknr(&old));
+			btrfs_set_file_extent_disk_num_blocks(extent,
+				    btrfs_file_extent_disk_num_blocks(&old));
+
+			btrfs_set_file_extent_offset(extent,
+				    btrfs_file_extent_offset(&old) +
+				    ((end - key.offset) >> inode->i_blkbits));
+			WARN_ON(btrfs_file_extent_num_blocks(&old) <
+				(extent_end - end) >> inode->i_blkbits);
+			btrfs_set_file_extent_num_blocks(extent,
+				    (extent_end - end) >> inode->i_blkbits);
+
+			btrfs_set_file_extent_type(extent,
+						   BTRFS_FILE_EXTENT_REG);
+			btrfs_set_file_extent_generation(extent,
+				    btrfs_file_extent_generation(&old));
+			btrfs_mark_buffer_dirty(path->nodes[0]);
+			if (btrfs_file_extent_disk_blocknr(&old) != 0) {
+				inode->i_blocks +=
+				      btrfs_file_extent_num_blocks(extent) << 3;
+			}
+			ret = 0;
+			goto out;
+		}
+	}
+out:
+	btrfs_free_path(path);
+	return ret;
+}
+
+/*
+ * this gets pages into the page cache and locks them down
+ */
+static int prepare_pages(struct btrfs_root *root,
+			 struct file *file,
+			 struct page **pages,
+			 size_t num_pages,
+			 loff_t pos,
+			 unsigned long first_index,
+			 unsigned long last_index,
+			 size_t write_bytes,
+			 u64 alloc_extent_start)
+{
+	int i;
+	unsigned long index = pos >> PAGE_CACHE_SHIFT;
+	struct inode *inode = file->f_path.dentry->d_inode;
+	int offset;
+	int err = 0;
+	int this_write;
+	struct buffer_head *bh;
+	struct buffer_head *head;
+	loff_t isize = i_size_read(inode);
+
+	memset(pages, 0, num_pages * sizeof(struct page *));
+
+	for (i = 0; i < num_pages; i++) {
+		pages[i] = grab_cache_page(inode->i_mapping, index + i);
+		if (!pages[i]) {
+			err = -ENOMEM;
+			goto failed_release;
+		}
+		cancel_dirty_page(pages[i], PAGE_CACHE_SIZE);
+		wait_on_page_writeback(pages[i]);
+		offset = pos & (PAGE_CACHE_SIZE -1);
+		this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
+		if (!page_has_buffers(pages[i])) {
+			create_empty_buffers(pages[i],
+					     root->fs_info->sb->s_blocksize,
+					     (1 << BH_Uptodate));
+		}
+		head = page_buffers(pages[i]);
+		bh = head;
+		do {
+			err = btrfs_map_bh_to_logical(root, bh,
+						      alloc_extent_start);
+			BUG_ON(err);
+			if (err)
+				goto failed_truncate;
+			bh = bh->b_this_page;
+			if (alloc_extent_start)
+				alloc_extent_start++;
+		} while (bh != head);
+		pos += this_write;
+		WARN_ON(this_write > write_bytes);
+		write_bytes -= this_write;
+	}
+	return 0;
+
+failed_release:
+	btrfs_drop_pages(pages, num_pages);
+	return err;
+
+failed_truncate:
+	btrfs_drop_pages(pages, num_pages);
+	if (pos > isize)
+		vmtruncate(inode, isize);
+	return err;
+}
+
+static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	loff_t pos;
+	size_t num_written = 0;
+	int err = 0;
+	int ret = 0;
+	struct inode *inode = file->f_path.dentry->d_inode;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct page *pages[8];
+	struct page *pinned[2];
+	unsigned long first_index;
+	unsigned long last_index;
+	u64 start_pos;
+	u64 num_blocks;
+	u64 alloc_extent_start;
+	u64 hint_block;
+	struct btrfs_trans_handle *trans;
+	struct btrfs_key ins;
+	pinned[0] = NULL;
+	pinned[1] = NULL;
+	if (file->f_flags & O_DIRECT)
+		return -EINVAL;
+	pos = *ppos;
+	vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
+	current->backing_dev_info = inode->i_mapping->backing_dev_info;
+	err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
+	if (err)
+		goto out;
+	if (count == 0)
+		goto out;
+	err = remove_suid(file->f_path.dentry);
+	if (err)
+		goto out;
+	file_update_time(file);
+
+	start_pos = pos & ~((u64)PAGE_CACHE_SIZE - 1);
+	num_blocks = (count + pos - start_pos + root->blocksize - 1) >>
+			inode->i_blkbits;
+
+	mutex_lock(&inode->i_mutex);
+	first_index = pos >> PAGE_CACHE_SHIFT;
+	last_index = (pos + count) >> PAGE_CACHE_SHIFT;
+
+	/*
+	 * there are lots of better ways to do this, but this code
+	 * makes sure the first and last page in the file range are
+	 * up to date and ready for cow
+	 */
+	if ((pos & (PAGE_CACHE_SIZE - 1))) {
+		pinned[0] = grab_cache_page(inode->i_mapping, first_index);
+		if (!PageUptodate(pinned[0])) {
+			ret = mpage_readpage(pinned[0], btrfs_get_block);
+			BUG_ON(ret);
+			wait_on_page_locked(pinned[0]);
+		} else {
+			unlock_page(pinned[0]);
+		}
+	}
+	if ((pos + count) & (PAGE_CACHE_SIZE - 1)) {
+		pinned[1] = grab_cache_page(inode->i_mapping, last_index);
+		if (!PageUptodate(pinned[1])) {
+			ret = mpage_readpage(pinned[1], btrfs_get_block);
+			BUG_ON(ret);
+			wait_on_page_locked(pinned[1]);
+		} else {
+			unlock_page(pinned[1]);
+		}
+	}
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	if (!trans) {
+		err = -ENOMEM;
+		mutex_unlock(&root->fs_info->fs_mutex);
+		goto out_unlock;
+	}
+	btrfs_set_trans_block_group(trans, inode);
+	/* FIXME blocksize != 4096 */
+	inode->i_blocks += num_blocks << 3;
+	hint_block = 0;
+
+	/* FIXME...EIEIO, ENOSPC and more */
+
+	/* step one, delete the existing extents in this range */
+	if (start_pos < inode->i_size) {
+		/* FIXME blocksize != pagesize */
+		ret = btrfs_drop_extents(trans, root, inode,
+					 start_pos,
+					 (pos + count + root->blocksize -1) &
+					 ~((u64)root->blocksize - 1),
+					 &hint_block);
+		BUG_ON(ret);
+	}
+
+	/* insert any holes we need to create */
+	if (inode->i_size < start_pos) {
+		u64 last_pos_in_file;
+		u64 hole_size;
+		u64 mask = root->blocksize - 1;
+		last_pos_in_file = (inode->i_size + mask) & ~mask;
+		hole_size = (start_pos - last_pos_in_file + mask) & ~mask;
+		hole_size >>= inode->i_blkbits;
+		if (last_pos_in_file < start_pos) {
+			ret = btrfs_insert_file_extent(trans, root,
+						       inode->i_ino,
+						       last_pos_in_file,
+						       0, 0, hole_size);
+		}
+		BUG_ON(ret);
+	}
+
+	/*
+	 * either allocate an extent for the new bytes or setup the key
+	 * to show we are doing inline data in the extent
+	 */
+	if (inode->i_size >= PAGE_CACHE_SIZE || pos + count < inode->i_size ||
+	    pos + count - start_pos > BTRFS_MAX_INLINE_DATA_SIZE(root)) {
+		ret = btrfs_alloc_extent(trans, root, inode->i_ino,
+					 num_blocks, hint_block, (u64)-1,
+					 &ins, 1);
+		BUG_ON(ret);
+		ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
+				       start_pos, ins.objectid, ins.offset,
+				       ins.offset);
+		BUG_ON(ret);
+	} else {
+		ins.offset = 0;
+		ins.objectid = 0;
+	}
+	BUG_ON(ret);
+	alloc_extent_start = ins.objectid;
+	ret = btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	while(count > 0) {
+		size_t offset = pos & (PAGE_CACHE_SIZE - 1);
+		size_t write_bytes = min(count, PAGE_CACHE_SIZE - offset);
+		size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
+					PAGE_CACHE_SHIFT;
+
+		memset(pages, 0, sizeof(pages));
+		ret = prepare_pages(root, file, pages, num_pages,
+				    pos, first_index, last_index,
+				    write_bytes, alloc_extent_start);
+		BUG_ON(ret);
+
+		/* FIXME blocks != pagesize */
+		if (alloc_extent_start)
+			alloc_extent_start += num_pages;
+		ret = btrfs_copy_from_user(pos, num_pages,
+					   write_bytes, pages, buf);
+		BUG_ON(ret);
+
+		ret = dirty_and_release_pages(NULL, root, file, pages,
+					      num_pages, pos, write_bytes);
+		BUG_ON(ret);
+		btrfs_drop_pages(pages, num_pages);
+
+		buf += write_bytes;
+		count -= write_bytes;
+		pos += write_bytes;
+		num_written += write_bytes;
+
+		balance_dirty_pages_ratelimited(inode->i_mapping);
+		btrfs_btree_balance_dirty(root);
+		cond_resched();
+	}
+out_unlock:
+	mutex_unlock(&inode->i_mutex);
+out:
+	if (pinned[0])
+		page_cache_release(pinned[0]);
+	if (pinned[1])
+		page_cache_release(pinned[1]);
+	*ppos = pos;
+	current->backing_dev_info = NULL;
+	mark_inode_dirty(inode);
+	return num_written ? num_written : err;
+}
+
+/*
+ * FIXME, do this by stuffing the csum we want in the info hanging off
+ * page->private.  For now, verify file csums on read
+ */
+static int btrfs_read_actor(read_descriptor_t *desc, struct page *page,
+			unsigned long offset, unsigned long size)
+{
+	char *kaddr;
+	unsigned long left, count = desc->count;
+	struct inode *inode = page->mapping->host;
+
+	if (size > count)
+		size = count;
+
+	if (!PageChecked(page)) {
+		/* FIXME, do it per block */
+		struct btrfs_root *root = BTRFS_I(inode)->root;
+		int ret;
+		struct buffer_head *bh;
+
+		if (page_has_buffers(page)) {
+			bh = page_buffers(page);
+			if (!buffer_mapped(bh)) {
+				SetPageChecked(page);
+				goto checked;
+			}
+		}
+
+		ret = btrfs_csum_verify_file_block(root,
+				  page->mapping->host->i_ino,
+				  page->index << PAGE_CACHE_SHIFT,
+				  kmap(page), PAGE_CACHE_SIZE);
+		if (ret) {
+			if (ret != -ENOENT) {
+				printk("failed to verify ino %lu page %lu ret %d\n",
+				       page->mapping->host->i_ino,
+				       page->index, ret);
+				memset(page_address(page), 1, PAGE_CACHE_SIZE);
+				flush_dcache_page(page);
+			}
+		}
+		SetPageChecked(page);
+		kunmap(page);
+	}
+checked:
+	/*
+	 * Faults on the destination of a read are common, so do it before
+	 * taking the kmap.
+	 */
+	if (!fault_in_pages_writeable(desc->arg.buf, size)) {
+		kaddr = kmap_atomic(page, KM_USER0);
+		left = __copy_to_user_inatomic(desc->arg.buf,
+						kaddr + offset, size);
+		kunmap_atomic(kaddr, KM_USER0);
+		if (left == 0)
+			goto success;
+	}
+
+	/* Do it the slow way */
+	kaddr = kmap(page);
+	left = __copy_to_user(desc->arg.buf, kaddr + offset, size);
+	kunmap(page);
+
+	if (left) {
+		size -= left;
+		desc->error = -EFAULT;
+	}
+success:
+	desc->count = count - size;
+	desc->written += size;
+	desc->arg.buf += size;
+	return size;
+}
+
+/**
+ * btrfs_file_aio_read - filesystem read routine, with a mod to csum verify
+ * @iocb:	kernel I/O control block
+ * @iov:	io vector request
+ * @nr_segs:	number of segments in the iovec
+ * @pos:	current file position
+ */
+static ssize_t btrfs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
+				   unsigned long nr_segs, loff_t pos)
+{
+	struct file *filp = iocb->ki_filp;
+	ssize_t retval;
+	unsigned long seg;
+	size_t count;
+	loff_t *ppos = &iocb->ki_pos;
+
+	count = 0;
+	for (seg = 0; seg < nr_segs; seg++) {
+		const struct iovec *iv = &iov[seg];
+
+		/*
+		 * If any segment has a negative length, or the cumulative
+		 * length ever wraps negative then return -EINVAL.
+		 */
+		count += iv->iov_len;
+		if (unlikely((ssize_t)(count|iv->iov_len) < 0))
+			return -EINVAL;
+		if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len))
+			continue;
+		if (seg == 0)
+			return -EFAULT;
+		nr_segs = seg;
+		count -= iv->iov_len;	/* This segment is no good */
+		break;
+	}
+	retval = 0;
+	if (count) {
+		for (seg = 0; seg < nr_segs; seg++) {
+			read_descriptor_t desc;
+
+			desc.written = 0;
+			desc.arg.buf = iov[seg].iov_base;
+			desc.count = iov[seg].iov_len;
+			if (desc.count == 0)
+				continue;
+			desc.error = 0;
+			do_generic_file_read(filp, ppos, &desc,
+					     btrfs_read_actor);
+			retval += desc.written;
+			if (desc.error) {
+				retval = retval ?: desc.error;
+				break;
+			}
+		}
+	}
+	return retval;
+}
+
+static int btrfs_sync_file(struct file *file,
+			   struct dentry *dentry, int datasync)
+{
+	struct inode *inode = dentry->d_inode;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	int ret;
+	struct btrfs_trans_handle *trans;
+
+	/*
+	 * FIXME, use inode generation number to check if we can skip the
+	 * commit
+	 */
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	if (!trans) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	ret = btrfs_commit_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+out:
+	return ret > 0 ? EIO : ret;
+}
+
+struct file_operations btrfs_file_operations = {
+	.llseek		= generic_file_llseek,
+	.read		= do_sync_read,
+	.aio_read       = btrfs_file_aio_read,
+	.write		= btrfs_file_write,
+	.mmap		= generic_file_mmap,
+	.open		= generic_file_open,
+	.ioctl		= btrfs_ioctl,
+	.fsync		= btrfs_sync_file,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= btrfs_compat_ioctl,
+#endif
+};
+
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
new file mode 100644
index 0000000..62a3a77
--- /dev/null
+++ b/fs/btrfs/inode.c
@@ -0,0 +1,2210 @@
+#include <linux/module.h>
+#include <linux/buffer_head.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/highmem.h>
+#include <linux/time.h>
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/smp_lock.h>
+#include <linux/backing-dev.h>
+#include <linux/mpage.h>
+#include <linux/swap.h>
+#include <linux/writeback.h>
+#include <linux/statfs.h>
+#include <linux/compat.h>
+#include "ctree.h"
+#include "disk-io.h"
+#include "transaction.h"
+#include "btrfs_inode.h"
+#include "ioctl.h"
+#include "print-tree.h"
+
+struct btrfs_iget_args {
+	u64 ino;
+	struct btrfs_root *root;
+};
+
+static struct inode_operations btrfs_dir_inode_operations;
+static struct inode_operations btrfs_symlink_inode_operations;
+static struct inode_operations btrfs_dir_ro_inode_operations;
+static struct inode_operations btrfs_file_inode_operations;
+static struct address_space_operations btrfs_aops;
+static struct address_space_operations btrfs_symlink_aops;
+static struct file_operations btrfs_dir_file_operations;
+
+static struct kmem_cache *btrfs_inode_cachep;
+struct kmem_cache *btrfs_trans_handle_cachep;
+struct kmem_cache *btrfs_transaction_cachep;
+struct kmem_cache *btrfs_bit_radix_cachep;
+struct kmem_cache *btrfs_path_cachep;
+
+#define S_SHIFT 12
+static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
+	[S_IFREG >> S_SHIFT]	= BTRFS_FT_REG_FILE,
+	[S_IFDIR >> S_SHIFT]	= BTRFS_FT_DIR,
+	[S_IFCHR >> S_SHIFT]	= BTRFS_FT_CHRDEV,
+	[S_IFBLK >> S_SHIFT]	= BTRFS_FT_BLKDEV,
+	[S_IFIFO >> S_SHIFT]	= BTRFS_FT_FIFO,
+	[S_IFSOCK >> S_SHIFT]	= BTRFS_FT_SOCK,
+	[S_IFLNK >> S_SHIFT]	= BTRFS_FT_SYMLINK,
+};
+
+void btrfs_read_locked_inode(struct inode *inode)
+{
+	struct btrfs_path *path;
+	struct btrfs_inode_item *inode_item;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_key location;
+	u64 alloc_group_block;
+	int ret;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	mutex_lock(&root->fs_info->fs_mutex);
+
+	memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
+	ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
+	if (ret) {
+		btrfs_free_path(path);
+		goto make_bad;
+	}
+	inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+				  path->slots[0],
+				  struct btrfs_inode_item);
+
+	inode->i_mode = btrfs_inode_mode(inode_item);
+	inode->i_nlink = btrfs_inode_nlink(inode_item);
+	inode->i_uid = btrfs_inode_uid(inode_item);
+	inode->i_gid = btrfs_inode_gid(inode_item);
+	inode->i_size = btrfs_inode_size(inode_item);
+	inode->i_atime.tv_sec = btrfs_timespec_sec(&inode_item->atime);
+	inode->i_atime.tv_nsec = btrfs_timespec_nsec(&inode_item->atime);
+	inode->i_mtime.tv_sec = btrfs_timespec_sec(&inode_item->mtime);
+	inode->i_mtime.tv_nsec = btrfs_timespec_nsec(&inode_item->mtime);
+	inode->i_ctime.tv_sec = btrfs_timespec_sec(&inode_item->ctime);
+	inode->i_ctime.tv_nsec = btrfs_timespec_nsec(&inode_item->ctime);
+	inode->i_blocks = btrfs_inode_nblocks(inode_item);
+	inode->i_generation = btrfs_inode_generation(inode_item);
+	alloc_group_block = btrfs_inode_block_group(inode_item);
+	BTRFS_I(inode)->block_group = btrfs_lookup_block_group(root->fs_info,
+						       alloc_group_block);
+
+	btrfs_free_path(path);
+	inode_item = NULL;
+
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	switch (inode->i_mode & S_IFMT) {
+#if 0
+	default:
+		init_special_inode(inode, inode->i_mode,
+				   btrfs_inode_rdev(inode_item));
+		break;
+#endif
+	case S_IFREG:
+		inode->i_mapping->a_ops = &btrfs_aops;
+		inode->i_fop = &btrfs_file_operations;
+		inode->i_op = &btrfs_file_inode_operations;
+		break;
+	case S_IFDIR:
+		inode->i_fop = &btrfs_dir_file_operations;
+		if (root == root->fs_info->tree_root)
+			inode->i_op = &btrfs_dir_ro_inode_operations;
+		else
+			inode->i_op = &btrfs_dir_inode_operations;
+		break;
+	case S_IFLNK:
+		inode->i_op = &btrfs_symlink_inode_operations;
+		inode->i_mapping->a_ops = &btrfs_symlink_aops;
+		break;
+	}
+	return;
+
+make_bad:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	make_bad_inode(inode);
+}
+
+static void fill_inode_item(struct btrfs_inode_item *item,
+			    struct inode *inode)
+{
+	btrfs_set_inode_uid(item, inode->i_uid);
+	btrfs_set_inode_gid(item, inode->i_gid);
+	btrfs_set_inode_size(item, inode->i_size);
+	btrfs_set_inode_mode(item, inode->i_mode);
+	btrfs_set_inode_nlink(item, inode->i_nlink);
+	btrfs_set_timespec_sec(&item->atime, inode->i_atime.tv_sec);
+	btrfs_set_timespec_nsec(&item->atime, inode->i_atime.tv_nsec);
+	btrfs_set_timespec_sec(&item->mtime, inode->i_mtime.tv_sec);
+	btrfs_set_timespec_nsec(&item->mtime, inode->i_mtime.tv_nsec);
+	btrfs_set_timespec_sec(&item->ctime, inode->i_ctime.tv_sec);
+	btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec);
+	btrfs_set_inode_nblocks(item, inode->i_blocks);
+	btrfs_set_inode_generation(item, inode->i_generation);
+	btrfs_set_inode_block_group(item,
+				    BTRFS_I(inode)->block_group->key.objectid);
+}
+
+static int btrfs_update_inode(struct btrfs_trans_handle *trans,
+			      struct btrfs_root *root,
+			      struct inode *inode)
+{
+	struct btrfs_inode_item *inode_item;
+	struct btrfs_path *path;
+	int ret;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	ret = btrfs_lookup_inode(trans, root, path,
+				 &BTRFS_I(inode)->location, 1);
+	if (ret) {
+		if (ret > 0)
+			ret = -ENOENT;
+		goto failed;
+	}
+
+	inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+				  path->slots[0],
+				  struct btrfs_inode_item);
+
+	fill_inode_item(inode_item, inode);
+	btrfs_mark_buffer_dirty(path->nodes[0]);
+	ret = 0;
+failed:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	return ret;
+}
+
+
+static int btrfs_unlink_trans(struct btrfs_trans_handle *trans,
+			      struct btrfs_root *root,
+			      struct inode *dir,
+			      struct dentry *dentry)
+{
+	struct btrfs_path *path;
+	const char *name = dentry->d_name.name;
+	int name_len = dentry->d_name.len;
+	int ret = 0;
+	u64 objectid;
+	struct btrfs_dir_item *di;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino,
+				    name, name_len, -1);
+	if (IS_ERR(di)) {
+		ret = PTR_ERR(di);
+		goto err;
+	}
+	if (!di) {
+		ret = -ENOENT;
+		goto err;
+	}
+	objectid = btrfs_disk_key_objectid(&di->location);
+	ret = btrfs_delete_one_dir_name(trans, root, path, di);
+	BUG_ON(ret);
+	btrfs_release_path(root, path);
+
+	di = btrfs_lookup_dir_index_item(trans, root, path, dir->i_ino,
+					 objectid, name, name_len, -1);
+	if (IS_ERR(di)) {
+		ret = PTR_ERR(di);
+		goto err;
+	}
+	if (!di) {
+		ret = -ENOENT;
+		goto err;
+	}
+	ret = btrfs_delete_one_dir_name(trans, root, path, di);
+	BUG_ON(ret);
+
+	dentry->d_inode->i_ctime = dir->i_ctime;
+err:
+	btrfs_free_path(path);
+	if (!ret) {
+		dir->i_size -= name_len * 2;
+		btrfs_update_inode(trans, root, dir);
+		drop_nlink(dentry->d_inode);
+		btrfs_update_inode(trans, root, dentry->d_inode);
+		dir->i_sb->s_dirt = 1;
+	}
+	return ret;
+}
+
+static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
+{
+	struct btrfs_root *root;
+	struct btrfs_trans_handle *trans;
+	int ret;
+
+	root = BTRFS_I(dir)->root;
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+	ret = btrfs_unlink_trans(trans, root, dir, dentry);
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+	return ret;
+}
+
+static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
+{
+	struct inode *inode = dentry->d_inode;
+	int err;
+	int ret;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	struct btrfs_path *path;
+	struct btrfs_key key;
+	struct btrfs_trans_handle *trans;
+	struct btrfs_key found_key;
+	int found_type;
+	struct btrfs_leaf *leaf;
+	char *goodnames = "..";
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+	key.objectid = inode->i_ino;
+	key.offset = (u64)-1;
+	key.flags = (u32)-1;
+	while(1) {
+		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+		if (ret < 0) {
+			err = ret;
+			goto out;
+		}
+		BUG_ON(ret == 0);
+		if (path->slots[0] == 0) {
+			err = -ENOENT;
+			goto out;
+		}
+		path->slots[0]--;
+		leaf = btrfs_buffer_leaf(path->nodes[0]);
+		btrfs_disk_key_to_cpu(&found_key,
+				      &leaf->items[path->slots[0]].key);
+		found_type = btrfs_key_type(&found_key);
+		if (found_key.objectid != inode->i_ino) {
+			err = -ENOENT;
+			goto out;
+		}
+		if ((found_type != BTRFS_DIR_ITEM_KEY &&
+		     found_type != BTRFS_DIR_INDEX_KEY) ||
+	            (!btrfs_match_dir_item_name(root, path, goodnames, 2) &&
+	            !btrfs_match_dir_item_name(root, path, goodnames, 1))) {
+			err = -ENOTEMPTY;
+			goto out;
+		}
+		ret = btrfs_del_item(trans, root, path);
+		BUG_ON(ret);
+
+		if (found_type == BTRFS_DIR_ITEM_KEY && found_key.offset == 1)
+			break;
+		btrfs_release_path(root, path);
+	}
+	ret = 0;
+	btrfs_release_path(root, path);
+
+	/* now the directory is empty */
+	err = btrfs_unlink_trans(trans, root, dir, dentry);
+	if (!err) {
+		inode->i_size = 0;
+	}
+out:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	ret = btrfs_end_transaction(trans, root);
+	btrfs_btree_balance_dirty(root);
+	if (ret && !err)
+		err = ret;
+	return err;
+}
+
+static int btrfs_free_inode(struct btrfs_trans_handle *trans,
+			    struct btrfs_root *root,
+			    struct inode *inode)
+{
+	struct btrfs_path *path;
+	int ret;
+
+	clear_inode(inode);
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	ret = btrfs_lookup_inode(trans, root, path,
+				 &BTRFS_I(inode)->location, -1);
+	BUG_ON(ret);
+	ret = btrfs_del_item(trans, root, path);
+	BUG_ON(ret);
+	btrfs_free_path(path);
+	return ret;
+}
+
+/*
+ * truncates go from a high offset to a low offset.  So, walk
+ * from hi to lo in the node and issue readas.  Stop when you find
+ * keys from a different objectid
+ */
+static void reada_truncate(struct btrfs_root *root, struct btrfs_path *path,
+			   u64 objectid)
+{
+	struct btrfs_node *node;
+	int i;
+	int nritems;
+	u64 item_objectid;
+	u64 blocknr;
+	int slot;
+	int ret;
+
+	if (!path->nodes[1])
+		return;
+	node = btrfs_buffer_node(path->nodes[1]);
+	slot = path->slots[1];
+	if (slot == 0)
+		return;
+	nritems = btrfs_header_nritems(&node->header);
+	for (i = slot - 1; i >= 0; i--) {
+		item_objectid = btrfs_disk_key_objectid(&node->ptrs[i].key);
+		if (item_objectid != objectid)
+			break;
+		blocknr = btrfs_node_blockptr(node, i);
+		ret = readahead_tree_block(root, blocknr);
+		if (ret)
+			break;
+	}
+}
+
+/*
+ * this can truncate away extent items, csum items and directory items.
+ * It starts at a high offset and removes keys until it can't find
+ * any higher than i_size.
+ *
+ * csum items that cross the new i_size are truncated to the new size
+ * as well.
+ */
+static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
+				   struct btrfs_root *root,
+				   struct inode *inode)
+{
+	int ret;
+	struct btrfs_path *path;
+	struct btrfs_key key;
+	struct btrfs_disk_key *found_key;
+	u32 found_type;
+	struct btrfs_leaf *leaf;
+	struct btrfs_file_extent_item *fi;
+	u64 extent_start = 0;
+	u64 extent_num_blocks = 0;
+	u64 item_end = 0;
+	int found_extent;
+	int del_item;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	/* FIXME, add redo link to tree so we don't leak on crash */
+	key.objectid = inode->i_ino;
+	key.offset = (u64)-1;
+	key.flags = (u32)-1;
+	while(1) {
+		btrfs_init_path(path);
+		fi = NULL;
+		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+		if (ret < 0) {
+			goto error;
+		}
+		if (ret > 0) {
+			BUG_ON(path->slots[0] == 0);
+			path->slots[0]--;
+		}
+		reada_truncate(root, path, inode->i_ino);
+		leaf = btrfs_buffer_leaf(path->nodes[0]);
+		found_key = &leaf->items[path->slots[0]].key;
+		found_type = btrfs_disk_key_type(found_key);
+
+		if (btrfs_disk_key_objectid(found_key) != inode->i_ino)
+			break;
+		if (found_type != BTRFS_CSUM_ITEM_KEY &&
+		    found_type != BTRFS_DIR_ITEM_KEY &&
+		    found_type != BTRFS_DIR_INDEX_KEY &&
+		    found_type != BTRFS_EXTENT_DATA_KEY)
+			break;
+
+		item_end = btrfs_disk_key_offset(found_key);
+		if (found_type == BTRFS_EXTENT_DATA_KEY) {
+			fi = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+					    path->slots[0],
+					    struct btrfs_file_extent_item);
+			if (btrfs_file_extent_type(fi) !=
+			    BTRFS_FILE_EXTENT_INLINE) {
+				item_end += btrfs_file_extent_num_blocks(fi) <<
+						inode->i_blkbits;
+			}
+		}
+		if (found_type == BTRFS_CSUM_ITEM_KEY) {
+			ret = btrfs_csum_truncate(trans, root, path,
+						  inode->i_size);
+			BUG_ON(ret);
+		}
+		if (item_end < inode->i_size) {
+			if (found_type) {
+				btrfs_set_key_type(&key, found_type - 1);
+				continue;
+			}
+			break;
+		}
+		if (btrfs_disk_key_offset(found_key) >= inode->i_size)
+			del_item = 1;
+		else
+			del_item = 0;
+		found_extent = 0;
+
+		/* FIXME, shrink the extent if the ref count is only 1 */
+		if (found_type == BTRFS_EXTENT_DATA_KEY &&
+			   btrfs_file_extent_type(fi) !=
+			   BTRFS_FILE_EXTENT_INLINE) {
+			u64 num_dec;
+			if (!del_item) {
+				u64 orig_num_blocks =
+					btrfs_file_extent_num_blocks(fi);
+				extent_num_blocks = inode->i_size -
+					btrfs_disk_key_offset(found_key) +
+					root->blocksize - 1;
+				extent_num_blocks >>= inode->i_blkbits;
+				btrfs_set_file_extent_num_blocks(fi,
+							 extent_num_blocks);
+				inode->i_blocks -= (orig_num_blocks -
+					extent_num_blocks) << 3;
+				mark_buffer_dirty(path->nodes[0]);
+			} else {
+				extent_start =
+					btrfs_file_extent_disk_blocknr(fi);
+				extent_num_blocks =
+					btrfs_file_extent_disk_num_blocks(fi);
+				/* FIXME blocksize != 4096 */
+				num_dec = btrfs_file_extent_num_blocks(fi) << 3;
+				if (extent_start != 0) {
+					found_extent = 1;
+					inode->i_blocks -= num_dec;
+				}
+			}
+		}
+		if (del_item) {
+			ret = btrfs_del_item(trans, root, path);
+			BUG_ON(ret);
+		} else {
+			break;
+		}
+		btrfs_release_path(root, path);
+		if (found_extent) {
+			ret = btrfs_free_extent(trans, root, extent_start,
+						extent_num_blocks, 0);
+			BUG_ON(ret);
+		}
+	}
+	ret = 0;
+error:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	inode->i_sb->s_dirt = 1;
+	return ret;
+}
+
+/*
+ * taken from block_truncate_page, but does cow as it zeros out
+ * any bytes left in the last page in the file.
+ */
+static int btrfs_truncate_page(struct address_space *mapping, loff_t from)
+{
+	struct inode *inode = mapping->host;
+	unsigned blocksize = 1 << inode->i_blkbits;
+	pgoff_t index = from >> PAGE_CACHE_SHIFT;
+	unsigned offset = from & (PAGE_CACHE_SIZE-1);
+	struct page *page;
+	char *kaddr;
+	int ret = 0;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	u64 alloc_hint = 0;
+	struct btrfs_key ins;
+	struct btrfs_trans_handle *trans;
+
+	if ((offset & (blocksize - 1)) == 0)
+		goto out;
+
+	ret = -ENOMEM;
+	page = grab_cache_page(mapping, index);
+	if (!page)
+		goto out;
+
+	if (!PageUptodate(page)) {
+		ret = mpage_readpage(page, btrfs_get_block);
+		lock_page(page);
+		if (!PageUptodate(page)) {
+			ret = -EIO;
+			goto out;
+		}
+	}
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, inode);
+
+	ret = btrfs_drop_extents(trans, root, inode,
+				 page->index << PAGE_CACHE_SHIFT,
+				 (page->index + 1) << PAGE_CACHE_SHIFT,
+				 &alloc_hint);
+	BUG_ON(ret);
+	ret = btrfs_alloc_extent(trans, root, inode->i_ino, 1,
+				 alloc_hint, (u64)-1, &ins, 1);
+	BUG_ON(ret);
+	ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
+				       page->index << PAGE_CACHE_SHIFT,
+				       ins.objectid, 1, 1);
+	BUG_ON(ret);
+	SetPageChecked(page);
+	kaddr = kmap(page);
+	memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
+	flush_dcache_page(page);
+	btrfs_csum_file_block(trans, root, inode->i_ino,
+			      page->index << PAGE_CACHE_SHIFT,
+			      kaddr, PAGE_CACHE_SIZE);
+	kunmap(page);
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	set_page_dirty(page);
+	unlock_page(page);
+	page_cache_release(page);
+out:
+	return ret;
+}
+
+static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
+{
+	struct inode *inode = dentry->d_inode;
+	int err;
+
+	err = inode_change_ok(inode, attr);
+	if (err)
+		return err;
+
+	if (S_ISREG(inode->i_mode) &&
+	    attr->ia_valid & ATTR_SIZE && attr->ia_size > inode->i_size) {
+		struct btrfs_trans_handle *trans;
+		struct btrfs_root *root = BTRFS_I(inode)->root;
+		u64 mask = root->blocksize - 1;
+		u64 pos = (inode->i_size + mask) & ~mask;
+		u64 hole_size;
+
+		if (attr->ia_size <= pos)
+			goto out;
+
+		btrfs_truncate_page(inode->i_mapping, inode->i_size);
+
+		hole_size = (attr->ia_size - pos + mask) & ~mask;
+		hole_size >>= inode->i_blkbits;
+
+		mutex_lock(&root->fs_info->fs_mutex);
+		trans = btrfs_start_transaction(root, 1);
+		btrfs_set_trans_block_group(trans, inode);
+		err = btrfs_insert_file_extent(trans, root, inode->i_ino,
+					       pos, 0, 0, hole_size);
+		BUG_ON(err);
+		btrfs_end_transaction(trans, root);
+		mutex_unlock(&root->fs_info->fs_mutex);
+	}
+out:
+	err = inode_setattr(inode, attr);
+
+	return err;
+}
+void btrfs_delete_inode(struct inode *inode)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	int ret;
+
+	truncate_inode_pages(&inode->i_data, 0);
+	if (is_bad_inode(inode)) {
+		goto no_delete;
+	}
+	inode->i_size = 0;
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, inode);
+	ret = btrfs_truncate_in_trans(trans, root, inode);
+	BUG_ON(ret);
+	btrfs_free_inode(trans, root, inode);
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+	return;
+no_delete:
+	clear_inode(inode);
+}
+
+/*
+ * this returns the key found in the dir entry in the location pointer.
+ * If no dir entries were found, location->objectid is 0.
+ */
+static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
+			       struct btrfs_key *location)
+{
+	const char *name = dentry->d_name.name;
+	int namelen = dentry->d_name.len;
+	struct btrfs_dir_item *di;
+	struct btrfs_path *path;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	int ret;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
+				    namelen, 0);
+	if (!di || IS_ERR(di)) {
+		location->objectid = 0;
+		ret = 0;
+		goto out;
+	}
+	btrfs_disk_key_to_cpu(location, &di->location);
+out:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	return ret;
+}
+
+/*
+ * when we hit a tree root in a directory, the btrfs part of the inode
+ * needs to be changed to reflect the root directory of the tree root.  This
+ * is kind of like crossing a mount point.
+ */
+static int fixup_tree_root_location(struct btrfs_root *root,
+			     struct btrfs_key *location,
+			     struct btrfs_root **sub_root)
+{
+	struct btrfs_path *path;
+	struct btrfs_root_item *ri;
+
+	if (btrfs_key_type(location) != BTRFS_ROOT_ITEM_KEY)
+		return 0;
+	if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
+		return 0;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	mutex_lock(&root->fs_info->fs_mutex);
+
+	*sub_root = btrfs_read_fs_root(root->fs_info, location);
+	if (IS_ERR(*sub_root))
+		return PTR_ERR(*sub_root);
+
+	ri = &(*sub_root)->root_item;
+	location->objectid = btrfs_root_dirid(ri);
+	location->flags = 0;
+	btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
+	location->offset = 0;
+
+	btrfs_free_path(path);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	return 0;
+}
+
+static int btrfs_init_locked_inode(struct inode *inode, void *p)
+{
+	struct btrfs_iget_args *args = p;
+	inode->i_ino = args->ino;
+	BTRFS_I(inode)->root = args->root;
+	return 0;
+}
+
+static int btrfs_find_actor(struct inode *inode, void *opaque)
+{
+	struct btrfs_iget_args *args = opaque;
+	return (args->ino == inode->i_ino &&
+		args->root == BTRFS_I(inode)->root);
+}
+
+struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
+				struct btrfs_root *root)
+{
+	struct inode *inode;
+	struct btrfs_iget_args args;
+	args.ino = objectid;
+	args.root = root;
+
+	inode = iget5_locked(s, objectid, btrfs_find_actor,
+			     btrfs_init_locked_inode,
+			     (void *)&args);
+	return inode;
+}
+
+static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
+				   struct nameidata *nd)
+{
+	struct inode * inode;
+	struct btrfs_inode *bi = BTRFS_I(dir);
+	struct btrfs_root *root = bi->root;
+	struct btrfs_root *sub_root = root;
+	struct btrfs_key location;
+	int ret;
+
+	if (dentry->d_name.len > BTRFS_NAME_LEN)
+		return ERR_PTR(-ENAMETOOLONG);
+	mutex_lock(&root->fs_info->fs_mutex);
+	ret = btrfs_inode_by_name(dir, dentry, &location);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	if (ret < 0)
+		return ERR_PTR(ret);
+	inode = NULL;
+	if (location.objectid) {
+		ret = fixup_tree_root_location(root, &location, &sub_root);
+		if (ret < 0)
+			return ERR_PTR(ret);
+		if (ret > 0)
+			return ERR_PTR(-ENOENT);
+		inode = btrfs_iget_locked(dir->i_sb, location.objectid,
+					  sub_root);
+		if (!inode)
+			return ERR_PTR(-EACCES);
+		if (inode->i_state & I_NEW) {
+			/* the inode and parent dir are two different roots */
+			if (sub_root != root) {
+				igrab(inode);
+				sub_root->inode = inode;
+			}
+			BTRFS_I(inode)->root = sub_root;
+			memcpy(&BTRFS_I(inode)->location, &location,
+			       sizeof(location));
+			btrfs_read_locked_inode(inode);
+			unlock_new_inode(inode);
+		}
+	}
+	return d_splice_alias(inode, dentry);
+}
+
+/*
+ * readahead one full node of leaves as long as their keys include
+ * the objectid supplied
+ */
+static void reada_leaves(struct btrfs_root *root, struct btrfs_path *path,
+			 u64 objectid)
+{
+	struct btrfs_node *node;
+	int i;
+	u32 nritems;
+	u64 item_objectid;
+	u64 blocknr;
+	int slot;
+	int ret;
+
+	if (!path->nodes[1])
+		return;
+	node = btrfs_buffer_node(path->nodes[1]);
+	slot = path->slots[1];
+	nritems = btrfs_header_nritems(&node->header);
+	for (i = slot + 1; i < nritems; i++) {
+		item_objectid = btrfs_disk_key_objectid(&node->ptrs[i].key);
+		if (item_objectid != objectid)
+			break;
+		blocknr = btrfs_node_blockptr(node, i);
+		ret = readahead_tree_block(root, blocknr);
+		if (ret)
+			break;
+	}
+}
+static unsigned char btrfs_filetype_table[] = {
+	DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
+};
+
+static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_item *item;
+	struct btrfs_dir_item *di;
+	struct btrfs_key key;
+	struct btrfs_path *path;
+	int ret;
+	u32 nritems;
+	struct btrfs_leaf *leaf;
+	int slot;
+	int advance;
+	unsigned char d_type;
+	int over = 0;
+	u32 di_cur;
+	u32 di_total;
+	u32 di_len;
+	int key_type = BTRFS_DIR_INDEX_KEY;
+
+	/* FIXME, use a real flag for deciding about the key type */
+	if (root->fs_info->tree_root == root)
+		key_type = BTRFS_DIR_ITEM_KEY;
+	mutex_lock(&root->fs_info->fs_mutex);
+	key.objectid = inode->i_ino;
+	key.flags = 0;
+	btrfs_set_key_type(&key, key_type);
+	key.offset = filp->f_pos;
+	path = btrfs_alloc_path();
+	btrfs_init_path(path);
+	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+	if (ret < 0)
+		goto err;
+	advance = 0;
+	reada_leaves(root, path, inode->i_ino);
+	while(1) {
+		leaf = btrfs_buffer_leaf(path->nodes[0]);
+		nritems = btrfs_header_nritems(&leaf->header);
+		slot = path->slots[0];
+		if (advance || slot >= nritems) {
+			if (slot >= nritems -1) {
+				reada_leaves(root, path, inode->i_ino);
+				ret = btrfs_next_leaf(root, path);
+				if (ret)
+					break;
+				leaf = btrfs_buffer_leaf(path->nodes[0]);
+				nritems = btrfs_header_nritems(&leaf->header);
+				slot = path->slots[0];
+			} else {
+				slot++;
+				path->slots[0]++;
+			}
+		}
+		advance = 1;
+		item = leaf->items + slot;
+		if (btrfs_disk_key_objectid(&item->key) != key.objectid)
+			break;
+		if (btrfs_disk_key_type(&item->key) != key_type)
+			break;
+		if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
+			continue;
+		filp->f_pos = btrfs_disk_key_offset(&item->key);
+		advance = 1;
+		di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
+		di_cur = 0;
+		di_total = btrfs_item_size(leaf->items + slot);
+		while(di_cur < di_total) {
+			d_type = btrfs_filetype_table[btrfs_dir_type(di)];
+			over = filldir(dirent, (const char *)(di + 1),
+				       btrfs_dir_name_len(di),
+				       btrfs_disk_key_offset(&item->key),
+				       btrfs_disk_key_objectid(&di->location),
+				       d_type);
+			if (over)
+				goto nopos;
+			di_len = btrfs_dir_name_len(di) + sizeof(*di);
+			di_cur += di_len;
+			di = (struct btrfs_dir_item *)((char *)di + di_len);
+		}
+	}
+	filp->f_pos++;
+nopos:
+	ret = 0;
+err:
+	btrfs_release_path(root, path);
+	btrfs_free_path(path);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	return ret;
+}
+
+int btrfs_write_inode(struct inode *inode, int wait)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_trans_handle *trans;
+	int ret = 0;
+
+	if (wait) {
+		mutex_lock(&root->fs_info->fs_mutex);
+		trans = btrfs_start_transaction(root, 1);
+		btrfs_set_trans_block_group(trans, inode);
+		ret = btrfs_commit_transaction(trans, root);
+		mutex_unlock(&root->fs_info->fs_mutex);
+	}
+	return ret;
+}
+
+/*
+ * This is somewhat expense, updating the tree every time the
+ * inode changes.  But, it is most likely to find the inode in cache.
+ * FIXME, needs more benchmarking...there are no reasons other than performance
+ * to keep or drop this code.
+ */
+void btrfs_dirty_inode(struct inode *inode)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_trans_handle *trans;
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, inode);
+	btrfs_update_inode(trans, root, inode);
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+}
+
+static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
+				     struct btrfs_root *root,
+				     u64 objectid,
+				     struct btrfs_block_group_cache *group,
+				     int mode)
+{
+	struct inode *inode;
+	struct btrfs_inode_item inode_item;
+	struct btrfs_key *location;
+	int ret;
+	int owner;
+
+	inode = new_inode(root->fs_info->sb);
+	if (!inode)
+		return ERR_PTR(-ENOMEM);
+
+	BTRFS_I(inode)->root = root;
+	if (mode & S_IFDIR)
+		owner = 0;
+	else
+		owner = 1;
+	group = btrfs_find_block_group(root, group, 0, 0, owner);
+	BTRFS_I(inode)->block_group = group;
+
+	inode->i_uid = current->fsuid;
+	inode->i_gid = current->fsgid;
+	inode->i_mode = mode;
+	inode->i_ino = objectid;
+	inode->i_blocks = 0;
+	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
+	fill_inode_item(&inode_item, inode);
+	location = &BTRFS_I(inode)->location;
+	location->objectid = objectid;
+	location->flags = 0;
+	location->offset = 0;
+	btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
+
+	ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
+	BUG_ON(ret);
+
+	insert_inode_hash(inode);
+	return inode;
+}
+
+static inline u8 btrfs_inode_type(struct inode *inode)
+{
+	return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
+}
+
+static int btrfs_add_link(struct btrfs_trans_handle *trans,
+			    struct dentry *dentry, struct inode *inode)
+{
+	int ret;
+	struct btrfs_key key;
+	struct btrfs_root *root = BTRFS_I(dentry->d_parent->d_inode)->root;
+	key.objectid = inode->i_ino;
+	key.flags = 0;
+	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
+	key.offset = 0;
+
+	ret = btrfs_insert_dir_item(trans, root,
+				    dentry->d_name.name, dentry->d_name.len,
+				    dentry->d_parent->d_inode->i_ino,
+				    &key, btrfs_inode_type(inode));
+	if (ret == 0) {
+		dentry->d_parent->d_inode->i_size += dentry->d_name.len * 2;
+		ret = btrfs_update_inode(trans, root,
+					 dentry->d_parent->d_inode);
+	}
+	return ret;
+}
+
+static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
+			    struct dentry *dentry, struct inode *inode)
+{
+	int err = btrfs_add_link(trans, dentry, inode);
+	if (!err) {
+		d_instantiate(dentry, inode);
+		return 0;
+	}
+	if (err > 0)
+		err = -EEXIST;
+	return err;
+}
+
+static int btrfs_create(struct inode *dir, struct dentry *dentry,
+			int mode, struct nameidata *nd)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	struct inode *inode;
+	int err;
+	int drop_inode = 0;
+	u64 objectid;
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+
+	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
+	if (err) {
+		err = -ENOSPC;
+		goto out_unlock;
+	}
+
+	inode = btrfs_new_inode(trans, root, objectid,
+				BTRFS_I(dir)->block_group, mode);
+	err = PTR_ERR(inode);
+	if (IS_ERR(inode))
+		goto out_unlock;
+
+	btrfs_set_trans_block_group(trans, inode);
+	err = btrfs_add_nondir(trans, dentry, inode);
+	if (err)
+		drop_inode = 1;
+	else {
+		inode->i_mapping->a_ops = &btrfs_aops;
+		inode->i_fop = &btrfs_file_operations;
+		inode->i_op = &btrfs_file_inode_operations;
+	}
+	dir->i_sb->s_dirt = 1;
+	btrfs_update_inode_block_group(trans, inode);
+	btrfs_update_inode_block_group(trans, dir);
+out_unlock:
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	if (drop_inode) {
+		inode_dec_link_count(inode);
+		iput(inode);
+	}
+	btrfs_btree_balance_dirty(root);
+	return err;
+}
+
+static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
+		      struct dentry *dentry)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	struct inode *inode = old_dentry->d_inode;
+	int err;
+	int drop_inode = 0;
+
+	if (inode->i_nlink == 0)
+		return -ENOENT;
+
+	inc_nlink(inode);
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+	atomic_inc(&inode->i_count);
+	err = btrfs_add_nondir(trans, dentry, inode);
+	if (err)
+		drop_inode = 1;
+	dir->i_sb->s_dirt = 1;
+	btrfs_update_inode_block_group(trans, dir);
+	btrfs_update_inode(trans, root, inode);
+
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	if (drop_inode) {
+		inode_dec_link_count(inode);
+		iput(inode);
+	}
+	btrfs_btree_balance_dirty(root);
+	return err;
+}
+
+static int btrfs_make_empty_dir(struct btrfs_trans_handle *trans,
+				struct btrfs_root *root,
+				u64 objectid, u64 dirid)
+{
+	int ret;
+	char buf[2];
+	struct btrfs_key key;
+
+	buf[0] = '.';
+	buf[1] = '.';
+
+	key.objectid = objectid;
+	key.offset = 0;
+	key.flags = 0;
+	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
+
+	ret = btrfs_insert_dir_item(trans, root, buf, 1, objectid,
+				    &key, BTRFS_FT_DIR);
+	if (ret)
+		goto error;
+	key.objectid = dirid;
+	ret = btrfs_insert_dir_item(trans, root, buf, 2, objectid,
+				    &key, BTRFS_FT_DIR);
+	if (ret)
+		goto error;
+error:
+	return ret;
+}
+
+static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
+{
+	struct inode *inode;
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	int err = 0;
+	int drop_on_err = 0;
+	u64 objectid;
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+	if (IS_ERR(trans)) {
+		err = PTR_ERR(trans);
+		goto out_unlock;
+	}
+
+	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
+	if (err) {
+		err = -ENOSPC;
+		goto out_unlock;
+	}
+
+	inode = btrfs_new_inode(trans, root, objectid,
+				BTRFS_I(dir)->block_group, S_IFDIR | mode);
+	if (IS_ERR(inode)) {
+		err = PTR_ERR(inode);
+		goto out_fail;
+	}
+	drop_on_err = 1;
+	inode->i_op = &btrfs_dir_inode_operations;
+	inode->i_fop = &btrfs_dir_file_operations;
+	btrfs_set_trans_block_group(trans, inode);
+
+	err = btrfs_make_empty_dir(trans, root, inode->i_ino, dir->i_ino);
+	if (err)
+		goto out_fail;
+
+	inode->i_size = 6;
+	err = btrfs_update_inode(trans, root, inode);
+	if (err)
+		goto out_fail;
+	err = btrfs_add_link(trans, dentry, inode);
+	if (err)
+		goto out_fail;
+	d_instantiate(dentry, inode);
+	drop_on_err = 0;
+	dir->i_sb->s_dirt = 1;
+	btrfs_update_inode_block_group(trans, inode);
+	btrfs_update_inode_block_group(trans, dir);
+
+out_fail:
+	btrfs_end_transaction(trans, root);
+out_unlock:
+	mutex_unlock(&root->fs_info->fs_mutex);
+	if (drop_on_err)
+		iput(inode);
+	btrfs_btree_balance_dirty(root);
+	return err;
+}
+
+/*
+ * FIBMAP and others want to pass in a fake buffer head.  They need to
+ * use BTRFS_GET_BLOCK_NO_DIRECT to make sure we don't try to memcpy
+ * any packed file data into the fake bh
+ */
+#define BTRFS_GET_BLOCK_NO_CREATE 0
+#define BTRFS_GET_BLOCK_CREATE 1
+#define BTRFS_GET_BLOCK_NO_DIRECT 2
+
+/*
+ * FIXME create==1 doe not work.
+ */
+static int btrfs_get_block_lock(struct inode *inode, sector_t iblock,
+				struct buffer_head *result, int create)
+{
+	int ret;
+	int err = 0;
+	u64 blocknr;
+	u64 extent_start = 0;
+	u64 extent_end = 0;
+	u64 objectid = inode->i_ino;
+	u32 found_type;
+	u64 alloc_hint = 0;
+	struct btrfs_path *path;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_file_extent_item *item;
+	struct btrfs_leaf *leaf;
+	struct btrfs_disk_key *found_key;
+	struct btrfs_trans_handle *trans = NULL;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	btrfs_init_path(path);
+	if (create & BTRFS_GET_BLOCK_CREATE) {
+		WARN_ON(1);
+		/* this almost but not quite works */
+		trans = btrfs_start_transaction(root, 1);
+		if (!trans) {
+			err = -ENOMEM;
+			goto out;
+		}
+		ret = btrfs_drop_extents(trans, root, inode,
+					 iblock << inode->i_blkbits,
+					 (iblock + 1) << inode->i_blkbits,
+					 &alloc_hint);
+		BUG_ON(ret);
+	}
+
+	ret = btrfs_lookup_file_extent(NULL, root, path,
+				       inode->i_ino,
+				       iblock << inode->i_blkbits, 0);
+	if (ret < 0) {
+		err = ret;
+		goto out;
+	}
+
+	if (ret != 0) {
+		if (path->slots[0] == 0) {
+			btrfs_release_path(root, path);
+			goto not_found;
+		}
+		path->slots[0]--;
+	}
+
+	item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
+			      struct btrfs_file_extent_item);
+	leaf = btrfs_buffer_leaf(path->nodes[0]);
+	blocknr = btrfs_file_extent_disk_blocknr(item);
+	blocknr += btrfs_file_extent_offset(item);
+
+	/* are we inside the extent that was found? */
+	found_key = &leaf->items[path->slots[0]].key;
+	found_type = btrfs_disk_key_type(found_key);
+	if (btrfs_disk_key_objectid(found_key) != objectid ||
+	    found_type != BTRFS_EXTENT_DATA_KEY) {
+		extent_end = 0;
+		extent_start = 0;
+		goto not_found;
+	}
+	found_type = btrfs_file_extent_type(item);
+	extent_start = btrfs_disk_key_offset(&leaf->items[path->slots[0]].key);
+	if (found_type == BTRFS_FILE_EXTENT_REG) {
+		extent_start = extent_start >> inode->i_blkbits;
+		extent_end = extent_start + btrfs_file_extent_num_blocks(item);
+		err = 0;
+		if (btrfs_file_extent_disk_blocknr(item) == 0)
+			goto out;
+		if (iblock >= extent_start && iblock < extent_end) {
+			btrfs_map_bh_to_logical(root, result, blocknr +
+						iblock - extent_start);
+			goto out;
+		}
+	} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
+		char *ptr;
+		char *map;
+		u32 size;
+
+		if (create & BTRFS_GET_BLOCK_NO_DIRECT) {
+			err = -EINVAL;
+			goto out;
+		}
+		size = btrfs_file_extent_inline_len(leaf->items +
+						    path->slots[0]);
+		extent_end = (extent_start + size) >> inode->i_blkbits;
+		extent_start >>= inode->i_blkbits;
+		if (iblock < extent_start || iblock > extent_end) {
+			goto not_found;
+		}
+		ptr = btrfs_file_extent_inline_start(item);
+		map = kmap(result->b_page);
+		memcpy(map, ptr, size);
+		memset(map + size, 0, PAGE_CACHE_SIZE - size);
+		flush_dcache_page(result->b_page);
+		kunmap(result->b_page);
+		set_buffer_uptodate(result);
+		SetPageChecked(result->b_page);
+		btrfs_map_bh_to_logical(root, result, 0);
+	}
+not_found:
+	if (create & BTRFS_GET_BLOCK_CREATE) {
+		struct btrfs_key ins;
+		ret = btrfs_alloc_extent(trans, root, inode->i_ino,
+					 1, alloc_hint, (u64)-1,
+					 &ins, 1);
+		BUG_ON(ret);
+		ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
+					       iblock << inode->i_blkbits,
+					       ins.objectid, ins.offset,
+					       ins.offset);
+		BUG_ON(ret);
+		SetPageChecked(result->b_page);
+		btrfs_map_bh_to_logical(root, result, ins.objectid);
+	}
+out:
+	if (trans)
+		err = btrfs_end_transaction(trans, root);
+	btrfs_free_path(path);
+	return err;
+}
+
+int btrfs_get_block(struct inode *inode, sector_t iblock,
+		    struct buffer_head *result, int create)
+{
+	int err;
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	mutex_lock(&root->fs_info->fs_mutex);
+	err = btrfs_get_block_lock(inode, iblock, result, create);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	return err;
+}
+
+static int btrfs_get_block_bmap(struct inode *inode, sector_t iblock,
+			   struct buffer_head *result, int create)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	mutex_lock(&root->fs_info->fs_mutex);
+	btrfs_get_block_lock(inode, iblock, result, BTRFS_GET_BLOCK_NO_DIRECT);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	return 0;
+}
+
+static sector_t btrfs_bmap(struct address_space *as, sector_t block)
+{
+	return generic_block_bmap(as, block, btrfs_get_block_bmap);
+}
+
+static int btrfs_prepare_write(struct file *file, struct page *page,
+			       unsigned from, unsigned to)
+{
+	return block_prepare_write(page, from, to, btrfs_get_block);
+}
+
+static int btrfs_readpage(struct file *file, struct page *page)
+{
+	return mpage_readpage(page, btrfs_get_block);
+}
+
+/*
+ * Aside from a tiny bit of packed file data handling, this is the
+ * same as the generic code.
+ *
+ * While block_write_full_page is writing back the dirty buffers under
+ * the page lock, whoever dirtied the buffers may decide to clean them
+ * again at any time.  We handle that by only looking at the buffer
+ * state inside lock_buffer().
+ *
+ * If block_write_full_page() is called for regular writeback
+ * (wbc->sync_mode == WB_SYNC_NONE) then it will redirty a page which has a
+ * locked buffer.   This only can happen if someone has written the buffer
+ * directly, with submit_bh().  At the address_space level PageWriteback
+ * prevents this contention from occurring.
+ */
+static int __btrfs_write_full_page(struct inode *inode, struct page *page,
+				   struct writeback_control *wbc)
+{
+	int err;
+	sector_t block;
+	sector_t last_block;
+	struct buffer_head *bh, *head;
+	const unsigned blocksize = 1 << inode->i_blkbits;
+	int nr_underway = 0;
+
+	BUG_ON(!PageLocked(page));
+
+	last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
+
+	if (!page_has_buffers(page)) {
+		create_empty_buffers(page, blocksize,
+					(1 << BH_Dirty)|(1 << BH_Uptodate));
+	}
+
+	/*
+	 * Be very careful.  We have no exclusion from __set_page_dirty_buffers
+	 * here, and the (potentially unmapped) buffers may become dirty at
+	 * any time.  If a buffer becomes dirty here after we've inspected it
+	 * then we just miss that fact, and the page stays dirty.
+	 *
+	 * Buffers outside i_size may be dirtied by __set_page_dirty_buffers;
+	 * handle that here by just cleaning them.
+	 */
+
+	block = (sector_t)page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
+	head = page_buffers(page);
+	bh = head;
+
+	/*
+	 * Get all the dirty buffers mapped to disk addresses and
+	 * handle any aliases from the underlying blockdev's mapping.
+	 */
+	do {
+		if (block > last_block) {
+			/*
+			 * mapped buffers outside i_size will occur, because
+			 * this page can be outside i_size when there is a
+			 * truncate in progress.
+			 */
+			/*
+			 * The buffer was zeroed by block_write_full_page()
+			 */
+			clear_buffer_dirty(bh);
+			set_buffer_uptodate(bh);
+		} else if (!buffer_mapped(bh) && buffer_dirty(bh)) {
+			WARN_ON(bh->b_size != blocksize);
+			err = btrfs_get_block(inode, block, bh, 0);
+			if (err) {
+				goto recover;
+			}
+			if (buffer_new(bh)) {
+				/* blockdev mappings never come here */
+				clear_buffer_new(bh);
+			}
+		}
+		bh = bh->b_this_page;
+		block++;
+	} while (bh != head);
+
+	do {
+		if (!buffer_mapped(bh))
+			continue;
+		/*
+		 * If it's a fully non-blocking write attempt and we cannot
+		 * lock the buffer then redirty the page.  Note that this can
+		 * potentially cause a busy-wait loop from pdflush and kswapd
+		 * activity, but those code paths have their own higher-level
+		 * throttling.
+		 */
+		if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
+			lock_buffer(bh);
+		} else if (test_set_buffer_locked(bh)) {
+			redirty_page_for_writepage(wbc, page);
+			continue;
+		}
+		if (test_clear_buffer_dirty(bh) && bh->b_blocknr != 0) {
+			mark_buffer_async_write(bh);
+		} else {
+			unlock_buffer(bh);
+		}
+	} while ((bh = bh->b_this_page) != head);
+
+	/*
+	 * The page and its buffers are protected by PageWriteback(), so we can
+	 * drop the bh refcounts early.
+	 */
+	BUG_ON(PageWriteback(page));
+	set_page_writeback(page);
+
+	do {
+		struct buffer_head *next = bh->b_this_page;
+		if (buffer_async_write(bh)) {
+			submit_bh(WRITE, bh);
+			nr_underway++;
+		}
+		bh = next;
+	} while (bh != head);
+	unlock_page(page);
+
+	err = 0;
+done:
+	if (nr_underway == 0) {
+		/*
+		 * The page was marked dirty, but the buffers were
+		 * clean.  Someone wrote them back by hand with
+		 * ll_rw_block/submit_bh.  A rare case.
+		 */
+		int uptodate = 1;
+		do {
+			if (!buffer_uptodate(bh)) {
+				uptodate = 0;
+				break;
+			}
+			bh = bh->b_this_page;
+		} while (bh != head);
+		if (uptodate)
+			SetPageUptodate(page);
+		end_page_writeback(page);
+	}
+	return err;
+
+recover:
+	/*
+	 * ENOSPC, or some other error.  We may already have added some
+	 * blocks to the file, so we need to write these out to avoid
+	 * exposing stale data.
+	 * The page is currently locked and not marked for writeback
+	 */
+	bh = head;
+	/* Recovery: lock and submit the mapped buffers */
+	do {
+		if (buffer_mapped(bh) && buffer_dirty(bh)) {
+			lock_buffer(bh);
+			mark_buffer_async_write(bh);
+		} else {
+			/*
+			 * The buffer may have been set dirty during
+			 * attachment to a dirty page.
+			 */
+			clear_buffer_dirty(bh);
+		}
+	} while ((bh = bh->b_this_page) != head);
+	SetPageError(page);
+	BUG_ON(PageWriteback(page));
+	set_page_writeback(page);
+	do {
+		struct buffer_head *next = bh->b_this_page;
+		if (buffer_async_write(bh)) {
+			clear_buffer_dirty(bh);
+			submit_bh(WRITE, bh);
+			nr_underway++;
+		}
+		bh = next;
+	} while (bh != head);
+	unlock_page(page);
+	goto done;
+}
+
+static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
+{
+	struct inode * const inode = page->mapping->host;
+	loff_t i_size = i_size_read(inode);
+	const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
+	unsigned offset;
+	void *kaddr;
+
+	/* Is the page fully inside i_size? */
+	if (page->index < end_index)
+		return __btrfs_write_full_page(inode, page, wbc);
+
+	/* Is the page fully outside i_size? (truncate in progress) */
+	offset = i_size & (PAGE_CACHE_SIZE-1);
+	if (page->index >= end_index+1 || !offset) {
+		/*
+		 * The page may have dirty, unmapped buffers.  For example,
+		 * they may have been added in ext3_writepage().  Make them
+		 * freeable here, so the page does not leak.
+		 */
+		block_invalidatepage(page, 0);
+		unlock_page(page);
+		return 0; /* don't care */
+	}
+
+	/*
+	 * The page straddles i_size.  It must be zeroed out on each and every
+	 * writepage invokation because it may be mmapped.  "A file is mapped
+	 * in multiples of the page size.  For a file that is not a multiple of
+	 * the  page size, the remaining memory is zeroed when mapped, and
+	 * writes to that region are not written out to the file."
+	 */
+	kaddr = kmap_atomic(page, KM_USER0);
+	memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
+	flush_dcache_page(page);
+	kunmap_atomic(kaddr, KM_USER0);
+	return __btrfs_write_full_page(inode, page, wbc);
+}
+
+static void btrfs_truncate(struct inode *inode)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	int ret;
+	struct btrfs_trans_handle *trans;
+
+	if (!S_ISREG(inode->i_mode))
+		return;
+	if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
+		return;
+
+	btrfs_truncate_page(inode->i_mapping, inode->i_size);
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, inode);
+
+	/* FIXME, add redo link to tree so we don't leak on crash */
+	ret = btrfs_truncate_in_trans(trans, root, inode);
+	BUG_ON(ret);
+	btrfs_update_inode(trans, root, inode);
+	ret = btrfs_end_transaction(trans, root);
+	BUG_ON(ret);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+}
+
+int btrfs_commit_write(struct file *file, struct page *page,
+		       unsigned from, unsigned to)
+{
+	struct inode *inode = page->mapping->host;
+	struct buffer_head *bh;
+	loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
+
+	SetPageUptodate(page);
+	bh = page_buffers(page);
+	set_buffer_uptodate(bh);
+	if (buffer_mapped(bh) && bh->b_blocknr != 0) {
+		set_page_dirty(page);
+	}
+	if (pos > inode->i_size) {
+		i_size_write(inode, pos);
+		mark_inode_dirty(inode);
+	}
+	return 0;
+}
+
+static int create_subvol(struct btrfs_root *root, char *name, int namelen)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_key key;
+	struct btrfs_root_item root_item;
+	struct btrfs_inode_item *inode_item;
+	struct buffer_head *subvol;
+	struct btrfs_leaf *leaf;
+	struct btrfs_root *new_root;
+	struct inode *inode;
+	struct inode *dir;
+	int ret;
+	u64 objectid;
+	u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	BUG_ON(!trans);
+
+	subvol = btrfs_alloc_free_block(trans, root, 0);
+	if (subvol == NULL)
+		return -ENOSPC;
+	leaf = btrfs_buffer_leaf(subvol);
+	btrfs_set_header_nritems(&leaf->header, 0);
+	btrfs_set_header_level(&leaf->header, 0);
+	btrfs_set_header_blocknr(&leaf->header, bh_blocknr(subvol));
+	btrfs_set_header_generation(&leaf->header, trans->transid);
+	btrfs_set_header_owner(&leaf->header, root->root_key.objectid);
+	memcpy(leaf->header.fsid, root->fs_info->disk_super->fsid,
+	       sizeof(leaf->header.fsid));
+	mark_buffer_dirty(subvol);
+
+	inode_item = &root_item.inode;
+	memset(inode_item, 0, sizeof(*inode_item));
+	btrfs_set_inode_generation(inode_item, 1);
+	btrfs_set_inode_size(inode_item, 3);
+	btrfs_set_inode_nlink(inode_item, 1);
+	btrfs_set_inode_nblocks(inode_item, 1);
+	btrfs_set_inode_mode(inode_item, S_IFDIR | 0755);
+
+	btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol));
+	btrfs_set_root_refs(&root_item, 1);
+	brelse(subvol);
+	subvol = NULL;
+
+	ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
+				       0, &objectid);
+	BUG_ON(ret);
+
+	btrfs_set_root_dirid(&root_item, new_dirid);
+
+	key.objectid = objectid;
+	key.offset = 1;
+	key.flags = 0;
+	btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
+	ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
+				&root_item);
+	BUG_ON(ret);
+
+	/*
+	 * insert the directory item
+	 */
+	key.offset = (u64)-1;
+	dir = root->fs_info->sb->s_root->d_inode;
+	ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
+				    name, namelen, dir->i_ino, &key,
+				    BTRFS_FT_DIR);
+	BUG_ON(ret);
+
+	ret = btrfs_commit_transaction(trans, root);
+	BUG_ON(ret);
+
+	new_root = btrfs_read_fs_root(root->fs_info, &key);
+	BUG_ON(!new_root);
+
+	trans = btrfs_start_transaction(new_root, 1);
+	BUG_ON(!trans);
+
+	inode = btrfs_new_inode(trans, new_root, new_dirid,
+				BTRFS_I(dir)->block_group, S_IFDIR | 0700);
+	inode->i_op = &btrfs_dir_inode_operations;
+	inode->i_fop = &btrfs_dir_file_operations;
+
+	ret = btrfs_make_empty_dir(trans, new_root, new_dirid, new_dirid);
+	BUG_ON(ret);
+
+	inode->i_nlink = 1;
+	inode->i_size = 6;
+	ret = btrfs_update_inode(trans, new_root, inode);
+	BUG_ON(ret);
+
+	ret = btrfs_commit_transaction(trans, new_root);
+	BUG_ON(ret);
+
+	iput(inode);
+
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+	return 0;
+}
+
+static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_key key;
+	struct btrfs_root_item new_root_item;
+	int ret;
+	u64 objectid;
+
+	if (!root->ref_cows)
+		return -EINVAL;
+
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	BUG_ON(!trans);
+
+	ret = btrfs_update_inode(trans, root, root->inode);
+	BUG_ON(ret);
+
+	ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
+				       0, &objectid);
+	BUG_ON(ret);
+
+	memcpy(&new_root_item, &root->root_item,
+	       sizeof(new_root_item));
+
+	key.objectid = objectid;
+	key.offset = 1;
+	key.flags = 0;
+	btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
+	btrfs_set_root_blocknr(&new_root_item, bh_blocknr(root->node));
+
+	ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
+				&new_root_item);
+	BUG_ON(ret);
+
+	/*
+	 * insert the directory item
+	 */
+	key.offset = (u64)-1;
+	ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
+				    name, namelen,
+				    root->fs_info->sb->s_root->d_inode->i_ino,
+				    &key, BTRFS_FT_DIR);
+
+	BUG_ON(ret);
+
+	ret = btrfs_inc_root_ref(trans, root);
+	BUG_ON(ret);
+
+	ret = btrfs_commit_transaction(trans, root);
+	BUG_ON(ret);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	btrfs_btree_balance_dirty(root);
+	return 0;
+}
+
+int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
+		cmd, unsigned long arg)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_ioctl_vol_args vol_args;
+	int ret = 0;
+	struct btrfs_dir_item *di;
+	int namelen;
+	struct btrfs_path *path;
+	u64 root_dirid;
+
+	switch (cmd) {
+	case BTRFS_IOC_SNAP_CREATE:
+		if (copy_from_user(&vol_args,
+				   (struct btrfs_ioctl_vol_args __user *)arg,
+				   sizeof(vol_args)))
+			return -EFAULT;
+		namelen = strlen(vol_args.name);
+		if (namelen > BTRFS_VOL_NAME_MAX)
+			return -EINVAL;
+		path = btrfs_alloc_path();
+		if (!path)
+			return -ENOMEM;
+		root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
+		mutex_lock(&root->fs_info->fs_mutex);
+		di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
+				    path, root_dirid,
+				    vol_args.name, namelen, 0);
+		mutex_unlock(&root->fs_info->fs_mutex);
+		btrfs_free_path(path);
+		if (di && !IS_ERR(di))
+			return -EEXIST;
+
+		if (root == root->fs_info->tree_root)
+			ret = create_subvol(root, vol_args.name, namelen);
+		else
+			ret = create_snapshot(root, vol_args.name, namelen);
+		WARN_ON(ret);
+		break;
+	default:
+		return -ENOTTY;
+	}
+	return ret;
+}
+
+#ifdef CONFIG_COMPAT
+long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
+			       unsigned long arg)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;
+	int ret;
+	lock_kernel();
+	ret = btrfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
+	unlock_kernel();
+	return ret;
+
+}
+#endif
+
+/*
+ * Called inside transaction, so use GFP_NOFS
+ */
+struct inode *btrfs_alloc_inode(struct super_block *sb)
+{
+	struct btrfs_inode *ei;
+
+	ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
+	if (!ei)
+		return NULL;
+	return &ei->vfs_inode;
+}
+
+void btrfs_destroy_inode(struct inode *inode)
+{
+	WARN_ON(!list_empty(&inode->i_dentry));
+	WARN_ON(inode->i_data.nrpages);
+
+	kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
+}
+
+static void init_once(void * foo, struct kmem_cache * cachep,
+		      unsigned long flags)
+{
+	struct btrfs_inode *ei = (struct btrfs_inode *) foo;
+
+	inode_init_once(&ei->vfs_inode);
+}
+
+void btrfs_destroy_cachep(void)
+{
+	if (btrfs_inode_cachep)
+		kmem_cache_destroy(btrfs_inode_cachep);
+	if (btrfs_trans_handle_cachep)
+		kmem_cache_destroy(btrfs_trans_handle_cachep);
+	if (btrfs_transaction_cachep)
+		kmem_cache_destroy(btrfs_transaction_cachep);
+	if (btrfs_bit_radix_cachep)
+		kmem_cache_destroy(btrfs_bit_radix_cachep);
+	if (btrfs_path_cachep)
+		kmem_cache_destroy(btrfs_path_cachep);
+}
+
+int btrfs_init_cachep(void)
+{
+	btrfs_inode_cachep = kmem_cache_create("btrfs_inode_cache",
+					     sizeof(struct btrfs_inode),
+					     0, (SLAB_RECLAIM_ACCOUNT|
+						SLAB_MEM_SPREAD),
+					     init_once, NULL);
+	if (!btrfs_inode_cachep)
+		goto fail;
+	btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle_cache",
+					     sizeof(struct btrfs_trans_handle),
+					     0, (SLAB_RECLAIM_ACCOUNT|
+						SLAB_MEM_SPREAD),
+					     NULL, NULL);
+	if (!btrfs_trans_handle_cachep)
+		goto fail;
+	btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction_cache",
+					     sizeof(struct btrfs_transaction),
+					     0, (SLAB_RECLAIM_ACCOUNT|
+						SLAB_MEM_SPREAD),
+					     NULL, NULL);
+	if (!btrfs_transaction_cachep)
+		goto fail;
+	btrfs_path_cachep = kmem_cache_create("btrfs_path_cache",
+					     sizeof(struct btrfs_transaction),
+					     0, (SLAB_RECLAIM_ACCOUNT|
+						SLAB_MEM_SPREAD),
+					     NULL, NULL);
+	if (!btrfs_path_cachep)
+		goto fail;
+	btrfs_bit_radix_cachep = kmem_cache_create("btrfs_radix",
+					     256,
+					     0, (SLAB_RECLAIM_ACCOUNT|
+						SLAB_MEM_SPREAD |
+						SLAB_DESTROY_BY_RCU),
+					     NULL, NULL);
+	if (!btrfs_bit_radix_cachep)
+		goto fail;
+	return 0;
+fail:
+	btrfs_destroy_cachep();
+	return -ENOMEM;
+}
+
+static int btrfs_getattr(struct vfsmount *mnt,
+			 struct dentry *dentry, struct kstat *stat)
+{
+	struct inode *inode = dentry->d_inode;
+	generic_fillattr(inode, stat);
+	stat->blksize = 256 * 1024;
+	return 0;
+}
+
+static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry,
+			   struct inode * new_dir,struct dentry *new_dentry)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(old_dir)->root;
+	struct inode *new_inode = new_dentry->d_inode;
+	struct inode *old_inode = old_dentry->d_inode;
+	struct timespec ctime = CURRENT_TIME;
+	struct btrfs_path *path;
+	struct btrfs_dir_item *di;
+	int ret;
+
+	if (S_ISDIR(old_inode->i_mode) && new_inode &&
+	    new_inode->i_size > BTRFS_EMPTY_DIR_SIZE) {
+		return -ENOTEMPTY;
+	}
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, new_dir);
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out_fail;
+	}
+
+	old_dentry->d_inode->i_nlink++;
+	old_dir->i_ctime = old_dir->i_mtime = ctime;
+	new_dir->i_ctime = new_dir->i_mtime = ctime;
+	old_inode->i_ctime = ctime;
+	if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
+		struct btrfs_key *location = &BTRFS_I(new_dir)->location;
+		u64 old_parent_oid;
+		di = btrfs_lookup_dir_item(trans, root, path, old_inode->i_ino,
+					   "..", 2, -1);
+		if (IS_ERR(di)) {
+			ret = PTR_ERR(di);
+			goto out_fail;
+		}
+		if (!di) {
+			ret = -ENOENT;
+			goto out_fail;
+		}
+		old_parent_oid = btrfs_disk_key_objectid(&di->location);
+		ret = btrfs_del_item(trans, root, path);
+		if (ret) {
+			ret = -EIO;
+			goto out_fail;
+		}
+		btrfs_release_path(root, path);
+
+		di = btrfs_lookup_dir_index_item(trans, root, path,
+						 old_inode->i_ino,
+						 old_parent_oid,
+						 "..", 2, -1);
+		if (IS_ERR(di)) {
+			ret = PTR_ERR(di);
+			goto out_fail;
+		}
+		if (!di) {
+			ret = -ENOENT;
+			goto out_fail;
+		}
+		ret = btrfs_del_item(trans, root, path);
+		if (ret) {
+			ret = -EIO;
+			goto out_fail;
+		}
+		btrfs_release_path(root, path);
+
+		ret = btrfs_insert_dir_item(trans, root, "..", 2,
+					    old_inode->i_ino, location,
+					    BTRFS_FT_DIR);
+		if (ret)
+			goto out_fail;
+	}
+
+
+	ret = btrfs_unlink_trans(trans, root, old_dir, old_dentry);
+	if (ret)
+		goto out_fail;
+
+	if (new_inode) {
+		new_inode->i_ctime = CURRENT_TIME;
+		ret = btrfs_unlink_trans(trans, root, new_dir, new_dentry);
+		if (ret)
+			goto out_fail;
+		if (S_ISDIR(new_inode->i_mode))
+			clear_nlink(new_inode);
+		else
+			drop_nlink(new_inode);
+		btrfs_update_inode(trans, root, new_inode);
+	}
+	ret = btrfs_add_link(trans, new_dentry, old_inode);
+	if (ret)
+		goto out_fail;
+
+out_fail:
+	btrfs_free_path(path);
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+	return ret;
+}
+
+static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
+			 const char *symname)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root = BTRFS_I(dir)->root;
+	struct btrfs_path *path;
+	struct btrfs_key key;
+	struct inode *inode;
+	int err;
+	int drop_inode = 0;
+	u64 objectid;
+	int name_len;
+	int datasize;
+	char *ptr;
+	struct btrfs_file_extent_item *ei;
+
+	name_len = strlen(symname) + 1;
+	if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
+		return -ENAMETOOLONG;
+	mutex_lock(&root->fs_info->fs_mutex);
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_trans_block_group(trans, dir);
+
+	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
+	if (err) {
+		err = -ENOSPC;
+		goto out_unlock;
+	}
+
+	inode = btrfs_new_inode(trans, root, objectid,
+				BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO);
+	err = PTR_ERR(inode);
+	if (IS_ERR(inode))
+		goto out_unlock;
+
+	btrfs_set_trans_block_group(trans, inode);
+	err = btrfs_add_nondir(trans, dentry, inode);
+	if (err)
+		drop_inode = 1;
+	else {
+		inode->i_mapping->a_ops = &btrfs_aops;
+		inode->i_fop = &btrfs_file_operations;
+		inode->i_op = &btrfs_file_inode_operations;
+	}
+	dir->i_sb->s_dirt = 1;
+	btrfs_update_inode_block_group(trans, inode);
+	btrfs_update_inode_block_group(trans, dir);
+	if (drop_inode)
+		goto out_unlock;
+
+	path = btrfs_alloc_path();
+	BUG_ON(!path);
+	key.objectid = inode->i_ino;
+	key.offset = 0;
+	key.flags = 0;
+	btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
+	datasize = btrfs_file_extent_calc_inline_size(name_len);
+	err = btrfs_insert_empty_item(trans, root, path, &key,
+				      datasize);
+	BUG_ON(err);
+	ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+	       path->slots[0], struct btrfs_file_extent_item);
+	btrfs_set_file_extent_generation(ei, trans->transid);
+	btrfs_set_file_extent_type(ei,
+				   BTRFS_FILE_EXTENT_INLINE);
+	ptr = btrfs_file_extent_inline_start(ei);
+	btrfs_memcpy(root, path->nodes[0]->b_data,
+		     ptr, symname, name_len);
+	mark_buffer_dirty(path->nodes[0]);
+	btrfs_free_path(path);
+	inode->i_op = &btrfs_symlink_inode_operations;
+	inode->i_mapping->a_ops = &btrfs_symlink_aops;
+	inode->i_size = name_len - 1;
+	btrfs_update_inode(trans, root, inode);
+	err = 0;
+
+out_unlock:
+	btrfs_end_transaction(trans, root);
+	mutex_unlock(&root->fs_info->fs_mutex);
+
+	if (drop_inode) {
+		inode_dec_link_count(inode);
+		iput(inode);
+	}
+	btrfs_btree_balance_dirty(root);
+	return err;
+}
+
+static struct inode_operations btrfs_dir_inode_operations = {
+	.lookup		= btrfs_lookup,
+	.create		= btrfs_create,
+	.unlink		= btrfs_unlink,
+	.link		= btrfs_link,
+	.mkdir		= btrfs_mkdir,
+	.rmdir		= btrfs_rmdir,
+	.rename		= btrfs_rename,
+	.symlink	= btrfs_symlink,
+	.setattr	= btrfs_setattr,
+};
+
+static struct inode_operations btrfs_dir_ro_inode_operations = {
+	.lookup		= btrfs_lookup,
+};
+
+static struct file_operations btrfs_dir_file_operations = {
+	.llseek		= generic_file_llseek,
+	.read		= generic_read_dir,
+	.readdir	= btrfs_readdir,
+	.ioctl		= btrfs_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= btrfs_compat_ioctl,
+#endif
+};
+
+static struct address_space_operations btrfs_aops = {
+	.readpage	= btrfs_readpage,
+	.writepage	= btrfs_writepage,
+	.sync_page	= block_sync_page,
+	.prepare_write	= btrfs_prepare_write,
+	.commit_write	= btrfs_commit_write,
+	.bmap		= btrfs_bmap,
+};
+
+static struct address_space_operations btrfs_symlink_aops = {
+	.readpage	= btrfs_readpage,
+	.writepage	= btrfs_writepage,
+};
+
+static struct inode_operations btrfs_file_inode_operations = {
+	.truncate	= btrfs_truncate,
+	.getattr	= btrfs_getattr,
+	.setattr	= btrfs_setattr,
+};
+
+static struct inode_operations btrfs_symlink_inode_operations = {
+	.readlink	= generic_readlink,
+	.follow_link	= page_follow_link_light,
+	.put_link	= page_put_link,
+};
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 9749090..94b3535 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -20,873 +20,9 @@
 #include "ioctl.h"
 #include "print-tree.h"
 
-struct btrfs_iget_args {
-	u64 ino;
-	struct btrfs_root *root;
-};
-
 #define BTRFS_SUPER_MAGIC 0x9123682E
 
-static struct inode_operations btrfs_dir_inode_operations;
-static struct inode_operations btrfs_symlink_inode_operations;
-static struct inode_operations btrfs_dir_ro_inode_operations;
 static struct super_operations btrfs_super_ops;
-static struct file_operations btrfs_dir_file_operations;
-static struct inode_operations btrfs_file_inode_operations;
-static struct address_space_operations btrfs_aops;
-static struct address_space_operations btrfs_symlink_aops;
-static struct file_operations btrfs_file_operations;
-
-static int drop_extents(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root,
-			  struct inode *inode,
-			  u64 start, u64 end, u64 *hint_block);
-static int btrfs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *result, int create);
-
-
-#define S_SHIFT 12
-static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
-	[S_IFREG >> S_SHIFT]	= BTRFS_FT_REG_FILE,
-	[S_IFDIR >> S_SHIFT]	= BTRFS_FT_DIR,
-	[S_IFCHR >> S_SHIFT]	= BTRFS_FT_CHRDEV,
-	[S_IFBLK >> S_SHIFT]	= BTRFS_FT_BLKDEV,
-	[S_IFIFO >> S_SHIFT]	= BTRFS_FT_FIFO,
-	[S_IFSOCK >> S_SHIFT]	= BTRFS_FT_SOCK,
-	[S_IFLNK >> S_SHIFT]	= BTRFS_FT_SYMLINK,
-};
-
-static void btrfs_read_locked_inode(struct inode *inode)
-{
-	struct btrfs_path *path;
-	struct btrfs_inode_item *inode_item;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_key location;
-	u64 alloc_group_block;
-	int ret;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	mutex_lock(&root->fs_info->fs_mutex);
-
-	memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
-	ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
-	if (ret) {
-		btrfs_free_path(path);
-		goto make_bad;
-	}
-	inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
-				  path->slots[0],
-				  struct btrfs_inode_item);
-
-	inode->i_mode = btrfs_inode_mode(inode_item);
-	inode->i_nlink = btrfs_inode_nlink(inode_item);
-	inode->i_uid = btrfs_inode_uid(inode_item);
-	inode->i_gid = btrfs_inode_gid(inode_item);
-	inode->i_size = btrfs_inode_size(inode_item);
-	inode->i_atime.tv_sec = btrfs_timespec_sec(&inode_item->atime);
-	inode->i_atime.tv_nsec = btrfs_timespec_nsec(&inode_item->atime);
-	inode->i_mtime.tv_sec = btrfs_timespec_sec(&inode_item->mtime);
-	inode->i_mtime.tv_nsec = btrfs_timespec_nsec(&inode_item->mtime);
-	inode->i_ctime.tv_sec = btrfs_timespec_sec(&inode_item->ctime);
-	inode->i_ctime.tv_nsec = btrfs_timespec_nsec(&inode_item->ctime);
-	inode->i_blocks = btrfs_inode_nblocks(inode_item);
-	inode->i_generation = btrfs_inode_generation(inode_item);
-	alloc_group_block = btrfs_inode_block_group(inode_item);
-	BTRFS_I(inode)->block_group = btrfs_lookup_block_group(root->fs_info,
-						       alloc_group_block);
-
-	btrfs_free_path(path);
-	inode_item = NULL;
-
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	switch (inode->i_mode & S_IFMT) {
-#if 0
-	default:
-		init_special_inode(inode, inode->i_mode,
-				   btrfs_inode_rdev(inode_item));
-		break;
-#endif
-	case S_IFREG:
-		inode->i_mapping->a_ops = &btrfs_aops;
-		inode->i_fop = &btrfs_file_operations;
-		inode->i_op = &btrfs_file_inode_operations;
-		break;
-	case S_IFDIR:
-		inode->i_fop = &btrfs_dir_file_operations;
-		if (root == root->fs_info->tree_root)
-			inode->i_op = &btrfs_dir_ro_inode_operations;
-		else
-			inode->i_op = &btrfs_dir_inode_operations;
-		break;
-	case S_IFLNK:
-		inode->i_op = &btrfs_symlink_inode_operations;
-		inode->i_mapping->a_ops = &btrfs_symlink_aops;
-		break;
-	}
-	return;
-
-make_bad:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	make_bad_inode(inode);
-}
-
-static void fill_inode_item(struct btrfs_inode_item *item,
-			    struct inode *inode)
-{
-	btrfs_set_inode_uid(item, inode->i_uid);
-	btrfs_set_inode_gid(item, inode->i_gid);
-	btrfs_set_inode_size(item, inode->i_size);
-	btrfs_set_inode_mode(item, inode->i_mode);
-	btrfs_set_inode_nlink(item, inode->i_nlink);
-	btrfs_set_timespec_sec(&item->atime, inode->i_atime.tv_sec);
-	btrfs_set_timespec_nsec(&item->atime, inode->i_atime.tv_nsec);
-	btrfs_set_timespec_sec(&item->mtime, inode->i_mtime.tv_sec);
-	btrfs_set_timespec_nsec(&item->mtime, inode->i_mtime.tv_nsec);
-	btrfs_set_timespec_sec(&item->ctime, inode->i_ctime.tv_sec);
-	btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec);
-	btrfs_set_inode_nblocks(item, inode->i_blocks);
-	btrfs_set_inode_generation(item, inode->i_generation);
-	btrfs_set_inode_block_group(item,
-				    BTRFS_I(inode)->block_group->key.objectid);
-}
-
-static int btrfs_update_inode(struct btrfs_trans_handle *trans,
-			      struct btrfs_root *root,
-			      struct inode *inode)
-{
-	struct btrfs_inode_item *inode_item;
-	struct btrfs_path *path;
-	int ret;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	ret = btrfs_lookup_inode(trans, root, path,
-				 &BTRFS_I(inode)->location, 1);
-	if (ret) {
-		if (ret > 0)
-			ret = -ENOENT;
-		goto failed;
-	}
-
-	inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
-				  path->slots[0],
-				  struct btrfs_inode_item);
-
-	fill_inode_item(inode_item, inode);
-	btrfs_mark_buffer_dirty(path->nodes[0]);
-	ret = 0;
-failed:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	return ret;
-}
-
-
-static int btrfs_unlink_trans(struct btrfs_trans_handle *trans,
-			      struct btrfs_root *root,
-			      struct inode *dir,
-			      struct dentry *dentry)
-{
-	struct btrfs_path *path;
-	const char *name = dentry->d_name.name;
-	int name_len = dentry->d_name.len;
-	int ret = 0;
-	u64 objectid;
-	struct btrfs_dir_item *di;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino,
-				    name, name_len, -1);
-	if (IS_ERR(di)) {
-		ret = PTR_ERR(di);
-		goto err;
-	}
-	if (!di) {
-		ret = -ENOENT;
-		goto err;
-	}
-	objectid = btrfs_disk_key_objectid(&di->location);
-	ret = btrfs_delete_one_dir_name(trans, root, path, di);
-	BUG_ON(ret);
-	btrfs_release_path(root, path);
-
-	di = btrfs_lookup_dir_index_item(trans, root, path, dir->i_ino,
-					 objectid, name, name_len, -1);
-	if (IS_ERR(di)) {
-		ret = PTR_ERR(di);
-		goto err;
-	}
-	if (!di) {
-		ret = -ENOENT;
-		goto err;
-	}
-	ret = btrfs_delete_one_dir_name(trans, root, path, di);
-	BUG_ON(ret);
-
-	dentry->d_inode->i_ctime = dir->i_ctime;
-err:
-	btrfs_free_path(path);
-	if (!ret) {
-		dir->i_size -= name_len * 2;
-		btrfs_update_inode(trans, root, dir);
-		drop_nlink(dentry->d_inode);
-		btrfs_update_inode(trans, root, dentry->d_inode);
-		dir->i_sb->s_dirt = 1;
-	}
-	return ret;
-}
-
-static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
-{
-	struct btrfs_root *root;
-	struct btrfs_trans_handle *trans;
-	int ret;
-
-	root = BTRFS_I(dir)->root;
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-	ret = btrfs_unlink_trans(trans, root, dir, dentry);
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-	return ret;
-}
-
-static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
-{
-	struct inode *inode = dentry->d_inode;
-	int err;
-	int ret;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	struct btrfs_path *path;
-	struct btrfs_key key;
-	struct btrfs_trans_handle *trans;
-	struct btrfs_key found_key;
-	int found_type;
-	struct btrfs_leaf *leaf;
-	char *goodnames = "..";
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-	key.objectid = inode->i_ino;
-	key.offset = (u64)-1;
-	key.flags = (u32)-1;
-	while(1) {
-		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
-		if (ret < 0) {
-			err = ret;
-			goto out;
-		}
-		BUG_ON(ret == 0);
-		if (path->slots[0] == 0) {
-			err = -ENOENT;
-			goto out;
-		}
-		path->slots[0]--;
-		leaf = btrfs_buffer_leaf(path->nodes[0]);
-		btrfs_disk_key_to_cpu(&found_key,
-				      &leaf->items[path->slots[0]].key);
-		found_type = btrfs_key_type(&found_key);
-		if (found_key.objectid != inode->i_ino) {
-			err = -ENOENT;
-			goto out;
-		}
-		if ((found_type != BTRFS_DIR_ITEM_KEY &&
-		     found_type != BTRFS_DIR_INDEX_KEY) ||
-	            (!btrfs_match_dir_item_name(root, path, goodnames, 2) &&
-	            !btrfs_match_dir_item_name(root, path, goodnames, 1))) {
-			err = -ENOTEMPTY;
-			goto out;
-		}
-		ret = btrfs_del_item(trans, root, path);
-		BUG_ON(ret);
-
-		if (found_type == BTRFS_DIR_ITEM_KEY && found_key.offset == 1)
-			break;
-		btrfs_release_path(root, path);
-	}
-	ret = 0;
-	btrfs_release_path(root, path);
-
-	/* now the directory is empty */
-	err = btrfs_unlink_trans(trans, root, dir, dentry);
-	if (!err) {
-		inode->i_size = 0;
-	}
-out:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	ret = btrfs_end_transaction(trans, root);
-	btrfs_btree_balance_dirty(root);
-	if (ret && !err)
-		err = ret;
-	return err;
-}
-
-static int btrfs_free_inode(struct btrfs_trans_handle *trans,
-			    struct btrfs_root *root,
-			    struct inode *inode)
-{
-	struct btrfs_path *path;
-	int ret;
-
-	clear_inode(inode);
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	ret = btrfs_lookup_inode(trans, root, path,
-				 &BTRFS_I(inode)->location, -1);
-	BUG_ON(ret);
-	ret = btrfs_del_item(trans, root, path);
-	BUG_ON(ret);
-	btrfs_free_path(path);
-	return ret;
-}
-
-static void reada_truncate(struct btrfs_root *root, struct btrfs_path *path,
-			   u64 objectid)
-{
-	struct btrfs_node *node;
-	int i;
-	int nritems;
-	u64 item_objectid;
-	u64 blocknr;
-	int slot;
-	int ret;
-
-	if (!path->nodes[1])
-		return;
-	node = btrfs_buffer_node(path->nodes[1]);
-	slot = path->slots[1];
-	if (slot == 0)
-		return;
-	nritems = btrfs_header_nritems(&node->header);
-	for (i = slot - 1; i >= 0; i--) {
-		item_objectid = btrfs_disk_key_objectid(&node->ptrs[i].key);
-		if (item_objectid != objectid)
-			break;
-		blocknr = btrfs_node_blockptr(node, i);
-		ret = readahead_tree_block(root, blocknr);
-		if (ret)
-			break;
-	}
-}
-
-static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
-				   struct inode *inode)
-{
-	int ret;
-	struct btrfs_path *path;
-	struct btrfs_key key;
-	struct btrfs_disk_key *found_key;
-	u32 found_type;
-	struct btrfs_leaf *leaf;
-	struct btrfs_file_extent_item *fi;
-	u64 extent_start = 0;
-	u64 extent_num_blocks = 0;
-	u64 item_end = 0;
-	int found_extent;
-	int del_item;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	/* FIXME, add redo link to tree so we don't leak on crash */
-	key.objectid = inode->i_ino;
-	key.offset = (u64)-1;
-	key.flags = (u32)-1;
-	while(1) {
-		btrfs_init_path(path);
-		fi = NULL;
-		ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
-		if (ret < 0) {
-			goto error;
-		}
-		if (ret > 0) {
-			BUG_ON(path->slots[0] == 0);
-			path->slots[0]--;
-		}
-		reada_truncate(root, path, inode->i_ino);
-		leaf = btrfs_buffer_leaf(path->nodes[0]);
-		found_key = &leaf->items[path->slots[0]].key;
-		found_type = btrfs_disk_key_type(found_key);
-		if (btrfs_disk_key_objectid(found_key) != inode->i_ino)
-			break;
-		if (found_type != BTRFS_CSUM_ITEM_KEY &&
-		    found_type != BTRFS_DIR_ITEM_KEY &&
-		    found_type != BTRFS_DIR_INDEX_KEY &&
-		    found_type != BTRFS_EXTENT_DATA_KEY)
-			break;
-		item_end = btrfs_disk_key_offset(found_key);
-		if (found_type == BTRFS_EXTENT_DATA_KEY) {
-			fi = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
-					    path->slots[0],
-					    struct btrfs_file_extent_item);
-			if (btrfs_file_extent_type(fi) !=
-			    BTRFS_FILE_EXTENT_INLINE) {
-				item_end += btrfs_file_extent_num_blocks(fi) <<
-						inode->i_blkbits;
-			}
-		}
-		if (found_type == BTRFS_CSUM_ITEM_KEY) {
-			ret = btrfs_csum_truncate(trans, root, path,
-						  inode->i_size);
-			BUG_ON(ret);
-		}
-		if (item_end < inode->i_size) {
-			if (found_type) {
-				btrfs_set_key_type(&key, found_type - 1);
-				continue;
-			}
-			break;
-		}
-		if (btrfs_disk_key_offset(found_key) >= inode->i_size)
-			del_item = 1;
-		else
-			del_item = 0;
-		found_extent = 0;
-
-		if (found_type == BTRFS_EXTENT_DATA_KEY &&
-			   btrfs_file_extent_type(fi) !=
-			   BTRFS_FILE_EXTENT_INLINE) {
-			u64 num_dec;
-			if (!del_item) {
-				u64 orig_num_blocks =
-					btrfs_file_extent_num_blocks(fi);
-				extent_num_blocks = inode->i_size -
-					btrfs_disk_key_offset(found_key) +
-					root->blocksize - 1;
-				extent_num_blocks >>= inode->i_blkbits;
-				btrfs_set_file_extent_num_blocks(fi,
-							 extent_num_blocks);
-				inode->i_blocks -= (orig_num_blocks -
-					extent_num_blocks) << 3;
-				mark_buffer_dirty(path->nodes[0]);
-			} else {
-				extent_start =
-					btrfs_file_extent_disk_blocknr(fi);
-				extent_num_blocks =
-					btrfs_file_extent_disk_num_blocks(fi);
-				/* FIXME blocksize != 4096 */
-				num_dec = btrfs_file_extent_num_blocks(fi) << 3;
-				if (extent_start != 0) {
-					found_extent = 1;
-					inode->i_blocks -= num_dec;
-				}
-			}
-		}
-		if (del_item) {
-			ret = btrfs_del_item(trans, root, path);
-			BUG_ON(ret);
-		} else {
-			break;
-		}
-		btrfs_release_path(root, path);
-		if (found_extent) {
-			ret = btrfs_free_extent(trans, root, extent_start,
-						extent_num_blocks, 0);
-			BUG_ON(ret);
-		}
-	}
-	ret = 0;
-error:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	inode->i_sb->s_dirt = 1;
-	return ret;
-}
-
-static int btrfs_truncate_page(struct address_space *mapping, loff_t from)
-{
-	struct inode *inode = mapping->host;
-	unsigned blocksize = 1 << inode->i_blkbits;
-	pgoff_t index = from >> PAGE_CACHE_SHIFT;
-	unsigned offset = from & (PAGE_CACHE_SIZE-1);
-	struct page *page;
-	char *kaddr;
-	int ret = 0;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	u64 alloc_hint;
-	struct btrfs_key ins;
-	struct btrfs_trans_handle *trans;
-
-	if ((offset & (blocksize - 1)) == 0)
-		goto out;
-
-	ret = -ENOMEM;
-	page = grab_cache_page(mapping, index);
-	if (!page)
-		goto out;
-
-	if (!PageUptodate(page)) {
-		ret = mpage_readpage(page, btrfs_get_block);
-		lock_page(page);
-		if (!PageUptodate(page)) {
-			ret = -EIO;
-			goto out;
-		}
-	}
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, inode);
-
-	ret = drop_extents(trans, root, inode, page->index << PAGE_CACHE_SHIFT,
-			   (page->index + 1) << PAGE_CACHE_SHIFT, &alloc_hint);
-	BUG_ON(ret);
-	ret = btrfs_alloc_extent(trans, root, inode->i_ino, 1,
-				 alloc_hint, (u64)-1, &ins, 1);
-	BUG_ON(ret);
-	ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
-				       page->index << PAGE_CACHE_SHIFT,
-				       ins.objectid, 1, 1);
-	BUG_ON(ret);
-	SetPageChecked(page);
-	kaddr = kmap(page);
-	memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
-	flush_dcache_page(page);
-	btrfs_csum_file_block(trans, root, inode->i_ino,
-			      page->index << PAGE_CACHE_SHIFT,
-			      kaddr, PAGE_CACHE_SIZE);
-	kunmap(page);
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	set_page_dirty(page);
-	unlock_page(page);
-	page_cache_release(page);
-out:
-	return ret;
-}
-
-static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
-{
-	struct inode *inode = dentry->d_inode;
-	int err;
-
-	err = inode_change_ok(inode, attr);
-	if (err)
-		return err;
-
-	if (S_ISREG(inode->i_mode) &&
-	    attr->ia_valid & ATTR_SIZE && attr->ia_size > inode->i_size) {
-		struct btrfs_trans_handle *trans;
-		struct btrfs_root *root = BTRFS_I(inode)->root;
-		u64 mask = root->blocksize - 1;
-		u64 pos = (inode->i_size + mask) & ~mask;
-		u64 hole_size;
-
-		if (attr->ia_size <= pos)
-			goto out;
-
-		btrfs_truncate_page(inode->i_mapping, inode->i_size);
-
-		hole_size = (attr->ia_size - pos + mask) & ~mask;
-		hole_size >>= inode->i_blkbits;
-
-		mutex_lock(&root->fs_info->fs_mutex);
-		trans = btrfs_start_transaction(root, 1);
-		btrfs_set_trans_block_group(trans, inode);
-		err = btrfs_insert_file_extent(trans, root, inode->i_ino,
-					       pos, 0, 0, hole_size);
-		BUG_ON(err);
-		btrfs_end_transaction(trans, root);
-		mutex_unlock(&root->fs_info->fs_mutex);
-	}
-out:
-	err = inode_setattr(inode, attr);
-
-	return err;
-}
-static void btrfs_delete_inode(struct inode *inode)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	int ret;
-
-	truncate_inode_pages(&inode->i_data, 0);
-	if (is_bad_inode(inode)) {
-		goto no_delete;
-	}
-	inode->i_size = 0;
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, inode);
-	ret = btrfs_truncate_in_trans(trans, root, inode);
-	BUG_ON(ret);
-	btrfs_free_inode(trans, root, inode);
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-	return;
-no_delete:
-	clear_inode(inode);
-}
-
-static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
-			       struct btrfs_key *location)
-{
-	const char *name = dentry->d_name.name;
-	int namelen = dentry->d_name.len;
-	struct btrfs_dir_item *di;
-	struct btrfs_path *path;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	int ret;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
-				    namelen, 0);
-	if (!di || IS_ERR(di)) {
-		location->objectid = 0;
-		ret = 0;
-		goto out;
-	}
-	btrfs_disk_key_to_cpu(location, &di->location);
-out:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	return ret;
-}
-
-static int fixup_tree_root_location(struct btrfs_root *root,
-			     struct btrfs_key *location,
-			     struct btrfs_root **sub_root)
-{
-	struct btrfs_path *path;
-	struct btrfs_root_item *ri;
-
-	if (btrfs_key_type(location) != BTRFS_ROOT_ITEM_KEY)
-		return 0;
-	if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
-		return 0;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	mutex_lock(&root->fs_info->fs_mutex);
-
-	*sub_root = btrfs_read_fs_root(root->fs_info, location);
-	if (IS_ERR(*sub_root))
-		return PTR_ERR(*sub_root);
-
-	ri = &(*sub_root)->root_item;
-	location->objectid = btrfs_root_dirid(ri);
-	location->flags = 0;
-	btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
-	location->offset = 0;
-
-	btrfs_free_path(path);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	return 0;
-}
-
-static int btrfs_init_locked_inode(struct inode *inode, void *p)
-{
-	struct btrfs_iget_args *args = p;
-	inode->i_ino = args->ino;
-	BTRFS_I(inode)->root = args->root;
-	return 0;
-}
-
-static int btrfs_find_actor(struct inode *inode, void *opaque)
-{
-	struct btrfs_iget_args *args = opaque;
-	return (args->ino == inode->i_ino &&
-		args->root == BTRFS_I(inode)->root);
-}
-
-static struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
-				       struct btrfs_root *root)
-{
-	struct inode *inode;
-	struct btrfs_iget_args args;
-	args.ino = objectid;
-	args.root = root;
-
-	inode = iget5_locked(s, objectid, btrfs_find_actor,
-			     btrfs_init_locked_inode,
-			     (void *)&args);
-	return inode;
-}
-
-static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
-				   struct nameidata *nd)
-{
-	struct inode * inode;
-	struct btrfs_inode *bi = BTRFS_I(dir);
-	struct btrfs_root *root = bi->root;
-	struct btrfs_root *sub_root = root;
-	struct btrfs_key location;
-	int ret;
-
-	if (dentry->d_name.len > BTRFS_NAME_LEN)
-		return ERR_PTR(-ENAMETOOLONG);
-	mutex_lock(&root->fs_info->fs_mutex);
-	ret = btrfs_inode_by_name(dir, dentry, &location);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	if (ret < 0)
-		return ERR_PTR(ret);
-	inode = NULL;
-	if (location.objectid) {
-		ret = fixup_tree_root_location(root, &location, &sub_root);
-		if (ret < 0)
-			return ERR_PTR(ret);
-		if (ret > 0)
-			return ERR_PTR(-ENOENT);
-		inode = btrfs_iget_locked(dir->i_sb, location.objectid,
-					  sub_root);
-		if (!inode)
-			return ERR_PTR(-EACCES);
-		if (inode->i_state & I_NEW) {
-			if (sub_root != root) {
-printk("adding new root for inode %lu root %p (found %p)\n", inode->i_ino, sub_root, BTRFS_I(inode)->root);
-				igrab(inode);
-				sub_root->inode = inode;
-			}
-			BTRFS_I(inode)->root = sub_root;
-			memcpy(&BTRFS_I(inode)->location, &location,
-			       sizeof(location));
-			btrfs_read_locked_inode(inode);
-			unlock_new_inode(inode);
-		}
-	}
-	return d_splice_alias(inode, dentry);
-}
-
-static void reada_leaves(struct btrfs_root *root, struct btrfs_path *path,
-			 u64 objectid)
-{
-	struct btrfs_node *node;
-	int i;
-	u32 nritems;
-	u64 item_objectid;
-	u64 blocknr;
-	int slot;
-	int ret;
-
-	if (!path->nodes[1])
-		return;
-	node = btrfs_buffer_node(path->nodes[1]);
-	slot = path->slots[1];
-	nritems = btrfs_header_nritems(&node->header);
-	for (i = slot + 1; i < nritems; i++) {
-		item_objectid = btrfs_disk_key_objectid(&node->ptrs[i].key);
-		if (item_objectid != objectid)
-			break;
-		blocknr = btrfs_node_blockptr(node, i);
-		ret = readahead_tree_block(root, blocknr);
-		if (ret)
-			break;
-	}
-}
-static unsigned char btrfs_filetype_table[] = {
-	DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
-};
-
-static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
-{
-	struct inode *inode = filp->f_path.dentry->d_inode;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_item *item;
-	struct btrfs_dir_item *di;
-	struct btrfs_key key;
-	struct btrfs_path *path;
-	int ret;
-	u32 nritems;
-	struct btrfs_leaf *leaf;
-	int slot;
-	int advance;
-	unsigned char d_type;
-	int over = 0;
-	u32 di_cur;
-	u32 di_total;
-	u32 di_len;
-	int key_type = BTRFS_DIR_INDEX_KEY;
-
-	/* FIXME, use a real flag for deciding about the key type */
-	if (root->fs_info->tree_root == root)
-		key_type = BTRFS_DIR_ITEM_KEY;
-	mutex_lock(&root->fs_info->fs_mutex);
-	key.objectid = inode->i_ino;
-	key.flags = 0;
-	btrfs_set_key_type(&key, key_type);
-	key.offset = filp->f_pos;
-	path = btrfs_alloc_path();
-	btrfs_init_path(path);
-	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-	if (ret < 0)
-		goto err;
-	advance = 0;
-	reada_leaves(root, path, inode->i_ino);
-	while(1) {
-		leaf = btrfs_buffer_leaf(path->nodes[0]);
-		nritems = btrfs_header_nritems(&leaf->header);
-		slot = path->slots[0];
-		if (advance || slot >= nritems) {
-			if (slot >= nritems -1) {
-				reada_leaves(root, path, inode->i_ino);
-				ret = btrfs_next_leaf(root, path);
-				if (ret)
-					break;
-				leaf = btrfs_buffer_leaf(path->nodes[0]);
-				nritems = btrfs_header_nritems(&leaf->header);
-				slot = path->slots[0];
-			} else {
-				slot++;
-				path->slots[0]++;
-			}
-		}
-		advance = 1;
-		item = leaf->items + slot;
-		if (btrfs_disk_key_objectid(&item->key) != key.objectid)
-			break;
-		if (btrfs_disk_key_type(&item->key) != key_type)
-			break;
-		if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
-			continue;
-		filp->f_pos = btrfs_disk_key_offset(&item->key);
-		advance = 1;
-		di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
-		di_cur = 0;
-		di_total = btrfs_item_size(leaf->items + slot);
-		while(di_cur < di_total) {
-			d_type = btrfs_filetype_table[btrfs_dir_type(di)];
-			over = filldir(dirent, (const char *)(di + 1),
-				       btrfs_dir_name_len(di),
-				       btrfs_disk_key_offset(&item->key),
-				       btrfs_disk_key_objectid(&di->location),
-				       d_type);
-			if (over)
-				goto nopos;
-			di_len = btrfs_dir_name_len(di) + sizeof(*di);
-			di_cur += di_len;
-			di = (struct btrfs_dir_item *)((char *)di + di_len);
-		}
-	}
-	filp->f_pos++;
-nopos:
-	ret = 0;
-err:
-	btrfs_release_path(root, path);
-	btrfs_free_path(path);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	return ret;
-}
 
 static void btrfs_put_super (struct super_block * sb)
 {
@@ -907,6 +43,7 @@
 	struct btrfs_super_block *disk_super;
 	struct btrfs_root *tree_root;
 	struct btrfs_inode *bi;
+	int err;
 
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
 	sb->s_magic = BTRFS_SUPER_MAGIC;
@@ -915,16 +52,12 @@
 
 	tree_root = open_ctree(sb);
 
-	if (!tree_root) {
+	if (!tree_root || IS_ERR(tree_root)) {
 		printk("btrfs: open_ctree failed\n");
 		return -EIO;
 	}
 	sb->s_fs_info = tree_root;
 	disk_super = tree_root->fs_info->disk_super;
-	printk("read in super total blocks %Lu root %Lu\n",
-	       btrfs_super_total_blocks(disk_super),
-	       btrfs_super_root_dir(disk_super));
-
 	inode = btrfs_iget_locked(sb, btrfs_super_root_dir(disk_super),
 				  tree_root);
 	bi = BTRFS_I(inode);
@@ -934,8 +67,10 @@
 	bi->root = tree_root;
 	btrfs_set_key_type(&bi->location, BTRFS_INODE_ITEM_KEY);
 
-	if (!inode)
-		return -ENOMEM;
+	if (!inode) {
+		err = -ENOMEM;
+		goto fail_close;
+	}
 	if (inode->i_state & I_NEW) {
 		btrfs_read_locked_inode(inode);
 		unlock_new_inode(inode);
@@ -944,323 +79,18 @@
 	root_dentry = d_alloc_root(inode);
 	if (!root_dentry) {
 		iput(inode);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto fail_close;
 	}
 	sb->s_root = root_dentry;
 	btrfs_transaction_queue_work(tree_root, HZ * 30);
 	return 0;
-}
 
-static int btrfs_write_inode(struct inode *inode, int wait)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_trans_handle *trans;
-	int ret = 0;
-
-	if (wait) {
-		mutex_lock(&root->fs_info->fs_mutex);
-		trans = btrfs_start_transaction(root, 1);
-		btrfs_set_trans_block_group(trans, inode);
-		ret = btrfs_commit_transaction(trans, root);
-		mutex_unlock(&root->fs_info->fs_mutex);
-	}
-	return ret;
-}
-
-static void btrfs_dirty_inode(struct inode *inode)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_trans_handle *trans;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, inode);
-	btrfs_update_inode(trans, root, inode);
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-}
-
-static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
-				     struct btrfs_root *root,
-				     u64 objectid,
-				     struct btrfs_block_group_cache *group,
-				     int mode)
-{
-	struct inode *inode;
-	struct btrfs_inode_item inode_item;
-	struct btrfs_key *location;
-	int ret;
-	int owner;
-
-	inode = new_inode(root->fs_info->sb);
-	if (!inode)
-		return ERR_PTR(-ENOMEM);
-
-	BTRFS_I(inode)->root = root;
-	if (mode & S_IFDIR)
-		owner = 0;
-	else
-		owner = 1;
-	group = btrfs_find_block_group(root, group, 0, 0, owner);
-	BTRFS_I(inode)->block_group = group;
-
-	inode->i_uid = current->fsuid;
-	inode->i_gid = current->fsgid;
-	inode->i_mode = mode;
-	inode->i_ino = objectid;
-	inode->i_blocks = 0;
-	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
-	fill_inode_item(&inode_item, inode);
-	location = &BTRFS_I(inode)->location;
-	location->objectid = objectid;
-	location->flags = 0;
-	location->offset = 0;
-	btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
-
-	ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
-	BUG_ON(ret);
-
-	insert_inode_hash(inode);
-	return inode;
-}
-
-static inline u8 btrfs_inode_type(struct inode *inode)
-{
-	return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
-}
-
-static int btrfs_add_link(struct btrfs_trans_handle *trans,
-			    struct dentry *dentry, struct inode *inode)
-{
-	int ret;
-	struct btrfs_key key;
-	struct btrfs_root *root = BTRFS_I(dentry->d_parent->d_inode)->root;
-	key.objectid = inode->i_ino;
-	key.flags = 0;
-	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
-	key.offset = 0;
-
-	ret = btrfs_insert_dir_item(trans, root,
-				    dentry->d_name.name, dentry->d_name.len,
-				    dentry->d_parent->d_inode->i_ino,
-				    &key, btrfs_inode_type(inode));
-	if (ret == 0) {
-		dentry->d_parent->d_inode->i_size += dentry->d_name.len * 2;
-		ret = btrfs_update_inode(trans, root,
-					 dentry->d_parent->d_inode);
-	}
-	return ret;
-}
-
-static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
-			    struct dentry *dentry, struct inode *inode)
-{
-	int err = btrfs_add_link(trans, dentry, inode);
-	if (!err) {
-		d_instantiate(dentry, inode);
-		return 0;
-	}
-	if (err > 0)
-		err = -EEXIST;
+fail_close:
+	close_ctree(tree_root);
 	return err;
 }
 
-static int btrfs_create(struct inode *dir, struct dentry *dentry,
-			int mode, struct nameidata *nd)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	struct inode *inode;
-	int err;
-	int drop_inode = 0;
-	u64 objectid;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-
-	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
-	if (err) {
-		err = -ENOSPC;
-		goto out_unlock;
-	}
-
-	inode = btrfs_new_inode(trans, root, objectid,
-				BTRFS_I(dir)->block_group, mode);
-	err = PTR_ERR(inode);
-	if (IS_ERR(inode))
-		goto out_unlock;
-
-	btrfs_set_trans_block_group(trans, inode);
-	err = btrfs_add_nondir(trans, dentry, inode);
-	if (err)
-		drop_inode = 1;
-	else {
-		inode->i_mapping->a_ops = &btrfs_aops;
-		inode->i_fop = &btrfs_file_operations;
-		inode->i_op = &btrfs_file_inode_operations;
-	}
-	dir->i_sb->s_dirt = 1;
-	btrfs_update_inode_block_group(trans, inode);
-	btrfs_update_inode_block_group(trans, dir);
-out_unlock:
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	if (drop_inode) {
-		inode_dec_link_count(inode);
-		iput(inode);
-	}
-	btrfs_btree_balance_dirty(root);
-	return err;
-}
-
-static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
-		      struct dentry *dentry)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	struct inode *inode = old_dentry->d_inode;
-	int err;
-	int drop_inode = 0;
-
-	if (inode->i_nlink == 0)
-		return -ENOENT;
-
-	inc_nlink(inode);
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-	atomic_inc(&inode->i_count);
-	err = btrfs_add_nondir(trans, dentry, inode);
-	if (err)
-		drop_inode = 1;
-	dir->i_sb->s_dirt = 1;
-	btrfs_update_inode_block_group(trans, dir);
-	btrfs_update_inode(trans, root, inode);
-
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	if (drop_inode) {
-		inode_dec_link_count(inode);
-		iput(inode);
-	}
-	btrfs_btree_balance_dirty(root);
-	return err;
-}
-
-static int btrfs_make_empty_dir(struct btrfs_trans_handle *trans,
-				struct btrfs_root *root,
-				u64 objectid, u64 dirid)
-{
-	int ret;
-	char buf[2];
-	struct btrfs_key key;
-
-	buf[0] = '.';
-	buf[1] = '.';
-
-	key.objectid = objectid;
-	key.offset = 0;
-	key.flags = 0;
-	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
-
-	ret = btrfs_insert_dir_item(trans, root, buf, 1, objectid,
-				    &key, BTRFS_FT_DIR);
-	if (ret)
-		goto error;
-	key.objectid = dirid;
-	ret = btrfs_insert_dir_item(trans, root, buf, 2, objectid,
-				    &key, BTRFS_FT_DIR);
-	if (ret)
-		goto error;
-error:
-	return ret;
-}
-
-static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
-{
-	struct inode *inode;
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	int err = 0;
-	int drop_on_err = 0;
-	u64 objectid;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-	if (IS_ERR(trans)) {
-		err = PTR_ERR(trans);
-		goto out_unlock;
-	}
-
-	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
-	if (err) {
-		err = -ENOSPC;
-		goto out_unlock;
-	}
-
-	inode = btrfs_new_inode(trans, root, objectid,
-				BTRFS_I(dir)->block_group, S_IFDIR | mode);
-	if (IS_ERR(inode)) {
-		err = PTR_ERR(inode);
-		goto out_fail;
-	}
-	drop_on_err = 1;
-	inode->i_op = &btrfs_dir_inode_operations;
-	inode->i_fop = &btrfs_dir_file_operations;
-	btrfs_set_trans_block_group(trans, inode);
-
-	err = btrfs_make_empty_dir(trans, root, inode->i_ino, dir->i_ino);
-	if (err)
-		goto out_fail;
-
-	inode->i_size = 6;
-	err = btrfs_update_inode(trans, root, inode);
-	if (err)
-		goto out_fail;
-	err = btrfs_add_link(trans, dentry, inode);
-	if (err)
-		goto out_fail;
-	d_instantiate(dentry, inode);
-	drop_on_err = 0;
-	dir->i_sb->s_dirt = 1;
-	btrfs_update_inode_block_group(trans, inode);
-	btrfs_update_inode_block_group(trans, dir);
-
-out_fail:
-	btrfs_end_transaction(trans, root);
-out_unlock:
-	mutex_unlock(&root->fs_info->fs_mutex);
-	if (drop_on_err)
-		iput(inode);
-	btrfs_btree_balance_dirty(root);
-	return err;
-}
-
-static int btrfs_sync_file(struct file *file,
-			   struct dentry *dentry, int datasync)
-{
-	struct inode *inode = dentry->d_inode;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	int ret;
-	struct btrfs_trans_handle *trans;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	if (!trans) {
-		ret = -ENOMEM;
-		goto out;
-	}
-	ret = btrfs_commit_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-out:
-	return ret > 0 ? EIO : ret;
-}
-
 static int btrfs_sync_fs(struct super_block *sb, int wait)
 {
 	struct btrfs_trans_handle *trans;
@@ -1278,1430 +108,15 @@
 	ret = btrfs_commit_transaction(trans, root);
 	sb->s_dirt = 0;
 	BUG_ON(ret);
-printk("btrfs sync_fs\n");
 	mutex_unlock(&root->fs_info->fs_mutex);
 	return 0;
 }
 
-#define BTRFS_GET_BLOCK_NO_CREATE 0
-#define BTRFS_GET_BLOCK_CREATE 1
-#define BTRFS_GET_BLOCK_NO_DIRECT 2
-
-static int btrfs_get_block_lock(struct inode *inode, sector_t iblock,
-			   struct buffer_head *result, int create)
-{
-	int ret;
-	int err = 0;
-	u64 blocknr;
-	u64 extent_start = 0;
-	u64 extent_end = 0;
-	u64 objectid = inode->i_ino;
-	u32 found_type;
-	u64 alloc_hint = 0;
-	struct btrfs_path *path;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_file_extent_item *item;
-	struct btrfs_leaf *leaf;
-	struct btrfs_disk_key *found_key;
-	struct btrfs_trans_handle *trans = NULL;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	btrfs_init_path(path);
-	if (create & BTRFS_GET_BLOCK_CREATE) {
-		WARN_ON(1);
-		/* this almost but not quite works */
-		trans = btrfs_start_transaction(root, 1);
-		if (!trans) {
-			err = -ENOMEM;
-			goto out;
-		}
-		ret = drop_extents(trans, root, inode,
-				   iblock << inode->i_blkbits,
-				   (iblock + 1) << inode->i_blkbits,
-				   &alloc_hint);
-		BUG_ON(ret);
-	}
-
-	ret = btrfs_lookup_file_extent(NULL, root, path,
-				       inode->i_ino,
-				       iblock << inode->i_blkbits, 0);
-	if (ret < 0) {
-		err = ret;
-		goto out;
-	}
-
-	if (ret != 0) {
-		if (path->slots[0] == 0) {
-			btrfs_release_path(root, path);
-			goto not_found;
-		}
-		path->slots[0]--;
-	}
-
-	item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
-			      struct btrfs_file_extent_item);
-	leaf = btrfs_buffer_leaf(path->nodes[0]);
-	blocknr = btrfs_file_extent_disk_blocknr(item);
-	blocknr += btrfs_file_extent_offset(item);
-
-	/* are we inside the extent that was found? */
-	found_key = &leaf->items[path->slots[0]].key;
-	found_type = btrfs_disk_key_type(found_key);
-	if (btrfs_disk_key_objectid(found_key) != objectid ||
-	    found_type != BTRFS_EXTENT_DATA_KEY) {
-		extent_end = 0;
-		extent_start = 0;
-		goto not_found;
-	}
-	found_type = btrfs_file_extent_type(item);
-	extent_start = btrfs_disk_key_offset(&leaf->items[path->slots[0]].key);
-	if (found_type == BTRFS_FILE_EXTENT_REG) {
-		extent_start = extent_start >> inode->i_blkbits;
-		extent_end = extent_start + btrfs_file_extent_num_blocks(item);
-		err = 0;
-		if (btrfs_file_extent_disk_blocknr(item) == 0)
-			goto out;
-		if (iblock >= extent_start && iblock < extent_end) {
-			btrfs_map_bh_to_logical(root, result, blocknr +
-						iblock - extent_start);
-			goto out;
-		}
-	} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
-		char *ptr;
-		char *map;
-		u32 size;
-
-		if (create & BTRFS_GET_BLOCK_NO_DIRECT) {
-			err = -EINVAL;
-			goto out;
-		}
-		size = btrfs_file_extent_inline_len(leaf->items +
-						    path->slots[0]);
-		extent_end = (extent_start + size) >> inode->i_blkbits;
-		extent_start >>= inode->i_blkbits;
-		if (iblock < extent_start || iblock > extent_end) {
-			goto not_found;
-		}
-		ptr = btrfs_file_extent_inline_start(item);
-		map = kmap(result->b_page);
-		memcpy(map, ptr, size);
-		memset(map + size, 0, PAGE_CACHE_SIZE - size);
-		flush_dcache_page(result->b_page);
-		kunmap(result->b_page);
-		set_buffer_uptodate(result);
-		SetPageChecked(result->b_page);
-		btrfs_map_bh_to_logical(root, result, 0);
-	}
-not_found:
-	if (create & BTRFS_GET_BLOCK_CREATE) {
-		struct btrfs_key ins;
-		ret = btrfs_alloc_extent(trans, root, inode->i_ino,
-					 1, alloc_hint, (u64)-1,
-					 &ins, 1);
-		BUG_ON(ret);
-		ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
-					       iblock << inode->i_blkbits,
-					       ins.objectid, ins.offset,
-					       ins.offset);
-		BUG_ON(ret);
-		SetPageChecked(result->b_page);
-		btrfs_map_bh_to_logical(root, result, ins.objectid);
-	}
-out:
-	if (trans)
-		err = btrfs_end_transaction(trans, root);
-	btrfs_free_path(path);
-	return err;
-}
-
-static int btrfs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *result, int create)
-{
-	int err;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	mutex_lock(&root->fs_info->fs_mutex);
-	err = btrfs_get_block_lock(inode, iblock, result, create);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	return err;
-}
-
-static int btrfs_get_block_bmap(struct inode *inode, sector_t iblock,
-			   struct buffer_head *result, int create)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	mutex_lock(&root->fs_info->fs_mutex);
-	btrfs_get_block_lock(inode, iblock, result, BTRFS_GET_BLOCK_NO_DIRECT);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	return 0;
-}
-
-static sector_t btrfs_bmap(struct address_space *as, sector_t block)
-{
-	return generic_block_bmap(as, block, btrfs_get_block_bmap);
-}
-
-static int btrfs_prepare_write(struct file *file, struct page *page,
-			       unsigned from, unsigned to)
-{
-	return block_prepare_write(page, from, to, btrfs_get_block);
-}
-
 static void btrfs_write_super(struct super_block *sb)
 {
 	sb->s_dirt = 0;
 }
 
-static int btrfs_readpage(struct file *file, struct page *page)
-{
-	return mpage_readpage(page, btrfs_get_block);
-}
-
-/*
- * While block_write_full_page is writing back the dirty buffers under
- * the page lock, whoever dirtied the buffers may decide to clean them
- * again at any time.  We handle that by only looking at the buffer
- * state inside lock_buffer().
- *
- * If block_write_full_page() is called for regular writeback
- * (wbc->sync_mode == WB_SYNC_NONE) then it will redirty a page which has a
- * locked buffer.   This only can happen if someone has written the buffer
- * directly, with submit_bh().  At the address_space level PageWriteback
- * prevents this contention from occurring.
- */
-static int __btrfs_write_full_page(struct inode *inode, struct page *page,
-				   struct writeback_control *wbc)
-{
-	int err;
-	sector_t block;
-	sector_t last_block;
-	struct buffer_head *bh, *head;
-	const unsigned blocksize = 1 << inode->i_blkbits;
-	int nr_underway = 0;
-
-	BUG_ON(!PageLocked(page));
-
-	last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
-
-	if (!page_has_buffers(page)) {
-		create_empty_buffers(page, blocksize,
-					(1 << BH_Dirty)|(1 << BH_Uptodate));
-	}
-
-	/*
-	 * Be very careful.  We have no exclusion from __set_page_dirty_buffers
-	 * here, and the (potentially unmapped) buffers may become dirty at
-	 * any time.  If a buffer becomes dirty here after we've inspected it
-	 * then we just miss that fact, and the page stays dirty.
-	 *
-	 * Buffers outside i_size may be dirtied by __set_page_dirty_buffers;
-	 * handle that here by just cleaning them.
-	 */
-
-	block = (sector_t)page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
-	head = page_buffers(page);
-	bh = head;
-
-	/*
-	 * Get all the dirty buffers mapped to disk addresses and
-	 * handle any aliases from the underlying blockdev's mapping.
-	 */
-	do {
-		if (block > last_block) {
-			/*
-			 * mapped buffers outside i_size will occur, because
-			 * this page can be outside i_size when there is a
-			 * truncate in progress.
-			 */
-			/*
-			 * The buffer was zeroed by block_write_full_page()
-			 */
-			clear_buffer_dirty(bh);
-			set_buffer_uptodate(bh);
-		} else if (!buffer_mapped(bh) && buffer_dirty(bh)) {
-			WARN_ON(bh->b_size != blocksize);
-			err = btrfs_get_block(inode, block, bh, 0);
-			if (err) {
-printk("writepage going to recovery err %d\n", err);
-				goto recover;
-			}
-			if (buffer_new(bh)) {
-				/* blockdev mappings never come here */
-				clear_buffer_new(bh);
-			}
-		}
-		bh = bh->b_this_page;
-		block++;
-	} while (bh != head);
-
-	do {
-		if (!buffer_mapped(bh))
-			continue;
-		/*
-		 * If it's a fully non-blocking write attempt and we cannot
-		 * lock the buffer then redirty the page.  Note that this can
-		 * potentially cause a busy-wait loop from pdflush and kswapd
-		 * activity, but those code paths have their own higher-level
-		 * throttling.
-		 */
-		if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
-			lock_buffer(bh);
-		} else if (test_set_buffer_locked(bh)) {
-			redirty_page_for_writepage(wbc, page);
-			continue;
-		}
-		if (test_clear_buffer_dirty(bh) && bh->b_blocknr != 0) {
-			mark_buffer_async_write(bh);
-		} else {
-			unlock_buffer(bh);
-		}
-	} while ((bh = bh->b_this_page) != head);
-
-	/*
-	 * The page and its buffers are protected by PageWriteback(), so we can
-	 * drop the bh refcounts early.
-	 */
-	BUG_ON(PageWriteback(page));
-	set_page_writeback(page);
-
-	do {
-		struct buffer_head *next = bh->b_this_page;
-		if (buffer_async_write(bh)) {
-			submit_bh(WRITE, bh);
-			nr_underway++;
-		}
-		bh = next;
-	} while (bh != head);
-	unlock_page(page);
-
-	err = 0;
-done:
-	if (nr_underway == 0) {
-		/*
-		 * The page was marked dirty, but the buffers were
-		 * clean.  Someone wrote them back by hand with
-		 * ll_rw_block/submit_bh.  A rare case.
-		 */
-		int uptodate = 1;
-		do {
-			if (!buffer_uptodate(bh)) {
-				uptodate = 0;
-				break;
-			}
-			bh = bh->b_this_page;
-		} while (bh != head);
-		if (uptodate)
-			SetPageUptodate(page);
-		end_page_writeback(page);
-	}
-	return err;
-
-recover:
-	/*
-	 * ENOSPC, or some other error.  We may already have added some
-	 * blocks to the file, so we need to write these out to avoid
-	 * exposing stale data.
-	 * The page is currently locked and not marked for writeback
-	 */
-	bh = head;
-	/* Recovery: lock and submit the mapped buffers */
-	do {
-		if (buffer_mapped(bh) && buffer_dirty(bh)) {
-			lock_buffer(bh);
-			mark_buffer_async_write(bh);
-		} else {
-			/*
-			 * The buffer may have been set dirty during
-			 * attachment to a dirty page.
-			 */
-			clear_buffer_dirty(bh);
-		}
-	} while ((bh = bh->b_this_page) != head);
-	SetPageError(page);
-	BUG_ON(PageWriteback(page));
-	set_page_writeback(page);
-	do {
-		struct buffer_head *next = bh->b_this_page;
-		if (buffer_async_write(bh)) {
-			clear_buffer_dirty(bh);
-			submit_bh(WRITE, bh);
-			nr_underway++;
-		}
-		bh = next;
-	} while (bh != head);
-	unlock_page(page);
-	goto done;
-}
-
-/*
- * The generic ->writepage function for buffer-backed address_spaces
- */
-static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
-{
-	struct inode * const inode = page->mapping->host;
-	loff_t i_size = i_size_read(inode);
-	const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
-	unsigned offset;
-	void *kaddr;
-
-	/* Is the page fully inside i_size? */
-	if (page->index < end_index)
-		return __btrfs_write_full_page(inode, page, wbc);
-
-	/* Is the page fully outside i_size? (truncate in progress) */
-	offset = i_size & (PAGE_CACHE_SIZE-1);
-	if (page->index >= end_index+1 || !offset) {
-		/*
-		 * The page may have dirty, unmapped buffers.  For example,
-		 * they may have been added in ext3_writepage().  Make them
-		 * freeable here, so the page does not leak.
-		 */
-		block_invalidatepage(page, 0);
-		unlock_page(page);
-		return 0; /* don't care */
-	}
-
-	/*
-	 * The page straddles i_size.  It must be zeroed out on each and every
-	 * writepage invokation because it may be mmapped.  "A file is mapped
-	 * in multiples of the page size.  For a file that is not a multiple of
-	 * the  page size, the remaining memory is zeroed when mapped, and
-	 * writes to that region are not written out to the file."
-	 */
-	kaddr = kmap_atomic(page, KM_USER0);
-	memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
-	flush_dcache_page(page);
-	kunmap_atomic(kaddr, KM_USER0);
-	return __btrfs_write_full_page(inode, page, wbc);
-}
-
-static void btrfs_truncate(struct inode *inode)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	int ret;
-	struct btrfs_trans_handle *trans;
-
-	if (!S_ISREG(inode->i_mode))
-		return;
-	if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
-		return;
-
-	btrfs_truncate_page(inode->i_mapping, inode->i_size);
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, inode);
-
-	/* FIXME, add redo link to tree so we don't leak on crash */
-	ret = btrfs_truncate_in_trans(trans, root, inode);
-	BUG_ON(ret);
-	btrfs_update_inode(trans, root, inode);
-	ret = btrfs_end_transaction(trans, root);
-	BUG_ON(ret);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-}
-
-static int btrfs_commit_write(struct file *file, struct page *page,
-			      unsigned from, unsigned to)
-{
-	struct inode *inode = page->mapping->host;
-	struct buffer_head *bh;
-	loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
-
-	SetPageUptodate(page);
-	bh = page_buffers(page);
-	set_buffer_uptodate(bh);
-	if (buffer_mapped(bh) && bh->b_blocknr != 0) {
-		set_page_dirty(page);
-	}
-	if (pos > inode->i_size) {
-		i_size_write(inode, pos);
-		mark_inode_dirty(inode);
-	}
-	return 0;
-}
-
-static int btrfs_copy_from_user(loff_t pos, int num_pages, int write_bytes,
-				struct page **prepared_pages,
-				const char __user * buf)
-{
-	long page_fault = 0;
-	int i;
-	int offset = pos & (PAGE_CACHE_SIZE - 1);
-
-	for (i = 0; i < num_pages && write_bytes > 0; i++, offset = 0) {
-		size_t count = min_t(size_t,
-				     PAGE_CACHE_SIZE - offset, write_bytes);
-		struct page *page = prepared_pages[i];
-		fault_in_pages_readable(buf, count);
-
-		/* Copy data from userspace to the current page */
-		kmap(page);
-		page_fault = __copy_from_user(page_address(page) + offset,
-					      buf, count);
-		/* Flush processor's dcache for this page */
-		flush_dcache_page(page);
-		kunmap(page);
-		buf += count;
-		write_bytes -= count;
-
-		if (page_fault)
-			break;
-	}
-	return page_fault ? -EFAULT : 0;
-}
-
-static void btrfs_drop_pages(struct page **pages, size_t num_pages)
-{
-	size_t i;
-	for (i = 0; i < num_pages; i++) {
-		if (!pages[i])
-			break;
-		unlock_page(pages[i]);
-		mark_page_accessed(pages[i]);
-		page_cache_release(pages[i]);
-	}
-}
-static int dirty_and_release_pages(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
-				   struct file *file,
-				   struct page **pages,
-				   size_t num_pages,
-				   loff_t pos,
-				   size_t write_bytes)
-{
-	int i;
-	int offset;
-	int err = 0;
-	int ret;
-	int this_write;
-	struct inode *inode = file->f_path.dentry->d_inode;
-	struct buffer_head *bh;
-	struct btrfs_file_extent_item *ei;
-
-	for (i = 0; i < num_pages; i++) {
-		offset = pos & (PAGE_CACHE_SIZE -1);
-		this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
-		/* FIXME, one block at a time */
-
-		mutex_lock(&root->fs_info->fs_mutex);
-		trans = btrfs_start_transaction(root, 1);
-		btrfs_set_trans_block_group(trans, inode);
-
-		bh = page_buffers(pages[i]);
-		if (buffer_mapped(bh) && bh->b_blocknr == 0) {
-			struct btrfs_key key;
-			struct btrfs_path *path;
-			char *ptr;
-			u32 datasize;
-
-			path = btrfs_alloc_path();
-			BUG_ON(!path);
-			key.objectid = inode->i_ino;
-			key.offset = pages[i]->index << PAGE_CACHE_SHIFT;
-			key.flags = 0;
-			btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
-			BUG_ON(write_bytes >= PAGE_CACHE_SIZE);
-			datasize = offset +
-				btrfs_file_extent_calc_inline_size(write_bytes);
-			ret = btrfs_insert_empty_item(trans, root, path, &key,
-						      datasize);
-			BUG_ON(ret);
-			ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
-			       path->slots[0], struct btrfs_file_extent_item);
-			btrfs_set_file_extent_generation(ei, trans->transid);
-			btrfs_set_file_extent_type(ei,
-						   BTRFS_FILE_EXTENT_INLINE);
-			ptr = btrfs_file_extent_inline_start(ei);
-			btrfs_memcpy(root, path->nodes[0]->b_data,
-				     ptr, bh->b_data, offset + write_bytes);
-			mark_buffer_dirty(path->nodes[0]);
-			btrfs_free_path(path);
-		} else if (buffer_mapped(bh)) {
-			btrfs_csum_file_block(trans, root, inode->i_ino,
-				      pages[i]->index << PAGE_CACHE_SHIFT,
-				      kmap(pages[i]), PAGE_CACHE_SIZE);
-			kunmap(pages[i]);
-		}
-		SetPageChecked(pages[i]);
-		// btrfs_update_inode_block_group(trans, inode);
-		ret = btrfs_end_transaction(trans, root);
-		BUG_ON(ret);
-		mutex_unlock(&root->fs_info->fs_mutex);
-
-		ret = btrfs_commit_write(file, pages[i], offset,
-					 offset + this_write);
-		pos += this_write;
-		if (ret) {
-			err = ret;
-			goto failed;
-		}
-		WARN_ON(this_write > write_bytes);
-		write_bytes -= this_write;
-	}
-failed:
-	return err;
-}
-
-static int drop_extents(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root,
-			  struct inode *inode,
-			  u64 start, u64 end, u64 *hint_block)
-{
-	int ret;
-	struct btrfs_key key;
-	struct btrfs_leaf *leaf;
-	int slot;
-	struct btrfs_file_extent_item *extent;
-	u64 extent_end = 0;
-	int keep;
-	struct btrfs_file_extent_item old;
-	struct btrfs_path *path;
-	u64 search_start = start;
-	int bookend;
-	int found_type;
-	int found_extent;
-	int found_inline;
-
-	path = btrfs_alloc_path();
-	if (!path)
-		return -ENOMEM;
-	while(1) {
-		btrfs_release_path(root, path);
-		ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
-					       search_start, -1);
-		if (ret < 0)
-			goto out;
-		if (ret > 0) {
-			if (path->slots[0] == 0) {
-				ret = 0;
-				goto out;
-			}
-			path->slots[0]--;
-		}
-		keep = 0;
-		bookend = 0;
-		found_extent = 0;
-		found_inline = 0;
-		extent = NULL;
-		leaf = btrfs_buffer_leaf(path->nodes[0]);
-		slot = path->slots[0];
-		btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
-		if (key.offset >= end || key.objectid != inode->i_ino) {
-			ret = 0;
-			goto out;
-		}
-		if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY) {
-			ret = 0;
-			goto out;
-		}
-		extent = btrfs_item_ptr(leaf, slot,
-					struct btrfs_file_extent_item);
-		found_type = btrfs_file_extent_type(extent);
-		if (found_type == BTRFS_FILE_EXTENT_REG) {
-			extent_end = key.offset +
-				(btrfs_file_extent_num_blocks(extent) <<
-				 inode->i_blkbits);
-			found_extent = 1;
-		} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
-			found_inline = 1;
-			extent_end = key.offset +
-			     btrfs_file_extent_inline_len(leaf->items + slot);
-		}
-
-		if (!found_extent && !found_inline) {
-			ret = 0;
-			goto out;
-		}
-
-		if (search_start >= extent_end) {
-			ret = 0;
-			goto out;
-		}
-
-		if (found_inline) {
-			u64 mask = root->blocksize - 1;
-			search_start = (extent_end + mask) & ~mask;
-		} else
-			search_start = extent_end;
-
-		if (end < extent_end && end >= key.offset) {
-			if (found_extent) {
-				u64 disk_blocknr =
-					btrfs_file_extent_disk_blocknr(extent);
-				u64 disk_num_blocks =
-				      btrfs_file_extent_disk_num_blocks(extent);
-				memcpy(&old, extent, sizeof(old));
-				if (disk_blocknr != 0) {
-					ret = btrfs_inc_extent_ref(trans, root,
-					         disk_blocknr, disk_num_blocks);
-					BUG_ON(ret);
-				}
-			}
-			WARN_ON(found_inline);
-			bookend = 1;
-		}
-
-		if (start > key.offset) {
-			u64 new_num;
-			u64 old_num;
-			/* truncate existing extent */
-			keep = 1;
-			WARN_ON(start & (root->blocksize - 1));
-			if (found_extent) {
-				new_num = (start - key.offset) >>
-					inode->i_blkbits;
-				old_num = btrfs_file_extent_num_blocks(extent);
-				*hint_block =
-					btrfs_file_extent_disk_blocknr(extent);
-				if (btrfs_file_extent_disk_blocknr(extent)) {
-					inode->i_blocks -=
-						(old_num - new_num) << 3;
-				}
-				btrfs_set_file_extent_num_blocks(extent,
-								 new_num);
-				mark_buffer_dirty(path->nodes[0]);
-			} else {
-				WARN_ON(1);
-			}
-		}
-		if (!keep) {
-			u64 disk_blocknr = 0;
-			u64 disk_num_blocks = 0;
-			u64 extent_num_blocks = 0;
-			if (found_extent) {
-				disk_blocknr =
-				      btrfs_file_extent_disk_blocknr(extent);
-				disk_num_blocks =
-				      btrfs_file_extent_disk_num_blocks(extent);
-				extent_num_blocks =
-				      btrfs_file_extent_num_blocks(extent);
-				*hint_block =
-					btrfs_file_extent_disk_blocknr(extent);
-			}
-			ret = btrfs_del_item(trans, root, path);
-			BUG_ON(ret);
-			btrfs_release_path(root, path);
-			extent = NULL;
-			if (found_extent && disk_blocknr != 0) {
-				inode->i_blocks -= extent_num_blocks << 3;
-				ret = btrfs_free_extent(trans, root,
-							disk_blocknr,
-							disk_num_blocks, 0);
-			}
-
-			BUG_ON(ret);
-			if (!bookend && search_start >= end) {
-				ret = 0;
-				goto out;
-			}
-			if (!bookend)
-				continue;
-		}
-		if (bookend && found_extent) {
-			/* create bookend */
-			struct btrfs_key ins;
-			ins.objectid = inode->i_ino;
-			ins.offset = end;
-			ins.flags = 0;
-			btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY);
-
-			btrfs_release_path(root, path);
-			ret = btrfs_insert_empty_item(trans, root, path, &ins,
-						      sizeof(*extent));
-			BUG_ON(ret);
-			extent = btrfs_item_ptr(
-				    btrfs_buffer_leaf(path->nodes[0]),
-				    path->slots[0],
-				    struct btrfs_file_extent_item);
-			btrfs_set_file_extent_disk_blocknr(extent,
-				    btrfs_file_extent_disk_blocknr(&old));
-			btrfs_set_file_extent_disk_num_blocks(extent,
-				    btrfs_file_extent_disk_num_blocks(&old));
-
-			btrfs_set_file_extent_offset(extent,
-				    btrfs_file_extent_offset(&old) +
-				    ((end - key.offset) >> inode->i_blkbits));
-			WARN_ON(btrfs_file_extent_num_blocks(&old) <
-				(extent_end - end) >> inode->i_blkbits);
-			btrfs_set_file_extent_num_blocks(extent,
-				    (extent_end - end) >> inode->i_blkbits);
-
-			btrfs_set_file_extent_type(extent,
-						   BTRFS_FILE_EXTENT_REG);
-			btrfs_set_file_extent_generation(extent,
-				    btrfs_file_extent_generation(&old));
-			btrfs_mark_buffer_dirty(path->nodes[0]);
-			if (btrfs_file_extent_disk_blocknr(&old) != 0) {
-				inode->i_blocks +=
-				      btrfs_file_extent_num_blocks(extent) << 3;
-			}
-			ret = 0;
-			goto out;
-		}
-	}
-out:
-	btrfs_free_path(path);
-	return ret;
-}
-
-static int prepare_pages(struct btrfs_root *root,
-			 struct file *file,
-			 struct page **pages,
-			 size_t num_pages,
-			 loff_t pos,
-			 unsigned long first_index,
-			 unsigned long last_index,
-			 size_t write_bytes,
-			 u64 alloc_extent_start)
-{
-	int i;
-	unsigned long index = pos >> PAGE_CACHE_SHIFT;
-	struct inode *inode = file->f_path.dentry->d_inode;
-	int offset;
-	int err = 0;
-	int this_write;
-	struct buffer_head *bh;
-	struct buffer_head *head;
-	loff_t isize = i_size_read(inode);
-
-	memset(pages, 0, num_pages * sizeof(struct page *));
-
-	for (i = 0; i < num_pages; i++) {
-		pages[i] = grab_cache_page(inode->i_mapping, index + i);
-		if (!pages[i]) {
-			err = -ENOMEM;
-			goto failed_release;
-		}
-		cancel_dirty_page(pages[i], PAGE_CACHE_SIZE);
-		wait_on_page_writeback(pages[i]);
-		offset = pos & (PAGE_CACHE_SIZE -1);
-		this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
-		if (!page_has_buffers(pages[i])) {
-			create_empty_buffers(pages[i],
-					     root->fs_info->sb->s_blocksize,
-					     (1 << BH_Uptodate));
-		}
-		head = page_buffers(pages[i]);
-		bh = head;
-		do {
-			err = btrfs_map_bh_to_logical(root, bh,
-						      alloc_extent_start);
-			BUG_ON(err);
-			if (err)
-				goto failed_truncate;
-			bh = bh->b_this_page;
-			if (alloc_extent_start)
-				alloc_extent_start++;
-		} while (bh != head);
-		pos += this_write;
-		WARN_ON(this_write > write_bytes);
-		write_bytes -= this_write;
-	}
-	return 0;
-
-failed_release:
-	btrfs_drop_pages(pages, num_pages);
-	return err;
-
-failed_truncate:
-	btrfs_drop_pages(pages, num_pages);
-	if (pos > isize)
-		vmtruncate(inode, isize);
-	return err;
-}
-
-static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
-				size_t count, loff_t *ppos)
-{
-	loff_t pos;
-	size_t num_written = 0;
-	int err = 0;
-	int ret = 0;
-	struct inode *inode = file->f_path.dentry->d_inode;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct page *pages[8];
-	struct page *pinned[2];
-	unsigned long first_index;
-	unsigned long last_index;
-	u64 start_pos;
-	u64 num_blocks;
-	u64 alloc_extent_start;
-	u64 hint_block;
-	struct btrfs_trans_handle *trans;
-	struct btrfs_key ins;
-	pinned[0] = NULL;
-	pinned[1] = NULL;
-	if (file->f_flags & O_DIRECT)
-		return -EINVAL;
-	pos = *ppos;
-	vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
-	current->backing_dev_info = inode->i_mapping->backing_dev_info;
-	err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
-	if (err)
-		goto out;
-	if (count == 0)
-		goto out;
-	err = remove_suid(file->f_path.dentry);
-	if (err)
-		goto out;
-	file_update_time(file);
-
-	start_pos = pos & ~((u64)PAGE_CACHE_SIZE - 1);
-	num_blocks = (count + pos - start_pos + root->blocksize - 1) >>
-			inode->i_blkbits;
-
-	mutex_lock(&inode->i_mutex);
-	first_index = pos >> PAGE_CACHE_SHIFT;
-	last_index = (pos + count) >> PAGE_CACHE_SHIFT;
-
-	if ((pos & (PAGE_CACHE_SIZE - 1))) {
-		pinned[0] = grab_cache_page(inode->i_mapping, first_index);
-		if (!PageUptodate(pinned[0])) {
-			ret = mpage_readpage(pinned[0], btrfs_get_block);
-			BUG_ON(ret);
-			wait_on_page_locked(pinned[0]);
-		} else {
-			unlock_page(pinned[0]);
-		}
-	}
-	if ((pos + count) & (PAGE_CACHE_SIZE - 1)) {
-		pinned[1] = grab_cache_page(inode->i_mapping, last_index);
-		if (!PageUptodate(pinned[1])) {
-			ret = mpage_readpage(pinned[1], btrfs_get_block);
-			BUG_ON(ret);
-			wait_on_page_locked(pinned[1]);
-		} else {
-			unlock_page(pinned[1]);
-		}
-	}
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	if (!trans) {
-		err = -ENOMEM;
-		mutex_unlock(&root->fs_info->fs_mutex);
-		goto out_unlock;
-	}
-	btrfs_set_trans_block_group(trans, inode);
-	/* FIXME blocksize != 4096 */
-	inode->i_blocks += num_blocks << 3;
-	hint_block = 0;
-	if (start_pos < inode->i_size) {
-		/* FIXME blocksize != pagesize */
-		ret = drop_extents(trans, root, inode,
-				   start_pos,
-				   (pos + count + root->blocksize -1) &
-				   ~((u64)root->blocksize - 1), &hint_block);
-		BUG_ON(ret);
-	}
-	if (inode->i_size < start_pos) {
-		u64 last_pos_in_file;
-		u64 hole_size;
-		u64 mask = root->blocksize - 1;
-		last_pos_in_file = (inode->i_size + mask) & ~mask;
-		hole_size = (start_pos - last_pos_in_file + mask) & ~mask;
-		hole_size >>= inode->i_blkbits;
-		if (last_pos_in_file < start_pos) {
-			ret = btrfs_insert_file_extent(trans, root,
-						       inode->i_ino,
-						       last_pos_in_file,
-						       0, 0, hole_size);
-		}
-		BUG_ON(ret);
-	}
-	if (inode->i_size >= PAGE_CACHE_SIZE || pos + count < inode->i_size ||
-	    pos + count - start_pos > BTRFS_MAX_INLINE_DATA_SIZE(root)) {
-		ret = btrfs_alloc_extent(trans, root, inode->i_ino,
-					 num_blocks, hint_block, (u64)-1,
-					 &ins, 1);
-		BUG_ON(ret);
-		ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
-				       start_pos, ins.objectid, ins.offset,
-				       ins.offset);
-		BUG_ON(ret);
-	} else {
-		ins.offset = 0;
-		ins.objectid = 0;
-	}
-	BUG_ON(ret);
-	alloc_extent_start = ins.objectid;
-	// btrfs_update_inode_block_group(trans, inode);
-	ret = btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	while(count > 0) {
-		size_t offset = pos & (PAGE_CACHE_SIZE - 1);
-		size_t write_bytes = min(count, PAGE_CACHE_SIZE - offset);
-		size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
-					PAGE_CACHE_SHIFT;
-
-		memset(pages, 0, sizeof(pages));
-		ret = prepare_pages(root, file, pages, num_pages,
-				    pos, first_index, last_index,
-				    write_bytes, alloc_extent_start);
-		BUG_ON(ret);
-
-		/* FIXME blocks != pagesize */
-		if (alloc_extent_start)
-			alloc_extent_start += num_pages;
-		ret = btrfs_copy_from_user(pos, num_pages,
-					   write_bytes, pages, buf);
-		BUG_ON(ret);
-
-		ret = dirty_and_release_pages(NULL, root, file, pages,
-					      num_pages, pos, write_bytes);
-		BUG_ON(ret);
-		btrfs_drop_pages(pages, num_pages);
-
-		buf += write_bytes;
-		count -= write_bytes;
-		pos += write_bytes;
-		num_written += write_bytes;
-
-		balance_dirty_pages_ratelimited(inode->i_mapping);
-		btrfs_btree_balance_dirty(root);
-		cond_resched();
-	}
-out_unlock:
-	mutex_unlock(&inode->i_mutex);
-out:
-	if (pinned[0])
-		page_cache_release(pinned[0]);
-	if (pinned[1])
-		page_cache_release(pinned[1]);
-	*ppos = pos;
-	current->backing_dev_info = NULL;
-	mark_inode_dirty(inode);
-	return num_written ? num_written : err;
-}
-
-static int btrfs_read_actor(read_descriptor_t *desc, struct page *page,
-			unsigned long offset, unsigned long size)
-{
-	char *kaddr;
-	unsigned long left, count = desc->count;
-	struct inode *inode = page->mapping->host;
-
-	if (size > count)
-		size = count;
-
-	if (!PageChecked(page)) {
-		/* FIXME, do it per block */
-		struct btrfs_root *root = BTRFS_I(inode)->root;
-		int ret;
-		struct buffer_head *bh;
-
-		if (page_has_buffers(page)) {
-			bh = page_buffers(page);
-			if (!buffer_mapped(bh)) {
-				SetPageChecked(page);
-				goto checked;
-			}
-		}
-
-		ret = btrfs_csum_verify_file_block(root,
-				  page->mapping->host->i_ino,
-				  page->index << PAGE_CACHE_SHIFT,
-				  kmap(page), PAGE_CACHE_SIZE);
-		if (ret) {
-			if (ret != -ENOENT) {
-				printk("failed to verify ino %lu page %lu ret %d\n",
-				       page->mapping->host->i_ino,
-				       page->index, ret);
-				memset(page_address(page), 1, PAGE_CACHE_SIZE);
-				flush_dcache_page(page);
-			}
-		}
-		SetPageChecked(page);
-		kunmap(page);
-	}
-checked:
-	/*
-	 * Faults on the destination of a read are common, so do it before
-	 * taking the kmap.
-	 */
-	if (!fault_in_pages_writeable(desc->arg.buf, size)) {
-		kaddr = kmap_atomic(page, KM_USER0);
-		left = __copy_to_user_inatomic(desc->arg.buf,
-						kaddr + offset, size);
-		kunmap_atomic(kaddr, KM_USER0);
-		if (left == 0)
-			goto success;
-	}
-
-	/* Do it the slow way */
-	kaddr = kmap(page);
-	left = __copy_to_user(desc->arg.buf, kaddr + offset, size);
-	kunmap(page);
-
-	if (left) {
-		size -= left;
-		desc->error = -EFAULT;
-	}
-success:
-	desc->count = count - size;
-	desc->written += size;
-	desc->arg.buf += size;
-	return size;
-}
-
-/**
- * btrfs_file_aio_read - filesystem read routine
- * @iocb:	kernel I/O control block
- * @iov:	io vector request
- * @nr_segs:	number of segments in the iovec
- * @pos:	current file position
- */
-static ssize_t btrfs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
-				   unsigned long nr_segs, loff_t pos)
-{
-	struct file *filp = iocb->ki_filp;
-	ssize_t retval;
-	unsigned long seg;
-	size_t count;
-	loff_t *ppos = &iocb->ki_pos;
-
-	count = 0;
-	for (seg = 0; seg < nr_segs; seg++) {
-		const struct iovec *iv = &iov[seg];
-
-		/*
-		 * If any segment has a negative length, or the cumulative
-		 * length ever wraps negative then return -EINVAL.
-		 */
-		count += iv->iov_len;
-		if (unlikely((ssize_t)(count|iv->iov_len) < 0))
-			return -EINVAL;
-		if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len))
-			continue;
-		if (seg == 0)
-			return -EFAULT;
-		nr_segs = seg;
-		count -= iv->iov_len;	/* This segment is no good */
-		break;
-	}
-	retval = 0;
-	if (count) {
-		for (seg = 0; seg < nr_segs; seg++) {
-			read_descriptor_t desc;
-
-			desc.written = 0;
-			desc.arg.buf = iov[seg].iov_base;
-			desc.count = iov[seg].iov_len;
-			if (desc.count == 0)
-				continue;
-			desc.error = 0;
-			do_generic_file_read(filp, ppos, &desc,
-					     btrfs_read_actor);
-			retval += desc.written;
-			if (desc.error) {
-				retval = retval ?: desc.error;
-				break;
-			}
-		}
-	}
-	return retval;
-}
-
-static int create_subvol(struct btrfs_root *root, char *name, int namelen)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_key key;
-	struct btrfs_root_item root_item;
-	struct btrfs_inode_item *inode_item;
-	struct buffer_head *subvol;
-	struct btrfs_leaf *leaf;
-	struct btrfs_root *new_root;
-	struct inode *inode;
-	struct inode *dir;
-	int ret;
-	u64 objectid;
-	u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	BUG_ON(!trans);
-
-	subvol = btrfs_alloc_free_block(trans, root, 0);
-	if (subvol == NULL)
-		return -ENOSPC;
-	leaf = btrfs_buffer_leaf(subvol);
-	btrfs_set_header_nritems(&leaf->header, 0);
-	btrfs_set_header_level(&leaf->header, 0);
-	btrfs_set_header_blocknr(&leaf->header, bh_blocknr(subvol));
-	btrfs_set_header_generation(&leaf->header, trans->transid);
-	btrfs_set_header_owner(&leaf->header, root->root_key.objectid);
-	memcpy(leaf->header.fsid, root->fs_info->disk_super->fsid,
-	       sizeof(leaf->header.fsid));
-	mark_buffer_dirty(subvol);
-
-	inode_item = &root_item.inode;
-	memset(inode_item, 0, sizeof(*inode_item));
-	btrfs_set_inode_generation(inode_item, 1);
-	btrfs_set_inode_size(inode_item, 3);
-	btrfs_set_inode_nlink(inode_item, 1);
-	btrfs_set_inode_nblocks(inode_item, 1);
-	btrfs_set_inode_mode(inode_item, S_IFDIR | 0755);
-
-	btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol));
-	btrfs_set_root_refs(&root_item, 1);
-	brelse(subvol);
-	subvol = NULL;
-
-	ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
-				       0, &objectid);
-	BUG_ON(ret);
-
-	btrfs_set_root_dirid(&root_item, new_dirid);
-
-	key.objectid = objectid;
-	key.offset = 1;
-	key.flags = 0;
-	btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
-	ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
-				&root_item);
-	BUG_ON(ret);
-
-	/*
-	 * insert the directory item
-	 */
-	key.offset = (u64)-1;
-	dir = root->fs_info->sb->s_root->d_inode;
-	ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
-				    name, namelen, dir->i_ino, &key,
-				    BTRFS_FT_DIR);
-	BUG_ON(ret);
-
-	ret = btrfs_commit_transaction(trans, root);
-	BUG_ON(ret);
-
-	new_root = btrfs_read_fs_root(root->fs_info, &key);
-	BUG_ON(!new_root);
-
-	trans = btrfs_start_transaction(new_root, 1);
-	BUG_ON(!trans);
-
-	inode = btrfs_new_inode(trans, new_root, new_dirid,
-				BTRFS_I(dir)->block_group, S_IFDIR | 0700);
-	inode->i_op = &btrfs_dir_inode_operations;
-	inode->i_fop = &btrfs_dir_file_operations;
-
-	ret = btrfs_make_empty_dir(trans, new_root, new_dirid, new_dirid);
-	BUG_ON(ret);
-
-	inode->i_nlink = 1;
-	inode->i_size = 6;
-	ret = btrfs_update_inode(trans, new_root, inode);
-	BUG_ON(ret);
-
-	ret = btrfs_commit_transaction(trans, new_root);
-	BUG_ON(ret);
-
-	iput(inode);
-
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-	return 0;
-}
-
-static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_key key;
-	struct btrfs_root_item new_root_item;
-	int ret;
-	u64 objectid;
-
-	if (!root->ref_cows)
-		return -EINVAL;
-
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	BUG_ON(!trans);
-
-	ret = btrfs_update_inode(trans, root, root->inode);
-	BUG_ON(ret);
-
-	ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
-				       0, &objectid);
-	BUG_ON(ret);
-
-	memcpy(&new_root_item, &root->root_item,
-	       sizeof(new_root_item));
-
-	key.objectid = objectid;
-	key.offset = 1;
-	key.flags = 0;
-	btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
-	btrfs_set_root_blocknr(&new_root_item, bh_blocknr(root->node));
-
-	ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
-				&new_root_item);
-	BUG_ON(ret);
-
-	/*
-	 * insert the directory item
-	 */
-	key.offset = (u64)-1;
-	ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
-				    name, namelen,
-				    root->fs_info->sb->s_root->d_inode->i_ino,
-				    &key, BTRFS_FT_DIR);
-
-	BUG_ON(ret);
-
-	ret = btrfs_inc_root_ref(trans, root);
-	BUG_ON(ret);
-
-	ret = btrfs_commit_transaction(trans, root);
-	BUG_ON(ret);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	btrfs_btree_balance_dirty(root);
-	return 0;
-}
-
-static int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
-		       cmd, unsigned long arg)
-{
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_ioctl_vol_args vol_args;
-	int ret = 0;
-	struct btrfs_dir_item *di;
-	int namelen;
-	struct btrfs_path *path;
-	u64 root_dirid;
-
-	switch (cmd) {
-	case BTRFS_IOC_SNAP_CREATE:
-		if (copy_from_user(&vol_args,
-				   (struct btrfs_ioctl_vol_args __user *)arg,
-				   sizeof(vol_args)))
-			return -EFAULT;
-		namelen = strlen(vol_args.name);
-		if (namelen > BTRFS_VOL_NAME_MAX)
-			return -EINVAL;
-		path = btrfs_alloc_path();
-		if (!path)
-			return -ENOMEM;
-		root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
-		mutex_lock(&root->fs_info->fs_mutex);
-		di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
-				    path, root_dirid,
-				    vol_args.name, namelen, 0);
-		mutex_unlock(&root->fs_info->fs_mutex);
-		btrfs_free_path(path);
-		if (di && !IS_ERR(di))
-			return -EEXIST;
-
-		if (root == root->fs_info->tree_root)
-			ret = create_subvol(root, vol_args.name, namelen);
-		else
-			ret = create_snapshot(root, vol_args.name, namelen);
-		WARN_ON(ret);
-		break;
-	default:
-		return -ENOTTY;
-	}
-	return ret;
-}
-
-#ifdef CONFIG_COMPAT
-static long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
-			       unsigned long arg)
-{
-	struct inode *inode = file->f_path.dentry->d_inode;
-	int ret;
-	lock_kernel();
-	ret = btrfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
-	unlock_kernel();
-	return ret;
-
-}
-#endif
-
-static struct kmem_cache *btrfs_inode_cachep;
-struct kmem_cache *btrfs_trans_handle_cachep;
-struct kmem_cache *btrfs_transaction_cachep;
-struct kmem_cache *btrfs_bit_radix_cachep;
-struct kmem_cache *btrfs_path_cachep;
-
-/*
- * Called inside transaction, so use GFP_NOFS
- */
-static struct inode *btrfs_alloc_inode(struct super_block *sb)
-{
-	struct btrfs_inode *ei;
-
-	ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
-	if (!ei)
-		return NULL;
-	return &ei->vfs_inode;
-}
-
-static void btrfs_destroy_inode(struct inode *inode)
-{
-	WARN_ON(!list_empty(&inode->i_dentry));
-	WARN_ON(inode->i_data.nrpages);
-
-	kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
-}
-
-static void init_once(void * foo, struct kmem_cache * cachep,
-		      unsigned long flags)
-{
-	struct btrfs_inode *ei = (struct btrfs_inode *) foo;
-
-	if ((flags & (SLAB_CTOR_CONSTRUCTOR)) ==
-	    SLAB_CTOR_CONSTRUCTOR) {
-		inode_init_once(&ei->vfs_inode);
-	}
-}
-
-static int init_inodecache(void)
-{
-	btrfs_inode_cachep = kmem_cache_create("btrfs_inode_cache",
-					     sizeof(struct btrfs_inode),
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD),
-					     init_once, NULL);
-	btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle_cache",
-					     sizeof(struct btrfs_trans_handle),
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD),
-					     NULL, NULL);
-	btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction_cache",
-					     sizeof(struct btrfs_transaction),
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD),
-					     NULL, NULL);
-	btrfs_path_cachep = kmem_cache_create("btrfs_path_cache",
-					     sizeof(struct btrfs_transaction),
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD),
-					     NULL, NULL);
-	btrfs_bit_radix_cachep = kmem_cache_create("btrfs_radix",
-					     256,
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD |
-						SLAB_DESTROY_BY_RCU),
-					     NULL, NULL);
-	if (btrfs_inode_cachep == NULL || btrfs_trans_handle_cachep == NULL ||
-	    btrfs_transaction_cachep == NULL || btrfs_bit_radix_cachep == NULL)
-		return -ENOMEM;
-	return 0;
-}
-
-static void destroy_inodecache(void)
-{
-	kmem_cache_destroy(btrfs_inode_cachep);
-	kmem_cache_destroy(btrfs_trans_handle_cachep);
-	kmem_cache_destroy(btrfs_transaction_cachep);
-	kmem_cache_destroy(btrfs_bit_radix_cachep);
-	kmem_cache_destroy(btrfs_path_cachep);
-}
-
 static int btrfs_get_sb(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
@@ -2709,15 +124,6 @@
 			   btrfs_fill_super, mnt);
 }
 
-static int btrfs_getattr(struct vfsmount *mnt,
-			 struct dentry *dentry, struct kstat *stat)
-{
-	struct inode *inode = dentry->d_inode;
-	generic_fillattr(inode, stat);
-	stat->blksize = 256 * 1024;
-	return 0;
-}
-
 static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct btrfs_root *root = btrfs_sb(dentry->d_sb);
@@ -2732,197 +138,6 @@
 	return 0;
 }
 
-static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry,
-			   struct inode * new_dir,struct dentry *new_dentry)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(old_dir)->root;
-	struct inode *new_inode = new_dentry->d_inode;
-	struct inode *old_inode = old_dentry->d_inode;
-	struct timespec ctime = CURRENT_TIME;
-	struct btrfs_path *path;
-	struct btrfs_dir_item *di;
-	int ret;
-
-	if (S_ISDIR(old_inode->i_mode) && new_inode &&
-	    new_inode->i_size > BTRFS_EMPTY_DIR_SIZE) {
-		return -ENOTEMPTY;
-	}
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, new_dir);
-	path = btrfs_alloc_path();
-	if (!path) {
-		ret = -ENOMEM;
-		goto out_fail;
-	}
-
-	old_dentry->d_inode->i_nlink++;
-	old_dir->i_ctime = old_dir->i_mtime = ctime;
-	new_dir->i_ctime = new_dir->i_mtime = ctime;
-	old_inode->i_ctime = ctime;
-	if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
-		struct btrfs_key *location = &BTRFS_I(new_dir)->location;
-		u64 old_parent_oid;
-		di = btrfs_lookup_dir_item(trans, root, path, old_inode->i_ino,
-					   "..", 2, -1);
-		if (IS_ERR(di)) {
-			ret = PTR_ERR(di);
-			goto out_fail;
-		}
-		if (!di) {
-			ret = -ENOENT;
-			goto out_fail;
-		}
-		old_parent_oid = btrfs_disk_key_objectid(&di->location);
-		ret = btrfs_del_item(trans, root, path);
-		if (ret) {
-			ret = -EIO;
-			goto out_fail;
-		}
-		btrfs_release_path(root, path);
-
-		di = btrfs_lookup_dir_index_item(trans, root, path,
-						 old_inode->i_ino,
-						 old_parent_oid,
-						 "..", 2, -1);
-		if (IS_ERR(di)) {
-			ret = PTR_ERR(di);
-			goto out_fail;
-		}
-		if (!di) {
-			ret = -ENOENT;
-			goto out_fail;
-		}
-		ret = btrfs_del_item(trans, root, path);
-		if (ret) {
-			ret = -EIO;
-			goto out_fail;
-		}
-		btrfs_release_path(root, path);
-
-		ret = btrfs_insert_dir_item(trans, root, "..", 2,
-					    old_inode->i_ino, location,
-					    BTRFS_FT_DIR);
-		if (ret)
-			goto out_fail;
-	}
-
-
-	ret = btrfs_unlink_trans(trans, root, old_dir, old_dentry);
-	if (ret)
-		goto out_fail;
-
-	if (new_inode) {
-		new_inode->i_ctime = CURRENT_TIME;
-		ret = btrfs_unlink_trans(trans, root, new_dir, new_dentry);
-		if (ret)
-			goto out_fail;
-		if (S_ISDIR(new_inode->i_mode))
-			clear_nlink(new_inode);
-		else
-			drop_nlink(new_inode);
-		btrfs_update_inode(trans, root, new_inode);
-	}
-	ret = btrfs_add_link(trans, new_dentry, old_inode);
-	if (ret)
-		goto out_fail;
-
-out_fail:
-	btrfs_free_path(path);
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-	return ret;
-}
-
-static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
-			 const char *symname)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = BTRFS_I(dir)->root;
-	struct btrfs_path *path;
-	struct btrfs_key key;
-	struct inode *inode;
-	int err;
-	int drop_inode = 0;
-	u64 objectid;
-	int name_len;
-	int datasize;
-	char *ptr;
-	struct btrfs_file_extent_item *ei;
-
-	name_len = strlen(symname) + 1;
-	if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
-		return -ENAMETOOLONG;
-	mutex_lock(&root->fs_info->fs_mutex);
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, dir);
-
-	err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
-	if (err) {
-		err = -ENOSPC;
-		goto out_unlock;
-	}
-
-	inode = btrfs_new_inode(trans, root, objectid,
-				BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO);
-	err = PTR_ERR(inode);
-	if (IS_ERR(inode))
-		goto out_unlock;
-
-	btrfs_set_trans_block_group(trans, inode);
-	err = btrfs_add_nondir(trans, dentry, inode);
-	if (err)
-		drop_inode = 1;
-	else {
-		inode->i_mapping->a_ops = &btrfs_aops;
-		inode->i_fop = &btrfs_file_operations;
-		inode->i_op = &btrfs_file_inode_operations;
-	}
-	dir->i_sb->s_dirt = 1;
-	btrfs_update_inode_block_group(trans, inode);
-	btrfs_update_inode_block_group(trans, dir);
-	if (drop_inode)
-		goto out_unlock;
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-	key.objectid = inode->i_ino;
-	key.offset = 0;
-	key.flags = 0;
-	btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
-	datasize = btrfs_file_extent_calc_inline_size(name_len);
-	err = btrfs_insert_empty_item(trans, root, path, &key,
-				      datasize);
-	BUG_ON(err);
-	ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
-	       path->slots[0], struct btrfs_file_extent_item);
-	btrfs_set_file_extent_generation(ei, trans->transid);
-	btrfs_set_file_extent_type(ei,
-				   BTRFS_FILE_EXTENT_INLINE);
-	ptr = btrfs_file_extent_inline_start(ei);
-	btrfs_memcpy(root, path->nodes[0]->b_data,
-		     ptr, symname, name_len);
-	mark_buffer_dirty(path->nodes[0]);
-	btrfs_free_path(path);
-	inode->i_op = &btrfs_symlink_inode_operations;
-	inode->i_mapping->a_ops = &btrfs_symlink_aops;
-	inode->i_size = name_len - 1;
-	btrfs_update_inode(trans, root, inode);
-	err = 0;
-
-out_unlock:
-	btrfs_end_transaction(trans, root);
-	mutex_unlock(&root->fs_info->fs_mutex);
-
-	if (drop_inode) {
-		inode_dec_link_count(inode);
-		iput(inode);
-	}
-	btrfs_btree_balance_dirty(root);
-	return err;
-}
-
 static struct file_system_type btrfs_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "btrfs",
@@ -2944,91 +159,21 @@
 	.statfs		= btrfs_statfs,
 };
 
-static struct inode_operations btrfs_dir_inode_operations = {
-	.lookup		= btrfs_lookup,
-	.create		= btrfs_create,
-	.unlink		= btrfs_unlink,
-	.link		= btrfs_link,
-	.mkdir		= btrfs_mkdir,
-	.rmdir		= btrfs_rmdir,
-	.rename		= btrfs_rename,
-	.symlink	= btrfs_symlink,
-	.setattr	= btrfs_setattr,
-};
-
-static struct inode_operations btrfs_dir_ro_inode_operations = {
-	.lookup		= btrfs_lookup,
-};
-
-static struct file_operations btrfs_dir_file_operations = {
-	.llseek		= generic_file_llseek,
-	.read		= generic_read_dir,
-	.readdir	= btrfs_readdir,
-	.ioctl		= btrfs_ioctl,
-#ifdef CONFIG_COMPAT
-	.compat_ioctl	= btrfs_compat_ioctl,
-#endif
-};
-
-static struct address_space_operations btrfs_aops = {
-	.readpage	= btrfs_readpage,
-	.writepage	= btrfs_writepage,
-	.sync_page	= block_sync_page,
-	.prepare_write	= btrfs_prepare_write,
-	.commit_write	= btrfs_commit_write,
-	.bmap		= btrfs_bmap,
-};
-
-static struct address_space_operations btrfs_symlink_aops = {
-	.readpage	= btrfs_readpage,
-	.writepage	= btrfs_writepage,
-};
-
-static struct inode_operations btrfs_file_inode_operations = {
-	.truncate	= btrfs_truncate,
-	.getattr	= btrfs_getattr,
-	.setattr	= btrfs_setattr,
-};
-
-static struct file_operations btrfs_file_operations = {
-	.llseek		= generic_file_llseek,
-	.read		= do_sync_read,
-	.aio_read       = btrfs_file_aio_read,
-	.write		= btrfs_file_write,
-	.mmap		= generic_file_mmap,
-	.open		= generic_file_open,
-	.ioctl		= btrfs_ioctl,
-	.fsync		= btrfs_sync_file,
-#ifdef CONFIG_COMPAT
-	.compat_ioctl	= btrfs_compat_ioctl,
-#endif
-};
-
-static struct inode_operations btrfs_symlink_inode_operations = {
-	.readlink	= generic_readlink,
-	.follow_link	= page_follow_link_light,
-	.put_link	= page_put_link,
-};
-
 static int __init init_btrfs_fs(void)
 {
 	int err;
-	printk("btrfs loaded!\n");
 	btrfs_init_transaction_sys();
-	err = init_inodecache();
+	err = btrfs_init_cachep();
 	if (err)
 		return err;
 	return register_filesystem(&btrfs_fs_type);
-	destroy_inodecache();
-	return err;
 }
 
 static void __exit exit_btrfs_fs(void)
 {
 	btrfs_exit_transaction_sys();
-	destroy_inodecache();
+	btrfs_destroy_cachep();
 	unregister_filesystem(&btrfs_fs_type);
-	printk("btrfs unloaded\n");
 }
 
 module_init(init_btrfs_fs)
