summaryrefslogtreecommitdiff
path: root/firmware/drivers/fat.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/fat.h')
-rw-r--r--firmware/drivers/fat.h118
1 files changed, 30 insertions, 88 deletions
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h
index 99b40ac284..b60b3d4164 100644
--- a/firmware/drivers/fat.h
+++ b/firmware/drivers/fat.h
@@ -22,38 +22,6 @@
22 22
23#define BLOCK_SIZE 512 23#define BLOCK_SIZE 512
24 24
25#define FATTYPE_FAT12 0
26#define FATTYPE_FAT16 1
27#define FATTYPE_FAT32 2
28
29#define BS_JMPBOOT 0
30#define BS_OEMNAME 3
31#define BPB_BYTSPERSEC 11
32#define BPB_SECPERCLUS 13
33#define BPB_RSVDSECCNT 14
34#define BPB_NUMFATS 16
35#define BPB_ROOTENTCNT 17
36#define BPB_TOTSEC16 19
37#define BPB_MEDIA 21
38#define BPB_FATSZ16 22
39#define BPB_SECPERTRK 24
40#define BPB_NUMHEADS 26
41#define BPB_HIDDSEC 28
42#define BPB_TOTSEC32 32
43
44#define BS_DRVNUM 36
45#define BS_RESERVED1 37
46#define BS_BOOTSIG 38
47#define BS_VOLID 39
48#define BS_VOLLAB 43
49#define BS_FILSYSTYPE 54
50
51#define BPB_FATSZ32 36
52
53#define BPB_LAST_WORD 510
54
55#define MIN(a,b) (((a) < (b))?(a):(b))
56
57struct bpb 25struct bpb
58{ 26{
59 char bs_oemname[9]; /* OEM string, ending with \0 */ 27 char bs_oemname[9]; /* OEM string, ending with \0 */
@@ -70,6 +38,8 @@ struct bpb
70 int bpb_hiddsec; /* Hidden sectors before the volume */ 38 int bpb_hiddsec; /* Hidden sectors before the volume */
71 unsigned int bpb_totsec32; /* Number of sectors on the volume 39 unsigned int bpb_totsec32; /* Number of sectors on the volume
72 (new 32-bit) */ 40 (new 32-bit) */
41 int last_word; /* 0xAA55 */
42
73 /**** FAT12/16 specific *****/ 43 /**** FAT12/16 specific *****/
74 int bs_drvnum; /* Drive number */ 44 int bs_drvnum; /* Drive number */
75 int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */ 45 int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */
@@ -86,8 +56,27 @@ struct bpb
86 int bpb_bkbootsec; 56 int bpb_bkbootsec;
87 57
88 /* variables for internal use */ 58 /* variables for internal use */
89 int fat_type; /* FAT12, FAT16 or FAT32 */ 59 int fatsize;
90 int last_word; /* must be 0xAA55 */ 60 int totalsectors;
61 int rootdirsector;
62 int firstdatasector;
63};
64
65struct fat_direntry
66{
67 unsigned char name[12]; /* Name plus \0 */
68 unsigned short attr; /* Attributes */
69 unsigned char crttimetenth; /* Millisecond creation
70 time stamp (0-199) */
71 unsigned short crttime; /* Creation time */
72 unsigned short crtdate; /* Creation date */
73 unsigned short lstaccdate; /* Last access date */
74 unsigned short fstclushi; /* High word of first cluster
75 (0 for FAT12/16) */
76 unsigned short wrttime; /* Last write time */
77 unsigned short wrtdate; /* Last write date */
78 unsigned short fstcluslo; /* Low word of first cluster */
79 unsigned int filesize; /* File size in bytes */
91}; 80};
92 81
93#define FAT_ATTR_READ_ONLY 0x01 82#define FAT_ATTR_READ_ONLY 0x01
@@ -96,68 +85,21 @@ struct bpb
96#define FAT_ATTR_VOLUME_ID 0x08 85#define FAT_ATTR_VOLUME_ID 0x08
97#define FAT_ATTR_DIRECTORY 0x10 86#define FAT_ATTR_DIRECTORY 0x10
98#define FAT_ATTR_ARCHIVE 0x20 87#define FAT_ATTR_ARCHIVE 0x20
99#define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \
100 FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
101#define FAT_ATTR_LONG_NAME_MASK (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \
102 FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID | \
103 FAT_ATTR_DIRECTORY | FAT_ATTR_ARCHIVE )
104
105
106#define FATDIR_NAME 0
107#define FATDIR_ATTR 11
108#define FATDIR_NTRES 12
109#define FATDIR_CRTTIMETENTH 13
110#define FATDIR_CRTTIME 14
111#define FATDIR_CRTDATE 16
112#define FATDIR_LSTACCDATE 18
113#define FATDIR_FSTCLUSHI 20
114#define FATDIR_WRTTIME 22
115#define FATDIR_WRTDATE 24
116#define FATDIR_FSTCLUSLO 26
117#define FATDIR_FILESIZE 28
118
119struct fat_direntry
120{
121 unsigned char name[12]; /* Name plus \0 */
122 unsigned short attr; /* Attributes */
123 unsigned char crttimetenth; /* Millisecond creation
124 time stamp (0-199) */
125 unsigned short crttime; /* Creation time */
126 unsigned short crtdate; /* Creation date */
127 unsigned short lstaccdate; /* Last access date */
128 unsigned short fstclushi; /* High word of first cluster
129 (0 for FAT12/16) */
130 unsigned short wrttime; /* Last write time */
131 unsigned short wrtdate; /* Last write date */
132 unsigned short fstcluslo; /* Low word of first cluster */
133 unsigned int filesize; /* File size in bytes */
134};
135
136struct fat_context
137{
138 unsigned int curr_dir_sec; /* Current directory sector */
139
140};
141
142struct disk_info
143{
144 int num_sectors;
145 int sec_per_track;
146 int num_heads;
147 unsigned int hidden_sectors;
148};
149 88
150struct fat_dirent 89struct fat_dirent
151{ 90{
152 int entry; 91 int entry;
153 unsigned int cached_sec; 92 unsigned int cached_sec;
154 unsigned int num_sec; 93 unsigned int num_sec;
155 char cached_buf[BLOCK_SIZE]; 94 char cached_buf[BLOCK_SIZE];
156}; 95};
157 96
158extern int fat_create_file(struct bpb *bpb, 97extern int fat_create_file(struct bpb *bpb,
159 unsigned int currdir, 98 unsigned int currdir,
160 char *name); 99 char *name);
100extern int fat_create_dir(struct bpb *bpb,
101 unsigned int currdir,
102 char *name);
161extern int fat_opendir(struct bpb *bpb, 103extern int fat_opendir(struct bpb *bpb,
162 struct fat_dirent *ent, 104 struct fat_dirent *ent,
163 unsigned int currdir); 105 unsigned int currdir);