]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/machine-image.h
machine-image: add a generic API to determine metadata of any image
[thirdparty/systemd.git] / src / shared / machine-image.h
CommitLineData
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 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
a8fbdf54
TA
23#include <stdbool.h>
24#include <stdint.h>
25
cd61c3bf 26#include "hashmap.h"
71d35b6b 27#include "lockfile-util.h"
a8fbdf54 28#include "macro.h"
d94c2b06
LP
29#include "path-util.h"
30#include "string-util.h"
71d35b6b 31#include "time-util.h"
cd61c3bf
LP
32
33typedef enum ImageType {
34 IMAGE_DIRECTORY,
35 IMAGE_SUBVOLUME,
aceac2f0 36 IMAGE_RAW,
eb38edce 37 IMAGE_BLOCK,
cd61c3bf
LP
38 _IMAGE_TYPE_MAX,
39 _IMAGE_TYPE_INVALID = -1
40} ImageType;
41
42typedef struct Image {
43 ImageType type;
44 char *name;
45 char *path;
46 bool read_only;
47
10f9c755 48 usec_t crtime;
cd61c3bf 49 usec_t mtime;
b6b18498 50
c19de711
LP
51 uint64_t usage;
52 uint64_t usage_exclusive;
b6b18498
LP
53 uint64_t limit;
54 uint64_t limit_exclusive;
70244d1d 55
c7664c07
LP
56 char *hostname;
57 sd_id128_t machine_id;
58 char **machine_info;
59 char **os_release;
60
61 bool metadata_valid;
62
70244d1d 63 void *userdata;
cd61c3bf
LP
64} Image;
65
66Image *image_unref(Image *i);
cd61c3bf
LP
67void image_hashmap_free(Hashmap *map);
68
ebeccf9e
LP
69DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
70DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
71
c2ce6a3d 72int image_find(const char *name, Image **ret);
cd61c3bf
LP
73int image_discover(Hashmap *map);
74
08682124 75int image_remove(Image *i);
ebd93cb6
LP
76int image_rename(Image *i, const char *new_name);
77int image_clone(Image *i, const char *new_name, bool read_only);
78int image_read_only(Image *i, bool b);
08682124 79
cd61c3bf
LP
80const char* image_type_to_string(ImageType t) _const_;
81ImageType image_type_from_string(const char *s) _pure_;
30535c16
LP
82
83bool image_name_is_valid(const char *s) _pure_;
84
85int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local);
86int image_name_lock(const char *name, int operation, LockFile *ret);
d6ce17c7 87
cb81cd80 88int image_set_limit(Image *i, uint64_t referenced_max);
d94c2b06 89
c7664c07
LP
90int image_read_metadata(Image *i);
91
d94c2b06
LP
92static inline bool IMAGE_IS_HIDDEN(const struct Image *i) {
93 assert(i);
94
95 return i->name && i->name[0] == '.';
96}
97
98static inline bool IMAGE_IS_VENDOR(const struct Image *i) {
99 assert(i);
100
101 return i->path && path_startswith(i->path, "/usr");
102}
103
104static 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}