]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/documents/doc/open.html
Import fatfs R0.15
[z180-stamp.git] / fatfs / documents / doc / open.html
index c00c5e4c9f0e655150b68614d0b6c006537e47ca..cc8b87ad98fed9fb8575d3f3df53000d02e9a4c3 100644 (file)
@@ -34,15 +34,15 @@ FRESULT f_open (
 <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>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_READ</td><td>Specifies read access to the file. Data can be read from the file.</tr>\r
+<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>\r
+<tr><td>FA_OPEN_EXISTING</td><td>Opens a 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 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
+Mode flags in POSIX fopen() function 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
@@ -86,7 +86,7 @@ Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:<br>
 \r
 <div class="para desc">\r
 <h4>Description</h4>\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>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>\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
@@ -111,14 +111,14 @@ int main (void)
     FRESULT fr;     <span class="c">/* FatFs return code */</span>\r
 \r
 \r
-    <span class="c">/* Register work area to the default drive */</span>\r
+    <span class="c">/* Give a 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 = <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
+    <span class="c">/* Read every line and display it */</span>\r
     while (f_gets(line, sizeof line, &amp;fil)) {\r
         printf(line);\r
     }\r
@@ -134,16 +134,16 @@ int main (void)
 \r
 int main (void)\r
 {\r
-    FATFS fs[2];         <span class="c">/* Work area (filesystem object) for logical drives */</span>\r
+    FATFS fs0, fs1;      <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
     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(&amp;fs[0], "0:", 0);\r
-    f_mount(&amp;fs[1], "1:", 0);\r
+    <span class="c">/* Give work areas to each logical drive */</span>\r
+    f_mount(&amp;fs0, "0:", 0);\r
+    f_mount(&amp;fs1, "1:", 0);\r
 \r
     <span class="c">/* Open source file on the drive 1 */</span>\r
     fr = <em>f_open</em>(&amp;fsrc, "1:file.bin", FA_READ);\r
@@ -155,10 +155,10 @@ int main (void)
 \r
     <span class="c">/* Copy source to destination */</span>\r
     for (;;) {\r
-        fr = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;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(&amp;fdst, buffer, br, &amp;bw);            <span class="c">/* Write it to the destination file */</span>\r
-        if (fr || bw &lt; br) break; <span class="c">/* error or disk full */</span>\r
+        fr = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of data from the source file */</span>\r
+        if (br == 0) break; <span class="c">/* error or eof */</span>\r
+        fr = f_write(&amp;fdst, buffer, br, &amp;bw);           <span class="c">/* Write it to the destination file */</span>\r
+        if (bw &lt; br) break; <span class="c">/* error or disk full */</span>\r
     }\r
 \r
     <span class="c">/* Close open files */</span>\r
@@ -166,8 +166,8 @@ int main (void)
     f_close(&amp;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
+    f_unmount("0:");\r
+    f_unmount("1:");\r
 \r
     return (int)fr;\r
 }\r