diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/fat.c | 48 |
1 files changed, 3 insertions, 45 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 4bf76bf8ef..310ac1c504 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -190,36 +190,21 @@ struct fsinfo { | |||
190 | 190 | ||
191 | struct bpb | 191 | struct bpb |
192 | { | 192 | { |
193 | char bs_oemname[9]; /* OEM string, ending with \0 */ | 193 | int bpb_bytspersec; /* Bytes per sector, typically 512 */ |
194 | int bpb_bytspersec; /* Bytes per sectory, typically 512 */ | ||
195 | unsigned int bpb_secperclus; /* Sectors per cluster */ | 194 | unsigned int bpb_secperclus; /* Sectors per cluster */ |
196 | int bpb_rsvdseccnt; /* Number of reserved sectors */ | 195 | int bpb_rsvdseccnt; /* Number of reserved sectors */ |
197 | int bpb_numfats; /* Number of FAT structures, typically 2 */ | 196 | int bpb_numfats; /* Number of FAT structures, typically 2 */ |
198 | int bpb_rootentcnt; /* Number of dir entries in the root */ | ||
199 | int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */ | 197 | int bpb_totsec16; /* Number of sectors on the volume (old 16-bit) */ |
200 | int bpb_media; /* Media type (typically 0xf0 or 0xf8) */ | 198 | int bpb_media; /* Media type (typically 0xf0 or 0xf8) */ |
201 | int bpb_fatsz16; /* Number of used sectors per FAT structure */ | 199 | int bpb_fatsz16; /* Number of used sectors per FAT structure */ |
202 | int bpb_secpertrk; /* Number of sectors per track */ | ||
203 | int bpb_numheads; /* Number of heads */ | ||
204 | int bpb_hiddsec; /* Hidden sectors before the volume */ | ||
205 | unsigned int bpb_totsec32; /* Number of sectors on the volume | 200 | unsigned int bpb_totsec32; /* Number of sectors on the volume |
206 | (new 32-bit) */ | 201 | (new 32-bit) */ |
207 | int last_word; /* 0xAA55 */ | 202 | int last_word; /* 0xAA55 */ |
208 | 203 | ||
209 | /**** FAT12/16 specific *****/ | ||
210 | int bs_drvnum; /* Drive number */ | ||
211 | int bs_bootsig; /* Is 0x29 if the following 3 fields are valid */ | ||
212 | unsigned int bs_volid; /* Volume ID */ | ||
213 | char bs_vollab[12]; /* Volume label, 11 chars plus \0 */ | ||
214 | char bs_filsystype[9]; /* File system type, 8 chars plus \0 */ | ||
215 | |||
216 | /**** FAT32 specific *****/ | 204 | /**** FAT32 specific *****/ |
217 | int bpb_fatsz32; | 205 | int bpb_fatsz32; |
218 | int bpb_extflags; | ||
219 | int bpb_fsver; | ||
220 | int bpb_rootclus; | 206 | int bpb_rootclus; |
221 | int bpb_fsinfo; | 207 | int bpb_fsinfo; |
222 | int bpb_bkbootsec; | ||
223 | 208 | ||
224 | /* variables for internal use */ | 209 | /* variables for internal use */ |
225 | unsigned int fatsize; | 210 | unsigned int fatsize; |
@@ -230,6 +215,7 @@ struct bpb | |||
230 | unsigned int dataclusters; | 215 | unsigned int dataclusters; |
231 | struct fsinfo fsinfo; | 216 | struct fsinfo fsinfo; |
232 | #ifdef HAVE_FAT16SUPPORT | 217 | #ifdef HAVE_FAT16SUPPORT |
218 | int bpb_rootentcnt; /* Number of dir entries in the root */ | ||
233 | /* internals for FAT16 support */ | 219 | /* internals for FAT16 support */ |
234 | bool is_fat16; /* true if we mounted a FAT16 partition, false if FAT32 */ | 220 | bool is_fat16; /* true if we mounted a FAT16 partition, false if FAT32 */ |
235 | unsigned int rootdirsectors; /* fixed # of sectors occupied by root dir */ | 221 | unsigned int rootdirsectors; /* fixed # of sectors occupied by root dir */ |
@@ -334,21 +320,14 @@ int fat_mount(int startsector) | |||
334 | memset(&fat_bpb, 0, sizeof(struct bpb)); | 320 | memset(&fat_bpb, 0, sizeof(struct bpb)); |
335 | fat_bpb.startsector = startsector; | 321 | fat_bpb.startsector = startsector; |
336 | 322 | ||
337 | strncpy(fat_bpb.bs_oemname, &buf[BS_OEMNAME], 8); | ||
338 | fat_bpb.bs_oemname[8] = 0; | ||
339 | |||
340 | fat_bpb.bpb_bytspersec = BYTES2INT16(buf,BPB_BYTSPERSEC); | 323 | fat_bpb.bpb_bytspersec = BYTES2INT16(buf,BPB_BYTSPERSEC); |
341 | fat_bpb.bpb_secperclus = buf[BPB_SECPERCLUS]; | 324 | fat_bpb.bpb_secperclus = buf[BPB_SECPERCLUS]; |
342 | fat_bpb.bpb_rsvdseccnt = BYTES2INT16(buf,BPB_RSVDSECCNT); | 325 | fat_bpb.bpb_rsvdseccnt = BYTES2INT16(buf,BPB_RSVDSECCNT); |
343 | fat_bpb.bpb_numfats = buf[BPB_NUMFATS]; | 326 | fat_bpb.bpb_numfats = buf[BPB_NUMFATS]; |
344 | fat_bpb.bpb_rootentcnt = BYTES2INT16(buf,BPB_ROOTENTCNT); /* needed only for FAT16 */ | ||
345 | fat_bpb.bpb_totsec16 = BYTES2INT16(buf,BPB_TOTSEC16); | 327 | fat_bpb.bpb_totsec16 = BYTES2INT16(buf,BPB_TOTSEC16); |
346 | fat_bpb.bpb_media = buf[BPB_MEDIA]; | 328 | fat_bpb.bpb_media = buf[BPB_MEDIA]; |
347 | fat_bpb.bpb_fatsz16 = BYTES2INT16(buf,BPB_FATSZ16); | 329 | fat_bpb.bpb_fatsz16 = BYTES2INT16(buf,BPB_FATSZ16); |
348 | fat_bpb.bpb_fatsz32 = BYTES2INT32(buf,BPB_FATSZ32); | 330 | fat_bpb.bpb_fatsz32 = BYTES2INT32(buf,BPB_FATSZ32); |
349 | fat_bpb.bpb_secpertrk = BYTES2INT16(buf,BPB_SECPERTRK); | ||
350 | fat_bpb.bpb_numheads = BYTES2INT16(buf,BPB_NUMHEADS); | ||
351 | fat_bpb.bpb_hiddsec = BYTES2INT32(buf,BPB_HIDDSEC); | ||
352 | fat_bpb.bpb_totsec32 = BYTES2INT32(buf,BPB_TOTSEC32); | 331 | fat_bpb.bpb_totsec32 = BYTES2INT32(buf,BPB_TOTSEC32); |
353 | fat_bpb.last_word = BYTES2INT16(buf,BPB_LAST_WORD); | 332 | fat_bpb.last_word = BYTES2INT16(buf,BPB_LAST_WORD); |
354 | 333 | ||
@@ -364,6 +343,7 @@ int fat_mount(int startsector) | |||
364 | fat_bpb.totalsectors = fat_bpb.bpb_totsec32; | 343 | fat_bpb.totalsectors = fat_bpb.bpb_totsec32; |
365 | 344 | ||
366 | #ifdef HAVE_FAT16SUPPORT | 345 | #ifdef HAVE_FAT16SUPPORT |
346 | fat_bpb.bpb_rootentcnt = BYTES2INT16(buf,BPB_ROOTENTCNT); | ||
367 | fat_bpb.rootdirsectors = ((fat_bpb.bpb_rootentcnt * 32) | 347 | fat_bpb.rootdirsectors = ((fat_bpb.bpb_rootentcnt * 32) |
368 | + (fat_bpb.bpb_bytspersec - 1)) / fat_bpb.bpb_bytspersec; | 348 | + (fat_bpb.bpb_bytspersec - 1)) / fat_bpb.bpb_bytspersec; |
369 | #endif /* #ifdef HAVE_FAT16SUPPORT */ | 349 | #endif /* #ifdef HAVE_FAT16SUPPORT */ |
@@ -405,15 +385,6 @@ int fat_mount(int startsector) | |||
405 | if (fat_bpb.is_fat16) | 385 | if (fat_bpb.is_fat16) |
406 | { /* FAT16 specific part of BPB */ | 386 | { /* FAT16 specific part of BPB */ |
407 | int dirclusters; | 387 | int dirclusters; |
408 | fat_bpb.bs_drvnum = buf[BS_DRVNUM]; | ||
409 | fat_bpb.bs_bootsig = buf[BS_BOOTSIG]; | ||
410 | |||
411 | if(fat_bpb.bs_bootsig == 0x29) | ||
412 | { | ||
413 | fat_bpb.bs_volid = BYTES2INT32(buf, BS_VOLID); | ||
414 | strncpy(fat_bpb.bs_vollab, &buf[BS_VOLLAB], 11); | ||
415 | strncpy(fat_bpb.bs_filsystype, &buf[BS_FILSYSTYPE], 8); | ||
416 | } | ||
417 | fat_bpb.rootdirsector = fat_bpb.bpb_rsvdseccnt | 388 | fat_bpb.rootdirsector = fat_bpb.bpb_rsvdseccnt |
418 | + fat_bpb.bpb_numfats * fat_bpb.bpb_fatsz16; | 389 | + fat_bpb.bpb_numfats * fat_bpb.bpb_fatsz16; |
419 | dirclusters = ((fat_bpb.rootdirsectors + fat_bpb.bpb_secperclus - 1) | 390 | dirclusters = ((fat_bpb.rootdirsectors + fat_bpb.bpb_secperclus - 1) |
@@ -425,21 +396,8 @@ int fat_mount(int startsector) | |||
425 | else | 396 | else |
426 | #endif /* #ifdef HAVE_FAT16SUPPORT */ | 397 | #endif /* #ifdef HAVE_FAT16SUPPORT */ |
427 | { /* FAT32 specific part of BPB */ | 398 | { /* FAT32 specific part of BPB */ |
428 | fat_bpb.bpb_extflags = BYTES2INT16(buf,BPB_EXTFLAGS); | ||
429 | fat_bpb.bpb_fsver = BYTES2INT16(buf,BPB_FSVER); | ||
430 | fat_bpb.bpb_rootclus = BYTES2INT32(buf,BPB_ROOTCLUS); | 399 | fat_bpb.bpb_rootclus = BYTES2INT32(buf,BPB_ROOTCLUS); |
431 | fat_bpb.bpb_fsinfo = BYTES2INT16(buf,BPB_FSINFO); | 400 | fat_bpb.bpb_fsinfo = BYTES2INT16(buf,BPB_FSINFO); |
432 | fat_bpb.bpb_bkbootsec = BYTES2INT16(buf,BPB_BKBOOTSEC); | ||
433 | fat_bpb.bs_drvnum = buf[BS_32_DRVNUM]; | ||
434 | fat_bpb.bs_bootsig = buf[BS_32_BOOTSIG]; | ||
435 | |||
436 | if(fat_bpb.bs_bootsig == 0x29) | ||
437 | { | ||
438 | fat_bpb.bs_volid = BYTES2INT32(buf,BS_32_VOLID); | ||
439 | strncpy(fat_bpb.bs_vollab, &buf[BS_32_VOLLAB], 11); | ||
440 | strncpy(fat_bpb.bs_filsystype, &buf[BS_32_FILSYSTYPE], 8); | ||
441 | } | ||
442 | |||
443 | fat_bpb.rootdirsector = cluster2sec(fat_bpb.bpb_rootclus); | 401 | fat_bpb.rootdirsector = cluster2sec(fat_bpb.bpb_rootclus); |
444 | } | 402 | } |
445 | 403 | ||