Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : #pragma once 3 : 4 : #include <stdbool.h> 5 : #include <stdint.h> 6 : 7 : #include "sd-id128.h" 8 : 9 : #include "hashmap.h" 10 : #include "lockfile-util.h" 11 : #include "macro.h" 12 : #include "path-util.h" 13 : #include "string-util.h" 14 : #include "time-util.h" 15 : 16 : typedef enum ImageClass { 17 : IMAGE_MACHINE, 18 : IMAGE_PORTABLE, 19 : _IMAGE_CLASS_MAX, 20 : _IMAGE_CLASS_INVALID = -1 21 : } ImageClass; 22 : 23 : typedef enum ImageType { 24 : IMAGE_DIRECTORY, 25 : IMAGE_SUBVOLUME, 26 : IMAGE_RAW, 27 : IMAGE_BLOCK, 28 : _IMAGE_TYPE_MAX, 29 : _IMAGE_TYPE_INVALID = -1 30 : } ImageType; 31 : 32 : typedef struct Image { 33 : unsigned n_ref; 34 : 35 : ImageType type; 36 : char *name; 37 : char *path; 38 : bool read_only; 39 : 40 : usec_t crtime; 41 : usec_t mtime; 42 : 43 : uint64_t usage; 44 : uint64_t usage_exclusive; 45 : uint64_t limit; 46 : uint64_t limit_exclusive; 47 : 48 : char *hostname; 49 : sd_id128_t machine_id; 50 : char **machine_info; 51 : char **os_release; 52 : 53 : bool metadata_valid:1; 54 : bool discoverable:1; /* true if we know for sure that image_find() would find the image given just the short name */ 55 : 56 : void *userdata; 57 : } Image; 58 : 59 : Image *image_unref(Image *i); 60 : Image *image_ref(Image *i); 61 : 62 0 : DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref); 63 : 64 : int image_find(ImageClass class, const char *name, Image **ret); 65 : int image_from_path(const char *path, Image **ret); 66 : int image_find_harder(ImageClass class, const char *name_or_path, Image **ret); 67 : int image_discover(ImageClass class, Hashmap *map); 68 : 69 : int image_remove(Image *i); 70 : int image_rename(Image *i, const char *new_name); 71 : int image_clone(Image *i, const char *new_name, bool read_only); 72 : int image_read_only(Image *i, bool b); 73 : 74 : const char* image_type_to_string(ImageType t) _const_; 75 : ImageType image_type_from_string(const char *s) _pure_; 76 : 77 : bool image_name_is_valid(const char *s) _pure_; 78 : 79 : int image_path_lock(const char *path, int operation, LockFile *global, LockFile *local); 80 : int image_name_lock(const char *name, int operation, LockFile *ret); 81 : 82 : int image_set_limit(Image *i, uint64_t referenced_max); 83 : 84 : int image_read_metadata(Image *i); 85 : 86 : bool image_in_search_path(ImageClass class, const char *image); 87 : 88 0 : static inline bool IMAGE_IS_HIDDEN(const struct Image *i) { 89 0 : assert(i); 90 : 91 0 : return i->name && i->name[0] == '.'; 92 : } 93 : 94 0 : static inline bool IMAGE_IS_VENDOR(const struct Image *i) { 95 0 : assert(i); 96 : 97 0 : return i->path && path_startswith(i->path, "/usr"); 98 : } 99 : 100 0 : static inline bool IMAGE_IS_HOST(const struct Image *i) { 101 0 : assert(i); 102 : 103 0 : if (i->name && streq(i->name, ".host")) 104 0 : return true; 105 : 106 0 : if (i->path && path_equal(i->path, "/")) 107 0 : return true; 108 : 109 0 : return false; 110 : } 111 : 112 : extern const struct hash_ops image_hash_ops;