]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/dissect-image.h
nspawn: make sure images containing an ESP are compatible with userns -U mode
[thirdparty/systemd.git] / src / shared / dissect-image.h
CommitLineData
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
27typedef struct DissectedImage DissectedImage;
28typedef struct DissectedPartition DissectedPartition;
18b5886e 29typedef struct DecryptedImage DecryptedImage;
8c1be37e
LP
30
31struct 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
43enum {
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
56static 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 64typedef enum DissectImageFlags {
2d3a5a73
LP
65 DISSECT_IMAGE_READ_ONLY = 1 << 0,
66 DISSECT_IMAGE_DISCARD_ON_LOOP = 1 << 1, /* Turn on "discard" if on a loop device and file system supports it */
67 DISSECT_IMAGE_DISCARD = 1 << 2, /* Turn on "discard" if file system supports it, on all block devices */
68 DISSECT_IMAGE_DISCARD_ON_CRYPTO = 1 << 3, /* 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,
2d3a5a73
LP
72 DISSECT_IMAGE_GPT_ONLY = 1 << 4, /* Only recognize images with GPT partition tables */
73 DISSECT_IMAGE_REQUIRE_ROOT = 1 << 5, /* Don't accept disks without root partition */
74 DISSECT_IMAGE_MOUNT_ROOT_ONLY = 1 << 6, /* Mount only the root partition */
75 DISSECT_IMAGE_MOUNT_NON_ROOT_ONLY = 1 << 7, /* Mount only non-root partitions */
18b5886e 76} DissectImageFlags;
8c1be37e
LP
77
78struct DissectedImage {
4623e8e6
LP
79 bool encrypted:1;
80 bool verity:1; /* verity available and usable */
81 bool can_verity:1; /* verity available, but not necessarily used */
3b925504 82
8c1be37e 83 DissectedPartition partitions[_PARTITION_DESIGNATOR_MAX];
3b925504
LP
84
85 char *hostname;
86 sd_id128_t machine_id;
87 char **machine_info;
88 char **os_release;
8c1be37e
LP
89};
90
c34b75a1 91int probe_filesystem(const char *node, char **ret_fstype);
9b6deb03 92int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DissectedImage **ret);
8c1be37e
LP
93
94DissectedImage* dissected_image_unref(DissectedImage *m);
95DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);
96
4623e8e6
LP
97int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret);
98int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DecryptedImage **ret);
2d3a5a73 99int dissected_image_mount(DissectedImage *m, const char *dest, uid_t uid_shift, DissectImageFlags flags);
18b5886e 100
3b925504
LP
101int dissected_image_acquire_metadata(DissectedImage *m);
102
18b5886e
LP
103DecryptedImage* decrypted_image_unref(DecryptedImage *p);
104DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);
105int decrypted_image_relinquish(DecryptedImage *d);
8c1be37e
LP
106
107const char* partition_designator_to_string(int i) _const_;
108int partition_designator_from_string(const char *name) _pure_;
78ebe980
LP
109
110int root_hash_load(const char *image, void **ret, size_t *ret_size);