homework: Auto-probe luks sector size

Auto-probe the luks sector size, if not explicitly
specified in the home record
This commit is contained in:
scarlet-storm
2026-02-17 18:23:35 +05:30
parent a24f11798b
commit fc280b64e8
+14 -4
View File
@@ -1755,6 +1755,7 @@ static int luks_format(
const PasswordCache *cache,
char **effective_passwords,
bool discard,
uint64_t sector_size,
UserRecord *hr,
struct crypt_device **ret) {
@@ -1809,7 +1810,7 @@ static int luks_format(
&(struct crypt_params_luks2) {
.label = label,
.subsystem = "systemd-home",
.sector_size = user_record_luks_sector_size(hr),
.sector_size = sector_size, /* sector-size of 0 is auto for libcryptsetup */
.pbkdf = &good_pbkdf,
});
if (r < 0)
@@ -2166,7 +2167,7 @@ int home_create_luks(
UserRecord **ret_home) {
_cleanup_free_ char *subdir = NULL, *disk_uuid_path = NULL;
uint64_t encrypted_size,
uint64_t encrypted_size, image_sector_size, luks_sector_size,
host_size = 0, partition_offset = 0, partition_size = 0; /* Unnecessary initialization to appease gcc */
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
sd_id128_t partition_uuid, fs_uuid, luks_uuid, disk_uuid;
@@ -2337,9 +2338,17 @@ int home_create_luks(
log_info("Allocating image file completed.");
}
if (h->luks_sector_size == UINT64_MAX) {
/* If sector size is not specified, select UINT32_MAX, i.e. auto-probe */
image_sector_size = UINT32_MAX;
/* Let cryptsetup decide if the sector size is not specified in home record */
luks_sector_size = 0;
} else
luks_sector_size = image_sector_size = user_record_luks_sector_size(h);
r = make_partition_table(
setup->image_fd,
user_record_luks_sector_size(h),
image_sector_size,
user_record_user_name_and_realm(h),
partition_uuid,
&partition_offset,
@@ -2355,7 +2364,7 @@ int home_create_luks(
O_RDWR,
partition_offset,
partition_size,
user_record_luks_sector_size(h),
image_sector_size,
0,
LOCK_EX,
&setup->loop);
@@ -2375,6 +2384,7 @@ int home_create_luks(
cache,
effective_passwords,
user_record_luks_discard(h) || user_record_luks_offline_discard(h),
luks_sector_size,
h,
&setup->crypt_device);
if (r < 0)