Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e635a27 authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse
Browse files

Btrfs: initial move to kernel module land

parent 1261ec42
Loading
Loading
Loading
Loading
+15 −35
Original line number Diff line number Diff line
CC=gcc
CFLAGS = -g -Wall -Werror
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h \
	  transaction.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 \
ifneq ($(KERNELRELEASE),)
# kbuild part of makefile

# 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
check=sparse $(CHECKFLAGS)
#check=ls
obj-m  := btrfs.o
btrfs-y := super.o

.c.o:
	$(check) $<
	$(CC) $(CFLAGS) -c $<
#btrfs-y := 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 \

all: tester debug-tree quick-test dir-test tags mkfs.btrfs

mkfs.btrfs: $(objects) mkfs.o
	gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o

debug-tree: $(objects) debug-tree.o
	gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o

tester: $(objects) random-test.o
	gcc $(CFLAGS) -o tester $(objects) random-test.o

dir-test: $(objects) dir-test.o
	gcc $(CFLAGS) -o dir-test $(objects) dir-test.o
quick-test: $(objects) quick-test.o
	gcc $(CFLAGS) -o quick-test $(objects) quick-test.o

$(objects): $(headers)

clean :
	rm debug-tree tester *.o
else

# Normal Makefile

KERNELDIR := /lib/modules/`uname -r`/build
all::
	$(MAKE) -C $(KERNELDIR) M=`pwd` modules
clean::
	rm *.o btrfs.ko
endif
+1 −5
Original line number Diff line number Diff line
#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 "print-tree.h"

static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
		      *root, struct btrfs_path *path, int level);
+12 −3
Original line number Diff line number Diff line
#ifndef __BTRFS__
#define __BTRFS__

#include "list.h"
#include "kerncompat.h"

struct btrfs_trans_handle;

#define BTRFS_MAGIC "_BtRfS_M"
@@ -75,6 +72,7 @@ struct btrfs_super_block {
	__le64 root;
	__le64 total_blocks;
	__le64 blocks_used;
	__le64 root_dir_objectid;
} __attribute__ ((__packed__));

/*
@@ -693,6 +691,17 @@ static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
	s->blocksize = cpu_to_le32(val);
}

static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
{
	return le64_to_cpu(s->root_dir_objectid);
}

static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
					    val)
{
	s->root_dir_objectid = cpu_to_le64(val);
}

static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
{
	return (u8 *)l->items;

fs/btrfs/debug-tree.c

deleted100644 → 0
+0 −38
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>
#include "kerncompat.h"
#include "radix-tree.h"
#include "ctree.h"
#include "disk-io.h"
#include "print-tree.h"
#include "transaction.h"

int main(int ac, char **av) {
	struct btrfs_super_block super;
	struct btrfs_root *root;

	if (ac != 2) {
		fprintf(stderr, "usage: %s device\n", av[0]);
		exit(1);
	}
	radix_tree_init();
	root = open_ctree(av[1], &super);
	if (!root) {
		fprintf(stderr, "unable to open %s\n", av[1]);
		exit(1);
	}
	printf("fs tree\n");
	btrfs_print_tree(root, root->node);
	printf("map tree\n");
	btrfs_print_tree(root->fs_info->extent_root,
			 root->fs_info->extent_root->node);
	printf("inode tree\n");
	btrfs_print_tree(root->fs_info->inode_root,
			 root->fs_info->inode_root->node);
	printf("root tree\n");
	btrfs_print_tree(root->fs_info->tree_root,
			 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));
	return 0;
}
+7 −5
Original line number Diff line number Diff line
#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"
@@ -21,6 +18,11 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
	key.objectid = dir;
	key.flags = 0;
	btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
	if (name_len == 1 && *name == '.')
		key.offset = 1;
	else if (name_len == 2 && name[0] == '.' && name[1] == '.')
		key.offset = 2;
	else
		ret = btrfs_name_hash(name, name_len, &key.offset);
	BUG_ON(ret);
	btrfs_init_path(&path);
Loading