fat.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*#######################################################################################
  2. Connect ARM to MMC/SD
  3. Copyright (C) 2004 Ulrich Radig
  4. #######################################################################################*/
  5. #ifndef _FAT_H_
  6. #define _FAT_H_
  7. #include <string.h>
  8. #include "mmc.h"
  9. #include "uart.h"
  10. #define FAT_DEBUG uart_puts
  11. //#define FAT_DEBUG(...)
  12. //Prototypes
  13. extern unsigned int fat_root_dir_addr (unsigned char *);
  14. extern unsigned int fat_read_dir_ent (unsigned int,unsigned char,unsigned long*,unsigned char *,unsigned char *);
  15. extern void fat_load (unsigned int,unsigned long *,unsigned char *);
  16. extern void fat_read_file (unsigned int,unsigned char *,unsigned long);
  17. extern void fat_write_file (unsigned int,unsigned char *,unsigned long);
  18. extern void fat_init (uint8_t *Buffer);
  19. extern unsigned char fat_search_file (unsigned char *,unsigned int *,unsigned long *,unsigned char *,unsigned char *);
  20. //Block Size in Bytes
  21. #define BlockSize 512
  22. //Master Boot Record
  23. #define MASTER_BOOT_RECORD 0
  24. //Volume Boot Record location in Master Boot Record
  25. #define VBR_ADDR 0x1C6
  26. //define ASCII
  27. #define SPACE 0x20
  28. #define DIR_ENTRY_IS_FREE 0xE5
  29. #define FIRST_LONG_ENTRY 0x01
  30. #define SECOND_LONG_ENTRY 0x42
  31. //define DIR_Attr
  32. #define ATTR_LONG_NAME 0x0F
  33. #define ATTR_READ_ONLY 0x01
  34. #define ATTR_HIDDEN 0x02
  35. #define ATTR_SYSTEM 0x04
  36. #define ATTR_VOLUME_ID 0x08
  37. #define ATTR_DIRECTORY 0x10
  38. #define ATTR_ARCHIVE 0x20
  39. struct BootSec
  40. {
  41. unsigned char BS_jmpBoot[3];
  42. unsigned char BS_OEMName[8];
  43. unsigned int BPB_BytesPerSec; //2 bytes
  44. unsigned char BPB_SecPerClus;
  45. unsigned int BPB_RsvdSecCnt; //2 bytes
  46. unsigned char BPB_NumFATs;
  47. unsigned int BPB_RootEntCnt; //2 bytes
  48. unsigned int BPB_TotSec16; //2 bytes
  49. unsigned char BPB_Media;
  50. unsigned int BPB_FATSz16; //2 bytes
  51. unsigned int BPB_SecPerTrk; //2 bytes
  52. unsigned int BPB_NumHeads; //2 bytes
  53. unsigned long BPB_HiddSec; //4 bytes
  54. unsigned long BPB_TotSec32; //4 bytes
  55. };
  56. //FAT12 and FAT16 Structure Starting at Offset 36
  57. #define BS_DRVNUM 36
  58. #define BS_RESERVED1 37
  59. #define BS_BOOTSIG 38
  60. #define BS_VOLID 39
  61. #define BS_VOLLAB 43
  62. #define BS_FILSYSTYPE 54
  63. //FAT32 Structure Starting at Offset 36
  64. #define BPB_FATSZ32 36
  65. #define BPB_EXTFLAGS 40
  66. #define BPB_FSVER 42
  67. #define BPB_ROOTCLUS 44
  68. #define BPB_FSINFO 48
  69. #define BPB_BKBOOTSEC 50
  70. #define BPB_RESERVED 52
  71. #define FAT32_BS_DRVNUM 64
  72. #define FAT32_BS_RESERVED1 65
  73. #define FAT32_BS_BOOTSIG 66
  74. #define FAT32_BS_VOLID 67
  75. #define FAT32_BS_VOLLAB 71
  76. #define FAT32_BS_FILSYSTYPE 82
  77. //End of Boot Sctor and BPB Structure
  78. struct DirEntry {
  79. unsigned char DIR_Name[11]; //8 chars filename
  80. unsigned char DIR_Attr; //file attributes RSHA, Longname, Drive Label, Directory
  81. unsigned char DIR_NTRes; //set to zero
  82. unsigned char DIR_CrtTimeTenth; //creation time part in milliseconds
  83. unsigned int DIR_CrtTime; //creation time
  84. unsigned int DIR_CrtDate; //creation date
  85. unsigned int DIR_LastAccDate; //last access date
  86. unsigned int DIR_FstClusHI; //first cluster high word
  87. unsigned int DIR_WrtTime; //last write time
  88. unsigned int DIR_WrtDate; //last write date
  89. unsigned int DIR_FstClusLO; //first cluster low word
  90. unsigned long DIR_FileSize;
  91. };
  92. #endif //_FAT_H_