fatfs v0.02 Jun 01, 2006:

- Added FAT12. Removed unbuffered mode.
- Fixed a problem on small (<32M) patition.
This commit is contained in:
savelij13 committed 2025-09-11 08:53:18 +03:00
1 parent 4f7376e6aa
commit 238747ef97
56 files changed
+424 -336

No files matched your search

+15 -20
View File
@@ -3,6 +3,7 @@
<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_open</title>
</head>
@@ -25,19 +26,18 @@ FRESULT f_open (
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the blank file object structure to be initialized. After the f_open function succeeded, the file can be accessed with the file object structure until it is closed. The member <tt>buffer</tt> in the structure must be initialized with the address of a 512 bytes file read/write buffer before or immediataly after the f_open function. The initialization is not needed when <tt>FA_UNBUFFERED</tt> flag has been specified.</dd>
<dd>Pointer to the blank file object structure to be initialized. After the f_open() succeeded, the file can be accessed with the file object structure until it is closed.</dd>
<dt>FileName</dt>
<dd>Pointer to a null-terminated string specifies the full-path file name to create or open. The directory separator is <tt>'/'</tt>. Because the FatFs module does not have a concept of current directory, a full-path name that followed from the root directory must be used. Leading space charactors are skipped if exist and heading <tt>'/'</tt> can be exist or omitted.</dd>
<dt>ModeFlags</dt>
<dd>Specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
<table class="lst">
<tr><th>Value</th><th>Description</th></td>
<tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.<br>Combine with FA_WRITE for read-write access.</td></td>
<tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file.<br>Combine with FA_READ for read-write access.</td></td>
<tr><td>FA_UNBUFFERED</td><td>This is for only FatFs module. When not specified, the file can be read/written in<br>stream I/O via the file read/write buffer pointed by member 'buffer' in the file<br>object. When specified, file read/write buffer is not used and number of bytes<br>to read/write must be integer multiple of 512. </td></td>
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file does not exist.</td></td>
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file exists, it is truncated and overwritten.</td></td>
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file, if it exists. If the file does not exist, the function creates the file.</td></td>
<tr><th>Value</th><th>Description</th></tr>
<tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.<br>Combine with FA_WRITE for read-write access.</td></tr>
<tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file.<br>Combine with FA_READ for read-write access.</td></tr>
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file does not exist.</td></tr>
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file exists, it is truncated and overwritten.</td></tr>
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file, if it exists. If the file does not exist, the function creates the file.</td></tr>
</table>
</dd>
</dl>
@@ -64,7 +64,7 @@ FRESULT f_open (
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal, such as a medium change during any file opend, has been occured.</dd>
<dd>Incorrect disk removal, such as a medium change during any file is opend, has been occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module has not been enabled.</dd>
<dt>FR_NO_FILESYSTEM</dt>
@@ -75,46 +75,41 @@ FRESULT f_open (
<div class="para">
<h4>Description</h4>
<p>To start to use the FatFs module, prepare a work area (<tt>FATFS</tt> structure), clear the structure and store the address to the global variable 'FatFs' to allocate the work area to the FatFs module. Then the FatFs module can work.</p>
<p>Flags <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt> are not supported in read-only configuration. Flag <tt>FA_UNBUFFERED</tt> is not supported in Tiny-FatFs.</p>
<p>To start to use the FatFs module, prepare a work area (<tt>FATFS</tt> structure), clear it and set its address to the global pointer 'FatFs' to allocate the work area to the FatFs module. Then the FatFs module can work.</p>
<p>Flags <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt> are not supported in read-only configuration.</p>
</div>
<div class="para">
<h4>Sample Code</h4>
<h4>Example (File Copy)</h4>
<pre>
void main ()
{
FATFS fs; // FatFs work area
FIL fsrc, fdst; // file structures
BYTE fbuff[512*2]; // file r/w buffers (not required for Tiny-FatFs)
BYTE buffer[4096]; // file copy buffer
FRESULT res; // FatFs function common result code
WORD br, bw; // File R/W count
// Activate FatFs module
// Give a work area for FatFs (activate module)
memset(&fs, 0, sizeof(FATFS));
FatFs = &fs;
// Open source file
fsrc.buffer = fbuff+0; // (not required for Tiny-FatFs)
res = f_open(&fsrc, "/srcfile.dat", FA_OPEN_EXISTING | FA_READ);
if (res) die(res);
// Create destination file
fdst.buffer = fbuff+512; // (not required for Tiny-FatFs)
res = f_open(&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);
if (res) die(res);
if (br == 0) break;
if (res || br == 0) break;
res = f_write(&fdst, buffer, br, &bw);
if (res) die(res);
if (bw &lt; br) break;
if (res || bw &lt; br) break;
}
// Close all files