From: Lennart Poettering Date: Mon, 21 Jun 2021 09:18:39 +0000 (+0200) Subject: fs-util: add fd-based flavour of path_is_encrypted() X-Git-Tag: v250-rc1~980^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91358db9dcb752f7ff5aac6638c6c7462d75001a;p=thirdparty%2Fsystemd.git fs-util: add fd-based flavour of path_is_encrypted() --- diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index fa2d6d6add8..53df7d2f0d2 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -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; diff --git a/src/shared/blockdev-util.h b/src/shared/blockdev-util.h index 90d9f136732..d36707cf632 100644 --- a/src/shared/blockdev-util.h +++ b/src/shared/blockdev-util.h @@ -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);