├── .classpath ├── .cproject ├── .externalToolBuilders └── org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder.launch ├── .gitattributes ├── .gitignore ├── .project ├── .settings ├── org.eclipse.cdt.codan.core.prefs ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── README.md ├── jni ├── Android.mk ├── Application.mk ├── edify │ ├── Android.mk │ ├── expr.c │ ├── expr.h │ ├── lexer.cpp │ ├── main.c │ ├── parser.cpp │ ├── parser.h │ └── yydefs.h ├── ext4_utils │ ├── Android.mk │ ├── allocate.c │ ├── allocate.h │ ├── canned_fs_config.c │ ├── canned_fs_config.h │ ├── contents.c │ ├── contents.h │ ├── crc16.c │ ├── ext2simg.c │ ├── ext4.h │ ├── ext4_extents.h │ ├── ext4_kernel_headers.h │ ├── ext4_sb.c │ ├── ext4_sb.h │ ├── ext4_utils.c │ ├── ext4_utils.h │ ├── ext4fixup.c │ ├── ext4fixup.h │ ├── ext4fixup_main.c │ ├── extent.c │ ├── extent.h │ ├── indirect.c │ ├── indirect.h │ ├── jbd2.h │ ├── make_ext4fs.c │ ├── make_ext4fs.h │ ├── make_ext4fs_main.c │ ├── setup_fs.c │ ├── sha1.c │ ├── sha1.h │ ├── uuid.c │ ├── uuid.h │ ├── wipe.c │ ├── wipe.h │ └── xattr.h ├── libmincrypt │ ├── Android.mk │ ├── dsa_sig.c │ ├── dsa_sig.h │ ├── hash-internal.h │ ├── p256.c │ ├── p256.h │ ├── p256_ec.c │ ├── p256_ecdsa.c │ ├── p256_ecdsa.h │ ├── rsa.c │ ├── rsa.h │ ├── sha.c │ ├── sha.h │ ├── sha256.c │ └── sha256.h ├── libsparse │ ├── Android.mk │ ├── append2simg.c │ ├── backed_block.c │ ├── backed_block.h │ ├── defs.h │ ├── img2simg.c │ ├── include │ │ └── sparse │ │ │ └── sparse.h │ ├── output_file.c │ ├── output_file.h │ ├── simg2img.c │ ├── simg2simg.c │ ├── sparse.c │ ├── sparse_crc32.c │ ├── sparse_crc32.h │ ├── sparse_defs.h │ ├── sparse_err.c │ ├── sparse_file.h │ ├── sparse_format.h │ └── sparse_read.c ├── minzip │ ├── Android.mk │ ├── Bits.h │ ├── DirUtil.c │ ├── DirUtil.h │ ├── Hash.c │ ├── Hash.h │ ├── Inlines.c │ ├── Log.h │ ├── SysUtil.c │ ├── SysUtil.h │ ├── Zip.c │ ├── Zip.h │ └── inline_magic.h ├── mtdutils │ ├── Android.mk │ ├── flash_image.c │ ├── mounts.c │ ├── mounts.h │ ├── mtd-abi.h │ ├── mtd-user.h │ ├── mtdutils.c │ └── mtdutils.h ├── safe-iop │ ├── Android.mk │ ├── include │ │ └── safe_iop.h │ └── src │ │ └── safe_iop.c ├── update-binary │ ├── Android.mk │ ├── install.c │ ├── install.h │ ├── update-binary.c │ └── update-binary.h └── zlib │ ├── Android.mk │ ├── src │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h │ ├── zconf.h │ ├── zlib.h │ └── zutil.h ├── project.properties └── res ├── drawable-hdpi └── ic_launcher.png ├── drawable-mdpi └── ic_launcher.png ├── drawable-xhdpi └── ic_launcher.png └── values ├── strings.xml └── styles.xml /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Custom_update-binary 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.andmore.ResourceManagerBuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.andmore.PreCompilerBuilder 21 | 22 | 23 | 24 | 25 | org.eclipse.jdt.core.javabuilder 26 | 27 | 28 | 29 | 30 | org.eclipse.andmore.ApkBuilder 31 | 32 | 33 | 34 | 35 | org.eclipse.ui.externaltools.ExternalToolBuilder 36 | full,incremental, 37 | 38 | 39 | LaunchConfigHandle 40 | <project>/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder.launch 41 | 42 | 43 | 44 | 45 | 46 | org.eclipse.andmore.AndroidNature 47 | org.eclipse.jdt.core.javanature 48 | org.eclipse.cdt.core.cnature 49 | org.eclipse.cdt.core.ccnature 50 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 51 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 52 | 53 | 54 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//jni/libxslt/libxslt/xslt.c=UTF-8 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.source=1.7 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Conventional update-binary for Android recovery (Eclipse NDK build)---Mainly for CWM/TWRP Recovery 2 | 3 | Some people may curious how does update-binary in your update.zip is created...And what is going on inside of it 4 | 5 | This show you how to compile it in normal way. 6 | 7 | # Features 8 | 1. Execution speed is faster, binary size is much smaller than AOSP rom generated binary, even without any PE compression. 9 | 2. Function is shrinked, but added set file permission. 10 | 3. Compatible with most platform, ARM, x86, etc. 11 | 4. SELinux is deleted from code. 12 | 13 | # Usage and common errors 14 | ## Usage 15 | Create a script file call "updater-script" inside your zip folder, e.g: ZIPFILE/META-INF/com/google/android/, edit your script here. 16 | 17 | Put your compiled update-binary into that folder too, pack your zip correctly(7zip deflate) will do the job, finally test your zip installer. 18 | ## Errors 19 | 1. Incompatible binary is used. You may using x86 binary on ARM devices. 20 | 2. Check your script, wrong syntax will cause error. 21 | 22 | # Example "updater-script" from [JamesDSPManager .zip installer](https://github.com/james34602/JamesDSPManager): 23 | ``` 24 | ui_print("**********************************************"); 25 | ui_print("*Installing JamesDSP for Android 5.X.X or above (ARM)*"); 26 | ui_print("**********************************************"); 27 | run_program("/sbin/busybox", "mount", "/system"); 28 | delete_recursive("/system/app/MusicFX"); 29 | delete_recursive("/system/priv-app/MusicFX"); 30 | delete_recursive("/system/priv-app/AudioFX"); 31 | delete_recursive("/system/priv-app/SoundAlive_20_L"); 32 | delete_recursive("/system/priv-app/SoundAlive_30"); 33 | delete_recursive("/data/data/org.cyanogenmod.audiofx"); 34 | delete_recursive("/data/data/com.android.musicfx"); 35 | delete_recursive("/data/data/com.sec.android.app.soundalive"); 36 | delete("/system/app/DSPManager_All.apk"); 37 | delete("/system/lib/libjamesDSPImpulseToolbox.so"); 38 | delete("/system/lib/soundfx/libjamesdsp.so"); 39 | delete("/system/vendor/etc/audio_effects.conf"); 40 | package_extract_dir("system", "/system"); 41 | ui_print("Fixing permissions..."); 42 | set_perm(0, 0, 0644, "/system/app/DSPManager_All.apk"); 43 | set_perm(0, 0, 0644, "/system/lib/libjamesDSPImpulseToolbox.so"); 44 | set_perm(0, 0, 0644, "/system/lib/soundfx/libjamesdsp.so"); 45 | set_perm(0, 0, 0644, "/system/vendor/etc/audio_effects.conf"); 46 | run_program("/sbin/busybox", "umount", "/system"); 47 | ui_print("**********************************************"); 48 | ui_print("* Installation complete... *"); 49 | ui_print("* Please reboot and launch JamesDSP *"); 50 | ui_print("**********************************************"); 51 | show_progress(0.100000, 0); 52 | ``` -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | include $(call all-makefiles-under,$(LOCAL_PATH)) -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_OPTIM := release 2 | APP_ABI := armeabi-v7a x86 -------------------------------------------------------------------------------- /jni/edify/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | edify_src_files := \ 4 | lexer.cpp \ 5 | parser.cpp \ 6 | expr.c 7 | LOCAL_SRC_FILES := $(edify_src_files) 8 | LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -DNDEBUG 9 | LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -DNDEBUG 10 | LOCAL_MODULE := libedify 11 | include $(BUILD_STATIC_LIBRARY) 12 | -------------------------------------------------------------------------------- /jni/edify/expr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 _EXPRESSION_H 18 | #define _EXPRESSION_H 19 | 20 | #include 21 | 22 | #include "yydefs.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define MAX_STRING_LEN 1024 29 | 30 | typedef struct Expr Expr; 31 | 32 | typedef struct { 33 | // Optional pointer to app-specific data; the core of edify never 34 | // uses this value. 35 | void* cookie; 36 | 37 | // The source of the original script. Must be NULL-terminated, 38 | // and in writable memory (Evaluate may make temporary changes to 39 | // it but will restore it when done). 40 | char* script; 41 | 42 | // The error message (if any) returned if the evaluation aborts. 43 | // Should be NULL initially, will be either NULL or a malloc'd 44 | // pointer after Evaluate() returns. 45 | char* errmsg; 46 | } State; 47 | 48 | #define VAL_STRING 1 // data will be NULL-terminated; size doesn't count null 49 | #define VAL_BLOB 2 50 | 51 | typedef struct { 52 | int type; 53 | ssize_t size; 54 | char* data; 55 | } Value; 56 | 57 | typedef Value* (*Function)(const char* name, State* state, 58 | int argc, Expr* argv[]); 59 | 60 | struct Expr { 61 | Function fn; 62 | char* name; 63 | int argc; 64 | Expr** argv; 65 | int start, end; 66 | }; 67 | 68 | // Take one of the Expr*s passed to the function as an argument, 69 | // evaluate it, return the resulting Value. The caller takes 70 | // ownership of the returned Value. 71 | Value* EvaluateValue(State* state, Expr* expr); 72 | 73 | // Take one of the Expr*s passed to the function as an argument, 74 | // evaluate it, assert that it is a string, and return the resulting 75 | // char*. The caller takes ownership of the returned char*. This is 76 | // a convenience function for older functions that want to deal only 77 | // with strings. 78 | char* Evaluate(State* state, Expr* expr); 79 | 80 | // Glue to make an Expr out of a literal. 81 | Value* Literal(const char* name, State* state, int argc, Expr* argv[]); 82 | 83 | // Functions corresponding to various syntactic sugar operators. 84 | // ("concat" is also available as a builtin function, to concatenate 85 | // more than two strings.) 86 | Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]); 87 | Value* LogicalAndFn(const char* name, State* state, int argc, Expr* argv[]); 88 | Value* LogicalOrFn(const char* name, State* state, int argc, Expr* argv[]); 89 | Value* LogicalNotFn(const char* name, State* state, int argc, Expr* argv[]); 90 | Value* SubstringFn(const char* name, State* state, int argc, Expr* argv[]); 91 | Value* EqualityFn(const char* name, State* state, int argc, Expr* argv[]); 92 | Value* InequalityFn(const char* name, State* state, int argc, Expr* argv[]); 93 | Value* SequenceFn(const char* name, State* state, int argc, Expr* argv[]); 94 | 95 | // Convenience function for building expressions with a fixed number 96 | // of arguments. 97 | Expr* Build(Function fn, YYLTYPE loc, int count, ...); 98 | 99 | // Global builtins, registered by RegisterBuiltins(). 100 | Value* IfElseFn(const char* name, State* state, int argc, Expr* argv[]); 101 | Value* AssertFn(const char* name, State* state, int argc, Expr* argv[]); 102 | Value* AbortFn(const char* name, State* state, int argc, Expr* argv[]); 103 | 104 | 105 | // For setting and getting the global error string (when returning 106 | // NULL from a function). 107 | void SetError(const char* message); // makes a copy 108 | const char* GetError(); // retains ownership 109 | void ClearError(); 110 | 111 | 112 | typedef struct { 113 | const char* name; 114 | Function fn; 115 | } NamedFunction; 116 | 117 | // Register a new function. The same Function may be registered under 118 | // multiple names, but a given name should only be used once. 119 | void RegisterFunction(const char* name, Function fn); 120 | 121 | // Register all the builtins. 122 | void RegisterBuiltins(); 123 | 124 | // Call this after all calls to RegisterFunction() but before parsing 125 | // any scripts to finish building the function table. 126 | void FinishRegistration(); 127 | 128 | // Find the Function for a given name; return NULL if no such function 129 | // exists. 130 | Function FindFunction(const char* name); 131 | 132 | 133 | // --- convenience functions for use in functions --- 134 | 135 | // Evaluate the expressions in argv, giving 'count' char* (the ... is 136 | // zero or more char** to put them in). If any expression evaluates 137 | // to NULL, free the rest and return -1. Return 0 on success. 138 | int ReadArgs(State* state, Expr* argv[], int count, ...); 139 | 140 | // Evaluate the expressions in argv, giving 'count' Value* (the ... is 141 | // zero or more Value** to put them in). If any expression evaluates 142 | // to NULL, free the rest and return -1. Return 0 on success. 143 | int ReadValueArgs(State* state, Expr* argv[], int count, ...); 144 | 145 | // Evaluate the expressions in argv, returning an array of char* 146 | // results. If any evaluate to NULL, free the rest and return NULL. 147 | // The caller is responsible for freeing the returned array and the 148 | // strings it contains. 149 | char** ReadVarArgs(State* state, int argc, Expr* argv[]); 150 | 151 | // Evaluate the expressions in argv, returning an array of Value* 152 | // results. If any evaluate to NULL, free the rest and return NULL. 153 | // The caller is responsible for freeing the returned array and the 154 | // Values it contains. 155 | Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]); 156 | 157 | // Use printf-style arguments to compose an error message to put into 158 | // *state. Returns NULL. 159 | Value* ErrorAbort(State* state, const char* format, ...) __attribute__((format(printf, 2, 3))); 160 | 161 | // Wrap a string into a Value, taking ownership of the string. 162 | Value* StringValue(char* str); 163 | 164 | // Free a Value object. 165 | void FreeValue(Value* v); 166 | 167 | int parse_string(const char* str, Expr** root, int* error_count); 168 | 169 | #ifdef __cplusplus 170 | } // extern "C" 171 | #endif 172 | 173 | #endif // _EXPRESSION_H 174 | -------------------------------------------------------------------------------- /jni/edify/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef parser_h 2 | #define parser_h 3 | /* A Bison parser, made by GNU Bison 2.7. */ 4 | 5 | /* Bison interface for Yacc-like parsers in C 6 | 7 | Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . */ 21 | 22 | /* As a special exception, you may create a larger work that contains 23 | part or all of the Bison parser skeleton and distribute that work 24 | under terms of your choice, so long as that work isn't itself a 25 | parser generator using the skeleton or a modified version thereof 26 | as a parser skeleton. Alternatively, if you modify or redistribute 27 | the parser skeleton itself, you may (at your option) remove this 28 | special exception, which will cause the skeleton and the resulting 29 | Bison output files to be licensed under the GNU General Public 30 | License without this special exception. 31 | 32 | This special exception was added by the Free Software Foundation in 33 | version 2.2 of Bison. */ 34 | 35 | #ifndef YY_YY_OUT_TARGET_PRODUCT_GENERIC_OBJ_STATIC_LIBRARIES_LIBEDIFY_INTERMEDIATES_PARSER_HPP_INCLUDED 36 | # define YY_YY_OUT_TARGET_PRODUCT_GENERIC_OBJ_STATIC_LIBRARIES_LIBEDIFY_INTERMEDIATES_PARSER_HPP_INCLUDED 37 | /* Enabling traces. */ 38 | #ifndef YYDEBUG 39 | # define YYDEBUG 0 40 | #endif 41 | #if YYDEBUG 42 | extern int yydebug; 43 | #endif 44 | 45 | /* Tokens. */ 46 | #ifndef YYTOKENTYPE 47 | # define YYTOKENTYPE 48 | /* Put the tokens into the symbol table, so that GDB and other debuggers 49 | know about them. */ 50 | enum yytokentype { 51 | AND = 258, 52 | OR = 259, 53 | SUBSTR = 260, 54 | SUPERSTR = 261, 55 | EQ = 262, 56 | NE = 263, 57 | IF = 264, 58 | THEN = 265, 59 | ELSE = 266, 60 | ENDIF = 267, 61 | STRING = 268, 62 | BAD = 269 63 | }; 64 | #endif 65 | 66 | 67 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 68 | typedef union YYSTYPE 69 | { 70 | /* Line 2058 of yacc.c */ 71 | #line 40 "bootable/recovery/edify/parser.y" 72 | 73 | char* str; 74 | Expr* expr; 75 | struct { 76 | int argc; 77 | Expr** argv; 78 | } args; 79 | 80 | 81 | /* Line 2058 of yacc.c */ 82 | #line 81 "out/target/product/generic/obj/STATIC_LIBRARIES/libedify_intermediates/parser.hpp" 83 | } YYSTYPE; 84 | # define YYSTYPE_IS_TRIVIAL 1 85 | # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 86 | # define YYSTYPE_IS_DECLARED 1 87 | #endif 88 | 89 | #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED 90 | typedef struct YYLTYPE 91 | { 92 | int first_line; 93 | int first_column; 94 | int last_line; 95 | int last_column; 96 | } YYLTYPE; 97 | # define yyltype YYLTYPE /* obsolescent; will be withdrawn */ 98 | # define YYLTYPE_IS_DECLARED 1 99 | # define YYLTYPE_IS_TRIVIAL 1 100 | #endif 101 | 102 | extern YYSTYPE yylval; 103 | extern YYLTYPE yylloc; 104 | #ifdef YYPARSE_PARAM 105 | #if defined __STDC__ || defined __cplusplus 106 | int yyparse (void *YYPARSE_PARAM); 107 | #else 108 | int yyparse (); 109 | #endif 110 | #else /* ! YYPARSE_PARAM */ 111 | #if defined __STDC__ || defined __cplusplus 112 | int yyparse (Expr** root, int* error_count); 113 | #else 114 | int yyparse (); 115 | #endif 116 | #endif /* ! YYPARSE_PARAM */ 117 | 118 | #endif /* !YY_YY_OUT_TARGET_PRODUCT_GENERIC_OBJ_STATIC_LIBRARIES_LIBEDIFY_INTERMEDIATES_PARSER_HPP_INCLUDED */ 119 | #endif 120 | -------------------------------------------------------------------------------- /jni/edify/yydefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 _YYDEFS_H_ 18 | #define _YYDEFS_H_ 19 | 20 | #define YYLTYPE YYLTYPE 21 | typedef struct { 22 | int start, end; 23 | } YYLTYPE; 24 | 25 | #define YYLLOC_DEFAULT(Current, Rhs, N) \ 26 | do { \ 27 | if (N) { \ 28 | (Current).start = YYRHSLOC(Rhs, 1).start; \ 29 | (Current).end = YYRHSLOC(Rhs, N).end; \ 30 | } else { \ 31 | (Current).start = YYRHSLOC(Rhs, 0).start; \ 32 | (Current).end = YYRHSLOC(Rhs, 0).end; \ 33 | } \ 34 | } while (0) 35 | 36 | int yylex(); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /jni/ext4_utils/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | libext4_utils_src_files := \ 3 | make_ext4fs.c \ 4 | ext4fixup.c \ 5 | ext4_utils.c \ 6 | allocate.c \ 7 | contents.c \ 8 | extent.c \ 9 | indirect.c \ 10 | uuid.c \ 11 | sha1.c \ 12 | wipe.c \ 13 | crc16.c \ 14 | ext4_sb.c 15 | 16 | include $(CLEAR_VARS) 17 | LOCAL_SRC_FILES := $(libext4_utils_src_files) 18 | LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -DNDEBUG 19 | LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -DNDEBUG 20 | LOCAL_MODULE := libext4_utils_static 21 | LOCAL_STATIC_LIBRARIES += \ 22 | libsparse_static 23 | include $(BUILD_STATIC_LIBRARY) 24 | -------------------------------------------------------------------------------- /jni/ext4_utils/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(); 42 | void block_allocator_free(); 43 | u32 allocate_block(); 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(); 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(); 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 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 "private/android_filesystem_config.h" 24 | 25 | #include "canned_fs_config.h" 26 | 27 | typedef struct { 28 | const char* path; 29 | unsigned uid; 30 | unsigned gid; 31 | unsigned mode; 32 | uint64_t capabilities; 33 | } Path; 34 | 35 | static Path* canned_data = NULL; 36 | static int canned_alloc = 0; 37 | static int canned_used = 0; 38 | 39 | static int path_compare(const void* a, const void* b) { 40 | return strcmp(((Path*)a)->path, ((Path*)b)->path); 41 | } 42 | 43 | int load_canned_fs_config(const char* fn) { 44 | FILE* f = fopen(fn, "r"); 45 | if (f == NULL) { 46 | fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); 47 | return -1; 48 | } 49 | 50 | char line[PATH_MAX + 200]; 51 | while (fgets(line, sizeof(line), f)) { 52 | while (canned_used >= canned_alloc) { 53 | canned_alloc = (canned_alloc+1) * 2; 54 | canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); 55 | } 56 | Path* p = canned_data + canned_used; 57 | p->path = strdup(strtok(line, " ")); 58 | p->uid = atoi(strtok(NULL, " ")); 59 | p->gid = atoi(strtok(NULL, " ")); 60 | p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal 61 | p->capabilities = 0; 62 | 63 | char* token = NULL; 64 | do { 65 | token = strtok(NULL, " "); 66 | if (token && strncmp(token, "capabilities=", 13) == 0) { 67 | p->capabilities = strtoll(token+13, NULL, 0); 68 | break; 69 | } 70 | } while (token); 71 | 72 | canned_used++; 73 | } 74 | 75 | fclose(f); 76 | 77 | qsort(canned_data, canned_used, sizeof(Path), path_compare); 78 | printf("loaded %d fs_config entries\n", canned_used); 79 | 80 | return 0; 81 | } 82 | 83 | void canned_fs_config(const char* path, int dir, 84 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { 85 | Path key; 86 | key.path = path+1; // canned paths lack the leading '/' 87 | Path* p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); 88 | if (p == NULL) { 89 | fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); 90 | exit(1); 91 | } 92 | *uid = p->uid; 93 | *gid = p->gid; 94 | *mode = p->mode; 95 | *capabilities = p->capabilities; 96 | 97 | #if 0 98 | // for debugging, run the built-in fs_config and compare the results. 99 | 100 | unsigned c_uid, c_gid, c_mode; 101 | uint64_t c_capabilities; 102 | fs_config(path, dir, &c_uid, &c_gid, &c_mode, &c_capabilities); 103 | 104 | if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); 105 | if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); 106 | if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); 107 | if (c_capabilities != *capabilities) printf("%s capabilities %llx %llx\n", path, *capabilities, c_capabilities); 108 | #endif 109 | } 110 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | void canned_fs_config(const char* path, int dir, 24 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | char *secon; 33 | uint64_t capabilities; 34 | }; 35 | 36 | u32 make_directory(u32 dir_inode_num, u32 entries, struct dentry *dentries, 37 | u32 dirs); 38 | u32 make_file(const char *filename, u64 len); 39 | u32 make_link(const char *link); 40 | int inode_set_permissions(u32 inode_num, u16 mode, u16 uid, u16 gid, u32 mtime); 41 | int inode_set_selinux(u32 inode_num, const char *secon); 42 | int inode_set_capabilities(u32 inode_num, uint64_t capabilities); 43 | struct block_allocation* get_saved_allocation_chain(); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/ext2simg.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 | #define _FILE_OFFSET_BITS 64 18 | #define _LARGEFILE64_SOURCE 1 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "ext4_utils.h" 31 | #include "make_ext4fs.h" 32 | #include "allocate.h" 33 | 34 | #if defined(__APPLE__) && defined(__MACH__) 35 | #define off64_t off_t 36 | #endif 37 | 38 | #ifndef USE_MINGW /* O_BINARY is windows-specific flag */ 39 | #define O_BINARY 0 40 | #endif 41 | 42 | extern struct fs_info info; 43 | 44 | static int verbose = 0; 45 | 46 | static void usage(char *path) 47 | { 48 | fprintf(stderr, "%s [ options ] \n", path); 49 | fprintf(stderr, "\n"); 50 | fprintf(stderr, " -c include CRC block\n"); 51 | fprintf(stderr, " -v verbose output\n"); 52 | fprintf(stderr, " -z gzip output\n"); 53 | fprintf(stderr, " -S don't use sparse output format\n"); 54 | } 55 | 56 | static int build_sparse_ext(int fd, const char *filename) 57 | { 58 | unsigned int i; 59 | unsigned int block; 60 | int start_contiguous_block; 61 | u8 *block_bitmap; 62 | off64_t ret; 63 | 64 | block_bitmap = malloc(info.block_size); 65 | if (!block_bitmap) 66 | critical_error("failed to allocate block bitmap"); 67 | 68 | if (aux_info.first_data_block > 0) 69 | sparse_file_add_file(ext4_sparse_file, filename, 0, 70 | info.block_size * aux_info.first_data_block, 0); 71 | 72 | for (i = 0; i < aux_info.groups; i++) { 73 | u32 first_block = aux_info.first_data_block + i * info.blocks_per_group; 74 | u32 last_block = min(info.blocks_per_group, aux_info.len_blocks - first_block); 75 | 76 | ret = lseek64(fd, (u64)info.block_size * aux_info.bg_desc[i].bg_block_bitmap, 77 | SEEK_SET); 78 | if (ret < 0) 79 | critical_error_errno("failed to seek to block group bitmap %d", i); 80 | 81 | ret = read(fd, block_bitmap, info.block_size); 82 | if (ret < 0) 83 | critical_error_errno("failed to read block group bitmap %d", i); 84 | if (ret != (int)info.block_size) 85 | critical_error("failed to read all of block group bitmap %d", i); 86 | 87 | start_contiguous_block = -1; 88 | for (block = 0; block < last_block; block++) { 89 | if (start_contiguous_block >= 0) { 90 | if (!bitmap_get_bit(block_bitmap, block)) { 91 | u32 start_block = first_block + start_contiguous_block; 92 | u32 len_blocks = block - start_contiguous_block; 93 | 94 | sparse_file_add_file(ext4_sparse_file, filename, 95 | (u64)info.block_size * start_block, 96 | info.block_size * len_blocks, start_block); 97 | start_contiguous_block = -1; 98 | } 99 | } else { 100 | if (bitmap_get_bit(block_bitmap, block)) 101 | start_contiguous_block = block; 102 | } 103 | } 104 | 105 | if (start_contiguous_block >= 0) { 106 | u32 start_block = first_block + start_contiguous_block; 107 | u32 len_blocks = last_block - start_contiguous_block; 108 | sparse_file_add_file(ext4_sparse_file, filename, 109 | (u64)info.block_size * start_block, 110 | info.block_size * len_blocks, start_block); 111 | } 112 | } 113 | 114 | return 0; 115 | } 116 | 117 | int main(int argc, char **argv) 118 | { 119 | int opt; 120 | const char *in = NULL; 121 | const char *out = NULL; 122 | int gzip = 0; 123 | int sparse = 1; 124 | int infd, outfd; 125 | int crc = 0; 126 | 127 | while ((opt = getopt(argc, argv, "cvzS")) != -1) { 128 | switch (opt) { 129 | case 'c': 130 | crc = 1; 131 | break; 132 | case 'v': 133 | verbose = 1; 134 | break; 135 | case 'z': 136 | gzip = 1; 137 | break; 138 | case 'S': 139 | sparse = 0; 140 | break; 141 | } 142 | } 143 | 144 | if (optind >= argc) { 145 | fprintf(stderr, "Expected image or block device after options\n"); 146 | usage(argv[0]); 147 | exit(EXIT_FAILURE); 148 | } 149 | 150 | in = argv[optind++]; 151 | 152 | if (optind >= argc) { 153 | fprintf(stderr, "Expected output image after input image\n"); 154 | usage(argv[0]); 155 | exit(EXIT_FAILURE); 156 | } 157 | 158 | out = argv[optind++]; 159 | 160 | if (optind < argc) { 161 | fprintf(stderr, "Unexpected argument: %s\n", argv[optind]); 162 | usage(argv[0]); 163 | exit(EXIT_FAILURE); 164 | } 165 | 166 | infd = open(in, O_RDONLY); 167 | 168 | if (infd < 0) 169 | critical_error_errno("failed to open input image"); 170 | 171 | read_ext(infd, verbose); 172 | 173 | ext4_sparse_file = sparse_file_new(info.block_size, info.len); 174 | 175 | build_sparse_ext(infd, in); 176 | 177 | close(infd); 178 | 179 | if (strcmp(out, "-")) { 180 | outfd = open(out, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); 181 | if (outfd < 0) { 182 | error_errno("open"); 183 | return EXIT_FAILURE; 184 | } 185 | } else { 186 | outfd = STDOUT_FILENO; 187 | } 188 | 189 | write_ext4_image(outfd, gzip, sparse, crc); 190 | close(outfd); 191 | 192 | sparse_file_destroy(ext4_sparse_file); 193 | 194 | return 0; 195 | } 196 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | const char *label; 43 | uint8_t no_journal; 44 | }; 45 | 46 | int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #if defined(__APPLE__) && defined(__MACH__) 42 | #define lseek64 lseek 43 | #define ftruncate64 ftruncate 44 | #define mmap64 mmap 45 | #define off64_t off_t 46 | #endif 47 | 48 | #include "ext4_sb.h" 49 | 50 | extern int force; 51 | 52 | #define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0) 53 | #define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) longjmp(setjmp_env, EXIT_FAILURE); } while (0) 54 | #define error_errno(s, args...) error(s ": %s", ##args, strerror(errno)) 55 | #define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); longjmp(setjmp_env, EXIT_FAILURE); } while (0) 56 | #define critical_error_errno(s, args...) critical_error(s ": %s", ##args, strerror(errno)) 57 | 58 | #define EXT4_JNL_BACKUP_BLOCKS 1 59 | 60 | #ifndef min /* already defined by windows.h */ 61 | #define min(a, b) ((a) < (b) ? (a) : (b)) 62 | #endif 63 | 64 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y)) 65 | #define EXT4_ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y))) 66 | 67 | /* XXX */ 68 | #define cpu_to_le32(x) (x) 69 | #define cpu_to_le16(x) (x) 70 | #define le32_to_cpu(x) (x) 71 | #define le16_to_cpu(x) (x) 72 | 73 | #ifdef __LP64__ 74 | typedef unsigned long u64; 75 | typedef signed long s64; 76 | #else 77 | typedef unsigned long long u64; 78 | typedef signed long long s64; 79 | #endif 80 | typedef unsigned int u32; 81 | typedef unsigned short int u16; 82 | typedef unsigned char u8; 83 | 84 | struct block_group_info; 85 | struct xattr_list_element; 86 | 87 | struct ext2_group_desc { 88 | u32 bg_block_bitmap; 89 | u32 bg_inode_bitmap; 90 | u32 bg_inode_table; 91 | u16 bg_free_blocks_count; 92 | u16 bg_free_inodes_count; 93 | u16 bg_used_dirs_count; 94 | u16 bg_flags; 95 | u32 bg_reserved[2]; 96 | u16 bg_reserved16; 97 | u16 bg_checksum; 98 | }; 99 | 100 | struct fs_aux_info { 101 | struct ext4_super_block *sb; 102 | struct ext4_super_block **backup_sb; 103 | struct ext2_group_desc *bg_desc; 104 | struct block_group_info *bgs; 105 | struct xattr_list_element *xattrs; 106 | u32 first_data_block; 107 | u64 len_blocks; 108 | u32 inode_table_blocks; 109 | u32 groups; 110 | u32 bg_desc_blocks; 111 | u32 default_i_flags; 112 | u32 blocks_per_ind; 113 | u32 blocks_per_dind; 114 | u32 blocks_per_tind; 115 | }; 116 | 117 | extern struct fs_info info; 118 | extern struct fs_aux_info aux_info; 119 | extern struct sparse_file *ext4_sparse_file; 120 | 121 | extern jmp_buf setjmp_env; 122 | 123 | static inline int log_2(int j) 124 | { 125 | int i; 126 | 127 | for (i = 0; j > 0; i++) 128 | j >>= 1; 129 | 130 | return i - 1; 131 | } 132 | 133 | int bitmap_get_bit(u8 *bitmap, u32 bit); 134 | void bitmap_clear_bit(u8 *bitmap, u32 bit); 135 | int ext4_bg_has_super_block(int bg); 136 | void read_sb(int fd, struct ext4_super_block *sb); 137 | void write_sb(int fd, unsigned long long offset, struct ext4_super_block *sb); 138 | void write_ext4_image(int fd, int gz, int sparse, int crc); 139 | void ext4_create_fs_aux_info(void); 140 | void ext4_free_fs_aux_info(void); 141 | void ext4_fill_in_sb(void); 142 | void ext4_create_resize_inode(void); 143 | void ext4_create_journal_inode(void); 144 | void ext4_update_free(void); 145 | void ext4_queue_sb(void); 146 | u64 get_block_device_size(int fd); 147 | int is_block_device_fd(int fd); 148 | u64 get_file_size(int fd); 149 | u64 parse_num(const char *arg); 150 | void ext4_parse_sb_info(struct ext4_super_block *sb); 151 | u16 ext4_crc16(u16 crc_in, const void *buf, int size); 152 | 153 | typedef void (*fs_config_func_t)(const char *path, int dir, unsigned *uid, unsigned *gid, 154 | unsigned *mode, uint64_t *capabilities); 155 | 156 | struct selabel_handle; 157 | 158 | int make_ext4fs_internal(int fd, const char *directory, 159 | const char *mountpoint, fs_config_func_t fs_config_func, int gzip, 160 | int sparse, int crc, int wipe, 161 | struct selabel_handle *sehnd, int verbose, time_t fixed_time, 162 | FILE* block_list_file); 163 | 164 | int read_ext(int fd, int verbose); 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/ext4fixup_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 | #include "ext4fixup.h" 22 | 23 | static void usage(char *me) 24 | { 25 | fprintf(stderr, "%s: usage: %s [-vn] \n", me, me); 26 | } 27 | 28 | int main(int argc, char **argv) 29 | { 30 | int opt; 31 | int verbose = 0; 32 | int no_write = 0; 33 | char *fsdev; 34 | char *me; 35 | int stop_phase = 0, stop_loc = 0, stop_count = 0; 36 | 37 | me = basename(argv[0]); 38 | 39 | while ((opt = getopt(argc, argv, "vnd:")) != -1) { 40 | switch (opt) { 41 | case 'v': 42 | verbose = 1; 43 | break; 44 | case 'n': 45 | no_write = 1; 46 | break; 47 | case 'd': 48 | sscanf(optarg, "%d,%d,%d", &stop_phase, &stop_loc, &stop_count); 49 | break; 50 | } 51 | } 52 | 53 | if (optind >= argc) { 54 | fprintf(stderr, "expected image or block device after options\n"); 55 | usage(me); 56 | exit(EXIT_FAILURE); 57 | } 58 | 59 | fsdev = argv[optind++]; 60 | 61 | if (optind < argc) { 62 | fprintf(stderr, "Unexpected argument: %s\n", argv[optind]); 63 | usage(me); 64 | exit(EXIT_FAILURE); 65 | } 66 | 67 | return ext4fixup_internal(fsdev, verbose, no_write, stop_phase, stop_loc, stop_count); 68 | } 69 | -------------------------------------------------------------------------------- /jni/ext4_utils/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(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /jni/ext4_utils/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(); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | -------------------------------------------------------------------------------- /jni/ext4_utils/make_ext4fs.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 _MAKE_EXT4FS_H_ 18 | #define _MAKE_EXT4FS_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | struct selabel_handle; 25 | 26 | int make_ext4fs(const char *filename, long long len, 27 | const char *mountpoint, struct selabel_handle *sehnd); 28 | int make_ext4fs_sparse_fd(int fd, long long len, 29 | const char *mountpoint, struct selabel_handle *sehnd); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /jni/ext4_utils/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 | #ifdef ANDROID 29 | #include 30 | #endif 31 | 32 | #ifndef USE_MINGW 33 | #include 34 | #include 35 | #include 36 | #else 37 | struct selabel_handle; 38 | #endif 39 | 40 | #include "make_ext4fs.h" 41 | #include "ext4_utils.h" 42 | #include "canned_fs_config.h" 43 | 44 | #ifndef USE_MINGW /* O_BINARY is windows-specific flag */ 45 | #define O_BINARY 0 46 | #endif 47 | 48 | extern struct fs_info info; 49 | 50 | 51 | static void usage(char *path) 52 | { 53 | fprintf(stderr, "%s [ -l ] [ -j ] [ -b ]\n", basename(path)); 54 | fprintf(stderr, " [ -g ] [ -i ] [ -I ]\n"); 55 | fprintf(stderr, " [ -L