summaryrefslogtreecommitdiff
path: root/ext4_utils
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2014-01-23 13:13:02 -0800
committerColin Cross <ccross@android.com>2014-01-23 13:43:30 -0800
commit9a2b60b28d866b94b86c7ceb3a9004d28e20b483 (patch)
tree04d372e104b4b280862291d83a679611c05cc680 /ext4_utils
parent782879ab61fe825835a9c6a701f91aa7d305acef (diff)
downloadextras-9a2b60b28d866b94b86c7ceb3a9004d28e20b483.tar.gz
ext4_utils: move superblock parsing to its own compilation unit
Move ext4_parse_sb to its own compilation unit so it can be used from fs_mgr without pulling in all of libext4_utils' dependencies when compiling with ld.bfd. Change-Id: I185352ecea0e0d577b8cdddfd519f2826d631277
Diffstat (limited to 'ext4_utils')
-rw-r--r--ext4_utils/Android.mk3
-rw-r--r--ext4_utils/ext2simg.c2
-rw-r--r--ext4_utils/ext4_sb.c47
-rw-r--r--ext4_utils/ext4_sb.h52
-rw-r--r--ext4_utils/ext4_utils.c17
-rw-r--r--ext4_utils/ext4_utils.h23
-rw-r--r--ext4_utils/ext4fixup.c2
7 files changed, 107 insertions, 39 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/ext2simg.c b/ext4_utils/ext2simg.c
index f75b6c2c..77c3650f 100644
--- a/ext4_utils/ext2simg.c
+++ b/ext4_utils/ext2simg.c
@@ -68,7 +68,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)
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 8c9d9312..2c79da93 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -261,7 +261,7 @@ void ext4_queue_sb(void)
}
}
-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");
@@ -269,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 298fc352..9b5b7c4a 100644
--- a/ext4_utils/ext4_utils.h
+++ b/ext4_utils/ext4_utils.h
@@ -45,7 +45,7 @@ extern "C" {
#define off64_t off_t
#endif
-#include "ext4_kernel_headers.h"
+#include "ext4_sb.h"
extern int force;
@@ -55,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 */
@@ -93,24 +92,6 @@ struct ext2_group_desc {
u16 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 fs_aux_info {
struct ext4_super_block *sb;
struct ext4_super_block **backup_sb;
@@ -156,7 +137,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..7cf1f0ea 100644
--- a/ext4_utils/ext4fixup.c
+++ b/ext4_utils/ext4fixup.c
@@ -203,7 +203,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");