• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Block device emulated in a file
3  *
4  * Copyright (c) 2022, The littlefs authors.
5  * Copyright (c) 2017, Arm Limited. All rights reserved.
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef LFS_FILEBD_H
9 #define LFS_FILEBD_H
10 
11 #include "lfs.h"
12 #include "lfs_util.h"
13 
14 #ifdef __cplusplus
15 extern "C"
16 {
17 #endif
18 
19 
20 // Block device specific tracing
21 #ifndef LFS_FILEBD_TRACE
22 #ifdef LFS_FILEBD_YES_TRACE
23 #define LFS_FILEBD_TRACE(...) LFS_TRACE(__VA_ARGS__)
24 #else
25 #define LFS_FILEBD_TRACE(...)
26 #endif
27 #endif
28 
29 // filebd config
30 struct lfs_filebd_config {
31     // Minimum size of a read operation in bytes.
32     lfs_size_t read_size;
33 
34     // Minimum size of a program operation in bytes.
35     lfs_size_t prog_size;
36 
37     // Size of an erase operation in bytes.
38     lfs_size_t erase_size;
39 
40     // Number of erase blocks on the device.
41     lfs_size_t erase_count;
42 };
43 
44 // filebd state
45 typedef struct lfs_filebd {
46     int fd;
47     const struct lfs_filebd_config *cfg;
48 } lfs_filebd_t;
49 
50 
51 // Create a file block device
52 int lfs_filebd_create(const struct lfs_config *cfg, const char *path,
53         const struct lfs_filebd_config *bdcfg);
54 
55 // Clean up memory associated with block device
56 int lfs_filebd_destroy(const struct lfs_config *cfg);
57 
58 // Read a block
59 int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block,
60         lfs_off_t off, void *buffer, lfs_size_t size);
61 
62 // Program a block
63 //
64 // The block must have previously been erased.
65 int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block,
66         lfs_off_t off, const void *buffer, lfs_size_t size);
67 
68 // Erase a block
69 //
70 // A block must be erased before being programmed. The
71 // state of an erased block is undefined.
72 int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block);
73 
74 // Sync the block device
75 int lfs_filebd_sync(const struct lfs_config *cfg);
76 
77 
78 #ifdef __cplusplus
79 } /* extern "C" */
80 #endif
81 
82 #endif
83