Add FEC info to init_by_name.

And use it in veritysetup dump.
This commit is contained in:
Milan Broz
2017-04-03 13:55:20 +02:00
parent fc0bef732b
commit 6c8b3686b4
4 changed files with 57 additions and 4 deletions

View File

@@ -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(&params, " ");
@@ -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(&params, " ");
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, &params, 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, &params, 10);
if (*params)
params++;
dmd->u.verity.fec_blocks = val64;
i++;
} else if (!strcasecmp(arg, "fec_roots")) {
val32 = strtoul(params, &params, 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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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))