From 3941f886e71e005224915c6e5f6f7b94d7ed0a29 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 5 Nov 2024 20:28:32 -0500 Subject: [PATCH] writer: Canonicalize no-verity errno to -ENOVERITY This is what we do elsewhere. Signed-off-by: Colin Walters --- libcomposefs/lcfs-writer.c | 4 ++++ tests/test-lcfs.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libcomposefs/lcfs-writer.c b/libcomposefs/lcfs-writer.c index 81826fd..18c20f8 100644 --- a/libcomposefs/lcfs-writer.c +++ b/libcomposefs/lcfs-writer.c @@ -576,6 +576,10 @@ int lcfs_fd_measure_fsverity(uint8_t *digest, int fd) fsv->digest_size = MAX_DIGEST_SIZE; int res = ioctl(fd, FS_IOC_MEASURE_VERITY, fsv); if (res == -1) { + if (errno == ENODATA || errno == EOPNOTSUPP || errno == ENOTTY) { + // Canonicalize errno + errno = ENOVERITY; + } return -errno; } // The file has fsverity enabled, but with an unexpected different algorithm (e.g. sha512). diff --git a/tests/test-lcfs.c b/tests/test-lcfs.c index e8d5f7f..59f0c13 100644 --- a/tests/test-lcfs.c +++ b/tests/test-lcfs.c @@ -2,6 +2,7 @@ #define _GNU_SOURCE #include "lcfs-writer.h" +#include "lcfs-mount.h" #include #include #include @@ -84,8 +85,10 @@ static void test_no_verity(void) assert(tmpfd > 0); uint8_t digest[LCFS_DIGEST_SIZE]; - int r = lcfs_fd_require_fsverity(digest, tmpfd); + int r = lcfs_fd_measure_fsverity(digest, tmpfd); + int errsv = errno; assert(r != 0); + assert(errsv == ENOVERITY); close(tmpfd); }