Rev 427 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 427 | Rev 433 | ||
---|---|---|---|
1 | #ifndef _FAT16_H |
1 | #ifndef _FAT16_H |
2 | #define _FAT16_H |
2 | #define _FAT16_H |
3 | 3 | ||
4 | 4 | ||
5 | //________________________________________________________________________________________________________________________________________ |
5 | //________________________________________________________________________________________________________________________________________ |
6 | // |
6 | // |
7 | // Definitions |
7 | // Definitions |
8 | // |
8 | // |
9 | //________________________________________________________________________________________________________________________________________ |
9 | //________________________________________________________________________________________________________________________________________ |
10 | 10 | ||
11 | #define FILE_MAX_OPEN 4 // The number of files that can accessed simultaneously. |
11 | #define FILE_MAX_OPEN 4 // The number of files that can accessed simultaneously. |
12 | #define SEEK_SET 0 |
12 | #define SEEK_SET 0 |
13 | #define SEEK_CUR 1 |
13 | #define SEEK_CUR 1 |
14 | #define SEEK_END 2 |
14 | #define SEEK_END 2 |
15 | #define EOF (-1) |
15 | #define EOF (-1) |
16 | #define BYTES_PER_SECTOR 512 |
16 | #define BYTES_PER_SECTOR 512 |
17 | /* |
17 | /* |
18 | ________________________________________________________________________________________________________________________________________ |
18 | ________________________________________________________________________________________________________________________________________ |
19 | |
19 | |
20 | Structure of a filepointer |
20 | Structure of a filepointer |
21 | ________________________________________________________________________________________________________________________________________ |
21 | ________________________________________________________________________________________________________________________________________ |
22 | */ |
22 | */ |
23 | typedef struct |
23 | typedef struct |
24 | { |
24 | { |
25 | u32 FirstSectorOfFirstCluster; // First sector of the first cluster of the file. |
25 | u32 FirstSectorOfFirstCluster; // First sector of the first cluster of the file. |
26 | u32 FirstSectorOfCurrCluster; // First sector of the cluster which is edited at the moment. |
26 | u32 FirstSectorOfCurrCluster; // First sector of the cluster which is edited at the moment. |
27 | u32 FirstSectorOfLastCluster; // First sector of the last cluster of the file |
27 | u32 FirstSectorOfLastCluster; // First sector of the last cluster of the file |
28 | u8 SectorOfCurrCluster; // The sector within the current cluster. |
28 | u8 SectorOfCurrCluster; // The sector within the current cluster. |
29 | u16 ByteOfCurrSector; // The byte location within the current sector. |
29 | u16 ByteOfCurrSector; // The byte location within the current sector. |
30 | u8 Mode; // Mode of fileoperation (read,write) |
30 | u8 Mode; // Mode of fileoperation (read,write) |
31 | u32 Size; // The size of the opend file in bytes. |
31 | u32 Size; // The size of the opend file in bytes. |
32 | u32 Position; // Pointer to a character within the file 0 < fileposition < filesize |
32 | u32 Position; // Pointer to a character within the file 0 < fileposition < filesize |
33 | u32 DirectorySector; // the sectorposition where the directoryentry has been made. |
33 | u32 DirectorySector; // the sectorposition where the directoryentry has been made. |
34 | u16 DirectoryIndex; // The index to the directoryentry within the specified sector. |
34 | u16 DirectoryIndex; // The index to the directoryentry within the specified sector. |
35 | u8 Attribute; // The attribute of the file opened. |
35 | u8 Attribute; // The attribute of the file opened. |
36 | u8 Cache[BYTES_PER_SECTOR]; // Cache for read and write operation from or to the sd-card. |
36 | u8 Cache[BYTES_PER_SECTOR]; // Cache for read and write operation from or to the sd-card. |
37 | u32 SectorInCache; // The last sector read, which is still in the sector cache. |
37 | u32 SectorInCache; // The last sector read, which is still in the sector cache. |
38 | u8 State; // State of the filepointer (used/unused/...) |
38 | u8 State; // State of the filepointer (used/unused/...) |
39 | } File_t; |
39 | } File_t; |
40 | 40 | ||
41 | // attribute definitions |
41 | // attribute definitions |
42 | #define ATTR_NONE 0x00 // normal file |
42 | #define ATTR_NONE 0x00 // normal file |
43 | #define ATTR_READONLY 0x01 // file is readonly |
43 | #define ATTR_READONLY 0x01 // file is readonly |
44 | #define ATTR_HIDDEN 0x02 // file is hidden |
44 | #define ATTR_HIDDEN 0x02 // file is hidden |
45 | #define ATTR_SYSTEM 0x04 // file is a system file |
45 | #define ATTR_SYSTEM 0x04 // file is a system file |
46 | #define ATTR_VOLUMELABEL 0x08 // entry is a volume label |
46 | #define ATTR_VOLUMELABEL 0x08 // entry is a volume label |
47 | #define ATTR_LONG_FILENAME 0x0F // this is a long filename entry |
47 | #define ATTR_LONG_FILENAME 0x0F // this is a long filename entry |
48 | #define ATTR_SUBDIRECTORY 0x10 // entry is a directory name |
48 | #define ATTR_SUBDIRECTORY 0x10 // entry is a directory name |
49 | #define ATTR_ARCHIVE 0x20 // file is new or modified |
49 | #define ATTR_ARCHIVE 0x20 // file is new or modified |
50 | #define ATTR_ANY_FILE 0x3F // all files |
50 | #define ATTR_ANY_FILE 0x3F // all files |
51 | 51 | ||
52 | 52 | ||
53 | 53 | ||
54 | //________________________________________________________________________________________________________________________________________ |
54 | //________________________________________________________________________________________________________________________________________ |
55 | // |
55 | // |
56 | // Structure of an item used by functions findfirst and findnext |
56 | // Structure of an item used by functions findfirst and findnext |
57 | //________________________________________________________________________________________________________________________________________ |
57 | //________________________________________________________________________________________________________________________________________ |
58 | 58 | ||
59 | typedef struct |
59 | typedef struct |
60 | { |
60 | { |
61 | File_t fp; // filepointer used to get access to the filesystemstructure |
61 | File_t fp; // filepointer used to get access to the filesystemstructure |
62 | s8 searchstring[12]; // findfirst and findnext will only return elements within the specified directory matching this searchstring (8+3 + Terminator). |
62 | s8 searchstring[12]; // findfirst and findnext will only return elements within the specified directory matching this searchstring (8+3 + Terminator). |
63 | s8 name[13]; // the name of the element found within the specified directory |
63 | s8 name[13]; // the name of the element found within the specified directory |
64 | 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 |
64 | 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 |
65 | u8 attribfilter; |
65 | u8 attribfilter; |
66 | u8 attribmask; |
66 | u8 attribmask; |
67 | } __attribute__((packed)) Find_t; |
67 | } __attribute__((packed)) Find_t; |
- | 68 | ||
- | 69 | ||
- | 70 | ||
- | 71 | typedef struct |
|
- | 72 | { |
|
- | 73 | u8 IsValid; // 0 means invalid, else valid |
|
- | 74 | u8 SectorsPerCluster; // how many sectors does a cluster contain? |
|
- | 75 | u8 FatCopies; // Numbers of copies of the FAT |
|
- | 76 | u16 MaxRootEntries; // Possible number of entries in the root directory. |
|
- | 77 | u16 SectorsPerFat; // how many sectors does a fat16 contain? |
|
- | 78 | u32 FirstFatSector; // sector of the start of the fat |
|
- | 79 | u32 FirstRootDirSector; // sector of the rootdirectory |
|
- | 80 | u32 FirstDataSector; // sector of the first cluster containing data (cluster2). |
|
- | 81 | u32 LastDataSector; // the last data sector of the partition |
|
- | 82 | u8 VolumeLabel[12]; // the volume label |
|
- | 83 | u32 CurrentWorkingDirectory;// A pointer to the directory we are actual using |
|
- | 84 | s8 PathToCwd[256]; // a string containing the complete path to the current working directory |
|
- | 85 | } __attribute__((packed)) Partition_t; |
|
- | 86 | ||
- | 87 | extern Partition_t Partition; // Structure holds partition information |
|
68 | 88 | ||
69 | //________________________________________________________________________________________________________________________________________ |
89 | //________________________________________________________________________________________________________________________________________ |
70 | // |
90 | // |
71 | // API to the FAT16 filesystem |
91 | // API to the FAT16 filesystem |
72 | // |
92 | // |
73 | //________________________________________________________________________________________________________________________________________ |
93 | //________________________________________________________________________________________________________________________________________ |
74 | 94 | ||
75 | // File System Funtions |
95 | // File System Funtions |
76 | u8 Fat16_Init(void); |
96 | u8 Fat16_Init(void); |
77 | u8 Fat16_Deinit(void); |
97 | u8 Fat16_Deinit(void); |
78 | u8 Fat16_IsValid(void); |
98 | u8 Fat16_IsValid(void); |
79 | s8* FAT16_GetVolumeLabel(void); |
99 | s8* FAT16_GetVolumeLabel(void); |
80 | 100 | ||
81 | // File Function |
101 | // File Function |
82 | File_t *fopen_(s8* const filename, const s8 mode); |
102 | File_t *fopen_(s8* const filename, const s8 mode); |
83 | s16 fclose_(File_t * const file); |
103 | s16 fclose_(File_t * const file); |
84 | u8 fexist_(s8* const filename); |
104 | u8 fexist_(s8* const filename); |
85 | s16 fflush_(File_t * const file); |
105 | s16 fflush_(File_t * const file); |
86 | s16 fseek_(File_t * const file, s32 offset, s16 origin); |
106 | s16 fseek_(File_t * const file, s32 offset, s16 origin); |
87 | s16 fgetc_(File_t * const file); |
107 | s16 fgetc_(File_t * const file); |
88 | s16 fputc_(s8 c, File_t * const file); |
108 | s16 fputc_(s8 c, File_t * const file); |
89 | u32 fread_(void *buffer, u32 size, u32 count, File_t * const file); |
109 | u32 fread_(void *buffer, u32 size, u32 count, File_t * const file); |
90 | u32 fwrite_(void *buffer, u32 size, u32 count, File_t * const file); |
110 | u32 fwrite_(void *buffer, u32 size, u32 count, File_t * const file); |
91 | s16 fputs_(s8 * const string, File_t * const file); |
111 | s16 fputs_(s8 * const string, File_t * const file); |
92 | s8 * fgets_(s8 * const string, s16 length, File_t * const file); |
112 | s8 * fgets_(s8 * const string, s16 length, File_t * const file); |
93 | u8 feof_(File_t * const file); |
113 | u8 feof_(File_t * const file); |
94 | u8 fdelete_(s8* const filepath); |
114 | u8 fdelete_(s8* const filepath); |
95 | 115 | ||
96 | // Directory Functions |
116 | // Directory Functions |
97 | s8 *getcwd_(void); |
117 | s8 *getcwd_(void); |
98 | u8 findfirst_(const s8* name, u8 attribmask, Find_t *); |
118 | u8 findfirst_(const s8* name, u8 attribmask, Find_t *); |
99 | u8 findnext_(Find_t *); |
119 | u8 findnext_(Find_t *); |
100 | u8 chdir_(s8* const dirpath); |
120 | u8 chdir_(s8* const dirpath); |
101 | u8 mkdir_(s8* const dirpath); |
121 | u8 mkdir_(s8* const dirpath); |
102 | u8 rmdir_(s8* const dirpath); |
122 | u8 rmdir_(s8* const dirpath); |
103 | 123 | ||
104 | 124 | ||
105 | 125 | ||
106 | 126 | ||
107 | #endif //_FAT16_H |
127 | #endif //_FAT16_H |
108 | 128 | ||
109 | 129 | ||
110 | 130 | ||
111 | 131 | ||
112 | 132 |