]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/machine-image.h
Add SPDX license identifiers to source files under the LGPL
[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
LP
55
56 void *userdata;
cd61c3bf
LP
57} Image;
58
59Image *image_unref(Image *i);
cd61c3bf
LP
60void image_hashmap_free(Hashmap *map);
61
ebeccf9e
LP
62DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
63DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
64
c2ce6a3d 65int image_find(const char *name, Image **ret);
cd61c3bf
LP
66int image_discover(Hashmap *map);
67
08682124 68int image_remove(Image *i);
ebd93cb6
LP
69int image_rename(Image *i, const char *new_name);
70int image_clone(Image *i, const char *new_name, bool read_only);
71int image_read_only(Image *i, bool b);
08682124 72
cd61c3bf
LP
73const char* image_type_to_string(ImageType t) _const_;
74ImageType image_type_from_string(const char *s) _pure_;
30535c16
LP
75
76bool image_name_is_valid(const char *s) _pure_;
77
78int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local);
79int image_name_lock(const char *name, int operation, LockFile *ret);
d6ce17c7 80
cb81cd80 81int image_set_limit(Image *i, uint64_t referenced_max);
d94c2b06
LP
82
83static inline bool IMAGE_IS_HIDDEN(const struct Image *i) {
84 assert(i);
85
86 return i->name && i->name[0] == '.';
87}
88
89static inline bool IMAGE_IS_VENDOR(const struct Image *i) {
90 assert(i);
91
92 return i->path && path_startswith(i->path, "/usr");
93}
94
95static inline bool IMAGE_IS_HOST(const struct Image *i) {
96 assert(i);
97
98 if (i->name && streq(i->name, ".host"))
99 return true;
100
101 if (i->path && path_equal(i->path, "/"))
102 return true;
103
104 return false;
105}