Skip to content

Commit

Permalink
writer: Canonicalize no-verity errno to -ENOVERITY
Browse files Browse the repository at this point in the history
This is what we do elsewhere.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 6, 2024
1 parent 95b4792 commit 3941f88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 4 additions & 1 deletion tests/test-lcfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _GNU_SOURCE

#include "lcfs-writer.h"
#include "lcfs-mount.h"
#include <assert.h>
#include <unistd.h>
#include <errno.h>
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 3941f88

Please sign in to comment.