master
Chris Mason 2007-04-05 14:29:12 -04:00 committed by David Woodhouse
parent b6414c8ee2
commit d785b7d058
5 changed files with 17 additions and 3 deletions

View File

@ -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 \ 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 \ root-tree.o dir-item.o hash.o file-item.o inode-item.o \
inode-map.o \ inode-map.o \
#
# if you don't have sparse installed, use ls instead # if you don't have sparse installed, use ls instead
CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
-Wcontext -Wcast-truncate -Wuninitialized -Wshadow -Wundef -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 all: bit-radix-test tester debug-tree quick-test dir-test tags mkfs.btrfs
mkfs.btrfs: $(objects) mkfs.o 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 bit-radix-test: $(objects) bit-radix.o
gcc $(CFLAGS) -o bit-radix-test $(objects) bit-radix.o gcc $(CFLAGS) -o bit-radix-test $(objects) bit-radix.o
debug-tree: $(objects) debug-tree.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 tester: $(objects) random-test.o
gcc $(CFLAGS) -o tester $(objects) random-test.o gcc $(CFLAGS) -o tester $(objects) random-test.o

View File

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <uuid/uuid.h>
#include "kerncompat.h" #include "kerncompat.h"
#include "radix-tree.h" #include "radix-tree.h"
#include "ctree.h" #include "ctree.h"
@ -10,6 +11,7 @@
int main(int ac, char **av) { int main(int ac, char **av) {
struct btrfs_super_block super; struct btrfs_super_block super;
struct btrfs_root *root; struct btrfs_root *root;
char uuidbuf[37];
if (ac != 2) { if (ac != 2) {
fprintf(stderr, "usage: %s device\n", av[0]); fprintf(stderr, "usage: %s device\n", av[0]);
@ -34,5 +36,8 @@ int main(int ac, char **av) {
root->fs_info->tree_root->node); root->fs_info->tree_root->node);
printf("total blocks %Lu\n", btrfs_super_total_blocks(&super)); printf("total blocks %Lu\n", btrfs_super_total_blocks(&super));
printf("blocks used %Lu\n", btrfs_super_blocks_used(&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; return 0;
} }

View File

@ -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) != if (root->node && btrfs_header_parentid(&buf->node.header) !=
btrfs_header_parentid(&root->node->node.header)) btrfs_header_parentid(&root->node->node.header))
BUG(); BUG();
if (memcmp(root->fs_info->disk_super->fsid, buf->node.header.fsid,
sizeof(buf->node.header.fsid)))
BUG();
return 0; return 0;
} }

View File

@ -461,6 +461,8 @@ struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
dirty_tree_block(trans, root, buf); dirty_tree_block(trans, root, buf);
btrfs_set_header_generation(&buf->node.header, btrfs_set_header_generation(&buf->node.header,
root->root_key.offset + 1); root->root_key.offset + 1);
memcpy(buf->node.header.fsid, root->fs_info->disk_super->fsid,
sizeof(buf->node.header.fsid));
return buf; return buf;
} }

4
mkfs.c
View File

@ -9,6 +9,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <uuid/uuid.h>
#include "kerncompat.h" #include "kerncompat.h"
#include "radix-tree.h" #include "radix-tree.h"
#include "ctree.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_blocksize(&super, blocksize);
btrfs_set_super_total_blocks(&super, num_blocks); btrfs_set_super_total_blocks(&super, num_blocks);
btrfs_set_super_blocks_used(&super, start_block + 5); btrfs_set_super_blocks_used(&super, start_block + 5);
uuid_generate(super.fsid);
block = malloc(blocksize); block = malloc(blocksize);
memset(block, 0, 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_blocknr(&empty_leaf->header, start_block + 1);
btrfs_set_header_nritems(&empty_leaf->header, 3); btrfs_set_header_nritems(&empty_leaf->header, 3);
btrfs_set_header_generation(&empty_leaf->header, 0); 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 */ /* create the items for the root tree */
btrfs_set_root_blocknr(&root_item, start_block + 2); btrfs_set_root_blocknr(&root_item, start_block + 2);