tree-wide: Use fdisk_new_context_at() more

This commit is contained in:
Daan De Meyer
2023-08-14 10:42:43 +02:00
parent fd9fe57a26
commit 4492eb1186
3 changed files with 8 additions and 24 deletions
+2 -6
View File
@@ -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);
+4 -12
View File
@@ -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);
+2 -6
View File
@@ -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);