]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/discover-image.h
ci: enable arm64 runner for build/unit jobs
[thirdparty/systemd.git] / src / shared / discover-image.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-id128.h"
5
6 #include "forward.h"
7 #include "os-util.h"
8
9 typedef enum ImageType {
10 IMAGE_DIRECTORY,
11 IMAGE_SUBVOLUME,
12 IMAGE_RAW,
13 IMAGE_BLOCK,
14 _IMAGE_TYPE_MAX,
15 _IMAGE_TYPE_INVALID = -EINVAL,
16 } ImageType;
17
18 typedef struct Image {
19 unsigned n_ref;
20
21 ImageType type;
22 ImageClass class;
23 char *name;
24 char *path;
25 bool read_only;
26
27 usec_t crtime;
28 usec_t mtime;
29
30 uint64_t usage;
31 uint64_t usage_exclusive;
32 uint64_t limit;
33 uint64_t limit_exclusive;
34
35 char *hostname;
36 sd_id128_t machine_id;
37 char **machine_info;
38 char **os_release;
39 char **sysext_release;
40 char **confext_release;
41
42 bool metadata_valid:1;
43 bool discoverable:1; /* true if we know for sure that image_find() would find the image given just the short name */
44
45 void *userdata;
46 } Image;
47
48 Image* image_unref(Image *i);
49 Image* image_ref(Image *i);
50
51 DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
52
53 int image_find(RuntimeScope scope, ImageClass class, const char *name, const char *root, Image **ret);
54 int image_from_path(const char *path, Image **ret);
55 int image_find_harder(RuntimeScope scope, ImageClass class, const char *name_or_path, const char *root, Image **ret);
56 int image_discover(RuntimeScope scope, ImageClass class, const char *root, Hashmap **images);
57
58 int image_remove(Image *i);
59 int image_rename(Image *i, const char *new_name, RuntimeScope scope);
60 int image_clone(Image *i, const char *new_name, bool read_only, RuntimeScope scope);
61 int image_read_only(Image *i, bool b);
62
63 const char* image_type_to_string(ImageType t) _const_;
64 ImageType image_type_from_string(const char *s) _pure_;
65
66 int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local);
67 int image_name_lock(const char *name, int operation, LockFile *ret);
68
69 int image_set_limit(Image *i, uint64_t referenced_max);
70 int image_set_pool_limit(ImageClass class, uint64_t referenced_max);
71
72 int image_read_metadata(Image *i, const ImagePolicy *image_policy);
73
74 bool image_in_search_path(RuntimeScope scope, ImageClass class, const char *root, const char *image);
75
76 static inline char** image_extension_release(Image *image, ImageClass class) {
77 assert(image);
78
79 if (class == IMAGE_SYSEXT)
80 return image->sysext_release;
81 if (class == IMAGE_CONFEXT)
82 return image->confext_release;
83
84 return NULL;
85 }
86
87 static inline bool image_is_hidden(const struct Image *i) {
88 assert(i);
89
90 return i->name && i->name[0] == '.';
91 }
92
93 bool image_is_vendor(const struct Image *i);
94 bool image_is_host(const struct Image *i);
95
96 int image_to_json(const struct Image *i, sd_json_variant **ret);
97
98 const char* image_root_to_string(ImageClass c) _const_;
99 const char* image_root_runtime_to_string(ImageClass c) _const_;
100
101 extern const struct hash_ops image_hash_ops;
102
103 extern const char* const image_search_path[_IMAGE_CLASS_MAX];