]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/documents/doc/open.html
Import fatfs R0.13b
[z180-stamp.git] / fatfs / documents / doc / open.html
similarity index 70%
rename from fatfs/doc/en/open.html
rename to fatfs/documents/doc/open.html
index feade156543a81fd554deb6a4d17a58b69805dca..c00c5e4c9f0e655150b68614d0b6c006537e47ca 100644 (file)
@@ -1,7 +1,7 @@
 <!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-Type" content="text/html; charset=utf-8">\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
@@ -13,7 +13,7 @@
 \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
+<p>The f_open function opens a 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
@@ -33,14 +33,26 @@ FRESULT f_open (
 <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>Meaning</th></tr>\r
+<tr><th>Flags</th><th>Meaning</th></tr>\r
 <tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.</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_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
 <tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file will be created.</td></tr>\r
-<tr><td>FA_OPEN_APPEND</td><td>Same as <tt>FA_OPEN_ALWAYS</tt> except read/write pointer is set end of the file.</td></tr>\r
+<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>\r
+</table>\r
+Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:<br>\r
+<table class="lst2">\r
+<tr><th>POSIX</th><th>FatFs</th></tr>\r
+<tr><td>"r"</td><td>FA_READ</td></tr>\r
+<tr><td>"r+"</td><td>FA_READ | FA_WRITE</td></tr>\r
+<tr><td>"w"</td><td>FA_CREATE_ALWAYS | FA_WRITE</td></tr>\r
+<tr><td>"w+"</td><td>FA_CREATE_ALWAYS | FA_WRITE | FA_READ</td></tr>\r
+<tr><td>"a"</td><td>FA_OPEN_APPEND | FA_WRITE</td></tr>\r
+<tr><td>"a+"</td><td>FA_OPEN_APPEND | FA_WRITE | FA_READ</td></tr>\r
+<tr><td>"wx"</td><td>FA_CREATE_NEW | FA_WRITE</td></tr>\r
+<tr><td>"w+x"</td><td>FA_CREATE_NEW | FA_WRITE | FA_READ</td></tr>\r
 </table>\r
 </dd>\r
 </dl>\r
@@ -54,10 +66,10 @@ FRESULT f_open (
 <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#nf">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#dn">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
@@ -74,15 +86,14 @@ FRESULT f_open (
 \r
 <div class="para desc">\r
 <h4>Description</h4>\r
-<p>Before using any file function, a work area (file system object) needs to be registered to the logical drive with <a href="mount.html"><tt>f_mount</tt></a> function. All API functions except for <tt>f_mkfs/f_fdisk</tt> function get ready to work after this procedure.</p>\r
-<p>After <tt>f_open</tt> function succeeded, the file object is valid. The file object is used for subsequent operations to the file to identify the file. Open file must be closed prior to power down, media removal or re-mount, or the file can be collapsed. To close an open file, use <a href="close.html"><tt>f_close</tt></a> function.</p>\r
+<p>The <tt>f_open</tt> function opens a file and creates a <em>file object</em>. The file object is used for subsequent read/write operations to the file to identify 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 is made and not closed prior to power down, media removal or re-mount, or the file can 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 any write mode flag is always prohibited.</p>\r
 </div>\r
 \r
 \r
 <div class="para comp">\r
 <h4>QuickInfo</h4>\r
-<p>Always available. Only <tt>FA_READ</tt> and <tt>FA_OPEN_EXISTING</tt> are supported when <tt>_FS_READONLY == 1</tt>.</p>\r
+<p>Always available. Only <tt>FA_READ</tt> and <tt>FA_OPEN_EXISTING</tt> are available for the mode flags when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 1</tt>.</p>\r
 </div>\r
 \r
 \r
@@ -91,25 +102,26 @@ FRESULT f_open (
 <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
+FATFS FatFs;   <span class="c">/* Work area (filesystem 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
+    FIL fil;        <span class="c">/* File object */</span>\r
+    char line[100]; <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(&amp;FatFs, "", 0);\r
 \r
     <span class="c">/* Open a text file */</span>\r
-    fr = f_open(&amp;fil, "message.txt", FA_READ);\r
+    fr = <em>f_open</em>(&amp;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, &amp;fil))\r
+    while (f_gets(line, sizeof line, &amp;fil)) {\r
         printf(line);\r
+    }\r
 \r
     <span class="c">/* Close the file */</span>\r
     f_close(&amp;fil);\r
@@ -122,7 +134,7 @@ int main (void)
 \r
 int main (void)\r
 {\r
-    FATFS fs[2];         <span class="c">/* Work area (file system object) for logical drives */</span>\r
+    FATFS fs[2];         <span class="c">/* Work area (filesystem 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
@@ -134,11 +146,11 @@ int main (void)
     f_mount(&amp;fs[1], "1:", 0);\r
 \r
     <span class="c">/* Open source file on the drive 1 */</span>\r
-    fr = f_open(&amp;fsrc, "1:file.bin", FA_READ);\r
+    fr = <em>f_open</em>(&amp;fsrc, "1:file.bin", 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(&amp;fdst, "0:file.bin", FA_WRITE | FA_CREATE_ALWAYS);\r
+    fr = <em>f_open</em>(&amp;fdst, "0:file.bin", FA_WRITE | FA_CREATE_ALWAYS);\r
     if (fr) return (int)fr;\r
 \r
     <span class="c">/* Copy source to destination */</span>\r