Debian Codegraph @

src/shared/discover-image.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-id128.h"
5
6 #include "shared-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_MSTACK,
15 _IMAGE_TYPE_MAX,
16 _IMAGE_TYPE_INVALID = -EINVAL,
17 } ImageType;
18
19 typedef struct Image {
20 unsigned n_ref;
21
22 ImageType type;
23 ImageClass class;
24 char *name;
25 char *path;
26 bool read_only;
27
28 usec_t crtime;
29 usec_t mtime;
30
31 struct file_handle *fh;
32 uint64_t on_mount_id;
33 uint64_t inode;
34
35 uint64_t usage;
36 uint64_t usage_exclusive;
37 uint64_t limit;
38 uint64_t limit_exclusive;
39
40 char *hostname;
41 sd_id128_t machine_id;
42 char **machine_info;
43 char **os_release;
44 char **sysext_release;
45 char **confext_release;
46
47 bool metadata_valid:1; /* true if the above 6 metadata fields have been read from the image */
48 bool discoverable:1; /* true if we know for sure that image_find() would find the image given just the short name */
49 bool foreign_uid_owned:1; /* true if this is of type IMAGE_DIRECTORY/IMAGE_SUBVOLUME and owned by foreign UID range */
50
51 void *userdata;
52 } Image;
53
54 DECLARE_TRIVIAL_REF_UNREF_FUNC(Image, image);
55 DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
56
57 int image_find(RuntimeScope scope, ImageClass class, const char *name, const char *root, Image **ret);
58 int image_from_path(const char *path, Image **ret);
59 int image_find_harder(RuntimeScope scope, ImageClass class, const char *name_or_path, const char *root, Image **ret);
60 int image_discover(RuntimeScope scope, ImageClass class, const char *root, Hashmap **images);
61
62 int image_remove(Image *i, RuntimeScope scope);
63 int image_rename(Image *i, const char *new_name, RuntimeScope scope);
64 int image_clone(Image *i, const char *new_name, bool read_only, RuntimeScope scope);
65 int image_read_only(Image *i, bool b, RuntimeScope scope);
66
67 DECLARE_STRING_TABLE_LOOKUP(image_type, ImageType);
68
69 int image_path_lock(RuntimeScope scope, const char *path, int operation, LockFile *global, LockFile *local);
70 int image_name_lock(RuntimeScope scope, const char *name, int operation, LockFile *ret);
71
72 int image_set_limit(Image *i, uint64_t referenced_max);
73 int image_set_pool_limit(RuntimeScope scope, ImageClass class, uint64_t referenced_max);
74 int image_get_pool_path(RuntimeScope scope, ImageClass class, char **ret);
75 int image_get_pool_usage(RuntimeScope scope, ImageClass class, uint64_t *ret);
76 int image_get_pool_limit(RuntimeScope scope, ImageClass class, uint64_t *ret);
77 int image_setup_pool(RuntimeScope scope, ImageClass class, bool use_btrfs_subvol, bool use_btrfs_quota);
78
79 int image_read_metadata(Image *i, const char *root, const ImagePolicy *image_policy, RuntimeScope scope);
80
81 bool image_in_search_path(RuntimeScope scope, ImageClass class, const char *root, const char *image);
82
83 static inline char** image_extension_release(Image *image, ImageClass class) {
84 assert(image);
85
86 if (class == IMAGE_SYSEXT)
87 return image->sysext_release;
88 if (class == IMAGE_CONFEXT)
89 return image->confext_release;
90
91 return NULL;
92 }
93
94 static inline bool image_is_hidden(const Image *i) {
95 assert(i);
96
97 return i->name && i->name[0] == '.';
98 }
99
100 static inline bool image_is_read_only(const Image *i) {
101 assert(i);
102
103 /* We enforce the rule that hidden images are always read-only too. If people want to change hidden
104 * images they should make a copy first, and make that one mutable */
105
106 if (image_is_hidden(i))
107 return true;
108
109 return i->read_only;
110 }
111 int bus_property_get_image_is_read_only(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error);
112
113 bool image_is_vendor(const Image *i);
114 bool image_is_host(const Image *i);
115
116 int image_to_json(const Image *i, sd_json_variant **ret);
117
118 int image_root_pick(RuntimeScope scope, ImageClass c, bool runtime, char **ret);
119
120 extern const struct hash_ops image_hash_ops;
121
122 extern const char* const image_search_path[_IMAGE_CLASS_MAX];