?? ff.lst
字號:
C51 COMPILER V8.08 FF 10/31/2008 14:44:16 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE FF
OBJECT MODULE PLACED IN .\ff.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\src\ff.c BROWSE DEBUG OBJECTEXTEND PRINT(.\ff.lst) OBJECT(.\ff.obj)
line level source
1 /*----------------------------------------------------------------------------/
2 / FatFs - FAT file system module R0.06 (C)ChaN, 2008
3 /-----------------------------------------------------------------------------/
4 / The FatFs module is an experimenal project to implement FAT file system to
5 / cheap microcontrollers. This is a free software and is opened for education,
6 / research and development under license policy of following trems.
7 /
8 / Copyright (C) 2008, ChaN, all right reserved.
9 /
10 / * The FatFs module is a free software and there is no warranty.
11 / * You can use, modify and/or redistribute it for personal, non-profit or
12 / commercial use without restriction under your responsibility.
13 / * Redistributions of source code must retain the above copyright notice.
14 /
15 /-----------------------------------------------------------------------------/
16 / Feb 26,'06 R0.00 Prototype.
17 /
18 / Apr 29,'06 R0.01 First stable version.
19 /
20 / Jun 01,'06 R0.02 Added FAT12 support.
21 / Removed unbuffered mode.
22 / Fixed a problem on small (<32M) patition.
23 / Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).
24 /
25 / Sep 22,'06 R0.03 Added f_rename().
26 / Changed option _FS_MINIMUM to _FS_MINIMIZE.
27 / Dec 11,'06 R0.03a Improved cluster scan algolithm to write files fast.
28 / Fixed f_mkdir() creates incorrect directory on FAT32.
29 /
30 / Feb 04,'07 R0.04 Supported multiple drive system.
31 / Changed some interfaces for multiple drive system.
32 / Changed f_mountdrv() to f_mount().
33 / Added f_mkfs().
34 / Apr 01,'07 R0.04a Supported multiple partitions on a plysical drive.
35 / Added a capability of extending file size to f_lseek().
36 / Added minimization level 3.
37 / Fixed an endian sensitive code in f_mkfs().
38 / May 05,'07 R0.04b Added a configuration option _USE_NTFLAG.
39 / Added FSInfo support.
40 / Fixed DBCS name can result FR_INVALID_NAME.
41 / Fixed short seek (<= csize) collapses the file object.
42 /
43 / Aug 25,'07 R0.05 Changed arguments of f_read(), f_write() and f_mkfs().
44 / Fixed f_mkfs() on FAT32 creates incorrect FSInfo.
45 / Fixed f_mkdir() on FAT32 creates incorrect directory.
46 / Feb 03,'08 R0.05a Added f_truncate() and f_utime().
47 / Fixed off by one error at FAT sub-type determination.
48 / Fixed btr in f_read() can be mistruncated.
49 / Fixed cached sector is not flushed when create and close
50 / without write.
51 /
52 / Apr 01,'08 R0.06 Added fputc(), fputs(), fprintf() and fgets().
53 / Improved performance of f_lseek() on moving to the same
54 / or following cluster.
55 /---------------------------------------------------------------------------*/
C51 COMPILER V8.08 FF 10/31/2008 14:44:16 PAGE 2
56
57 #include <string.h>
58 #include "ff.h" /* FatFs declarations */
59 #include "diskio.h" /* Include file for user provided disk functions */
60
61
62 /*--------------------------------------------------------------------------
63
64 Module Private Functions
65
66 ---------------------------------------------------------------------------*/
67
68 static
69 FATFS *FatFs[_DRIVES]; /* Pointer to the file system objects (logical drives) */
70 static
71 WORD fsid; /* File system mount ID */
72
73
74
75 /*-----------------------------------------------------------------------*/
76 /* Change window offset */
77 /*-----------------------------------------------------------------------*/
78
79 static
80 BOOL move_window ( /* TRUE: successful, FALSE: failed */
81 FATFS *fs, /* File system object */
82 DWORD sector /* Sector number to make apperance in the fs->win[] */
83 ) /* Move to zero only writes back dirty window */
84 {
85 1 DWORD wsect;
86 1
87 1
88 1 wsect = fs->winsect;
89 1 if (wsect != sector) { /* Changed current window */
90 2 #if !_FS_READONLY
BYTE n;
if (fs->winflag) { /* Write back dirty window if needed */
if (disk_write(fs->drive, fs->win, wsect, 1) != RES_OK)
return FALSE;
fs->winflag = 0;
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to FAT copy */
wsect += fs->sects_fat;
disk_write(fs->drive, fs->win, wsect, 1);
}
}
}
#endif
104 2 if (sector) {
105 3 if (disk_read(fs->drive, fs->win, sector, 1) != RES_OK)
106 3 return FALSE;
107 3 fs->winsect = sector;
108 3 }
109 2 }
110 1 return TRUE;
111 1 }
112
113
114
115
116 /*-----------------------------------------------------------------------*/
117 /* Clean-up cached data */
C51 COMPILER V8.08 FF 10/31/2008 14:44:16 PAGE 3
118 /*-----------------------------------------------------------------------*/
119
120 #if !_FS_READONLY
static
FRESULT sync ( /* FR_OK: successful, FR_RW_ERROR: failed */
FATFS *fs /* File system object */
)
{
fs->winflag = 1;
if (!move_window(fs, 0)) return FR_RW_ERROR;
#if _USE_FSINFO
/* Update FSInfo sector if needed */
if (fs->fs_type == FS_FAT32 && fs->fsi_flag) {
fs->winsect = 0;
memset(fs->win, 0, 512);
ST_WORD(&fs->win[BS_55AA], 0xAA55);
ST_DWORD(&fs->win[FSI_LeadSig], 0x41615252);
ST_DWORD(&fs->win[FSI_StrucSig], 0x61417272);
ST_DWORD(&fs->win[FSI_Free_Count], fs->free_clust);
ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust);
disk_write(fs->drive, fs->win, fs->fsi_sector, 1);
fs->fsi_flag = 0;
}
#endif
/* Make sure that no pending write process in the physical drive */
if (disk_ioctl(fs->drive, CTRL_SYNC, NULL) != RES_OK)
return FR_RW_ERROR;
return FR_OK;
}
#endif
148
149
150
151
152 /*-----------------------------------------------------------------------*/
153 /* Get a cluster status */
154 /*-----------------------------------------------------------------------*/
155
156 static
157 DWORD get_cluster ( /* 0,>=2: successful, 1: failed */
158 FATFS *fs, /* File system object */
159 DWORD clust /* Cluster# to get the link information */
160 )
161 {
162 1 WORD wc, bc;
163 1 DWORD fatsect;
164 1
165 1
166 1 if (clust >= 2 && clust < fs->max_clust) { /* Is it a valid cluster#? */
167 2 fatsect = fs->fatbase;
168 2 switch (fs->fs_type) {
169 3 case FS_FAT12 :
170 3 bc = (WORD)clust * 3 / 2;
171 3 if (!move_window(fs, fatsect + (bc / SS(fs)))) break;
172 3 wc = fs->win[bc & (SS(fs) - 1)]; bc++;
173 3 if (!move_window(fs, fatsect + (bc / SS(fs)))) break;
174 3 wc |= (WORD)fs->win[bc & (SS(fs) - 1)] << 8;
175 3 return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
176 3
177 3 case FS_FAT16 :
178 3 if (!move_window(fs, fatsect + (clust / (SS(fs) / 2)))) break;
179 3 return LD_WORD(&fs->win[((WORD)clust * 2) & (SS(fs) - 1)]);
C51 COMPILER V8.08 FF 10/31/2008 14:44:16 PAGE 4
180 3
181 3 case FS_FAT32 :
182 3 if (!move_window(fs, fatsect + (clust / (SS(fs) / 4)))) break;
183 3 return LD_DWORD(&fs->win[((WORD)clust * 4) & (SS(fs) - 1)]) & 0x0FFFFFFF;
184 3 }
185 2 }
186 1
187 1 return 1; /* Out of cluster range, or an error occured */
188 1 }
189
190
191
192
193 /*-----------------------------------------------------------------------*/
194 /* Change a cluster status */
195 /*-----------------------------------------------------------------------*/
196
197 #if !_FS_READONLY
static
BOOL put_cluster ( /* TRUE: successful, FALSE: failed */
FATFS *fs, /* File system object */
DWORD clust, /* Cluster# to change (must be 2 to fs->max_clust-1) */
DWORD val /* New value to mark the cluster */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -