Commit c4198986 authored by Ondrej Kozina's avatar Ondrej Kozina Committed by Milan Broz

Sort LUKS2 segments by keys in crypt_dump output.

parent 7514786b
......@@ -35,6 +35,7 @@
#define LUKS2_TOKENS_MAX 32
#define LUKS2_SEGMENT_MAX 32
......@@ -1530,40 +1530,45 @@ static void hdr_dump_tokens(struct crypt_device *cd, json_object *hdr_jobj)
/* FIXME: sort segments when more segments available later */
static void hdr_dump_segments(struct crypt_device *cd, json_object *hdr_jobj)
json_object *jobj1, *jobj2, *jobj3;
char segment[16];
json_object *jobj_segments, *jobj_segment, *jobj1, *jobj2;
int i;
uint64_t value;
log_std(cd, "Data segments:\n");
json_object_object_get_ex(hdr_jobj, "segments", &jobj1);
json_object_object_get_ex(hdr_jobj, "segments", &jobj_segments);
json_object_object_foreach(jobj1, key, val) {
json_object_object_get_ex(val, "type", &jobj2);
log_std(cd, " %s: %s\n", key, json_object_get_string(jobj2));
for (i = 0; i < LUKS2_SEGMENT_MAX; i++) {
(void) snprintf(segment, sizeof(segment), "%i", i);
if (!json_object_object_get_ex(jobj_segments, segment, &jobj_segment))
json_object_object_get_ex(jobj_segment, "type", &jobj1);
log_std(cd, " %s: %s\n", segment, json_object_get_string(jobj1));
json_object_object_get_ex(val, "offset", &jobj3);
json_str_to_uint64(jobj3, &value);
json_object_object_get_ex(jobj_segment, "offset", &jobj1);
json_str_to_uint64(jobj1, &value);
log_std(cd, "\toffset: %" PRIu64 " [bytes]\n", value);
json_object_object_get_ex(val, "size", &jobj3);
if (!(strcmp(json_object_get_string(jobj3), "dynamic")))
json_object_object_get_ex(jobj_segment, "size", &jobj1);
if (!(strcmp(json_object_get_string(jobj1), "dynamic")))
log_std(cd, "\tlength: (whole device)\n");
else {
json_str_to_uint64(jobj3, &value);
json_str_to_uint64(jobj1, &value);
log_std(cd, "\tlength: %" PRIu64 " [bytes]\n", value);
if (json_object_object_get_ex(val, "encryption", &jobj3))
log_std(cd, "\tcipher: %s\n", json_object_get_string(jobj3));
if (json_object_object_get_ex(jobj_segment, "encryption", &jobj1))
log_std(cd, "\tcipher: %s\n", json_object_get_string(jobj1));
if (json_object_object_get_ex(val, "sector_size", &jobj3))
log_std(cd, "\tsector: %" PRIu32 " [bytes]\n", json_object_get_uint32(jobj3));
if (json_object_object_get_ex(jobj_segment, "sector_size", &jobj1))
log_std(cd, "\tsector: %" PRIu32 " [bytes]\n", json_object_get_uint32(jobj1));
if (json_object_object_get_ex(val, "integrity", &jobj2) &&
json_object_object_get_ex(jobj2, "type", &jobj3))
log_std(cd, "\tintegrity: %s\n", json_object_get_string(jobj3));
if (json_object_object_get_ex(jobj_segment, "integrity", &jobj1) &&
json_object_object_get_ex(jobj1, "type", &jobj2))
log_std(cd, "\tintegrity: %s\n", json_object_get_string(jobj2));
log_std(cd, "\n");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment