mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 10:14:55 +00:00
vboot2: Add host library functions to read/write files and objects
And unit tests for them. Move roundup32() into hostlib. Fix WriteFile() returning success even if it failed to write to the file. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I8a115335c088dc5c66c88423d1ccbda7eaca1996 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/230844
This commit is contained in:
committed by
chrome-internal-fetch
parent
8577b5360c
commit
02e11b323b
@@ -43,4 +43,45 @@ int ReadFileBit(const char* filename, int bitmask);
|
||||
* Returns 0 if success, 1 if error. */
|
||||
int WriteFile(const char* filename, const void *data, uint64_t size);
|
||||
|
||||
/**
|
||||
* Read data from a file into a newly allocated buffer.
|
||||
*
|
||||
* @param filename Name of file to read from
|
||||
* @param data_ptr On exit, pointer to newly allocated buffer with data
|
||||
* will be stored here. Caller must free() the buffer
|
||||
* when done with it.
|
||||
* @param size_ptr On exit, size of data will be stored here.
|
||||
* @return VB2_SUCCESS, or non-zero if error.
|
||||
*/
|
||||
int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr);
|
||||
|
||||
/**
|
||||
* Write data to a file from a buffer.
|
||||
*
|
||||
* @param filename Name of file to write to
|
||||
* @param buf Buffer to write
|
||||
* @param size Number of bytes of data to write
|
||||
* @return VB2_SUCCESS, or non-zero if error.
|
||||
*/
|
||||
int vb2_write_file(const char *filename, const void *buf, uint32_t size);
|
||||
|
||||
/**
|
||||
* Write a buffer which starts with a standard vb2_struct_common header.
|
||||
*
|
||||
* Determines the buffer size from the common header total size field.
|
||||
*
|
||||
* @param filename Name of file to write to
|
||||
* @param buf Buffer to write
|
||||
* @return VB2_SUCCESS, or non-zero if error.
|
||||
*/
|
||||
int vb2_write_object(const char *filename, const void *buf);
|
||||
|
||||
/**
|
||||
* Round up a size to a multiple of 32 bits (4 bytes).
|
||||
*/
|
||||
static __inline const uint32_t roundup32(uint32_t v)
|
||||
{
|
||||
return (v + 3) & ~3;
|
||||
}
|
||||
|
||||
#endif /* VBOOT_REFERENCE_HOST_MISC_H_ */
|
||||
|
||||
Reference in New Issue
Block a user