summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-01 11:44:26 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-01 16:35:56 +0200
commitbff5d2fd5af2fbf79f0f692ccc30ea47fd141188 (patch)
treedd4ca5999c59f79a59350e1bb051ebae1fecdd19 /src/shared
parentrepart: add sections to --help text (diff)
downloadsystemd-bff5d2fd5af2fbf79f0f692ccc30ea47fd141188.tar.xz
systemd-bff5d2fd5af2fbf79f0f692ccc30ea47fd141188.zip
blockdev-util: add partscan check function that takes an sd_device*
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/blockdev-util.c22
-rw-r--r--src/shared/blockdev-util.h3
-rw-r--r--src/shared/dissect-image.c2
-rw-r--r--src/shared/loop-util.c2
4 files changed, 19 insertions, 10 deletions
diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c
index 2055550336..53d60bd0dd 100644
--- a/src/shared/blockdev-util.c
+++ b/src/shared/blockdev-util.c
@@ -356,8 +356,7 @@ int lock_whole_block_device(dev_t devt, int operation) {
return TAKE_FD(lock_fd);
}
-int blockdev_partscan_enabled(int fd) {
- _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+int blockdev_partscan_enabled(sd_device *dev) {
unsigned capability;
int r, ext_range;
@@ -408,11 +407,7 @@ int blockdev_partscan_enabled(int fd) {
* 4) check 'ext_range' sysfs attribute, and if '1' we can conclude partition scanning is disabled,
* 5) otherwise check 'capability' sysfs attribute for ancient version. */
- assert(fd >= 0);
-
- r = block_device_new_from_fd(fd, 0, &dev);
- if (r < 0)
- return r;
+ assert(dev);
/* For v6.10 or newer. */
r = device_get_sysattr_bool(dev, "partscan");
@@ -458,6 +453,19 @@ int blockdev_partscan_enabled(int fd) {
return true;
}
+int blockdev_partscan_enabled_fd(int fd) {
+ _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+ int r;
+
+ assert(fd >= 0);
+
+ r = block_device_new_from_fd(fd, 0, &dev);
+ if (r < 0)
+ return r;
+
+ return blockdev_partscan_enabled(dev);
+}
+
static int blockdev_is_encrypted(const char *sysfs_path, unsigned depth_left) {
_cleanup_free_ char *p = NULL, *uuids = NULL;
_cleanup_closedir_ DIR *d = NULL;
diff --git a/src/shared/blockdev-util.h b/src/shared/blockdev-util.h
index 28aede289a..e8e9d37ef9 100644
--- a/src/shared/blockdev-util.h
+++ b/src/shared/blockdev-util.h
@@ -40,7 +40,8 @@ int get_block_device_harder(const char *path, dev_t *dev);
int lock_whole_block_device(dev_t devt, int operation);
-int blockdev_partscan_enabled(int fd);
+int blockdev_partscan_enabled(sd_device *d);
+int blockdev_partscan_enabled_fd(int fd);
int fd_is_encrypted(int fd);
int path_is_encrypted(const char *path);
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 1a3ed0cf7f..28c2d7dbc0 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -893,7 +893,7 @@ static int dissect_image(
if (FLAGS_SET(flags, DISSECT_IMAGE_ADD_PARTITION_DEVICES)) {
/* Safety check: refuse block devices that carry a partition table but for which the kernel doesn't
* do partition scanning. */
- r = blockdev_partscan_enabled(fd);
+ r = blockdev_partscan_enabled_fd(fd);
if (r < 0)
return r;
if (r == 0)
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c
index e295eb2a21..d707d466ab 100644
--- a/src/shared/loop-util.c
+++ b/src/shared/loop-util.c
@@ -149,7 +149,7 @@ static int loop_configure_verify(int fd, const struct loop_config *c) {
* into the block device. Let's hence verify if things work correctly here
* before returning. */
- r = blockdev_partscan_enabled(fd);
+ r = blockdev_partscan_enabled_fd(fd);
if (r < 0)
return r;
if (r == 0) {