diff options
author | Colin Cross <ccross@android.com> | 2014-01-30 04:00:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-01-30 04:00:05 +0000 |
commit | 74da04349d74ae63f68da6fab560025714209743 (patch) | |
tree | bbce41eca757f15e2058d53e014890f06c0c1341 | |
parent | e35f7fedabf9346d299abe10af25eaf88207a133 (diff) | |
parent | af0723439af552c170425416ee8e35f4f20bbe67 (diff) | |
download | extras-74da04349d74ae63f68da6fab560025714209743.tar.gz |
Merge changes Icaf79989,I185352ec,I5a72147f,Ied3dc6a0
* changes:
ext4_utils: fix build for 64 bit
ext4_utils: move superblock parsing to its own compilation unit
ext4_utils: move sparse file pointer out of fs_info
ext4_utils: refactor kernel headers
-rw-r--r-- | ext4_utils/Android.mk | 3 | ||||
-rw-r--r-- | ext4_utils/allocate.c | 7 | ||||
-rw-r--r-- | ext4_utils/allocate.h | 2 | ||||
-rw-r--r-- | ext4_utils/contents.c | 6 | ||||
-rw-r--r-- | ext4_utils/ext2simg.c | 17 | ||||
-rw-r--r-- | ext4_utils/ext4_jbd2.h | 53 | ||||
-rw-r--r-- | ext4_utils/ext4_kernel_headers.h | 59 | ||||
-rw-r--r-- | ext4_utils/ext4_sb.c | 47 | ||||
-rw-r--r-- | ext4_utils/ext4_sb.h | 52 | ||||
-rw-r--r-- | ext4_utils/ext4_utils.c | 31 | ||||
-rw-r--r-- | ext4_utils/ext4_utils.h | 64 | ||||
-rw-r--r-- | ext4_utils/ext4fixup.c | 7 | ||||
-rw-r--r-- | ext4_utils/extent.c | 19 | ||||
-rw-r--r-- | ext4_utils/indirect.c | 18 | ||||
-rw-r--r-- | ext4_utils/jbd2.h | 2 | ||||
-rw-r--r-- | ext4_utils/make_ext4fs.c | 17 | ||||
-rw-r--r-- | ext4_utils/xattr.h | 2 |
17 files changed, 233 insertions, 173 deletions
diff --git a/ext4_utils/Android.mk b/ext4_utils/Android.mk index 6eba3b17..8cb04eb6 100644 --- a/ext4_utils/Android.mk +++ b/ext4_utils/Android.mk @@ -13,7 +13,8 @@ libext4_utils_src_files := \ uuid.c \ sha1.c \ wipe.c \ - crc16.c + crc16.c \ + ext4_sb.c # # -- All host/targets including windows diff --git a/ext4_utils/allocate.c b/ext4_utils/allocate.c index c0b2c7eb..64924c73 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 <sparse/sparse.h> @@ -181,7 +180,7 @@ static void allocate_bg_inode_table(struct block_group_info *bg) if (bg->inode_table == NULL) critical_error_errno("calloc"); - sparse_file_add_data(info.sparse_file, bg->inode_table, + sparse_file_add_data(ext4_sparse_file, bg->inode_table, aux_info.inode_table_blocks * info.block_size, block); bg->flags &= ~EXT4_BG_INODE_UNINIT; @@ -299,7 +298,7 @@ static void init_bg(struct block_group_info *bg, unsigned int i) u32 block = bg->first_block; if (bg->has_superblock) block += 1 + aux_info.bg_desc_blocks + info.bg_desc_reserve_blocks; - sparse_file_add_data(info.sparse_file, bg->bitmaps, 2 * info.block_size, + sparse_file_add_data(ext4_sparse_file, bg->bitmaps, 2 * info.block_size, block); bg->data_blocks_used = 0; @@ -718,7 +717,7 @@ struct ext4_xattr_header *get_xattr_block_for_inode(struct ext4_inode *inode) inode->i_blocks_lo = cpu_to_le32(le32_to_cpu(inode->i_blocks_lo) + (info.block_size / 512)); inode->i_file_acl_lo = cpu_to_le32(block_num); - int result = sparse_file_add_data(info.sparse_file, block, info.block_size, block_num); + int result = sparse_file_add_data(ext4_sparse_file, block, info.block_size, block_num); if (result != 0) { error("get_xattr: sparse_file_add_data failure %d", result); free(block); 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/ext2simg.c b/ext4_utils/ext2simg.c index 7b63836c..1531f0bb 100644 --- a/ext4_utils/ext2simg.c +++ b/ext4_utils/ext2simg.c @@ -22,6 +22,7 @@ #include <sys/types.h> #include <sys/mman.h> #include <fcntl.h> +#include <inttypes.h> #include <libgen.h> #include <unistd.h> @@ -68,7 +69,7 @@ static int read_ext(int fd) if (ret != sizeof(sb)) critical_error("failed to read all of superblock"); - ext4_parse_sb(&sb); + ext4_parse_sb_info(&sb); ret = lseek64(fd, info.len, SEEK_SET); if (ret < 0) @@ -86,13 +87,13 @@ static int read_ext(int fd) if (verbose) { printf("Found filesystem with parameters:\n"); - printf(" Size: %llu\n", info.len); + printf(" Size: %"PRIu64"\n", info.len); printf(" Block size: %d\n", info.block_size); printf(" Blocks per group: %d\n", info.blocks_per_group); printf(" Inodes per group: %d\n", info.inodes_per_group); printf(" Inode size: %d\n", info.inode_size); printf(" Label: %s\n", info.label); - printf(" Blocks: %llu\n", aux_info.len_blocks); + printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); printf(" Used %d/%d inodes and %d/%d blocks\n", @@ -126,7 +127,7 @@ static int build_sparse_ext(int fd, const char *filename) critical_error("failed to allocate block bitmap"); if (aux_info.first_data_block > 0) - sparse_file_add_file(info.sparse_file, filename, 0, + sparse_file_add_file(ext4_sparse_file, filename, 0, info.block_size * aux_info.first_data_block, 0); for (i = 0; i < aux_info.groups; i++) { @@ -151,7 +152,7 @@ static int build_sparse_ext(int fd, const char *filename) u32 start_block = first_block + start_contiguous_block; u32 len_blocks = block - start_contiguous_block; - sparse_file_add_file(info.sparse_file, filename, + sparse_file_add_file(ext4_sparse_file, filename, (u64)info.block_size * start_block, info.block_size * len_blocks, start_block); start_contiguous_block = -1; @@ -165,7 +166,7 @@ static int build_sparse_ext(int fd, const char *filename) if (start_contiguous_block >= 0) { u32 start_block = first_block + start_contiguous_block; u32 len_blocks = last_block - start_contiguous_block; - sparse_file_add_file(info.sparse_file, filename, + sparse_file_add_file(ext4_sparse_file, filename, (u64)info.block_size * start_block, info.block_size * len_blocks, start_block); } @@ -230,7 +231,7 @@ int main(int argc, char **argv) read_ext(infd); - info.sparse_file = sparse_file_new(info.block_size, info.len); + ext4_sparse_file = sparse_file_new(info.block_size, info.len); build_sparse_ext(infd, in); @@ -249,7 +250,7 @@ int main(int argc, char **argv) write_ext4_image(outfd, gzip, sparse, crc); close(outfd); - sparse_file_destroy(info.sparse_file); + sparse_file_destroy(ext4_sparse_file); return 0; } 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 <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 diff --git a/ext4_utils/ext4_sb.c b/ext4_utils/ext4_sb.c new file mode 100644 index 00000000..1d527a10 --- /dev/null +++ b/ext4_utils/ext4_sb.c @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include <errno.h> + +#include "ext4_sb.h" + +int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info) +{ + uint64_t len_blocks; + + if (sb->s_magic != EXT4_SUPER_MAGIC) + return -EINVAL; + + if ((sb->s_state & EXT4_VALID_FS) != EXT4_VALID_FS) + return -EINVAL; + + info->block_size = 1024 << sb->s_log_block_size; + info->blocks_per_group = sb->s_blocks_per_group; + info->inodes_per_group = sb->s_inodes_per_group; + info->inode_size = sb->s_inode_size; + info->inodes = sb->s_inodes_count; + info->feat_ro_compat = sb->s_feature_ro_compat; + info->feat_compat = sb->s_feature_compat; + info->feat_incompat = sb->s_feature_incompat; + info->bg_desc_reserve_blocks = sb->s_reserved_gdt_blocks; + info->label = sb->s_volume_name; + + len_blocks = ((uint64_t)sb->s_blocks_count_hi << 32) + + sb->s_blocks_count_lo; + info->len = (uint64_t)info->block_size * len_blocks; + + return 0; +} diff --git a/ext4_utils/ext4_sb.h b/ext4_utils/ext4_sb.h new file mode 100644 index 00000000..832fa333 --- /dev/null +++ b/ext4_utils/ext4_sb.h @@ -0,0 +1,52 @@ +/* + * 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_SB_H_ +#define _EXT4_UTILS_EXT4_SB_H_ + +#include "ext4_kernel_headers.h" + +#define EXT4_SUPER_MAGIC 0xEF53 + +#ifdef __cplusplus +extern "C" { +#endif + +struct fs_info { + int64_t len; /* If set to 0, ask the block device for the size, + * if less than 0, reserve that much space at the + * end of the partition, else use the size given. */ + uint32_t block_size; + uint32_t blocks_per_group; + uint32_t inodes_per_group; + uint32_t inode_size; + uint32_t inodes; + uint32_t journal_blocks; + uint16_t feat_ro_compat; + uint16_t feat_compat; + uint16_t feat_incompat; + uint32_t bg_desc_reserve_blocks; + const char *label; + uint8_t no_journal; +}; + +int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c index d4fbc7c8..2c79da93 100644 --- a/ext4_utils/ext4_utils.c +++ b/ext4_utils/ext4_utils.c @@ -41,12 +41,10 @@ #include <sys/disk.h> #endif -#include "ext4.h" -#include "jbd2.h" - int force = 0; struct fs_info info; struct fs_aux_info aux_info; +struct sparse_file *ext4_sparse_file; jmp_buf setjmp_env; @@ -84,7 +82,7 @@ int ext4_bg_has_super_block(int bg) /* Write the filesystem image to a file */ void write_ext4_image(int fd, int gz, int sparse, int crc) { - sparse_file_write(info.sparse_file, fd, gz, sparse, crc); + sparse_file_write(ext4_sparse_file, fd, gz, sparse, crc); } /* Compute the rest of the parameters of the filesystem from the basic info */ @@ -228,10 +226,10 @@ void ext4_fill_in_sb() memcpy(aux_info.backup_sb[i], sb, info.block_size); /* Update the block group nr of this backup superblock */ aux_info.backup_sb[i]->s_block_group_nr = i; - sparse_file_add_data(info.sparse_file, aux_info.backup_sb[i], + sparse_file_add_data(ext4_sparse_file, aux_info.backup_sb[i], info.block_size, group_start_block); } - sparse_file_add_data(info.sparse_file, aux_info.bg_desc, + sparse_file_add_data(ext4_sparse_file, aux_info.bg_desc, aux_info.bg_desc_blocks * info.block_size, group_start_block + 1); header_size = 1 + aux_info.bg_desc_blocks + info.bg_desc_reserve_blocks; @@ -257,13 +255,13 @@ void ext4_queue_sb(void) if (info.block_size > 1024) { u8 *buf = calloc(info.block_size, 1); memcpy(buf + 1024, (u8*)aux_info.sb, 1024); - sparse_file_add_data(info.sparse_file, buf, info.block_size, 0); + sparse_file_add_data(ext4_sparse_file, buf, info.block_size, 0); } else { - sparse_file_add_data(info.sparse_file, aux_info.sb, 1024, 1); + sparse_file_add_data(ext4_sparse_file, aux_info.sb, 1024, 1); } } -void ext4_parse_sb(struct ext4_super_block *sb) +void ext4_parse_sb_info(struct ext4_super_block *sb) { if (sb->s_magic != EXT4_SUPER_MAGIC) error("superblock magic incorrect"); @@ -271,20 +269,7 @@ void ext4_parse_sb(struct ext4_super_block *sb) if ((sb->s_state & EXT4_VALID_FS) != EXT4_VALID_FS) error("filesystem state not valid"); - info.block_size = 1024 << sb->s_log_block_size; - info.blocks_per_group = sb->s_blocks_per_group; - info.inodes_per_group = sb->s_inodes_per_group; - info.inode_size = sb->s_inode_size; - info.inodes = sb->s_inodes_count; - info.feat_ro_compat = sb->s_feature_ro_compat; - info.feat_compat = sb->s_feature_compat; - info.feat_incompat = sb->s_feature_incompat; - info.bg_desc_reserve_blocks = sb->s_reserved_gdt_blocks; - info.label = sb->s_volume_name; - - aux_info.len_blocks = ((u64)sb->s_blocks_count_hi << 32) + - sb->s_blocks_count_lo; - info.len = (u64)info.block_size * aux_info.len_blocks; + ext4_parse_sb(sb, &info); ext4_create_fs_aux_info(); diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h index 083aff56..447d4161 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_sb.h" + extern int force; #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0) @@ -53,7 +55,6 @@ extern int force; #define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); longjmp(setjmp_env, EXIT_FAILURE); } while (0) #define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno)) -#define EXT4_SUPER_MAGIC 0xEF53 #define EXT4_JNL_BACKUP_BLOCKS 1 #ifndef min /* already defined by windows.h */ @@ -63,27 +64,19 @@ 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) #define le32_to_cpu(x) (x) #define le16_to_cpu(x) (x) +#ifdef __LP64__ +typedef unsigned long u64; +typedef signed long s64; +#else typedef unsigned long long u64; typedef signed long long s64; +#endif typedef unsigned int u32; typedef unsigned short int u16; typedef unsigned char u8; @@ -92,36 +85,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; -}; - -struct fs_info { - s64 len; /* If set to 0, ask the block device for the size, - * if less than 0, reserve that much space at the - * end of the partition, else use the size given. */ - u32 block_size; - u32 blocks_per_group; - u32 inodes_per_group; - u32 inode_size; - u32 inodes; - u32 journal_blocks; - u16 feat_ro_compat; - u16 feat_compat; - u16 feat_incompat; - u32 bg_desc_reserve_blocks; - const char *label; - u8 no_journal; - - struct sparse_file *sparse_file; + 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_aux_info { @@ -143,6 +116,7 @@ struct fs_aux_info { extern struct fs_info info; extern struct fs_aux_info aux_info; +extern struct sparse_file *ext4_sparse_file; extern jmp_buf setjmp_env; @@ -168,7 +142,7 @@ void ext4_queue_sb(void); u64 get_block_device_size(int fd); u64 get_file_size(int fd); u64 parse_num(const char *arg); -void ext4_parse_sb(struct ext4_super_block *sb); +void ext4_parse_sb_info(struct ext4_super_block *sb); u16 ext4_crc16(u16 crc_in, const void *buf, int size); typedef void (*fs_config_func_t)(const char *path, int dir, unsigned *uid, unsigned *gid, diff --git a/ext4_utils/ext4fixup.c b/ext4_utils/ext4fixup.c index d271116c..7beeefbe 100644 --- a/ext4_utils/ext4fixup.c +++ b/ext4_utils/ext4fixup.c @@ -25,6 +25,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> +#include <inttypes.h> #include <unistd.h> #ifndef USE_MINGW @@ -203,7 +204,7 @@ static int read_ext(int fd) read_sb(fd, &sb); - ext4_parse_sb(&sb); + ext4_parse_sb_info(&sb); if (info.feat_incompat & EXT4_FEATURE_INCOMPAT_RECOVER) { critical_error("Filesystem needs recovery first, mount and unmount to do that\n"); @@ -235,13 +236,13 @@ static int read_ext(int fd) if (verbose) { printf("Found filesystem with parameters:\n"); - printf(" Size: %llu\n", info.len); + printf(" Size: %"PRIu64"\n", info.len); printf(" Block size: %d\n", info.block_size); printf(" Blocks per group: %d\n", info.blocks_per_group); printf(" Inodes per group: %d\n", info.inodes_per_group); printf(" Inode size: %d\n", info.inode_size); printf(" Label: %s\n", info.label); - printf(" Blocks: %llu\n", aux_info.len_blocks); + printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); printf(" Used %d/%d inodes and %d/%d blocks\n", diff --git a/ext4_utils/extent.c b/ext4_utils/extent.c index 948bf41e..abb30ce4 100644 --- a/ext4_utils/extent.c +++ b/ext4_utils/extent.c @@ -15,12 +15,11 @@ */ #include "ext4_utils.h" -#include "ext4.h" -#include "ext4_extents.h" #include "extent.h" #include <sparse/sparse.h> +#include <inttypes.h> #include <stdlib.h> #include <stdio.h> @@ -43,7 +42,7 @@ static u8 *extent_create_backing(struct block_allocation *alloc, len = min(region_len * info.block_size, backing_len); - sparse_file_add_data(info.sparse_file, ptr, len, region_block); + sparse_file_add_data(ext4_sparse_file, ptr, len, region_block); ptr += len; backing_len -= len; } @@ -65,7 +64,7 @@ static void extent_create_backing_file(struct block_allocation *alloc, len = min(region_len * info.block_size, backing_len); - sparse_file_add_file(info.sparse_file, filename, offset, len, + sparse_file_add_file(ext4_sparse_file, filename, offset, len, region_block); offset += len; backing_len -= len; @@ -125,12 +124,12 @@ static struct block_allocation *do_inode_allocate_extents( if (!data) critical_error_errno("calloc"); - sparse_file_add_data(info.sparse_file, data, info.block_size, + sparse_file_add_data(ext4_sparse_file, data, info.block_size, extent_block); if (((int)(info.block_size - sizeof(struct ext4_extent_header) / sizeof(struct ext4_extent))) < allocation_len) { - error("File size %llu is too big to fit in a single extent block\n", + error("File size %"PRIu64" is too big to fit in a single extent block\n", len); return NULL; } @@ -186,14 +185,14 @@ u8 *inode_allocate_data_extents(struct ext4_inode *inode, u64 len, alloc = do_inode_allocate_extents(inode, len); if (alloc == NULL) { - error("failed to allocate extents for %llu bytes", len); + error("failed to allocate extents for %"PRIu64" bytes", len); return NULL; } if (backing_len) { data = extent_create_backing(alloc, backing_len); if (!data) - error("failed to create backing for %llu bytes", backing_len); + error("failed to create backing for %"PRIu64" bytes", backing_len); } free_alloc(alloc); @@ -210,7 +209,7 @@ void inode_allocate_file_extents(struct ext4_inode *inode, u64 len, alloc = do_inode_allocate_extents(inode, len); if (alloc == NULL) { - error("failed to allocate extents for %llu bytes", len); + error("failed to allocate extents for %"PRIu64" bytes", len); return; } @@ -226,7 +225,7 @@ void inode_allocate_extents(struct ext4_inode *inode, u64 len) alloc = do_inode_allocate_extents(inode, len); if (alloc == NULL) { - error("failed to allocate extents for %llu bytes", len); + error("failed to allocate extents for %"PRIu64" bytes", len); return; } diff --git a/ext4_utils/indirect.c b/ext4_utils/indirect.c index cd826ac1..cd85a434 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" @@ -46,7 +44,7 @@ static u8 *create_backing(struct block_allocation *alloc, len = min(region_len * info.block_size, backing_len); - sparse_file_add_data(info.sparse_file, ptr, len, region_block); + sparse_file_add_data(ext4_sparse_file, ptr, len, region_block); ptr += len; backing_len -= len; } @@ -123,7 +121,7 @@ static void fill_dindirect_block(u32 *dind_block, int len, struct block_allocati dind_block[i] = ind_block; u32 *ind_block_data = calloc(info.block_size, 1); - sparse_file_add_data(info.sparse_file, ind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, ind_block_data, info.block_size, ind_block); int ind_block_len = min((int)aux_info.blocks_per_ind, len); @@ -153,7 +151,7 @@ static void fill_tindirect_block(u32 *tind_block, int len, struct block_allocati tind_block[i] = dind_block; u32 *dind_block_data = calloc(info.block_size, 1); - sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size, dind_block); int dind_block_len = min((int)aux_info.blocks_per_dind, len); @@ -202,7 +200,7 @@ static int inode_attach_indirect_blocks(struct ext4_inode *inode, } u32 *ind_block_data = calloc(info.block_size, 1); - sparse_file_add_data(info.sparse_file, ind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, ind_block_data, info.block_size, ind_block); fill_indirect_block(ind_block_data, len, alloc); @@ -234,7 +232,7 @@ static int inode_attach_dindirect_blocks(struct ext4_inode *inode, } u32 *dind_block_data = calloc(info.block_size, 1); - sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size, dind_block); fill_dindirect_block(dind_block_data, len, alloc); @@ -266,7 +264,7 @@ static int inode_attach_tindirect_blocks(struct ext4_inode *inode, } u32 *tind_block_data = calloc(info.block_size, 1); - sparse_file_add_data(info.sparse_file, tind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, tind_block_data, info.block_size, tind_block); fill_tindirect_block(tind_block_data, len, alloc); @@ -446,13 +444,13 @@ void inode_attach_resize(struct ext4_inode *inode, u32 *dind_block_data = calloc(info.block_size, 1); if (!dind_block_data) critical_error_errno("calloc"); - sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size, + sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size, dind_block); u32 *ind_block_data = calloc(info.block_size, info.bg_desc_reserve_blocks); if (!ind_block_data) critical_error_errno("calloc"); - sparse_file_add_data(info.sparse_file, ind_block_data, + sparse_file_add_data(ext4_sparse_file, ind_block_data, info.block_size * info.bg_desc_reserve_blocks, get_block(alloc, 0)); 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/make_ext4fs.c b/ext4_utils/make_ext4fs.c index c2a26653..0cb5bae9 100644 --- a/ext4_utils/make_ext4fs.c +++ b/ext4_utils/make_ext4fs.c @@ -26,6 +26,7 @@ #include <assert.h> #include <dirent.h> #include <fcntl.h> +#include <inttypes.h> #include <libgen.h> #include <stdio.h> #include <stdlib.h> @@ -362,9 +363,9 @@ void reset_ext4fs_info() { memset(&info, 0, sizeof(info)); memset(&aux_info, 0, sizeof(aux_info)); - if (info.sparse_file) { - sparse_file_destroy(info.sparse_file); - info.sparse_file = NULL; + if (ext4_sparse_file) { + sparse_file_destroy(ext4_sparse_file); + ext4_sparse_file = NULL; } } @@ -531,7 +532,7 @@ int make_ext4fs_internal(int fd, const char *_directory, info.bg_desc_reserve_blocks = compute_bg_desc_reserve_blocks(); printf("Creating filesystem with parameters:\n"); - printf(" Size: %llu\n", info.len); + printf(" Size: %"PRIu64"\n", info.len); printf(" Block size: %d\n", info.block_size); printf(" Blocks per group: %d\n", info.blocks_per_group); printf(" Inodes per group: %d\n", info.inodes_per_group); @@ -541,11 +542,11 @@ int make_ext4fs_internal(int fd, const char *_directory, ext4_create_fs_aux_info(); - printf(" Blocks: %llu\n", aux_info.len_blocks); + printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); - info.sparse_file = sparse_file_new(info.block_size, info.len); + ext4_sparse_file = sparse_file_new(info.block_size, info.len); block_allocator_init(); @@ -607,8 +608,8 @@ int make_ext4fs_internal(int fd, const char *_directory, write_ext4_image(fd, gzip, sparse, crc); - sparse_file_destroy(info.sparse_file); - info.sparse_file = NULL; + sparse_file_destroy(ext4_sparse_file); + ext4_sparse_file = NULL; free(mountpoint); free(directory); 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 */ |