fatfs v0.06 Apr 01, 2008:

- Added f_forward(). (Tiny-FatFs)
- Added string functions: fputc(), fputs(), fprintf() and fgets().
- Improved performance of f_lseek() on move to the same or following cluster.
This commit is contained in:
savelij13 committed 2025-09-11 09:17:24 +03:00
1 parent e400c8c902
commit b94c8f3bf3
72 files changed
+1804 -536

No files matched your search

+17 -17
View File
@@ -24,24 +24,24 @@ These correspondence are defined in integer.h. This will not be a problem on mos
</div>
<div class="para">
<h3>Memory Usage (R0.05a)</h3>
<h3>Memory Usage (R0.06)</h3>
<p>These are the memory usage on some target systems. The memory sizes are in unit of byte, D means number of logical drives and F means number of open files. All samples are optimezed in code size.</p>
<table class="lst2">
<tr><th></th><th>AVR</th><th>H8/300H</th><th>PIC</th><th>MSP430</th><th>TLCS-870/C</th><th>V850ES</th><th>SH2</th></tr>
<tr><td>Compiler</td><td>gcc</td><td>CH38</td><td>C30(gcc)</td><td>CL430</td><td>CC870C</td><td>CA850</td><td>SHC</td></tr>
<tr><td>_MCU_ENDIAN</td><td>1</td><td>2</td><td>2</td><td>2</td><td>1</td><td>1</td><td>2</td></tr>
<tr class="lst3"><td>FatFs Code<br>(Full, R/W)</td><td>9146</td><td>9218</td><td>9155</td><td></td><td></td><td>6662</td><td>7430</td></tr>
<tr><td>FatFs Code<br>(Minimum, R/W)</td><td>5824</td><td>5756</td><td>5861</td><td></td><td></td><td>4096</td><td>4710</td></tr>
<tr><td>FatFs Code<br>(Full, R/O)</td><td>4268</td><td>4116</td><td>4187</td><td></td><td></td><td>2986</td><td>3382</td></tr>
<tr><td>FatFs Code<br>(Minimum, R/O)</td><td>3076</td><td>3134</td><td>3143</td><td></td><td></td><td>2200</td><td>2610</td></tr>
<tr><td>FatFs Work (Static)</td><td>D*2+2</td><td>D*4+2</td><td>D*2+2</td><td></td><td></td><td>D*4+2</td><td>D*4+2</td></tr>
<tr><td>FatFs Work (Dynamic)</td><td>D*554+F*544</td><td>D*554+F*550</td><td>D*554+F*544</td><td></td><td></td><td>D*554+F*550</td><td>D*554+F*550</td></tr>
<tr class="lst3"><td>Tiny-FatFs Code<br>(Full, R/W)</td><td>7566</td><td>7626</td><td>7371</td><td>6894</td><td>9314</td><td>5926</td><td>6580</td></tr>
<tr><td>Tiny-FatFs Code<br>(Minimum, R/W)</td><td>4730</td><td>4814</td><td>4683</td><td>4306</td><td>6285</td><td>3670</td><td>4236</td></tr>
<tr><td>Tiny-FatFs Code<br>(Full, R/O)</td><td>3564</td><td>3532</td><td>3522</td><td>3226</td><td>4389</td><td>2678</td><td>3022</td></tr>
<tr><td>Tiny-FatFs Code<br>(Minimum, R/O)</td><td>2554</td><td>2674</td><td>2595</td><td>2372</td><td>3376</td><td>1856</td><td>2300</td></tr>
<tr><td>Tiny-FatFs Wrok (Static)</td><td>4</td><td>6</td><td>4</td><td>4</td><td>4</td><td>6</td><td>6</td></tr>
<tr><td>Tiny-FatFs Work (Dynamic)</td><td>544+F*28</td><td>544+F*32</td><td>544+F*28</td><td>544+F*28</td><td>544+F*28</td><td>544+F*32</td><td>544+F*32</td></tr>
<tr><th></th><th>AVR</th><th>H8/300H</th><th>PIC</th><th>MSP430</th><th>TLCS-870/C</th><th>V850ES</th><th>SH2</th><th>ARM7</th></tr>
<tr><td>Compiler</td><td>gcc(WinAVR)</td><td>CH38</td><td>gcc(C30)</td><td>CL430</td><td>CC870C</td><td>CA850</td><td>SHC</td><td>gcc(WinARM)</td></tr>
<tr><td>_MCU_ENDIAN</td><td>1</td><td>2</td><td>2</td><td>2</td><td>1</td><td>1</td><td>2</td><td>2</td></tr>
<tr class="lst3"><td>FatFs Code (Full, R/W)</td><td>9280</td><td>9348</td><td>9387</td><td></td><td></td><td>6728</td><td>7538</td><td>11820</td></tr>
<tr><td>FatFs Code (Min, R/W)</td><td>5814</td><td>5798</td><td>5913</td><td></td><td></td><td>4094</td><td>4742</td><td></td></tr>
<tr><td>FatFs Code (Full, R/O)</td><td>4402</td><td>4236</td><td>4371</td><td></td><td></td><td>3054</td><td>3474</td><td></td></tr>
<tr><td>FatFs Code (Min, R/O)</td><td>3066</td><td>3158</td><td>3213</td><td></td><td></td><td>2172</td><td>2630</td><td></td></tr>
<tr><td>FatFs Work (Static)</td><td>D*2+2</td><td>D*4+2</td><td>D*2+2</td><td></td><td></td><td>D*4+2</td><td>D*4+2</td><td></td></tr>
<tr><td>FatFs Work (Dynamic)</td><td>D*554+F*544</td><td>D*554+F*550</td><td>D*554+F*544</td><td></td><td></td><td>D*554+F*550</td><td>D*554+F*550</td><td>D*554+F*550</td></tr>
<tr class="lst3"><td>Tiny-FatFs Code (Full, R/W)</td><td>7628</td><td>7668</td><td>7560</td><td>7108</td><td>9501</td><td>5978</td><td>6640</td><td></td></tr>
<tr><td>Tiny-FatFs Code (Min, R/W)</td><td>4684</td><td>4820</td><td>4698</td><td>4390</td><td>6322</td><td>3678</td><td>4236</td><td></td></tr>
<tr><td>Tiny-FatFs Code (Full, R/O)</td><td>3634</td><td>3600</td><td>3618</td><td>3382</td><td>4554</td><td>2722</td><td>3072</td><td></td></tr>
<tr><td>Tiny-FatFs Code (Min, R/O)</td><td>2524</td><td>2700</td><td>2601</td><td>2398</td><td>3390</td><td>1862</td><td>2300</td><td></td></tr>
<tr><td>Tiny-FatFs Wrok (Static)</td><td>4</td><td>6</td><td>4</td><td>4</td><td>4</td><td>6</td><td>6</td><td></td></tr>
<tr><td>Tiny-FatFs Work (Dynamic)</td><td>544+F*28</td><td>544+F*32</td><td>544+F*28</td><td>544+F*28</td><td>544+F*28</td><td>544+F*32</td><td>544+F*32</td><td>544+F*32</td></tr>
</table>
</div>
@@ -111,7 +111,7 @@ Currently the file object structure is held by application layer. This is not a
<li>Efficient sector buffer management<br>
The FatFs module has only one sector buffer per logical drive. There is an ineffciency on random file access with many files simultanesously. When additional memory for the sector buffer is available, the file access performance will able to be improved with an advanced cache mechanism.</li>
<li>Long file name<br>
There is an extended feature to handle long file name (LFN) up to 255 characters, in addition to 8.3 format file name, on FAT file system. To support this, 512 byte string buffer for file name and UCS-2 - Shift_JIS mutual conversion table are required. Therefore memory consumption of code and work area will be increased drastically. The FatFs module does not support this feature. The LFN on the FAT file system is a patent of Microsoft. When support it on the commercial products, you have to be licensed.</li>
There is an extended feature to handle long file name (LFN) up to 255 characters in addition to 8.3 format file name on the FAT file system. To support this feature, 512 byte string buffer for file name and Unicode - Local code mutual conversion table which occupies 256KB is required. Therefore memory consumption of code and work area will be increased drastically. The FatFs module currently does not support this feature. The LFN on the FAT file system is a patent of Microsoft. When use it on the commercial products, you have to be licensed.</li>
<li>Porting to RTOS<br>
When use FatFs module from only one task, no consideration is needed. However when make access to a logical drive from two or more tasks simultanesously, any exclusion control will be required. The FatFs module is also ported to a free RTOS based on &mu;ITRON by <a href="http://www.toppers.jp/en/index.html">TOPPERS Project</a>.</li>
</ul>
+6 -6
View File
@@ -23,18 +23,18 @@ FRESULT f_chmod (
</div>
<div class="para">
<h4>Parameter</h4>
<h4>Parameters</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be changed</dd>
<dt>Attribute</dt>
<dd>Attribute flags to be set in one or more combination of the following flags. The specified flags are set and others are cleard.<br>
<table class="lst">
<tr><th>Attribute</th><th>Description</th></td>
<tr><td>AM_RDO</td><td>Read only</td></td>
<tr><td>AM_ARC</td><td>Archive</td></td>
<tr><td>AM_SYS</td><td>System</td></td>
<tr><td>AM_HID</td><td>Hidden</td></td>
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td>AM_RDO</td><td>Read only</td></tr>
<tr><td>AM_ARC</td><td>Archive</td></tr>
<tr><td>AM_SYS</td><td>System</td></tr>
<tr><td>AM_HID</td><td>Hidden</td></tr>
</table>
</dd>
<dt>AttributeMask</dt>
+1 -1
View File
@@ -21,7 +21,7 @@ DSTATUS disk_initialize (
</div>
<div class="para">
<h4>Parameters</h4>
<h4>Parameter</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to initialize.</dd>
+3 -2
View File
@@ -53,9 +53,10 @@ DRESULT disk_ioctl (
<div class="para">
<h4>Description</h4>
<p>The FatFs module uses only device independent commands described below. Any device dependent function is not used.</p>
<p>In read-only configuration, the disk_ioctl function is not needed.</p>
<table class="lst">
<tr><th>Command</th><th>Description</td></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the disk drive has finished pending write process. When the disk I/O module has a write back cache, flush the dirty sector immediately. In read-only configuration, this command is not needed.</td></tr>
<tr><th>Command</th><th>Description</th></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the disk drive has finished pending write process. When the disk I/O module has a write back cache, flush the dirty sector immediately.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Returns total sectors on the drive into the DWORD variable pointed by Buffer. This command is used in only f_mkfs function.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the memory array in unit of sector into the DWORD variable pointed by Buffer. When the erase block size is unknown or magnetic disk device, return 1. This command is used in only f_mkfs function.</td></tr>
</table>
+2 -2
View File
@@ -17,7 +17,7 @@
DRESULT disk_read (
BYTE <em>Drive</em>, /* Physical drive number */
BYTE* <em>Buffer</em>, /* Pointer to the read data buffer */
DWORD <em>SectorNumber</em>, /* Sector number to read from */
DWORD <em>SectorNumber</em>, /* Start sector number */
BYTE <em>SectorCount</em> /* Number of sectros to read */
);
</pre>
@@ -44,7 +44,7 @@ DRESULT disk_read (
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any error occured during the read operation.</dd>
<dd>Any hard error occured during the read operation and could not recover it.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
+2 -2
View File
@@ -21,7 +21,7 @@ DSTATUS disk_status (
</div>
<div class="para">
<h4>Parameters</h4>
<h4>Parameter</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to be confirmed.</dd>
@@ -34,7 +34,7 @@ DSTATUS disk_status (
<p>The disk status is returned in combination of following flags.</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>Indicates that the disk drive has not been initialiezed. This flag is set on: system reset, disk removal and disk_initialize function failed, and cleared on: disk_initialize function succeeded.</dd>
<dd>Indicates that the disk drive has not been initialized. This flag is set on: system reset, disk removal and disk_initialize function failed, and cleared on: disk_initialize function succeeded.</dd>
<dt>STA_NODISK</dt>
<dd>Indicates that no medium in the drive. This is always cleared on fixed disk drive.</dd>
<dt>STA_PROTECTED</dt>
+2 -2
View File
@@ -30,7 +30,7 @@ DRESULT disk_write (
<dd>Specifies the physical drive number.</dd>
<dt>Buffer</dt>
<dd>Pointer to the data to be written.</dd>
<dt>SectorNumber</dd>
<dt>SectorNumber</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dt>SectorCount</dt>
<dd>Specifies the number of sectors to write. The value can be 1 to 255.</dd>
@@ -44,7 +44,7 @@ DRESULT disk_write (
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any error occured during the write operation.</dd>
<dd>Any hard error occured during the write operation and could not recover it.</dd>
<dt>RES_WRPRT</dt>
<dd>The disk is write protected.</dd>
<dt>RES_PARERR</dt>
+2 -2
View File
@@ -12,7 +12,7 @@
<div class="para">
<h2>File and Path name on the FatFs module</h2>
<p>The format of file and path name on the FatFs module is similer to MS-DOS. However it does not have a concept of current directory, all objects on the drive are specified in full path name from the root directory.</p>
<p>The format of file and path name on the FatFs module is similer to MS-DOS. However it does not have a concept of current directory like OS oriented file system. All objects on the drive are specified in full path name from the root directory.</p>
<pre>
"[<em>drive#</em>:][/]<em>directory</em>/<em>file</em>"
@@ -28,7 +28,7 @@
</pre>
<p>The FatFs module supports only 8.3 format file name and long file name is currentry not supported. For directory separator, a '/' is used, not a '\'. Heading '/' is ignored and can be omitted.</p>
<p>The logical drive number is specified in a numeral with a colon. When the drive number is omitted, it means the default drive (0). As for the Tiny-FatFs, it has only one logical drive and always works as drive 0. Any drive number cannot be contained in the path name.</p>
<p>The logical drive number is specified in a numeral with a colon. When the drive number is omitted, it is assumed default drive (0:). As for the Tiny-FatFs, it has only one logical drive and always works as drive 0. Any drive number cannot be contained in the path name.</p>
</div>
<p><br></p>
+135
View File
@@ -0,0 +1,135 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_forward</title>
</head>
<body>
<div class="para">
<h2>f_forward</h2>
<p>The f_forward function reads the file data and forward it to the data streaming device.</p>
<pre>
FRESULT f_forward (
FIL* <em>FileObject</em>, /* File object */
UINT (*<em>Func</em>)(const BYTE*,UINT), /* Data streaming function */
UINT <em>ByteToFwd</em>, /* Number of bytes to forward */
UINT* <em>ByteFwd</em> /* Number of bytes forwarded */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the open file object.</dd>
<dt>Func</dt>
<dd>Pointer to the user-defined data streaming function. For details, refer to the sample code.</dd>
<dt>ByteToFwd</dt>
<dd>Number of bytes to forward in range of UINT.</dd>
<dt>ByteFwd</dt>
<dd>Pointer to the UINT variable to return number of bytes forwarded.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_DENIED</dt>
<dd>The function denied due to the file has been opened in non-read mode.</dd>
<dt>FR_RW_ERROR</dt>
<dd>The function failed due to a disk error or an internal error.</dd>
<dt>FR_NOT_READY</dt>
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The f_forward() is for only Tiny-FatFs and not supported on FatFs. It reads the data from the file and forward it to the outgoing stream without data buffer. This is suitable for small memory system because it does not require any data buffer at application module. The file pointer of the file object increases in number of bytes forwarded. In case of <tt>*ByteFwd &lt; ByteToFwd</tt> without error, it means the requested bytes could not be transferred due to end of file or stream goes busy during transfering process.</p>
<p>This function is available when <tt>_USE_FORWARD == 1</tt>.</p>
</div>
<div class="para">
<h4>Example (Audio playback)</h4>
<pre>
/*-----------------------------------------------------------------------*/
/* Sample code of data transfer function to be called from f_forward */
/*-----------------------------------------------------------------------*/
UINT out_stream ( /* Returns number of bytes sent or stream status */
const BYTE *p, /* Pointer to the data block to be sent */
UINT btf /* &gt;0: Transfer call (Number of bytes to be sent). 0: Sense call */
)
{
UINT cnt = 0;
if (btf == 0) { /* Sense call */
/* Return stream status (0: Busy, 1: Ready) */
/* When once it returned ready to sense call, it must accept a byte at least */
/* at subsequent transfer call, or f_forward will result FR_RW_ERROR. */
if (FIFO_READY) cnt = 1;
}
else { /* Transfer call */
do { /* Repeat while there is any data to be sent and the stream is ready */
FIFO_PORT = *p++;
cnt++;
} while (cnt &lt; btf &amp;&amp; FIFO_READY);
}
return cnt;
}
/*-----------------------------------------------------------------------*/
/* Sample code using f_forward function */
/*-----------------------------------------------------------------------*/
FRESULT play_file (
char *fn /* Pointer to the audio file name to be played */
)
{
FRESULT rc;
FIL fil;
UINT dmy;
/* Open the audio file in read only mode */
rc = f_open(&amp;fil, fn, FA_READ);
/* Repeat until the file pointer reaches end of the file */
while (rc == FR_OK &amp;&amp; fil.fptr &lt; fil.fsize) {
/* any other processes... */
/* Fill output stream periodicaly or on-demand */
rc = f_forward(&amp;fil, out_stream, 1000, &amp;dmy);
}
/* The read-only file object may be discarded without close */
return rc;
}
</pre>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
+4 -4
View File
@@ -56,7 +56,7 @@ FRESULT f_getfree (
<div class="para">
<h4>Descriptions</h4>
<p>The f_getfree function gets number of free clusters on the drive. The <tt>sects_clust</tt> member in the file system object is refreting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. When <tt>_USE_FSINFO</tt> option is enabled, this function might return an inaccurate free cluster count on FAT32 volume. When it is disabled, this function will take a time on FAT32 volume.</p>
<p>The f_getfree function gets number of free clusters on the drive. The member <tt>csize</tt> in the file system object is refreting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. When <tt>_USE_FSINFO</tt> option is enabled, this function might return an inaccurate free cluster count on FAT32 volume. When it is disabled, this function will take a time on FAT32 volume.</p>
<p>This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
</div>
@@ -69,14 +69,14 @@ FRESULT f_getfree (
// Get free clusters
res = f_getfree("", &clust, &fs);
res = f_getfree("", &amp;clust, &amp;fs);
if (res) die(res);
// Get free space
printf("%lu KB total disk space.\n"
"%lu KB available on the disk.\n",
(DWORD)(fs->max_clust - 2) * fs->sects_clust / 2,
clust * fs->sects_clust / 2);
(DWORD)(fs->max_clust - 2) * fs->csize / 2,
clust * fs->csize / 2);
</pre>
</div>
+58
View File
@@ -0,0 +1,58 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - fgets</title>
</head>
<body>
<div class="para">
<h2>fgets</h2>
<p>The fgets reads a string from the file.</p>
<pre>
char* fgets (
char* <em>Str</em>, /* Read buffer */
int <em>Size</em>, /* Size of the read buffer */
FIL* <em>FileObject</em> /* File object */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Str</dt>
<dd>Pointer to read buffer to store the read string.</dd>
<dt>Size</dt>
<dd>Size of the read buffer.</dd>
<dt>FileObject</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<p>When the function succeeded, <tt>Str</tt> will be returuned.</p>
</div>
<div class="para">
<h4>Description</h4>
<p>The fgets() is a wrapper function of <a href="read.html">f_read()</a>. The read operation continues until a <tt>'\n'</tt> is stored, reached end of file or buffer is filled with Size - 1 characters. The read string is terminated with a <tt>'\0'</tt>. When the file is already reached end of file or any error occured during read operation, fgets() returns a <tt>NULL</tt>. The EOF status can be examined with <tt>feof()</tt> macro.</p>
<p>This function is available when <tt>_USE_STRFUNC</tt> is 1 or 2. When it is set to 2, <tt>'\r'</tt> contained in the file is stripped.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
+5 -5
View File
@@ -50,7 +50,7 @@ FRESULT f_lseek (
<div class="para">
<h4>Description</h4>
<p>The f_lseek function moves the file R/W pointer of an open file. The offset can be specified in only origin from top of the file. When an offset above the file size is specified in write mode, the file size is extended to the offset and the data in the extended area is undefined. This is suitable to create a large file quickly, for fast write operation without cluster allocation delay. After the f_lseek function succeeded, member fptr in the file object should be checked in order to make sure the R/W pointer has been moved correctry. In case of fptr is less than Offset, any of the followings has been occured.</p>
<p>The f_lseek function moves the file R/W pointer of an open file. The offset can be specified in only origin from top of the file. When an offset above the file size is specified in write mode, the file size is extended to the offset and the data in the extended area is undefined. This is suitable to create a large file quickly, for fast write operation without cluster allocation delay. After the f_lseek function succeeded, member fptr in the file object should be checked in order to make sure the R/W pointer has been moved correctry. In case of fptr is less than expected value, any of the followings has been occured.</p>
<ul>
<li>In read-only mode, the Offset was clipped in file size.</li>
<li>The drive gets full during the file extending process.</li>
@@ -63,16 +63,16 @@ FRESULT f_lseek (
<h4>Example</h4>
<pre>
// Move to offset of 5000 from top of the file.
res = f_lseek(&file, 5000);
res = f_lseek(&amp;file, 5000);
// Forward 3000 bytes
res = f_lseek(&file, file.fptr + 3000);
res = f_lseek(&amp;file, file.fptr + 3000);
// Rewind 2000 bytes (take care on overflow)
res = f_lseek(&file, file.fptr - 2000);
res = f_lseek(&amp;file, file.fptr - 2000);
// Move to end of the file to append data
res = f_lseek(&file, file.fsize);
res = f_lseek(&amp;file, file.fsize);
</pre>
</div>
-2
View File
@@ -61,8 +61,6 @@ FRESULT f_mkdir (
<div class="para">
<h4>Description</h4>
<p>The f_mkdir function creates a new directory. This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
<p>
</p>
</div>
+4 -4
View File
@@ -30,7 +30,7 @@ FRESULT f_mkfs (
<dt>PartitioningRule</dt>
<dd>When 0 is given, a partition table is created into first sector on the drive and then the file system is created on the partition. This is called FDISK format. When 1 is given, the file system starts from the first sector without partition table. This is often called super floppy (SFD) format.</dd>
<dt>AllocSize</dt>
<dd>Specifies allocation unit size (number of bytes per cluster). The value must be power of 2 in range of from 512 to 32768.</dd>
<dd>Specifies allocation unit size in number of bytes per cluster. The value must be power of 2 in range of from 512 to 32768. FAT64 (64KB/cluster on FAT16) is not supported.</dd>
</dl>
</div>
@@ -62,9 +62,9 @@ FRESULT f_mkfs (
<div class="para">
<h4>Description</h4>
<p>The f_mkfs function creates a FAT file system on the drive. There are two partitioning rules, FDISK and SFD, for removable media. It can be selected with an argument. The FDISK format is recommended for most case. This function currently does not support multiple partition, so that existing partitions on the physical dirve will be deleted and re-created a partition occupies entire disk space.</p>
<p>The FAT sub-type, FAT12/FAT16/FAT32, is determined by only how many clusters on the drive and nothing else, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the drive size and specified cluster size. The cluster size affects performance of file system and large cluster increases the performance, so that 32768 bytes per cluster is recommended for most case except for small drive.</p>
<p>This function is supported on only FatFs with _USE_MKFS option.<p>
<p>The f_mkfs function creates a FAT file system on the drive. There are two partitioning rules, FDISK and SFD, for removable media. It can be selected with an argument. The FDISK format is recommended for most case. This function currently <em>does not support multiple partition</em>, so that existing partitions on the physical dirve will be deleted and re-created a new partition occupies entire disk space.</p>
<p>The FAT sub-type, FAT12/FAT16/FAT32, is determined by number of clusters on the drive and nothing else, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the drive size and the specified cluster size. The cluster size affects performance of file system and large cluster increases the performance, so that 32768 bytes per cluster is recommended for most case except for small drive.</p>
<p>This function is supported on only FatFs with _USE_MKFS option.</p>
</div>
+2 -2
View File
@@ -44,8 +44,8 @@ FRESULT f_mount (
<div class="para">
<h4>Description</h4>
<p>The f_mount function registers/unregisters a work area to the FatFs module. The work area must be given to the logical drive with this function before any other file function. To unregister a work area, specify a NULL to the <em>FileSystemObject</em>, and then the work area can be discarded.</p>
<p>This function only initializes the work area and registers its address to the internal table, any access to the disk I/O layer does not occure. The actual mounting process is performed depends on requirement in any other file funcitons with path name.<p>
<p>The f_mount function registers/unregisters a work area to the FatFs module. The work area must be given to the logical drive with this function prior to any other file function. To unregister a work area, specify a NULL to the <em>FileSystemObject</em>, and then the work area can be discarded.</p>
<p>This function only initializes the given work area and registers its address to the internal table, any access to the disk I/O layer does not occure. The volume mount process is performed on first file access after f_mount or media change.</p>
</div>
+8 -8
View File
@@ -81,7 +81,7 @@ FRESULT f_open (
<div class="para">
<h4>Description</h4>
<p>The created file object is used for subsequent calls to refer to the file. When close an open file object, use <a href="close.html">f_close</a> function. If modified file is not closed correctly, the file will be collapsed.</p>
<p>The created file object is used for subsequent calls to refer to the file. When close an open file object, use <a href="close.html">f_close</a> function. If modified file is not closed correctly, the file may be collapsed.</p>
<p>Before using any file function, a work area (file system object) must be given to the logical drive with <a href="mount.html">f_mount</a> function. All file functions can work after this procedure.</p>
<p>The mode flags, <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_CREATE_NEW, FA_OPEN_ALWAYS</tt>, are not supported in read-only configuration.</p>
</div>
@@ -100,27 +100,27 @@ void main ()
// Register a work area for logical drive 0
f_mount(0, &fs);
f_mount(0, &amp;fs);
// Open source file
res = f_open(&fsrc, "srcfile.dat", FA_OPEN_EXISTING | FA_READ);
res = f_open(&amp;fsrc, "srcfile.dat", FA_OPEN_EXISTING | FA_READ);
if (res) die(res);
// Create destination file
res = f_open(&fdst, "dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
res = f_open(&amp;fdst, "dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (res) die(res);
// Copy source to destination
for (;;) {
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
res = f_read(&amp;fsrc, buffer, sizeof(buffer), &amp;br);
if (res || br == 0) break; // error or eof
res = f_write(&fdst, buffer, br, &bw);
res = f_write(&amp;fdst, buffer, br, &amp;bw);
if (res || bw &lt; br) break; // error or disk full
}
// Close all files
f_close(&fsrc);
f_close(&fdst);
f_close(&amp;fsrc);
f_close(&amp;fdst);
// Unregister a work area before discard it
f_mount(0, NULL);
+1 -3
View File
@@ -22,7 +22,7 @@ FRESULT f_opendir (
</div>
<div class="para">
<h4>Parameter</h4>
<h4>Parameters</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>Pointer to the blank directory object to be created.</dd>
@@ -37,8 +37,6 @@ FRESULT f_opendir (
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded and the directory object is created. It is used for subsequent calls to read the directory entries.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the directory.</dd>
<dt>FR_NO_PATH</dt>
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
+72
View File
@@ -0,0 +1,72 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - fprintf</title>
</head>
<body>
<div class="para">
<h2>fprintf</h2>
<p>The fprintf function writes formatted string to the file.</p>
<pre>
int fprintf (
FIL* <em>FileObject</em>, /* File object */
const char* <em>Foramt</em>, /* Format stirng */
...
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the open file object structure.</dd>
<dt>Format</dt>
<dd>Pointer to the null-terminated format string.</dd>
<dt>...</dt>
<dd>Optional arguments.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<p>When the function succeeded, number of characters written is returned. When the function failed due to disk full or any error, an <tt>EOF</tt> will be returned.</p>
</div>
<div class="para">
<h4>Description</h4>
<p>The fprintf() is a wrapper function of <a href="putc.html">fputc()</a> and <a href="puts.html">fputs()</a>. The format control directive is a sub-set of standard library. It supports <tt>c s d u X</tt> for the data type, <tt>l</tt> for the precision and <tt>0</tt> for the flags.</p>
<p>This function is available when read-write configuration and <tt>_USE_STRFUNC</tt> is 1 or 2.</p>
</div>
<div class="para">
<h4>Example</h4>
<pre>
fprintf(&amp;fil, "%6d", -200); // " -200"
fprintf(&amp;fil, "%02u", 5); // "05"
fprintf(&amp;fil, "%ld", 12345678L); // "12345678"
fprintf(&amp;fil, "%08lX", 1194684UL); // "00123ABC"
fprintf(&amp;fil, "%s", "String"); // "String"
fprintf(&amp;fil, "%c", 'a'); // "a"
</pre>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">f_open</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="gets.html">fgets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
+54
View File
@@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - fputc</title>
</head>
<body>
<div class="para">
<h2>fputc</h2>
<p>The fputc funciton puts a character to the file.</p>
<pre>
int fputc (
int <em>Chr</em>, /* A character to put */
FIL* <em>FileObject</em> /* File object */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Chr</dt>
<dd>A character to be put.</dd>
<dt>FileObject</dt>
<dd>Pointer to the open file object structuer.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<p>When the character was written successfuly, the function returns the character. When the function failed due to disk full or any error, an <tt>EOF</tt> will be returned.</p>
</div>
<div class="para">
<h4>Description</h4>
<p>The fputc() is a wrapper function of <a href="write.html">f_write()</a>. This function is available when read-write configuration and <tt>_USE_STRFUNC</tt> is 1 or 2. When it is set 2, a <tt>'\n'</tt> is extended to <tt>"\r\n"</tt>.</p>
</div>
<div class="para">
<h4>Reference</h4>
<p><tt><a href="open.html">f_open</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="gets.html">fgets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
+54
View File
@@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - fputs</title>
</head>
<body>
<div class="para">
<h2>fputs</h2>
<p>The fputs function writes a string to the file.</p>
<pre>
int fputs (
const char* <em>Str</em>, /* String */
FIL* <em>FileObject</em> /* File object */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Str</dt>
<dd>Pointer to the null terminated string to be written. The null character will not be written.</dd>
<dt>FileObject</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para">
<h4>Return Value</h4>
<p>When the function succeeded, number of characters written (not minus value) is returned. When the function failed due to disk full or any error, an <tt>EOF</tt> will be returned.</p>
</div>
<div class="para">
<h4>Description</h4>
<p>The fputs() is a wrapper function of <a href="putc.html">fputc()</a>. This function is available when read-write configuration and <tt>_USE_STRFUNC</tt> is 1 or 2. When it is set 2, a <tt>'\n'</tt> is extended to <tt>"\r\n"</tt>.</p>
</div>
<div class="para">
<h4>Reference</h4>
<p><tt><a href="open.html">f_open</a>, <a href="putc.html">fputc</a>, <a href="printf.html">fprintf</a>, <a href="gets.html">fgets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>
+3 -3
View File
@@ -34,7 +34,7 @@ FRESULT f_read (
<dd>Number of bytes to read in range of UINT.</dd>
<dt>ByteRead</dt>
<dd>Pointer to the UINT variable to return number of bytes read.</dd>
</dt>
</dl>
</div>
@@ -57,13 +57,13 @@ FRESULT f_read (
<div class="para">
<h4>Description</h4>
<p>The file pointer in the file object increases in number of bytes read. The <tt>ByteRead</tt> will become less than <tt>ByteToRead</tt> when the read pointer reached to end of the file or any error occured during the read operation.</p>
<p>The file pointer of the file object increases in number of bytes read. After the function succeeded, <tt>*ByteRead</tt> should be checked to detect end of file. In case of <tt>*ByteRead &lt; ByteToRead</tt>, it means the R/W pointer reached end of file during read operation.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">f_open</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
<p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
+5 -5
View File
@@ -62,15 +62,15 @@ void scan_files (char* path)
DIR dirs;
int i;
if (f_opendir(&dirs, path) == FR_OK) {
if (f_opendir(&amp;dirs, path) == FR_OK) {
i = strlen(path);
while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0]) {
if (finfo.fattrib & AM_DIR) {
sprintf(&path[i], "/%s", &finfo.fname[0]);
while ((f_readdir(&amp;dirs, &amp;finfo) == FR_OK) &amp;&amp; finfo.fname[0]) {
if (finfo.fattrib &amp; AM_DIR) {
sprintf(&amp;path[i], "/%s", &amp;finfo.fname[0]);
scan_files(path);
path[i] = 0;
} else {
printf("%s/%s\n", path, &finfo.fname[0]);
printf("%s/%s\n", path, &amp;finfo.fname[0]);
}
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ FRESULT f_rename (
</div>
<div class="para">
<h4>Parameter</h4>
<h4>Parameters</h4>
<dl class="par">
<dt>OldName</dt>
<dd>Pointer to a null-terminated string specifies the old <a href="filename.html">file/directory name</a> to be renamed.</dd>
+2 -2
View File
@@ -27,7 +27,7 @@ typedef struct _FATFS {
DWORD last_clust; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */
BYTE fs_type; /* FAT type (0:Not mounted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE csize; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
BYTE drive; /* Physical drive number */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
@@ -50,7 +50,7 @@ typedef struct _FATFS {
CLUST last_clust; /* Last allocated cluster */
CLUST free_clust; /* Number of free clusters */
BYTE fs_type; /* FAT type (0:Not mounted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE csize; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
+2 -2
View File
@@ -19,7 +19,7 @@
typedef struct _FIL {
WORD id; /* Owner file system mount ID (inverted) */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
BYTE csect; /* Sector address in the cluster */
FATFS* fs; /* Pointer to the owner file system object */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
@@ -37,7 +37,7 @@ typedef struct _FIL {
typedef struct _FIL {
WORD id; /* Owner file system mount ID (inverted) */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
BYTE csect; /* Sector address in the cluster */
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
+2 -2
View File
@@ -12,7 +12,7 @@
<div class="para">
<h2>f_sync</h2>
<p>The f_sync function flushes the cached information of a wriiting file.</p>
<p>The f_sync function flushes the cached information of a writing file.</p>
<pre>
FRESULT f_sync (
FIL* <em>FileObject</em> /* Pointer to the file object */
@@ -21,7 +21,7 @@ FRESULT f_sync (
</div>
<div class="para">
<h4>Parameters</h4>
<h4>Parameter</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the open file object to be flushed.</dd>
+2 -2
View File
@@ -21,7 +21,7 @@ FRESULT f_truncate (
</div>
<div class="para">
<h4>Parameters</h4>
<h4>Parameter</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the open file object to be truncated.</dd>
@@ -48,7 +48,7 @@ FRESULT f_truncate (
<div class="para">
<h4>Description</h4>
<p>The f_truncate function truncates the file size to the current file R/W point. When the file R/W pointer is pointing end of the file, there is no effect. This function is not supported in read-only configuration and minimization level of &gt;=1.</p>
<p>The f_truncate function truncates the file size to the current file R/W point. When the file R/W pointer is already pointing end of the file, there is no effect. This function is not supported in read-only configuration and minimization level of &gt;=1.</p>
</div>
+1 -1
View File
@@ -21,7 +21,7 @@ FRESULT f_unlink (
</div>
<div class="para">
<h4>Parameters</h4>
<h4>Parameter</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be removed.</dd>
+1 -1
View File
@@ -22,7 +22,7 @@ FRESULT f_utime (
</div>
<div class="para">
<h4>Parameter</h4>
<h4>Parameters</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be changed.</dd>
+4 -3
View File
@@ -24,7 +24,7 @@ FRESULT f_write (
</div>
<div class="para">
<h4>Parameter</h4>
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the open file object structure.</dd>
@@ -57,13 +57,14 @@ FRESULT f_write (
<div class="para">
<h4>Description</h4>
<p>The read/write pointer in the file object is increased in number of bytes written. The <tt>ByteWritten</tt> will become less than <tt>ByteToWrite</tt> when the drive gets full during the write operation. This function is not supported in read-only configuration.</p>
<p>The read/write pointer in the file object is increased in number of bytes written. After the function succeeded, <tt>*ByteWritten</tt> should be checked to detect disk full. In case of <tt>*ByteWritten &lt; ByteToWrite</tt>, it means the disk got full during write operation.</p>
<p>This function is not supported in read-only configuration.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>