+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
-<html lang="en">\r
-<head>\r
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\r
-<meta http-equiv="Content-Style-Type" content="text/css">\r
-<link rel="up" title="FatFs" href="../00index_e.html">\r
-<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/open.html">\r
-<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">\r
-<title>FatFs - f_open</title>\r
-</head>\r
-\r
-<body>\r
-\r
-<div class="para func">\r
-<h2>f_open</h2>\r
-<p>The f_open function creates a <em>file object</em> to be used to access the file.</p>\r
-<pre>\r
-FRESULT f_open (\r
- FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] Pointer to the file object structure */</span>\r
- const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] File name */</span>\r
- BYTE <span class="arg">mode</span> <span class="c">/* [IN] Mode flags */</span>\r
-);\r
-</pre>\r
-</div>\r
-\r
-<div class="para arg">\r
-<h4>Parameters</h4>\r
-<dl class="par">\r
-<dt>fp</dt>\r
-<dd>Pointer to the blank file object structure to be created.</dd>\r
-<dt>path</dt>\r
-<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to open or create.</dd>\r
-<dt>mode</dt>\r
-<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>\r
-<table class="lst">\r
-<tr><th>Value</th><th>Description</th></tr>\r
-<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>\r
-<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>\r
-<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file is not existing. (Default)</td></tr>\r
-<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file is created.<br>\r
-To append data to the file, use <a href="lseek.html"><tt>f_lseek()</tt></a> function after file open in this method.</td></tr>\r
-<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>\r
-<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it will be truncated and overwritten.</td></tr>\r
-</table>\r
-</dd>\r
-</dl>\r
-</div>\r
-\r
-\r
-<div class="para ret">\r
-<h4>Return Values</h4>\r
-<p>\r
-<a href="rc.html#ok">FR_OK</a>,\r
-<a href="rc.html#de">FR_DISK_ERR</a>,\r
-<a href="rc.html#ie">FR_INT_ERR</a>,\r
-<a href="rc.html#nr">FR_NOT_READY</a>,\r
-<a href="rc.html#ok">FR_NO_FILE</a>,\r
-<a href="rc.html#np">FR_NO_PATH</a>,\r
-<a href="rc.html#in">FR_INVALID_NAME</a>,\r
-<a href="rc.html#de">FR_DENIED</a>,\r
-<a href="rc.html#ex">FR_EXIST</a>,\r
-<a href="rc.html#io">FR_INVALID_OBJECT</a>,\r
-<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,\r
-<a href="rc.html#id">FR_INVALID_DRIVE</a>,\r
-<a href="rc.html#ne">FR_NOT_ENABLED</a>,\r
-<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,\r
-<a href="rc.html#tm">FR_TIMEOUT</a>,\r
-<a href="rc.html#lo">FR_LOCKED</a>,\r
-<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,\r
-<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>\r
-</p>\r
-</div>\r
-\r
-\r
-<div class="para desc">\r
-<h4>Description</h4>\r
-<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 <a href="close.html"><tt>f_close()</tt></a> function. If the file is modified and not closed properly, the file data will be collapsed.</p>\r
-<p>If duplicated file open is needed, read <a href="appnote.html#dup">here</a> carefully. However duplicated open of a file with write mode flag is always prohibited.</p>\r
-<p>Before using any file function, a work area (file system object) must be registered to the logical drive with <a href="mount.html"><tt>f_mount()</tt></a> function. All API functions except for <a href="fdisk.html"><tt>f_fdisk()</tt></a> function can work after this procedure.</p>\r
-</div>\r
-\r
-\r
-<div class="para comp">\r
-<h4>QuickInfo</h4>\r
-<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>\r
-</div>\r
-\r
-\r
-<div class="para use">\r
-<h4>Example</h4>\r
-<pre>\r
-<span class="c">/* Read a text file and display it */</span>\r
-\r
-FATFS FatFs; <span class="c">/* Work area (file system object) for logical drive */</span>\r
-\r
-int main (void)\r
-{\r
- FIL fil; <span class="c">/* File object */</span>\r
- char line[82]; <span class="c">/* Line buffer */</span>\r
- FRESULT fr; <span class="c">/* FatFs return code */</span>\r
-\r
-\r
- <span class="c">/* Register work area to the default drive */</span>\r
- f_mount(&FatFs, "", 0);\r
-\r
- <span class="c">/* Open a text file */</span>\r
- fr = f_open(&fil, "message.txt", FA_READ);\r
- if (fr) return (int)fr;\r
-\r
- <span class="c">/* Read all lines and display it */</span>\r
- while (f_gets(line, sizeof line, &fil))\r
- printf(line);\r
-\r
- <span class="c">/* Close the file */</span>\r
- f_close(&fil);\r
-\r
- return 0;\r
-}\r
-</pre>\r
-<pre>\r
-<span class="c">/* Copy a file "file.bin" on the drive 1 to drive 0 */</span>\r
-\r
-int main (void)\r
-{\r
- FATFS fs[2]; <span class="c">/* Work area (file system object) for logical drives */</span>\r
- FIL fsrc, fdst; <span class="c">/* File objects */</span>\r
- BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>\r
- FRESULT fr; <span class="c">/* FatFs function common result code */</span>\r
- UINT br, bw; <span class="c">/* File read/write count */</span>\r
-\r
-\r
- <span class="c">/* Register work area for each logical drive */</span>\r
- f_mount(&fs[0], "0:", 0);\r
- f_mount(&fs[1], "1:", 0);\r
-\r
- <span class="c">/* Open source file on the drive 1 */</span>\r
- fr = f_open(&fsrc, "1:file.bin", FA_OPEN_EXISTING | FA_READ);\r
- if (fr) return (int)fr;\r
-\r
- <span class="c">/* Create destination file on the drive 0 */</span>\r
- fr = f_open(&fdst, "0:file.bin", FA_CREATE_ALWAYS | FA_WRITE);\r
- if (fr) return (int)fr;\r
-\r
- <span class="c">/* Copy source to destination */</span>\r
- for (;;) {\r
- fr = f_read(&fsrc, buffer, sizeof buffer, &br); <span class="c">/* Read a chunk of source file */</span>\r
- if (fr || br == 0) break; <span class="c">/* error or eof */</span>\r
- fr = f_write(&fdst, buffer, br, &bw); <span class="c">/* Write it to the destination file */</span>\r
- if (fr || bw < br) break; <span class="c">/* error or disk full */</span>\r
- }\r
-\r
- <span class="c">/* Close open files */</span>\r
- f_close(&fsrc);\r
- f_close(&fdst);\r
-\r
- <span class="c">/* Unregister work area prior to discard it */</span>\r
- f_mount(NULL, "0:", 0);\r
- f_mount(NULL, "1:", 0);\r
-\r
- return (int)fr;\r
-}\r
-</pre>\r
-</div>\r
-\r
-\r
-<div class="para ref">\r
-<h4>See Also</h4>\r
-<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>\r
-</div>\r
-\r
-<p class="foot"><a href="../00index_e.html">Return</a></p>\r
-</body>\r
-</html>\r