Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128283
b: refs/heads/master
c: 1d4f640
h: refs/heads/master
i:
  128281: b1e607f
  128279: 9ba2c11
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed Mar 15, 2007
1 parent 189b5ec commit ea555fa
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 75 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 24af03ea5e765d57860c975efcdcd41ec7f63fd9
refs/heads/master: 1d4f6404de26df49eb8452f8fdf7672b59f407fc
5 changes: 3 additions & 2 deletions trunk/fs/btrfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

CC=gcc
CFLAGS = -g -Wall
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h
Expand All @@ -15,14 +14,16 @@ check=sparse $(CHECKFLAGS)
$(check) $<
$(CC) $(CFLAGS) -c $<

all: tester debug-tree quick-test
all: tester debug-tree quick-test dir-test

debug-tree: $(objects) debug-tree.o
gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o

tester: $(objects) random-test.o
gcc $(CFLAGS) -o tester $(objects) random-test.o

dir-test: $(objects) dir-test.o
gcc $(CFLAGS) -o dir-test $(objects) dir-test.o
quick-test: $(objects) quick-test.o
gcc $(CFLAGS) -o quick-test $(objects) quick-test.o

Expand Down
72 changes: 41 additions & 31 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,37 +180,6 @@ struct btrfs_root {
#define BTRFS_EXTENT_ITEM_KEY 4
#define BTRFS_STRING_ITEM_KEY 5

static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d)
{
return le64_to_cpu(d->objectid);
}

static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val)
{
d->objectid = cpu_to_le64(val);
}

static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
{
return le16_to_cpu(d->flags);
}

static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
{
d->flags = cpu_to_le16(val);
}

static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
{
return d->type;
}

static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
{
d->type = val;
}


static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
{
return le64_to_cpu(ei->owner);
Expand Down Expand Up @@ -267,6 +236,41 @@ static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
item->size = cpu_to_le16(val);
}

static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d)
{
return le64_to_cpu(d->objectid);
}

static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val)
{
d->objectid = cpu_to_le64(val);
}

static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
{
return le16_to_cpu(d->flags);
}

static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
{
d->flags = cpu_to_le16(val);
}

static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
{
return d->type;
}

static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
{
d->type = val;
}

static inline u32 btrfs_dir_name_len(struct btrfs_item *i)
{
return btrfs_item_size(i) - sizeof(struct btrfs_dir_item);
}

static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
struct btrfs_disk_key *disk)
{
Expand Down Expand Up @@ -506,4 +510,10 @@ int btrfs_update_root(struct btrfs_root *root, struct btrfs_key *key,
struct btrfs_root_item *item);
int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
struct btrfs_root_item *item, struct btrfs_key *key);
int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,
u64 dir, u64 objectid, u8 type);
int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path,
u64 dir, 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);
#endif
58 changes: 17 additions & 41 deletions trunk/fs/btrfs/dir-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,

key.objectid = dir;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
btrfs_init_path(&path);
Expand All @@ -38,65 +39,40 @@ int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,
return ret;
}

int btrfs_del_dir_item(struct btrfs_root *root, u64 dir, char *name,
int name_len)
int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path,
u64 dir, char *name, int name_len, int mod)
{
int ret = 0;
struct btrfs_path path;
int ret;
struct btrfs_key key;
int ins_len = mod < 0 ? -1 : 0;
int cow = mod != 0;

key.objectid = dir;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &key, &path, 0, 1);
if (ret)
goto out;
ret = btrfs_del_item(root, &path);
out:
btrfs_release_path(root, &path);
ret = btrfs_search_slot(root, &key, path, ins_len, cow);
return ret;
}

int btrfs_lookup_dir_item(struct btrfs_root *root, u64 dir, char *name,
int name_len, u64 *objectid)
int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
char *name, int name_len)
{
int ret = 0;
struct btrfs_path path;
struct btrfs_item *item;
struct btrfs_dir_item *dir_item;
char *name_ptr;
struct btrfs_key key;
u32 item_len;
struct btrfs_item *item;

key.objectid = dir;
key.flags = 0;
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
btrfs_init_path(&path);
ret = btrfs_search_slot(root, &key, &path, 0, 0);
if (ret)
goto out;

dir_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
struct btrfs_dir_item);

item = path.nodes[0]->leaf.items + path.slots[0];
item = path->nodes[0]->leaf.items + path->slots[0];
item_len = btrfs_item_size(item);
if (item_len != name_len + sizeof(struct btrfs_dir_item)) {
BUG();
ret = 1;
goto out;
return 0;
}
dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0],
struct btrfs_dir_item);
name_ptr = (char *)(dir_item + 1);
if (memcmp(name_ptr, name, name_len)) {
BUG();
ret = 1;
goto out;
return 0;
}
*objectid = btrfs_dir_objectid(dir_item);
out:
btrfs_release_path(root, &path);
return ret;
return 1;
}
Loading

0 comments on commit ea555fa

Please sign in to comment.