]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/dissect-image.h
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / shared / dissect-image.h
CommitLineData
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
26typedef struct DissectedImage DissectedImage;
27typedef struct DissectedPartition DissectedPartition;
18b5886e 28typedef struct DecryptedImage DecryptedImage;
8c1be37e
LP
29
30struct 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). */
be30ad41 35 sd_id128_t uuid; /* Partition entry UUID as reported by the GPT */
8c1be37e
LP
36 char *fstype;
37 char *node;
18b5886e
LP
38 char *decrypted_node;
39 char *decrypted_fstype;
8c1be37e
LP
40};
41
42enum {
43 PARTITION_ROOT,
44 PARTITION_ROOT_SECONDARY, /* Secondary architecture */
45 PARTITION_HOME,
46 PARTITION_SRV,
47 PARTITION_ESP,
48 PARTITION_SWAP,
4623e8e6
LP
49 PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */
50 PARTITION_ROOT_SECONDARY_VERITY, /* verity data for the PARTITION_ROOT_SECONDARY partition */
8c1be37e
LP
51 _PARTITION_DESIGNATOR_MAX,
52 _PARTITION_DESIGNATOR_INVALID = -1
53};
54
4623e8e6
LP
55static inline int PARTITION_VERITY_OF(int p) {
56 if (p == PARTITION_ROOT)
57 return PARTITION_ROOT_VERITY;
58 if (p == PARTITION_ROOT_SECONDARY)
59 return PARTITION_ROOT_SECONDARY_VERITY;
60 return _PARTITION_DESIGNATOR_INVALID;
61}
62
18b5886e
LP
63typedef enum DissectImageFlags {
64 DISSECT_IMAGE_READ_ONLY = 1,
971e2ef0 65 DISSECT_IMAGE_DISCARD_ON_LOOP = 2, /* Turn on "discard" if on a loop device and file system supports it */
18b5886e
LP
66 DISSECT_IMAGE_DISCARD = 4, /* Turn on "discard" if file system supports it, on all block devices */
67 DISSECT_IMAGE_DISCARD_ON_CRYPTO = 8, /* Turn on "discard" also on crypto devices */
971e2ef0
ZJS
68 DISSECT_IMAGE_DISCARD_ANY = DISSECT_IMAGE_DISCARD_ON_LOOP |
69 DISSECT_IMAGE_DISCARD |
70 DISSECT_IMAGE_DISCARD_ON_CRYPTO,
9b6deb03 71 DISSECT_IMAGE_GPT_ONLY = 16, /* Only recognize images with GPT partition tables */
e0f9e7bd 72 DISSECT_IMAGE_REQUIRE_ROOT = 32, /* Don't accept disks without root partition */
18b5886e 73} DissectImageFlags;
8c1be37e
LP
74
75struct DissectedImage {
4623e8e6
LP
76 bool encrypted:1;
77 bool verity:1; /* verity available and usable */
78 bool can_verity:1; /* verity available, but not necessarily used */
8c1be37e
LP
79 DissectedPartition partitions[_PARTITION_DESIGNATOR_MAX];
80};
81
9b6deb03 82int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DissectedImage **ret);
8c1be37e
LP
83
84DissectedImage* dissected_image_unref(DissectedImage *m);
85DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);
86
4623e8e6
LP
87int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret);
88int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret);
18b5886e
LP
89int dissected_image_mount(DissectedImage *m, const char *dest, DissectImageFlags flags);
90
91DecryptedImage* decrypted_image_unref(DecryptedImage *p);
92DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);
93int decrypted_image_relinquish(DecryptedImage *d);
8c1be37e
LP
94
95const char* partition_designator_to_string(int i) _const_;
96int partition_designator_from_string(const char *name) _pure_;
78ebe980
LP
97
98int root_hash_load(const char *image, void **ret, size_t *ret_size);