-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesys.h
128 lines (102 loc) · 3.12 KB
/
filesys.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef _FILESYS_H
#define _FILESYS_H
#include <stdint.h>
#include "filesys_conf.h"
#define DRIVE_INFO_MODEL_LEN 32
#define DRIVE_INFO_FW_LEN 8
#define DRIVE_INFO_SERNO_LEN 20
#define DRIVE_TYPE_EMU 0
#define DRIVE_TYPE_MMC 1
#define DRIVE_TYPE_SDV1 2
#define DRIVE_TYPE_SDV2 3
#define DRIVE_TYPE_SDHC 4
typedef struct {
char model[DRIVE_INFO_MODEL_LEN + 1];
char serno[DRIVE_INFO_SERNO_LEN + 1];
uint8_t type;
uint32_t blk_count;
} TFS_DRIVE_INFO;
#define TFS_NAME_LEN 16
// blocksize results in 512 bytes (9 relevant bits)
#define TFS_BLOCKSIZE_WIDTH 9
#define TFS_BLOCKSIZE (1 << TFS_BLOCKSIZE_WIDTH)
#define TFS_ERR_OK 0
#define TFS_ERR_NO_DEV 1
#define TFS_ERR_IO 2
#define TFS_ERR_DISK_FULL 3
#define TFS_ERR_FILE_EXIST 4
#define TFS_ERR_NOT_EXIST 5
#define TFS_ERR_NOT_EMPTY 6
#define TFS_ERR_NO_NAME 7
#define TFS_ERR_NAME_INVAL 8
#define TFS_ERR_UNEXP_EOF 9
#ifdef TFS_EXTENDED_API
#define TFS_ERR_NO_FREE_FD 100
#define TFS_ERR_INVAL_FD 101
#define TFS_FILE_BUSY 102
#endif
#ifdef __GNUC__
#define _PACKED __attribute__((packed))
#else
#define _PACKED
#endif
typedef struct {
uint32_t blk;
uint32_t size;
uint8_t type;
char name[TFS_NAME_LEN];
} _PACKED TFS_DIR_ITEM;
#define TFS_DIR_ITEM_FREE 0
#define TFS_DIR_ITEM_DIR 1
#define TFS_DIR_ITEM_FILE 2
extern TFS_DRIVE_INFO drive_info;
extern uint8_t last_error;
// drive low level interface
void drive_select();
void drive_deselect();
void drive_read_block(uint32_t blkno, uint8_t *data);
void drive_write_block(uint32_t blkno, const uint8_t *data);
void tfs_init(void);
#ifdef TFS_ENABLE_FORMAT
void tfs_format(void);
#ifdef TFS_FORMAT_STATE_CALLBACK
#define TFS_FORMAT_STATE_START 0
#define TFS_FORMAT_STATE_BITMAP_START 1
#define TFS_FORMAT_STATE_BITMAP_DONE 2
#define TFS_FORMAT_STATE_ROOTDIR 3
#define TFS_FORMAT_STATE_DONE 4
// user defined callbacks
void tfs_format_state(uint8_t state);
void tfs_format_progress(uint32_t pos, uint32_t max);
#endif
#endif
uint32_t tfs_get_used(void);
#ifdef TFS_READ_DIR_USERDATA
uint8_t tfs_read_dir(TFS_READ_DIR_USERDATA data);
uint8_t tfs_dir_handler(TFS_READ_DIR_USERDATA data, const TFS_DIR_ITEM *item);
#else
uint8_t tfs_read_dir(void);
uint8_t tfs_dir_handler(const TFS_DIR_ITEM *item);
#endif
void tfs_change_dir_root(void);
void tfs_change_dir_parent(void);
void tfs_change_dir(const char *name);
void tfs_create_dir(const char *name);
void tfs_write_file(const char *name, const uint8_t *data, uint32_t len, uint8_t overwrite);
uint32_t tfs_read_file(const char *name, uint8_t *data, uint32_t max_len);
#ifdef TFS_EXTENDED_API
void tfs_delete(const char *name, uint8_t type);
#else
void tfs_delete(const char *name);
#endif
void tfs_rename(const char *from, const char *to);
#ifdef TFS_EXTENDED_API
TFS_DIR_ITEM *tfs_stat(const char *name);
void tfs_touch(const char *name);
int8_t tfs_open(const char *name);
void tfs_close(int8_t fd);
void tfs_trunc(int8_t fd, uint32_t size);
uint32_t tfs_write(int8_t fd, const uint8_t *data, uint32_t len, uint32_t offset);
uint32_t tfs_read(int8_t fd, uint8_t *data, uint32_t len, uint32_t offset);
#endif
#endif