1 /* 2 * Copyright (C) 2010 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 #ifndef _EXT4_UTILS_H_ 18 #define _EXT4_UTILS_H_ 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #include <sys/types.h> 25 #include <unistd.h> 26 27 #include <errno.h> 28 #include <setjmp.h> 29 #include <stdarg.h> 30 #include <stdint.h> 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <string.h> 34 #include <sys/types.h> 35 36 #include "ext4_sb.h" 37 38 extern int force; 39 40 #define EXT4_JNL_BACKUP_BLOCKS 1 41 42 #ifndef __cplusplus 43 #ifndef min /* already defined by windows.h */ 44 #define min(a, b) ((a) < (b) ? (a) : (b)) 45 #endif 46 #endif 47 48 #define DIV_ROUND_UP(x, y) (((x) + (y)-1) / (y)) 49 #define EXT4_ALIGN(x, y) ((y)*DIV_ROUND_UP((x), (y))) 50 51 /* XXX */ 52 #define cpu_to_le32(x) (x) 53 #define cpu_to_le16(x) (x) 54 #define le32_to_cpu(x) (x) 55 #define le16_to_cpu(x) (x) 56 57 #ifdef __LP64__ 58 typedef unsigned long u64; 59 typedef signed long s64; 60 61 #define PRIext4u64 "lu" 62 #else 63 typedef unsigned long long u64; 64 typedef signed long long s64; 65 66 #define PRIext4u64 PRIu64 67 #endif 68 typedef unsigned int u32; 69 typedef unsigned short int u16; 70 typedef unsigned char u8; 71 72 struct block_group_info; 73 struct xattr_list_element; 74 75 struct ext2_group_desc { 76 u64 bg_block_bitmap; 77 u64 bg_inode_bitmap; 78 u64 bg_inode_table; 79 u32 bg_free_blocks_count; 80 u32 bg_free_inodes_count; 81 u32 bg_used_dirs_count; 82 u16 bg_flags; 83 }; 84 85 struct fs_aux_info { 86 struct ext4_super_block* sb; 87 struct ext4_super_block* sb_block; 88 struct ext4_super_block* sb_zero; 89 struct ext4_super_block** backup_sb; 90 struct ext2_group_desc* bg_desc; 91 struct block_group_info* bgs; 92 struct xattr_list_element* xattrs; 93 u32 first_data_block; 94 u64 len_blocks; 95 u32 inode_table_blocks; 96 u32 groups; 97 u32 bg_desc_blocks; 98 u32 default_i_flags; 99 u64 blocks_per_ind; 100 u64 blocks_per_dind; 101 u64 blocks_per_tind; 102 }; 103 104 extern struct fs_info info; 105 extern struct fs_aux_info aux_info; 106 107 extern jmp_buf setjmp_env; 108 109 int bitmap_get_bit(u8* bitmap, u32 bit); // vold 110 u64 get_block_device_size(int fd); // recovery 111 int is_block_device_fd(int fd); // wipe.c 112 u64 get_file_size(int fd); // fs_mgr 113 int ext4_bg_has_super_block(int bg); 114 int read_ext(int fd, int verbose); // vold 115 116 #ifdef __cplusplus 117 } 118 #endif 119 120 #endif 121