Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 392 → Rev 393

/tags/V0.28i/fat16.h
0,0 → 1,105
#ifndef _FAT16_H
#define _FAT16_H
 
 
//________________________________________________________________________________________________________________________________________
//
// Definitions
//
//________________________________________________________________________________________________________________________________________
 
//#define __USE_TIME_DATE_ATTRIBUTE
#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;
 
#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[11]; // findfirst and findnext will only return elements within the specified directory matching this searchstring.
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;
 
//________________________________________________________________________________________________________________________________________
//
// API to the FAT16 filesystem
//
//________________________________________________________________________________________________________________________________________
 
u8 Fat16_Init(void);
u8 Fat16_Deinit(void);
u8 Fat16_IsValid(void);
s8* FAT16_GetVolumeLabel(void);
File_t *fopen_(s8 * const filename, const s8 mode);
s16 fclose_(File_t *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 findfirst_(const s8* name, u8 attribmask, Find_t *);
u8 findnext_(Find_t *);
u8 chdir_(s8 *folder);
s8 *GetPath(void);
 
 
 
 
#endif //_FAT16_H