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_
21 #define _FILE_OFFSET_BITS 64
22 #define _LARGEFILE64_SOURCE
23 #include <sys/types.h>
26 #include <sys/types.h>
33 #if defined(__APPLE__) && defined(__MACH__)
39 extern void* __mmap2(void *, size_t, int, int, int, off_t);
40 static inline void *mmap64(void *addr, size_t length, int prot, int flags,
41 int fd, off64_t offset)
43 return __mmap2(addr, length, prot, flags, fd, offset >> 12);
49 #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
50 #define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) exit(EXIT_FAILURE); } while (0)
51 #define error_errno(s, args...) error(s ": %s", ##args, strerror(errno))
52 #define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); exit(EXIT_FAILURE); } while (0)
53 #define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno))
55 #define EXT4_SUPER_MAGIC 0xEF53
56 #define EXT4_JNL_BACKUP_BLOCKS 1
58 #define min(a, b) ((a) < (b) ? (a) : (b))
60 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
61 #define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
76 typedef unsigned long long u64;
77 typedef unsigned int u32;
78 typedef unsigned short int u16;
79 typedef unsigned char u8;
81 struct block_group_info;
83 struct ext2_group_desc {
84 __le32 bg_block_bitmap;
85 __le32 bg_inode_bitmap;
86 __le32 bg_inode_table;
87 __le16 bg_free_blocks_count;
88 __le16 bg_free_inodes_count;
89 __le16 bg_used_dirs_count;
91 __le32 bg_reserved[3];
105 u32 bg_desc_reserve_blocks;
111 struct ext4_super_block *sb;
112 struct ext2_group_desc *bg_desc;
113 struct block_group_info *bgs;
114 u32 first_data_block;
116 u32 inode_table_blocks;
125 extern struct fs_info info;
126 extern struct fs_aux_info aux_info;
128 static inline int log_2(int j)
132 for (i = 0; j > 0; i++)
138 int ext4_bg_has_super_block(int bg);
139 void write_ext4_image(const char *filename, int gz, int sparse, int crc);
140 void ext4_create_fs_aux_info(void);
141 void ext4_free_fs_aux_info(void);
142 void ext4_fill_in_sb(void);
143 void ext4_create_resize_inode(void);
144 void ext4_create_journal_inode(void);
145 void ext4_update_free(void);
146 void ext4_queue_sb(void);
147 u64 get_file_size(const char *filename);
148 u64 parse_num(const char *arg);
149 void ext4_parse_sb(struct ext4_super_block *sb);