]>
Commit | Line | Data |
---|---|---|
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 | ||
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 { | |
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 | ||
27 | typedef 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 | ||
37 | typedef 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 | ||
49 | typedef struct PortableChange { | |
50 | int type; /* PortableFileChangeType or negative error number */ | |
51 | char *path; | |
52 | char *source; | |
53 | } PortableChange; | |
54 | ||
55 | PortableMetadata *portable_metadata_unref(PortableMetadata *i); | |
56 | DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref); | |
57 | ||
61d0578b LP |
58 | int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret); |
59 | ||
60 | int portable_extract(const char *image, char **matches, PortableMetadata **ret_os_release, Hashmap **ret_unit_files, sd_bus_error *error); | |
61 | ||
62 | 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); | |
63 | int portable_detach(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error); | |
64 | ||
65 | int portable_get_state(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableState *ret, sd_bus_error *error); | |
66 | ||
67 | int portable_get_profiles(char ***ret); | |
68 | ||
69 | void portable_changes_free(PortableChange *changes, size_t n_changes); | |
70 | ||
71 | const char *portable_change_type_to_string(PortableChangeType t) _const_; | |
72 | PortableChangeType portable_change_type_from_string(const char *t) _pure_; | |
73 | ||
74 | const char *portable_state_to_string(PortableState t) _const_; | |
75 | PortableState portable_state_from_string(const char *t) _pure_; |