R0.15a
Nov 22, 2024 Fixed a complie error when FF_FS_LOCK != 0. (appeared at R0.15) Fixed a potential issue when work FatFs concurrency with FF_FS_REENTRANT, FF_VOLUMES >= 2 and FF_FS_LOCK > 0. Made f_setlabel accept a volume label with Unix style volume ID when FF_STR_VOLUME_ID == 2. Made FatFs update PercInUse field in exFAT VBR. (A preceding f_getfree is needed for the accuracy)
This commit is contained in:
+20
-20
@@ -3,8 +3,6 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<link rel="up" title="FatFs" href="../00index_e.html">
|
||||
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/open.html">
|
||||
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
|
||||
<title>FatFs - f_open</title>
|
||||
</head>
|
||||
@@ -27,19 +25,19 @@ FRESULT f_open (
|
||||
<h4>Parameters</h4>
|
||||
<dl class="par">
|
||||
<dt>fp</dt>
|
||||
<dd>Pointer to the blank file object structure.</dd>
|
||||
<dd>Pointer to the blank file object structure. If a null pointer is given, the function fails with <tt>FR_INVALID_OBJECT</tt>.</dd>
|
||||
<dt>path</dt>
|
||||
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">file name</a> to open or create.</dd>
|
||||
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">file name</a> to open or create. If a null pointer is given, the function fails with <tt>FR_INVALID_DRIVE</tt>.</dd>
|
||||
<dt>mode</dt>
|
||||
<dd>Mode flags that 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>Flags</th><th>Meaning</th></tr>
|
||||
<tr><td>FA_READ</td><td>Specifies read access to the file. Data can be read from the file.</tr>
|
||||
<tr><td>FA_WRITE</td><td>Specifies write access to the file. Data can be written to the file. Combine with <tt>FA_READ</tt> for read-write access.</td></tr>
|
||||
<tr><td>FA_OPEN_EXISTING</td><td>Opens a file. The function fails if the file is not existing. (Default)</td></tr>
|
||||
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails with <tt>FR_EXIST</tt> if the file is existing.</td></tr>
|
||||
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it will be truncated and overwritten.</td></tr>
|
||||
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file will be created.</td></tr>
|
||||
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file is not existing. (Default)</td></tr>
|
||||
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, the file is truncated and overwritten.</td></tr>
|
||||
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails if the file is existing.</td></tr>
|
||||
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file. If it is not exist, a new file is created.</td></tr>
|
||||
<tr><td>FA_OPEN_APPEND</td><td>Same as <tt>FA_OPEN_ALWAYS</tt> except the read/write pointer is set end of the file.</td></tr>
|
||||
</table>
|
||||
Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:<br>
|
||||
@@ -86,7 +84,8 @@ Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_open</tt> function opens a file and creates a <em>file object</em>. The file object is an identifier for subsequent operations to the file. Open file should be closed with <a href="close.html"><tt>f_close</tt></a> function after the session of the file access. If any change to the file has been made and not closed prior to power off, media removal or re-mount, or the file can be collapsed.</p>
|
||||
<p>The <tt>f_open</tt> function opens a file and creates a <em>file object</em>. It is the identifier for subsequent read/write operations to the file. After the function succeeded, the file object is valid. If the function failed, the file object is set invalid.</p>
|
||||
<p>Open file should be closed with <a href="close.html"><tt>f_close</tt></a> function after the session of the file access. If any change to the file has been made and not closed prior to power off, media removal or re-mount, or the file can be collapsed.</p>
|
||||
<p>If duplicated file open is needed, read <a href="appnote.html#dup">here</a> carefully. However duplicated open of a file with any write mode flag is always prohibited.</p>
|
||||
</div>
|
||||
|
||||
@@ -112,19 +111,19 @@ int main (void)
|
||||
|
||||
|
||||
<span class="c">/* Give a work area to the default drive */</span>
|
||||
f_mount(&FatFs, "", 0);
|
||||
<em>f_mount</em>(&FatFs, "", 0);
|
||||
|
||||
<span class="c">/* Open a text file */</span>
|
||||
fr = <em>f_open</em>(&fil, "message.txt", FA_READ);
|
||||
if (fr) return (int)fr;
|
||||
|
||||
<span class="c">/* Read every line and display it */</span>
|
||||
while (f_gets(line, sizeof line, &fil)) {
|
||||
while (<em>f_gets</em>(line, sizeof line, &fil)) {
|
||||
printf(line);
|
||||
}
|
||||
|
||||
<span class="c">/* Close the file */</span>
|
||||
f_close(&fil);
|
||||
<em>f_close</em>(&fil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -142,8 +141,8 @@ int main (void)
|
||||
|
||||
|
||||
<span class="c">/* Give work areas to each logical drive */</span>
|
||||
f_mount(&fs0, "0:", 0);
|
||||
f_mount(&fs1, "1:", 0);
|
||||
<em>f_mount</em>(&fs0, "0:", 0);
|
||||
<em>f_mount</em>(&fs1, "1:", 0);
|
||||
|
||||
<span class="c">/* Open source file on the drive 1 */</span>
|
||||
fr = <em>f_open</em>(&fsrc, "1:file.bin", FA_READ);
|
||||
@@ -155,19 +154,19 @@ int main (void)
|
||||
|
||||
<span class="c">/* Copy source to destination */</span>
|
||||
for (;;) {
|
||||
fr = f_read(&fsrc, buffer, sizeof buffer, &br); <span class="c">/* Read a chunk of data from the source file */</span>
|
||||
fr = <em>f_read</em>(&fsrc, buffer, sizeof buffer, &br); <span class="c">/* Read a chunk of data from the source file */</span>
|
||||
if (br == 0) break; <span class="c">/* error or eof */</span>
|
||||
fr = f_write(&fdst, buffer, br, &bw); <span class="c">/* Write it to the destination file */</span>
|
||||
fr = <em>f_write</em>(&fdst, buffer, br, &bw); <span class="c">/* Write it to the destination file */</span>
|
||||
if (bw < br) break; <span class="c">/* error or disk full */</span>
|
||||
}
|
||||
|
||||
<span class="c">/* Close open files */</span>
|
||||
f_close(&fsrc);
|
||||
f_close(&fdst);
|
||||
<em>f_close</em>(&fsrc);
|
||||
<em>f_close</em>(&fdst);
|
||||
|
||||
<span class="c">/* Unregister work area prior to discard it */</span>
|
||||
f_unmount("0:");
|
||||
f_unmount("1:");
|
||||
<em>f_unmount</em>("0:");
|
||||
<em>f_unmount</em>("1:");
|
||||
|
||||
return (int)fr;
|
||||
}
|
||||
@@ -180,6 +179,7 @@ int main (void)
|
||||
<p><tt><a href="read.html">f_read</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a>, <a href="sfatfs.html">FATFS</a></tt></p>
|
||||
</div>
|
||||
|
||||
|
||||
<p class="foot"><a href="../00index_e.html">Return</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user