OSDN Git Service

ext4_utils: refactor kernel headers
authorColin Cross <ccross@android.com>
Thu, 23 Jan 2014 20:53:30 +0000 (12:53 -0800)
committerColin Cross <ccross@android.com>
Thu, 23 Jan 2014 21:22:36 +0000 (13:22 -0800)
Move the kernel header includes into a single include file that
can deal with getting the kernel int types correct on all
platforms.

Change-Id: Ied3dc6a0f5cbb3ceb686aa3de72f16e10a36462a

ext4_utils/allocate.c
ext4_utils/allocate.h
ext4_utils/contents.c
ext4_utils/ext4_jbd2.h [deleted file]
ext4_utils/ext4_kernel_headers.h [new file with mode: 0644]
ext4_utils/ext4_utils.c
ext4_utils/ext4_utils.h
ext4_utils/extent.c
ext4_utils/indirect.c
ext4_utils/jbd2.h
ext4_utils/xattr.h

index c0b2c7e..09ffa1b 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "ext4_utils.h"
 #include "allocate.h"
-#include "ext4.h"
 
 #include <sparse/sparse.h>
 
index 7a3ffed..a0999e4 100644 (file)
@@ -20,8 +20,6 @@
 #define EXT4_ALLOCATE_FAILED (u32)(~0)
 
 #include "ext4_utils.h"
-#include "ext4.h"
-#include "xattr.h"
 
 struct block_allocation;
 
index 3abbdc3..80e5692 100644 (file)
 #define XATTR_CAPS_SUFFIX "capability"
 
 #include "ext4_utils.h"
-#include "ext4.h"
 #include "make_ext4fs.h"
 #include "allocate.h"
 #include "contents.h"
 #include "extent.h"
 #include "indirect.h"
-#include "xattr.h"
 
 #ifdef USE_MINGW
 #define S_IFLNK 0  /* used by make_link, not needed under mingw */
@@ -330,7 +328,7 @@ static void xattr_assert_sane(struct ext4_xattr_entry *entry)
 static void ext4_xattr_hash_entry(struct ext4_xattr_header *header,
                struct ext4_xattr_entry *entry)
 {
-       __u32 hash = 0;
+       u32 hash = 0;
        char *name = entry->e_name;
        int n;
 
@@ -341,7 +339,7 @@ static void ext4_xattr_hash_entry(struct ext4_xattr_header *header,
        }
 
        if (entry->e_value_block == 0 && entry->e_value_size != 0) {
-               __le32 *value = (__le32 *)((char *)header +
+               u32 *value = (u32 *)((char *)header +
                        le16_to_cpu(entry->e_value_offs));
                for (n = (le32_to_cpu(entry->e_value_size) +
                        EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) {
diff --git a/ext4_utils/ext4_jbd2.h b/ext4_utils/ext4_jbd2.h
deleted file mode 100644 (file)
index d937f5c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _EXT4_JBD2_H
-#define _EXT4_JBD2_H
-
-#include "ext4.h"
-
-#define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal)
-
-#define EXT4_SINGLEDATA_TRANS_BLOCKS(sb)   (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)   ? 27U : 8U)
-
-#define EXT4_XATTR_TRANS_BLOCKS 6U
-
-#define EXT4_DATA_TRANS_BLOCKS(sb) (EXT4_SINGLEDATA_TRANS_BLOCKS(sb) +   EXT4_XATTR_TRANS_BLOCKS - 2 +   EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
-
-#define EXT4_META_TRANS_BLOCKS(sb) (EXT4_XATTR_TRANS_BLOCKS +   EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
-
-#define EXT4_DELETE_TRANS_BLOCKS(sb) (2 * EXT4_DATA_TRANS_BLOCKS(sb) + 64)
-
-#define EXT4_MAX_TRANS_DATA 64U
-
-#define EXT4_RESERVE_TRANS_BLOCKS 12U
-
-#define EXT4_INDEX_EXTRA_TRANS_BLOCKS 8
-
-#define EXT4_QUOTA_TRANS_BLOCKS(sb) 0
-#define EXT4_QUOTA_INIT_BLOCKS(sb) 0
-#define EXT4_QUOTA_DEL_BLOCKS(sb) 0
-#define EXT4_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_TRANS_BLOCKS(sb))
-#define EXT4_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))
-#define EXT4_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb))
-
-#define ext4_journal_get_undo_access(handle, bh)   __ext4_journal_get_undo_access(__func__, (handle), (bh))
-#define ext4_journal_get_write_access(handle, bh)   __ext4_journal_get_write_access(__func__, (handle), (bh))
-#define ext4_forget(handle, is_metadata, inode, bh, block_nr)   __ext4_forget(__func__, (handle), (is_metadata), (inode), (bh),  (block_nr))
-#define ext4_journal_get_create_access(handle, bh)   __ext4_journal_get_create_access(__func__, (handle), (bh))
-#define ext4_handle_dirty_metadata(handle, inode, bh)   __ext4_handle_dirty_metadata(__func__, (handle), (inode), (bh))
-
-#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
-
-#define ext4_journal_stop(handle)   __ext4_journal_stop(__func__, (handle))
-
-#endif
-
diff --git a/ext4_utils/ext4_kernel_headers.h b/ext4_utils/ext4_kernel_headers.h
new file mode 100644 (file)
index 0000000..4b24dce
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _EXT4_UTILS_EXT4_KERNEL_HEADERS_H_
+#define _EXT4_UTILS_EXT4_KERNEL_HEADERS_H_
+
+#include <stdint.h>
+
+#ifdef __BIONIC__
+#include <sys/types.h>
+#else
+#define __le64 uint64_t
+#define __le32 uint32_t
+#define __le16 uint16_t
+
+#define __be64 uint64_t
+#define __be32 uint32_t
+#define __be16 uint16_t
+
+#define __u64 uint64_t
+#define __u32 uint32_t
+#define __u16 uint16_t
+#define __u8 uint8_t
+#endif
+
+#include "ext4.h"
+#include "xattr.h"
+#include "ext4_extents.h"
+#include "jbd2.h"
+
+#ifndef __BIONIC__
+#undef __le64
+#undef __le32
+#undef __le16
+
+#undef __be64
+#undef __be32
+#undef __be16
+
+#undef __u64
+#undef __u32
+#undef __u16
+#undef __u8
+#endif
+
+#endif
index d4fbc7c..3547545 100644 (file)
@@ -41,9 +41,6 @@
 #include <sys/disk.h>
 #endif
 
-#include "ext4.h"
-#include "jbd2.h"
-
 int force = 0;
 struct fs_info info;
 struct fs_aux_info aux_info;
index 083aff5..07f9363 100644 (file)
@@ -45,6 +45,8 @@ extern "C" {
 #define off64_t off_t
 #endif
 
+#include "ext4_kernel_headers.h"
+
 extern int force;
 
 #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
@@ -63,19 +65,6 @@ extern int force;
 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
 #define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
 
-#define __le64 u64
-#define __le32 u32
-#define __le16 u16
-
-#define __be64 u64
-#define __be32 u32
-#define __be16 u16
-
-#define __u64 u64
-#define __u32 u32
-#define __u16 u16
-#define __u8 u8
-
 /* XXX */
 #define cpu_to_le32(x) (x)
 #define cpu_to_le16(x) (x)
@@ -92,16 +81,16 @@ struct block_group_info;
 struct xattr_list_element;
 
 struct ext2_group_desc {
-       __le32 bg_block_bitmap;
-       __le32 bg_inode_bitmap;
-       __le32 bg_inode_table;
-       __le16 bg_free_blocks_count;
-       __le16 bg_free_inodes_count;
-       __le16 bg_used_dirs_count;
-       __le16 bg_flags;
-       __le32 bg_reserved[2];
-       __le16 bg_reserved16;
-       __le16 bg_checksum;
+       u32 bg_block_bitmap;
+       u32 bg_inode_bitmap;
+       u32 bg_inode_table;
+       u16 bg_free_blocks_count;
+       u16 bg_free_inodes_count;
+       u16 bg_used_dirs_count;
+       u16 bg_flags;
+       u32 bg_reserved[2];
+       u16 bg_reserved16;
+       u16 bg_checksum;
 };
 
 struct fs_info {
index 948bf41..ce58142 100644 (file)
@@ -15,8 +15,6 @@
  */
 
 #include "ext4_utils.h"
-#include "ext4.h"
-#include "ext4_extents.h"
 #include "extent.h"
 
 #include <sparse/sparse.h>
index cd826ac..b516a8a 100644 (file)
@@ -15,8 +15,6 @@
  */
 
 #include "ext4_utils.h"
-#include "ext4.h"
-#include "ext4_extents.h"
 #include "indirect.h"
 #include "allocate.h"
 
index 1c81641..bac58c2 100644 (file)
@@ -46,7 +46,7 @@ typedef struct journal_header_s
 
 #define JBD2_CRC32_CHKSUM_SIZE 4
 
-#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32))
+#define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32))
 
 struct commit_header {
  __be32 h_magic;
index 60c01ce..0f323fd 100644 (file)
@@ -40,6 +40,6 @@ struct ext4_xattr_entry {
      (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
 #define EXT4_XATTR_SIZE(size) \
     (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
-#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
+#define IS_LAST_ENTRY(entry) (*(uint32_t *)(entry) == 0)
 
 #endif /* !_SYSTEM_EXTRAS_EXT4_UTILS_XATTR_H */