1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <errno.h>
18 
19 #include "ext4_sb.h"
20 
ext4_parse_sb(struct ext4_super_block * sb,struct fs_info * info)21 int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info)
22 {
23 	uint64_t len_blocks;
24 
25         if (sb->s_magic != EXT4_SUPER_MAGIC)
26                 return -EINVAL;
27 
28         if ((sb->s_state & EXT4_VALID_FS) != EXT4_VALID_FS)
29                 return -EINVAL;
30 
31 	info->block_size = 1024 << sb->s_log_block_size;
32 	info->blocks_per_group = sb->s_blocks_per_group;
33 	info->inodes_per_group = sb->s_inodes_per_group;
34 	info->inode_size = sb->s_inode_size;
35 	info->inodes = sb->s_inodes_count;
36 	info->feat_ro_compat = sb->s_feature_ro_compat;
37 	info->feat_compat = sb->s_feature_compat;
38 	info->feat_incompat = sb->s_feature_incompat;
39 	info->bg_desc_reserve_blocks = sb->s_reserved_gdt_blocks;
40 	info->label = sb->s_volume_name;
41 
42 	len_blocks = ((uint64_t)sb->s_blocks_count_hi << 32) +
43                 sb->s_blocks_count_lo;
44 	info->len = (uint64_t)info->block_size * len_blocks;
45 
46 	return 0;
47 }
48