diff options
author | LonelyFool <2655294004@qq.com> | 2021-03-18 16:17:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-18 16:17:00 +0800 |
commit | c9128e2006a7f4d317c6e883b7c6cc96fa0cf8cc (patch) | |
tree | 986b535e0146db6e597c4842c9fbe2d8bc1763ee | |
parent | 85c77370eea40aa5cc6e4c154f8624c0d8cb9988 (diff) | |
parent | 504699665ea19e8d3a9d986afc372c0634549b92 (diff) | |
download | dynpart-tools-c9128e2006a7f4d317c6e883b7c6cc96fa0cf8cc.tar.gz dynpart-tools-c9128e2006a7f4d317c6e883b7c6cc96fa0cf8cc.tar.bz2 dynpart-tools-c9128e2006a7f4d317c6e883b7c6cc96fa0cf8cc.zip |
Merge pull request #1 from FlyGoat/master
Add lpdump and lpadd
-rw-r--r-- | .gitignore | 7 | ||||
-rwxr-xr-x | make.sh | 8 | ||||
-rwxr-xr-x | partition_tools/lpadd.cc | 1 | ||||
-rwxr-xr-x | partition_tools/lpdump.cc | 21 |
4 files changed, 35 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75f073a --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.img +*.o +*.a +lpdump +lpmake +lpunpack +lpadd @@ -296,8 +296,16 @@ if [ "$HOSTTYPE" = i686 ] || [ "$HOSTTYPE" = x86_64 ];then clang++ -static -std=c++17 -I../include -o ../lpunpack lpunpack.cc ../liblp/liblp.a ../libsparse/libsparse.a -lz ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread clang++ -static -std=c++17 -I../include -o ../lpmake lpmake.cc ../liblp/liblp.a ../libsparse/libsparse.a -lz ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread + + clang++ -static -std=c++17 -I../include -o ../lpdump lpdump_host.cc lpdump.cc ../liblp/liblp.a ../libsparse/libsparse.a -lz ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread + + clang++ -static -std=c++17 -I../include -o ../lpadd lpadd.cc ../liblp/liblp.a ../libsparse/libsparse.a -lz ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread else clang++ -static -std=c++17 -I../include -o ../lpunpack lpunpack.cc ../liblp/liblp.a ../libsparse/libsparse.a ../zlib/libz.a ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread clang++ -static -std=c++17 -I../include -o ../lpmake lpmake.cc ../liblp/liblp.a ../libsparse/libsparse.a ../zlib/libz.a ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread + + clang++ -static -std=c++17 -I../include -o ../lpdump lpdump_host.cc lpdump.c ../liblp/liblp.a ../libsparse/libsparse.a ../zlib/libz.a ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread + + clang++ -static -std=c++17 -I../include -o ../lpadd lpadd.cc ../liblp/liblp.a ../libsparse/libsparse.a ../zlib/libz.a ../base/libbase.a ../liblog/liblog.a ../crypto/libcrypto.a ../libcrypto_utils/libcrypto_utils.a ../ext4_utils/libext4_utils.a -lpthread fi diff --git a/partition_tools/lpadd.cc b/partition_tools/lpadd.cc index 48cad72..f9a4b2d 100755 --- a/partition_tools/lpadd.cc +++ b/partition_tools/lpadd.cc @@ -15,6 +15,7 @@ #include <getopt.h> #include <sysexits.h> #include <unistd.h> +#include <string.h> #include <iostream> #include <optional> diff --git a/partition_tools/lpdump.cc b/partition_tools/lpdump.cc index 047b5ee..7f518fd 100755 --- a/partition_tools/lpdump.cc +++ b/partition_tools/lpdump.cc @@ -37,11 +37,15 @@ #include <cutils/android_get_control_file.h> #include <fs_mgr.h> #endif +#ifdef ENABLE_JSON #include <jsonpb/jsonpb.h> +#endif #include <liblp/builder.h> #include <liblp/liblp.h> +#ifdef ENABLE_JSON #include "dynamic_partitions_device_info.pb.h" +#endif using namespace android; using namespace android::fs_mgr; @@ -56,7 +60,9 @@ static int usage(int /* argc */, char* argv[], std::ostream& cerr) { "\n" "Options:\n" " -s, --slot=N Slot number or suffix.\n" +#ifdef ENABLE_JSON " -j, --json Print in JSON format.\n" +#endif " -d, --dump-metadata-size\n" " Print the space reserved for metadata to stdout\n" " in bytes.\n" @@ -132,6 +138,7 @@ static std::string RemoveSuffix(const std::string& s, const std::string& suffix) return s; } +#ifdef ENABLE_JSON // Merge proto with information from metadata. static bool MergeMetadata(const LpMetadata* metadata, DynamicPartitionsDeviceInfoProto* proto) { @@ -268,6 +275,7 @@ static int PrintJson(const LpMetadata* metadata, std::ostream& cout, cout << *error_or_json; return EX_OK; } +#endif static int DumpMetadataSize(const LpMetadata& metadata, std::ostream& cout) { auto super_device = GetMetadataSuperBlockDevice(metadata); @@ -393,7 +401,9 @@ int LpdumpMain(int argc, char* argv[], std::ostream& cout, std::ostream& cerr) { { "all", no_argument, nullptr, 'a' }, { "slot", required_argument, nullptr, 's' }, { "help", no_argument, nullptr, 'h' }, +#ifdef ENABLE_JSON { "json", no_argument, nullptr, 'j' }, +#endif { "dump-metadata-size", no_argument, nullptr, 'd' }, { "is-super-empty", no_argument, nullptr, 'e' }, { nullptr, 0, nullptr, 0 }, @@ -405,7 +415,9 @@ int LpdumpMain(int argc, char* argv[], std::ostream& cout, std::ostream& cerr) { int rv; int index; +#ifdef ENABLE_JSON bool json = false; +#endif bool dump_metadata_size = false; bool dump_all = false; std::optional<uint32_t> slot; @@ -432,9 +444,11 @@ int LpdumpMain(int argc, char* argv[], std::ostream& cout, std::ostream& cerr) { case 'd': dump_metadata_size = true; break; +#ifdef ENABLE_JSON case 'j': json = true; break; +#endif case '?': case ':': return usage(argc, argv, cerr); @@ -446,11 +460,12 @@ int LpdumpMain(int argc, char* argv[], std::ostream& cout, std::ostream& cerr) { cerr << "Cannot specify both --all and --slot.\n"; return usage(argc, argv, cerr); } +#ifdef ENABLE_JSON if (json) { cerr << "Cannot specify both --all and --json.\n"; return usage(argc, argv, cerr); } - +#endif // When dumping everything always start from the first slot. slot = 0; } @@ -486,11 +501,13 @@ int LpdumpMain(int argc, char* argv[], std::ostream& cout, std::ostream& cerr) { auto pt = ReadDeviceOrFile(super_path, slot.value()); +#ifdef ENABLE_JSON // --json option doesn't require metadata to be present. if (json) { return PrintJson(pt.get(), cout, cerr); } - +#endif + if (!pt) { cerr << "Failed to read metadata.\n"; return EX_NOINPUT; |