Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 746 → Rev 747

/tags/V2.14c/fat16.h
0,0 → 1,131
#ifndef _FAT16_H
#define _FAT16_H
 
 
//________________________________________________________________________________________________________________________________________
//
// Definitions
//
//________________________________________________________________________________________________________________________________________
 
#define FILE_MAX_OPEN 4 // The number of files that can accessed simultaneously.
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define EOF (-1)
#define BYTES_PER_SECTOR 512
/*
________________________________________________________________________________________________________________________________________
Structure of a filepointer
________________________________________________________________________________________________________________________________________
*/
typedef struct
{
u32 FirstSectorOfFirstCluster; // First sector of the first cluster of the file.
u32 FirstSectorOfCurrCluster; // First sector of the cluster which is edited at the moment.
u32 FirstSectorOfLastCluster; // First sector of the last cluster of the file
u8 SectorOfCurrCluster; // The sector within the current cluster.
u16 ByteOfCurrSector; // The byte location within the current sector.
u8 Mode; // Mode of fileoperation (read,write)
u32 Size; // The size of the opend file in bytes.
u32 Position; // Pointer to a character within the file 0 < fileposition < filesize
u32 DirectorySector; // the sectorposition where the directoryentry has been made.
u16 DirectoryIndex; // The index to the directoryentry within the specified sector.
u8 Attribute; // The attribute of the file opened.
u8 Cache[BYTES_PER_SECTOR]; // Cache for read and write operation from or to the sd-card.
u32 SectorInCache; // The last sector read, which is still in the sector cache.
u8 State; // State of the filepointer (used/unused/...)
} File_t;
 
// attribute definitions
#define ATTR_NONE 0x00 // normal file
#define ATTR_READONLY 0x01 // file is readonly
#define ATTR_HIDDEN 0x02 // file is hidden
#define ATTR_SYSTEM 0x04 // file is a system file
#define ATTR_VOLUMELABEL 0x08 // entry is a volume label
#define ATTR_LONG_FILENAME 0x0F // this is a long filename entry
#define ATTR_SUBDIRECTORY 0x10 // entry is a directory name
#define ATTR_ARCHIVE 0x20 // file is new or modified
#define ATTR_ANY_FILE 0x3F // all files
 
 
 
//________________________________________________________________________________________________________________________________________
//
// Structure of an item used by functions findfirst and findnext
//________________________________________________________________________________________________________________________________________
 
typedef struct
{
File_t fp; // filepointer used to get access to the filesystemstructure
s8 searchstring[12]; // findfirst and findnext will only return elements within the specified directory matching this searchstring (8+3 + Terminator).
s8 name[13]; // the name of the element found within the specified directory
u8 active; // if the attribute active is set the name and the attributes of an element found within DirectoryEntryExist will be entered into the structure
u8 attribfilter;
u8 attribmask;
} __attribute__((packed)) Find_t;
 
 
 
typedef struct
{
u8 IsValid; // 0 means invalid, else valid
u8 SectorsPerCluster; // how many sectors does a cluster contain?
u8 FatCopies; // Numbers of copies of the FAT
u16 MaxRootEntries; // Possible number of entries in the root directory.
u16 SectorsPerFat; // how many sectors does a fat16 contain?
u32 FirstFatSector; // sector of the start of the fat
u32 FirstRootDirSector; // sector of the rootdirectory
u32 FirstDataSector; // sector of the first cluster containing data (cluster2).
u32 LastDataSector; // the last data sector of the partition
u8 VolumeLabel[12]; // the volume label
u32 CurrentWorkingDirectory;// A pointer to the directory we are actual using
s8 PathToCwd[256]; // a string containing the complete path to the current working directory
} __attribute__((packed)) Partition_t;
 
extern Partition_t Partition; // Structure holds partition information
 
//________________________________________________________________________________________________________________________________________
//
// API to the FAT16 filesystem
//
//________________________________________________________________________________________________________________________________________
 
// File System Funtions
u8 Fat16_Init(void);
u8 Fat16_Deinit(void);
u8 Fat16_IsValid(void);
s8* FAT16_GetVolumeLabel(void);
 
// File Function
File_t *fopen_(s8* const filename, const s8 mode);
s16 fclose_(File_t * const file);
u8 fexist_(s8* const filename);
s16 fflush_(File_t * const file);
s16 fseek_(File_t * const file, s32 offset, s16 origin);
s16 fgetc_(File_t * const file);
s16 fputc_(s8 c, File_t * const file);
u32 fread_(void *buffer, u32 size, u32 count, File_t * const file);
u32 fwrite_(void *buffer, u32 size, u32 count, File_t * const file);
s16 fputs_(s8 * const string, File_t * const file);
s8 * fgets_(s8 * const string, s16 length, File_t * const file);
u8 feof_(File_t * const file);
u8 fdelete_(s8* const filepath);
 
// Directory Functions
s8 *getcwd_(void);
u8 findfirst_(const s8* name, u8 attribmask, Find_t *);
u8 findnext_(Find_t *);
u8 chdir_(s8* const dirpath);
u8 mkdir_(s8* const dirpath);
u8 rmdir_(s8* const dirpath);
 
 
 
 
#endif //_FAT16_H