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