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