btrfs-progs: Improvement for making btrfs image from source directory.
[platform/upstream/btrfs-progs.git] / random-test.c
index 3a38ae7..0003236 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -48,7 +66,7 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
        unsigned long oid;
        btrfs_init_path(&path);
        ret = setup_key(radix, &key, 0);
-       sprintf(buf, "str-%Lu\n", key.objectid);
+       sprintf(buf, "str-%llu\n", (unsigned long long)key.objectid);
        ret = btrfs_insert_item(trans, root, &key, buf, strlen(buf));
        if (ret)
                goto error;
@@ -60,7 +78,7 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                goto error;
        return ret;
 error:
-       printf("failed to insert %Lu\n", key.objectid);
+       printf("failed to insert %llu\n", (unsigned long long)key.objectid);
        return -1;
 }
 
@@ -75,10 +93,11 @@ static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
        ret = setup_key(radix, &key, 1);
        if (ret < 0)
                return 0;
-       sprintf(buf, "str-%Lu\n", key.objectid);
+       sprintf(buf, "str-%llu\n", (unsigned long long)key.objectid);
        ret = btrfs_insert_item(trans, root, &key, buf, strlen(buf));
        if (ret != -EEXIST) {
-               printf("insert on %Lu gave us %d\n", key.objectid, ret);
+               printf("insert on %llu gave us %d\n",
+                      (unsigned long long)key.objectid, ret);
                return 1;
        }
        return 0;
@@ -107,7 +126,7 @@ static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                goto error;
        return 0;
 error:
-       printf("failed to delete %Lu\n", key.objectid);
+       printf("failed to delete %llu\n", (unsigned long long)key.objectid);
        return -1;
 }
 
@@ -127,7 +146,7 @@ static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
                goto error;
        return 0;
 error:
-       printf("unable to find key %Lu\n", key.objectid);
+       printf("unable to find key %llu\n", (unsigned long long)key.objectid);
        return -1;
 }
 
@@ -147,7 +166,8 @@ static int lookup_enoent(struct btrfs_trans_handle *trans, struct btrfs_root
                goto error;
        return 0;
 error:
-       printf("able to find key that should not exist %Lu\n", key.objectid);
+       printf("able to find key that should not exist %llu\n",
+              (unsigned long long)key.objectid);
        return -1;
 }
 
@@ -261,7 +281,7 @@ static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix)
 {
        struct btrfs_path path;
        struct btrfs_key key;
-       unsigned long found;
+       unsigned long found = 0;
        int ret;
        int slot;
        int i;
@@ -384,7 +404,7 @@ int main(int ac, char **av)
                        if (ret) {
                                fprintf(stderr, "op %d failed %d:%d\n",
                                        op, i, iterations);
-                               btrfs_print_tree(root, root->node);
+                               btrfs_print_tree(root, root->node, 1);
                                fprintf(stderr, "op %d failed %d:%d\n",
                                        op, i, iterations);
                                err = ret;