1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __ITS_FLASH_FS_DBLOCK_H__
9 #define __ITS_FLASH_FS_DBLOCK_H__
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include "psa/error.h"
15 #include "its_flash_fs_mblock.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /**
22  * \brief Compacts block data for the given logical block.
23  *
24  * \param[in,out] fs_ctx      Filesystem context
25  * \param[in]     lblock      Logical data block to compact
26  * \param[in]     free_size   Available data size to compact
27  * \param[in]     src_offset  Offset in the current data block which points to
28  *                            the data position to reallocate
29  * \param[in]     dst_offset  Offset in the scratch block which points to the
30  *                            data position to store the data to be reallocated
31  * \param[in]     size        Number of bytes to be reallocated
32  *
33  * \return Returns error code as specified in \ref psa_status_t
34  */
35 psa_status_t its_flash_fs_dblock_compact_block(
36                                               struct its_flash_fs_ctx_t *fs_ctx,
37                                               uint32_t lblock,
38                                               size_t free_size,
39                                               size_t src_offset,
40                                               size_t dst_offset,
41                                               size_t size);
42 
43 /**
44  * \brief Reads the file content.
45  *
46  * \param[in,out] fs_ctx     Filesystem context
47  * \param[in]     file_meta  File metadata
48  * \param[in]     offset     Offset in the file
49  * \param[in]     size       Size to be read
50  * \param[out]    buf        Buffer pointer to store the data
51  *
52  * \return Returns error code as specified in \ref psa_status_t
53  */
54 psa_status_t its_flash_fs_dblock_read_file(
55                                         struct its_flash_fs_ctx_t *fs_ctx,
56                                         const struct its_file_meta_t *file_meta,
57                                         size_t offset,
58                                         size_t size,
59                                         uint8_t *buf);
60 
61 /**
62  * \brief Writes scratch data block content with requested data and the rest of
63  *        the data from the given logical block.
64  *
65  * \param[in,out] fs_ctx      Filesystem context
66  * \param[in]     block_meta  Block metadata
67  * \param[in]     file_meta   File metadata
68  * \param[in]     offset      Offset in the scratch data block where to start
69  *                            the copy of the incoming data
70  * \param[in]     size        Size of the incoming data
71  * \param[in]     data        Pointer to data buffer to copy in the scratch data
72  *                            block
73  *
74  * \return Returns error code as specified in \ref psa_status_t
75  */
76 psa_status_t its_flash_fs_dblock_write_file(
77                                       struct its_flash_fs_ctx_t *fs_ctx,
78                                       const struct its_block_meta_t *block_meta,
79                                       const struct its_file_meta_t *file_meta,
80                                       size_t offset,
81                                       size_t size,
82                                       const uint8_t *data);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif /* __ITS_FLASH_FS_DBLOCK_H__ */
89