├── MODULE_LICENSE_APACHE2 ├── libsparse ├── Makefile ├── sparse_crc32.h ├── defs.h ├── sparse_file.h ├── sparse_err.c ├── sparse_defs.h ├── output_file.h ├── sparse_format.h ├── backed_block.h ├── sparse_crc32.c ├── sparse.c ├── backed_block.c ├── include │ └── sparse │ │ └── sparse.h ├── sparse_read.c └── output_file.c ├── Makefile ├── sha1.h ├── ext4fixup.h ├── uuid.h ├── canned_fs_config.h ├── wipe.h ├── indirect.h ├── extent.h ├── xattr.h ├── contents.h ├── ext4_kernel_headers.h ├── ext4_sb.h ├── ext4_sb.c ├── uuid.c ├── wipe.c ├── allocate.h ├── crc16.c ├── ext4_extents.h ├── canned_fs_config.c ├── include └── private │ └── android_filesystem_capability.h ├── jbd2.h ├── ext4_utils.h ├── make_ext4fs_main.c ├── extent.c ├── sha1.c ├── NOTICE ├── indirect.c ├── contents.c ├── make_ext4fs.c └── ext4_utils.c /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libsparse/Makefile: -------------------------------------------------------------------------------- 1 | CC ?= gcc 2 | AR ?= ar 3 | 4 | CFLAGS += -Iinclude 5 | 6 | OBJ := \ 7 | backed_block.o \ 8 | output_file.o \ 9 | sparse.o \ 10 | sparse_crc32.o \ 11 | sparse_err.o \ 12 | sparse_read.o 13 | 14 | %.o: %.c 15 | $(CC) $(CFLAGS) -c -o $@ $^ 16 | 17 | libsparse.a: $(OBJ) 18 | $(AR) rcs $@ $^ 19 | 20 | clean: 21 | rm -f $(OBJ) libsparse.a 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC ?= gcc 2 | CFLAGS += -Iinclude -Ilibsparse/include 3 | 4 | ifeq ($(STATIC),1) 5 | ZLIB := -Wl,-Bstatic -lz -Wl,-Bdynamic 6 | else 7 | ZLIB := -lz 8 | endif 9 | 10 | OBJ := \ 11 | allocate.o \ 12 | canned_fs_config.o \ 13 | contents.o \ 14 | crc16.o \ 15 | ext4fixup.o \ 16 | ext4_sb.o \ 17 | ext4_utils.o \ 18 | extent.o \ 19 | indirect.o \ 20 | make_ext4fs_main.o \ 21 | make_ext4fs.o \ 22 | sha1.o \ 23 | uuid.o \ 24 | wipe.o 25 | 26 | %.o: %.c 27 | $(CC) $(CFLAGS) -c -o $@ $^ 28 | 29 | make_ext4fs: $(OBJ) libsparse/libsparse.a 30 | $(CC) $(LDFLAGS) -o $@ $^ $(ZLIB) 31 | 32 | libsparse/libsparse.a: 33 | $(MAKE) -C libsparse/ libsparse.a 34 | 35 | clean: 36 | $(MAKE) -C libsparse/ clean 37 | rm -f $(OBJ) make_ext4fs 38 | -------------------------------------------------------------------------------- /libsparse/sparse_crc32.h: -------------------------------------------------------------------------------- 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 | #include 18 | 19 | uint32_t sparse_crc32(uint32_t crc, const void *buf, size_t size); 20 | 21 | -------------------------------------------------------------------------------- /sha1.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: sha1.h,v 1.13 2005/12/26 18:41:36 perry Exp $ */ 2 | 3 | /* 4 | * SHA-1 in C 5 | * By Steve Reid 6 | * 100% Public Domain 7 | */ 8 | 9 | #ifndef _SYS_SHA1_H_ 10 | #define _SYS_SHA1_H_ 11 | 12 | #include 13 | #include 14 | 15 | #define SHA1_DIGEST_LENGTH 20 16 | #define SHA1_DIGEST_STRING_LENGTH 41 17 | 18 | typedef struct { 19 | uint32_t state[5]; 20 | uint32_t count[2]; 21 | u_char buffer[64]; 22 | } SHA1_CTX; 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | void SHA1Transform(uint32_t[5], const u_char[64]); 28 | void SHA1Init(SHA1_CTX *); 29 | void SHA1Update(SHA1_CTX *, const u_char *, u_int); 30 | void SHA1Final(u_char[SHA1_DIGEST_LENGTH], SHA1_CTX *); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* _SYS_SHA1_H_ */ 36 | -------------------------------------------------------------------------------- /ext4fixup.h: -------------------------------------------------------------------------------- 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 | int ext4fixup(char *fsdev); 18 | int ext4fixup_internal(char *fsdev, int v_flag, int n_flag, 19 | int stop_phase, int stop_loc, int stop_count); 20 | 21 | -------------------------------------------------------------------------------- /libsparse/defs.h: -------------------------------------------------------------------------------- 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 | #ifndef _LIBSPARSE_DEFS_H_ 18 | 19 | #ifndef __unused 20 | #define __unused __attribute__((__unused__)) 21 | #endif 22 | 23 | #endif /* _LIBSPARSE_DEFS_H_ */ 24 | -------------------------------------------------------------------------------- /uuid.h: -------------------------------------------------------------------------------- 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 _UUID_H_ 18 | #define _UUID_H_ 19 | 20 | #include "ext4_utils.h" 21 | 22 | void generate_uuid(const char *namespace, const char *name, u8 result[16]); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /canned_fs_config.h: -------------------------------------------------------------------------------- 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 | #ifndef _CANNED_FS_CONFIG_H 18 | #define _CANNED_FS_CONFIG_H 19 | 20 | #include 21 | 22 | int load_canned_fs_config(const char* fn); 23 | int canned_fs_config(const char* path, int dir, 24 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libsparse/sparse_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 _LIBSPARSE_SPARSE_FILE_H_ 18 | #define _LIBSPARSE_SPARSE_FILE_H_ 19 | 20 | #include 21 | 22 | struct sparse_file { 23 | unsigned int block_size; 24 | int64_t len; 25 | bool verbose; 26 | 27 | struct backed_block_list *backed_block_list; 28 | struct output_file *out; 29 | }; 30 | 31 | 32 | #endif /* _LIBSPARSE_SPARSE_FILE_H_ */ 33 | -------------------------------------------------------------------------------- /wipe.h: -------------------------------------------------------------------------------- 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 _WIPE_H_ 18 | #define _WIPE_H_ 19 | 20 | #include "ext4_utils.h" 21 | 22 | /* Set WIPE_IS_SUPPORTED to 1 if the current platform supports 23 | * wiping of block devices. 0 otherwise. For now, only Linux does. 24 | */ 25 | #ifdef __linux__ 26 | # define WIPE_IS_SUPPORTED 1 27 | #else 28 | # define WIPE_IS_SUPPORTED 0 29 | #endif 30 | 31 | int wipe_block_device(int fd, s64 len); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /indirect.h: -------------------------------------------------------------------------------- 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 _INDIRECT_H_ 18 | #define _INDIRECT_H_ 19 | 20 | #include "allocate.h" 21 | 22 | void inode_allocate_indirect(struct ext4_inode *inode, unsigned long len); 23 | u8 *inode_allocate_data_indirect(struct ext4_inode *inode, unsigned long len, 24 | unsigned long backing_len); 25 | void inode_attach_resize(struct ext4_inode *inode, 26 | struct block_allocation *alloc); 27 | void free_indirect_blocks(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /extent.h: -------------------------------------------------------------------------------- 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 _EXTENT_H_ 18 | #define _EXTENT_H_ 19 | 20 | #include "allocate.h" 21 | #include "ext4_utils.h" 22 | 23 | void inode_allocate_extents(struct ext4_inode *inode, u64 len); 24 | struct block_allocation* inode_allocate_file_extents( 25 | struct ext4_inode *inode, u64 len, const char *filename); 26 | u8 *inode_allocate_data_extents(struct ext4_inode *inode, u64 len, 27 | u64 backing_len); 28 | void free_extent_blocks(void); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libsparse/sparse_err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void sparse_default_print(const char *fmt, ...) 24 | { 25 | va_list argp; 26 | 27 | va_start(argp, fmt); 28 | vfprintf(stderr, fmt, argp); 29 | va_end(argp); 30 | } 31 | 32 | void (*sparse_print_error)(const char *fmt, ...) = sparse_default_print; 33 | void (*sparse_print_verbose)(const char *fmt, ...) = sparse_default_print; 34 | -------------------------------------------------------------------------------- /xattr.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef _SYSTEM_EXTRAS_EXT4_UTILS_XATTR_H 4 | #define _SYSTEM_EXTRAS_EXT4_UTILS_XATTR_H 1 5 | 6 | #define EXT4_XATTR_MAGIC 0xEA020000 7 | #define EXT4_XATTR_INDEX_SECURITY 6 8 | 9 | struct ext4_xattr_header { 10 | __le32 h_magic; 11 | __le32 h_refcount; 12 | __le32 h_blocks; 13 | __le32 h_hash; 14 | __le32 h_checksum; 15 | __u32 h_reserved[3]; 16 | }; 17 | 18 | struct ext4_xattr_ibody_header { 19 | __le32 h_magic; 20 | }; 21 | 22 | struct ext4_xattr_entry { 23 | __u8 e_name_len; 24 | __u8 e_name_index; 25 | __le16 e_value_offs; 26 | __le32 e_value_block; 27 | __le32 e_value_size; 28 | __le32 e_hash; 29 | char e_name[0]; 30 | }; 31 | 32 | #define EXT4_XATTR_PAD_BITS 2 33 | #define EXT4_XATTR_PAD (1<e_name_len))) 41 | #define EXT4_XATTR_SIZE(size) \ 42 | (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND) 43 | #define IS_LAST_ENTRY(entry) (*(uint32_t *)(entry) == 0) 44 | 45 | #endif /* !_SYSTEM_EXTRAS_EXT4_UTILS_XATTR_H */ 46 | -------------------------------------------------------------------------------- /contents.h: -------------------------------------------------------------------------------- 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 _DIRECTORY_H_ 18 | #define _DIRECTORY_H_ 19 | 20 | struct dentry { 21 | char *path; 22 | char *full_path; 23 | const char *filename; 24 | char *link; 25 | unsigned long size; 26 | u8 file_type; 27 | u16 mode; 28 | u16 uid; 29 | u16 gid; 30 | u32 *inode; 31 | u32 mtime; 32 | uint64_t capabilities; 33 | }; 34 | 35 | u32 make_directory(u32 dir_inode_num, u32 entries, struct dentry *dentries, 36 | u32 dirs); 37 | u32 make_file(const char *filename, u64 len); 38 | u32 make_link(const char *link); 39 | u32 make_special(const char *path); 40 | int inode_set_permissions(u32 inode_num, u16 mode, u16 uid, u16 gid, u32 mtime); 41 | int inode_set_capabilities(u32 inode_num, uint64_t capabilities); 42 | struct block_allocation* get_saved_allocation_chain(void); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ext4_kernel_headers.h: -------------------------------------------------------------------------------- 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 | #ifndef _EXT4_UTILS_EXT4_KERNEL_HEADERS_H_ 18 | #define _EXT4_UTILS_EXT4_KERNEL_HEADERS_H_ 19 | 20 | #include 21 | 22 | #ifdef __BIONIC__ 23 | #include 24 | #else 25 | #define __le64 uint64_t 26 | #define __le32 uint32_t 27 | #define __le16 uint16_t 28 | 29 | #define __be64 uint64_t 30 | #define __be32 uint32_t 31 | #define __be16 uint16_t 32 | 33 | #define __u64 uint64_t 34 | #define __u32 uint32_t 35 | #define __u16 uint16_t 36 | #define __u8 uint8_t 37 | #endif 38 | 39 | #include "ext4.h" 40 | #include "xattr.h" 41 | #include "ext4_extents.h" 42 | #include "jbd2.h" 43 | 44 | #ifndef __BIONIC__ 45 | #undef __le64 46 | #undef __le32 47 | #undef __le16 48 | 49 | #undef __be64 50 | #undef __be32 51 | #undef __be16 52 | 53 | #undef __u64 54 | #undef __u32 55 | #undef __u16 56 | #undef __u8 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libsparse/sparse_defs.h: -------------------------------------------------------------------------------- 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 _LIBSPARSE_SPARSE_DEFS_ 18 | #define _LIBSPARSE_SPARSE_DEFS_ 19 | 20 | #include 21 | #include 22 | 23 | #define __le64 u64 24 | #define __le32 u32 25 | #define __le16 u16 26 | 27 | #define __be64 u64 28 | #define __be32 u32 29 | #define __be16 u16 30 | 31 | #define __u64 u64 32 | #define __u32 u32 33 | #define __u16 u16 34 | #define __u8 u8 35 | 36 | typedef unsigned long long u64; 37 | typedef signed long long s64; 38 | typedef unsigned int u32; 39 | typedef unsigned short int u16; 40 | typedef unsigned char u8; 41 | 42 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y)) 43 | #define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y))) 44 | #define ALIGN_DOWN(x, y) ((y) * ((x) / (y))) 45 | 46 | #define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); } while (0) 47 | #define error_errno(s, args...) error(s ": %s", ##args, strerror(errno)) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /ext4_sb.h: -------------------------------------------------------------------------------- 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 | #ifndef _EXT4_UTILS_EXT4_SB_H_ 18 | #define _EXT4_UTILS_EXT4_SB_H_ 19 | 20 | #include "ext4_kernel_headers.h" 21 | 22 | #define EXT4_SUPER_MAGIC 0xEF53 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | struct fs_info { 29 | int64_t len; /* If set to 0, ask the block device for the size, 30 | * if less than 0, reserve that much space at the 31 | * end of the partition, else use the size given. */ 32 | uint32_t block_size; 33 | uint32_t blocks_per_group; 34 | uint32_t inodes_per_group; 35 | uint32_t inode_size; 36 | uint32_t inodes; 37 | uint32_t journal_blocks; 38 | uint16_t feat_ro_compat; 39 | uint16_t feat_compat; 40 | uint16_t feat_incompat; 41 | uint32_t bg_desc_reserve_blocks; 42 | uint32_t reserve_pcnt; 43 | const char *label; 44 | uint8_t no_journal; 45 | }; 46 | 47 | int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libsparse/output_file.h: -------------------------------------------------------------------------------- 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 _OUTPUT_FILE_H_ 18 | #define _OUTPUT_FILE_H_ 19 | 20 | #include 21 | 22 | struct output_file; 23 | 24 | struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t len, 25 | int gz, int sparse, int chunks, int crc); 26 | struct output_file *output_file_open_callback(int (*write)(void *, const void *, int), 27 | void *priv, unsigned int block_size, int64_t len, int gz, int sparse, 28 | int chunks, int crc); 29 | int write_data_chunk(struct output_file *out, unsigned int len, void *data); 30 | int write_fill_chunk(struct output_file *out, unsigned int len, 31 | uint32_t fill_val); 32 | int write_file_chunk(struct output_file *out, unsigned int len, 33 | const char *file, int64_t offset); 34 | int write_fd_chunk(struct output_file *out, unsigned int len, 35 | int fd, int64_t offset); 36 | int write_skip_chunk(struct output_file *out, int64_t len); 37 | void output_file_close(struct output_file *out); 38 | 39 | int read_all(int fd, void *buf, size_t len); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /ext4_sb.c: -------------------------------------------------------------------------------- 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 18 | 19 | #include "ext4_sb.h" 20 | 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 | -------------------------------------------------------------------------------- /uuid.c: -------------------------------------------------------------------------------- 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 | #include 18 | 19 | #include 20 | 21 | #include "ext4_utils.h" 22 | #include "sha1.h" 23 | #include "uuid.h" 24 | 25 | /* Definition from RFC-4122 */ 26 | struct uuid { 27 | u32 time_low; 28 | u16 time_mid; 29 | u16 time_hi_and_version; 30 | u8 clk_seq_hi_res; 31 | u8 clk_seq_low; 32 | u16 node0_1; 33 | u32 node2_5; 34 | }; 35 | 36 | static void sha1_hash(const char *namespace, const char *name, 37 | unsigned char sha1[SHA1_DIGEST_LENGTH]) 38 | { 39 | SHA1_CTX ctx; 40 | SHA1Init(&ctx); 41 | SHA1Update(&ctx, (const u8*)namespace, strlen(namespace)); 42 | SHA1Update(&ctx, (const u8*)name, strlen(name)); 43 | SHA1Final(sha1, &ctx); 44 | } 45 | 46 | void generate_uuid(const char *namespace, const char *name, u8 result[16]) 47 | { 48 | unsigned char sha1[SHA1_DIGEST_LENGTH]; 49 | struct uuid *uuid = (struct uuid *)result; 50 | 51 | sha1_hash(namespace, name, (unsigned char*)sha1); 52 | memcpy(uuid, sha1, sizeof(struct uuid)); 53 | 54 | uuid->time_low = ntohl(uuid->time_low); 55 | uuid->time_mid = ntohs(uuid->time_mid); 56 | uuid->time_hi_and_version = ntohs(uuid->time_hi_and_version); 57 | uuid->time_hi_and_version &= 0x0FFF; 58 | uuid->time_hi_and_version |= (5 << 12); 59 | uuid->clk_seq_hi_res &= ~(1 << 6); 60 | uuid->clk_seq_hi_res |= 1 << 7; 61 | } 62 | -------------------------------------------------------------------------------- /wipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 "ext4_utils.h" 18 | #include "wipe.h" 19 | 20 | #if WIPE_IS_SUPPORTED 21 | 22 | #if defined(__linux__) 23 | 24 | #include 25 | #include 26 | 27 | #ifndef BLKDISCARD 28 | #define BLKDISCARD _IO(0x12,119) 29 | #endif 30 | 31 | #ifndef BLKSECDISCARD 32 | #define BLKSECDISCARD _IO(0x12,125) 33 | #endif 34 | 35 | int wipe_block_device(int fd, s64 len) 36 | { 37 | u64 range[2]; 38 | int ret; 39 | 40 | if (!is_block_device_fd(fd)) { 41 | // Wiping only makes sense on a block device. 42 | return 0; 43 | } 44 | 45 | range[0] = 0; 46 | range[1] = len; 47 | ret = ioctl(fd, BLKSECDISCARD, &range); 48 | if (ret < 0) { 49 | range[0] = 0; 50 | range[1] = len; 51 | ret = ioctl(fd, BLKDISCARD, &range); 52 | if (ret < 0) { 53 | warn("Discard failed\n"); 54 | return 1; 55 | } else { 56 | warn("Wipe via secure discard failed, used discard instead\n"); 57 | return 0; 58 | } 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | #else /* __linux__ */ 65 | #error "Missing block device wiping implementation for this platform!" 66 | #endif 67 | 68 | #else /* WIPE_IS_SUPPORTED */ 69 | 70 | int wipe_block_device(int fd, s64 len) 71 | { 72 | /* Wiping is not supported on this platform. */ 73 | return 1; 74 | } 75 | 76 | #endif /* WIPE_IS_SUPPORTED */ 77 | -------------------------------------------------------------------------------- /libsparse/sparse_format.h: -------------------------------------------------------------------------------- 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 _LIBSPARSE_SPARSE_FORMAT_H_ 18 | #define _LIBSPARSE_SPARSE_FORMAT_H_ 19 | #include "sparse_defs.h" 20 | 21 | typedef struct sparse_header { 22 | __le32 magic; /* 0xed26ff3a */ 23 | __le16 major_version; /* (0x1) - reject images with higher major versions */ 24 | __le16 minor_version; /* (0x0) - allow images with higer minor versions */ 25 | __le16 file_hdr_sz; /* 28 bytes for first revision of the file format */ 26 | __le16 chunk_hdr_sz; /* 12 bytes for first revision of the file format */ 27 | __le32 blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */ 28 | __le32 total_blks; /* total blocks in the non-sparse output image */ 29 | __le32 total_chunks; /* total chunks in the sparse input image */ 30 | __le32 image_checksum; /* CRC32 checksum of the original data, counting "don't care" */ 31 | /* as 0. Standard 802.3 polynomial, use a Public Domain */ 32 | /* table implementation */ 33 | } sparse_header_t; 34 | 35 | #define SPARSE_HEADER_MAGIC 0xed26ff3a 36 | 37 | #define CHUNK_TYPE_RAW 0xCAC1 38 | #define CHUNK_TYPE_FILL 0xCAC2 39 | #define CHUNK_TYPE_DONT_CARE 0xCAC3 40 | #define CHUNK_TYPE_CRC32 0xCAC4 41 | 42 | typedef struct chunk_header { 43 | __le16 chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 44 | __le16 reserved1; 45 | __le32 chunk_sz; /* in blocks in output image */ 46 | __le32 total_sz; /* in bytes of chunk input file including chunk header and data */ 47 | } chunk_header_t; 48 | 49 | /* Following a Raw or Fill or CRC32 chunk is data. 50 | * For a Raw chunk, it's the data in chunk_sz * blk_sz. 51 | * For a Fill chunk, it's 4 bytes of the fill data. 52 | * For a CRC32 chunk, it's 4 bytes of CRC32 53 | */ 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /libsparse/backed_block.h: -------------------------------------------------------------------------------- 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 _BACKED_BLOCK_H_ 18 | #define _BACKED_BLOCK_H_ 19 | 20 | #include 21 | 22 | struct backed_block_list; 23 | struct backed_block; 24 | 25 | enum backed_block_type { 26 | BACKED_BLOCK_DATA, 27 | BACKED_BLOCK_FILE, 28 | BACKED_BLOCK_FD, 29 | BACKED_BLOCK_FILL, 30 | }; 31 | 32 | int backed_block_add_data(struct backed_block_list *bbl, void *data, 33 | unsigned int len, unsigned int block); 34 | int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val, 35 | unsigned int len, unsigned int block); 36 | int backed_block_add_file(struct backed_block_list *bbl, const char *filename, 37 | int64_t offset, unsigned int len, unsigned int block); 38 | int backed_block_add_fd(struct backed_block_list *bbl, int fd, 39 | int64_t offset, unsigned int len, unsigned int block); 40 | 41 | struct backed_block *backed_block_iter_new(struct backed_block_list *bbl); 42 | struct backed_block *backed_block_iter_next(struct backed_block *bb); 43 | unsigned int backed_block_len(struct backed_block *bb); 44 | unsigned int backed_block_block(struct backed_block *bb); 45 | void *backed_block_data(struct backed_block *bb); 46 | const char *backed_block_filename(struct backed_block *bb); 47 | int backed_block_fd(struct backed_block *bb); 48 | int64_t backed_block_file_offset(struct backed_block *bb); 49 | uint32_t backed_block_fill_val(struct backed_block *bb); 50 | enum backed_block_type backed_block_type(struct backed_block *bb); 51 | int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb, 52 | unsigned int max_len); 53 | 54 | struct backed_block *backed_block_iter_new(struct backed_block_list *bbl); 55 | struct backed_block *backed_block_iter_next(struct backed_block *bb); 56 | 57 | struct backed_block_list *backed_block_list_new(unsigned int block_size); 58 | void backed_block_list_destroy(struct backed_block_list *bbl); 59 | 60 | void backed_block_list_move(struct backed_block_list *from, 61 | struct backed_block_list *to, struct backed_block *start, 62 | struct backed_block *end); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /allocate.h: -------------------------------------------------------------------------------- 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 _ALLOCATE_H_ 18 | #define _ALLOCATE_H_ 19 | 20 | #define EXT4_ALLOCATE_FAILED (u32)(~0) 21 | 22 | #include "ext4_utils.h" 23 | 24 | struct region; 25 | 26 | struct region_list { 27 | struct region *first; 28 | struct region *last; 29 | struct region *iter; 30 | u32 partial_iter; 31 | }; 32 | 33 | struct block_allocation { 34 | struct region_list list; 35 | struct region_list oob_list; 36 | char* filename; 37 | struct block_allocation* next; 38 | }; 39 | 40 | 41 | void block_allocator_init(void); 42 | void block_allocator_free(void); 43 | u32 allocate_block(void); 44 | struct block_allocation *allocate_blocks(u32 len); 45 | int block_allocation_num_regions(struct block_allocation *alloc); 46 | int block_allocation_len(struct block_allocation *alloc); 47 | struct ext4_inode *get_inode(u32 inode); 48 | struct ext4_xattr_header *get_xattr_block_for_inode(struct ext4_inode *inode); 49 | void reduce_allocation(struct block_allocation *alloc, u32 len); 50 | u32 get_block(struct block_allocation *alloc, u32 block); 51 | u32 get_oob_block(struct block_allocation *alloc, u32 block); 52 | void get_next_region(struct block_allocation *alloc); 53 | void get_region(struct block_allocation *alloc, u32 *block, u32 *len); 54 | u32 get_free_blocks(u32 bg); 55 | u32 get_free_inodes(u32 bg); 56 | u32 reserve_inodes(int bg, u32 inodes); 57 | void add_directory(u32 inode); 58 | u16 get_directories(int bg); 59 | u16 get_bg_flags(int bg); 60 | void init_unused_inode_tables(void); 61 | u32 allocate_inode(void); 62 | void free_alloc(struct block_allocation *alloc); 63 | int reserve_oob_blocks(struct block_allocation *alloc, int blocks); 64 | int advance_blocks(struct block_allocation *alloc, int blocks); 65 | int advance_oob_blocks(struct block_allocation *alloc, int blocks); 66 | int last_region(struct block_allocation *alloc); 67 | void rewind_alloc(struct block_allocation *alloc); 68 | void append_region(struct block_allocation *alloc, 69 | u32 block, u32 len, int bg); 70 | struct block_allocation *create_allocation(void); 71 | int append_oob_allocation(struct block_allocation *alloc, u32 len); 72 | void print_blocks(FILE* f, struct block_allocation *alloc); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /crc16.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or 3 | * code or tables extracted from it, as desired without restriction. 4 | */ 5 | 6 | /* CRC32 code derived from work by Gary S. Brown. */ 7 | 8 | /* Code taken from FreeBSD 8 */ 9 | 10 | /* Converted to crc16 */ 11 | 12 | #include "ext4_utils.h" 13 | 14 | static u16 crc16_tab[] = { 15 | 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 16 | 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 17 | 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 18 | 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, 19 | 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 20 | 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 21 | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 22 | 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 23 | 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 24 | 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, 25 | 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 26 | 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, 27 | 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 28 | 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, 29 | 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 30 | 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, 31 | 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 32 | 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, 33 | 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 34 | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, 35 | 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 36 | 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, 37 | 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 38 | 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, 39 | 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 40 | 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, 41 | 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 42 | 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, 43 | 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 44 | 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, 45 | 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 46 | 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040, 47 | }; 48 | 49 | u16 ext4_crc16(u16 crc_in, const void *buf, int size) 50 | { 51 | const u8 *p = buf; 52 | u16 crc = crc_in; 53 | 54 | while (size--) 55 | crc = crc16_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 56 | 57 | return crc; 58 | } 59 | -------------------------------------------------------------------------------- /ext4_extents.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Linux kernel header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to libc. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | **************************************************************************** 11 | ****************************************************************************/ 12 | #ifndef _EXT4_EXTENTS 13 | #define _EXT4_EXTENTS 14 | 15 | #include "ext4.h" 16 | 17 | #define AGGRESSIVE_TEST_ 18 | 19 | #define EXTENTS_STATS__ 20 | 21 | #define CHECK_BINSEARCH__ 22 | 23 | #define EXT_DEBUG__ 24 | #ifdef EXT_DEBUG 25 | #define ext_debug(a...) printk(a) 26 | #else 27 | #define ext_debug(a...) 28 | #endif 29 | 30 | #define EXT_STATS_ 31 | 32 | struct ext4_extent { 33 | __le32 ee_block; 34 | __le16 ee_len; 35 | __le16 ee_start_hi; 36 | __le32 ee_start_lo; 37 | }; 38 | 39 | struct ext4_extent_idx { 40 | __le32 ei_block; 41 | __le32 ei_leaf_lo; 42 | __le16 ei_leaf_hi; 43 | __u16 ei_unused; 44 | }; 45 | 46 | struct ext4_extent_header { 47 | __le16 eh_magic; 48 | __le16 eh_entries; 49 | __le16 eh_max; 50 | __le16 eh_depth; 51 | __le32 eh_generation; 52 | }; 53 | 54 | #define EXT4_EXT_MAGIC 0xf30a 55 | 56 | struct ext4_ext_path { 57 | ext4_fsblk_t p_block; 58 | __u16 p_depth; 59 | struct ext4_extent *p_ext; 60 | struct ext4_extent_idx *p_idx; 61 | struct ext4_extent_header *p_hdr; 62 | struct buffer_head *p_bh; 63 | }; 64 | 65 | #define EXT4_EXT_CACHE_NO 0 66 | #define EXT4_EXT_CACHE_GAP 1 67 | #define EXT4_EXT_CACHE_EXTENT 2 68 | 69 | #define EXT_CONTINUE 0 70 | #define EXT_BREAK 1 71 | #define EXT_REPEAT 2 72 | 73 | #define EXT_MAX_BLOCK 0xffffffff 74 | 75 | #define EXT_INIT_MAX_LEN (1UL << 15) 76 | #define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1) 77 | 78 | #define EXT_FIRST_EXTENT(__hdr__) ((struct ext4_extent *) (((char *) (__hdr__)) + sizeof(struct ext4_extent_header))) 79 | #define EXT_FIRST_INDEX(__hdr__) ((struct ext4_extent_idx *) (((char *) (__hdr__)) + sizeof(struct ext4_extent_header))) 80 | #define EXT_HAS_FREE_INDEX(__path__) (le16_to_cpu((__path__)->p_hdr->eh_entries) < le16_to_cpu((__path__)->p_hdr->eh_max)) 81 | #define EXT_LAST_EXTENT(__hdr__) (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1) 82 | #define EXT_LAST_INDEX(__hdr__) (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1) 83 | #define EXT_MAX_EXTENT(__hdr__) (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1) 84 | #define EXT_MAX_INDEX(__hdr__) (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1) 85 | 86 | #endif 87 | 88 | 89 | -------------------------------------------------------------------------------- /canned_fs_config.c: -------------------------------------------------------------------------------- 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "canned_fs_config.h" 24 | 25 | typedef struct { 26 | const char* path; 27 | unsigned uid; 28 | unsigned gid; 29 | unsigned mode; 30 | uint64_t capabilities; 31 | } Path; 32 | 33 | static Path* canned_data = NULL; 34 | static int canned_alloc = 0; 35 | static int canned_used = 0; 36 | 37 | static int path_compare(const void* a, const void* b) { 38 | return strcmp(((Path*)a)->path, ((Path*)b)->path); 39 | } 40 | 41 | int load_canned_fs_config(const char* fn) { 42 | FILE* f = fopen(fn, "r"); 43 | if (f == NULL) { 44 | fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); 45 | return -1; 46 | } 47 | 48 | char line[PATH_MAX + 200]; 49 | while (fgets(line, sizeof(line), f)) { 50 | while (canned_used >= canned_alloc) { 51 | canned_alloc = (canned_alloc+1) * 2; 52 | canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); 53 | } 54 | Path* p = canned_data + canned_used; 55 | p->path = strdup(strtok(line, " \t")); 56 | 57 | if (!p->path || !*p->path || *p->path == '#') 58 | continue; 59 | 60 | p->uid = atoi(strtok(NULL, " \t")); 61 | p->gid = atoi(strtok(NULL, " \t")); 62 | p->mode = strtol(strtok(NULL, " \t"), NULL, 8); // mode is in octal 63 | p->capabilities = 0; 64 | 65 | char* token = NULL; 66 | do { 67 | token = strtok(NULL, " \t"); 68 | if (token && strncmp(token, "capabilities=", 13) == 0) { 69 | p->capabilities = strtoll(token+13, NULL, 0); 70 | break; 71 | } 72 | } while (token); 73 | 74 | canned_used++; 75 | } 76 | 77 | fclose(f); 78 | 79 | qsort(canned_data, canned_used, sizeof(Path), path_compare); 80 | printf("loaded %d fs_config entries\n", canned_used); 81 | 82 | return 0; 83 | } 84 | 85 | int canned_fs_config(const char* path, int dir, 86 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { 87 | Path key; 88 | key.path = path; 89 | Path* p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); 90 | if (p == NULL) { 91 | return 0; 92 | } 93 | *uid = p->uid; 94 | *gid = p->gid; 95 | *mode = p->mode; 96 | *capabilities = p->capabilities; 97 | 98 | #if 0 99 | // for debugging, run the built-in fs_config and compare the results. 100 | 101 | unsigned c_uid, c_gid, c_mode; 102 | uint64_t c_capabilities; 103 | fs_config(path, dir, &c_uid, &c_gid, &c_mode, &c_capabilities); 104 | 105 | if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); 106 | if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); 107 | if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); 108 | if (c_capabilities != *capabilities) printf("%s capabilities %llx %llx\n", path, *capabilities, c_capabilities); 109 | #endif 110 | 111 | return 1; 112 | } 113 | -------------------------------------------------------------------------------- /include/private/android_filesystem_capability.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | /* 18 | * Taken from linux/capability.h, with minor modifications 19 | */ 20 | 21 | #ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_FILESYSTEM_CAPABILITY_H 22 | #define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_FILESYSTEM_CAPABILITY_H 23 | 24 | #include 25 | 26 | #define __user 27 | #define __u32 uint32_t 28 | #define __le32 uint32_t 29 | 30 | #define _LINUX_CAPABILITY_VERSION_1 0x19980330 31 | #define _LINUX_CAPABILITY_U32S_1 1 32 | #define _LINUX_CAPABILITY_VERSION_2 0x20071026 33 | #define _LINUX_CAPABILITY_U32S_2 2 34 | #define _LINUX_CAPABILITY_VERSION_3 0x20080522 35 | #define _LINUX_CAPABILITY_U32S_3 2 36 | 37 | typedef struct __user_cap_header_struct { 38 | __u32 version; 39 | int pid; 40 | } __user *cap_user_header_t; 41 | 42 | typedef struct __user_cap_data_struct { 43 | __u32 effective; 44 | __u32 permitted; 45 | __u32 inheritable; 46 | } __user *cap_user_data_t; 47 | 48 | #define VFS_CAP_REVISION_MASK 0xFF000000 49 | #define VFS_CAP_REVISION_SHIFT 24 50 | #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK 51 | #define VFS_CAP_FLAGS_EFFECTIVE 0x000001 52 | #define VFS_CAP_REVISION_1 0x01000000 53 | #define VFS_CAP_U32_1 1 54 | #define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1)) 55 | #define VFS_CAP_REVISION_2 0x02000000 56 | #define VFS_CAP_U32_2 2 57 | #define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2)) 58 | #define XATTR_CAPS_SZ XATTR_CAPS_SZ_2 59 | #define VFS_CAP_U32 VFS_CAP_U32_2 60 | #define VFS_CAP_REVISION VFS_CAP_REVISION_2 61 | 62 | struct vfs_cap_data { 63 | __le32 magic_etc; 64 | struct { 65 | __le32 permitted; 66 | __le32 inheritable; 67 | } data[VFS_CAP_U32]; 68 | }; 69 | 70 | #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1 71 | #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1 72 | #define CAP_CHOWN 0 73 | #define CAP_DAC_OVERRIDE 1 74 | #define CAP_DAC_READ_SEARCH 2 75 | #define CAP_FOWNER 3 76 | #define CAP_FSETID 4 77 | #define CAP_KILL 5 78 | #define CAP_SETGID 6 79 | #define CAP_SETUID 7 80 | #define CAP_SETPCAP 8 81 | #define CAP_LINUX_IMMUTABLE 9 82 | #define CAP_NET_BIND_SERVICE 10 83 | #define CAP_NET_BROADCAST 11 84 | #define CAP_NET_ADMIN 12 85 | #define CAP_NET_RAW 13 86 | #define CAP_IPC_LOCK 14 87 | #define CAP_IPC_OWNER 15 88 | #define CAP_SYS_MODULE 16 89 | #define CAP_SYS_RAWIO 17 90 | #define CAP_SYS_CHROOT 18 91 | #define CAP_SYS_PTRACE 19 92 | #define CAP_SYS_PACCT 20 93 | #define CAP_SYS_ADMIN 21 94 | #define CAP_SYS_BOOT 22 95 | #define CAP_SYS_NICE 23 96 | #define CAP_SYS_RESOURCE 24 97 | #define CAP_SYS_TIME 25 98 | #define CAP_SYS_TTY_CONFIG 26 99 | #define CAP_MKNOD 27 100 | #define CAP_LEASE 28 101 | #define CAP_AUDIT_WRITE 29 102 | #define CAP_AUDIT_CONTROL 30 103 | #define CAP_SETFCAP 31 104 | #define CAP_MAC_OVERRIDE 32 105 | #define CAP_MAC_ADMIN 33 106 | #define CAP_SYSLOG 34 107 | #define CAP_WAKE_ALARM 35 108 | #define CAP_LAST_CAP CAP_WAKE_ALARM 109 | #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP) 110 | #define CAP_TO_INDEX(x) ((x) >> 5) 111 | #define CAP_TO_MASK(x) (1 << ((x) & 31)) 112 | 113 | #undef __user 114 | #undef __u32 115 | #undef __le32 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /jbd2.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Linux kernel header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to libc. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | **************************************************************************** 11 | ****************************************************************************/ 12 | #ifndef _LINUX_JBD2_H 13 | #define _LINUX_JBD2_H 14 | 15 | #define JBD2_DEBUG 16 | #define jfs_debug jbd_debug 17 | 18 | #define journal_oom_retry 1 19 | 20 | #undef JBD2_PARANOID_IOFAIL 21 | 22 | #define JBD2_DEFAULT_MAX_COMMIT_AGE 5 23 | 24 | #define jbd_debug(f, a...) 25 | 26 | #define JBD2_MIN_JOURNAL_BLOCKS 1024 27 | 28 | #define JBD2_MAGIC_NUMBER 0xc03b3998U 29 | 30 | #define JBD2_DESCRIPTOR_BLOCK 1 31 | #define JBD2_COMMIT_BLOCK 2 32 | #define JBD2_SUPERBLOCK_V1 3 33 | #define JBD2_SUPERBLOCK_V2 4 34 | #define JBD2_REVOKE_BLOCK 5 35 | 36 | typedef struct journal_header_s 37 | { 38 | __be32 h_magic; 39 | __be32 h_blocktype; 40 | __be32 h_sequence; 41 | } journal_header_t; 42 | 43 | #define JBD2_CRC32_CHKSUM 1 44 | #define JBD2_MD5_CHKSUM 2 45 | #define JBD2_SHA1_CHKSUM 3 46 | 47 | #define JBD2_CRC32_CHKSUM_SIZE 4 48 | 49 | #define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32)) 50 | 51 | struct commit_header { 52 | __be32 h_magic; 53 | __be32 h_blocktype; 54 | __be32 h_sequence; 55 | unsigned char h_chksum_type; 56 | unsigned char h_chksum_size; 57 | unsigned char h_padding[2]; 58 | __be32 h_chksum[JBD2_CHECKSUM_BYTES]; 59 | __be64 h_commit_sec; 60 | __be32 h_commit_nsec; 61 | }; 62 | 63 | typedef struct journal_block_tag_s 64 | { 65 | __be32 t_blocknr; 66 | __be32 t_flags; 67 | __be32 t_blocknr_high; 68 | } journal_block_tag_t; 69 | 70 | #define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high)) 71 | #define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t)) 72 | 73 | typedef struct jbd2_journal_revoke_header_s 74 | { 75 | journal_header_t r_header; 76 | __be32 r_count; 77 | } jbd2_journal_revoke_header_t; 78 | 79 | #define JBD2_FLAG_ESCAPE 1 80 | #define JBD2_FLAG_SAME_UUID 2 81 | #define JBD2_FLAG_DELETED 4 82 | #define JBD2_FLAG_LAST_TAG 8 83 | 84 | typedef struct journal_superblock_s 85 | { 86 | 87 | journal_header_t s_header; 88 | 89 | __be32 s_blocksize; 90 | __be32 s_maxlen; 91 | __be32 s_first; 92 | 93 | __be32 s_sequence; 94 | __be32 s_start; 95 | 96 | __be32 s_errno; 97 | 98 | __be32 s_feature_compat; 99 | __be32 s_feature_incompat; 100 | __be32 s_feature_ro_compat; 101 | 102 | __u8 s_uuid[16]; 103 | 104 | __be32 s_nr_users; 105 | 106 | __be32 s_dynsuper; 107 | 108 | __be32 s_max_transaction; 109 | __be32 s_max_trans_data; 110 | 111 | __u32 s_padding[44]; 112 | 113 | __u8 s_users[16*48]; 114 | 115 | } journal_superblock_t; 116 | 117 | #define JBD2_HAS_COMPAT_FEATURE(j,mask) ((j)->j_format_version >= 2 && ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask)))) 118 | #define JBD2_HAS_RO_COMPAT_FEATURE(j,mask) ((j)->j_format_version >= 2 && ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask)))) 119 | #define JBD2_HAS_INCOMPAT_FEATURE(j,mask) ((j)->j_format_version >= 2 && ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) 120 | 121 | #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001 122 | 123 | #define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 124 | #define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 125 | #define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 126 | 127 | #define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM 128 | #define JBD2_KNOWN_ROCOMPAT_FEATURES 0 129 | #define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | JBD2_FEATURE_INCOMPAT_64BIT | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) 130 | 131 | #define BJ_None 0 132 | #define BJ_Metadata 1 133 | #define BJ_Forget 2 134 | #define BJ_IO 3 135 | #define BJ_Shadow 4 136 | #define BJ_LogCtl 5 137 | #define BJ_Reserved 6 138 | #define BJ_Types 7 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /ext4_utils.h: -------------------------------------------------------------------------------- 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 | #ifndef _GNU_SOURCE 25 | #define _GNU_SOURCE 26 | #endif 27 | #define _FILE_OFFSET_BITS 64 28 | #define _LARGEFILE64_SOURCE 1 29 | #include 30 | 31 | #ifndef __APPLE__ 32 | #include 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "ext4_sb.h" 45 | 46 | extern int force; 47 | 48 | #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0) 49 | #define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) longjmp(setjmp_env, EXIT_FAILURE); } while (0) 50 | #define error_errno(s, args...) error(s ": %s", ##args, strerror(errno)) 51 | #define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); longjmp(setjmp_env, EXIT_FAILURE); } while (0) 52 | #define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno)) 53 | 54 | #define EXT4_JNL_BACKUP_BLOCKS 1 55 | 56 | #ifndef min /* already defined by windows.h */ 57 | #define min(a, b) ((a) < (b) ? (a) : (b)) 58 | #endif 59 | 60 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y)) 61 | #define EXT4_ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y))) 62 | 63 | /* XXX */ 64 | #define cpu_to_le32(x) (x) 65 | #define cpu_to_le16(x) (x) 66 | #define le32_to_cpu(x) (x) 67 | #define le16_to_cpu(x) (x) 68 | 69 | #ifdef __LP64__ 70 | typedef unsigned long u64; 71 | typedef signed long s64; 72 | #else 73 | typedef unsigned long long u64; 74 | typedef signed long long s64; 75 | #endif 76 | typedef unsigned int u32; 77 | typedef unsigned short int u16; 78 | typedef unsigned char u8; 79 | 80 | struct block_group_info; 81 | struct xattr_list_element; 82 | 83 | struct ext2_group_desc { 84 | u32 bg_block_bitmap; 85 | u32 bg_inode_bitmap; 86 | u32 bg_inode_table; 87 | u16 bg_free_blocks_count; 88 | u16 bg_free_inodes_count; 89 | u16 bg_used_dirs_count; 90 | u16 bg_flags; 91 | u32 bg_reserved[2]; 92 | u16 bg_reserved16; 93 | u16 bg_checksum; 94 | }; 95 | 96 | struct fs_aux_info { 97 | struct ext4_super_block *sb; 98 | struct ext4_super_block **backup_sb; 99 | struct ext2_group_desc *bg_desc; 100 | struct block_group_info *bgs; 101 | struct xattr_list_element *xattrs; 102 | u32 first_data_block; 103 | u64 len_blocks; 104 | u32 inode_table_blocks; 105 | u32 groups; 106 | u32 bg_desc_blocks; 107 | u32 default_i_flags; 108 | u32 blocks_per_ind; 109 | u32 blocks_per_dind; 110 | u32 blocks_per_tind; 111 | }; 112 | 113 | extern struct fs_info info; 114 | extern struct fs_aux_info aux_info; 115 | extern struct sparse_file *ext4_sparse_file; 116 | 117 | extern jmp_buf setjmp_env; 118 | 119 | static inline int log_2(int j) 120 | { 121 | int i; 122 | 123 | for (i = 0; j > 0; i++) 124 | j >>= 1; 125 | 126 | return i - 1; 127 | } 128 | 129 | int bitmap_get_bit(u8 *bitmap, u32 bit); 130 | void bitmap_clear_bit(u8 *bitmap, u32 bit); 131 | int ext4_bg_has_super_block(int bg); 132 | void read_sb(int fd, struct ext4_super_block *sb); 133 | void write_sb(int fd, unsigned long long offset, struct ext4_super_block *sb); 134 | void write_ext4_image(int fd, int gz, int sparse, int crc); 135 | void ext4_create_fs_aux_info(void); 136 | void ext4_free_fs_aux_info(void); 137 | void ext4_fill_in_sb(void); 138 | void ext4_create_resize_inode(void); 139 | void ext4_create_journal_inode(void); 140 | void ext4_update_free(void); 141 | void ext4_queue_sb(void); 142 | u64 get_block_device_size(int fd); 143 | int is_block_device_fd(int fd); 144 | u64 get_file_size(int fd); 145 | u64 parse_num(const char *arg); 146 | void ext4_parse_sb_info(struct ext4_super_block *sb); 147 | u16 ext4_crc16(u16 crc_in, const void *buf, int size); 148 | 149 | typedef int (*fs_config_func_t)(const char *path, int dir, unsigned *uid, unsigned *gid, 150 | unsigned *mode, uint64_t *capabilities); 151 | 152 | struct selabel_handle; 153 | 154 | int make_ext4fs_internal(int fd, const char *directory, 155 | fs_config_func_t fs_config_func, int gzip, 156 | int sparse, int crc, int wipe, 157 | int verbose, time_t fixed_time, 158 | FILE* block_list_file); 159 | 160 | int read_ext(int fd, int verbose); 161 | 162 | #ifdef __cplusplus 163 | } 164 | #endif 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /make_ext4fs_main.c: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #if defined(__linux__) 23 | #include 24 | #elif defined(__APPLE__) && defined(__MACH__) 25 | #include 26 | #endif 27 | 28 | #include "ext4_utils.h" 29 | #include "canned_fs_config.h" 30 | 31 | extern struct fs_info info; 32 | 33 | 34 | static void usage(char *path) 35 | { 36 | fprintf(stderr, "%s [ -l ] [ -j ] [ -b ]\n", basename(path)); 37 | fprintf(stderr, " [ -g ] [ -i ] [ -I ]\n"); 38 | fprintf(stderr, " [ -m ] [ -L