source: uKadecot/trunk/pfatfs/pff.h@ 101

Last change on this file since 101 was 101, checked in by coas-nagasima, 9 years ago

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 5.5 KB
RevLine 
[101]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
21extern "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
40typedef 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
61typedef struct {
62 FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
63 WORD index; /* Current read/write index number */
64 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
65 CLUST sclust; /* Table start cluster (0:Static table) */
66 CLUST clust; /* Current cluster */
67 DWORD sect; /* Current sector */
68#if _USE_LFN
69 WCHAR* lfn; /* Pointer to the LFN working buffer */
70 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
71#endif
72} DIR;
73
74
75
76/* File status structure */
77
78typedef struct {
79 DWORD fsize; /* File size */
80 WORD fdate; /* Last modified date */
81 WORD ftime; /* Last modified time */
82 BYTE fattrib; /* Attribute */
83 char fname[13]; /* File name */
84#if _USE_LFN
85 char* lfname; /* Pointer to the LFN buffer */
86 UINT lfsize; /* Size of LFN buffer in TCHAR */
87#endif
88} FILINFO;
89
90
91
92/* File function return code (FRESULT) */
93
94typedef enum {
95 FR_OK = 0, /* (0) Succeeded */
96 FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
97 FR_NOT_READY, /* (2) The physical drive cannot work */
98 FR_NO_FILE, /* (3) Could not find the file */
99 FR_NO_PATH, /* (4) Could not find the path */
100 FR_INVALID_NAME, /* (5) The path name format is invalid */
101 FR_NOT_OPENED, /* (6) */
102 FR_NOT_ENABLED, /* (7) */
103 FR_NO_FILESYSTEM, /* (8) There is no valid FAT volume */
104} FRESULT;
105
106
107
108/*--------------------------------------------------------------*/
109/* Petit FatFs module application interface */
110
111FRESULT pf_mount (FATFS* fs); /* Mount/Unmount a logical drive */
112FRESULT pf_open (FATFS* fs, const char* path); /* Open a file */
113FRESULT pf_read (FATFS* fs, void* buff, UINT btr, UINT* br); /* Read data from the open file */
114FRESULT pf_write (FATFS* fs, const void* buff, UINT btw, UINT* bw); /* Write data to the open file */
115FRESULT pf_lseek (FATFS* fs, DWORD ofs); /* Move file pointer of the open file */
116FRESULT pf_opendir (DIR* dj, const char* path); /* Open a directory */
117FRESULT pf_readdir (DIR* dj, FILINFO* fno); /* Read a directory item from the open directory */
118
119
120
121/*--------------------------------------------------------------*/
122/* Flags and offset address */
123
124/* File status flag (FATFS.flag) */
125
126#define FA_OPENED 0x01
127#define FA_WPRT 0x02
128#define FA__WIP 0x40
129
130
131/* FAT sub type (FATFS.fs_type) */
132
133#define FS_FAT12 1
134#define FS_FAT16 2
135#define FS_FAT32 3
136
137
138/* File attribute bits for directory entry */
139
140#define AM_RDO 0x01 /* Read only */
141#define AM_HID 0x02 /* Hidden */
142#define AM_SYS 0x04 /* System */
143#define AM_VOL 0x08 /* Volume label */
144#define AM_LFN 0x0F /* LFN entry */
145#define AM_DIR 0x10 /* Directory */
146#define AM_ARC 0x20 /* Archive */
147#define AM_MASK 0x3F /* Mask of defined bits */
148
149
150/*--------------------------------*/
151/* Multi-byte word access macros */
152
153#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
154#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
155#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
156#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
157#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
158#else /* Use byte-by-byte access to the FAT structure */
159#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
160#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
161#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
162#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)
163#endif
164
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* _PFATFS */
Note: See TracBrowser for help on using the repository browser.