Rev 24 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#ifndef __fat16_h
#define __fat16_h
//________________________________________________________________________________________________________________________________________
//
// Definitions
//
//________________________________________________________________________________________________________________________________________
//#define __USE_TIME_DATE_ATTRIBUTE
#define __MAX_FILES_USED 2 // The number of files that can accessed simultaneously.
#define MBR_SECTOR 0 // the masterboot record is located in sector 0.
#define _UNUSED 1 // Bits used in the attribute of an directory entry.
#define _USED 2
#define _ARCHIVE 2
#define _READ_ONLY 4
#define _SYSTEM 8
#define _DIRECTORY 16
#define _FILE 32
//________________________________________________________________________________________________________________________________________
//
// Structure of a filepointer
//
//________________________________________________________________________________________________________________________________________
typedef struct afile
{
u32 start_cluster; // Sectorpointer to the first sector of the first datacluster of the file.
u32 cluster_pointer; // Pointer to the cluster which is edited at the moment.
u8 sector_index; // The sector which is edited at the moment (cluster_pointer + sector_index).
u16 byte_index; // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index).
u8 mode; // mode of fileoperation (read,write)
u32 filesize; // the size of the opend file in bytes.
u32 fileposition; // pointer to a character within the file 0 < fileposition < filesize
u32 sector_in_buffer; // the last sector read, wich is still in the sectorbuffer.
u32 directory_sector; // the sectorposition where the directoryentry has been made.
u8 directory_index; // the index to the directoryentry within the specified sector.
u8 attribute; // the attribute of the file opened.
u8 buffer[512]; // Buffer for read and write operation from or to the mmc.
u8 state; // state of the filepointer (used/unused/...)
} File;
//________________________________________________________________________________________________________________________________________
//
// Structure of an directoryentry
//
//________________________________________________________________________________________________________________________________________
struct DirEntry
{
u8 name[8]; // 8 bytes name.
u8 extension[3]; // 3 bytes extension.
u8 attribute; // attribute of the directory entry (unused,archive,read-only,system,directory,volume)
u8 reserved[10]; // reserved bytes within the directory entry.
u16 time; // time and
u16 date; // date of last write acces to the file or directory.
u16 startcluster; // first cluster of the file or directory.
u32 size; // size of the file or directory in bytes.
};
//________________________________________________________________________________________________________________________________________
//
// Structure of an entry within the fileallocationtable.
//
//________________________________________________________________________________________________________________________________________
struct FatEntry
{
u16 next_cluster; // the next cluster of the file.
};
//________________________________________________________________________________________________________________________________________
//
// Structure of an partitionentry
//
//________________________________________________________________________________________________________________________________________
struct PartitionEntry
{
u8 PartitionState;
u8 BeginningHead;
u16 BeginningCylinder;
u8 Type;
u8 EndHead;
u16 EndCylinder;
u32 NoSectorsBeforePartition;
u32 NoSectorsPartition ;
} __attribute__((packed));
//________________________________________________________________________________________________________________________________________
//
// Structure of the VolumeBootRecord
//
//________________________________________________________________________________________________________________________________________
struct VBR_Entry
{
u8 dummy[11];
u16 bps;
u8 SectorsPerCluster;
u16 ReservedSectors;
u8 NoFATCopies;
u16 MaxRootEntries;
u16 dummy2;
u8 dummy3;
u16 SectorsPerFAT;
} __attribute__((packed));
//________________________________________________________________________________________________________________________________________
//
// Structure of the MasterBootRecord
//
//________________________________________________________________________________________________________________________________________
struct MBR_Entry
{
u8 ExecutableCode[446];
struct PartitionEntry PartitionEntry1;
struct PartitionEntry PartitionEntry2;
struct PartitionEntry PartitionEntry3;
struct PartitionEntry PartitionEntry4;
u16 ExecutableMarker;
} __attribute__((packed));
//________________________________________________________________________________________________________________________________________
//
// API to the FAT16 filesystem
//
//________________________________________________________________________________________________________________________________________
extern u8 InitFat16(void);
extern File * fopen_(u8 *fname,s8 mode);
extern s16 fflush_(File *file);
extern void fclose_(File *file);
extern u32 fread_(void *buffer, u32 size, u32 count, File *file);
extern u32 fwrite_(void *buffer, u32 size, u32 count, File *file);
extern s16 fseek_(File *file, s32 offset, s16 origin);
extern s16 fgetchar_(File *file);
extern u8 fputchar_(File *file,s8 c);
extern u8 fputs_(File *file,s8 *string);
extern s8 * fgets_(s8 *s, s16 count, File *file);
extern s16 frename_(s8 *oldname, s8 *newname);
extern u8 fexist_(u8*fname);
//________________________________________________________________________________________________________________________________________
//
// Functions needed internaly for the fat16 implementation
//
//________________________________________________________________________________________________________________________________________
extern u8 CreateDirectoryEntry(u8*fname, u16 cluster, File *file,u8 attrib);
extern u16 FindNextFreeCluster(File *file);
extern u8 SeekDirectoryEntry(u8*fname, File *file);
extern void SeperateFileName(u8*fname, u8*name);
extern u8 ScanSubDirectories(u8*fname, File *file);
extern u16 GetNextCluster(File *file);
extern u8 AppendCluster(File *file);
extern u16 GetFatClusterOffset(File *file);
extern u16 GetFatSectorIndex(File *file);
//________________________________________________________________________________________________________________________________________
//
// Vaiables needed internaly for the fat16 implementation
//
//________________________________________________________________________________________________________________________________________
extern u8 SectorsPerCluster;
extern u8 SectorsPerCluster;
extern struct time rtctime;
#endif