blob: 6d28297e1a53df0f4e9b55e49328a6e4e4018b4f [file] [log] [blame]
Eric Biggers431c67b2018-06-27 15:01:06 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * The 'fsverity enable' command
4 *
5 * Copyright (C) 2018 Google, Inc.
6 *
7 * Written by Eric Biggers, 2018.
8 */
9
10#include <fcntl.h>
11#include <sys/ioctl.h>
12
13#include "commands.h"
14#include "fsverity_sys_decls.h"
15
16int 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}