2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _EXT4_UTILS_H_
18 #define _EXT4_UTILS_H_
20 #include <sys/types.h>
29 #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
30 #define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) exit(EXIT_FAILURE); } while (0)
31 #define error_errno(s) error(s ": %s", strerror(errno))
32 #define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); exit(EXIT_FAILURE); } while (0)
33 #define critical_error_errno(s) critical_error(s ": %s", strerror(errno))
35 #define EXT4_SUPER_MAGIC 0xEF53
36 #define EXT4_JNL_BACKUP_BLOCKS 1
38 #define min(a, b) ((a) < (b) ? (a) : (b))
40 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
41 #define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
56 typedef unsigned long long u64;
57 typedef unsigned int u32;
58 typedef unsigned short int u16;
59 typedef unsigned char u8;
61 struct block_group_info;
63 struct ext2_group_desc {
64 __le32 bg_block_bitmap;
65 __le32 bg_inode_bitmap;
66 __le32 bg_inode_table;
67 __le16 bg_free_blocks_count;
68 __le16 bg_free_inodes_count;
69 __le16 bg_used_dirs_count;
71 __le32 bg_reserved[3];
85 u32 bg_desc_reserve_blocks;
91 struct ext4_super_block *sb;
92 struct ext2_group_desc *bg_desc;
93 struct block_group_info *bgs;
96 u32 inode_table_blocks;
105 extern struct fs_info info;
106 extern struct fs_aux_info aux_info;
108 static inline int log_2(int j)
112 for (i = 0; j > 0; i++)
118 int ext4_bg_has_super_block(int bg);
119 void write_ext4_image(const char *filename, int gz, int sparse);
120 void ext4_create_fs_aux_info(void);
121 void ext4_free_fs_aux_info(void);
122 void ext4_fill_in_sb(void);
123 void ext4_create_resize_inode(void);
124 void ext4_create_journal_inode(void);
125 void ext4_update_free(void);
126 u64 get_file_size(const char *filename);
127 u64 parse_num(const char *arg);