ATmega8GPSLoggerBasismodul  20131018
fat16.h
Go to the documentation of this file.
1 #ifndef __fat16_h
2 #define __fat16_h
3 
4 //________________________________________________________________________________________________________________________________________
5 //
6 // Structure of a filepointer
7 //
8 //________________________________________________________________________________________________________________________________________
9 
10 typedef struct afile
11 {
12  unsigned long start_cluster; // Sectorpointer to the first sector of the first datacluster of the file.
13  unsigned long cluster_pointer; // Pointer to the cluster which is edited at the moment.
14  unsigned char sector_index; // The sector which is edited at the moment (cluster_pointer + sector_index).
15  unsigned int byte_index; // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index).
16  unsigned char mode; // mode of fileoperation (read,write)
17  unsigned long filesize; // the size of the opend file in bytes.
18  unsigned long fileposition; // pointer to a character within the file 0 < fileposition < filesize
19  unsigned long sector_in_buffer; // the last sector read, wich is still in the sectorbuffer.
20  unsigned long directory_sector; // the sectorposition where the directoryentry has been made.
21  unsigned char directory_index; // the index to the directoryentry within the specified sector.
22  unsigned char attribute; // the attribute of the file opened.
23 } File;
24 
25 //________________________________________________________________________________________________________________________________________
26 //
27 // Structure of an directoryentry
28 //
29 //________________________________________________________________________________________________________________________________________
30 
31 struct DirEntry
32 {
33  unsigned char name[8]; // 8 bytes name.
34  unsigned char extension[3]; // 3 bytes extension.
35  unsigned char attribute; // attribute of the directory entry (unused,archive,read-only,system,directory,volume)
36  unsigned char reserved[10];
37  unsigned int time; // time and
38  unsigned int date; // date of last write acces to the file or directory.
39  unsigned int startcluster; // first cluster of the file or directory.
40  unsigned long size; // size of the file or directory in bytes.
41 };
42 
43 //________________________________________________________________________________________________________________________________________
44 //
45 // Structure of an entry within the fileallocationtable.
46 //
47 //________________________________________________________________________________________________________________________________________
48 
49 struct FatEntry
50 {
51  unsigned int next_cluster; // the next cluster of the file.
52 };
53 //________________________________________________________________________________________________________________________________________
54 //
55 // API to the FAT16 filesystem
56 //
57 //________________________________________________________________________________________________________________________________________
58 
59 extern unsigned char InitFat16(void);
60 extern unsigned char fopen_(unsigned char *fname,char mode, File *file);
61 extern int fflush_(File *file);
62 extern void fclose_(File *file);
63 extern unsigned long fread_(void *buffer, unsigned long size, unsigned long count, File *file);
64 extern unsigned long fwrite_(void *buffer, unsigned long size, unsigned long count, File *file);
65 extern int fseek_(File *file, long offset, int origin);
66 extern int fgetchar_(File *file);
67 extern unsigned char fputchar_(File *file,char c);
68 extern unsigned char fputs_(File *file,char *string);
69 extern char * fgets_(char *s, int count, File *file);
70 extern int rename(char *oldname, char *newname);
71 extern unsigned char fexist_(unsigned char *fname, File *file);
72 
73 //________________________________________________________________________________________________________________________________________
74 //
75 // Functions needed internaly for the fat16 implementation
76 //
77 //________________________________________________________________________________________________________________________________________
78 
79 extern unsigned char CreateDirectoryEntry(unsigned char *fname, unsigned int cluster, File *file,unsigned char attrib);
80 extern unsigned int FindNextFreeCluster(File *file);
81 extern unsigned char SeekDirectoryEntry(unsigned char *fname, File *file);
82 extern void SeperateFileName(unsigned char *fname, unsigned char *name);
83 extern unsigned char ScanSubDirectories(unsigned char *fname, File *file);
84 extern unsigned int GetNextCluster(File *file);
85 extern unsigned char AppendCluster(File *file);
86 extern unsigned int GetFatClusterOffset(File *file);
87 extern unsigned int GetFatSectorIndex(File *file);
88 
89 
90 //________________________________________________________________________________________________________________________________________
91 //
92 // Definitions
93 //
94 //________________________________________________________________________________________________________________________________________
95 
96 //#define __USE_TIME_DATE_ATTRIBUTE
97 #define MBR_SECTOR 0 // the masterboot record is located in sector 0.
98 #define _UNUSED 1 // Bits used in the attribute of an directory entry.
99 #define _ARCHIVE 2
100 #define _READ_ONLY 4
101 #define _SYSTEM 8
102 #define _DIRECTORY 16
103 #define _FILE 32
104 
105 //________________________________________________________________________________________________________________________________________
106 //
107 // Vaiables needed internaly for the fat16 implementation
108 //
109 //________________________________________________________________________________________________________________________________________
110 
111 extern unsigned char SectorsPerCluster;
112 extern unsigned char FileBuffer[512];
113 extern unsigned char SectorsPerCluster;
114 extern File myfile;
115 
116 //extern struct time rtctime;
117 #endif
118 
119 
120 
121 
unsigned long filesize
Definition: fat16.h:17
unsigned long fread_(void *buffer, unsigned long size, unsigned long count, File *file)
Definition: fat16.c:221
unsigned char fexist_(unsigned char *fname, File *file)
Definition: fat16.c:505
unsigned long size
Definition: fat16.h:40
void SeperateFileName(unsigned char *fname, unsigned char *name)
Definition: fat16.c:854
int rename(char *oldname, char *newname)
unsigned long directory_sector
Definition: fat16.h:20
unsigned char extension[3]
Definition: fat16.h:34
unsigned char ScanSubDirectories(unsigned char *fname, File *file)
Definition: fat16.c:790
unsigned char name[8]
Definition: fat16.h:33
unsigned int startcluster
Definition: fat16.h:39
unsigned char mode
Definition: fat16.h:16
unsigned char fputchar_(File *file, char c)
Definition: fat16.c:400
unsigned char attribute
Definition: fat16.h:35
int fgetchar_(File *file)
Definition: fat16.c:356
unsigned int time
Definition: fat16.h:37
Definition: fat16.h:49
Definition: fat16.h:10
unsigned char SeekDirectoryEntry(unsigned char *fname, File *file)
Definition: fat16.c:736
unsigned int FindNextFreeCluster(File *file)
Definition: fat16.c:574
File myfile
unsigned long fileposition
Definition: fat16.h:18
unsigned int GetFatClusterOffset(File *file)
Definition: fat16.c:646
int fseek_(File *file, long offset, int origin)
Definition: fat16.c:286
unsigned char FileBuffer[512]
Definition: fat16.c:55
unsigned char fputs_(File *file, char *string)
Definition: fat16.c:443
Definition: fat16.h:31
unsigned long start_cluster
Definition: fat16.h:12
struct afile File
unsigned long sector_in_buffer
Definition: fat16.h:19
unsigned int date
Definition: fat16.h:38
unsigned char AppendCluster(File *file)
Definition: fat16.c:614
unsigned int next_cluster
Definition: fat16.h:51
unsigned char InitFat16(void)
Definition: fat16.c:71
unsigned int GetFatSectorIndex(File *file)
Definition: fat16.c:664
char * fgets_(char *s, int count, File *file)
Definition: fat16.c:463
int fflush_(File *file)
Definition: fat16.c:159
unsigned char sector_index
Definition: fat16.h:14
unsigned char fopen_(unsigned char *fname, char mode, File *file)
Definition: fat16.c:97
unsigned long fwrite_(void *buffer, unsigned long size, unsigned long count, File *file)
Definition: fat16.c:254
unsigned int GetNextCluster(File *file)
Definition: fat16.c:526
unsigned char SectorsPerCluster
Definition: fat16.h:113
unsigned long cluster_pointer
Definition: fat16.h:13
void fclose_(File *file)
Definition: fat16.c:195
unsigned char attribute
Definition: fat16.h:22
unsigned char CreateDirectoryEntry(unsigned char *fname, unsigned int cluster, File *file, unsigned char attrib)
Definition: fat16.c:687
unsigned char directory_index
Definition: fat16.h:21
unsigned int byte_index
Definition: fat16.h:15
unsigned char reserved[10]
Definition: fat16.h:36