1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "dissect-image.h"
10 #include "string-util.h"
12 typedef struct 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
,
33 _PORTABLE_TYPE_INVALID
= -EINVAL
,
36 /* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno
44 _PORTABLE_CHANGE_TYPE_MAX
,
45 _PORTABLE_CHANGE_TYPE_INVALID
= -EINVAL
,
48 typedef enum PortableState
{
51 PORTABLE_ATTACHED_RUNTIME
,
53 PORTABLE_ENABLED_RUNTIME
,
55 PORTABLE_RUNNING_RUNTIME
,
57 _PORTABLE_STATE_INVALID
= -EINVAL
,
60 typedef struct PortableChange
{
61 int type_or_errno
; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */
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_
;