From 4492eb118678de1783a38e132f6a44f68d39d1d0 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 14 Aug 2023 10:42:43 +0200 Subject: [PATCH] tree-wide: Use fdisk_new_context_at() more --- src/home/homework-luks.c | 8 ++------ src/sysupdate/sysupdate-partition.c | 16 ++++------------ src/sysupdate/sysupdate-resource.c | 8 ++------ 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 5920fbb732c..e41920ce9c6 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -2764,13 +2764,9 @@ static int get_maximum_partition_size( assert(p); assert(ret_maximum_partition_size); - c = fdisk_new_context(); - if (!c) - return log_oom(); - - r = fdisk_assign_device(c, FORMAT_PROC_FD_PATH(fd), 0); + r = fdisk_new_context_at(fd, /* path= */ NULL, /* read_only= */ true, /* sector_size= */ UINT32_MAX, &c); if (r < 0) - return log_error_errno(r, "Failed to open device: %m"); + return log_error_errno(r, "Failed to create fdisk context: %m"); start_lba = fdisk_partition_get_start(p); assert(start_lba <= UINT64_MAX/512); diff --git a/src/sysupdate/sysupdate-partition.c b/src/sysupdate/sysupdate-partition.c index 587265482bd..fa4453d6651 100644 --- a/src/sysupdate/sysupdate-partition.c +++ b/src/sysupdate/sysupdate-partition.c @@ -119,13 +119,9 @@ int find_suitable_partition( assert(device); assert(ret); - c = fdisk_new_context(); - if (!c) - return log_oom(); - - r = fdisk_assign_device(c, device, /* readonly= */ true); + r = fdisk_new_context_at(AT_FDCWD, device, /* read_only= */ true, /* sector_size= */ UINT32_MAX, &c); if (r < 0) - return log_error_errno(r, "Failed to open device '%s': %m", device); + return log_error_errno(r, "Failed to create fdisk context from '%s': %m", device); if (!fdisk_is_labeltype(c, FDISK_DISKLABEL_GPT)) return log_error_errno(SYNTHETIC_ERRNO(EHWPOISON), "Disk %s has no GPT disk label, not suitable.", device); @@ -188,13 +184,9 @@ int patch_partition( if (change == 0) /* Nothing to do */ return 0; - c = fdisk_new_context(); - if (!c) - return log_oom(); - - r = fdisk_assign_device(c, device, /* readonly= */ false); + r = fdisk_new_context_at(AT_FDCWD, device, /* read_only= */ false, /* sector_size= */ UINT32_MAX, &c); if (r < 0) - return log_error_errno(r, "Failed to open device '%s': %m", device); + return log_error_errno(r, "Failed to create fdisk context from '%s': %m", device); assert_se((fd = fdisk_get_devfd(c)) >= 0); diff --git a/src/sysupdate/sysupdate-resource.c b/src/sysupdate/sysupdate-resource.c index 30973a360df..a6efa289615 100644 --- a/src/sysupdate/sysupdate-resource.c +++ b/src/sysupdate/sysupdate-resource.c @@ -168,13 +168,9 @@ static int resource_load_from_blockdev(Resource *rr) { assert(rr); - c = fdisk_new_context(); - if (!c) - return log_oom(); - - r = fdisk_assign_device(c, rr->path, /* readonly= */ true); + r = fdisk_new_context_at(AT_FDCWD, rr->path, /* read_only= */ true, /* sector_size= */ UINT32_MAX, &c); if (r < 0) - return log_error_errno(r, "Failed to open device '%s': %m", rr->path); + return log_error_errno(r, "Failed to create fdisk context from '%s': %m", rr->path); if (!fdisk_is_labeltype(c, FDISK_DISKLABEL_GPT)) return log_error_errno(SYNTHETIC_ERRNO(EHWPOISON), "Disk %s has no GPT disk label, not suitable.", rr->path); -- 2.47.3