Subversion Repositories NaviCtrl

Rev

Rev 380 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
#ifndef _FAT16_H
2
#define _FAT16_H
1 ingob 3
 
4
 
5
//________________________________________________________________________________________________________________________________________
6
// 
41 ingob 7
// Definitions
1 ingob 8
//                              
9
//________________________________________________________________________________________________________________________________________
10
 
41 ingob 11
//#define               __USE_TIME_DATE_ATTRIBUTE
211 killagreg 12
#define FILE_MAX_OPEN   4                               // The number of files that can accessed simultaneously. 
41 ingob 13
#define SEEK_SET        0
14
#define SEEK_CUR        1
15
#define SEEK_END        2
16
#define EOF     (-1) 
17
#define BYTES_PER_SECTOR        512
18
/*
19
________________________________________________________________________________________________________________________________________
20
 
21
        Structure of a filepointer
22
________________________________________________________________________________________________________________________________________
23
*/
24
typedef struct
24 StephanB 25
{
41 ingob 26
        u32 FirstSectorOfFirstCluster;  // First sector of the first cluster of the file.
27
        u32 FirstSectorOfCurrCluster;   // First sector of the cluster which is edited at the moment.
380 holgerb 28
        u32 FirstSectorOfLastCluster;   // First sector of the last cluster of the file
41 ingob 29
        u8      SectorOfCurrCluster;            // The sector within the current cluster.
30
        u16 ByteOfCurrSector;                   // The byte location within the current sector.
31
        u8      Mode;                                           // Mode of fileoperation (read,write)
32
        u32 Size;                                               // The size of the opend file in bytes.
33
        u32 Position;                                   // Pointer to a character within the file 0 < fileposition < filesize
34
        u32 DirectorySector;                    // the sectorposition where the directoryentry has been made.
35
        u16     DirectoryIndex;                         // The index to the directoryentry within the specified sector.
36
        u8      Attribute;                                      // The attribute of the file opened.
37
        u8  Cache[BYTES_PER_SECTOR];    // Cache for read and write operation from or to the sd-card.
38
        u32 SectorInCache;                              // The last sector read, which is still in the sector cache.
39
        u8      State;                                          // State of the filepointer (used/unused/...) 
40
} File_t;
1 ingob 41
 
379 holgerb 42
 
43
#define ATTR_NONE               0x00    // normal file
44
#define ATTR_READONLY           0x01    // file is readonly
45
#define ATTR_HIDDEN                     0x02    // file is hidden
46
#define ATTR_SYSTEM                     0x04    // file is a system file
47
#define ATTR_VOLUMELABEL        0x08    // entry is a volume label
48
#define ATTR_LONG_FILENAME      0x0F    // this is a long filename entry
49
#define ATTR_SUBDIRECTORY       0x10    // entry is a directory name
50
#define ATTR_ARCHIVE            0x20    // file is new or modified
51
#define ATTR_ANY_FILE           0x3F    // all files
349 ingob 52
 
379 holgerb 53
 
54
 
1 ingob 55
//________________________________________________________________________________________________________________________________________
379 holgerb 56
//
57
//      Structure of an item used by functions findfirst and findnext
58
//________________________________________________________________________________________________________________________________________
59
 
60
typedef struct
61
{
62
        File_t  fp;                                             // filepointer used to get access to the filesystemstructure
63
        s8              searchstring[11];               // findfirst and findnext will only return elements within the specified directory matching this searchstring.
64
        s8              name[13];                               // the name of the element found within the specified directory
65
        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 
66
        u8              attribfilter;                  
67
        u8              attribmask;
68
} __attribute__((packed)) Find_t;
69
 
70
//________________________________________________________________________________________________________________________________________
1 ingob 71
// 
72
// API to the FAT16 filesystem
73
//                              
74
//________________________________________________________________________________________________________________________________________
75
 
41 ingob 76
u8              Fat16_Init(void);
77
u8              Fat16_Deinit(void);
90 killagreg 78
u8              Fat16_IsValid(void);
210 killagreg 79
s8*             FAT16_GetVolumeLabel(void);
89 killagreg 80
 
81
File_t *fopen_(s8 * const filename, const s8 mode);
41 ingob 82
s16     fclose_(File_t *file);
89 killagreg 83
u8              fexist_(s8 * const filename);
84
s16             fflush_(File_t * const file);
85
s16     fseek_(File_t * const file, s32 offset, s16 origin);
86
s16             fgetc_(File_t * const file);
87
s16             fputc_(s8 c, File_t * const file);
88
u32     fread_(void *buffer, u32 size, u32 count, File_t * const file);
89
u32     fwrite_(void *buffer, u32 size, u32 count, File_t * const file);
90 killagreg 90
s16             fputs_(s8 * const string, File_t * const file);
89 killagreg 91
s8 *    fgets_(s8 * const string, s16 length, File_t * const file);
92
u8              feof_(File_t * const file);
379 holgerb 93
u8              findfirst_(const s8* name, u8 attribmask, Find_t *);
94
u8              findnext_(Find_t *);
95
u8              chdir_(s8 *folder);
96
s8              *GetPath(void);
1 ingob 97
 
24 StephanB 98
 
99
 
379 holgerb 100
 
41 ingob 101
#endif //_FAT16_H
1 ingob 102
 
103
 
104
 
105