Debian Codegraph @

src/libostree/ostree-repo-static-delta-private.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Colin Walters <[email protected]>
3 *
4 * SPDX-License-Identifier: LGPL-2.0+
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #pragma once
21
22 #include "ostree-core.h"
23
24 G_BEGIN_DECLS
25
26 /* Arbitrarily chosen */
27 #define OSTREE_STATIC_DELTA_PART_MAX_SIZE_BYTES (16 * 1024 * 1024)
28 /* 1 byte for object type, 32 bytes for checksum */
29 #define OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN 33
30
31 #define OSTREE_SUMMARY_STATIC_DELTAS "ostree.static-deltas"
32
33 /**
34 * OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0:
35 *
36 * y compression type (0: none, 'x': lzma)
37 * ---
38 * a(uuu) modes
39 * aa(ayay) xattrs
40 * ay raw data source
41 * ay operations
42 */
43 #define OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0 "(a(uuu)aa(ayay)ayay)"
44
45 /**
46 * OSTREE_STATIC_DELTA_META_ENTRY_FORMAT:
47 *
48 * u: version (non-canonical endian)
49 * ay checksum
50 * guint64 size: Total size of delta (sum of parts) (non-canonical endian)
51 * guint64 usize: Uncompressed size of resulting objects on disk (non-canonical endian)
52 * ARRAY[(guint8 objtype, csum object)]
53 *
54 * The checksum is of the delta payload, and each entry in the array
55 * represents an OSTree object which will be created by the deltapart.
56 */
57
58 #define OSTREE_STATIC_DELTA_META_ENTRY_FORMAT "(uayttay)"
59
60 /**
61 * OSTREE_STATIC_DELTA_FALLBACK_FORMAT:
62 *
63 * y: objtype
64 * ay: checksum
65 * t: compressed size (non-canonical endian)
66 * t: uncompressed size (non-canonical endian)
67 *
68 * Object to fetch invididually; includes compressed/uncompressed size.
69 */
70 #define OSTREE_STATIC_DELTA_FALLBACK_FORMAT "(yaytt)"
71
72 /**
73 * OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT:
74 *
75 * A .delta object is a custom binary format. It has the following high
76 * level form:
77 *
78 * delta-descriptor:
79 * metadata: a{sv}
80 * t: timestamp (big endian)
81 * from: ay checksum
82 * to: ay checksum
83 * commit: new commit object
84 * ARRAY[(csum from, csum to)]: ay
85 * ARRAY[delta-meta-entry]
86 * array[fallback]
87 *
88 * The metadata would include things like a version number, as well as
89 * extended verification data like a GPG signature.
90 *
91 * The second array is an array of delta objects that should be
92 * fetched and applied before this one. This is a fairly generic
93 * recursion mechanism that would potentially allow saving significant
94 * storage space on the server.
95 *
96 * The heart of the static delta: the array of delta parts.
97 *
98 * Finally, we have the fallback array, which is the set of objects to
99 * fetch individually - the compiler determined it wasn't worth
100 * duplicating the space.
101 */
102 #define OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT \
103 "(a{sv}tayay" OSTREE_COMMIT_GVARIANT_STRING "aya" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT \
104 "a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT ")"
105
106 /**
107 * OSTREE_STATIC_DELTA_SIGNED_FORMAT
108 *
109 * magic: t magic number, 8 bytes for alignment
110 * superblock: ay delta supeblock variant
111 * signatures: a{sv}
112 *
113 * The signed static delta starts with the 'OSTSGNDT' magic number followed by
114 * the array of bytes containing the superblock used for the signature.
115 *
116 * Then, the signatures array contains the signatures of the superblock. A
117 * signature has the following form:
118 * type: signature key
119 * signature: variant depending on type used
120 */
121 #define OSTREE_STATIC_DELTA_SIGNED_FORMAT "(taya{sv})"
122
123 #define OSTREE_STATIC_DELTA_SIGNED_MAGIC 0x4F535453474E4454 /* OSTSGNDT */
124
125 typedef enum
126 {
127 OSTREE_STATIC_DELTA_OPEN_FLAGS_NONE = 0,
128 OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM = (1 << 0),
129 OSTREE_STATIC_DELTA_OPEN_FLAGS_VARIANT_TRUSTED = (1 << 1)
130 } OstreeStaticDeltaOpenFlags;
131
132 typedef enum
133 {
134 OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE = 'S',
135 OSTREE_STATIC_DELTA_OP_OPEN = 'o',
136 OSTREE_STATIC_DELTA_OP_WRITE = 'w',
137 OSTREE_STATIC_DELTA_OP_SET_READ_SOURCE = 'r',
138 OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE = 'R',
139 OSTREE_STATIC_DELTA_OP_CLOSE = 'c',
140 OSTREE_STATIC_DELTA_OP_BSPATCH = 'B'
141 } OstreeStaticDeltaOpCode;
142 #define OSTREE_STATIC_DELTA_N_OPS 7
143
144 gboolean _ostree_static_delta_part_open (GInputStream *part_in, GBytes *inline_part_bytes,
145 OstreeStaticDeltaOpenFlags flags,
146 const char *expected_checksum, GVariant **out_part,
147 GCancellable *cancellable, GError **error);
148
149 typedef struct
150 {
151 guint n_ops_executed[OSTREE_STATIC_DELTA_N_OPS];
152 } OstreeDeltaExecuteStats;
153
154 gboolean _ostree_static_delta_part_execute (OstreeRepo *repo, GVariant *header,
155 GVariant *part_payload, gboolean stats_only,
156 OstreeDeltaExecuteStats *stats,
157 GCancellable *cancellable, GError **error);
158
159 void _ostree_static_delta_part_execute_async (OstreeRepo *repo, GVariant *header,
160 GVariant *part_payload, GCancellable *cancellable,
161 GAsyncReadyCallback callback, gpointer user_data);
162
163 gboolean _ostree_static_delta_part_execute_finish (OstreeRepo *repo, GAsyncResult *result,
164 GError **error);
165
166 gboolean _ostree_static_delta_parse_checksum_array (GVariant *array, guint8 **out_checksums_array,
167 guint *out_n_checksums, GError **error);
168
169 gboolean _ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo,
170 GVariant *checksum_array,
171 gboolean *out_have_all,
172 GCancellable *cancellable,
173 GError **error);
174
175 typedef struct
176 {
177 char *checksum;
178 guint64 size;
179 GPtrArray *basenames;
180 } OstreeDeltaContentSizeNames;
181
182 void _ostree_delta_content_sizenames_free (gpointer v);
183
184 gboolean _ostree_delta_compute_similar_objects (OstreeRepo *repo, GVariant *from_commit,
185 GVariant *to_commit,
186 GHashTable *new_reachable_regfile_content,
187 guint similarity_percent_threshold,
188 GHashTable **out_modified_regfile_content,
189 GCancellable *cancellable, GError **error);
190
191 gboolean _ostree_repo_static_delta_query_exists (OstreeRepo *repo, const char *delta_id,
192 gboolean *out_exists, GCancellable *cancellable,
193 GError **error);
194 GVariant *_ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, const char *from,
195 const char *to, GCancellable *cancellable,
196 GError **error);
197
198 gboolean _ostree_repo_static_delta_dump (OstreeRepo *repo, const char *delta_id,
199 GCancellable *cancellable, GError **error);
200
201 gboolean _ostree_repo_static_delta_delete (OstreeRepo *repo, const char *delta_id,
202 GCancellable *cancellable, GError **error);
203 gboolean _ostree_repo_static_delta_reindex (OstreeRepo *repo, const char *opt_to_commit,
204 GCancellable *cancellable, GError **error);
205
206 /* Used for static deltas which due to a historical mistake are
207 * inconsistent endian.
208 *
209 * https://bugzilla.gnome.org/show_bug.cgi?id=762515
210 */
211 static inline guint32
212 maybe_swap_endian_u32 (gboolean swap, guint32 v)
213 {
214 if (!swap)
215 return v;
216 return GUINT32_SWAP_LE_BE (v);
217 }
218
219 static inline guint64
220 maybe_swap_endian_u64 (gboolean swap, guint64 v)
221 {
222 if (!swap)
223 return v;
224 return GUINT64_SWAP_LE_BE (v);
225 }
226
227 typedef enum
228 {
229 OSTREE_DELTA_ENDIAN_BIG,
230 OSTREE_DELTA_ENDIAN_LITTLE,
231 OSTREE_DELTA_ENDIAN_INVALID
232 } OstreeDeltaEndianness;
233
234 OstreeDeltaEndianness _ostree_delta_get_endianness (GVariant *superblock,
235 gboolean *out_was_heuristic);
236
237 gboolean _ostree_delta_needs_byteswap (GVariant *superblock);
238
239 G_END_DECLS