From 84e9d08a4bd72f106c1d97823c76410ae5076420 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Thu, 7 Jun 2007 22:12:21 -0400 Subject: endian fixes, makefile fixes --- Makefile | 49 +++++++++++++++++++++++++++---------------------- bit-radix.c | 4 +--- ctree.h | 10 ++++++++++ dir-test.c | 4 ++-- kerncompat.h | 37 +++++++++++++++++++++++++++---------- mkfs.c | 6 +++--- 6 files changed, 70 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 2ca356f2..92caf10a 100644 --- a/Makefile +++ b/Makefile @@ -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) - 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 diff --git a/bit-radix.c b/bit-radix.c index 7da97ce7..cd9928a3 100644 --- a/bit-radix.c +++ b/bit-radix.c @@ -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; diff --git a/ctree.h b/ctree.h index 68edbaa6..9240fef5 100644 --- a/ctree.h +++ b/ctree.h @@ -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 diff --git a/dir-test.c b/dir-test.c index cdef7169..03dbfa14 100644 --- a/dir-test.c +++ b/dir-test.c @@ -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; diff --git a/kerncompat.h b/kerncompat.h index c706f551..28704658 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -1,16 +1,22 @@ #ifndef __KERNCOMPAT #define __KERNCOMPAT + +#include +#include +#include +#include +#include + #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 +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 -#include -#include 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 diff --git a/mkfs.c b/mkfs.c index 1d5c0d6c..14b1b898 100644 --- a/mkfs.c +++ b/mkfs.c @@ -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); -- cgit v1.2.3