Btrfs: still corruption hunting
[deliverable/linux.git] / fs / btrfs / dir-item.c
index a42a67b99753a55146eb01f8fa14c248db736d9a..f55c89472ac067e969be816b08febcaf25a22905 100644 (file)
@@ -1,13 +1,12 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "kerncompat.h"
-#include "radix-tree.h"
+#include <linux/module.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "hash.h"
+#include "transaction.h"
 
-int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,
-                         u64 dir, u64 objectid, u8 type)
+int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
+                         *root, const char *name, int name_len, u64 dir, u64
+                         objectid, u8 type)
 {
        int ret = 0;
        struct btrfs_path path;
@@ -23,25 +22,28 @@ int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,
        BUG_ON(ret);
        btrfs_init_path(&path);
        data_size = sizeof(*dir_item) + name_len;
-       ret = btrfs_insert_empty_item(root, &path, &key, data_size);
+       ret = btrfs_insert_empty_item(trans, root, &path, &key, data_size);
        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);
        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);
+       btrfs_memcpy(root, path.nodes[0]->b_data, name_ptr, name, name_len);
+       btrfs_mark_buffer_dirty(path.nodes[0]);
 out:
        btrfs_release_path(root, &path);
        return ret;
 }
 
-int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path,
-                         u64 dir, char *name, int name_len, int mod)
+int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
+                         *root, struct btrfs_path *path, u64 dir,
+                         const char *name, int name_len, int mod)
 {
        int ret;
        struct btrfs_key key;
@@ -53,17 +55,19 @@ int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path,
        btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
        ret = btrfs_name_hash(name, name_len, &key.offset);
        BUG_ON(ret);
-       ret = btrfs_search_slot(root, &key, path, ins_len, cow);
+       ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
        return ret;
 }
 
-int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
-                             char *name, int name_len)
+int btrfs_match_dir_item_name(struct btrfs_root *root,
+                             struct btrfs_path *path,
+                             const char *name, int name_len)
 {
        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 page took 0.029212 seconds and 5 git commands to generate.