diff options
author | Eric Biggers <ebiggers@google.com> | 2018-03-13 11:57:29 -0700 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2018-03-13 11:57:29 -0700 |
commit | a544a98c6d3ee05421873296b9d8039efd1803a8 (patch) | |
tree | 93169be98e98b00bf6d04e9b9854527f7d3904fc | |
parent | 7d7c3d5d2ddd7ef2c90ea4b2389cab6a551ebad4 (diff) | |
download | fsverity-a544a98c6d3ee05421873296b9d8039efd1803a8.tar.gz |
Clean up ioctl-fs-verity-set and rename to fsverityset
Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r-- | fsverityset.c | 34 | ||||
-rw-r--r-- | ioctl-fs-verity-set.c | 36 |
2 files changed, 34 insertions, 36 deletions
diff --git a/fsverityset.c b/fsverityset.c new file mode 100644 index 0000000..6075071 --- /dev/null +++ b/fsverityset.c @@ -0,0 +1,34 @@ +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <unistd.h> + +#include "fsverity_api.h" + +static void usage(void) +{ + fprintf(stderr, "Usage: fsverityset FILE\n"); + exit(2); +} + +int main(int args, char *argv[]) +{ + int fd; + struct fsverity_set set = { 0 }; + + if (args != 2) + usage(); + + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Can't open %s: %m\n", argv[1]); + return 1; + } + if (ioctl(fd, FS_IOC_SET_FSVERITY, &set)) { + fprintf(stderr, "FS_IOC_SET_FSVERITY: %m\n"); + return 1; + } + close(fd); + return 0; +} diff --git a/ioctl-fs-verity-set.c b/ioctl-fs-verity-set.c deleted file mode 100644 index ffc3a9c..0000000 --- a/ioctl-fs-verity-set.c +++ /dev/null @@ -1,36 +0,0 @@ -#include <linux/fs.h> -#include <stdio.h> -#include <errno.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> - -int main(int args, char *argv[]) -{ - int res, fd; - struct fsverity_set fsverity_set; - char *endptr; - - if (args != 3) { - printf("Usage:\n ioctl-fs-verity-set [filepath] [offset of fs-verity header]\n"); - return -EINVAL; - } - fsverity_set.offset = strtol(argv[2], &endptr, 10); - printf("Parsed offset: [%llu]\n", fsverity_set.offset); - fsverity_set.flags = 0; - fd = open(argv[1], O_RDWR); - if (fd == -1) { - printf("Could not open [%s]\n", argv[1]); - return -EINVAL; - } - res = ioctl(fd, FS_IOC_SET_FSVERITY, &fsverity_set); - if (res) { - printf("ioctl() returned [%d]\n", res); - return 1; - } - close(fd); - return 0; -} |