Commit e20d96d6 authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Mountable btrfs, with readdir

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 2e635a27
......@@ -2,7 +2,8 @@ ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
obj-m := btrfs.o
btrfs-y := super.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
#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 \
......@@ -14,7 +15,7 @@ else
KERNELDIR := /lib/modules/`uname -r`/build
all::
$(MAKE) -C $(KERNELDIR) M=`pwd` modules
$(MAKE) C=1 -C $(KERNELDIR) M=`pwd` modules
clean::
rm *.o btrfs.ko
endif
This diff is collapsed.
#ifndef __BTRFS__
#define __BTRFS__
#include <linux/radix-tree.h>
#include <linux/fs.h>
struct btrfs_trans_handle;
#define BTRFS_MAGIC "_BtRfS_M"
......@@ -10,6 +13,12 @@ struct btrfs_trans_handle;
#define BTRFS_INODE_MAP_OBJECTID 3
#define BTRFS_FS_TREE_OBJECTID 4
/*
* we can actually store much bigger names, but lets not confuse the rest
* of linux
*/
#define BTRFS_NAME_LEN 255
/*
* the key defines the order in the tree, and so it also defines (optimal)
* block layout. objectid corresonds to the inode number. The flags
......@@ -57,7 +66,7 @@ struct btrfs_header {
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
struct btrfs_buffer;
struct buffer_head;
/*
* the super block basically lists the main trees of the FS
* it currently lacks any block count etc etc
......@@ -120,7 +129,7 @@ struct btrfs_node {
* used while walking the tree.
*/
struct btrfs_path {
struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
struct buffer_head *nodes[BTRFS_MAX_LEVEL];
int slots[BTRFS_MAX_LEVEL];
};
......@@ -211,17 +220,14 @@ struct btrfs_fs_info {
struct btrfs_root *inode_root;
struct btrfs_key current_insert;
struct btrfs_key last_insert;
struct radix_tree_root cache_radix;
struct radix_tree_root pinned_radix;
struct list_head trans;
struct list_head cache;
u64 last_inode_alloc;
u64 last_inode_alloc_dirid;
u64 generation;
int cache_size;
int fp;
struct btrfs_trans_handle *running_transaction;
struct btrfs_super_block *disk_super;
struct buffer_head *sb_buffer;
struct super_block *sb;
};
/*
......@@ -230,8 +236,8 @@ struct btrfs_fs_info {
* only for the extent tree.
*/
struct btrfs_root {
struct btrfs_buffer *node;
struct btrfs_buffer *commit_root;
struct buffer_head *node;
struct buffer_head *commit_root;
struct btrfs_root_item root_item;
struct btrfs_key root_key;
struct btrfs_fs_info *fs_info;
......@@ -389,6 +395,29 @@ static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
i->compat_flags = cpu_to_le16(val);
}
static inline u32 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
{
return le32_to_cpu(ts->sec);
}
static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
u32 val)
{
ts->sec = cpu_to_le32(val);
}
static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
{
return le32_to_cpu(ts->nsec);
}
static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
u32 val)
{
ts->nsec = cpu_to_le32(val);
}
static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
{
......@@ -757,15 +786,20 @@ static inline void btrfs_set_file_extent_num_blocks(struct
e->num_blocks = cpu_to_le64(val);
}
static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
{
return sb->s_fs_info;
}
/* helper function to cast into the data area of the leaf. */
#define btrfs_item_ptr(leaf, slot, type) \
((type *)(btrfs_leaf_data(leaf) + \
btrfs_item_offset((leaf)->items + (slot))))
struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_buffer *buf);
struct buffer_head *buf);
int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 blocknr, u64 num_blocks, int pin);
int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
......@@ -783,7 +817,7 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_buffer *snap);
*root, struct buffer_head *snap);
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
btrfs_root *root);
int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
......@@ -800,8 +834,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
*root, char *name, int name_len, u64 dir, u64
objectid, u8 type);
int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_path *path, u64 dir, char *name,
int name_len, int mod);
*root, struct btrfs_path *path, u64 dir,
const char *name, int name_len, int mod);
int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
char *name, int name_len);
int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
......
......@@ -18,12 +18,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
key.objectid = dir;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
if (name_len == 1 && *name == '.')
key.offset = 1;
else if (name_len == 2 && name[0] == '.' && name[1] == '.')
key.offset = 2;
else
ret = btrfs_name_hash(name, name_len, &key.offset);
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
btrfs_init_path(&path);
data_size = sizeof(*dir_item) + name_len;
......@@ -31,7 +26,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
if (ret)
goto out;
dir_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
dir_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
path.slots[0],
struct btrfs_dir_item);
btrfs_set_dir_objectid(dir_item, objectid);
btrfs_set_dir_type(dir_item, type);
......@@ -45,8 +41,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
}
int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_path *path, u64 dir, char *name,
int name_len, int mod)
*root, struct btrfs_path *path, u64 dir,
const char *name, int name_len, int mod)
{
int ret;
struct btrfs_key key;
......@@ -69,7 +65,8 @@ int btrfs_match_dir_item_name(struct btrfs_root *root,
struct btrfs_dir_item *dir_item;
char *name_ptr;
dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0],
dir_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
path->slots[0],
struct btrfs_dir_item);
if (btrfs_dir_name_len(dir_item) != name_len)
return 0;
......
This diff is collapsed.
#ifndef __DISKIO__
#define __DISKIO__
#include "list.h"
struct btrfs_buffer {
u64 blocknr;
int count;
struct list_head dirty;
struct list_head cache;
union {
struct btrfs_node node;
struct btrfs_leaf leaf;
};
};
#include <linux/buffer_head.h>
struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr);
struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr);
#define BTRFS_SUPER_INFO_OFFSET (16 * 1024)
static inline struct btrfs_node *btrfs_buffer_node(struct buffer_head *bh)
{
return (struct btrfs_node *)bh->b_data;
}
static inline struct btrfs_leaf *btrfs_buffer_leaf(struct buffer_head *bh)
{
return (struct btrfs_leaf *)bh->b_data;
}
static inline struct btrfs_header *btrfs_buffer_header(struct buffer_head *bh)
{
return &((struct btrfs_node *)bh->b_data)->header;
}
struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr);
struct buffer_head *find_tree_block(struct btrfs_root *root, u64 blocknr);
int write_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_buffer *buf);
struct buffer_head *buf);
int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_buffer *buf);
struct buffer_head *buf);
int clean_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_buffer *buf);
struct btrfs_root *root, struct buffer_head *buf);
int btrfs_commit_transaction(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_super_block *s);
struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super);
int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s);
void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf);
struct btrfs_root *open_ctree(struct super_block *sb,
struct buffer_head *sb_buffer,
struct btrfs_super_block *disk_super);
int close_ctree(struct btrfs_root *root);
void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf);
int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_super_block *s);
int mkfs(int fd, u64 num_blocks, u32 blocksize);
#define BTRFS_SUPER_INFO_OFFSET (16 * 1024)
#endif
This diff is collapsed.
......@@ -10,6 +10,7 @@
* License.
*/
#include <linux/types.h>
#define DELTA 0x9E3779B9
static void TEA_transform(__u32 buf[2], __u32 const in[])
......@@ -63,6 +64,14 @@ int btrfs_name_hash(const char *name, int len, u64 *hash_result)
const char *p;
__u32 in[8], buf[2];
if (len == 1 && *name == '.') {
*hash_result = 1;
return 0;
} else if (len == 2 && name[0] == '.' && name[1] == '.') {
*hash_result = 2;
return 0;
}
/* Initialize the default seed for the hash checksum functions */
buf[0] = 0x67452301;
buf[1] = 0xefcdab89;
......
......@@ -15,7 +15,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
int ret;
u64 hole_size = 0;
int slot = 0;
u64 last_ino;
u64 last_ino = 0;
int start_found;
struct btrfs_leaf *l;
struct btrfs_root *root = fs_root->fs_info->inode_root;
......@@ -40,7 +40,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
path.slots[0]--;
while (1) {
l = &path.nodes[0]->leaf;
l = btrfs_buffer_leaf(path.nodes[0]);
slot = path.slots[0];
if (slot >= btrfs_header_nritems(&l->header)) {
ret = btrfs_next_leaf(root, &path);
......@@ -105,8 +105,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
if (ret)
goto out;
inode_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
struct btrfs_inode_map_item);
inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
path.slots[0], struct btrfs_inode_map_item);
btrfs_cpu_key_to_disk(&inode_item->key, location);
out:
btrfs_release_path(inode_root, &path);
......
......@@ -17,7 +17,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
printk("leaf %Lu total ptrs %d free space %d\n",
btrfs_header_blocknr(&l->header), nr,
btrfs_leaf_free_space(root, l));
fflush(stdout);
for (i = 0 ; i < nr ; i++) {
item = l->items + i;
type = btrfs_disk_key_type(&item->key);
......@@ -67,10 +66,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
btrfs_leaf_data(l) + btrfs_item_offset(item));
break;
};
fflush(stdout);
}
}
void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t)
{
int i;
u32 nr;
......@@ -78,16 +77,16 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
if (!t)
return;
c = &t->node;
c = btrfs_buffer_node(t);
nr = btrfs_header_nritems(&c->header);
if (btrfs_is_leaf(c)) {
btrfs_print_leaf(root, (struct btrfs_leaf *)c);
return;
}
printk("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
btrfs_header_level(&c->header), nr,
(u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
fflush(stdout);
printk("node %Lu level %d total ptrs %d free spc %u\n",
btrfs_header_blocknr(&c->header),
btrfs_header_level(&c->header), nr,
(u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
for (i = 0; i < nr; i++) {
printk("\tkey %d (%Lu %u %Lu) block %Lu\n",
i,
......@@ -95,12 +94,11 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
c->ptrs[i].key.flags,
c->ptrs[i].key.offset,
btrfs_node_blockptr(c, i));
fflush(stdout);
}
for (i = 0; i < nr; i++) {
struct btrfs_buffer *next_buf = read_tree_block(root,
struct buffer_head *next_buf = read_tree_block(root,
btrfs_node_blockptr(c, i));
struct btrfs_node *next = &next_buf->node;
struct btrfs_node *next = btrfs_buffer_node(next_buf);
if (btrfs_is_leaf(next) &&
btrfs_header_level(&c->header) != 1)
BUG();
......
#ifndef __PRINT_TREE_
#define __PRINT_TREE_
void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l);
void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t);
void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t);
#endif
......@@ -21,7 +21,7 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
if (ret < 0)
goto out;
BUG_ON(ret == 0);
l = &path.nodes[0]->leaf;
l = btrfs_buffer_leaf(path.nodes[0]);
BUG_ON(path.slots[0] == 0);
slot = path.slots[0] - 1;
if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) {
......@@ -51,7 +51,7 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
if (ret < 0)
goto out;
BUG_ON(ret != 0);
l = &path.nodes[0]->leaf;
l = btrfs_buffer_leaf(path.nodes[0]);
slot = path.slots[0];
memcpy(btrfs_item_ptr(l, slot, struct btrfs_root_item), item,
sizeof(*item));
......
#include <linux/module.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/highmem.h>
......@@ -8,13 +9,18 @@
#include <linux/smp_lock.h>
#include <linux/backing-dev.h>
#include "ctree.h"
#include "disk-io.h"
#define BTRFS_SUPER_MAGIC 0x9123682E
static struct inode_operations btrfs_dir_inode_operations;
static struct super_operations btrfs_super_ops;
static struct file_operations btrfs_dir_file_operations;
#if 0
/* some random number */
static struct super_operations ramfs_ops;
static struct inode_operations ramfs_dir_inode_operations;
static struct backing_dev_info ramfs_backing_dev_info = {
.ra_pages = 0, /* No readahead */
......@@ -129,46 +135,243 @@ static struct inode_operations ramfs_dir_inode_operations = {
};
#endif
struct inode *btrfs_get_inode(struct super_block *sb, int mode, dev_t dev)
static void btrfs_read_locked_inode(struct inode *inode)
{
struct inode * inode = new_inode(sb);
struct btrfs_path path;
struct btrfs_inode_item *inode_item;
struct btrfs_root *root = btrfs_sb(inode->i_sb);
int ret;
printk("read locked inode %lu\n", inode->i_ino);
btrfs_init_path(&path);
ret = btrfs_lookup_inode(NULL, root, &path, inode->i_ino, 0);
if (ret) {
make_bad_inode(inode);
return;
}
inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
path.slots[0],
struct btrfs_inode_item);
if (inode) {
inode->i_mode = mode;
inode->i_uid = current->fsuid;
inode->i_gid = current->fsgid;
inode->i_blocks = 0;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
printk("found locked inode %lu\n", inode->i_ino);
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);
printk("about to release\n");
btrfs_release_path(root, &path);
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:
printk("inode %lu now a file\n", inode->i_ino);
break;
case S_IFDIR:
printk("inode %lu now a directory\n", inode->i_ino);
inode->i_op = &btrfs_dir_inode_operations;
inode->i_fop = &btrfs_dir_file_operations;
break;
case S_IFLNK:
printk("inode %lu now a link\n", inode->i_ino);
// inode->i_op = &page_symlink_inode_operations;
break;
}
return inode;
printk("returning!\n");
return;
}
static struct super_operations btrfs_ops = {
.statfs = simple_statfs,
.drop_inode = generic_delete_inode,
};
static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
ino_t *ino)
{
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_sb(dir->i_sb);
int ret;
btrfs_init_path(&path);
ret = btrfs_lookup_dir_item(NULL, root, &path, dir->i_ino, name,
namelen, 0);
if (ret) {
*ino = 0;
goto out;
}
di = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), path.slots[0],
struct btrfs_dir_item);
*ino = btrfs_dir_objectid(di);
out:
btrfs_release_path(root, &path);
return ret;
}
static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
struct nameidata *nd)
{
struct inode * inode;
ino_t ino;
int ret;
if (dentry->d_name.len > BTRFS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
ret = btrfs_inode_by_name(dir, dentry, &ino);
if (ret < 0)
return ERR_PTR(ret);
inode = NULL;
if (ino) {
printk("lookup on %.*s returns %lu\n", dentry->d_name.len, dentry->d_name.name, ino);
inode = iget(dir->i_sb, ino);
if (!inode)
return ERR_PTR(-EACCES);
}
return d_splice_alias(inode, dentry);
}
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_sb(inode->i_sb);
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 = DT_UNKNOWN;
int over;
key.objectid = inode->i_ino;
printk("readdir on dir %Lu pos %Lu\n", key.objectid, filp->f_pos);
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
key.offset = filp->f_pos;
btrfs_init_path(&path);
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) {
goto err;
}
printk("first ret %d\n", ret);
advance = filp->f_pos > 0 && ret != 0;
while(1) {
leaf = btrfs_buffer_leaf(path.nodes[0]);
nritems = btrfs_header_nritems(&leaf->header);
slot = path.slots[0];
printk("leaf %Lu nritems %lu slot %d\n", path.nodes[0]->b_blocknr, nritems, slot);
if (advance) {
printk("advancing!\n");
if (slot == nritems -1) {
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];
printk("2leaf %Lu nritems %lu slot %d\n", path.nodes[0]->b_blocknr, nritems, slot);
} else {
slot++;
path.slots[0]++;
}
}
advance = 1;
item = leaf->items + slot;
printk("item key %Lu %u %Lu\n", btrfs_disk_key_objectid(&item->key),
btrfs_disk_key_flags(&item->key), btrfs_disk_key_offset(&item->key));
if (btrfs_disk_key_objectid(&item->key) != key.objectid)
break;
if (btrfs_disk_key_type(&item->key) != BTRFS_DIR_ITEM_KEY)
continue;
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
printk("filldir name %.*s, objectid %Lu\n", btrfs_dir_name_len(di),
(const char *)(di + 1), btrfs_dir_objectid(di));
over = filldir(dirent, (const char *)(di + 1),
btrfs_dir_name_len(di),
btrfs_disk_key_offset(&item->key),
btrfs_dir_objectid(di), d_type);
if (over)
break;
filp->f_pos = btrfs_disk_key_offset(&item->key) + 1;
}
printk("filldir all done\n");
ret = 0;
err:
btrfs_release_path(root, &path);
return ret;
}
static void btrfs_put_super (struct super_block * sb)
{
struct btrfs_root *root = btrfs_sb(sb);
int ret;
ret = close_ctree(root);
if (ret) {
printk("close ctree returns %d\n", ret);
}
sb->s_fs_info = NULL;
}
static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
{
struct inode * inode;
struct dentry * root;
struct dentry * root_dentry;
struct btrfs_super_block *disk_super;
struct buffer_head *bh;
struct btrfs_root *root;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_blocksize = PAGE_CACHE_SIZE;
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
sb->s_magic = BTRFS_SUPER_MAGIC;
sb->s_op = &btrfs_ops;
sb->s_op = &btrfs_super_ops;
sb->s_time_gran = 1;
inode = btrfs_get_inode(sb, S_IFDIR | 0755, 0);
bh = sb_bread(sb, BTRFS_SUPER_INFO_OFFSET / sb->s_blocksize);
if (!bh) {
printk("btrfs: unable to read on disk super\n");
return -EIO;
}
disk_super = (struct btrfs_super_block *)bh->b_data;
root = open_ctree(sb, bh, disk_super);
sb->s_fs_info = root;
if (!root) {
printk("btrfs: open_ctree failed\n");
return -EIO;
}
printk("read in super total blocks %Lu root %Lu\n",
btrfs_super_total_blocks(disk_super),
btrfs_super_root_dir(disk_super));
inode = iget_locked(sb, btrfs_super_root_dir(disk_super));
if (!inode)
return -ENOMEM;
if (inode->i_state & I_NEW) {
btrfs_read_locked_inode(inode);
unlock_new_inode(inode);
}
root = d_alloc_root(inode);
if (!root) {
root_dentry = d_alloc_root(inode);
if (!root_dentry) {
iput(inode);
return -ENOMEM;
}
sb->s_root = root;
sb->s_root = root_dentry;
return 0;
}
......@@ -187,6 +390,24 @@ static struct file_system_type btrfs_fs_type = {
.fs_flags = FS_REQUIRES_DEV,
};
static struct super_operations btrfs_super_ops = {
.statfs = simple_statfs,
.drop_inode = generic_delete_inode,
.put_super = btrfs_put_super,
.read_inode = btrfs_read_locked_inode,
};
static struct inode_operations btrfs_dir_inode_operations = {
.lookup = btrfs_lookup,
};
static struct file_operations btrfs_dir_file_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.readdir = btrfs_readdir,
};
static int __init init_btrfs_fs(void)
{
printk("btrfs loaded!\n");
......
......@@ -10,7 +10,7 @@ struct btrfs_trans_handle {
static inline struct btrfs_trans_handle *
btrfs_start_transaction(struct btrfs_root *root, int num_blocks)
{
struct btrfs_trans_handle *h = malloc(sizeof(*h));
struct btrfs_trans_handle *h = kmalloc(sizeof(*h), GFP_NOFS);
h->transid = root->root_key.offset;
h->blocks_reserved = num_blocks;
h->blocks_used = 0;
......@@ -21,7 +21,7 @@ static inline void btrfs_free_transaction(struct btrfs_root *root,
struct btrfs_trans_handle *handle)
{
memset(handle, 0, sizeof(*handle));
free(handle);
kfree(handle);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment