STIMA  3
pff.h
1 /*---------------------------------------------------------------------------/
2 / Petit FatFs - FAT file system module include file R0.03 (C)ChaN, 2014
3 /----------------------------------------------------------------------------/
4 / Petit FatFs module is an open source software to implement FAT file system to
5 / small embedded systems. This is a free software and is opened for education,
6 / research and commercial developments under license policy of following trems.
7 /
8 / Copyright (C) 2014, ChaN, all right reserved.
9 /
10 / * The Petit FatFs module is a free software and there is NO WARRANTY.
11 / * No restriction on use. You can use, modify and redistribute it for
12 / personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
13 / * Redistributions of source code must retain the above copyright notice.
14 /
15 /----------------------------------------------------------------------------*/
16 
17 #ifndef _PFATFS
18 #define _PFATFS 4004 /* Revision ID */
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include "integer.h"
25 #include "pffconf.h"
26 
27 #if _PFATFS != _PFFCONF
28 #error Wrong configuration file (pffconf.h).
29 #endif
30 
31 #if _FS_FAT32
32 #define CLUST DWORD
33 #else
34 #define CLUST WORD
35 #endif
36 
37 
38 /* File system object structure */
39 
40 typedef struct {
41  BYTE fs_type; /* FAT sub type */
42  BYTE flag; /* File status flags */
43  BYTE csize; /* Number of sectors per cluster */
44  BYTE pad1;
45  WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
46  CLUST n_fatent; /* Number of FAT entries (= number of clusters + 2) */
47  DWORD fatbase; /* FAT start sector */
48  DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
49  DWORD database; /* Data start sector */
50  DWORD fptr; /* File R/W pointer */
51  DWORD fsize; /* File size */
52  CLUST org_clust; /* File start cluster */
53  CLUST curr_clust; /* File current cluster */
54  DWORD dsect; /* File current data sector */
55 } FATFS;
56 
57 
58 
59 /* Directory object structure */
60 
61 typedef struct {
62  WORD index; /* Current read/write index number */
63  BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
64  CLUST sclust; /* Table start cluster (0:Static table) */
65  CLUST clust; /* Current cluster */
66  DWORD sect; /* Current sector */
67 } DIR;
68 
69 
70 
71 /* File status structure */
72 
73 typedef struct {
74  DWORD fsize; /* File size */
75  WORD fdate; /* Last modified date */
76  WORD ftime; /* Last modified time */
77  BYTE fattrib; /* Attribute */
78  char fname[13]; /* File name */
79 } FILINFO;
80 
81 
82 
83 /* File function return code (FRESULT) */
84 
85 typedef enum {
86  FR_OK = 0, /* 0 */
87  FR_DISK_ERR, /* 1 */
88  FR_NOT_READY, /* 2 */
89  FR_NO_FILE, /* 3 */
90  FR_NOT_OPENED, /* 4 */
91  FR_NOT_ENABLED, /* 5 */
92  FR_NO_FILESYSTEM /* 6 */
93 } FRESULT;
94 
95 
96 
97 /*--------------------------------------------------------------*/
98 /* Petit FatFs module application interface */
99 
100 FRESULT pf_mount (FATFS* fs); /* Mount/Unmount a logical drive */
101 FRESULT pf_open (const char* path); /* Open a file */
102 #ifdef _USE_MINIMALISTIC_PFF
103 FRESULT pf_read (void* buff, UINT btr); /* Read data from the open file */
104 #else
105 FRESULT pf_read (void* buff, UINT btr, UINT* br); /* Read data from the open file */
106 #endif
107 FRESULT pf_write (const void* buff, UINT btw, UINT* bw); /* Write data to the open file */
108 FRESULT pf_lseek (DWORD ofs); /* Move file pointer of the open file */
109 FRESULT pf_opendir (DIR* dj, const char* path); /* Open a directory */
110 FRESULT pf_readdir (DIR* dj, FILINFO* fno); /* Read a directory item from the open directory */
111 
112 
113 
114 /*--------------------------------------------------------------*/
115 /* Flags and offset address */
116 
117 /* File status flag (FATFS.flag) */
118 
119 #define FA_OPENED 0x01
120 #define FA_WPRT 0x02
121 #define FA__WIP 0x40
122 
123 
124 /* FAT sub type (FATFS.fs_type) */
125 
126 #define FS_FAT12 1
127 #define FS_FAT16 2
128 #define FS_FAT32 3
129 
130 
131 /* File attribute bits for directory entry */
132 
133 #define AM_RDO 0x01 /* Read only */
134 #define AM_HID 0x02 /* Hidden */
135 #define AM_SYS 0x04 /* System */
136 #define AM_VOL 0x08 /* Volume label */
137 #define AM_LFN 0x0F /* LFN entry */
138 #define AM_DIR 0x10 /* Directory */
139 #define AM_ARC 0x20 /* Archive */
140 #define AM_MASK 0x3F /* Mask of defined bits */
141 
142 
143 /*--------------------------------*/
144 /* Multi-byte word access macros */
145 
146 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
147 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
148 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
149 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
150 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
151 #else /* Use byte-by-byte access to the FAT structure */
152 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
153 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
154 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
155 #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
156 #endif
157 
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* _PFATFS */
Definition: pff.h:61
Definition: pff.h:40
Definition: pff.h:73