diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index fa2d6d6add..53df7d2f0d 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 90d9f13673..d36707cf63 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);