summaryrefslogtreecommitdiffstats
path: root/src/test/test-blockdev-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-blockdev-util.c')
-rw-r--r--src/test/test-blockdev-util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/test-blockdev-util.c b/src/test/test-blockdev-util.c
index 134386c..19626e0 100644
--- a/src/test/test-blockdev-util.c
+++ b/src/test/test-blockdev-util.c
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "blockdev-util.h"
+#include "device-util.h"
#include "errno-util.h"
+#include "fd-util.h"
#include "tests.h"
static void test_path_is_encrypted_one(const char *p, int expect) {
@@ -38,4 +40,39 @@ TEST(path_is_encrypted) {
test_path_is_encrypted_one("/dev", booted > 0 ? false : -1);
}
+TEST(partscan_enabled) {
+
+ _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
+ int r;
+
+ assert_se(sd_device_enumerator_new(&e) >= 0);
+ assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0);
+ assert_se(sd_device_enumerator_add_match_subsystem(e, "block", /* match = */ true) >= 0);
+
+ FOREACH_DEVICE(e, dev) {
+ _cleanup_close_ int fd = -EBADF;
+ const char *name;
+
+ r = sd_device_get_devname(dev, &name);
+ if (r < 0) {
+ log_warning_errno(r, "Found block device without a name, skipping.");
+ continue;
+ }
+
+ fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
+ if (fd < 0) {
+ log_warning_errno(fd, "Found block device '%s' which we cannot open, skipping: %m", name);
+ continue;
+ }
+
+ r = blockdev_partscan_enabled(fd);
+ if (r < 0) {
+ log_warning_errno(r, "Failed to determine if block device '%s' has partition scanning enabled, skipping: %m", name);
+ continue;
+ }
+
+ log_info("%s has partition scanning enabled: %s", name, yes_no(r));
+ }
+}
+
DEFINE_TEST_MAIN(LOG_INFO);