CC=gcc
CFLAGS = -O2 -g -Wall -fno-strict-aliasing -Werror
-headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h \
- transaction.h ioctl.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 \
-Wuninitialized -Wshadow -Wundef
-check=sparse $(CHECKFLAGS)
-#check=ls
+
+progs = btrfsctl btrfsck mkfs.btrfs debug-tree
+
+# make C=1 to enable sparse
+ifdef C
+ check=sparse $(CHECKFLAGS)
+else
+ check=ls
+endif
.c.o:
$(check) $<
$(CC) $(CFLAGS) -c $<
-all: tester debug-tree quick-test dir-test mkfs.btrfs \
- btrfsctl btrfsck
-btrfsctl: ioctl.h btrfsctl.o $(headers)
+all: $(progs)
+
+$(progs): depend
+
+depend:
+ @$(CC) -MM $(ALL_CFLAGS) *.c 1> .depend
+
+btrfsctl: btrfsctl.o
gcc $(CFLAGS) -o btrfsctl btrfsctl.o
-btrfsck: btrfsck.o $(headers) bit-radix.o
+btrfsck: $(objects) btrfsck.o bit-radix.o
gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) bit-radix.o
-mkfs.btrfs: $(objects) mkfs.o $(headers)
+mkfs.btrfs: $(objects) mkfs.o
gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o -luuid
-bit-radix-test: $(objects) bit-radix.o $(headers)
- gcc $(CFLAGS) -o bit-radix-test $(objects) bit-radix.o
-
-debug-tree: $(objects) debug-tree.o $(headers)
+debug-tree: $(objects) debug-tree.o
gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o -luuid
-tester: $(objects) random-test.o $(headers)
- gcc $(CFLAGS) -o tester $(objects) random-test.o
-
-dir-test: $(objects) dir-test.o $(headers)
+dir-test: $(objects) dir-test.o
gcc $(CFLAGS) -o dir-test $(objects) dir-test.o
-quick-test: $(objects) quick-test.o $(headers)
- gcc $(CFLAGS) -o quick-test $(objects) quick-test.o
-$(objects): $(headers)
+quick-test: $(objects) quick-test.o
+ gcc $(CFLAGS) -o quick-test $(objects) quick-test.o
clean :
- rm debug-tree mkfs.btrfs btrfsctl btrfsck *.o
+ rm -f $(progs) cscope.out *.o .depend
+ifneq ($(wildcard .depend),)
+include .depend
+endif
{
int num = 0;
-#if BITS_PER_LONG == 64
- if ((word & 0xffffffff) == 0) {
+ if (sizeof(long) == 8 && (word & 0xffffffff) == 0) {
num += 32;
word >>= 32;
}
-#endif
if ((word & 0xffff) == 0) {
num += 16;
word >>= 16;
/* 32 bytes in various csum fields */
#define BTRFS_CSUM_SIZE 32
+#define BTRFS_FT_UNKNOWN 0
+#define BTRFS_FT_REG_FILE 1
+#define BTRFS_FT_DIR 2
+#define BTRFS_FT_CHRDEV 3
+#define BTRFS_FT_BLKDEV 4
+#define BTRFS_FT_FIFO 5
+#define BTRFS_FT_SOCK 6
+#define BTRFS_FT_SYMLINK 7
+#define BTRFS_FT_MAX 8
+
/*
* the key defines the order in the tree, and so it also defines (optimal)
* block layout. objectid corresonds to the inode number. The flags
if (ret)
goto error;
ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid,
- &inode_map, 1);
+ &inode_map, BTRFS_FT_UNKNOWN);
if (ret)
goto error;
btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
key.offset = 0;
ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid,
- &key, 1);
+ &key, BTRFS_FT_UNKNOWN);
if (ret != -EEXIST) {
printf("insert on %s gave us %d\n", buf, ret);
return 1;
#ifndef __KERNCOMPAT
#define __KERNCOMPAT
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <endian.h>
+#include <byteswap.h>
+
#define gfp_t int
#define get_cpu_var(p) (p)
#define __get_cpu_var(p) (p)
-#define BITS_PER_LONG 64
+#define BITS_PER_LONG (sizeof(long) * 8)
#define __GFP_BITS_SHIFT 20
#define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1))
#define GFP_KERNEL 0
#define GFP_NOFS 0
#define __read_mostly
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define PAGE_SHIFT 12
#define ULONG_MAX (~0UL)
#define BUG() abort()
#ifdef __CHECKER__
#define __bitwise__
#endif
+#ifndef __CHECKER__
+#include <asm/types.h>
+typedef __u32 u32;
+typedef __u64 u64;
+typedef __u16 u16;
+typedef __u8 u8;
+#else
typedef unsigned int u32;
-typedef u32 __u32;
+typedef unsigned int __u32;
typedef unsigned long long u64;
typedef unsigned char u8;
typedef unsigned short u16;
+#endif
-typedef unsigned long pgoff_t;
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
struct vma_shared { int prio_tree_node; };
struct vm_area_struct {
unsigned long vm_end;
struct vma_shared shared;
};
-
struct page {
unsigned long index;
};
#define ENOMEM 5
#define EEXIST 6
+#ifdef __CHECKER__
#define __CHECK_ENDIAN__
-#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
typedef u64 __bitwise __le64;
typedef u64 __bitwise __be64;
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
+#define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
+#define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
+#define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
+#define cpu_to_le16(x) ((__force __le16)(u16)(bswap_16(x)))
+#define le16_to_cpu(x) ((__force u16)(__le16)(bswap_16(x)))
+#else
#define cpu_to_le64(x) ((__force __le64)(u64)(x))
#define le64_to_cpu(x) ((__force u64)(__le64)(x))
#define cpu_to_le32(x) ((__force __le32)(u32)(x))
#define cpu_to_le16(x) ((__force __le16)(u16)(x))
#define le16_to_cpu(x) ((__force u16)(__le16)(x))
#endif
+#endif
if (ret)
goto error;
ret = btrfs_insert_dir_item(trans, root, buf, 1, objectid,
- &inode_map, 1);
+ &inode_map, BTRFS_FT_DIR);
if (ret)
goto error;
ret = btrfs_insert_dir_item(trans, root, buf, 2, objectid,
- &inode_map, 1);
+ &inode_map, BTRFS_FT_DIR);
if (ret)
goto error;
btrfs_set_root_dirid(&root->root_item, objectid);
ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
"default", strlen("default"),
btrfs_super_root_dir(root->fs_info->disk_super),
- &location, 1);
+ &location, BTRFS_FT_DIR);
if (ret)
goto err;
btrfs_commit_transaction(trans, root, root->fs_info->disk_super);