<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 <ahref="filename.html">file name</a> to open or create.</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>
<tableclass="lst">
<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. Combine with <tt>FA_WRITE</tt> 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. Combine with <tt>FA_READ</tt> for read-write access.</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_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file is created.<br>
To append data to the file, use <ahref="lseek.html"><tt>f_lseek()</tt></a> function after file open in this method.</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>
</table>
</dd>
</dl>
</div>
<divclass="para ret">
<h4>Return Values</h4>
<p>
<ahref="rc.html#ok">FR_OK</a>,
<ahref="rc.html#de">FR_DISK_ERR</a>,
<ahref="rc.html#ie">FR_INT_ERR</a>,
<ahref="rc.html#nr">FR_NOT_READY</a>,
<ahref="rc.html#ok">FR_NO_FILE</a>,
<ahref="rc.html#np">FR_NO_PATH</a>,
<ahref="rc.html#in">FR_INVALID_NAME</a>,
<ahref="rc.html#de">FR_DENIED</a>,
<ahref="rc.html#ex">FR_EXIST</a>,
<ahref="rc.html#io">FR_INVALID_OBJECT</a>,
<ahref="rc.html#wp">FR_WRITE_PROTECTED</a>,
<ahref="rc.html#id">FR_INVALID_DRIVE</a>,
<ahref="rc.html#ne">FR_NOT_ENABLED</a>,
<ahref="rc.html#ns">FR_NO_FILESYSTEM</a>,
<ahref="rc.html#tm">FR_TIMEOUT</a>,
<ahref="rc.html#lo">FR_LOCKED</a>,
<ahref="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<ahref="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>
<divclass="para desc">
<h4>Description</h4>
<p>After <tt>f_open()</tt> function succeeded, the file object is valid. The file object is used for subsequent read/write functions to identify the file. To close an open file, use <ahref="close.html"><tt>f_close()</tt></a> function. If the file is modified and not closed properly, the file data will be collapsed.</p>
<p>If duplicated file open is needed, read <ahref="appnote.html#dup">here</a> carefully. However duplicated open of a file with write mode flag is always prohibited.</p>
<p>Before using any file function, a work area (file system object) must be registered to the logical drive with <ahref="mount.html"><tt>f_mount()</tt></a> function. All API functions except for <ahref="fdisk.html"><tt>f_fdisk()</tt></a> function can work after this procedure.</p>
</div>
<divclass="para comp">
<h4>QuickInfo</h4>
<p>Always available. The mode flags, <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_CREATE_NEW and FA_OPEN_ALWAYS</tt>, are not available when <tt>_FS_READONLY == 1</tt>.</p>
</div>
<divclass="para use">
<h4>Example</h4>
<pre>
<spanclass="c">/* Read a text file and display it */</span>
FATFS FatFs; <spanclass="c">/* Work area (file system object) for logical drive */</span>
int main (void)
{
FIL fil; <spanclass="c">/* File object */</span>
char line[82]; <spanclass="c">/* Line buffer */</span>