-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.h
More file actions
202 lines (179 loc) · 6.13 KB
/
fs.h
File metadata and controls
202 lines (179 loc) · 6.13 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* Filesystem wrapper for SPIFFS.
*
* Copyright Thinnect Inc. 2020
* @license MIT
*/
#ifndef _FS_H_
#define _FS_H_
#include <stdint.h>
#include "spiffs.h"
#define FS_APPEND (SPIFFS_APPEND)
#define FS_TRUNC (SPIFFS_TRUNC)
#define FS_CREAT (SPIFFS_CREAT)
#define FS_RDONLY (SPIFFS_RDONLY)
#define FS_WRONLY (SPIFFS_WRONLY)
#define FS_RDWR (SPIFFS_RDWR)
#define FS_SEEK_SET (SPIFFS_SEEK_SET)
#define FS_SEEK_CUR (SPIFFS_SEEK_CUR)
#define FS_SEEK_END (SPIFFS_SEEK_END)
#define FS_ERR_REFORMATTED (-70000)
typedef struct fs_driver_struct
{
int32_t(*read)(int partition, uint32_t addr, uint32_t size, uint8_t * dst);
int32_t(*write)(int partition, uint32_t addr, uint32_t size, uint8_t * src);
int32_t(*erase)(int partition, uint32_t addr, uint32_t size);
int32_t(*size)(int partition);
int32_t(*erase_size)(int partition);
void (*suspend)();
void (*lock)();
void (*unlock)();
} fs_driver_t;
typedef int32_t fs_fd;
typedef struct fs_stat_struct
{
uint32_t size;
} fs_stat;
/**
* Callback function for queued actions.
* @param len Number of bytes read / written.
* @param p_user User pointer provided with the call.
*/
typedef void (*fs_rw_done_f) (int32_t len, void * p_user);
/**
* Initializes filesystem on the specified partition of the driver.
*
* @param file_sys_nr - File system number 0..2
* @param partition - The partition on the device to use for the filesystem.
* @param driver - The device to use.
*/
void fs_init(int file_sys_nr, int partition, fs_driver_t *driver);
/**
* Starts filesystem thread.
*/
void fs_start();
/**
* Return filesystem total and used space.
*
* @param file_sys_nr - File system number 0..2
* @param p_total - Memory to stored total available space value (may be NULL if not needed).
* @param p_used - Memory to stored used space value (may be NULL if not needed).
*
* @return 0 for success, SPIFFS error otherwise.
*/
int32_t fs_info (int file_sys_nr, uint32_t * p_total, uint32_t * p_used);
/**
* Opens the file specified by path
*
* @param file_sys_nr - File system number 0..2
* @param path Name of the file to be opened
* @param flags Flags
*
* @return Returns file descriptor or error
*/
fs_fd fs_open(int file_sys_nr, char *path, uint32_t flags);
/**
* Attempts to read up to count bytes from file descriptor fd into the buffer starting at buf
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
* @param buf Pointer where to read data
* @param count Length of data to be read
*
* @return the number of bytes read or error
*/
int32_t fs_read(int file_sys_nr, fs_fd fd, void *buf, int32_t count);
/**
* Writes up to count bytes from the buffer starting at buf
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
* @param buf Pointer to the data to be written
* @param count Length of data to be written
*
* @return the number of bytes written or error
*/
int32_t fs_write(int file_sys_nr, fs_fd fd, const void *buf, int32_t count);
/**
* Flushes cached writes to flash.
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
*/
void fs_flush(int file_sys_nr, fs_fd fd);
/**
* Closes the file descriptor
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
*/
void fs_close(int file_sys_nr, fs_fd fd);
/**
* Deletes a name from the filesystem
*
* @param file_sys_nr - File system number 0..2
* @param path Name of the file to be deleted
*/
void fs_unlink(int file_sys_nr, char *path);
/**
* Repositions the file offset of the open file descriptor
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
* @param offs The new offset
* @param whence Offset from beginning, from current location or from end of file
*
* @return The resulting offset or error
*/
int32_t fs_lseek(int file_sys_nr, fs_fd fd, int32_t offs, int whence);
/**
* Return information about a file
*
* @param file_sys_nr - File system number 0..2
* @param fd File descriptor
* @param s Buffer to store the information
*
* @return 0 or negative on error
*/
int32_t fs_fstat(int file_sys_nr, fs_fd fd, fs_stat *s);
/*****************************************************************************
* Put one data read request to the read queue
* @param file_sys_nr - File system number 0..2
* @param p_file_name - Pointer to the file name
* @param p_value - Pointer to the data record
* @param len - Data record length in bytes
* @param wait - When wait = 0 function returns immediately, even when putting fails,
* otherwise waits until put succeeds (and blocks calling thread)
* @param f_callback - Callback when operation has been completed.
* @param p_user - User pointer passed to callback.
*
* @return Returns number of bytes to read on success, 0 otherwise
****************************************************************************/
int32_t fs_read_record (int file_sys_nr,
const char * p_file_name,
void * p_value,
int32_t len,
uint32_t wait,
fs_rw_done_f f_callback,
void * p_user);
/*****************************************************************************
* Put one data write request to the write queue
* @param file_sys_nr - File system number 0..2
* @param p_file_name - Pointer to the file name
* @param p_value - Pointer to the data record
* @param len - Data record length in bytes
* @param wait - When wait = 0 function returns immediately, even when putting fails,
* otherwise waits until put succeeds (and blocks calling thread)
* @param f_callback - Callback when operation has been completed.
* @param p_user - User pointer passed to callback.
*
* @return Returns number of bytes to write on success, 0 otherwise
****************************************************************************/
int32_t fs_write_record (int file_sys_nr,
const char * p_file_name,
const void * p_value,
int32_t len,
uint32_t wait,
fs_rw_done_f f_callback,
void * p_user);
#endif//_FS_H_