fs-util: add fd-based flavour of path_is_encrypted()

This commit is contained in:
Lennart Poettering
2021-07-08 09:29:33 +02:00
parent 0bfef8b46f
commit 91358db9dc
2 changed files with 17 additions and 0 deletions
+16
View 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;
+1
View 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);