]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/portable/portable.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / portable / portable.h
CommitLineData
61d0578b
LP
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
11typedef 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
20typedef enum PortableFlags {
ef31828d
LP
21 PORTABLE_PREFER_COPY = 1 << 0,
22 PORTABLE_PREFER_SYMLINK = 1 << 1,
23 PORTABLE_RUNTIME = 1 << 2,
61d0578b
LP
24} PortableFlags;
25
26typedef 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
36typedef 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
48typedef struct PortableChange {
49 int type; /* PortableFileChangeType or negative error number */
50 char *path;
51 char *source;
52} PortableChange;
53
54PortableMetadata *portable_metadata_unref(PortableMetadata *i);
55DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata*, portable_metadata_unref);
56
61d0578b
LP
57int portable_metadata_hashmap_to_sorted_array(Hashmap *unit_files, PortableMetadata ***ret);
58
59int portable_extract(const char *image, char **matches, PortableMetadata **ret_os_release, Hashmap **ret_unit_files, sd_bus_error *error);
60
61int 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);
62int portable_detach(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableChange **changes, size_t *n_changes, sd_bus_error *error);
63
64int portable_get_state(sd_bus *bus, const char *name_or_path, PortableFlags flags, PortableState *ret, sd_bus_error *error);
65
66int portable_get_profiles(char ***ret);
67
68void portable_changes_free(PortableChange *changes, size_t n_changes);
69
70const char *portable_change_type_to_string(PortableChangeType t) _const_;
71PortableChangeType portable_change_type_from_string(const char *t) _pure_;
72
73const char *portable_state_to_string(PortableState t) _const_;
74PortableState portable_state_from_string(const char *t) _pure_;