]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/discover-image.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 #include "image-policy.h"
12 #include "lock-util.h"
15 #include "path-util.h"
16 #include "string-util.h"
17 #include "time-util.h"
19 typedef enum ImageType
{
25 _IMAGE_TYPE_INVALID
= -EINVAL
,
28 typedef struct Image
{
41 uint64_t usage_exclusive
;
43 uint64_t limit_exclusive
;
46 sd_id128_t machine_id
;
49 char **sysext_release
;
50 char **confext_release
;
52 bool metadata_valid
:1;
53 bool discoverable
:1; /* true if we know for sure that image_find() would find the image given just the short name */
58 Image
*image_unref(Image
*i
);
59 Image
*image_ref(Image
*i
);
61 DEFINE_TRIVIAL_CLEANUP_FUNC(Image
*, image_unref
);
63 int image_find(ImageClass
class, const char *root
, const char *name
, Image
**ret
);
64 int image_from_path(const char *path
, Image
**ret
);
65 int image_find_harder(ImageClass
class, const char *root
, const char *name_or_path
, Image
**ret
);
66 int image_discover(ImageClass
class, const char *root
, Hashmap
*map
);
68 int image_remove(Image
*i
);
69 int image_rename(Image
*i
, const char *new_name
);
70 int image_clone(Image
*i
, const char *new_name
, bool read_only
);
71 int image_read_only(Image
*i
, bool b
);
73 const char* image_type_to_string(ImageType t
) _const_
;
74 ImageType
image_type_from_string(const char *s
) _pure_
;
76 int image_path_lock(const char *path
, int operation
, LockFile
*global
, LockFile
*local
);
77 int image_name_lock(const char *name
, int operation
, LockFile
*ret
);
79 int image_set_limit(Image
*i
, uint64_t referenced_max
);
81 int image_read_metadata(Image
*i
, const ImagePolicy
*image_policy
);
83 bool image_in_search_path(ImageClass
class, const char *root
, const char *image
);
85 static inline char **image_extension_release(Image
*image
, ImageClass
class) {
88 if (class == IMAGE_SYSEXT
)
89 return image
->sysext_release
;
90 if (class == IMAGE_CONFEXT
)
91 return image
->confext_release
;
96 static inline bool IMAGE_IS_HIDDEN(const struct Image
*i
) {
99 return i
->name
&& i
->name
[0] == '.';
102 static inline bool IMAGE_IS_VENDOR(const struct Image
*i
) {
105 return i
->path
&& path_startswith(i
->path
, "/usr");
108 static inline bool IMAGE_IS_HOST(const struct Image
*i
) {
111 if (i
->name
&& streq(i
->name
, ".host"))
114 if (i
->path
&& path_equal(i
->path
, "/"))
120 int image_to_json(const struct Image
*i
, JsonVariant
**ret
);
122 const char *image_root_to_string(ImageClass c
) _const_
;
124 extern const struct hash_ops image_hash_ops
;
126 extern const char* const image_search_path
[_IMAGE_CLASS_MAX
];