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.h80
1 files changed, 47 insertions, 33 deletions
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h
index f1dc8dc5a0..99b40ac284 100644
--- a/firmware/drivers/fat.h
+++ b/firmware/drivers/fat.h
@@ -20,6 +20,8 @@
20#ifndef FAT_H 20#ifndef FAT_H
21#define FAT_H 21#define FAT_H
22 22
23#define BLOCK_SIZE 512
24
23#define FATTYPE_FAT12 0 25#define FATTYPE_FAT12 0
24#define FATTYPE_FAT16 1 26#define FATTYPE_FAT16 1
25#define FATTYPE_FAT32 2 27#define FATTYPE_FAT32 2
@@ -50,37 +52,42 @@
50 52
51#define BPB_LAST_WORD 510 53#define BPB_LAST_WORD 510
52 54
53#define MIN(a,b) (((a) < (b))?(a):(b))) 55#define MIN(a,b) (((a) < (b))?(a):(b))
54 56
55struct bpb 57struct bpb
56{ 58{
57 char bs_oemname[9]; /* OEM string, ending with \0 */ 59 char bs_oemname[9]; /* OEM string, ending with \0 */
58 int bpb_bytspersec; /* Bytes per sectory, typically 512 */ 60 int bpb_bytspersec; /* Bytes per sectory, typically 512 */
59 int bpb_secperclus; /* Sectors per cluster */ 61 int bpb_secperclus; /* Sectors per cluster */
60 int bpb_rsvdseccnt; /* Number of reserved sectors */ 62 int bpb_rsvdseccnt; /* Number of reserved sectors */
61 int bpb_numfats; /* Number of FAT structures, typically 2 */ 63 int bpb_numfats; /* Number of FAT structures, typically 2 */
62 int bpb_rootentcnt; /* Number of dir entries in the root */ 64 int bpb_rootentcnt; /* Number of dir entries in the root */
63 int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */ 65 int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */
64 int bpb_media; /* Media type (typically 0xf0 or 0xf8) */ 66 int bpb_media; /* Media type (typically 0xf0 or 0xf8) */
65 int bpb_fatsz16; /* Number of used sectors per FAT structure */ 67 int bpb_fatsz16; /* Number of used sectors per FAT structure */
66 int bpb_secpertrk; /* Number of sectors per track */ 68 int bpb_secpertrk; /* Number of sectors per track */
67 int bpb_numheads; /* Number of heads */ 69 int bpb_numheads; /* Number of heads */
68 int bpb_hiddsec; /* Hidden sectors before the volume */ 70 int bpb_hiddsec; /* Hidden sectors before the volume */
69 unsigned int bpb_totsec32; /* Number of sectors on the volume 71 unsigned int bpb_totsec32; /* Number of sectors on the volume
70 (new 32-bit) */ 72 (new 32-bit) */
71 /**** FAT12/16 specific *****/ 73 /**** FAT12/16 specific *****/
72 int bs_drvnum; /* Drive number */ 74 int bs_drvnum; /* Drive number */
73 int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */ 75 int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */
74 unsigned int bs_volid; /* Volume ID */ 76 unsigned int bs_volid; /* Volume ID */
75 char bs_vollab[12]; /* Volume label, 11 chars plus \0 */ 77 char bs_vollab[12]; /* Volume label, 11 chars plus \0 */
76 char bs_filsystype[9]; /* File system type, 8 chars plus \0 */ 78 char bs_filsystype[9]; /* File system type, 8 chars plus \0 */
77 79
78 /**** FAT32 specific *****/ 80 /**** FAT32 specific *****/
79 int bpb_fatsz32; 81 int bpb_fatsz32;
80 82 int bpb_extflags;
81 int last_word; /* Must be 0xaa55 */ 83 int bpb_fsver;
82 84 int bpb_rootclus;
83 int fat_type; /* What type of FAT is this? */ 85 int bpb_fsinfo;
86 int bpb_bkbootsec;
87
88 /* variables for internal use */
89 int fat_type; /* FAT12, FAT16 or FAT32 */
90 int last_word; /* must be 0xAA55 */
84}; 91};
85 92
86#define FAT_ATTR_READ_ONLY 0x01 93#define FAT_ATTR_READ_ONLY 0x01
@@ -91,6 +98,9 @@ struct bpb
91#define FAT_ATTR_ARCHIVE 0x20 98#define FAT_ATTR_ARCHIVE 0x20
92#define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \ 99#define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \
93 FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID) 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 )
94 104
95 105
96#define FATDIR_NAME 0 106#define FATDIR_NAME 0
@@ -145,10 +155,14 @@ struct fat_dirent
145 char cached_buf[BLOCK_SIZE]; 155 char cached_buf[BLOCK_SIZE];
146}; 156};
147 157
148int fat_format(struct disk_info *di, char *vol_name); 158extern int fat_create_file(struct bpb *bpb,
149int fat_create_file(struct bpb *bpb, unsigned int currdir, char *name); 159 unsigned int currdir,
150int fat_opendir(struct bpb *bpb, struct fat_dirent *ent, unsigned int currdir); 160 char *name);
151int fat_getnext(struct bpb *bpb, struct fat_dirent *ent, 161extern int fat_opendir(struct bpb *bpb,
152 struct fat_direntry *entry); 162 struct fat_dirent *ent,
163 unsigned int currdir);
164extern int fat_getnext(struct bpb *bpb,
165 struct fat_dirent *ent,
166 struct fat_direntry *entry);
153 167
154#endif 168#endif