]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/machine-image.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "lockfile-util.h"
10 #include "path-util.h"
11 #include "string-util.h"
12 #include "time-util.h"
14 typedef enum ImageClass
{
18 _IMAGE_CLASS_INVALID
= -1
21 typedef enum ImageType
{
27 _IMAGE_TYPE_INVALID
= -1
30 typedef struct Image
{
42 uint64_t usage_exclusive
;
44 uint64_t limit_exclusive
;
47 sd_id128_t machine_id
;
51 bool metadata_valid
:1;
52 bool discoverable
:1; /* true if we know for sure that image_find() would find the image given just the short name */
57 Image
*image_unref(Image
*i
);
58 Image
*image_ref(Image
*i
);
60 static inline Hashmap
* image_hashmap_free(Hashmap
*map
) {
61 return hashmap_free_with_destructor(map
, image_unref
);
64 DEFINE_TRIVIAL_CLEANUP_FUNC(Image
*, image_unref
);
65 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap
*, image_hashmap_free
);
67 int image_find(ImageClass
class, const char *name
, Image
**ret
);
68 int image_from_path(const char *path
, Image
**ret
);
69 int image_find_harder(ImageClass
class, const char *name_or_path
, Image
**ret
);
70 int image_discover(ImageClass
class, Hashmap
*map
);
72 int image_remove(Image
*i
);
73 int image_rename(Image
*i
, const char *new_name
);
74 int image_clone(Image
*i
, const char *new_name
, bool read_only
);
75 int image_read_only(Image
*i
, bool b
);
77 const char* image_type_to_string(ImageType t
) _const_
;
78 ImageType
image_type_from_string(const char *s
) _pure_
;
80 bool image_name_is_valid(const char *s
) _pure_
;
82 int image_path_lock(const char *path
, int operation
, LockFile
*global
, LockFile
*local
);
83 int image_name_lock(const char *name
, int operation
, LockFile
*ret
);
85 int image_set_limit(Image
*i
, uint64_t referenced_max
);
87 int image_read_metadata(Image
*i
);
89 bool image_in_search_path(ImageClass
class, const char *image
);
91 static inline bool IMAGE_IS_HIDDEN(const struct Image
*i
) {
94 return i
->name
&& i
->name
[0] == '.';
97 static inline bool IMAGE_IS_VENDOR(const struct Image
*i
) {
100 return i
->path
&& path_startswith(i
->path
, "/usr");
103 static inline bool IMAGE_IS_HOST(const struct Image
*i
) {
106 if (i
->name
&& streq(i
->name
, ".host"))
109 if (i
->path
&& path_equal(i
->path
, "/"))