source: uKadecot/trunk/pfatfs/pff.h

Last change on this file was 154, checked in by coas-nagasima, 8 years ago

SDカードの中身を/~/でアクセスできるよう変更

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