Debian Codegraph @

src/sysupdate/sysupdate-resource.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "gpt.h"
5 #include "sysupdate-forward.h"
6
7 typedef enum ResourceType {
8 RESOURCE_URL_FILE,
9 RESOURCE_URL_TAR,
10 RESOURCE_TAR,
11 RESOURCE_PARTITION,
12 RESOURCE_REGULAR_FILE,
13 RESOURCE_DIRECTORY,
14 RESOURCE_SUBVOLUME,
15 _RESOURCE_TYPE_MAX,
16 _RESOURCE_TYPE_INVALID = -EINVAL,
17 } ResourceType;
18
19 static inline bool RESOURCE_IS_SOURCE(ResourceType t) {
20 return IN_SET(t,
21 RESOURCE_URL_FILE,
22 RESOURCE_URL_TAR,
23 RESOURCE_TAR,
24 RESOURCE_REGULAR_FILE,
25 RESOURCE_DIRECTORY,
26 RESOURCE_SUBVOLUME);
27 }
28
29 static inline bool RESOURCE_IS_TARGET(ResourceType t) {
30 return IN_SET(t,
31 RESOURCE_PARTITION,
32 RESOURCE_REGULAR_FILE,
33 RESOURCE_DIRECTORY,
34 RESOURCE_SUBVOLUME);
35 }
36
37 /* Returns true for all resources that deal with file system objects, i.e. where we operate on top of the
38 * file system layer, instead of below. */
39 static inline bool RESOURCE_IS_FILESYSTEM(ResourceType t) {
40 return IN_SET(t,
41 RESOURCE_TAR,
42 RESOURCE_REGULAR_FILE,
43 RESOURCE_DIRECTORY,
44 RESOURCE_SUBVOLUME);
45 }
46
47 static inline bool RESOURCE_IS_TAR(ResourceType t) {
48 return IN_SET(t,
49 RESOURCE_TAR,
50 RESOURCE_URL_TAR);
51 }
52
53 static inline bool RESOURCE_IS_URL(ResourceType t) {
54 return IN_SET(t,
55 RESOURCE_URL_TAR,
56 RESOURCE_URL_FILE);
57 }
58
59 typedef enum PathRelativeTo {
60 /* Please make sure to follow the naming of the corresponding PartitionDesignator enum values,
61 * where this makes sense, like for the following three. */
62 PATH_RELATIVE_TO_ROOT,
63 PATH_RELATIVE_TO_ESP,
64 PATH_RELATIVE_TO_XBOOTLDR,
65 PATH_RELATIVE_TO_BOOT, /* Refers to $BOOT from the BLS. No direct counterpart in PartitionDesignator */
66 PATH_RELATIVE_TO_EXPLICIT,
67 _PATH_RELATIVE_TO_MAX,
68 _PATH_RELATIVE_TO_INVALID = -EINVAL,
69 } PathRelativeTo;
70
71 typedef struct Resource {
72 ResourceType type;
73
74 /* Where to look for instances, and what to match precisely */
75 char *path;
76 bool path_auto; /* automatically find root path (only available if target resource, not source resource) */
77 PathRelativeTo path_relative_to;
78 char **patterns;
79 GptPartitionType partition_type;
80 bool partition_type_set;
81
82 /* All instances of this resource we found */
83 Instance **instances;
84 size_t n_instances;
85
86 /* If this is a partition resource (RESOURCE_PARTITION), then how many partition slots are currently unassigned, that we can use */
87 size_t n_empty;
88 } Resource;
89
90 void resource_destroy(Resource *rr);
91
92 int resource_load_instances(Resource *rr, bool verify, Hashmap **web_cache);
93
94 Instance* resource_find_instance(Resource *rr, const char *version);
95
96 int resource_resolve_path(Resource *rr, const char *root, const char *relative_to_directory, const char *node);
97
98 DECLARE_STRING_TABLE_LOOKUP(resource_type, ResourceType);
99 DECLARE_STRING_TABLE_LOOKUP(path_relative_to, PathRelativeTo);