1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef REGION_FILE_H 4 #define REGION_FILE_H 5 6 #include <commonlib/region.h> 7 #include <stddef.h> 8 #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 20 struct region_file; 21 22 /* 23 * Initialize a region file associated with a provided region device. 24 * Returns < 0 on error, 0 on success. 25 */ 26 int 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 */ 32 int region_file_data(const struct region_file *f, struct region_device *rdev); 33 34 /* 35 * Create region file entry struct to insert multiple data buffers 36 * into the same region_file. 37 */ 38 struct update_region_file_entry { 39 /* size of this entry */ 40 size_t size; 41 /* data pointer */ 42 const void *data; 43 }; 44 45 /* Update region file with latest data. Returns < 0 on error, 0 on success. */ 46 int region_file_update_data_arr(struct region_file *f, 47 const struct update_region_file_entry *entries, 48 size_t num_entries); 49 int region_file_update_data(struct region_file *f, const void *buf, size_t size); 50 51 /* Declared here for easy object allocation. */ 52 struct 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 */ 64