1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 #include "string-util.h"
11 typedef struct PortableMetadata
{
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, '/'))
20 typedef enum PortableFlags
{
21 PORTABLE_PREFER_COPY
= 1 << 0,
22 PORTABLE_PREFER_SYMLINK
= 1 << 1,
23 PORTABLE_RUNTIME
= 1 << 2,
26 typedef enum PortableChangeType
{
32 _PORTABLE_CHANGE_TYPE_MAX
,
33 _PORTABLE_CHANGE_TYPE_INVALID
= INT_MIN
,
36 typedef enum PortableState
{
39 PORTABLE_ATTACHED_RUNTIME
,
41 PORTABLE_ENABLED_RUNTIME
,
43 PORTABLE_RUNNING_RUNTIME
,
45 _PORTABLE_STATE_INVALID
= -1
48 typedef struct PortableChange
{
49 int type
; /* PortableFileChangeType or negative error number */
54 PortableMetadata
*portable_metadata_unref(PortableMetadata
*i
);
55 DEFINE_TRIVIAL_CLEANUP_FUNC(PortableMetadata
*, portable_metadata_unref
);
57 Hashmap
*portable_metadata_hashmap_unref(Hashmap
*h
);
58 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap
*, portable_metadata_hashmap_unref
);
60 int portable_metadata_hashmap_to_sorted_array(Hashmap
*unit_files
, PortableMetadata
***ret
);
62 int portable_extract(const char *image
, char **matches
, PortableMetadata
**ret_os_release
, Hashmap
**ret_unit_files
, sd_bus_error
*error
);
64 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
);
65 int portable_detach(sd_bus
*bus
, const char *name_or_path
, PortableFlags flags
, PortableChange
**changes
, size_t *n_changes
, sd_bus_error
*error
);
67 int portable_get_state(sd_bus
*bus
, const char *name_or_path
, PortableFlags flags
, PortableState
*ret
, sd_bus_error
*error
);
69 int portable_get_profiles(char ***ret
);
71 void portable_changes_free(PortableChange
*changes
, size_t n_changes
);
73 const char *portable_change_type_to_string(PortableChangeType t
) _const_
;
74 PortableChangeType
portable_change_type_from_string(const char *t
) _pure_
;
76 const char *portable_state_to_string(PortableState t
) _const_
;
77 PortableState
portable_state_from_string(const char *t
) _pure_
;