]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/portable/portable.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / portable / portable.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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
11 typedef 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
20 typedef enum PortableFlags {
21 PORTABLE_PREFER_COPY = 1 << 0,
22 PORTABLE_PREFER_SYMLINK = 1 << 1,
23 PORTABLE_RUNTIME = 1 << 2,
24 } PortableFlags;
25
26 typedef enum PortableChangeType {
27 PORTABLE_COPY,
28 PORTABLE_SYMLINK,
29 PORTABLE_UNLINK,
30 PORTABLE_WRITE,
31 PORTABLE_MKDIR,
32 _PORTABLE_CHANGE_TYPE_MAX,
33 _PORTABLE_CHANGE_TYPE_INVALID = INT_MIN,
34 } PortableChangeType;
35
36 typedef enum PortableState {
37 PORTABLE_DETACHED,
38 PORTABLE_ATTACHED,
39 PORTABLE_ATTACHED_RUNTIME,
40 PORTABLE_ENABLED,
41 PORTABLE_ENABLED_RUNTIME,
42 PORTABLE_RUNNING,
43 PORTABLE_RUNNING_RUNTIME,
44 _PORTABLE_STATE_MAX,
45 _PORTABLE_STATE_INVALID = -1
46 } PortableState;
47
48 typedef struct PortableChange {
49 int type; /* PortableFileChangeType or negative error number */
50 char *path;
51 char *source;
52 } PortableChange;
53
54 PortableMetadata *portable_metadata_unref(PortableMetadata *i);
55 DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref);
56
57 int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret);
58
59 int portable_extract(const char *image, char **matches, PortableMetadata **ret_os_release, Hashmap **ret_unit_files, sd_bus_error *error);
60
61 int 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);
62 int portable_detach(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
63
64 int portable_get_state(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableState *ret, sd_bus_error *error);
65
66 int portable_get_profiles(char ***ret);
67
68 void portable_changes_free(PortableChange *changes, size_t n_changes);
69
70 const char *portable_change_type_to_string(PortableChangeType t) _const_;
71 PortableChangeType portable_change_type_from_string(const char *t) _pure_;
72
73 const char *portable_state_to_string(PortableState t) _const_;
74 PortableState portable_state_from_string(const char *t) _pure_;