Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | cd0bc98 | 2016-11-19 12:36:09 -0600 | [diff] [blame] | 2 | |
| 3 | #ifndef REGION_FILE_H |
| 4 | #define REGION_FILE_H |
| 5 | |
| 6 | #include <commonlib/region.h> |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | /* |
| 10 | * A region file is an abstraction to allow appending updates in a |
| 11 | * region_device where the data returned is the most recently written |
| 12 | * data. It is block based with a 16 byte granularity. So if you write |
| 13 | * 2 bytes into the file the data returned in the region_device would |
| 14 | * have 16 bytes allocated for the latest update. Additionally, the |
| 15 | * current maximum file size allowed is 1MiB - 48 bytes. See comments |
| 16 | * in C implementation file for further details. |
| 17 | */ |
| 18 | |
| 19 | struct region_file; |
| 20 | |
| 21 | /* |
| 22 | * Initialize a region file associated with a provided region device. |
| 23 | * Returns < 0 on error, 0 on success. |
| 24 | */ |
| 25 | int region_file_init(struct region_file *f, const struct region_device *p); |
| 26 | |
| 27 | /* |
| 28 | * Initialize region device object associated with latest update of file data. |
| 29 | * Returns < 0 on error, 0 on success. |
| 30 | */ |
| 31 | int region_file_data(const struct region_file *f, struct region_device *rdev); |
| 32 | |
| 33 | /* Update region file with latest data. Returns < 0 on error, 0 on success. */ |
| 34 | int region_file_update_data(struct region_file *f, const void *buf, |
| 35 | size_t size); |
| 36 | |
| 37 | /* Declared here for easy object allocation. */ |
| 38 | struct region_file { |
| 39 | /* Region device covering file */ |
| 40 | struct region_device rdev; |
| 41 | /* Metadata containing blocks of the data stream. */ |
| 42 | struct region_device metadata; |
| 43 | /* Blocks forming data. */ |
| 44 | uint16_t data_blocks[2]; |
| 45 | /* Current slot in metadata marking end of data. */ |
| 46 | int slot; |
| 47 | }; |
| 48 | |
| 49 | #endif /* REGION_FILE_H */ |