diff options
author | Keun-young Park <keunyoung@google.com> | 2017-07-21 20:11:52 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-21 20:11:52 +0000 |
commit | bc4c5032fc3b6554016710333ec7bb4a75f028ec (patch) | |
tree | 4dbcc8787f104f778e38ede036937b9e2dbc8e67 /fs_mgr | |
parent | 3f531ac5cfd04d98cd519b119179752680ddc78a (diff) | |
parent | 9dd1a12b1ed822127b0f24282c547e551dd99603 (diff) | |
download | system_core-bc4c5032fc3b6554016710333ec7bb4a75f028ec.tar.gz system_core-bc4c5032fc3b6554016710333ec7bb4a75f028ec.tar.bz2 system_core-bc4c5032fc3b6554016710333ec7bb4a75f028ec.zip |
Merge "fs_mgr:Add filter condition to make sure that the super block is correct."
am: 9dd1a12b1e
Change-Id: I8947564ee32cd90ea8f3a7c986426b9c3dbd70af
Diffstat (limited to 'fs_mgr')
-rw-r--r-- | fs_mgr/fs_mgr.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index ff9b84f7b..874189a80 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -249,6 +249,13 @@ static ext4_fsblk_t ext4_r_blocks_count(const struct ext4_super_block* es) { le32_to_cpu(es->s_r_blocks_count_lo); } +static bool is_ext4_superblock_valid(const struct ext4_super_block* es) { + if (es->s_magic != EXT4_SUPER_MAGIC) return false; + if (es->s_rev_level != EXT4_DYNAMIC_REV && es->s_rev_level != EXT4_GOOD_OLD_REV) return false; + if (EXT4_INODES_PER_GROUP(es) == 0) return false; + return true; +} + // Read the primary superblock from an ext4 filesystem. On failure return // false. If it's not an ext4 filesystem, also set FS_STAT_EXT4_INVALID_MAGIC. static bool read_ext4_superblock(const char* blk_device, struct ext4_super_block* sb, int* fs_stat) { @@ -264,9 +271,8 @@ static bool read_ext4_superblock(const char* blk_device, struct ext4_super_block return false; } - if (sb->s_magic != EXT4_SUPER_MAGIC) { - LINFO << "Invalid ext4 magic:0x" << std::hex << sb->s_magic << " " - << "on '" << blk_device << "'"; + if (!is_ext4_superblock_valid(sb)) { + LINFO << "Invalid ext4 superblock on '" << blk_device << "'"; // not a valid fs, tune2fs, fsck, and mount will all fail. *fs_stat |= FS_STAT_EXT4_INVALID_MAGIC; return false; |