]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/portable/portable.h
Merge pull request #18007 from fw-strlen/ipv6_masq_and_dnat
[thirdparty/systemd.git] / src / portable / portable.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
61d0578b
LP
2#pragma once
3
4#include "sd-bus.h"
5
6#include "hashmap.h"
7#include "macro.h"
8#include "set.h"
9#include "string-util.h"
10
11typedef struct PortableMetadata {
12 int fd;
13 char *source;
14 char name[];
15} PortableMetadata;
16
17#define PORTABLE_METADATA_IS_OS_RELEASE(m) (streq((m)->name, "/etc/os-release"))
18#define PORTABLE_METADATA_IS_UNIT(m) (!IN_SET((m)->name[0], 0, '/'))
19
20typedef enum PortableFlags {
ef31828d
LP
21 PORTABLE_PREFER_COPY = 1 << 0,
22 PORTABLE_PREFER_SYMLINK = 1 << 1,
23 PORTABLE_RUNTIME = 1 << 2,
e26fe5f9 24 PORTABLE_REATTACH = 1 << 3,
61d0578b
LP
25} PortableFlags;
26
27typedef enum PortableChangeType {
28 PORTABLE_COPY,
29 PORTABLE_SYMLINK,
30 PORTABLE_UNLINK,
31 PORTABLE_WRITE,
32 PORTABLE_MKDIR,
33 _PORTABLE_CHANGE_TYPE_MAX,
34 _PORTABLE_CHANGE_TYPE_INVALID = INT_MIN,
35} PortableChangeType;
36
37typedef enum PortableState {
38 PORTABLE_DETACHED,
39 PORTABLE_ATTACHED,
40 PORTABLE_ATTACHED_RUNTIME,
41 PORTABLE_ENABLED,
42 PORTABLE_ENABLED_RUNTIME,
43 PORTABLE_RUNNING,
44 PORTABLE_RUNNING_RUNTIME,
45 _PORTABLE_STATE_MAX,
2d93c20e 46 _PORTABLE_STATE_INVALID = -EINVAL,
61d0578b
LP
47} PortableState;
48
49typedef struct PortableChange {
50 int type; /* PortableFileChangeType or negative error number */
51 char *path;
52 char *source;
53} PortableChange;
54
55PortableMetadata *portable_metadata_unref(PortableMetadata *i);
56DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref);
57
61d0578b
LP
58int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret);
59
60int portable_extract(const char *image, char **matches, PortableMetadata **ret_os_release, Hashmap **ret_unit_files, sd_bus_error *error);
61
62int portable_attach(sd_bus *bus, const char *name_or_path, char **matches, const char *profile, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
63int portable_detach(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
64
65int portable_get_state(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableState *ret, sd_bus_error *error);
66
67int portable_get_profiles(char ***ret);
68
69void portable_changes_free(PortableChange *changes, size_t n_changes);
70
71const char *portable_change_type_to_string(PortableChangeType t) _const_;
72PortableChangeType portable_change_type_from_string(const char *t) _pure_;
73
74const char *portable_state_to_string(PortableState t) _const_;
75PortableState portable_state_from_string(const char *t) _pure_;