]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/machine-image.h
Merge pull request #8417 from brauner/2018-03-09/add_bind_mount_fallback_to_private_d...
[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
10 #include <stdbool.h>
11 #include <stdint.h>
12
13 #include "hashmap.h"
14 #include "lockfile-util.h"
15 #include "macro.h"
16 #include "path-util.h"
17 #include "string-util.h"
18 #include "time-util.h"
19
20 typedef enum ImageType {
21 IMAGE_DIRECTORY,
22 IMAGE_SUBVOLUME,
23 IMAGE_RAW,
24 IMAGE_BLOCK,
25 _IMAGE_TYPE_MAX,
26 _IMAGE_TYPE_INVALID = -1
27 } ImageType;
28
29 typedef struct Image {
30 ImageType type;
31 char *name;
32 char *path;
33 bool read_only;
34
35 usec_t crtime;
36 usec_t mtime;
37
38 uint64_t usage;
39 uint64_t usage_exclusive;
40 uint64_t limit;
41 uint64_t limit_exclusive;
42
43 char *hostname;
44 sd_id128_t machine_id;
45 char **machine_info;
46 char **os_release;
47
48 bool metadata_valid;
49
50 void *userdata;
51 } Image;
52
53 Image *image_unref(Image *i);
54 static inline Hashmap* image_hashmap_free(Hashmap *map) {
55 return hashmap_free_with_destructor(map, image_unref);
56 }
57
58 DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
59 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
60
61 int image_find(const char *name, Image **ret);
62 int image_discover(Hashmap *map);
63
64 int image_remove(Image *i);
65 int image_rename(Image *i, const char *new_name);
66 int image_clone(Image *i, const char *new_name, bool read_only);
67 int image_read_only(Image *i, bool b);
68
69 const char* image_type_to_string(ImageType t) _const_;
70 ImageType image_type_from_string(const char *s) _pure_;
71
72 bool image_name_is_valid(const char *s) _pure_;
73
74 int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local);
75 int image_name_lock(const char *name, int operation, LockFile *ret);
76
77 int image_set_limit(Image *i, uint64_t referenced_max);
78
79 int image_read_metadata(Image *i);
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 }