This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
fat.h
128 lines (106 loc) · 2.47 KB
/
fat.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
/*
* File: fat.h
* Author: krik
*
* Created on 22 Ìàé 2011 ã., 1:06
*/
#ifndef _FAT_H
#define _FAT_H
#include "types.h"
#include "errors.h"
#define FAT_MAX_DIR_SIZE 1024
#define FAT_MAX_NAME_LEN 128
#define FAT_MAX_NAME_LEN_S 256
#define FAT_TYPE_16 1
#define FAT_TYPE_32 2
typedef struct {
u8 name[FAT_MAX_NAME_LEN];
u32 entry_cluster;
u32 size;
u32 hdr_sector;
u16 hdr_idx;
u16 fav_idx;
u8 is_dir;
} FatRecord;
typedef struct {
u8 name[8];
u8 ext[3];
u8 attrib;
u8 x[8];
u16 cluster_hi;
u16 time;
u16 date;
u16 cluster_lo;
u32 size;
} FatRecordHdr;
typedef struct {
FatRecord * rec[FAT_MAX_DIR_SIZE];
FatRecord * s_records[FAT_MAX_DIR_SIZE];
u8 *path;
u16 size;
u32 entry_cluster;
u32 entry_sector;
u32 in_cluster_ptr;
u32 current_cluster;
u8 is_root;
} Dir;
typedef struct {
u32 pbr_entry;
u32 root_entry;
u32 fat_entry;
u32 data_entry;
u8 type;
u8 cluster_size;
u32 loaded_sector;
u32 cluster_byte_size;
u32 sectors_per_fat;
} Fat;
typedef struct {
u8 *table_buff;
u8 *table_sector;
u8 *data_sector;
u32 data_sec_idx;
u32 table_sec_idx;
} FatCache;
typedef struct {
u32 sector;
u32 cluster;
u32 sec_available;
u16 in_cluster_ptr;
FatRecord rec;
u8 mode;
} File;
extern Dir *dir;
//extern Dir dir_o;
extern File file;
extern FatCache *fat_cache;
//extern FatRecord rec_tmp;
#define ED_ROOT "/ED64"
#define ED_SAVE "/ED64/SDSAVE"
#define ED_ROM_CFG "/ED64/SDSAVE/LAST.CRT"
//#define ED_TEST_CFG "/MISC/test.dat"
//#define ED_OPTIONS "/ED64/options.dat"
//#define ED_FAVOR "/ED64/favor.dat"
//#define ED_SAVE_DMP "/EDMD/sav-dmp.bin"
#define FILE_MODE_RD 1
#define FILE_MODE_WR 2
u8 fatInit();
u8 fatLoadDir(u32 cluster);
u8 fatLoadDirByName(u8 *name);
u8 fatWriteFile(void *src, u32 sectors);
u8 fatReadFile(void *dst, u32 sectors);
u8 fatReadPartialFile(void *dst, u32 sectors, int b_offset);
u8 fatCreateRecord(u8 *name, u8 is_dir, u8 check_exist);
u8 fatOpenFileByeName(u8 *name, u32 wr_sectors);
u8 fatFindRecord(u8 *name, FatRecord *rec, u8 is_dir);
u8 fatOpenFile(FatRecord *rec, u32 wr_sectors);
u8 fatSkipSectors(u32 sectors);
u8 fatCreateRecIfNotExist(u8 *name, u8 is_dir);
u8 fatGetFullName(u8 *name, u32 dir_entry, u32 rec_entry);
u8 fatOpenDirByName(u8 *name);
void fatInitRam();
u8 streq(u8 *str1, u8 *str2);
u8 streql(u8 *str1, u8 *str2, u8 len);
u8 slen(u8 *str);
void fatSortRecords();
#endif /* _FAT_H */