/*
* LUKS - Linux Unified Key Setup v2, internal segment handling
*
- * Copyright (C) 2018-2021, Red Hat, Inc. All rights reserved.
- * Copyright (C) 2018-2021, Ondrej Kozina
+ * Copyright (C) 2018-2023 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2018-2023 Ondrej Kozina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
return json_object_get_string(jobj);
}
-int json_segment_get_sector_size(json_object *jobj_segment)
+uint32_t json_segment_get_sector_size(json_object *jobj_segment)
{
json_object *jobj;
+ int i;
if (!jobj_segment ||
!json_object_object_get_ex(jobj_segment, "sector_size", &jobj))
- return -1;
+ return SECTOR_SIZE;
- return json_object_get_int(jobj);
+ i = json_object_get_int(jobj);
+ return i < 0 ? SECTOR_SIZE : i;
}
static json_object *json_segment_get_flags(json_object *jobj_segment)
int LUKS2_segment_first_unused_id(struct luks2_hdr *hdr)
{
json_object *jobj_segments;
- int id, last_id = -1;
if (!json_object_object_get_ex(hdr->jobj, "segments", &jobj_segments))
return -EINVAL;
- json_object_object_foreach(jobj_segments, slot, val) {
- UNUSED(val);
- id = atoi(slot);
- if (id > last_id)
- last_id = id;
- }
-
- return last_id + 1;
+ return json_object_object_length(jobj_segments);
}
int LUKS2_segment_set_flag(json_object *jobj_segment, const char *flag)