return 1;
if (k1.objectid < k2->objectid)
return -1;
- if (k1.offset > k2->offset)
- return 1;
- if (k1.offset < k2->offset)
- return -1;
if (k1.flags > k2->flags)
return 1;
if (k1.flags < k2->flags)
return -1;
+ if (k1.offset > k2->offset)
+ return 1;
+ if (k1.offset < k2->offset)
+ return -1;
return 0;
}
*/
struct btrfs_disk_key {
__le64 objectid;
- __le64 offset;
__le32 flags;
+ __le64 offset;
} __attribute__ ((__packed__));
struct btrfs_key {
u64 objectid;
- u64 offset;
u32 flags;
+ u64 offset;
} __attribute__ ((__packed__));
/*
struct btrfs_dir_item {
__le64 objectid;
__le16 flags;
+ __le16 name_len;
u8 type;
} __attribute__ ((__packed__));
d->type = val;
}
-static inline u32 btrfs_dir_name_len(struct btrfs_item *i)
+static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
+{
+ return le16_to_cpu(d->name_len);
+}
+
+static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
{
- return btrfs_item_size(i) - sizeof(struct btrfs_dir_item);
+ d->name_len = cpu_to_le16(val);
}
static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
btrfs_set_dir_objectid(dir_item, objectid);
btrfs_set_dir_type(dir_item, type);
btrfs_set_dir_flags(dir_item, 0);
+ btrfs_set_dir_name_len(dir_item, name_len);
name_ptr = (char *)(dir_item + 1);
memcpy(name_ptr, name, name_len);
out:
int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
char *name, int name_len)
{
- struct btrfs_item *item;
struct btrfs_dir_item *dir_item;
char *name_ptr;
- u32 item_len;
- 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)) {
- return 0;
- }
+
dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0],
struct btrfs_dir_item);
+ if (btrfs_dir_name_len(dir_item) != name_len)
+ return 0;
name_ptr = (char *)(dir_item + 1);
- if (memcmp(name_ptr, name, name_len)) {
+ if (memcmp(name_ptr, name, name_len))
return 0;
- }
return 1;
}
di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
struct btrfs_dir_item);
found = (char *)(di + 1);
- found_len = btrfs_dir_name_len(path.nodes[0]->leaf.items +
- path.slots[0]);
+ found_len = btrfs_dir_name_len(di);
btrfs_name_hash(buf, strlen(buf), &myhash);
btrfs_name_hash(found, found_len, &foundhash);
if (myhash != foundhash)
slot = path.slots[0];
di = btrfs_item_ptr(&path.nodes[0]->leaf, slot,
struct btrfs_dir_item);
- found_len = btrfs_dir_name_len(path.nodes[0]->leaf.items +
- slot);
+ found_len = btrfs_dir_name_len(di);
memcpy(buf, (char *)(di + 1), found_len);
BUG_ON(found_len > 128);
buf[found_len] = '\0';
for (i = 0 ; i < nr ; i++) {
item = l->items + i;
type = btrfs_disk_key_type(&item->key);
- printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n",
+ printf("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n",
i,
btrfs_disk_key_objectid(&item->key),
- btrfs_disk_key_offset(&item->key),
btrfs_disk_key_flags(&item->key),
+ btrfs_disk_key_offset(&item->key),
btrfs_item_offset(item),
btrfs_item_size(item));
switch (type) {
(u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
fflush(stdout);
for (i = 0; i < nr; i++) {
- printf("\tkey %d (%Lu %Lu %u) block %Lu\n",
+ printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
i,
c->ptrs[i].key.objectid,
- c->ptrs[i].key.offset,
c->ptrs[i].key.flags,
+ c->ptrs[i].key.offset,
btrfs_node_blockptr(c, i));
fflush(stdout);
}