repart: Allow configuring sector size

Let's allow users to configure the (logical) sector size of their
image. This is required when building images for a 4k sector size
disk on a 512b sector size host or vice-versa.
This commit is contained in:
Daan De Meyer
2023-01-17 20:09:22 +01:00
parent 065bdb6f0f
commit e1878ef72a
10 changed files with 97 additions and 41 deletions
+20
View File
@@ -256,6 +256,26 @@ int parse_size(const char *t, uint64_t base, uint64_t *size) {
return 0;
}
int parse_sector_size(const char *t, uint64_t *ret) {
int r;
assert(t);
assert(ret);
uint64_t ss;
r = safe_atou64(t, &ss);
if (r < 0)
return log_error_errno(r, "Failed to parse sector size parameter %s", t);
if (ss < 512 || ss > 4096) /* Allow up to 4K due to dm-crypt support and 4K alignment by the homed LUKS backend */
return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Sector size not between 512 and 4096: %s", t);
if (!ISPOWEROF2(ss))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Sector size not power of 2: %s", t);
*ret = ss;
return 0;
}
int parse_range(const char *t, unsigned *lower, unsigned *upper) {
_cleanup_free_ char *word = NULL;
unsigned l, u;
+1
View File
@@ -18,6 +18,7 @@ int parse_ifindex(const char *s);
int parse_mtu(int family, const char *s, uint32_t *ret);
int parse_size(const char *t, uint64_t base, uint64_t *size);
int parse_sector_size(const char *t, uint64_t *ret);
int parse_range(const char *t, unsigned *lower, unsigned *upper);
int parse_errno(const char *t);