diff options
Diffstat (limited to 'firmware/drivers/fat.h')
-rw-r--r-- | firmware/drivers/fat.h | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h new file mode 100644 index 0000000000..f1dc8dc5a0 --- /dev/null +++ b/firmware/drivers/fat.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef FAT_H | ||
21 | #define FAT_H | ||
22 | |||
23 | #define FATTYPE_FAT12 0 | ||
24 | #define FATTYPE_FAT16 1 | ||
25 | #define FATTYPE_FAT32 2 | ||
26 | |||
27 | #define BS_JMPBOOT 0 | ||
28 | #define BS_OEMNAME 3 | ||
29 | #define BPB_BYTSPERSEC 11 | ||
30 | #define BPB_SECPERCLUS 13 | ||
31 | #define BPB_RSVDSECCNT 14 | ||
32 | #define BPB_NUMFATS 16 | ||
33 | #define BPB_ROOTENTCNT 17 | ||
34 | #define BPB_TOTSEC16 19 | ||
35 | #define BPB_MEDIA 21 | ||
36 | #define BPB_FATSZ16 22 | ||
37 | #define BPB_SECPERTRK 24 | ||
38 | #define BPB_NUMHEADS 26 | ||
39 | #define BPB_HIDDSEC 28 | ||
40 | #define BPB_TOTSEC32 32 | ||
41 | |||
42 | #define BS_DRVNUM 36 | ||
43 | #define BS_RESERVED1 37 | ||
44 | #define BS_BOOTSIG 38 | ||
45 | #define BS_VOLID 39 | ||
46 | #define BS_VOLLAB 43 | ||
47 | #define BS_FILSYSTYPE 54 | ||
48 | |||
49 | #define BPB_FATSZ32 36 | ||
50 | |||
51 | #define BPB_LAST_WORD 510 | ||
52 | |||
53 | #define MIN(a,b) (((a) < (b))?(a):(b))) | ||
54 | |||
55 | struct bpb | ||
56 | { | ||
57 | char bs_oemname[9]; /* OEM string, ending with \0 */ | ||
58 | int bpb_bytspersec; /* Bytes per sectory, typically 512 */ | ||
59 | int bpb_secperclus; /* Sectors per cluster */ | ||
60 | int bpb_rsvdseccnt; /* Number of reserved sectors */ | ||
61 | int bpb_numfats; /* Number of FAT structures, typically 2 */ | ||
62 | int bpb_rootentcnt; /* Number of dir entries in the root */ | ||
63 | int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */ | ||
64 | int bpb_media; /* Media type (typically 0xf0 or 0xf8) */ | ||
65 | int bpb_fatsz16; /* Number of used sectors per FAT structure */ | ||
66 | int bpb_secpertrk; /* Number of sectors per track */ | ||
67 | int bpb_numheads; /* Number of heads */ | ||
68 | int bpb_hiddsec; /* Hidden sectors before the volume */ | ||
69 | unsigned int bpb_totsec32; /* Number of sectors on the volume | ||
70 | (new 32-bit) */ | ||
71 | /**** FAT12/16 specific *****/ | ||
72 | int bs_drvnum; /* Drive number */ | ||
73 | int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */ | ||
74 | unsigned int bs_volid; /* Volume ID */ | ||
75 | char bs_vollab[12]; /* Volume label, 11 chars plus \0 */ | ||
76 | char bs_filsystype[9]; /* File system type, 8 chars plus \0 */ | ||
77 | |||
78 | /**** FAT32 specific *****/ | ||
79 | int bpb_fatsz32; | ||
80 | |||
81 | int last_word; /* Must be 0xaa55 */ | ||
82 | |||
83 | int fat_type; /* What type of FAT is this? */ | ||
84 | }; | ||
85 | |||
86 | #define FAT_ATTR_READ_ONLY 0x01 | ||
87 | #define FAT_ATTR_HIDDEN 0x02 | ||
88 | #define FAT_ATTR_SYSTEM 0x04 | ||
89 | #define FAT_ATTR_VOLUME_ID 0x08 | ||
90 | #define FAT_ATTR_DIRECTORY 0x10 | ||
91 | #define FAT_ATTR_ARCHIVE 0x20 | ||
92 | #define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \ | ||
93 | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID) | ||
94 | |||
95 | |||
96 | #define FATDIR_NAME 0 | ||
97 | #define FATDIR_ATTR 11 | ||
98 | #define FATDIR_NTRES 12 | ||
99 | #define FATDIR_CRTTIMETENTH 13 | ||
100 | #define FATDIR_CRTTIME 14 | ||
101 | #define FATDIR_CRTDATE 16 | ||
102 | #define FATDIR_LSTACCDATE 18 | ||
103 | #define FATDIR_FSTCLUSHI 20 | ||
104 | #define FATDIR_WRTTIME 22 | ||
105 | #define FATDIR_WRTDATE 24 | ||
106 | #define FATDIR_FSTCLUSLO 26 | ||
107 | #define FATDIR_FILESIZE 28 | ||
108 | |||
109 | struct fat_direntry | ||
110 | { | ||
111 | unsigned char name[12]; /* Name plus \0 */ | ||
112 | unsigned short attr; /* Attributes */ | ||
113 | unsigned char crttimetenth; /* Millisecond creation | ||
114 | time stamp (0-199) */ | ||
115 | unsigned short crttime; /* Creation time */ | ||
116 | unsigned short crtdate; /* Creation date */ | ||
117 | unsigned short lstaccdate; /* Last access date */ | ||
118 | unsigned short fstclushi; /* High word of first cluster | ||
119 | (0 for FAT12/16) */ | ||
120 | unsigned short wrttime; /* Last write time */ | ||
121 | unsigned short wrtdate; /* Last write date */ | ||
122 | unsigned short fstcluslo; /* Low word of first cluster */ | ||
123 | unsigned int filesize; /* File size in bytes */ | ||
124 | }; | ||
125 | |||
126 | struct fat_context | ||
127 | { | ||
128 | unsigned int curr_dir_sec; /* Current directory sector */ | ||
129 | |||
130 | }; | ||
131 | |||
132 | struct disk_info | ||
133 | { | ||
134 | int num_sectors; | ||
135 | int sec_per_track; | ||
136 | int num_heads; | ||
137 | unsigned int hidden_sectors; | ||
138 | }; | ||
139 | |||
140 | struct fat_dirent | ||
141 | { | ||
142 | int entry; | ||
143 | unsigned int cached_sec; | ||
144 | unsigned int num_sec; | ||
145 | char cached_buf[BLOCK_SIZE]; | ||
146 | }; | ||
147 | |||
148 | int fat_format(struct disk_info *di, char *vol_name); | ||
149 | int fat_create_file(struct bpb *bpb, unsigned int currdir, char *name); | ||
150 | int fat_opendir(struct bpb *bpb, struct fat_dirent *ent, unsigned int currdir); | ||
151 | int fat_getnext(struct bpb *bpb, struct fat_dirent *ent, | ||
152 | struct fat_direntry *entry); | ||
153 | |||
154 | #endif | ||