Eric Biggers | 431c67b | 2018-06-27 15:01:06 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * The 'fsverity enable' command |
| 4 | * |
Eric Biggers | 8387ad3 | 2018-08-21 12:37:56 -0700 | [diff] [blame] | 5 | * Copyright (C) 2018 Google LLC |
Eric Biggers | 431c67b | 2018-06-27 15:01:06 -0700 | [diff] [blame] | 6 | * |
Eric Biggers | 8387ad3 | 2018-08-21 12:37:56 -0700 | [diff] [blame] | 7 | * Written by Eric Biggers. |
Eric Biggers | 431c67b | 2018-06-27 15:01:06 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <fcntl.h> |
| 11 | #include <sys/ioctl.h> |
| 12 | |
| 13 | #include "commands.h" |
Eric Biggers | 25b5945 | 2018-07-27 10:47:02 -0700 | [diff] [blame] | 14 | #include "fsverity_uapi.h" |
Eric Biggers | 431c67b | 2018-06-27 15:01:06 -0700 | [diff] [blame] | 15 | |
| 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 | } |