From 6c8b3686b41c7b5169eaa819cc34b80488bf01cf Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Mon, 3 Apr 2017 13:55:20 +0200 Subject: [PATCH] Add FEC info to init_by_name. And use it in veritysetup dump. --- lib/libdevmapper.c | 43 +++++++++++++++++++++++++++++++++++++++---- lib/setup.c | 6 ++++++ lib/utils_dm.h | 1 + src/veritysetup.c | 11 +++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index be4a6923..8acf93b6 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -982,7 +982,7 @@ static int _dm_query_verity(uint32_t get_flags, uint64_t val64; ssize_t len; char *str, *str2, *arg; - unsigned int i; + unsigned int i, features; int r; if (get_flags & DM_ACTIVE_VERITY_PARAMS) @@ -1099,7 +1099,8 @@ static int _dm_query_verity(uint32_t get_flags, return -EINVAL; params++; - for (i = 0; i < val64; i++) { + features = (int)val64; + for (i = 0; i < features; i++) { if (!params) return -EINVAL; arg = strsep(¶ms, " "); @@ -1109,12 +1110,46 @@ static int _dm_query_verity(uint32_t get_flags, dmd->flags |= CRYPT_ACTIVATE_RESTART_ON_CORRUPTION; else if (!strcasecmp(arg, "ignore_zero_blocks")) dmd->flags |= CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS; - else /* unknown option */ + else if (!strcasecmp(arg, "use_fec_from_device")) { + str = strsep(¶ms, " "); + str2 = crypt_lookup_dev(str); + if (get_flags & DM_ACTIVE_VERITY_HASH_DEVICE) { + r = device_alloc(&dmd->u.verity.fec_device, str2); + if (r < 0 && r != -ENOTBLK) { + free(str2); + return r; + } + } + if (vp) + vp->fec_device = str2; + i++; + } else if (!strcasecmp(arg, "fec_start")) { + val64 = strtoull(params, ¶ms, 10); + if (*params) + params++; + dmd->u.verity.fec_offset = val64; + if (vp) + vp->fec_area_offset = val64 * vp->hash_block_size; + i++; + } else if (!strcasecmp(arg, "fec_blocks")) { + val64 = strtoull(params, ¶ms, 10); + if (*params) + params++; + dmd->u.verity.fec_blocks = val64; + i++; + } else if (!strcasecmp(arg, "fec_roots")) { + val32 = strtoul(params, ¶ms, 10); + if (*params) + params++; + if (vp) + vp->fec_roots = val32; + i++; + } else /* unknown option */ return -EINVAL; } /* All parameters should be processed */ - if (params) + if (params && *params) return -EINVAL; } diff --git a/lib/setup.c b/lib/setup.c index 464f747a..31b61079 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -735,6 +735,9 @@ static int _init_by_name_verity(struct crypt_device *cd, const char *name) cd->u.verity.hdr.flags = params.flags; cd->u.verity.hdr.salt_size = params.salt_size; cd->u.verity.hdr.salt = params.salt; + cd->u.verity.hdr.fec_device = params.fec_device; + cd->u.verity.hdr.fec_roots = params.fec_roots; + cd->u.verity.fec_device = dmd.u.verity.fec_device; cd->metadata_device = dmd.u.verity.hash_device; } out: @@ -2502,6 +2505,9 @@ int crypt_get_verity_info(struct crypt_device *cd, vp->data_device = device_path(cd->device); vp->hash_device = mdata_device_path(cd); + vp->fec_device = device_path(cd->u.verity.fec_device); + vp->fec_area_offset = cd->u.verity.hdr.fec_area_offset; + vp->fec_roots = cd->u.verity.hdr.fec_roots; vp->hash_name = cd->u.verity.hdr.hash_name; vp->salt = cd->u.verity.hdr.salt; vp->salt_size = cd->u.verity.hdr.salt_size; diff --git a/lib/utils_dm.h b/lib/utils_dm.h index 6fa3868c..a0250788 100644 --- a/lib/utils_dm.h +++ b/lib/utils_dm.h @@ -84,6 +84,7 @@ struct crypt_dm_active_device { uint64_t hash_offset; /* hash offset in blocks (not header) */ uint64_t hash_blocks; /* size of hash device (in hash blocks) */ uint64_t fec_offset; /* FEC offset in blocks (not header) */ + uint64_t fec_blocks; /* size of FEC device (in hash blocks) */ struct crypt_params_verity *vp; } verity; } u; diff --git a/src/veritysetup.c b/src/veritysetup.c index 4fa83a3b..fd84636f 100644 --- a/src/veritysetup.c +++ b/src/veritysetup.c @@ -304,6 +304,17 @@ static int action_status(int arg) log_std(" hash offset: %" PRIu64 " sectors\n", vp.hash_area_offset * vp.hash_block_size / 512); + if (vp.fec_device) { + log_std(" FEC device: %s\n", vp.fec_device); + if (crypt_loop_device(vp.fec_device)) { + backing_file = crypt_loop_backing_file(vp.fec_device); + log_std(" FEC loop: %s\n", backing_file); + free(backing_file); + } + log_std(" FEC offset: %" PRIu64 " sectors\n", + vp.fec_area_offset * vp.hash_block_size / 512); + log_std(" FEC roots: %u\n", vp.fec_roots); + } if (cad.flags & (CRYPT_ACTIVATE_IGNORE_CORRUPTION| CRYPT_ACTIVATE_RESTART_ON_CORRUPTION| CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS))