-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfile.h
46 lines (45 loc) · 1.46 KB
/
sfile.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
//
// Ivan Shipaev
// Simple file system
#ifndef _SFILE_H_
#define _SFILE_H_
#include "stdint.h"
#include "sfile_conf.h"
//------------------------------------------------------------------------
typedef struct sfs_t {
struct {
uint8_t *buf;
uint32_t block;
uint8_t fchange;
} cache;
uint32_t block_size;
uint32_t block_count;
int (*read)(uint32_t block, void *buffer);
int (*prog)(uint32_t block, const void *buffer);
int (*erase)(uint32_t block);
SFS_MUTEX *mutex;
} sfs_t;
//------------------------------------------------------------------------
typedef struct sfile_t {
sfs_t *fs;
uint32_t msize; // ìàêñèìàëüíûé ðàçìåð äàííûõ
uint32_t start; // àäðåñ óêàçàòåëü íà íà÷àëà ôàéëà
uint32_t offset;
} sfile_t;
//------------------------------------------------------------------------
void s_fs_init(sfs_t* fs, void *buffer,
uint32_t block_size, uint32_t block_count,
int (*read)(uint32_t block, void *buffer),
int (*prog)(uint32_t block, const void *buffer),
int (*erase)(uint32_t block), SFS_MUTEX* mutex);
int s_fs_sync(sfs_t *fs);
//---------------------------------------------------------------------
int s_flush(sfile_t *file);
int s_write(sfile_t *file, const void *buf, uint32_t len);
int s_read(sfile_t *file, void *buf, uint32_t len);
void s_open(sfs_t* fs, sfile_t *file, uint32_t addr, uint32_t msize);
int s_seek(sfile_t* file, int offset);
uint32_t s_getoff(sfile_t* file);
int s_msize(sfile_t *file);
#endif /*_SFILE_H_*/