Mbed OS Reference
Loading...
Searching...
No Matches
lfs_emubd.h
1/*
2 * Block device emulated on standard files
3 *
4 * Copyright (c) 2017, Arm Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7#ifndef LFS_EMUBD_H
8#define LFS_EMUBD_H
9
10#include "lfs.h"
11#include "lfs_util.h"
12
13#ifdef __cplusplus
14extern "C"
15{
16#endif
17
18
19// Config options
20#ifndef LFS_EMUBD_READ_SIZE
21#define LFS_EMUBD_READ_SIZE 1
22#endif
23
24#ifndef LFS_EMUBD_PROG_SIZE
25#define LFS_EMUBD_PROG_SIZE 1
26#endif
27
28#ifndef LFS_EMUBD_ERASE_SIZE
29#define LFS_EMUBD_ERASE_SIZE 512
30#endif
31
32#ifndef LFS_EMUBD_TOTAL_SIZE
33#define LFS_EMUBD_TOTAL_SIZE 524288
34#endif
35
36
37// The emu bd state
38typedef struct lfs_emubd {
39 char *path;
40 char *child;
41
42 struct {
43 uint64_t read_count;
44 uint64_t prog_count;
45 uint64_t erase_count;
46 } stats;
47
48 struct {
49 uint32_t read_size;
50 uint32_t prog_size;
51 uint32_t block_size;
52 uint32_t block_count;
53 } cfg;
55
56
57// Create a block device using path for the directory to store blocks
58int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
59
60// Clean up memory associated with emu block device
61void lfs_emubd_destroy(const struct lfs_config *cfg);
62
63// Read a block
64int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
65 lfs_off_t off, void *buffer, lfs_size_t size);
66
67// Program a block
68//
69// The block must have previously been erased.
70int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
71 lfs_off_t off, const void *buffer, lfs_size_t size);
72
73// Erase a block
74//
75// A block must be erased before being programmed. The
76// state of an erased block is undefined.
77int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
78
79// Sync the block device
80int lfs_emubd_sync(const struct lfs_config *cfg);
81
82
83#ifdef __cplusplus
84} /* extern "C" */
85#endif
86
87#endif