blob: ed092f032139170ea802c9804ceb030716de1ac1 [file] [log] [blame]
Eric Biggers431c67b2018-06-27 15:01:06 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * The 'fsverity enable' command
4 *
Eric Biggers8387ad32018-08-21 12:37:56 -07005 * Copyright (C) 2018 Google LLC
Eric Biggers431c67b2018-06-27 15:01:06 -07006 *
Eric Biggers8387ad32018-08-21 12:37:56 -07007 * Written by Eric Biggers.
Eric Biggers431c67b2018-06-27 15:01:06 -07008 */
9
10#include <fcntl.h>
11#include <sys/ioctl.h>
12
13#include "commands.h"
Eric Biggers25b59452018-07-27 10:47:02 -070014#include "fsverity_uapi.h"
Eric Biggers431c67b2018-06-27 15:01:06 -070015
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}