udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / portable / portable.h
blobc61d65fed3500f94874d415ac658bbe37da1eb39
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
4 #include "sd-bus.h"
6 #include "dissect-image.h"
7 #include "hashmap.h"
8 #include "macro.h"
9 #include "set.h"
10 #include "string-util.h"
12 typedef struct PortableMetadata {
13 int fd;
14 char *source;
15 char *image_path;
16 char *selinux_label;
17 char name[];
18 } PortableMetadata;
20 #define PORTABLE_METADATA_IS_OS_RELEASE(m) (streq((m)->name, "/etc/os-release"))
21 #define PORTABLE_METADATA_IS_EXTENSION_RELEASE(m) (startswith((m)->name, "/usr/lib/extension-release.d/extension-release."))
22 #define PORTABLE_METADATA_IS_UNIT(m) (!IN_SET((m)->name[0], 0, '/'))
24 typedef enum PortableFlags {
25 PORTABLE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */
26 PORTABLE_FORCE_ATTACH = 1 << 1, /* Public API via DBUS, do not change */
27 PORTABLE_FORCE_SYSEXT = 1 << 2, /* Public API via DBUS, do not change */
28 PORTABLE_PREFER_COPY = 1 << 3,
29 PORTABLE_PREFER_SYMLINK = 1 << 4,
30 PORTABLE_REATTACH = 1 << 5,
31 _PORTABLE_MASK_PUBLIC = PORTABLE_RUNTIME | PORTABLE_FORCE_ATTACH | PORTABLE_FORCE_SYSEXT,
32 _PORTABLE_TYPE_MAX,
33 _PORTABLE_TYPE_INVALID = -EINVAL,
34 } PortableFlags;
36 /* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno
37 * values. */
38 enum {
39 PORTABLE_COPY,
40 PORTABLE_SYMLINK,
41 PORTABLE_UNLINK,
42 PORTABLE_WRITE,
43 PORTABLE_MKDIR,
44 _PORTABLE_CHANGE_TYPE_MAX,
45 _PORTABLE_CHANGE_TYPE_INVALID = -EINVAL,
48 typedef enum PortableState {
49 PORTABLE_DETACHED,
50 PORTABLE_ATTACHED,
51 PORTABLE_ATTACHED_RUNTIME,
52 PORTABLE_ENABLED,
53 PORTABLE_ENABLED_RUNTIME,
54 PORTABLE_RUNNING,
55 PORTABLE_RUNNING_RUNTIME,
56 _PORTABLE_STATE_MAX,
57 _PORTABLE_STATE_INVALID = -EINVAL,
58 } PortableState;
60 typedef struct PortableChange {
61 int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */
62 char *path;
63 char *source;
64 } PortableChange;
66 PortableMetadata *portable_metadata_unref(PortableMetadata *i);
67 DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref);
69 int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret);
71 int portable_extract(const char *image, char **matches, char **extension_image_paths, const ImagePolicy *image_policy, PortableFlags flags, PortableMetadata **ret_os_release, OrderedHashmap **ret_extension_releases, Hashmap **ret_unit_files, char ***ret_valid_prefixes, sd_bus_error *error);
73 int portable_attach(sd_bus *bus, const char *name_or_path, char **matches, const char *profile, char **extension_images, const ImagePolicy* image_policy, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
74 int portable_detach(sd_bus *bus, const char *name_or_path, char **extension_image_paths, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
76 int portable_get_state(sd_bus *bus, const char *name_or_path, char **extension_image_paths, PortableFlags flags, PortableState *ret, sd_bus_error *error);
78 int portable_get_profiles(char ***ret);
80 void portable_changes_free(PortableChange *changes, size_t n_changes);
82 const char *portable_change_type_to_string(int t) _const_;
83 int portable_change_type_from_string(const char *t) _pure_;
85 const char *portable_state_to_string(PortableState t) _const_;
86 PortableState portable_state_from_string(const char *t) _pure_;