00001
00002 void sub2();
00003 #ifndef _CORE_SRC_FAT_HPP
00004 #define _CORE_SRC_FAT_HPP
00005 const uint32 NAME_MAX = 0x100;
00006
00007 const uint32 FAT_FAT12 = 12;
00008 const uint32 FAT_FAT16 = 16;
00009 const uint32 FAT_FAT32 = 32;
00010
00011 const uint32 FAT_READ = 0x0;
00012 const uint32 FAT_WRITE = 0x1;
00013
00014 const uint8 FAT_DIRENT_FREE = 0xE5;
00015 const uint8 FAT_DIRENT_FREE2 = 0x05;
00016 const uint8 FAT_DIRENT_ALL_FREE = 0x00;
00017 const uint8 FAT_DIRENT_PAD = 0x20;
00018 extern uint8 FAT_DIRENT_ILLEGAL[];
00019
00020 const uint8 FAT_ATTR_RO = 0x01;
00021 const uint8 FAT_ATTR_HIDDEN = 0x02;
00022 const uint8 FAT_ATTR_SYSTEM = 0x04;
00023 const uint8 FAT_ATTR_VOLUME = 0x08;
00024 const uint8 FAT_ATTR_DIR = 0x10;
00025 const uint8 FAT_ATTR_ARCH = 0x20;
00026 const uint8 FAT_ATTR_LFN = 0x0F;
00027
00028 const uint8 LFN_SIG_MASK = 0x1f;
00029 const uint8 LFN_SIG_LAST = 0x40;
00030
00031 const uint32 FAT32_BAD = 0x0FFFFFF7;
00032 const uint32 FAT16_BAD = 0xFFF7;
00033 const uint32 FAT12_BAD = 0x0FF7;
00034
00035 struct bootsect_t
00036 {
00037 char BS_jmpBoot[3];
00038 char BS_OEMName[8];
00039 uint16 BPB_BytsPerSec;
00040 uint8 BPB_SecPerClus;
00041 uint16 BPB_ResvdSecCnt;
00042 uint8 BPB_NumFATs;
00043 uint16 BPB_RootEntCnt;
00044 uint16 BPB_TotSec16;
00045 uint8 BPB_Media;
00046 uint16 BPB_FATSz16;
00047 uint16 BPB_SecPerTrk;
00048 uint16 BPB_NumHeads;
00049 uint32 BPB_HiddSec;
00050 uint32 BPB_TotSec32;
00051 union extbpb_t
00052 {
00053 struct bpb16_t
00054 {
00055 uint8 BS_DrvNum;
00056 uint8 BS_Reserved1;
00057 uint8 BS_BootSig;
00058 char BS_VolID[4];
00059 char BS_VolLab[11];
00060 char BS_FilSysType[8];
00061 } __attribute__ ((packed)) bpb16;
00062 struct bpb32_t
00063 {
00064 uint32 BPB_FATSz32;
00065 uint16 BPB_ExtFlags;
00066 uint16 BPB_FSVer;
00067 uint32 BPB_RootClus;
00068 uint16 BPB_FSInfo;
00069 uint16 BPB_BkBootSec;
00070 char BPB_Reserved[12];
00071 uint8 BS_DrvNum;
00072 uint8 BS_Reserved1;
00073 uint8 BS_BootSig;
00074 char BS_VolID[4];
00075 char BS_VolLab[11];
00076 char BS_FilSysType[8];
00077 } bpb32 __attribute__ ((packed));
00078 } ext;
00079 } __attribute__ ((packed)) ;
00080
00081
00082 union fatdirent_t
00083 {
00084
00085 struct sfndirent_t
00086 {
00087 char DIR_Name[11];
00088 uint8 DIR_Attr;
00089 uint8 DIR_NTRes;
00090 uint8 DIR_CrtTimeTenth;
00091 uint16 DIR_CrtTime;
00092 uint16 DIR_CrtDate;
00093 uint16 DIR_LstAccDate;
00094 uint16 DIR_FstClusHI;
00095 uint16 DIR_WrtTime;
00096 uint16 DIR_WrtDate;
00097 uint16 DIR_FstClusLO;
00098 uint32 DIR_FileSize;
00099 } sfn __attribute__ ((packed)) ;
00100
00101 struct lfndirent_t
00102 {
00103 uint8 DIR_Sig;
00104 char DIR_LName1[10];
00105 uint8 DIR_Attr;
00106 uint8 DIR_Flags;
00107 uint8 DIR_ChkSum;
00108 char DIR_LName2[12];
00109 uint16 DIR_First;
00110 uint8 DIR_LName3[4];
00111 } lfn __attribute__ ((packed)) ;
00112 };
00113
00114 struct dirent
00115 {
00116 char name[NAME_MAX + 1];
00117 uint64 size;
00118 uint32 parent;
00119 uint32 block;
00120 uint32 flags;
00121 void *resvd;
00122 uint32 entry_in_dir;
00123 };
00124
00125
00126 struct fatinode_t
00127 {
00128 uint32 parent;
00129 uint32 start;
00130 };
00131
00132
00133 uint32 fat_probe(uint32 arg) asm ("__fat_probe");
00134
00135
00136
00137 class fat_t
00138 {
00139 public:
00140 char *path;
00141
00142 uint32 source;
00143 int valid;
00144 uint32 sector_size, cluster_size;
00145 uint32 FirstDataSector;
00146 uint32 RootDirSectors;
00147 uint32 FATSz;
00148 uint32 TotSec, DataSec;
00149 uint32 CountofClusters;
00150 uint32 SecPerClus;
00151 uint32 FirstRootDirSecNum;
00152 uint32 ResvdSecCnt;
00153 uint32 active_fat;
00154
00155 uint32 fat_type;
00156
00157 fat_t();
00158 void init();
00159 fat_t(char *ph);
00160 void init(char *ph);
00161 ~fat_t();
00162 void done();
00163 void inval();
00164
00165
00166 int verify();
00167 int fat_rawrw(uint32 sector, char *ch, uint32 count, uint32 read_write);
00168 int cluster_rw(uint32 block, char *ch, uint32 count, uint32 read_write);
00169 int rootdir_rw(char *ch, uint32 read_write);
00170 uint32 clus2sect(uint32 cluster);
00171 uint32 free_clusters();
00172 uint32 next_free();
00173 uint32 verify_boot_sector(uint32 block);
00174 uint32 get_active_table();
00175
00176 uint32 read_next_clust(uint32 table, uint32 cluster);
00177 int write_next_clust(uint32 table, uint32 cluster, uint32 val);
00178 uint32 cluster_no (uint32 table, uint32 first, uint32 n);
00179 int isEOF(uint32 val);
00180 uint32 chain_length(uint32 first);
00181 int read_chain(uint32 first, uint32 count, char *buff);
00182
00183 int lfn_parse_dir (char *cluster_buffer, uint32 clus, dirent *ent, uint32 *entry);
00184 int valid_lfn(fatdirent_t *ent);
00185 int valid_sfn(fatdirent_t *ent);
00186 int sfn2name (char *raw, char *buff);
00187 int lfn2name (fatdirent_t *first, uint32 count, char *buff);
00188 int find_entry(char *name, struct dirent *ent);
00189 int get_file(char *name, char *buffer, uint32 clus, dirent *ent);
00190
00191
00192
00193
00194 int write ( struct file_handle_t *file, char *buff, int nbytes);
00195 int readdir ( struct file_handle_t *file, struct dirent *entry, int count);
00196 int open ( struct file_handle_t *file );
00197 int close ( struct file_handle_t *file );
00198 };
00199
00200 #endif