]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
cd61c3bf LP |
2 | #pragma once |
3 | ||
a8fbdf54 TA |
4 | #include <stdbool.h> |
5 | #include <stdint.h> | |
6 | ||
cd61c3bf | 7 | #include "hashmap.h" |
71d35b6b | 8 | #include "lockfile-util.h" |
a8fbdf54 | 9 | #include "macro.h" |
d94c2b06 LP |
10 | #include "path-util.h" |
11 | #include "string-util.h" | |
71d35b6b | 12 | #include "time-util.h" |
cd61c3bf | 13 | |
5ef46e5f LP |
14 | typedef enum ImageClass { |
15 | IMAGE_MACHINE, | |
16 | IMAGE_PORTABLE, | |
17 | _IMAGE_CLASS_MAX, | |
18 | _IMAGE_CLASS_INVALID = -1 | |
19 | } ImageClass; | |
20 | ||
cd61c3bf LP |
21 | typedef enum ImageType { |
22 | IMAGE_DIRECTORY, | |
23 | IMAGE_SUBVOLUME, | |
aceac2f0 | 24 | IMAGE_RAW, |
eb38edce | 25 | IMAGE_BLOCK, |
cd61c3bf LP |
26 | _IMAGE_TYPE_MAX, |
27 | _IMAGE_TYPE_INVALID = -1 | |
28 | } ImageType; | |
29 | ||
30 | typedef struct Image { | |
9614bb06 LP |
31 | unsigned n_ref; |
32 | ||
cd61c3bf LP |
33 | ImageType type; |
34 | char *name; | |
35 | char *path; | |
36 | bool read_only; | |
37 | ||
10f9c755 | 38 | usec_t crtime; |
cd61c3bf | 39 | usec_t mtime; |
b6b18498 | 40 | |
c19de711 LP |
41 | uint64_t usage; |
42 | uint64_t usage_exclusive; | |
b6b18498 LP |
43 | uint64_t limit; |
44 | uint64_t limit_exclusive; | |
70244d1d | 45 | |
c7664c07 LP |
46 | char *hostname; |
47 | sd_id128_t machine_id; | |
48 | char **machine_info; | |
49 | char **os_release; | |
50 | ||
cf604fd4 LP |
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 */ | |
c7664c07 | 53 | |
70244d1d | 54 | void *userdata; |
cd61c3bf LP |
55 | } Image; |
56 | ||
57 | Image *image_unref(Image *i); | |
9614bb06 LP |
58 | Image *image_ref(Image *i); |
59 | ||
e85b096b ZJS |
60 | static inline Hashmap* image_hashmap_free(Hashmap *map) { |
61 | return hashmap_free_with_destructor(map, image_unref); | |
62 | } | |
cd61c3bf | 63 | |
ebeccf9e LP |
64 | DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref); |
65 | DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free); | |
66 | ||
5ef46e5f | 67 | int image_find(ImageClass class, const char *name, Image **ret); |
2ddf182b LP |
68 | int image_from_path(const char *path, Image **ret); |
69 | int image_find_harder(ImageClass class, const char *name_or_path, Image **ret); | |
5ef46e5f | 70 | int image_discover(ImageClass class, Hashmap *map); |
cd61c3bf | 71 | |
08682124 | 72 | int image_remove(Image *i); |
ebd93cb6 LP |
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); | |
08682124 | 76 | |
cd61c3bf LP |
77 | const char* image_type_to_string(ImageType t) _const_; |
78 | ImageType image_type_from_string(const char *s) _pure_; | |
30535c16 LP |
79 | |
80 | bool image_name_is_valid(const char *s) _pure_; | |
81 | ||
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); | |
d6ce17c7 | 84 | |
cb81cd80 | 85 | int image_set_limit(Image *i, uint64_t referenced_max); |
d94c2b06 | 86 | |
c7664c07 LP |
87 | int image_read_metadata(Image *i); |
88 | ||
ace9ab19 LP |
89 | bool image_in_search_path(ImageClass class, const char *image); |
90 | ||
d94c2b06 LP |
91 | static inline bool IMAGE_IS_HIDDEN(const struct Image *i) { |
92 | assert(i); | |
93 | ||
94 | return i->name && i->name[0] == '.'; | |
95 | } | |
96 | ||
97 | static inline bool IMAGE_IS_VENDOR(const struct Image *i) { | |
98 | assert(i); | |
99 | ||
100 | return i->path && path_startswith(i->path, "/usr"); | |
101 | } | |
102 | ||
103 | static inline bool IMAGE_IS_HOST(const struct Image *i) { | |
104 | assert(i); | |
105 | ||
106 | if (i->name && streq(i->name, ".host")) | |
107 | return true; | |
108 | ||
109 | if (i->path && path_equal(i->path, "/")) | |
110 | return true; | |
111 | ||
112 | return false; | |
113 | } |