1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * The 'fsverity enable' command
4 *
5 * Copyright (C) 2018 Google LLC
6 *
7 * Written by Eric Biggers.
8 */
9
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12
13 #include "commands.h"
14 #include "fsverity_uapi.h"
15
fsverity_cmd_enable(const struct fsverity_command * cmd,int argc,char * argv[])16 int fsverity_cmd_enable(const struct fsverity_command *cmd,
17 int argc, char *argv[])
18 {
19 struct filedes file;
20
21 if (argc != 2) {
22 usage(cmd, stderr);
23 return 2;
24 }
25
26 if (!open_file(&file, argv[1], O_RDONLY, 0))
27 return 1;
28 if (ioctl(file.fd, FS_IOC_ENABLE_VERITY, NULL) != 0) {
29 error_msg_errno("FS_IOC_ENABLE_VERITY failed on '%s'",
30 file.name);
31 filedes_close(&file);
32 return 1;
33 }
34 if (!filedes_close(&file))
35 return 1;
36 return 0;
37 }
38