uuids
authorChris Mason <chris.mason@oracle.com>
Thu, 5 Apr 2007 18:29:12 +0000 (14:29 -0400)
committerDavid Woodhouse <dwmw2@hera.kernel.org>
Thu, 5 Apr 2007 18:29:12 +0000 (14:29 -0400)
Makefile
debug-tree.c
disk-io.c
extent-tree.c
mkfs.c

index d3e7089..50d980a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h \
 objects = 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 \
          inode-map.o \
-
+#
 # if you don't have sparse installed, use ls instead
 CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
                -Wcontext -Wcast-truncate -Wuninitialized -Wshadow -Wundef
@@ -19,13 +19,13 @@ check=sparse $(CHECKFLAGS)
 all: bit-radix-test tester debug-tree quick-test dir-test tags mkfs.btrfs
 
 mkfs.btrfs: $(objects) mkfs.o
-       gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o
+       gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o -luuid
 
 bit-radix-test: $(objects) bit-radix.o
        gcc $(CFLAGS) -o bit-radix-test $(objects) bit-radix.o
 
 debug-tree: $(objects) debug-tree.o
-       gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o
+       gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o -luuid
 
 tester: $(objects) random-test.o
        gcc $(CFLAGS) -o tester $(objects) random-test.o
index fd07969..5de69f2 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <uuid/uuid.h>
 #include "kerncompat.h"
 #include "radix-tree.h"
 #include "ctree.h"
@@ -10,6 +11,7 @@
 int main(int ac, char **av) {
        struct btrfs_super_block super;
        struct btrfs_root *root;
+       char uuidbuf[37];
 
        if (ac != 2) {
                fprintf(stderr, "usage: %s device\n", av[0]);
@@ -34,5 +36,8 @@ int main(int ac, char **av) {
                         root->fs_info->tree_root->node);
        printf("total blocks %Lu\n", btrfs_super_total_blocks(&super));
        printf("blocks used %Lu\n", btrfs_super_blocks_used(&super));
+       uuidbuf[36] = '\0';
+       uuid_unparse(super.fsid, uuidbuf);
+       printf("uuid %s\n", uuidbuf);
        return 0;
 }
index 05637f9..0911d4e 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -21,6 +21,9 @@ static int check_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
        if (root->node && btrfs_header_parentid(&buf->node.header) !=
            btrfs_header_parentid(&root->node->node.header))
                BUG();
+       if (memcmp(root->fs_info->disk_super->fsid, buf->node.header.fsid,
+                  sizeof(buf->node.header.fsid)))
+               BUG();
        return 0;
 }
 
index 06ecbe3..868d4b9 100644 (file)
@@ -461,6 +461,8 @@ struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
        dirty_tree_block(trans, root, buf);
        btrfs_set_header_generation(&buf->node.header,
                                    root->root_key.offset + 1);
+       memcpy(buf->node.header.fsid, root->fs_info->disk_super->fsid,
+              sizeof(buf->node.header.fsid));
        return buf;
 }
 
diff --git a/mkfs.c b/mkfs.c
index bf2a434..9337cc0 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -9,6 +9,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <uuid/uuid.h>
 #include "kerncompat.h"
 #include "radix-tree.h"
 #include "ctree.h"
@@ -99,6 +100,7 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize)
        btrfs_set_super_blocksize(&super, blocksize);
        btrfs_set_super_total_blocks(&super, num_blocks);
        btrfs_set_super_blocks_used(&super, start_block + 5);
+       uuid_generate(super.fsid);
 
        block = malloc(blocksize);
        memset(block, 0, blocksize);
@@ -115,6 +117,8 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize)
        btrfs_set_header_blocknr(&empty_leaf->header, start_block + 1);
        btrfs_set_header_nritems(&empty_leaf->header, 3);
        btrfs_set_header_generation(&empty_leaf->header, 0);
+       memcpy(empty_leaf->header.fsid, super.fsid,
+              sizeof(empty_leaf->header.fsid));
 
        /* create the items for the root tree */
        btrfs_set_root_blocknr(&root_item, start_block + 2);