diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2016-11-20 06:27:01 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-20 06:27:01 +0000 |
commit | 8a05232e6a6d5e8b1614075a49681a9ef23a54d2 (patch) | |
tree | ea986f365d80ac55f6923be4e5900344340870ab | |
parent | 4f492d7c7d69904edd10f28dd6d2b6bae1cde779 (diff) | |
parent | 61fce29c45cd5c2b94b836d68b49d231b0c6d2bb (diff) | |
download | extras-8a05232e6a6d5e8b1614075a49681a9ef23a54d2.tar.gz |
DO NOT MERGE: fec: add --padding
am: 61fce29c45
Change-Id: Ia302825abf17edc824a37cd3085f02946deb9d12
-rw-r--r-- | verity/fec/image.cpp | 29 | ||||
-rw-r--r-- | verity/fec/image.h | 1 | ||||
-rw-r--r-- | verity/fec/main.cpp | 15 |
3 files changed, 35 insertions, 10 deletions
diff --git a/verity/fec/image.cpp b/verity/fec/image.cpp index 7c1eab76..62f797b9 100644 --- a/verity/fec/image.cpp +++ b/verity/fec/image.cpp @@ -291,14 +291,11 @@ bool image_ecc_load(const std::string& filename, image *ctx) bool image_ecc_save(image *ctx) { - assert(sizeof(fec_header) <= FEC_BLOCKSIZE); - - uint8_t header[FEC_BLOCKSIZE]; - uint8_t *p = header; + assert(2 * sizeof(fec_header) <= FEC_BLOCKSIZE); - memset(p, 0, FEC_BLOCKSIZE); + uint8_t header[FEC_BLOCKSIZE] = {0}; - fec_header *f = (fec_header *)p; + fec_header *f = (fec_header *)header; f->magic = FEC_MAGIC; f->version = FEC_VERSION; @@ -310,7 +307,8 @@ bool image_ecc_save(image *ctx) SHA256(ctx->fec, ctx->fec_size, f->hash); /* store a copy of the fec_header at the end of the header block */ - memcpy(&p[sizeof(header) - sizeof(fec_header)], p, sizeof(fec_header)); + memcpy(&header[sizeof(header) - sizeof(fec_header)], header, + sizeof(fec_header)); assert(ctx->fec_filename); @@ -322,11 +320,24 @@ bool image_ecc_save(image *ctx) strerror(errno)); } - if (!android::base::WriteFully(fd, ctx->fec, ctx->fec_size) || - !android::base::WriteFully(fd, header, sizeof(header))) { + if (!android::base::WriteFully(fd, ctx->fec, ctx->fec_size)) { FATAL("failed to write to output: %s\n", strerror(errno)); } + if (ctx->padding > 0) { + uint8_t padding[FEC_BLOCKSIZE] = {0}; + + for (uint32_t i = 0; i < ctx->padding; i += FEC_BLOCKSIZE) { + if (!android::base::WriteFully(fd, padding, FEC_BLOCKSIZE)) { + FATAL("failed to write padding: %s\n", strerror(errno)); + } + } + } + + if (!android::base::WriteFully(fd, header, sizeof(header))) { + FATAL("failed to write to header: %s\n", strerror(errno)); + } + close(fd); return true; diff --git a/verity/fec/image.h b/verity/fec/image.h index 72048c6a..64f0e42e 100644 --- a/verity/fec/image.h +++ b/verity/fec/image.h @@ -52,6 +52,7 @@ struct image { int rs_n; int threads; uint32_t fec_size; + uint32_t padding; uint64_t blocks; uint64_t inp_size; uint64_t pos; diff --git a/verity/fec/main.cpp b/verity/fec/main.cpp index 8dbb95d1..9998142b 100644 --- a/verity/fec/main.cpp +++ b/verity/fec/main.cpp @@ -107,6 +107,8 @@ static int usage() " -r, --roots=<bytes> number of parity bytes\n" " -j, --threads=<threads> number of threads to use\n" " -S treat data as a sparse file\n" + "encoding options:\n" + " -p, --padding=<bytes> add padding after ECC data\n" "decoding options:\n" " -i, --inplace correct <data> in place\n" ); @@ -220,6 +222,10 @@ static int decode(image& ctx, const std::vector<std::string>& inp_filenames, "files\n"); } + if (ctx.padding) { + FATAL("invalid parameters: padding is only relevant when encoding\n"); + } + if (!image_ecc_load(fec_filename, &ctx) || !image_load(inp_filenames, &ctx)) { FATAL("failed to read input\n"); @@ -284,10 +290,11 @@ int main(int argc, char **argv) {"print-fec-size", required_argument, 0, 's'}, {"get-ecc-start", required_argument, 0, 'E'}, {"get-verity-start", required_argument, 0, 'V'}, + {"padding", required_argument, 0, 'p'}, {"verbose", no_argument, 0, 'v'}, {NULL, 0, 0, 0} }; - int c = getopt_long(argc, argv, "hedSr:imj:s:E:V:v", long_options, NULL); + int c = getopt_long(argc, argv, "hedSr:ij:s:E:V:p:v", long_options, NULL); if (c < 0) { break; } @@ -339,6 +346,12 @@ int main(int argc, char **argv) mode = MODE_GETVERITYSTART; inp_filenames.push_back(optarg); break; + case 'p': + ctx.padding = (uint32_t)parse_arg(optarg, "padding", UINT32_MAX); + if (ctx.padding % FEC_BLOCKSIZE) { + FATAL("padding must be multiple of %u\n", FEC_BLOCKSIZE); + } + break; case 'v': ctx.verbose = true; break; |