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