blob: a3cb79d044afcd9c4cd09dee73d4dc6027fbb86d [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbincd0bc982016-11-19 12:36:09 -06002
3#ifndef REGION_FILE_H
4#define REGION_FILE_H
5
6#include <commonlib/region.h>
Elyes HAOUAS5817c562020-07-12 09:03:22 +02007#include <stddef.h>
Aaron Durbincd0bc982016-11-19 12:36:09 -06008#include <stdint.h>
9
10/*
11 * A region file is an abstraction to allow appending updates in a
12 * region_device where the data returned is the most recently written
13 * data. It is block based with a 16 byte granularity. So if you write
14 * 2 bytes into the file the data returned in the region_device would
15 * have 16 bytes allocated for the latest update. Additionally, the
16 * current maximum file size allowed is 1MiB - 48 bytes. See comments
17 * in C implementation file for further details.
18 */
19
20struct region_file;
21
22/*
23 * Initialize a region file associated with a provided region device.
24 * Returns < 0 on error, 0 on success.
25 */
26int region_file_init(struct region_file *f, const struct region_device *p);
27
28/*
29 * Initialize region device object associated with latest update of file data.
30 * Returns < 0 on error, 0 on success.
31 */
32int region_file_data(const struct region_file *f, struct region_device *rdev);
33
Shelley Chen2d90ddd2020-09-15 00:41:14 -070034/*
35 * Create region file entry struct to insert multiple data buffers
36 * into the same region_file.
37 */
38struct update_region_file_entry {
39 /* size of this entry */
40 size_t size;
41 /* data pointer */
42 const void *data;
43};
44
Aaron Durbincd0bc982016-11-19 12:36:09 -060045/* Update region file with latest data. Returns < 0 on error, 0 on success. */
Shelley Chen2d90ddd2020-09-15 00:41:14 -070046int region_file_update_data_arr(struct region_file *f,
47 const struct update_region_file_entry *entries,
48 size_t num_entries);
49int region_file_update_data(struct region_file *f, const void *buf, size_t size);
Aaron Durbincd0bc982016-11-19 12:36:09 -060050
51/* Declared here for easy object allocation. */
52struct region_file {
53 /* Region device covering file */
54 struct region_device rdev;
55 /* Metadata containing blocks of the data stream. */
56 struct region_device metadata;
57 /* Blocks forming data. */
58 uint16_t data_blocks[2];
59 /* Current slot in metadata marking end of data. */
60 int slot;
61};
62
63#endif /* REGION_FILE_H */