From 7900c773815d062deb266f744f95aa76b3573fa3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 23 Jan 2014 12:53:30 -0800 Subject: [PATCH] ext4_utils: refactor kernel headers 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 | 1 - ext4_utils/allocate.h | 2 -- ext4_utils/contents.c | 6 ++-- ext4_utils/ext4_jbd2.h | 53 ------------------------------------ ext4_utils/ext4_kernel_headers.h | 59 ++++++++++++++++++++++++++++++++++++++++ ext4_utils/ext4_utils.c | 3 -- ext4_utils/ext4_utils.h | 35 ++++++++---------------- ext4_utils/extent.c | 2 -- ext4_utils/indirect.c | 2 -- ext4_utils/jbd2.h | 2 +- ext4_utils/xattr.h | 2 +- 11 files changed, 75 insertions(+), 92 deletions(-) delete mode 100644 ext4_utils/ext4_jbd2.h create mode 100644 ext4_utils/ext4_kernel_headers.h diff --git a/ext4_utils/allocate.c b/ext4_utils/allocate.c index c0b2c7eb..09ffa1b4 100644 --- a/ext4_utils/allocate.c +++ b/ext4_utils/allocate.c @@ -16,7 +16,6 @@ #include "ext4_utils.h" #include "allocate.h" -#include "ext4.h" #include diff --git a/ext4_utils/allocate.h b/ext4_utils/allocate.h index 7a3ffed1..a0999e4a 100644 --- a/ext4_utils/allocate.h +++ b/ext4_utils/allocate.h @@ -20,8 +20,6 @@ #define EXT4_ALLOCATE_FAILED (u32)(~0) #include "ext4_utils.h" -#include "ext4.h" -#include "xattr.h" struct block_allocation; diff --git a/ext4_utils/contents.c b/ext4_utils/contents.c index 3abbdc35..80e5692b 100644 --- a/ext4_utils/contents.c +++ b/ext4_utils/contents.c @@ -28,13 +28,11 @@ #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 index d937f5cd..00000000 --- a/ext4_utils/ext4_jbd2.h +++ /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 index 00000000..4b24dce4 --- /dev/null +++ b/ext4_utils/ext4_kernel_headers.h @@ -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 + +#ifdef __BIONIC__ +#include +#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 diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c index d4fbc7c8..3547545c 100644 --- a/ext4_utils/ext4_utils.c +++ b/ext4_utils/ext4_utils.c @@ -41,9 +41,6 @@ #include #endif -#include "ext4.h" -#include "jbd2.h" - int force = 0; struct fs_info info; struct fs_aux_info aux_info; diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h index 083aff56..07f93630 100644 --- a/ext4_utils/ext4_utils.h +++ b/ext4_utils/ext4_utils.h @@ -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 { diff --git a/ext4_utils/extent.c b/ext4_utils/extent.c index 948bf41e..ce58142f 100644 --- a/ext4_utils/extent.c +++ b/ext4_utils/extent.c @@ -15,8 +15,6 @@ */ #include "ext4_utils.h" -#include "ext4.h" -#include "ext4_extents.h" #include "extent.h" #include diff --git a/ext4_utils/indirect.c b/ext4_utils/indirect.c index cd826ac1..b516a8a5 100644 --- a/ext4_utils/indirect.c +++ b/ext4_utils/indirect.c @@ -15,8 +15,6 @@ */ #include "ext4_utils.h" -#include "ext4.h" -#include "ext4_extents.h" #include "indirect.h" #include "allocate.h" diff --git a/ext4_utils/jbd2.h b/ext4_utils/jbd2.h index 1c816417..bac58c2e 100644 --- a/ext4_utils/jbd2.h +++ b/ext4_utils/jbd2.h @@ -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; diff --git a/ext4_utils/xattr.h b/ext4_utils/xattr.h index 60c01cef..0f323fdc 100644 --- a/ext4_utils/xattr.h +++ b/ext4_utils/xattr.h @@ -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 */ -- 2.11.0