endian fixes, makefile fixes

This commit is contained in:
Chris Mason 2007-06-07 22:12:21 -04:00 committed by David Woodhouse
parent 9b25940b9d
commit 84e9d08a4b
6 changed files with 70 additions and 40 deletions

View File

@ -1,49 +1,54 @@
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)
quick-test: $(objects) quick-test.o
gcc $(CFLAGS) -o quick-test $(objects) quick-test.o
$(objects): $(headers)
clean :
rm debug-tree mkfs.btrfs btrfsctl btrfsck *.o
rm -f $(progs) cscope.out *.o .depend
ifneq ($(wildcard .depend),)
include .depend
endif

View File

@ -86,12 +86,10 @@ static unsigned long __ffs(unsigned long word)
{
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;

10
ctree.h
View File

@ -24,6 +24,16 @@ struct btrfs_trans_handle;
/* 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

View File

@ -77,7 +77,7 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
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;
@ -143,7 +143,7 @@ static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
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;

View File

@ -1,16 +1,22 @@
#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__
@ -21,17 +27,20 @@
#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 {
@ -40,7 +49,6 @@ struct vm_area_struct {
unsigned long vm_end;
struct vma_shared shared;
};
struct page {
unsigned long index;
};
@ -95,8 +103,8 @@ static inline int test_bit(int nr, const volatile unsigned long *addr)
#define ENOMEM 5
#define EEXIST 6
#ifdef __CHECKER__
#define __CHECK_ENDIAN__
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
@ -109,6 +117,14 @@ typedef u32 __bitwise __be32;
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))
@ -116,3 +132,4 @@ typedef u64 __bitwise __be64;
#define cpu_to_le16(x) ((__force __le16)(u16)(x))
#define le16_to_cpu(x) ((__force u16)(__le16)(x))
#endif
#endif

6
mkfs.c
View File

@ -51,11 +51,11 @@ static int __make_root_dir(struct btrfs_trans_handle *trans,
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);
@ -149,7 +149,7 @@ static int make_root_dir(int fd) {
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);