]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
8c1be37e LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2016 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
23 | #include <stdbool.h> | |
24 | ||
25 | #include "macro.h" | |
26 | ||
27 | typedef struct DissectedImage DissectedImage; | |
28 | typedef struct DissectedPartition DissectedPartition; | |
18b5886e | 29 | typedef struct DecryptedImage DecryptedImage; |
8c1be37e LP |
30 | |
31 | struct DissectedPartition { | |
32 | bool found:1; | |
33 | bool rw:1; | |
34 | int partno; /* -1 if there was no partition and the images contains a file system directly */ | |
35 | int architecture; /* Intended architecture: either native, secondary or unset (-1). */ | |
be30ad41 | 36 | sd_id128_t uuid; /* Partition entry UUID as reported by the GPT */ |
8c1be37e LP |
37 | char *fstype; |
38 | char *node; | |
18b5886e LP |
39 | char *decrypted_node; |
40 | char *decrypted_fstype; | |
8c1be37e LP |
41 | }; |
42 | ||
43 | enum { | |
44 | PARTITION_ROOT, | |
45 | PARTITION_ROOT_SECONDARY, /* Secondary architecture */ | |
46 | PARTITION_HOME, | |
47 | PARTITION_SRV, | |
48 | PARTITION_ESP, | |
49 | PARTITION_SWAP, | |
4623e8e6 LP |
50 | PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */ |
51 | PARTITION_ROOT_SECONDARY_VERITY, /* verity data for the PARTITION_ROOT_SECONDARY partition */ | |
8c1be37e LP |
52 | _PARTITION_DESIGNATOR_MAX, |
53 | _PARTITION_DESIGNATOR_INVALID = -1 | |
54 | }; | |
55 | ||
4623e8e6 LP |
56 | static inline int PARTITION_VERITY_OF(int p) { |
57 | if (p == PARTITION_ROOT) | |
58 | return PARTITION_ROOT_VERITY; | |
59 | if (p == PARTITION_ROOT_SECONDARY) | |
60 | return PARTITION_ROOT_SECONDARY_VERITY; | |
61 | return _PARTITION_DESIGNATOR_INVALID; | |
62 | } | |
63 | ||
18b5886e LP |
64 | typedef enum DissectImageFlags { |
65 | DISSECT_IMAGE_READ_ONLY = 1, | |
971e2ef0 | 66 | DISSECT_IMAGE_DISCARD_ON_LOOP = 2, /* Turn on "discard" if on a loop device and file system supports it */ |
18b5886e LP |
67 | DISSECT_IMAGE_DISCARD = 4, /* Turn on "discard" if file system supports it, on all block devices */ |
68 | DISSECT_IMAGE_DISCARD_ON_CRYPTO = 8, /* Turn on "discard" also on crypto devices */ | |
971e2ef0 ZJS |
69 | DISSECT_IMAGE_DISCARD_ANY = DISSECT_IMAGE_DISCARD_ON_LOOP | |
70 | DISSECT_IMAGE_DISCARD | | |
71 | DISSECT_IMAGE_DISCARD_ON_CRYPTO, | |
9b6deb03 | 72 | DISSECT_IMAGE_GPT_ONLY = 16, /* Only recognize images with GPT partition tables */ |
e0f9e7bd | 73 | DISSECT_IMAGE_REQUIRE_ROOT = 32, /* Don't accept disks without root partition */ |
18b5886e | 74 | } DissectImageFlags; |
8c1be37e LP |
75 | |
76 | struct DissectedImage { | |
4623e8e6 LP |
77 | bool encrypted:1; |
78 | bool verity:1; /* verity available and usable */ | |
79 | bool can_verity:1; /* verity available, but not necessarily used */ | |
8c1be37e LP |
80 | DissectedPartition partitions[_PARTITION_DESIGNATOR_MAX]; |
81 | }; | |
82 | ||
9b6deb03 | 83 | int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DissectedImage **ret); |
8c1be37e LP |
84 | |
85 | DissectedImage* dissected_image_unref(DissectedImage *m); | |
86 | DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref); | |
87 | ||
4623e8e6 LP |
88 | int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret); |
89 | int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret); | |
18b5886e LP |
90 | int dissected_image_mount(DissectedImage *m, const char *dest, DissectImageFlags flags); |
91 | ||
92 | DecryptedImage* decrypted_image_unref(DecryptedImage *p); | |
93 | DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref); | |
94 | int decrypted_image_relinquish(DecryptedImage *d); | |
8c1be37e LP |
95 | |
96 | const char* partition_designator_to_string(int i) _const_; | |
97 | int partition_designator_from_string(const char *name) _pure_; | |
78ebe980 LP |
98 | |
99 | int root_hash_load(const char *image, void **ret, size_t *ret_size); |