hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/fs/incfs/format.h
....@@ -72,7 +72,7 @@
7272 *
7373 *
7474 * +-------------------------------------------+
75
- * | incfs_super_block |]---+
75
+ * | incfs_file_header |]---+
7676 * +-------------------------------------------+ |
7777 * | metadata |<---+
7878 * | incfs_file_signature |]---+
....@@ -118,11 +118,13 @@
118118 INCFS_MD_NONE = 0,
119119 INCFS_MD_BLOCK_MAP = 1,
120120 INCFS_MD_FILE_ATTR = 2,
121
- INCFS_MD_SIGNATURE = 3
121
+ INCFS_MD_SIGNATURE = 3,
122
+ INCFS_MD_STATUS = 4,
123
+ INCFS_MD_VERITY_SIGNATURE = 5,
122124 };
123125
124126 enum incfs_file_header_flags {
125
- INCFS_FILE_COMPLETE = 1 << 0,
127
+ INCFS_FILE_MAPPED = 1 << 1,
126128 };
127129
128130 /* Header included at the beginning of all metadata records on the disk. */
....@@ -136,16 +138,16 @@
136138 __le16 h_record_size;
137139
138140 /*
139
- * CRC32 of the metadata record.
141
+ * Was: CRC32 of the metadata record.
140142 * (e.g. inode, dir entry etc) not just this struct.
141143 */
142
- __le32 h_record_crc;
144
+ __le32 h_unused1;
143145
144146 /* Offset of the next metadata entry if any */
145147 __le64 h_next_md_offset;
146148
147
- /* Offset of the previous metadata entry if any */
148
- __le64 h_prev_md_offset;
149
+ /* Was: Offset of the previous metadata entry if any */
150
+ __le64 h_unused2;
149151
150152 } __packed;
151153
....@@ -164,25 +166,41 @@
164166 __le16 fh_data_block_size;
165167
166168 /* File flags, from incfs_file_header_flags */
167
- __le32 fh_file_header_flags;
169
+ __le32 fh_flags;
168170
169
- /* Offset of the first metadata record */
170
- __le64 fh_first_md_offset;
171
+ union {
172
+ /* Standard incfs file */
173
+ struct {
174
+ /* Offset of the first metadata record */
175
+ __le64 fh_first_md_offset;
171176
172
- /*
173
- * Put file specific information after this point
174
- */
177
+ /* Full size of the file's content */
178
+ __le64 fh_file_size;
175179
176
- /* Full size of the file's content */
177
- __le64 fh_file_size;
180
+ /* File uuid */
181
+ incfs_uuid_t fh_uuid;
182
+ };
178183
179
- /* File uuid */
180
- incfs_uuid_t fh_uuid;
184
+ /* Mapped file - INCFS_FILE_MAPPED set in fh_flags */
185
+ struct {
186
+ /* Offset in original file */
187
+ __le64 fh_original_offset;
188
+
189
+ /* Full size of the file's content */
190
+ __le64 fh_mapped_file_size;
191
+
192
+ /* Original file's uuid */
193
+ incfs_uuid_t fh_original_uuid;
194
+ };
195
+ };
181196 } __packed;
182197
183198 enum incfs_block_map_entry_flags {
184
- INCFS_BLOCK_COMPRESSED_LZ4 = (1 << 0),
185
- INCFS_BLOCK_HASH = (1 << 1),
199
+ INCFS_BLOCK_COMPRESSED_LZ4 = 1,
200
+ INCFS_BLOCK_COMPRESSED_ZSTD = 2,
201
+
202
+ /* Reserve 3 bits for compression alg */
203
+ INCFS_BLOCK_COMPRESSED_MASK = 7,
186204 };
187205
188206 /* Block map entry pointing to an actual location of the data block. */
....@@ -211,18 +229,18 @@
211229 __le32 m_block_count;
212230 } __packed;
213231
214
-/* Metadata record for file attribute. Type = INCFS_MD_FILE_ATTR */
215
-struct incfs_file_attr {
216
- struct incfs_md_header fa_header;
217
-
218
- __le64 fa_offset;
219
-
220
- __le16 fa_size;
221
-
222
- __le32 fa_crc;
223
-} __packed;
224
-
225
-/* Metadata record for file signature. Type = INCFS_MD_SIGNATURE */
232
+/*
233
+ * Metadata record for file signature. Type = INCFS_MD_SIGNATURE
234
+ *
235
+ * The signature stored here is the APK V4 signature data blob. See the
236
+ * definition of incfs_new_file_args::signature_info for an explanation of this
237
+ * blob. Specifically, it contains the root hash, but it does *not* contain
238
+ * anything that the kernel treats as a signature.
239
+ *
240
+ * When FS_IOC_ENABLE_VERITY is called on a file without this record, an APK V4
241
+ * signature blob and a hash tree are added to the file, and then this metadata
242
+ * record is created to record their locations.
243
+ */
226244 struct incfs_file_signature {
227245 struct incfs_md_header sg_header;
228246
....@@ -241,6 +259,39 @@
241259 u64 sig_offset;
242260 u32 hash_size;
243261 u64 hash_offset;
262
+};
263
+
264
+struct incfs_status {
265
+ struct incfs_md_header is_header;
266
+
267
+ __le32 is_data_blocks_written; /* Number of data blocks written */
268
+
269
+ __le32 is_hash_blocks_written; /* Number of hash blocks written */
270
+
271
+ __le32 is_dummy[6]; /* Spare fields */
272
+} __packed;
273
+
274
+/*
275
+ * Metadata record for verity signature. Type = INCFS_MD_VERITY_SIGNATURE
276
+ *
277
+ * This record will only exist for verity-enabled files with signatures. Verity
278
+ * enabled files without signatures do not have this record. This signature is
279
+ * checked by fs-verity identically to any other fs-verity signature.
280
+ */
281
+struct incfs_file_verity_signature {
282
+ struct incfs_md_header vs_header;
283
+
284
+ /* The size of the signature */
285
+ __le32 vs_size;
286
+
287
+ /* Signature's offset in the backing file */
288
+ __le64 vs_offset;
289
+} __packed;
290
+
291
+/* In memory version of above */
292
+struct incfs_df_verity_signature {
293
+ u32 size;
294
+ u64 offset;
244295 };
245296
246297 /* State of the backing file. */
....@@ -273,21 +324,22 @@
273324 union {
274325 struct incfs_md_header md_header;
275326 struct incfs_blockmap blockmap;
276
- struct incfs_file_attr file_attr;
277327 struct incfs_file_signature signature;
328
+ struct incfs_status status;
329
+ struct incfs_file_verity_signature verity_signature;
278330 } md_buffer;
279331
280332 int (*handle_blockmap)(struct incfs_blockmap *bm,
281333 struct metadata_handler *handler);
282
- int (*handle_file_attr)(struct incfs_file_attr *fa,
283
- struct metadata_handler *handler);
284334 int (*handle_signature)(struct incfs_file_signature *sig,
285335 struct metadata_handler *handler);
336
+ int (*handle_status)(struct incfs_status *sig,
337
+ struct metadata_handler *handler);
338
+ int (*handle_verity_signature)(struct incfs_file_verity_signature *s,
339
+ struct metadata_handler *handler);
286340 };
287341 #define INCFS_MAX_METADATA_RECORD_SIZE \
288
- FIELD_SIZEOF(struct metadata_handler, md_buffer)
289
-
290
-loff_t incfs_get_end_offset(struct file *f);
342
+ sizeof_field(struct metadata_handler, md_buffer)
291343
292344 /* Backing file context management */
293345 struct mount_info;
....@@ -303,6 +355,9 @@
303355 int incfs_write_fh_to_backing_file(struct backing_file_context *bfc,
304356 incfs_uuid_t *uuid, u64 file_size);
305357
358
+int incfs_write_mapping_fh_to_backing_file(struct backing_file_context *bfc,
359
+ incfs_uuid_t *uuid, u64 file_size, u64 offset);
360
+
306361 int incfs_write_data_block_to_backing_file(struct backing_file_context *bfc,
307362 struct mem_range block,
308363 int block_index, loff_t bm_base_off,
....@@ -315,16 +370,17 @@
315370 loff_t bm_base_off,
316371 loff_t file_size);
317372
318
-int incfs_write_file_attr_to_backing_file(struct backing_file_context *bfc,
319
- struct mem_range value, struct incfs_file_attr *attr);
320
-
321373 int incfs_write_signature_to_backing_file(struct backing_file_context *bfc,
322
- struct mem_range sig, u32 tree_size);
374
+ struct mem_range sig, u32 tree_size,
375
+ loff_t *tree_offset, loff_t *sig_offset);
323376
324
-int incfs_write_file_header_flags(struct backing_file_context *bfc, u32 flags);
325
-
326
-int incfs_make_empty_backing_file(struct backing_file_context *bfc,
327
- incfs_uuid_t *uuid, u64 file_size);
377
+int incfs_write_status_to_backing_file(struct backing_file_context *bfc,
378
+ loff_t status_offset,
379
+ u32 data_blocks_written,
380
+ u32 hash_blocks_written);
381
+int incfs_write_verity_signature_to_backing_file(
382
+ struct backing_file_context *bfc, struct mem_range signature,
383
+ loff_t *offset);
328384
329385 /* Reading stuff */
330386 int incfs_read_file_header(struct backing_file_context *bfc,