fatfs v0.10 Oct 02,2013:

- Added selection of character encoding on the file. (_STRF_ENCODE)
- Added f_closedir().
- Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
- Added forced mount feature with changes of f_mount().
- Improved behavior of volume auto detection.
- Improved write throughput of f_puts() and f_printf().
- Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
- Fixed f_write() can be truncated when the file size is close to 4GB.
- Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
This commit is contained in:
savelij13 committed 2025-09-11 09:58:52 +03:00
1 parent 750225eb33
commit f9a05f6eda
83 files changed
+1636 -1121

No files matched your search

+53 -20
View File
@@ -16,7 +16,7 @@
<p>The f_open function creates a <em>file object</em> to be used to access the file.</p>
<pre>
FRESULT f_open (
FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] File object structure */</span>
FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] Pointer to the file object structure */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] File name */</span>
BYTE <span class="arg">mode</span> <span class="c">/* [IN] Mode flags */</span>
);
@@ -27,7 +27,7 @@ FRESULT f_open (
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the file object structure to be created.</dd>
<dd>Pointer to the blank file object structure to be created.</dd>
<dt>path</dt>
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to create or open.</dd>
<dt>mode</dt>
@@ -87,35 +87,66 @@ To append data to the file, use <a href="lseek.html"><tt>f_lseek()</tt></a> func
<div class="para use">
<h4>Example (File Copy)</h4>
<h4>Example</h4>
<pre>
void main (void)
<span class="c">/* Read a text file and display it */</span>
FATFS FatFs; <span class="c">/* Work area (file system object) for logical drive */</span>
int main (void)
{
FIL fil; <span class="c">/* File object */</span>
char line[82]; <span class="c">/* Line buffer */</span>
FRESULT fr; <span class="c">/* FatFs return code */</span>
<span class="c">/* Register work area to the default drive */</span>
f_mount(&amp;FatFs, "", 0);
<span class="c">/* Open a text file */</span>
fr = f_open(&fil, "message.txt", FA_READ);
if (fr) return (int)fr;
<span class="c">/* Read all lines and display it */</span>
while (f_gets(line, sizeof line, &fil))
printf(line);
<span class="c">/* Close the file */</span>
f_close(&fil);
return 0;
}
</pre>
<pre>
<span class="c">/* Copy a file "file.bin" on the drive 1 to drive 0 */</span>
int main (void)
{
FATFS fs[2]; <span class="c">/* Work area (file system object) for logical drives */</span>
FIL fsrc, fdst; <span class="c">/* file objects */</span>
BYTE buffer[4096]; <span class="c">/* file copy buffer */</span>
FRESULT res; <span class="c">/* FatFs function common result code */</span>
FIL fsrc, fdst; <span class="c">/* File objects */</span>
BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>
FRESULT fr; <span class="c">/* FatFs function common result code */</span>
UINT br, bw; <span class="c">/* File read/write count */</span>
<span class="c">/* Register work area for each volume (Always succeeds regardless of disk status) */</span>
f_mount(0, &amp;fs[0]);
f_mount(1, &amp;fs[1]);
<span class="c">/* Register work area for each logical drive */</span>
f_mount(&amp;fs[0], "0:", 0);
f_mount(&amp;fs[1], "1:", 0);
<span class="c">/* Open source file on the drive 1 */</span>
res = f_open(&amp;fsrc, "1:srcfile.dat", FA_OPEN_EXISTING | FA_READ);
if (res) die(res);
fr = f_open(&amp;fsrc, "1:file.bin", FA_OPEN_EXISTING | FA_READ);
if (fr) return (int)fr;
<span class="c">/* Create destination file on the drive 0 */</span>
res = f_open(&amp;fdst, "0:dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (res) die(res);
fr = f_open(&amp;fdst, "0:file.bin", FA_CREATE_ALWAYS | FA_WRITE);
if (fr) return (int)fr;
<span class="c">/* Copy source to destination */</span>
for (;;) {
res = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of src file */</span>
if (res || br == 0) break; <span class="c">/* error or eof */</span>
res = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* Write it to the dst file */</span>
if (res || bw &lt; br) break; <span class="c">/* error or disk full */</span>
fr = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of source file */</span>
if (fr || br == 0) break; <span class="c">/* error or eof */</span>
fr = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* Write it to the destination file */</span>
if (fr || bw &lt; br) break; <span class="c">/* error or disk full */</span>
}
<span class="c">/* Close open files */</span>
@@ -123,8 +154,10 @@ void main (void)
f_close(&amp;fdst);
<span class="c">/* Unregister work area prior to discard it */</span>
f_mount(0, NULL);
f_mount(1, NULL);
f_mount(NULL, "0:", 0);
f_mount(NULL, "1:", 0);
return (int)fr;
}
</pre>
</div>