]>
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 | ||
fd67de01 LP |
7 | #include "sd-id128.h" |
8 | ||
cd61c3bf | 9 | #include "hashmap.h" |
71d35b6b | 10 | #include "lockfile-util.h" |
a8fbdf54 | 11 | #include "macro.h" |
d94c2b06 LP |
12 | #include "path-util.h" |
13 | #include "string-util.h" | |
71d35b6b | 14 | #include "time-util.h" |
cd61c3bf | 15 | |
5ef46e5f LP |
16 | typedef enum ImageClass { |
17 | IMAGE_MACHINE, | |
18 | IMAGE_PORTABLE, | |
19 | _IMAGE_CLASS_MAX, | |
20 | _IMAGE_CLASS_INVALID = -1 | |
21 | } ImageClass; | |
22 | ||
cd61c3bf LP |
23 | typedef enum ImageType { |
24 | IMAGE_DIRECTORY, | |
25 | IMAGE_SUBVOLUME, | |
aceac2f0 | 26 | IMAGE_RAW, |
eb38edce | 27 | IMAGE_BLOCK, |
cd61c3bf LP |
28 | _IMAGE_TYPE_MAX, |
29 | _IMAGE_TYPE_INVALID = -1 | |
30 | } ImageType; | |
31 | ||
32 | typedef struct Image { | |
9614bb06 LP |
33 | unsigned n_ref; |
34 | ||
cd61c3bf LP |
35 | ImageType type; |
36 | char *name; | |
37 | char *path; | |
38 | bool read_only; | |
39 | ||
10f9c755 | 40 | usec_t crtime; |
cd61c3bf | 41 | usec_t mtime; |
b6b18498 | 42 | |
c19de711 LP |
43 | uint64_t usage; |
44 | uint64_t usage_exclusive; | |
b6b18498 LP |
45 | uint64_t limit; |
46 | uint64_t limit_exclusive; | |
70244d1d | 47 | |
c7664c07 LP |
48 | char *hostname; |
49 | sd_id128_t machine_id; | |
50 | char **machine_info; | |
51 | char **os_release; | |
52 | ||
cf604fd4 LP |
53 | bool metadata_valid:1; |
54 | bool discoverable:1; /* true if we know for sure that image_find() would find the image given just the short name */ | |
c7664c07 | 55 | |
70244d1d | 56 | void *userdata; |
cd61c3bf LP |
57 | } Image; |
58 | ||
59 | Image *image_unref(Image *i); | |
9614bb06 LP |
60 | Image *image_ref(Image *i); |
61 | ||
ebeccf9e | 62 | DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref); |
ebeccf9e | 63 | |
5ef46e5f | 64 | int image_find(ImageClass class, const char *name, Image **ret); |
2ddf182b LP |
65 | int image_from_path(const char *path, Image **ret); |
66 | int image_find_harder(ImageClass class, const char *name_or_path, Image **ret); | |
5ef46e5f | 67 | int image_discover(ImageClass class, Hashmap *map); |
cd61c3bf | 68 | |
08682124 | 69 | int image_remove(Image *i); |
ebd93cb6 LP |
70 | int image_rename(Image *i, const char *new_name); |
71 | int image_clone(Image *i, const char *new_name, bool read_only); | |
72 | int image_read_only(Image *i, bool b); | |
08682124 | 73 | |
cd61c3bf LP |
74 | const char* image_type_to_string(ImageType t) _const_; |
75 | ImageType image_type_from_string(const char *s) _pure_; | |
30535c16 LP |
76 | |
77 | bool image_name_is_valid(const char *s) _pure_; | |
78 | ||
79 | int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local); | |
80 | int image_name_lock(const char *name, int operation, LockFile *ret); | |
d6ce17c7 | 81 | |
cb81cd80 | 82 | int image_set_limit(Image *i, uint64_t referenced_max); |
d94c2b06 | 83 | |
c7664c07 LP |
84 | int image_read_metadata(Image *i); |
85 | ||
ace9ab19 LP |
86 | bool image_in_search_path(ImageClass class, const char *image); |
87 | ||
d94c2b06 LP |
88 | static inline bool IMAGE_IS_HIDDEN(const struct Image *i) { |
89 | assert(i); | |
90 | ||
91 | return i->name && i->name[0] == '.'; | |
92 | } | |
93 | ||
94 | static inline bool IMAGE_IS_VENDOR(const struct Image *i) { | |
95 | assert(i); | |
96 | ||
97 | return i->path && path_startswith(i->path, "/usr"); | |
98 | } | |
99 | ||
100 | static inline bool IMAGE_IS_HOST(const struct Image *i) { | |
101 | assert(i); | |
102 | ||
103 | if (i->name && streq(i->name, ".host")) | |
104 | return true; | |
105 | ||
106 | if (i->path && path_equal(i->path, "/")) | |
107 | return true; | |
108 | ||
109 | return false; | |
110 | } | |
b07ec5a1 YW |
111 | |
112 | extern const struct hash_ops image_hash_ops; |