Add helper function to change segment size.

This commit is contained in:
Ondrej Kozina
2023-05-31 15:53:55 +02:00
committed by Milan Broz
parent 5042ec2cd0
commit 2712882aa3
2 changed files with 25 additions and 0 deletions

View File

@@ -341,6 +341,10 @@ uint64_t LUKS2_segment_size(struct luks2_hdr *hdr,
int segment,
unsigned blockwise);
bool LUKS2_segment_set_size(struct luks2_hdr *hdr,
int segment,
const uint64_t *segment_size_bytes);
int LUKS2_segment_is_type(struct luks2_hdr *hdr,
int segment,
const char *type);

View File

@@ -91,6 +91,22 @@ uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise)
return blockwise ? crypt_jobj_get_uint64(jobj) >> SECTOR_SHIFT : crypt_jobj_get_uint64(jobj);
}
static bool json_segment_set_size(json_object *jobj_segment, const uint64_t *size_bytes)
{
json_object *jobj;
if (!jobj_segment)
return false;
jobj = size_bytes ? crypt_jobj_new_uint64(*size_bytes) : json_object_new_string("dynamic");
if (!jobj)
return false;
json_object_object_add(jobj_segment, "size", jobj);
return true;
}
const char *json_segment_get_cipher(json_object *jobj_segment)
{
json_object *jobj;
@@ -316,6 +332,11 @@ uint64_t LUKS2_segment_size(struct luks2_hdr *hdr, int segment, unsigned blockwi
return json_segment_get_size(LUKS2_get_segment_jobj(hdr, segment), blockwise);
}
bool LUKS2_segment_set_size(struct luks2_hdr *hdr, int segment, const uint64_t *segment_size_bytes)
{
return json_segment_set_size(LUKS2_get_segment_jobj(hdr, segment), segment_size_bytes);
}
int LUKS2_segment_is_type(struct luks2_hdr *hdr, int segment, const char *type)
{
return !strcmp(json_segment_type(LUKS2_get_segment_jobj(hdr, segment)) ?: "", type);