This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
forked from Jason2866/LittleFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlittlefs_api.h
106 lines (93 loc) · 3.51 KB
/
littlefs_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef ESP_LITTLEFS_API_H__
#define ESP_LITTLEFS_API_H__
#include <stdint.h>
#include <stddef.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_vfs.h"
#include "esp_partition.h"
#include "lfs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief a file descriptor
* That's also a singly linked list used for keeping tracks of all opened file descriptor
*
* Shortcomings/potential issues of 32-bit hash (when CONFIG_LITTLEFS_USE_ONLY_HASH) listed here:
* * unlink - If a different file is open that generates a hash collision, it will report an
* error that it cannot unlink an open file.
* * rename - If a different file is open that generates a hash collision with
* src or dst, it will report an error that it cannot rename an open file.
* Potential consequences:
* 1. A file cannot be deleted while a collision-geneating file is open.
* Worst-case, if the other file is always open during the lifecycle
* of your app, it's collision file cannot be deleted, which in the
* worst-case could cause storage-capacity issues.
* 2. Same as (1), but for renames
*/
typedef struct _vfs_littlefs_file_t {
lfs_file_t file;
uint32_t hash;
struct _vfs_littlefs_file_t * next; /*!< Pointer to next file in Singly Linked List */
#ifndef CONFIG_LITTLEFS_USE_ONLY_HASH
char * path;
#endif
} vfs_littlefs_file_t;
/**
* @brief littlefs definition structure
*/
typedef struct {
lfs_t *fs; /*!< Handle to the underlying littlefs */
SemaphoreHandle_t lock; /*!< FS lock */
const esp_partition_t* partition; /*!< The partition on which littlefs is located */
char base_path[ESP_VFS_PATH_MAX+1]; /*!< Mount point */
struct lfs_config cfg; /*!< littlefs Mount configuration */
vfs_littlefs_file_t *file; /*!< Singly Linked List of files */
vfs_littlefs_file_t **cache; /*!< A cache of pointers to the opened files */
uint16_t cache_size; /*!< The cache allocated size (in pointers) */
uint16_t fd_count; /*!< The count of opened file descriptor used to speed up computation */
} esp_littlefs_t;
/**
* @brief Read a region in a block.
*
* Negative error codes are propogated to the user.
*
* @return errorcode. 0 on success.
*/
int littlefs_api_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size);
/**
* @brief Program a region in a block.
*
* The block must have previously been erased.
* Negative error codes are propogated to the user.
* May return LFS_ERR_CORRUPT if the block should be considered bad.
*
* @return errorcode. 0 on success.
*/
int littlefs_api_prog(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size);
/**
* @brief Erase a block.
*
* A block must be erased before being programmed.
* The state of an erased block is undefined.
* Negative error codes are propogated to the user.
* May return LFS_ERR_CORRUPT if the block should be considered bad.
* @return errorcode. 0 on success.
*/
int littlefs_api_erase(const struct lfs_config *c, lfs_block_t block);
/**
* @brief Sync the state of the underlying block device.
*
* Negative error codes are propogated to the user.
*
* @return errorcode. 0 on success.
*/
int littlefs_api_sync(const struct lfs_config *c);
#ifdef __cplusplus
}
#endif
#endif