Debian Codegraph @

src/portable/portable.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "runtime-scope.h"
5 #include "shared-forward.h"
6 #include "string-util.h"
7
8 typedef struct PortableMetadata {
9 int fd;
10 char *source;
11 char *image_path;
12 char *selinux_label;
13 char name[];
14 } PortableMetadata;
15
16 #define PORTABLE_METADATA_IS_OS_RELEASE(m) (streq((m)->name, "/etc/os-release"))
17 #define PORTABLE_METADATA_IS_EXTENSION_RELEASE(m) (startswith_strv((m)->name, STRV_MAKE("/usr/lib/extension-release.d/extension-release.", "/etc/extension-release.d/extension-release.")))
18 #define PORTABLE_METADATA_IS_UNIT(m) (!IN_SET((m)->name[0], 0, '/'))
19
20 typedef enum PortableFlags {
21 PORTABLE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */
22 PORTABLE_FORCE_ATTACH = 1 << 1, /* Public API via DBUS, do not change */
23 PORTABLE_FORCE_EXTENSION = 1 << 2, /* Public API via DBUS, do not change */
24 PORTABLE_PREFER_COPY = 1 << 3,
25 PORTABLE_PREFER_SYMLINK = 1 << 4,
26 PORTABLE_MIXED_COPY_LINK = 1 << 5,
27 PORTABLE_REATTACH = 1 << 6,
28 _PORTABLE_MASK_PUBLIC = PORTABLE_RUNTIME | PORTABLE_FORCE_ATTACH | PORTABLE_FORCE_EXTENSION,
29 _PORTABLE_TYPE_MAX,
30 _PORTABLE_TYPE_INVALID = -EINVAL,
31 } PortableFlags;
32
33 /* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno
34 * values. */
35 enum {
36 PORTABLE_COPY,
37 PORTABLE_SYMLINK,
38 PORTABLE_UNLINK,
39 PORTABLE_WRITE,
40 PORTABLE_MKDIR,
41 _PORTABLE_CHANGE_TYPE_MAX,
42 _PORTABLE_CHANGE_TYPE_INVALID = -EINVAL,
43 };
44
45 typedef enum PortableState {
46 PORTABLE_DETACHED,
47 PORTABLE_ATTACHED,
48 PORTABLE_ATTACHED_RUNTIME,
49 PORTABLE_ENABLED,
50 PORTABLE_ENABLED_RUNTIME,
51 PORTABLE_RUNNING,
52 PORTABLE_RUNNING_RUNTIME,
53 _PORTABLE_STATE_MAX,
54 _PORTABLE_STATE_INVALID = -EINVAL,
55 } PortableState;
56
57 typedef struct PortableChange {
58 int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */
59 char *path;
60 char *source;
61 } PortableChange;
62
63 PortableMetadata *portable_metadata_unref(PortableMetadata *i);
64 DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref);
65
66 int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret);
67
68 int portable_extract(
69 RuntimeScope scope,
70 const char *name_or_path,
71 char **matches,
72 char **extension_image_paths,
73 const ImagePolicy *image_policy,
74 PortableFlags flags,
75 PortableMetadata **ret_os_release,
76 OrderedHashmap **ret_extension_releases,
77 Hashmap **ret_unit_files,
78 char ***ret_valid_prefixes,
79 sd_bus_error *error);
80
81 int portable_attach(
82 RuntimeScope scope,
83 sd_bus *bus,
84 const char *name_or_path,
85 char **matches,
86 const char *profile,
87 char **extension_image_paths,
88 const ImagePolicy* image_policy,
89 PortableFlags flags,
90 PortableChange **changes,
91 size_t *n_changes,
92 sd_bus_error *error);
93
94 int portable_detach(
95 RuntimeScope scope,
96 sd_bus *bus,
97 const char *name_or_path,
98 char **extension_image_paths,
99 PortableFlags flags,
100 PortableChange **changes,
101 size_t *n_changes,
102 sd_bus_error *error);
103
104 int portable_get_state(
105 RuntimeScope scope,
106 sd_bus *bus,
107 const char *name_or_path,
108 char **extension_image_paths,
109 PortableFlags flags,
110 PortableState *ret,
111 sd_bus_error *error);
112
113 int portable_get_profiles(RuntimeScope scope, char ***ret);
114
115 void portable_changes_free(PortableChange *array, size_t n);
116
117 DECLARE_STRING_TABLE_LOOKUP(portable_change_type, int);
118
119 DECLARE_STRING_TABLE_LOOKUP(portable_state, PortableState);