]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add fd-based flavour of path_is_encrypted()
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Jun 2021 09:18:39 +0000 (11:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2021 07:29:33 +0000 (09:29 +0200)
src/shared/blockdev-util.c
src/shared/blockdev-util.h

index fa2d6d6add8c81a35356c4b4680fc27bbba83866..53df7d2f0d2de9dc155e411912f8c589fa4dc57c 100644 (file)
@@ -334,6 +334,22 @@ static int blockdev_is_encrypted(const char *sysfs_path, unsigned depth_left) {
         return found_encrypted;
 }
 
+int fd_is_encrypted(int fd) {
+        char p[SYS_BLOCK_PATH_MAX(NULL)];
+        dev_t devt;
+        int r;
+
+        r = get_block_device_fd(fd, &devt);
+        if (r < 0)
+                return r;
+        if (r == 0) /* doesn't have a block device */
+                return false;
+
+        xsprintf_sys_block_path(p, NULL, devt);
+
+        return blockdev_is_encrypted(p, 10 /* safety net: maximum recursion depth */);
+}
+
 int path_is_encrypted(const char *path) {
         char p[SYS_BLOCK_PATH_MAX(NULL)];
         dev_t devt;
index 90d9f1367322b1a0a98c2e7f7b386c8012ad9e13..d36707cf632833dca8ce521382462974f65cb4d5 100644 (file)
@@ -24,4 +24,5 @@ int lock_whole_block_device(dev_t devt, int operation);
 
 int blockdev_partscan_enabled(int fd);
 
+int fd_is_encrypted(int fd);
 int path_is_encrypted(const char *path);