blockdev-util: add partscan check function that takes an sd_device*

This commit is contained in:
Lennart Poettering
2024-07-01 16:35:56 +02:00
parent 68debef4c1
commit bff5d2fd5a
6 changed files with 21 additions and 12 deletions
+15 -7
View File
@@ -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;