]>
Commit | Line | Data |
---|---|---|
a032b68d | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
b012e921 MB |
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; | |
8b3d4ff0 | 14 | char *image_path; |
ea0999c9 | 15 | char *selinux_label; |
b012e921 MB |
16 | char name[]; |
17 | } PortableMetadata; | |
18 | ||
19 | #define PORTABLE_METADATA_IS_OS_RELEASE(m) (streq((m)->name, "/etc/os-release")) | |
ea0999c9 | 20 | #define PORTABLE_METADATA_IS_EXTENSION_RELEASE(m) (startswith((m)->name, "/usr/lib/extension-release.d/extension-release.")) |
b012e921 MB |
21 | #define PORTABLE_METADATA_IS_UNIT(m) (!IN_SET((m)->name[0], 0, '/')) |
22 | ||
23 | typedef enum PortableFlags { | |
8b3d4ff0 MB |
24 | PORTABLE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ |
25 | PORTABLE_PREFER_COPY = 1 << 1, | |
26 | PORTABLE_PREFER_SYMLINK = 1 << 2, | |
3a6ce677 | 27 | PORTABLE_REATTACH = 1 << 3, |
8b3d4ff0 MB |
28 | _PORTABLE_MASK_PUBLIC = PORTABLE_RUNTIME, |
29 | _PORTABLE_TYPE_MAX, | |
30 | _PORTABLE_TYPE_INVALID = -EINVAL, | |
b012e921 MB |
31 | } PortableFlags; |
32 | ||
3a6ce677 BR |
33 | /* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno |
34 | * values. */ | |
35 | enum { | |
b012e921 MB |
36 | PORTABLE_COPY, |
37 | PORTABLE_SYMLINK, | |
38 | PORTABLE_UNLINK, | |
39 | PORTABLE_WRITE, | |
40 | PORTABLE_MKDIR, | |
41 | _PORTABLE_CHANGE_TYPE_MAX, | |
3a6ce677 BR |
42 | _PORTABLE_CHANGE_TYPE_INVALID = -EINVAL, |
43 | }; | |
b012e921 MB |
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, | |
3a6ce677 | 54 | _PORTABLE_STATE_INVALID = -EINVAL, |
b012e921 MB |
55 | } PortableState; |
56 | ||
57 | typedef struct PortableChange { | |
3a6ce677 | 58 | int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */ |
b012e921 MB |
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 | ||
b012e921 MB |
66 | int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret); |
67 | ||
9cde670f | 68 | int portable_extract(const char *image, char **matches, char **extension_image_paths, PortableMetadata **ret_os_release, OrderedHashmap **ret_extension_releases, Hashmap **ret_unit_files, char ***ret_valid_prefixes, sd_bus_error *error); |
b012e921 | 69 | |
8b3d4ff0 MB |
70 | int portable_attach(sd_bus *bus, const char *name_or_path, char **matches, const char *profile, char **extension_images, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error); |
71 | 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); | |
b012e921 MB |
72 | |
73 | int portable_get_state(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableState *ret, sd_bus_error *error); | |
74 | ||
75 | int portable_get_profiles(char ***ret); | |
76 | ||
77 | void portable_changes_free(PortableChange *changes, size_t n_changes); | |
78 | ||
3a6ce677 BR |
79 | const char *portable_change_type_to_string(int t) _const_; |
80 | int portable_change_type_from_string(const char *t) _pure_; | |
b012e921 MB |
81 | |
82 | const char *portable_state_to_string(PortableState t) _const_; | |
83 | PortableState portable_state_from_string(const char *t) _pure_; |