]>
Commit | Line | Data |
---|---|---|
cd61c3bf LP |
1 | #pragma once |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
ebeccf9e | 6 | Copyright 2014 Lennart Poettering |
cd61c3bf LP |
7 | |
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
a8fbdf54 TA |
22 | #include <stdbool.h> |
23 | #include <stdint.h> | |
24 | ||
cd61c3bf | 25 | #include "hashmap.h" |
71d35b6b | 26 | #include "lockfile-util.h" |
a8fbdf54 | 27 | #include "macro.h" |
d94c2b06 LP |
28 | #include "path-util.h" |
29 | #include "string-util.h" | |
71d35b6b | 30 | #include "time-util.h" |
cd61c3bf LP |
31 | |
32 | typedef enum ImageType { | |
33 | IMAGE_DIRECTORY, | |
34 | IMAGE_SUBVOLUME, | |
aceac2f0 | 35 | IMAGE_RAW, |
cd61c3bf LP |
36 | _IMAGE_TYPE_MAX, |
37 | _IMAGE_TYPE_INVALID = -1 | |
38 | } ImageType; | |
39 | ||
40 | typedef struct Image { | |
41 | ImageType type; | |
42 | char *name; | |
43 | char *path; | |
44 | bool read_only; | |
45 | ||
10f9c755 | 46 | usec_t crtime; |
cd61c3bf | 47 | usec_t mtime; |
b6b18498 | 48 | |
c19de711 LP |
49 | uint64_t usage; |
50 | uint64_t usage_exclusive; | |
b6b18498 LP |
51 | uint64_t limit; |
52 | uint64_t limit_exclusive; | |
70244d1d LP |
53 | |
54 | void *userdata; | |
cd61c3bf LP |
55 | } Image; |
56 | ||
57 | Image *image_unref(Image *i); | |
cd61c3bf LP |
58 | void image_hashmap_free(Hashmap *map); |
59 | ||
ebeccf9e LP |
60 | DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref); |
61 | DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free); | |
62 | ||
c2ce6a3d | 63 | int image_find(const char *name, Image **ret); |
cd61c3bf LP |
64 | int image_discover(Hashmap *map); |
65 | ||
08682124 | 66 | int image_remove(Image *i); |
ebd93cb6 LP |
67 | int image_rename(Image *i, const char *new_name); |
68 | int image_clone(Image *i, const char *new_name, bool read_only); | |
69 | int image_read_only(Image *i, bool b); | |
08682124 | 70 | |
cd61c3bf LP |
71 | const char* image_type_to_string(ImageType t) _const_; |
72 | ImageType image_type_from_string(const char *s) _pure_; | |
30535c16 LP |
73 | |
74 | bool image_name_is_valid(const char *s) _pure_; | |
75 | ||
76 | int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local); | |
77 | int image_name_lock(const char *name, int operation, LockFile *ret); | |
d6ce17c7 | 78 | |
cb81cd80 | 79 | int image_set_limit(Image *i, uint64_t referenced_max); |
d94c2b06 LP |
80 | |
81 | static inline bool IMAGE_IS_HIDDEN(const struct Image *i) { | |
82 | assert(i); | |
83 | ||
84 | return i->name && i->name[0] == '.'; | |
85 | } | |
86 | ||
87 | static inline bool IMAGE_IS_VENDOR(const struct Image *i) { | |
88 | assert(i); | |
89 | ||
90 | return i->path && path_startswith(i->path, "/usr"); | |
91 | } | |
92 | ||
93 | static inline bool IMAGE_IS_HOST(const struct Image *i) { | |
94 | assert(i); | |
95 | ||
96 | if (i->name && streq(i->name, ".host")) | |
97 | return true; | |
98 | ||
99 | if (i->path && path_equal(i->path, "/")) | |
100 | return true; | |
101 | ||
102 | return false; | |
103 | } |