diff options
author | Leo C. | 2024-06-30 09:37:28 +0200 |
---|---|---|
committer | Leo C. | 2024-06-30 09:37:28 +0200 |
commit | 5630b9308323c3f3aaa09be8fe0f3aecaa826473 (patch) | |
tree | ad11998289caa623b98507393f838611317ad03e /fatfs | |
parent | dbd0d34e68c73b9d3628cc1a1bda0b883976fc8b (diff) | |
download | z180-stamp-chan-fatfs.zip |
Import fatfs R0.15fatfs-0.15chan-fatfs
Diffstat (limited to 'fatfs')
65 files changed, 3440 insertions, 1970 deletions
diff --git a/fatfs/LICENSE.txt b/fatfs/LICENSE.txt index bdce118..25379e4 100644 --- a/fatfs/LICENSE.txt +++ b/fatfs/LICENSE.txt @@ -21,4 +21,4 @@ FatFs has being developped as a personal project of the author, ChaN. It is free / by use of this software.
/----------------------------------------------------------------------------*/
-Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
+Therefore FatFs license is one of the BSD-style licenses, but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, do not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses include GNU GPL. When you redistribute the FatFs source code with changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
diff --git a/fatfs/documents/00index_e.html b/fatfs/documents/00index_e.html index 3646a38..b3b8adb 100644 --- a/fatfs/documents/00index_e.html +++ b/fatfs/documents/00index_e.html @@ -5,6 +5,8 @@ <meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="cache-control" content="no-cache">
<meta name="description" content="Open source FAT filesystem for embedded projects">
+<link rel="start" title="Site Top" href="../../">
+<link rel="up" title="Freewares" href="../../fsw_e.html">
<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - Generic FAT Filesystem Module</title>
</head>
@@ -19,18 +21,18 @@ <h4>Features</h4>
<ul>
- <li>DOS/Windows compatible FAT/exFAT filesystem.</li>
- <li>Platform independent. Easy to port.</li>
- <li>Very small footprint for program code and work area.</li>
- <li>Various <a href="doc/config.html">configuration options</a> to support for:
+ <li>DOS/Windows Compatible FAT/exFAT Filesystem.</li>
+ <li>Platform Independent. <a href="doc/appnote.html#port">Easy to port</a>.</li>
+ <li>Very Small <a href="doc/appnote.html#memory">Footprint</a> for Program Code and Work Area.</li>
+ <li>Various <a href="doc/config.html">Configuration Options</a> to Support for:
<ul>
- <li>Long file name in ANSI/OEM or Unicode.</li>
- <li>exFAT filesystem.</li>
- <li>Thread safe for RTOS.</li>
- <li>Multiple volumes (physical drives and partitions).</li>
- <li>Variable sector size.</li>
- <li>Multiple code pages including DBCS.</li>
- <li>Read-only, optional API, I/O buffer and etc...</li>
+ <li>Long File Name in ANSI/OEM or Unicode.</li>
+ <li>exFAT Filesystem, 64-bit LBA and GPT for Huge Storages.</li>
+ <li>Thread Safe for RTOS.</li>
+ <li>Multiple Volumes. (Physical Drives and Partitions)</li>
+ <li>Variable Sector Size.</li>
+ <li>Multiple Code Pages Including DBCS.</li>
+ <li>Read-only, Optional APIs, I/O Buffer and etc...</li>
</ul>
</li>
</ul>
@@ -67,7 +69,7 @@ <ul>
<li><a href="doc/opendir.html">f_opendir</a> - Open a directory</li>
<li><a href="doc/closedir.html">f_closedir</a> - Close an open directory</li>
- <li><a href="doc/readdir.html">f_readdir</a> - Read an directory item</li>
+ <li><a href="doc/readdir.html">f_readdir</a> - Read a directory item</li>
<li><a href="doc/findfirst.html">f_findfirst</a> - Open a directory and read the first item matched</li>
<li><a href="doc/findnext.html">f_findnext</a> - Read a next item matched</li>
</ul>
@@ -89,8 +91,8 @@ <ul>
<li><a href="doc/mount.html">f_mount</a> - Register/Unregister the work area of the volume</li>
<li><a href="doc/mkfs.html">f_mkfs</a> - Create an FAT volume on the logical drive</li>
- <li><a href="doc/fdisk.html">f_fdisk</a> - Create logical drives on the physical drive</li>
- <li><a href="doc/getfree.html">f_getfree</a> - Get total size and free size on the volume</li>
+ <li><a href="doc/fdisk.html">f_fdisk</a> - Create partitions on the physical drive</li>
+ <li><a href="doc/getfree.html">f_getfree</a> - Get free space on the volume</li>
<li><a href="doc/getlabel.html">f_getlabel</a> - Get volume label</li>
<li><a href="doc/setlabel.html">f_setlabel</a> - Set volume label</li>
<li><a href="doc/setcp.html">f_setcp</a> - Set active code page</li>
@@ -103,39 +105,45 @@ <div class="para">
<h3>Media Access Interface</h3>
<img src="res/layers2.png" class="rset" width="245" height="220" alt="layer">
-<p>Since the FatFs module is the <em>filesystem layer</em> independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The low level device control module is <em>not a part of FatFs module</em> and it needs to be provided by implementer. FatFs accesses the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for low level disk I/O module is available <a href="res/app4.c">here</a>.</p>
+<p>Since FatFs module is the <em>Filesystem Layer</em> independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The storage device control module is <em>not any part of FatFs module</em> and it needs to be provided by implementer. FatFs controls the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for storage device control module is available <a href="res/app4.c">here</a>.</p>
<ul>
- <li><a href="doc/dstat.html">disk_status</a> - Get device status</li>
- <li><a href="doc/dinit.html">disk_initialize</a> - Initialize device</li>
- <li><a href="doc/dread.html">disk_read</a> - Read sector(s)</li>
- <li><a href="doc/dwrite.html">disk_write</a> - Write sector(s)</li>
- <li><a href="doc/dioctl.html">disk_ioctl</a> - Control device dependent functions</li>
- <li><a href="doc/fattime.html">get_fattime</a> - Get current time</li>
+ <li>Storage Device Controls
+ <ul>
+ <li><a href="doc/dstat.html">disk_status</a> - Get device status</li>
+ <li><a href="doc/dinit.html">disk_initialize</a> - Initialize device</li>
+ <li><a href="doc/dread.html">disk_read</a> - Read data</li>
+ <li><a href="doc/dwrite.html">disk_write</a> - Write data</li>
+ <li><a href="doc/dioctl.html">disk_ioctl</a> - Control device dependent functions</li>
+ </ul>
+ </li>
+ <li>Real Time Clock
+ <ul>
+ <li><a href="doc/fattime.html">get_fattime</a> - Get current time</li>
+ </ul>
+ </li>
</ul>
</div>
<div class="para">
<h3>Resources</h3>
-<p>The FatFs module is a free software opened for education, research and development. You can use, modify and/or redistribute it for personal projects or commercial products without any restriction under your responsibility. For further information, refer to the application note.</p>
+<p>The FatFs module is a free software opened for education, research and development. You can use, modify and/or redistribute it for any purpose without any restriction under your responsibility. For further information, refer to the application note.</p>
<ul>
- <li>Read first: <a href="doc/appnote.html">FatFs module application note</a></li>
- <li>Download: <a href="http://elm-chan.org/fsw/ff/archives.html">Archives of FatFs and Petit-FatFs</a></li>
+ <li><em>Getting Started: <a href="doc/appnote.html">FatFs Application Note</a></em></li>
<li>Community: <a href="http://elm-chan.org/fsw/ff/bd/">FatFs User Forum</a></li>
<li><a href="https://msdn.microsoft.com/en-us/windows/hardware/gg463080.aspx">FAT32 Specification by Microsoft</a>↗ (The authorized document on FAT filesystem)</li>
- <li><a href="http://elm-chan.org/docs/fat_e.html">The basics of FAT filesystem</a></li>
- <li><a href="http://elm-chan.org/docs/exfat_e.html">The basics of exFAT filesystem</a></li>
+ <li><a href="http://elm-chan.org/docs/fat_e.html">The basics of FAT filesystem</a> (FatFs is written based on this documentation)</li>
+ <li><a href="http://elm-chan.org/docs/exfat_e.html">The basics of exFAT filesystem</a> (FatFs is written based on this documentation)</li>
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to use MMC/SDC</a></li>
<li><a href="http://elm-chan.org/junk/fa/faff.html">Playing with FlashAir and FatFs</a></li>
<li><a href="http://nemuisan.blog.bai.ne.jp/">Nemuisan's Blog</a>↗ (Well written implementations for STM32F/SPI & SDIO and LPC4088/SDMMC)</li>
<li><a href="http://stm32f4-discovery.net/2014/07/library-21-read-sd-card-fatfs-stm32f4xx-devices/">Read SD card with FatFs on STM32F4xx devices by Tilen Majerle</a>↗ (Quick and easy implementation for STM32F4-Discovery)</li>
<li><a href="res/rwtest1.png">Benchmark 1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li>
<li><a href="res/rwtest2.png">Benchmark 2</a> (LPC2368/72MHz with MMC via MCI)</li>
- <li><a href="res/fd.mp4">Demo movie of an application</a> (this project is in ffsample.zip/lpc23xx)</li></ul>
</div>
<hr>
-<p class="foot"><a href="http://elm-chan.org/fsw/ff/00index_e.html">FatFs Home Page</a></p>
+<p class="foot"><a href="../../fsw_e.html">Return</a></p>
</body>
</html>
diff --git a/fatfs/documents/css_e.css b/fatfs/documents/css_e.css index 8274af3..1181a09 100644 --- a/fatfs/documents/css_e.css +++ b/fatfs/documents/css_e.css @@ -14,6 +14,7 @@ strong {} pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
+pre span.e {color: red;}
pre span.b {font-weight: bold;}
pre span.arg {font-style: italic;}
tt {margin: 0 0.2em; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
@@ -57,13 +58,16 @@ small {font-size: 80%;} .indent {margin-left: 2em;}
/* Tables */
-table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
-th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
-td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
+table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid gray; }
+table caption {font-family: sans-serif; font-weight: bold;}
+table th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: gray; padding: 0 3px; vertical-align: top; white-space: nowrap;}
+table td {background-color: white; border: 1px solid gray; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
table.lst3 td {font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
-table caption {font-family: sans-serif; font-weight: bold;}
-tr.lst3 td { border-width: 2px 1px 1px; }
+tr.lst3 td {border-width: 2px 1px 1px; }
+table.lst4 td {padding: 0.3em;}
+table.lst4 td:nth-child(2) {width: 45%;}
+table.lst4 td:nth-child(3) {width: 45%;}
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}
diff --git a/fatfs/documents/doc/appnote.html b/fatfs/documents/doc/appnote.html index ee88b42..5a7a2df 100644 --- a/fatfs/documents/doc/appnote.html +++ b/fatfs/documents/doc/appnote.html @@ -19,12 +19,13 @@ <li><a href="#lfn">Long File Name</a></li>
<li><a href="#unicode">Unicode API</a></li>
<li><a href="#exfat">exFAT Filesystem</a></li>
+<li><a href="#lba64">64-bit LBA</a></li>
<li><a href="#reentrant">Re-entrancy</a></li>
<li><a href="#dup">Duplicated File Access</a></li>
<li><a href="#fs1">Performance Effective File Access</a></li>
<li><a href="#fs2">Considerations on Flash Memory Media</a></li>
<li><a href="#critical">Critical Section</a></li>
-<li><a href="#fs3">Extended Use of FatFs API</a></li>
+<li><a href="#fs3">Various Usable Functions for FatFs Projects</a></li>
<li><a href="#license">About FatFs License</a></li>
</ol>
@@ -32,33 +33,58 @@ <h3>How to Port</h3>
<h4>Basic Considerations</h4>
-<p>The FatFs module is assuming following conditions on portability.</p>
+<p>The FatFs module assumes following conditions on portability.</p>
<ul>
<li>ANSI C<br>
-The FatFs module is a middleware written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with ANSI C.</li>
+The FatFs module is a middleware written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with C89 or later. Only exFAT feature requires C99.</li>
<li>Size of integer types<br>
-The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> are 8/16/32 bit and <tt>int</tt> is 16 or 32 bit. These correspondence are defined in <tt>integer.h</tt>. This will not be a problem on most compilers. When a conflict with existing definitions is occured, you must resolve it with care.</li>
+<ul>
+<li>Size of <tt>char</tt> must be 8-bit.</li>
+<li>Size of <tt>int</tt>, as well as integer promotion, must be 16-bit or 32-bit.</li>
+<li>Size of <tt>short</tt> and <tt>long</tt> must be 16-bit and 32-bit respectively. (in C89 only)</li>
+</ul>
+<li>Dependency<br>
+<ul>
+<li>C89: <tt>string.h</tt>.</li>
+<li>C99: <tt>string.h</tt> and <tt>stdint.h</tt>.</li>
+<li>Optional: <tt>stdarg.h</tt> and <tt>math.h</tt>.</li>
</ul>
+</ul>
+
+<h4>Integer Types in FatFs API</h4>
+<p>Integer types used in FatFs are defined in <tt>ff.h</tt> as described below. It is based on Win32 API (<tt>windef.h</tt>). This will not be a problem on most platform. When a conflict with existing definitions occured, you must resolve it with care.</p>
+<dl>
+<dt><tt>BYTE</tt></dt><dd>8-bit unsigned integer in range of 0 to 2<sup>8</sup> - 1.</dd>
+<dt><tt>WORD</tt></dt><dd>16-bit unsigned integer in range of 0 to 2<sup>16</sup> - 1.</dd>
+<dt><tt>DWORD</tt></dt><dd>32-bit unsigned integer in range of 0 to 2<sup>32</sup> - 1.</dd>
+<dt><tt>QWORD</tt></dt><dd>64-bit unsigned integer in range of 0 to 2<sup>64</sup> - 1.</dd>
+<dt><tt>UINT</tt></dt><dd>Alias of <tt>unsigned int</tt> used to specify any number.</dd>
+<dt><tt>WCHAR</tt></dt><dd>Alias of <tt>WORD</tt> used to specify a UTF-16 code unit.</dd>
+<dt><tt>TCHAR</tt></dt><dd>Alias of <tt>char</tt>, <tt>WCHAR</tt> or <tt>DWORD</tt> used to specify a character encoding unit.</dd>
+<dt><tt>FSIZE_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address file offset and to specify file size.</dd>
+<dt><tt>LBA_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address sectors in LBA and to specify number of sectors.</dd>
+</dl>
<h4>System Organizations</h4>
-<p>The dependency diagram shown below is a typical but not specific configuration of the embedded system with FatFs module.</p>
+<p>The dependency diagram shown below is a typical, but not specific, configuration of the embedded system with FatFs module.</p>
<p><img src="../res/modules.png" width="580" height="280" alt="dependency diagram"></p>
-<p>(a) If a working disk module with FatFs disk interface is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, glue functions are needed to translate the interfaces between FatFs and the drivers.</p>
+<p>(a) If a working disk module for FatFs is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, some glue functions are needed to translate the interfaces between FatFs and the driver.</p>
<p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p>
<h4>Required Functions</h4>
-<p>You need to provide only low level disk I/O functions required by FatFs module and nothing else. If a working disk module for the target system is already provided, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk I/O module or write it from scratch. Most of defined functions are not that always required. For example, any write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</p>
+<p>You need to provide only MAI functions required by FatFs module and nothing else. If a working device control module for the target system is available, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another device control module or write it from scratch. Most of MAI functions are not that always required. For instance, the write function is not required in read-only configuration. Following table shows which function is required depends on the configuration options.</p>
<table class="lst2">
-<tr><th>Function</th><th>Required when</th><th>Note</th></tr>
+<tr><th>Function</th><th>Required when:</th><th>Note</th></tr>
<tr><td>disk_status<br>disk_initialize<br>disk_read</td><td>Always</td><td rowspan="5">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
-<tr><td>disk_write<br>get_fattime<br>disk_ioctl (CTRL_SYNC)</td><td>FF_FS_READONLY == 0</td></tr>
-<tr><td>disk_ioctl (GET_SECTOR_COUNT)<br>disk_ioctl (GET_BLOCK_SIZE)</td><td>FF_USE_MKFS == 1</td></tr>
-<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>FF_MAX_SS != FF_MIN_SS</td></tr>
-<tr><td>disk_ioctl (CTRL_TRIM)</td><td>FF_USE_TRIM == 1</td></tr>
-<tr><td>ff_uni2oem<br>ff_oem2uni<br>ff_wtoupper</td><td>FF_USE_LFN != 0</td><td>Unicode support functions.<br>Just add ffunicode.c to the project.</td></tr>
-<tr><td>ff_cre_syncobj<br>ff_del_syncobj<br>ff_req_grant<br>ff_rel_grant</td><td>FF_FS_REENTRANT == 1</td><td rowspan="2">O/S dependent functions.<br>Samples available in ffsystem.c.</td></tr>
+<tr><td>disk_write<br>get_fattime<br>disk_ioctl (CTRL_SYNC)</td><td><a href="config.html#fs_readonly">FF_FS_READONLY == 0</a></td></tr>
+<tr><td>disk_ioctl (GET_SECTOR_COUNT)<br>disk_ioctl (GET_BLOCK_SIZE)</td><td><a href="config.html#use_mkfs">FF_USE_MKFS == 1</a></td></tr>
+<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td><a href="config.html#max_ss">FF_MAX_SS != FF_MIN_SS</a></td></tr>
+<tr><td>disk_ioctl (CTRL_TRIM)</td><td><a href="config.html#use_trim">FF_USE_TRIM == 1</a></td></tr>
+<tr><td>ff_uni2oem<br>ff_oem2uni<br>ff_wtoupper</td><td><a href="config.html#use_lfn">FF_USE_LFN != 0</a></td><td>Unicode support functions.<br>Add optional module ffunicode.c to the project.</td></tr>
+<tr><td>ff_mutex_create<br>ff_mutex_delete<br>ff_mutex_take<br>ff_mutex_give</td><td><a href="config.html#fs_reentrant">FF_FS_REENTRANT == 1</a></td><td rowspan="2">O/S dependent functions.<br>Sample code is available in ffsystem.c.</td></tr>
<tr><td>ff_mem_alloc<br>ff_mem_free</td><td>FF_USE_LFN == 3</td></tr>
</table>
+<p>FatFs cares about neither what kind of storage device is used nor how it is implemented. Only a requirement is that it is a block device read/written in fixed-size blocks that accessible via the disk I/O functions defined above.</p>
</div>
<div class="para doc" id="limits">
@@ -66,11 +92,12 @@ The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> <ul>
<li>Filesystem type: FAT, FAT32(rev0.0) and exFAT(rev1.0).</li>
<li>Number of open files: Unlimited. (depends on available memory)</li>
-<li>Number of volumes: Upto 10.</li>
-<li>Volume size: Upto 2 TB at 512 bytes/sector.</li>
-<li>File size: Upto 4 GB - 1 on FAT volume and virtually unlimited on exFAT volume.</li>
-<li>Cluster size: Upto 128 sectors on FAT volume and upto 16 MB on exFAT volume.</li>
+<li>Number of volumes: Up to 10.</li>
<li>Sector size: 512, 1024, 2048 and 4096 bytes.</li>
+<li>Minimum volume size: 128 sectors.</li>
+<li>Maximum volume size: 2<sup>32</sup> - 1 sectors in 32-bit LBA, virtually unlimited in 64-bit LBA with exFAT.</li>
+<li>Maximum file size: 2<sup>32</sup> - 1 bytes on FAT volume, virtually unlimited on exFAT volume.</li>
+<li>Cluster size: Upto 128 sectors on FAT volume and up to 16 MB on exFAT volume.</li>
</ul>
</div>
@@ -81,29 +108,29 @@ The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> <tr><th></th><th>ARM7<small><br>32bit</small></th><th>ARM7<small><br>Thumb</small></th><th>CM3<small><br>Thumb-2</small></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>RL78</th><th>V850ES</th><th>SH-2A</th><th>RX600</th><th>IA-32</th></tr>
<tr class="cal"> <td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>MSC</td></tr>
<!-- ARM Thumb CM3 AVR H8 PIC24 RL78 V850ES SH-2A RX600 IA-32 -->
-<tr class="ral"><td class="cal">text (Full, R/W)</td><td>10.4k</td><td>6.7k</td><td>6.3k</td><td>12.4k</td> <td>9.9k</td><td>11.2k</td><td>13.0k</td><td>8.7k</td><td>9.0k</td><td>6.5k</td><td>8.9k</td></tr>
-<tr class="ral"><td class="cal">text (Min, R/W)</td> <td>7.0k</td><td>4.7k</td><td>4.4k</td> <td>8.4k</td> <td>6.9k</td> <td>7.8k</td> <td>9.4k</td><td>6.0k</td><td>6.2k</td><td>4.6k</td><td>6.3k</td></tr>
-<tr class="ral"><td class="cal">text (Full, R/O)</td> <td>4.8k</td><td>3.1k</td><td>2.8k</td> <td>5.7k</td> <td>4.7k</td> <td>5.3k</td> <td>6.4k</td><td>4.2k</td><td>4.0k</td><td>3.1k</td><td>4.2k</td></tr>
-<tr class="ral"><td class="cal">text (Min, R/O)</td> <td>3.6k</td><td>2.4k</td><td>2.2k</td> <td>4.4k</td> <td>3.6k</td> <td>4.1k</td> <td>5.0k</td><td>3.3k</td><td>3.1k</td><td>2.4k</td><td>3.3k</td></tr>
-<tr class="ral"><td class="cal">bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
+<tr class="ral"><td class="cal">.text (Def, R/W)</td><td>10.4k</td><td>6.7k</td><td>6.1k</td><td>12.5k</td><td>11.0k</td><td>11.4k</td><td>13.0k</td><td>8.9k</td><td>9.2k</td><td>6.5k</td><td>8.9k</td></tr>
+<tr class="ral"><td class="cal">.text (Min, R/W)</td> <td>7.0k</td><td>4.7k</td><td>4.2k</td> <td>8.5k</td> <td>7.6k</td> <td>7.9k</td> <td>9.5k</td><td>6.3k</td><td>6.4k</td><td>4.7k</td><td>6.4k</td></tr>
+<tr class="ral"><td class="cal">.text (Def, R/O)</td> <td>4.9k</td><td>3.2k</td><td>2.7k</td> <td>6.1k</td> <td>5.2k</td> <td>5.4k</td> <td>6.5k</td><td>4.3k</td><td>4.2k</td><td>3.2k</td><td>4.3k</td></tr>
+<tr class="ral"><td class="cal">.text (Min, R/O)</td> <td>3.7k</td><td>2.5k</td><td>2.1k</td> <td>4.4k</td> <td>4.0k</td> <td>4.2k</td> <td>5.1k</td><td>3.4k</td><td>3.3k</td><td>2.5k</td><td>3.5k</td></tr>
+<tr class="ral"><td class="cal">.bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr class="ral"><td class="cal">Work area<br><small>(FF_FS_TINY == 0)</small></td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td></tr>
<tr class="ral"><td class="cal">Work area<br><small>(FF_FS_TINY == 1)</small></td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td></tr>
</table>
-<p>These are the memory usage on some target systems with following condition. The memory sizes are in unit of byte, <em>V</em> denotes number of mounted volumes and <em>F</em> denotes number of open files. All samples here are optimezed in code size.</p>
+<p>These are the memory usage of FatFs module without lower layer on some target systems in following condition. <em>V</em> denotes number of mounted volumes and <em>F</em> denotes number of open files. Every samples here are optimezed in code size.</p>
<pre>
-FatFs R0.13a options:
-FF_FS_READONLY 0 (Read/Write) or 1 (Read only)
-FF_FS_MINIMIZE 0 (Full, with all basic functions) or 3 (Min, with fully minimized)
+FatFs R0.15 options:
+FF_FS_READONLY 0 (R/W, read/write) or 1 (R/O, read only)
+FF_FS_MINIMIZE 0 (Def, with all basic functions) or 3 (Min, with fully minimized)
FF_FS_TINY 0 (Default) or 1 (Tiny file object)
-And other options are left unchanged from original setting.
+And any other options are left unchanged from original setting.
</pre>
</div>
<div class="para doc" id="reduce">
-<h3>Reducing Modle Size</h3>
-<p>Follwing table shows which API function is removed by configuration options for the module size reduction. To use any API function, the row of the function must be clear.</p>
+<h3>Reducing Module Size</h3>
+<p>Follwing table shows which API function is removed by configuration options to reduce the module size. To use an API function, the row of the function must be clear.</p>
<table class="lst2">
-<tr><td rowspan="2">Function</td><td colspan="4">FF_FS_<br>MINIMIZE</td><td colspan="2">FF_FS_<br>READONLY</td><td colspan="2">FF_USE_<br>STRFUNC</td><td colspan="3">FF_FS_<br>RPATH</td><td colspan="2">FF_USE_<br>FIND</td><td colspan="2">FF_USE_<br>CHMOD</td><td colspan="2">FF_USE_<br>EXPAND</td><td colspan="2">FF_USE_<br>LABEL</td><td colspan="2">FF_USE_<br>MKFS</td><td colspan="2">FF_USE_<br>FORWARD</td><td colspan="2">FF_MULTI_<br>PARTITION</td></tr>
+<tr><td rowspan="2">Function</td><td colspan="4"><a href="config.html#fs_minimize">FF_FS_<br>MINIMIZE</a></td><td colspan="2"><a href="config.html#fs_readonly">FF_FS_<br>READONLY</a></td><td colspan="2"><a href="config.html#use_strfunc">FF_USE_<br>STRFUNC</a></td><td colspan="3"><a href="config.html#fs_rpath">FF_FS_<br>RPATH</a></td><td colspan="2"><a href="config.html#use_find">FF_USE_<br>FIND</a></td><td colspan="2"><a href="config.html#use_chmod">FF_USE_<br>CHMOD</a></td><td colspan="2"><a href="config.html#use_expand">FF_USE_<br>EXPAND</a></td><td colspan="2"><a href="config.html#use_label">FF_USE_<br>LABEL</a></td><td colspan="2"><a href="config.html#use_mkfs">FF_USE_<br>MKFS</a></td><td colspan="2"><a href="config.html#use_forward">FF_USE_<br>FORWARD</a></td><td colspan="2"><a href="config.html#multi_partition">FF_MULTI_<br>PARTITION</a></td></tr>
<tr> <td>0</td><td>1</td><td>2</td><td>3</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>
<tr class="lst3">
<td>f_mount</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
@@ -144,141 +171,169 @@ And other options are left unchanged from original setting. <div class="para doc" id="lfn">
<h3>Long File Name</h3>
-<p>FatFs module supports long file name (LFN). The two different file names, short file name (SFN) and LFN, of a file is transparent on the API except for <tt>f_readdir</tt> function. The support for LFN is disabled by default. To enable the LFN, set <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>ffunicode.c</tt> to the project. The LFN requiers a certain working buffer in addition. The buffer size can be configured by <tt><a href="config.html#max_lfn">FF_MAX_LFN</a></tt> according to the available memory. The length of an LFN will be up to 255 characters, so that the <tt>FF_MAX_LFN</tt> should be set to 255 for all file names. If the size of working buffer is insufficient for the input file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When use any re-entry to the API with LFN is enabled, <tt>FF_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The working buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled.</p>
-<table class="lst2 rset">
-<caption>With LFN at CM3+gcc</caption>
-<tr><th><tt>FF_CODE_PAGE</tt></th><th>Increment</th></tr>
-<tr><td>437-869 (SBCS)</td><td>+3.3k</td></tr>
-<tr><td>932 (Japanese)</td><td>+62k</td></tr>
-<tr><td>936 (Simplified Chinese)</td><td>+177k</td></tr>
-<tr><td>949 (Korean)</td><td>+140k</td></tr>
-<tr><td>950 (Traditional Chinese)</td><td>+111k</td></tr>
-<tr><td>0 (All code pages)</td><td>+486k</td></tr>
-</table>
-<p>When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows increment of code size by LFN function at different code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table. As the result, the FatFs with LFN enebled with those code pages will not able to be ported on the most 8-bit MCU systems.</p>
-<p>If you can discard ANSI/OEM code API and backward compatibility with non-ASCII SFN, you will able to configure FatFs for Unicode API with any SBCS.</p>
-<p>There ware some restrictions on using LFN for open source project because the support for LFN on the FAT volume was a patent of Microsoft Corporation. The related patents have expired and using the LFN function have got free for any projects.</p>
-</div>
-
-<div class="para doc" id="unicode">
-<h3>Unicode API</h3>
-<p>By default, FatFs uses ANSI/OEM code set on the API even at LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt>. This means that FatFs supports the full featured LFN specification. The data type <tt>TCHAR</tt> specifies path name strings on the API is an alias of either <tt>char</tt>(ANSI/OEM or UTF-8), <tt>WCHAR</tt>(UTF-16) or <tt>DWORD</tt>(UTF-32) depends on that option. For more information, refer to the description in the <a href="filename.html#uni">file name</a>.</p>
-<p>Note that code page setting, <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>, has actually no meaning for the path names at the Unicode API. However it still affects code conversion of string I/O functions at <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a> != 0</tt> and backward compatibility with legacy systems, so that code page needs to be configured properly when it is considered a problem.</p>
-</div>
-
-<div class="para doc" id="exfat">
-<h3>exFAT Filesystem</h3>
-<p>The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as a recommended filesystem for high capacity SD cards larger than 32 GB and they are being shipped with this format, so that the exFAT became one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows upto and some filesystem overhead, especially cluster allocation delay, are reduced as well. This feature improves the write throughput to the file.</p>
-<p>Note that the exFAT is a patent of Microsoft Corporation. The exFAT function of FatFs is an implementation based on <cite>US. Pat. App. Pub. No. 2009/0164440 A1</cite>. FatFs module can switch the support for exFAT on/off by configuration option, <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>. When enable the exFAT on the commercial products, a license by Microsoft will be needed depends on the final destination of the products.</p>
-<p><em>Remark: Enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.</em></p>
-</div>
-
-<div class="para doc" id="reentrant">
-<h3>Re-entrancy</h3>
-<p>The file operations to the <em>different volumes</em> each other is always re-entrant regardless of configurations except when LFN is enabled with static working buffer. It can work concurrently without any mutual exclusion.</p>
-<p>The file operations to the <em>same volume</em> is not re-entrant. It can also be configured for thread-safe by option <tt><a href="config.html#fs_reentrant">FF_FS_REENTRANT</a></tt>. In this case, also the OS dependent synchronization control functions, <tt>ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant</tt>, need to be added to the project. There are some examples in the <tt>ffsystem.c</tt>. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by <tt>FF_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout function might not be supported on the some RTOSs.</p>
-<p>There is an exception on the re-entrancy for <tt>f_mount/f_mkfs</tt> function. These volume management functions are not re-entrant to the same volume. When use these functions, other tasks need to avoid to access the volume.</p>
-<p>Remarks: This section describes on the re-entrancy of the FatFs module itself. The <tt>FF_FS_REENTRANT</tt> option enables only exclusive use of each filesystem objects and FatFs never prevents to re-enter <tt>disk_*()</tt> functions. Thus the low level disk I/O layer must be always thread-safe when FatFs API is re-entered for different volumes.</p>
-</div>
-
-<div class="para doc" id="dup">
-<h3>Duplicated File Open</h3>
-<p>FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed or deleted. A violation of these rules can cause data collaption.</p>
-<p>The file lock control can be enabled by <tt><a href="config.html#fs_lock">FF_FS_LOCK</a></tt> option. The value of option defines the number of open objects to manage simultaneously. In this case, if any opening, renaming or removing against the file shareing rule that described above is attempted, the file function will be rejected with <tt>FR_LOCKED</tt>. If number of open objects, files and sub-directories, is equal to <tt>FF_FS_LOCK</tt>, an extra <tt>f_open/f_opendir</tt> function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</p>
-</div>
-
-<div class="para doc" id="fs1">
-<h3>Performance Effective File Access</h3>
-<p>For good read/write throughput on the small embedded systems with limited size of memory, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by <tt>f_read</tt> function.</p>
-<p>Figure 1. Sector unaligned read (short)<br>
-<img src="../res/f1.png" width="490" height="110" alt="">
-</p>
-<p>Figure 2. Sector unaligned read (long)<br>
-<img src="../res/f2.png" width="490" height="140" alt="">
-</p>
-<p>Figure 3. Fully sector aligned read<br>
-<img src="../res/f3.png" width="490" height="119" alt="">
-</p>
-<p>The file I/O buffer is a sector buffer to read/write a part of data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the filesystem object. The buffer configuration option <tt><a href="config.html#fs_tiny">FF_FS_TINY</a></tt> determins which sector buffer is used for the file data transfer. When tiny buffer configuration (1) is selected, data memory consumption is reduced <tt>FF_MAX_SS</tt> bytes each file object. In this case, FatFs module uses only a sector buffer in the filesystem object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.</p>
-<p>Figure 1 shows that a partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with <tt>disk_read</tt> function at a time but the multiple sector transfer is divided at cluster boundary even if it is contiguous.</p>
-<p>Therefore taking effort to sector aligned read/write accesss eliminates buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.</p>
-</div>
-
-<div class="para doc" id="fs2">
-<h3>Considerations on Flash Memory Media</h3>
-<p>To maximize the write performance of flash memory media, such as SDC, CFC and U Disk, it must be controlled in consideration of its characteristitcs.</p>
-<h4>Using Mutiple-Sector Write</h4>
-<div class="rset">
-Figure 6. Comparison between Multiple/Single Sector Write<br>
-<img src="../res/f6.png" width="630" height="148" alt="fig.6">
-</div>
-<p>The write throughput of the flash memory media becomes the worst at single sector write transaction. The write throughput increases as the number of sectors per a write transaction as shown in Figure 6. This effect more appers at faster interface speed and the performance ratio often becomes grater than ten. <a href="../res/rwtest2.png">This result</a> is clearly explaining how fast is multiple block write (W:16K, 32 sectors) than single block write (W:100, 1 sector), and also larger card tends to be slow at single block write. Number of write transactions also affects life time of the flash memory media. When compared at same amount of write data, the single sector write in Figure 6 above wears flash memory media 16 times more than multiple sector write in Figure 6 below. Single sector write is pretty pain for the flash memory media.</p>
-<p>Therefore the application program should write the data in large block as possible. The ideal write chunk size and alighment is size of sector, and size of cluster is the best. Of course all layers between the application and the storage device must have consideration on multiple sector write, however most of open-source memory card drivers lack it. Do not split a multiple sector write request into single sector write transactions or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write operation. </p>
-<h4>Forcing Memory Erase</h4>
-<p>When remove a file with <tt>f_unlink</tt> function, the data clusters occupied by the file are marked 'free' on the FAT. But the data sectors containing the file data are not that applied any process, so that the file data left occupies a part of the flash memory array as 'live block'. If the file data can be erased on removing the file, those data blocks will be turned into the free block pool. This may skip internal block erase operation to the data block on next write operation. As the result the write performance might be improved. FatFs can manage this function by setting <tt><a href="config.html#use_trim">FF_USE_TRIM</a></tt> to 1. Note that this is an expectation of internal process of the storage device and not that always effective. Most applications will not need this function. Also <tt>f_unlink</tt> function can take a time when remove a large file.</p>
-</div>
-
-<div class="para doc" id="critical">
-<h3>Critical Section</h3>
-<p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, incorrect media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.</p>
-<div class="lset">
-Figure 4. Long critical section<br>
-<img src="../res/f4.png" width="320" height="436" alt="fig.4">
-</div>
-<div class="lset">
-Figure 5. Minimized critical section<br>
-<img src="../res/f5.png" width="320" height="436" alt="fig.5">
-</div>
-<br class="clr">
-<p>An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.</p>
-<ul>
-<li>The file data being rewrited is collapsed.</li>
-<li>The file being appended returns initial state.</li>
-<li>The file created as new is gone.</li>
-<li>The file created as new or overwritten remains but no content.</li>
-<li>Efficiency of disk use gets worse due to lost clusters.</li>
-</ul>
-<p>Each case does not affect any file not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using <tt>f_sync</tt> function as shown in Figure 5.</p>
-</div>
-
-<div class="para doc" id="fs3">
-<h3>Extended Use of FatFs API</h3>
-<p>These are examples of extended use of FatFs APIs. New item will be added whenever a useful code is found.</p>
-<ol>
-<li><a href="http://elm-chan.org/fsw/ff/res/app1.c">Open or create a file for append</a> (for only R0.12 and earlier)</li>
-<li><a href="http://elm-chan.org/fsw/ff/res/app2.c">Empty a directory</a></li>
-<li><a href="http://elm-chan.org/fsw/ff/res/app3.c">Allocate contiguous area to the file</a> (for only R0.11a and earlier)</li>
-<li><a href="http://elm-chan.org/fsw/ff/res/app4.c">Compatibility checker for low level disk I/O module</a></li>
-<li><a href="http://elm-chan.org/fsw/ff/res/mkfatimg.zip">FAT volume image creator</a></li>
-</ol>
-</div>
-
-<div class="para doc" id="license">
-<h3>About FatFs License</h3>
-<p>FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that included in the source files.</p>
-<pre>
-/*----------------------------------------------------------------------------/
-/ FatFs - Generic FAT Filesystem Module Rx.xx /
-/-----------------------------------------------------------------------------/
-/
-/ Copyright (C) 20xx, ChaN, all right reserved.
-/
-/ FatFs module is an open source software. Redistribution and use of FatFs in
-/ source and binary forms, with or without modification, are permitted provided
-/ that the following condition is met:
-/
-/ 1. Redistributions of source code must retain the above copyright notice,
-/ this condition and the following disclaimer.
-/
-/ This software is provided by the copyright holder and contributors "AS IS"
-/ and any warranties related to this software are DISCLAIMED.
-/ The copyright owner or contributors be NOT LIABLE for any damages caused
-/ by use of this software.
-/----------------------------------------------------------------------------*/
-</pre>
-<p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.</p>
-</div>
-
-<p class="foot"><a href="../00index_e.html">Return Home</a></p>
-</body>
-</html>
+<p>FatFs module supports the long file name (LFN) extension of the FAT filesystem. The two different file names, short file name (SFN) and LFN, of a file is transparent on the API. The support for LFN feature is disabled by default. To enable the LFN, set <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>ffunicode.c</tt> to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by <tt><a href="config.html#max_lfn">FF_MAX_LFN</a></tt> according to the available memory. The length of LFN can be up to 255 characters, so that the <tt>FF_MAX_LFN</tt> should be set to 255 for any existing file names. If the size of working buffer is insufficient for the input file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When use any re-entry to the API with LFN feature in RTOS environment, <tt>FF_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The LFN working buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled.</p> +<h4>Impact upon Module Size</h4> +<table class="lst2 rset"> +<caption>With LFN at CM3 + gcc</caption> +<tr><th><tt>FF_CODE_PAGE</tt></th><th>Code size</th></tr> +<tr><td>437-869 (SBCS)</td><td>+3.3k</td></tr> +<tr><td>932 (Japanese)</td><td>+62k</td></tr> +<tr><td>936 (Simplified Chinese)</td><td>+177k</td></tr> +<tr><td>949 (Korean)</td><td>+140k</td></tr> +<tr><td>950 (Traditional Chinese)</td><td>+111k</td></tr> +<tr><td>0 (All code pages)</td><td>+486k</td></tr> +</table> +<p>When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows the increment of code size in some code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table.</p> +<p>As the result, the FatFs with LFN enabled with DBCS code pages will not able to be ported on the most 8-bit MCU systems. If the target system is in legacy-free, in only Unicode and any ANSI/OEM code is not used at all, the code page setting gets meaningless. You will able to reduce the code size by configureing FatFs for Unicode API with any SBCS code page.</p> +<p>There ware some restrictions on using LFN for open source project, because the LFN extension on the FAT filesystem was a patent of Microsoft Corporation. However the related patents all have expired and using the LFN feature is free for any projects.</p> +</div> + +<div class="para doc" id="unicode"> +<h3>Unicode API</h3> +<p>By default, FatFs uses ANSI/OEM code set on the API even in LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt>. This means that FatFs is compliant with the full featured LFN specification. The data type <tt>TCHAR</tt> specifies path name strings on the API is an alias of either <tt>char</tt>(ANSI/OEM or UTF-8), <tt>WCHAR</tt>(UTF-16) or <tt>DWORD</tt>(UTF-32) depends on that option. For more information, refer to the description in the <a href="filename.html#uni">file name</a>.</p> +<p>Note that setting of code page, <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>, has actually no meaning when FatFs is configured for the Unicode API. It should be set 437 to reduce the module size. However it still affects code conversion of string I/O functions when <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a> == 0</tt>, and also backward compatibility with legacy systems. In this case, the code page may need to be configured properly if it is considered a problem.</p> +</div> + +<div class="para doc" id="exfat"> +<h3>exFAT Filesystem</h3> +<p>The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as the filesystem for SDXC card, 64 GB and larger, and they are being shipped with this format. Therefore the exFAT is one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows up to and some filesystem overhead, especially cluster allocation delay, are reduced as well. These features allow to record the large data without dividing into some files and improve the write throughput to the file.</p> +<p>Note that the exFAT filesystem is a patent of Microsoft Corporation. The exFAT feature of FatFs is an implementation based on <cite>US. Pat. App. Pub. No. 2009/0164440 A1</cite>. FatFs module can switch the exFAT on or off by a configuration option, <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>. When enable the exFAT for the commercial products, a license by Microsoft will be needed depends on the final destination of the products.</p> +<p><em>Remarks: Enabling exFAT discards C89 compatibility and it wants C99 because of need for 64-bit integer type.</em></p> +</div> + +<div class="para doc" id="lba64"> +<h3>64-bit LBA</h3> +<p>LBA (Logical Block Addressing) is an addressing method to specify the location of data block, called <em>sector</em>, on the storage media. It is a simple linear address beginning from 0 as the first sector, 1 as the second sector and so on. The host system does not need to consider how the data block is located and managed in the storage device. FatFs supports only LBA for the media access. 32-bit LBA is a common size in the most LBA scheme. It can address up to 2<sup>32</sup> sectors, 2 TB in 512 bytes/sector. When a storage device larger than 2 TB is used, larger sector size or 64-bit LBA will be needed to address the entire sectors of the storage device.</p> +<p>By default, FatFs works in 32-bit LBA for media access. FatFs can also switch it to 64-bit LBA by a configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>. It also enables GPT (GUID Partition Table) for partiotion management on the storage device. For further information about GPT, refer to <tt><a href="mkfs.html">f_mkfs</a></tt> and <tt><a href="fdisk.html">f_fdisk</a></tt> function.</p> +</div> + +<div class="para doc" id="reentrant"> +<h3>Re-entrancy</h3> +<p>The file operations of two tasks to the <em>different volumes</em> each other is always re-entrant and it can work concurrently without any mutual exclusion regardless of the configurations except when LFN is enabled with static working buffer (<tt>FF_USE_LFN = 1</tt>).</p> +<p>The file operations of two tasks to the <em>same volume</em> is not thread-safe by default. FatFs can also be configured to make it thread-safe by an option <tt><a href="config.html#fs_reentrant">FF_FS_REENTRANT</a></tt>. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by <tt>FF_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout feature might not be supported on the some OSs. To enable this feature, OS dependent synchronization control functions, <tt>ff_mutex_create/ff_mutex_delete/ff_mutex_take/ff_mutex_give</tt>, need to be added to the project. There is an example code in the <tt>ffsystem.c</tt> for some OSs.</p> +<p>Note that there is an exception on the re-entrancy for <tt>f_mount</tt> and <tt>f_mkfs</tt> function. You will know why it is. These volume management functions are always not thread-safe to the volume being processed. When use these functions, other tasks need to avoid to access the corresponding volume.</p> +<div class="rset"> +<table class="lst2"> +<tr><th><tt>Function</tt></th><th>Case 1</th><th>Case 2</th><th>Case 3</th></tr> +<tr><td>disk_status</td><td>Yes</td><td>Yes</td><td>Yes(*)</td></tr> +<tr><td>disk_initialize</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> +<tr><td>disk_read</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> +<tr><td>disk_write</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> +<tr><td>disk_ioctl</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> +<tr><td>get_fattime</td><td>No</td><td>Yes</td><td>Yes</td></tr> +</table> +<small> +Case 1: Same volume.<br> +Case 2: Different volume on the same drive.<br> +Case 3: Different volume on the different drive.<br> +(*) In only different drive number. +</small> +</div> +<p>Remarks: This section describes on the re-entrancy of the FatFs module itself. The <tt>FF_FS_REENTRANT</tt> option enables only exclusive use of each filesystem objects and FatFs does not that prevent to re-enter the storage device control functions. Thus the device control layer needs to be always thread-safe when FatFs API is re-entered for different volumes. Right table shows which control function can be re-entered when FatFs API is re-entered on some conditions.</p> +</div> + +<div class="para doc" id="dup"> +<h3>Duplicated File Open</h3> +<p>FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed or deleted. A violation of these rules can cause data collaption.</p> +<p>The file lock control can be enabled by <tt><a href="config.html#fs_lock">FF_FS_LOCK</a></tt> option. The value of option defines the number of open objects to manage simultaneously. In this case, if any opening, renaming or removing against the file shareing rule that described above is attempted, the file function will be rejected with <tt>FR_LOCKED</tt>. If number of open objects, files and sub-directories, is equal to <tt>FF_FS_LOCK</tt>, an extra <tt>f_open/f_opendir</tt> function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</p> +</div> + +<div class="para doc" id="fs1"> +<h3>Performance Effective File Access</h3> +<p>For good read/write throughput on the small embedded systems with limited size of memory, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by <tt>f_read</tt> function.</p> +<p>Figure 1. Sector unaligned read (short)<br> +<img src="../res/f1.png" width="490" height="110" alt=""> +</p> +<p>Figure 2. Sector unaligned read (long)<br> +<img src="../res/f2.png" width="490" height="140" alt=""> +</p> +<p>Figure 3. Fully sector aligned read<br> +<img src="../res/f3.png" width="490" height="119" alt=""> +</p> +<p>The file I/O buffer is a sector buffer to read/write a part of data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the filesystem object. The buffer configuration option <tt><a href="config.html#fs_tiny">FF_FS_TINY</a></tt> determins which sector buffer is used for the file data transfer. When tiny buffer configuration (1) is selected, data memory consumption is reduced <tt>FF_MAX_SS</tt> bytes each file object. In this case, FatFs module uses only a sector buffer in the filesystem object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.</p> +<p>Figure 1 shows that a partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with <tt>disk_read</tt> function at a time but the multiple sector transfer is divided at cluster boundary even if it is contiguous.</p> +<p>Therefore taking effort to sector aligned read/write accesss eliminates buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.</p> +</div> + +<div class="para doc" id="fs2"> +<h3>Considerations on Flash Memory Media</h3> +<p>To maximize the write performance of flash memory media, such as SDC, CFC and U Disk, it must be controlled in consideration of its characteristitcs.</p> +<h4>Using Mutiple-Sector Write</h4> +<div class="rset"> +Figure 6. Comparison between Multiple/Single Sector Write<br> +<img src="../res/f6.png" width="630" height="148" alt="fig.6"> +</div> +<p>The write throughput of the flash memory media becomes the worst at single sector write transaction. The write throughput increases as the number of sectors per a write transaction as shown in Figure 6. This effect more appers at faster interface speed and the performance ratio often becomes grater than ten. <a href="../res/rwtest2.png">This result</a> is clearly explaining how fast is multiple block write (W:16K, 32 sectors) than single block write (W:100, 1 sector), and also larger card tends to be slow at single block write. Number of write transactions also affects life time of the flash memory media. When compared at same amount of write data, the single sector write in Figure 6 above wears flash memory media 16 times more than multiple sector write in Figure 6 below. Single sector write is pretty pain for the flash memory media.</p> +<p>Therefore the application program should write the data in large block as possible. The ideal write chunk size and alighment is size of sector, and size of cluster is the best. Of course all layers between the application and the storage device must have consideration on multiple sector write, however most of open-source memory card drivers lack it. Do not split a multiple sector write request into single sector write transactions or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write operation. </p> +<h4>Forcing Memory Erase</h4> +<p>When remove a file with <tt>f_unlink</tt> function, the data clusters occupied by the file are marked 'free' on the FAT. But the data sectors containing the file data are not that applied any process, so that the file data left occupies a part of the flash memory array as 'live block'. If the file data can be erased on removing the file, those data blocks will be turned into the free block pool. This may skip internal block erase operation to the data block on next write operation. As the result the write performance might be improved. FatFs can manage this function by setting <tt><a href="config.html#use_trim">FF_USE_TRIM</a></tt> to 1. Note that because this effect is from an expectation of internal process of the storage device, it is not that always effective. Most applications will not need this function. Also <tt>f_unlink</tt> function can take a time when remove a large file.</p> +</div> + +<div class="para doc" id="critical"> +<h3>Critical Section</h3> +<p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, wrong media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.</p> +<div class="lset"> +Figure 4. Long critical section<br> +<img src="../res/f4.png" width="320" height="436" alt="fig.4"> +</div> +<div class="lset"> +Figure 5. Minimized critical section<br> +<img src="../res/f5.png" width="320" height="436" alt="fig.5"> +</div> +<br class="clr"> +<p>An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.</p> +<ul> +<li>The file data being rewrited is collapsed.</li> +<li>The file being appended returns initial state.</li> +<li>The file created as new is gone.</li> +<li>The file created as new or overwritten remains but no content.</li> +<li>Efficiency of disk use gets worse due to lost clusters.</li> +</ul> +<p>Each case does not affect any file not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using <tt>f_sync</tt> function as shown in Figure 5.</p> +</div> + +<div class="para doc" id="fs3"> +<h3>Various Usable Functions for FatFs Projects</h3> +<p>These are examples of extended use of FatFs APIs. New item will be added when useful code example is found.</p> +<ol> +<li><a href="http://elm-chan.org/fsw/ff/res/app1.c">Open or Create File for Append</a> (superseded by FA_OPEN_APPEND flag added at R0.12)</li> +<li><a href="http://elm-chan.org/fsw/ff/res/app2.c">Delete Non-empty Sub-directory</a> (for R0.12 and later)</li> +<li><a href="http://elm-chan.org/fsw/ff/res/app3.c">Create Contiguous File</a> (superseded by f_expand function added at R0.12)</li> +<li><a href="http://elm-chan.org/fsw/ff/res/app5.c">Test if the File is Contiguous or Not</a></li> +<li><a href="http://elm-chan.org/fsw/ff/res/app4.c">Compatibility Checker for Storage Device Control Module</a></li> +<li><a href="http://elm-chan.org/fsw/ff/res/app6.c">Performance Checker for Storage Device Control Module</a></li> +<li><a href="http://elm-chan.org/fsw/ff/res/mkfatimg.zip">FAT Volume Image Creator</a> (Pre-creating built-in FAT volume)</li> +<li>Virtual Drive Feature (refer to lpc176x/ in <a href="../ffsample.zip">ffsample.zip</a>)</li> +<li><a href="http://elm-chan.org/fsw/ff/res/uniconv.zip">Embedded Unicode String Utilities</a> (OEMxxx→Unicode, Unicode→OEMxxx, Unicode→Unicode)</li> +</ol> +</div> + +<div class="para doc" id="license"> +<h3>About FatFs License</h3> +<p>FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that included in the source files.</p> +<pre> +/*----------------------------------------------------------------------------/ +/ FatFs - Generic FAT Filesystem Module Rx.xx / +/-----------------------------------------------------------------------------/ +/ +/ Copyright (C) 20xx, ChaN, all right reserved. +/ +/ FatFs module is an open source software. Redistribution and use of FatFs in +/ source and binary forms, with or without modification, are permitted provided +/ that the following condition is met: +/ +/ 1. Redistributions of source code must retain the above copyright notice, +/ this condition and the following disclaimer. +/ +/ This software is provided by the copyright holder and contributors "AS IS" +/ and any warranties related to this software are DISCLAIMED. +/ The copyright owner or contributors be NOT LIABLE for any damages caused +/ by use of this software. +/----------------------------------------------------------------------------*/ +</pre> +<p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses includes GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that compatible with FatFs license.</p> +</div> + +<p class="foot"><a href="../00index_e.html">Return Home</a></p> +</body> +</html> diff --git a/fatfs/documents/doc/chdir.html b/fatfs/documents/doc/chdir.html index 072b9e9..93e116c 100644 --- a/fatfs/documents/doc/chdir.html +++ b/fatfs/documents/doc/chdir.html @@ -25,7 +25,7 @@ FRESULT f_chdir ( <h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
-<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory</a> to go.</dd>
+<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory</a> to be set as current directory.</dd>
</dl>
</div>
@@ -50,7 +50,7 @@ FRESULT f_chdir ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_chdir</tt> function changes the current directory of the logical drive. Also the current drive is changed at Unix style volume ID, <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 2</tt>. The current directory of each logical drive is initialized to the root directory on mount.</p>
+<p>The <tt>f_chdir</tt> function changes the current directory of the logical drive. Also the current drive will be changed when in Unix style drive prefix, <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 2</tt>. The current directory of each logical drive is initialized to the root directory on mount.</p>
<p>Note that the current directory is retained in the each file system object and the current drive is retained in a static variable, so that it also affects other tasks that use the file functions.</p>
</div>
diff --git a/fatfs/documents/doc/chdrive.html b/fatfs/documents/doc/chdrive.html index fb1c32f..4dfc7d8 100644 --- a/fatfs/documents/doc/chdrive.html +++ b/fatfs/documents/doc/chdrive.html @@ -41,7 +41,7 @@ FRESULT f_chdrive ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_chdrive</tt> function changes only the current drive. The initial value of the current drive number is 0. Note that the current drive is retained in a static variable, so that it also affects other tasks that using the file functions.</p>
+<p>The <tt>f_chdrive</tt> function changes only the current drive. The initial value of the current drive number is 0. In Unix style drive prefix configuration, this function will not be needed because <tt>f_chdir</tt> function changes also the current drive. Note that the current drive is retained in a static variable, so that it also affects other tasks that using the file functions.</p>
</div>
<div class="para comp">
@@ -56,8 +56,6 @@ FRESULT f_chdrive ( <em>f_chdrive</em>("2:"); <span class="c">/* Set drive 2 as current drive */</span>
<em>f_chdrive</em>(""); <span class="c">/* No effect (set current drive as current drive) */</span>
-
- <em>f_chdrive</em>("/flash"); <span class="c">/* Set drive "flash" as current drive (at Unix style volume ID) */</span>
</pre>
</div>
diff --git a/fatfs/documents/doc/config.html b/fatfs/documents/doc/config.html index aeea190..788e075 100644 --- a/fatfs/documents/doc/config.html +++ b/fatfs/documents/doc/config.html @@ -11,13 +11,12 @@ <body>
<h1>Configuration Options</h1>
-<p>There are many options to configure the functions of FatFs for requirement of each project. The configuration options are defined in the <em><tt>ffconf.h</tt></em>.</p>
+<p>There are many options to configure the features of FatFs for various requirements of each project. The configuration options are defined in <em><tt>ffconf.h</tt></em>.</p>
<ul>
<li>Function Configurations
<ul>
<li><a href="#fs_readonly">FF_FS_READONLY</a></li>
<li><a href="#fs_minimize">FF_FS_MINIMIZE</a></li>
- <li><a href="#use_strfunc">FF_USE_STRFUNC</a></li>
<li><a href="#use_find">FF_USE_FIND</a></li>
<li><a href="#use_mkfs">FF_USE_MKFS</a></li>
<li><a href="#use_fastseek">FF_USE_FASTSEEK</a></li>
@@ -25,6 +24,10 @@ <li><a href="#use_chmod">FF_USE_CHMOD</a></li>
<li><a href="#use_label">FF_USE_LABEL</a></li>
<li><a href="#use_forward">FF_USE_FORWARD</a></li>
+ <li><a href="#use_strfunc">FF_USE_STRFUNC</a></li>
+ <li><a href="#print_lli">FF_PRINT_LLI</a></li>
+ <li><a href="#print_fp">FF_PRINT_FLOAT</a></li>
+ <li><a href="#strf_encode">FF_STRF_ENCODE</a></li>
</ul>
</li>
<li>Namespace and Locale Configurations
@@ -34,7 +37,6 @@ <li><a href="#max_lfn">FF_MAX_LFN</a></li>
<li><a href="#lfn_unicode">FF_LFN_UNICODE</a></li>
<li><a href="#lfn_buf">FF_LFN_BUF, FF_SFN_BUF</a></li>
- <li><a href="#strf_encode">FF_STRF_ENCODE</a></li>
<li><a href="#fs_rpath">FF_FS_RPATH</a></li>
</ul>
</li>
@@ -45,8 +47,9 @@ <li><a href="#volume_strs">FF_VOLUME_STRS</a></li>
<li><a href="#multi_partition">FF_MULTI_PARTITION</a></li>
<li><a href="#max_ss">FF_MIN_SS, FF_MAX_SS</a></li>
+ <li><a href="#fs_lba64">FF_LBA64</a></li>
+ <li><a href="#fs_gptmin">FF_GPT_MIN</a></li>
<li><a href="#use_trim">FF_USE_TRIM</a></li>
- <li><a href="#fs_nofsinfo">FF_FS_NOFSINFO</a></li>
</ul>
</li>
<li>System Configurations
@@ -55,6 +58,7 @@ <li><a href="#fs_exfat">FF_FS_EXFAT</a></li>
<li><a href="#fs_nortc">FF_FS_NORTC</a></li>
<li><a href="#nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</a></li>
+ <li><a href="#fs_nofsinfo">FF_FS_NOFSINFO</a></li>
<li><a href="#fs_lock">FF_FS_LOCK</a></li>
<li><a href="#fs_reentrant">FF_FS_REENTRANT</a></li>
<li><a href="#fs_timeout">FF_FS_TIMEOUT</a></li>
@@ -79,15 +83,6 @@ <tr><td>3</td><td><tt>f_lseek</tt> function is removed in addition to 2.</td></tr>
</table>
-<h4 id="use_strfunc">FF_USE_STRFUNC</h4>
-<p>This option switches string functions, <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>.</p>
-<table class="lst1">
-<tr><th>Value</th><th>Description</th></tr>
-<tr><td>0</td><td>Disable string functions.</td></tr>
-<tr><td>1</td><td>Enable string functions without LF-CRLF conversion.</td></tr>
-<tr><td>2</td><td>Enable string functions with LF-CRLF conversion.</td></tr>
-</table>
-
<h4 id="use_find">FF_USE_FIND</h4>
<p>Disable (0) or Enable (1) filtered directory read functions, <tt>f_findfirst</tt> and <tt>f_findnext</tt>. Also <tt>FF_FS_MINIMIZE</tt> needs to be 0 or 1.</p>
@@ -109,6 +104,38 @@ <h4 id="use_forward">FF_USE_FORWARD</h4>
<p>Disable (0) or Enable (1) <tt>f_forward</tt> function.</p>
+<h4 id="use_strfunc">FF_USE_STRFUNC</h4>
+<p>This option switches string functions, <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>. These functions are equivalents of regular string stream I/O functions in POSIX. If <tt>sprintf</tt> is available and code conversion is not needed, <tt>f_write</tt> with <tt>sprintf</tt> will be efficient in code size and performance rather than <tt>f_printf</tt>. When enable this feature, <tt>stdarg.h</tt> is included in <tt>ff.c</tt>.</p>
+<table class="lst1">
+<tr><th>Value</th><th>Description</th></tr>
+<tr><td>0</td><td>Disable string functions.</td></tr>
+<tr><td>1</td><td>Enable string functions without LF-CRLF conversion.</td></tr>
+<tr><td>2</td><td>Enable string functions with LF-CRLF conversion.</td></tr>
+</table>
+
+<h4 id="print_lli">FF_PRINT_LLI</h4>
+<p>This option switches support for long long integer argument in <tt>f_printf</tt>.</p>
+<p>Disable (0) or Enable (1). When enable this feature, C standard needs to be C99 or later.</p>
+
+<h4 id="print_fp">FF_PRINT_FLOAT</h4>
+<p>This option switches support for floating point argument in <tt>f_printf</tt>. When enable this feature, C standard needs to be C99 or later and <tt>math.h</tt> is included in <tt>ff.c</tt>.</p>
+<table class="lst1">
+<tr><th>Value</th><th>Description</th></tr>
+<tr><td>0</td><td>Disable floating point argument.</td></tr>
+<tr><td>1</td><td>Enable floating point argument in type <tt>'f'</tt>, <tt>'e'</tt> and <tt>'E'</tt>.</td></tr>
+<tr><td>2</td><td>Enable it with decimal separator <tt>','</tt> instead of <tt>'.'</tt>.</td></tr>
+</table>
+
+<h4 id="strf_encode">FF_STRF_ENCODE</h4>
+<p>When character encoding on the API is Unicode (<tt>FF_LFN_UNICODE >= 1</tt>), string I/O functions enabled by <tt>FF_USE_STRFUNC</tt> convert the character encoding in it. This option defines the assumption of character encoding <em>on the file</em> to be read/written via those functions. When LFN is not enabled or <tt>FF_LFN_UNICODE == 0</tt>, the string functions work without any code conversion and this option has no effect.</p>
+<table class="lst2">
+<tr><th>Value</th><th>Character encoding on the file</th></tr>
+<tr><td>0</td><td>ANSI/OEM in current code page</td></tr>
+<tr><td>1</td><td>Unicode in UTF-16LE</td></tr>
+<tr><td>2</td><td>Unicode in UTF-16BE</td></tr>
+<tr><td>3</td><td>Unicode in UTF-8</td></tr>
+</table>
+
</div>
@@ -116,10 +143,10 @@ <h3>Namespace and Locale Configurations</h3>
<h4 id="code_page">FF_CODE_PAGE</h4>
-<p>This option specifies the OEM code page to be used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used at all, there is no difference between any code page settings.</p>
+<p>This option specifies the OEM code page used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used for the path name or <tt>FF_LFN_UNICODE != 0</tt>, there is no difference between any code page settings. Set it 437 anyway.</p>
<table class="lst1">
<tr><th>Value</th><th>Code page</th></tr>
-<tr><td>0</td><td>Include all code pages below and set by <tt>f_setcp()</tt></td></tr>
+<tr><td>0</td><td>Includes all code pages below and set by <tt>f_setcp()</tt></td></tr>
<tr><td>437</td><td>U.S.</td></tr>
<tr><td>720</td><td>Arabic</td></tr>
<tr><td>737</td><td>Greek</td></tr>
@@ -154,10 +181,10 @@ </table>
<h4 id="max_lfn">FF_MAX_LFN</h4>
-<p>LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 in UTF-16 encoding unit of the LFN. The buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.</p>
+<p>LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 characters (actually in UTF-16 code units) of the LFN. The buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.</p>
<h4 id="lfn_unicode">FF_LFN_UNICODE</h4>
-<p>This option switches character encoding for the file name on the API. When Unicode is selected, <tt>FF_CODE_PAGE</tt> has actually no meaning except for compatibility with legacy systems. FatFs supports the code point upto U+10FFFF.</p>
+<p>This option switches character encoding for the file name on the API. FatFs supports the code point up to U+10FFFF. This option also affects behavior of string I/O functions (see <tt>FF_STRF_ENCODE</tt>).</p>
<table class="lst2">
<tr><th>Value</th><th>Character Encoding</th><th><tt>TCHAR</tt></th></tr>
<tr><td>0</td><td>ANSI/OEM in current CP</td><td>char</td></tr>
@@ -165,35 +192,26 @@ <tr><td>2</td><td>Unicode in UTF-8</td><td>char</td></tr>
<tr><td>3</td><td>Unicode in UTF-32</td><td>DWORD</td></tr>
</table>
-<p>This option also affects behavior of string I/O functions (see <tt>FF_STRF_ENCODE</tt>). When LFN is not enabled, this option has no effect and FatFs works at ANSI/OEM code on the API. For more information, read <a href="filename.html#uni">here</a>.</p>
+<p>When Unicode is selected, <tt>FF_CODE_PAGE</tt> has actually no meaning except for compatibility with legacy systems, such as MS-DOS and any system without support for LFN.</p>
+<p>When LFN is not enabled, this option has no effect and FatFs works in ANSI/OEM code on the API. For more information, read <a href="filename.html#uni">here</a>.</p>
<h4 id="lfn_buf">FF_LFN_BUF, FF_SFN_BUF</h4>
-<p>This set of options defines size of file name members, <tt>fname[]</tt> and <tt>altname[]</tt>, in the <tt><a href="sfileinfo.html">FILINFO</a></tt> structure which is used to read out the directory items. These values should be suffcient for the file names to read. How long is the read file name length maximum depends on the character encoding on the API as follows:</p>
+<p>This set of options defines size of file name members, <tt>fname[]</tt> and <tt>altname[]</tt>, in the <tt><a href="sfileinfo.html">FILINFO</a></tt> structure which is used to read out the directory items. These values should be suffcient for the file names to read. The maximum possible length of read file name depends on the character encoding scheme on the API as follows:</p>
<table class="lst2">
<tr><th>Encoding</th><th>LFN length</th><th>SFN length</th></tr>
-<tr><td>ANSI/OEM at SBCS</td><td>255 items</td><td>12 items</td></tr>
-<tr><td>ANSI/OEM at DBCS</td><td>510 items</td><td>12 items</td></tr>
+<tr><td>ANSI/OEM in SBCS</td><td>255 items</td><td>12 items</td></tr>
+<tr><td>ANSI/OEM in DBCS</td><td>510 items</td><td>12 items</td></tr>
<tr><td>Unicode in UTF-16/32</td><td>255 items</td><td>12 items</td></tr>
<tr><td>Unicode in UTF-8</td><td>765 items</td><td>34 items</td></tr>
</table>
<p>If the size of name member is insufficient for the LFN, the item is treated as without LFN. When LFN is not enabled, these options have no effect.</p>
-<h4 id="strf_encode">FF_STRF_ENCODE</h4>
-<p>When character encoding on the API is Unicode (<tt>FF_LFN_UNICODE >= 1</tt>), string I/O functions, <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>, convert the character encodins in it. This option defines the assumption of character encoding <em>on the file</em> to be read/written via those functions. When LFN is not enabled or <tt>FF_LFN_UNICODE == 0</tt>, the string functions work without any encoding conversion and this option has no effect.</p>
-<table class="lst2">
-<tr><th>Value</th><th>Character encoding on the file</th></tr>
-<tr><td>0</td><td>ANSI/OEM in current code page</td></tr>
-<tr><td>1</td><td>Unicode in UTF-16LE</td></tr>
-<tr><td>2</td><td>Unicode in UTF-16BE</td></tr>
-<tr><td>3</td><td>Unicode in UTF-8</td></tr>
-</table>
-
<h4 id="fs_rpath">FF_FS_RPATH</h4>
<p>This option configures relative path function. For more information, read <a href="filename.html#nam">here</a>.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
-<tr><td>0</td><td>Disable relative path function and remove related functions.</td></tr>
-<tr><td>1</td><td>Enable relative path function. <tt>f_chdir</tt> and <tt>f_chdrive</tt> function is available.</td></tr>
+<tr><td>0</td><td>Disable relative path and remove related functions.</td></tr>
+<tr><td>1</td><td>Enable relative path. <tt>f_chdir</tt> and <tt>f_chdrive</tt> function is available.</td></tr>
<tr><td>2</td><td><tt>f_getcwd</tt> function is available in addition to 1</td></tr>
</table>
@@ -204,43 +222,39 @@ <h3>Volume/Drive Configurations</h3>
<h4 id="volumes">FF_VOLUMES</h4>
-<p>This option configures number of volumes (logical drives upto 10) to be used.</p>
+<p>This option configures number of volumes (logical drives up to 10) to be used.</p>
<h4 id="str_volume_id">FF_STR_VOLUME_ID</h4>
<p>This option switches the support for string volume ID. When arbitrary string for the volume ID is enabled for the drive prefix, also pre-defined strings by <tt>FF_VOLUME_STRS</tt> or user defined strings can be used as drive prefix in the path name. Numeric drive number is always valid regardless of this option, and also either format of drive prefix can be enabled by this option.</p>
<table class="lst2">
<tr><th>Value</th><th>Description</th><th>Example</th></tr>
-<tr><td>0</td><td>Only DOS/Windows style drive prefix in numeric ID can be used.</td><td>0:/filename</td></tr>
+<tr><td>0</td><td>Only DOS/Windows style drive prefix in numeric ID can be used.</td><td>1:/filename</td></tr>
<tr><td>1</td><td>Also DOS/Windows style drive prefix in string ID can be used.</td><td>flash:/filename</td></tr>
<tr><td>2</td><td>Also Unix style drive prefix in string ID can be used.</td><td>/flash/filename</td></tr>
</table>
<h4 id="volume_strs">FF_VOLUME_STRS</h4>
-<p>This option defines the volume ID strings for each logical drives. Number of items must not be less than <tt>FF_VOLUMES</tt>. Valid characters for the volume ID string are A-Z, a-z and 0-9, however, they are compared in case-insensitive. If <tt>FF_STR_VOLUME_ID == 0</tt>, this option has no effect. If <tt>FF_STR_VOLUME_ID >= 1</tt> and this option is not defined, a user defined volume string table needs to be defined as shown below.</p>
+<p>This option defines the volume ID strings for each logical drives. Number of items must not be less than <tt>FF_VOLUMES</tt>. Valid characters for the volume ID string are A-Z, a-z and 0-9, however, they are compared in case-insensitive. If <tt>FF_STR_VOLUME_ID == 0</tt>, this option has no effect. If <tt>FF_STR_VOLUME_ID >= 1</tt> and this option is not defined, a user defined volume string table needs to be defined as shown below. The table should not be modified on the fly.</p>
<pre>
-<span class="c">/* User defined volume ID strings for 0: 1: 2: 3: ... */</span>
-const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"};
+<span class="c">/* User defined volume ID strings for 0: to 3: */</span>
+const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb"};
</pre>
<h4 id="multi_partition">FF_MULTI_PARTITION</h4>
<p>Disable (0) or Enable (1). This option switches multi-partition function. By default (0), each logical drive number is bound to the same physical drive number and only a volume in the physical drive is mounted. When enabled, each logical drive is bound to the partition on the physical drive listed in the user defined partition resolution table <tt>VolToPart[]</tt>. Also <tt>f_fdisk</tt> funciton will be available. For more information, read <a href="filename.html#vol">here</a>.</p>
<h4 id="max_ss">FF_MIN_SS, FF_MAX_SS</h4>
-<p>This set of options defines the extent of sector size used on the low level disk I/O interface, <tt>disk_read</tt> and <tt>disk_write</tt> function. Valid values are 512, 1024, 2048 and 4096. <tt>FF_MIN_SS</tt> defines minimum sector size and <tt>FF_MAX_SS</tt> defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When <tt>FF_MAX_SS > FF_MIN_SS</tt>, support of variable sector size is enabled and <tt>GET_SECTOR_SIZE</tt> command needs to be implemented to the <tt>disk_ioctl</tt> function.</p>
+<p>This set of options defines the extent of sector size used for the low level disk I/O interface, <tt>disk_read</tt> and <tt>disk_write</tt> function. Valid values are 512, 1024, 2048 and 4096. <tt>FF_MIN_SS</tt> defines minimum sector size and <tt>FF_MAX_SS</tt> defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When <tt>FF_MAX_SS > FF_MIN_SS</tt>, support of variable sector size is enabled and <tt>GET_SECTOR_SIZE</tt> command needs to be implemented to the <tt>disk_ioctl</tt> function.</p>
+
+<h4 id="fs_lba64">FF_LBA64</h4>
+<p>This option switches media access interface to 64-bit LBA and enables GUID Partition Table (GPT) for partition management, Enabled (1) or Disabled (0). exFAT filesystem needs to be enabled to enable this feature.</p>
+
+<h4 id="fs_gptmin">FF_MIN_GPT</h4>
+<p>This option specifies the threshold of determination of partitioning format when create patitions on the drive in <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function. When number of available sectors is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when <tt>FF_LBA64 == 0</tt>.</p>
<h4 id="use_trim">FF_USE_TRIM</h4>
<p>Disable (0) or Enable (1). This option switches ATA-TRIM function. To enable Trim function, also <tt>CTRL_TRIM</tt> command should be implemented to the <tt>disk_ioctl</tt> function.</p>
-<h4 id="fs_nofsinfo">FF_FS_NOFSINFO</h4>
-<p>0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and <tt>f_getfree</tt> function at first time after volume mount will force a full FAT scan. Bit 1 controls the use of last allocated cluster number.</p>
-<table class="lst1">
-<tr><th>Value</th><th>Description</th></tr>
-<tr><td>bit0=0</td><td>Use free cluster count in the FSINFO if available.</td></tr>
-<tr><td>bit0=1</td><td>Do not trust free cluster count in the FSINFO.</td></tr>
-<tr><td>bit1=0</td><td>Use last allocated cluster number in the FSINFO to find a free cluster if available.</td></tr>
-<tr><td>bit1=1</td><td>Do not trust last allocated cluster number in the FSINFO.</td></tr>
-</table>
-
</div>
@@ -248,33 +262,40 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"}; <h3>System Configurations</h3>
<h4 id="fs_tiny">FF_FS_TINY</h4>
-<p>Normal (0) or Tiny (1). At the tiny configuration, size of the file object <tt>FIL</tt> is reduced <tt>FF_MAX_SS</tt> bytes. Instead of private data buffer eliminated from the file object, common sector buffer in the filesystem object <tt>FATFS</tt> is used for the file data transfer.</p>
+<p>Normal (0) or Tiny (1). The tiny configuration reduces size of the <tt>FIL</tt> structure, file object, <tt>FF_MAX_SS</tt> bytes each. Instead of private sector buffer eliminated from the file object, common sector buffer in the <tt>FATFS</tt> structure, filesystem object, is used for the file data transfer.</p>
<h4 id="fs_exfat">FF_FS_EXFAT</h4>
-<p>This option switches support for the exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing <tt>FF_LFN_UNICODE >= 1</tt> and <tt>FF_MAX_LFN == 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.</p>
+<p>This option switches support for exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing <tt>FF_LFN_UNICODE >= 1</tt> and <tt>FF_MAX_LFN == 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility and wants C99 because of need for 64-bit integer type.</p>
<h4 id="fs_nortc">FF_FS_NORTC</h4>
-<p>Use RTC (0) or Do not use RTC (1). This option controls timestamp function. If the system does not have any RTC function or valid timestamp is not needed, set <tt>FF_FS_NORTC</tt> to 1 to disable the timestamp function. Every objects modified by FatFs will have a fixed timestamp defined by <tt>FF_NORTC_MON</tt>, <tt>FF_NORTC_MDAY</tt> and <tt>FF_NORTC_YEAR</tt>. To use the timestamp function, set <tt>FF_FS_NORTC == 0</tt> and add <tt>get_fattime</tt> function to the project to get current time form the RTC. This option has no effect at read-only configuration.</p>
+<p>Use RTC (0) or Do not use RTC (1). This option controls timestamp featuer. If the system does not have an RTC or valid timestamp is not needed, set <tt>FF_FS_NORTC</tt> to 1 to disable the timestamp function. Every objects modified by FatFs will have a constant timestamp defined by <tt>FF_NORTC_MON</tt>, <tt>FF_NORTC_MDAY</tt> and <tt>FF_NORTC_YEAR</tt>. To use the timestamp featuer, set <tt>FF_FS_NORTC == 0</tt> and add <tt>get_fattime</tt> function to the project to get current time form the RTC. This option has no effect in read-only configuration.</p>
<h4 id="nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</h4>
-<p>This set of options defines the time to be used at no RTC systems. This option has no effect at read-only configuration or <tt>FF_FS_NORTC == 0</tt>.</p>
+<p>This set of options defines the time to be used in no RTC systems. This option has no effect in read-only configuration or <tt>FF_FS_NORTC == 0</tt>.</p>
+
+<h4 id="fs_nofsinfo">FF_FS_NOFSINFO</h4>
+<p>0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and <tt>f_getfree</tt> function at first time after the volume mounted will force a full FAT scan. Bit 1 controls the use of last allocated cluster number for new allocation.</p>
+<table class="lst1">
+<tr><th>Value</th><th>Description</th></tr>
+<tr><td>bit0=0</td><td>Use free cluster count in the FSINFO if available.</td></tr>
+<tr><td>bit0=1</td><td>Do not trust free cluster count in the FSINFO.</td></tr>
+<tr><td>bit1=0</td><td>Use last allocated cluster number in the FSINFO to find a free cluster if available.</td></tr>
+<tr><td>bit1=1</td><td>Do not trust last allocated cluster number in the FSINFO.</td></tr>
+</table>
<h4 id="fs_lock">FF_FS_LOCK</h4>
-<p>This option switches file lock function to control duplicated file open and illegal operations to open objects. Note that the file lock function is independent of re-entrancy. This option must be 0 at read-only configuration.</p>
+<p>This option switches file lock feature to control duplicated file open and illegal operations to the open objects. Note that this feature is independent of re-entrancy. This option must be 0 in read-only configuration.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
-<tr><td>0</td><td>Disable file lock function. To avoid collapsing file by wrong file operation, application program needs to avoid illegal open, remove and rename to the open objects.</td></tr>
-<tr><td>>0</td><td>Enable file lock function. The value defines how many files/sub-directories can be opened simultaneously under the file lock control. Illigal operations to the open object will be rejected with <tt>FR_LOCKED</tt>.</td></tr>
+<tr><td>0</td><td>Disable file lock feature. To avoid to collapse files due to wrong file operations, application program needs to avoid illegal open, remove and rename to the open objects.</td></tr>
+<tr><td>>0</td><td>Enable file lock feature. The value defines how many files/sub-directories can be opened simultaneously under the file lock feature. Illigal operations to the open object will be rejected with <tt>FR_LOCKED</tt>.</td></tr>
</table>
<h4 id="fs_reentrant">FF_FS_REENTRANT</h4>
-<p>Disable (0) or Enable (1). This option switches the re-entrancy (thread safe) of the FatFs module itself. Note that file/directory access to the different volume is always re-entrant and it can work simultaneously regardless of this option but volume control functions. <tt>f_mount</tt>, <tt>f_mkfs</tt> and <tt>f_fdisk</tt>, are always not re-entrant. Only file/directory access to the same volume, in other words, exclusive use of each filesystem object, is under control of this function. To enable this feature, also user provided synchronization handlers, <tt>ff_req_grant</tt>, <tt>ff_rel_grant</tt>, <tt>ff_del_syncobj</tt> and <tt>ff_cre_syncobj</tt>, need to be added to the project. Sample code is available in <tt>ffsystem.c</tt>.</p>
+<p>Disable (0) or Enable (1). This option switches the re-entrancy (thread safe) of the FatFs module itself. Note that file/directory access to the different volume is always re-entrant and it can work simultaneously regardless of this option, however, volume management functions, <tt>f_mount</tt>, <tt>f_mkfs</tt> and <tt>f_fdisk</tt>, are <em>always not re-entrant</em>. Only file/directory access to the same volume, in other words, exclusive use of each filesystem object, is under control in this feature. To enable this feature, also user provided synchronization handlers, <tt>ff_mutex_take</tt>, <tt>ff_mutex_give</tt>, <tt>ff_mutex_create</tt> and <tt>ff_mutex_delete</tt>, need to be added to the project. Sample code is available in <tt>ffsystem.c</tt>.</p>
<h4 id="fs_timeout">FF_FS_TIMEOUT</h4>
-<p>Number of time ticks to abort the file function with <tt>FR_TIMEOUT</tt> when wait time is too long. This option has no effect when <tt>FF_FS_REENTRANT == 0</tt>.</p>
-
-<h4 id="sync_t">FF_SYNC_t</h4>
-<p>This option defines O/S dependent sync object type. e.g. <tt>HANDLE</tt>, <tt>ID</tt>, <tt>OS_EVENT*</tt>, <tt>SemaphoreHandle_t</tt> and etc. A header file for O/S definitions needs to be included somewhere in the scope of <tt>ff.c</tt>. This option has no effect when <tt>FF_FS_REENTRANT == 0</tt>.</p>
+<p>Number of O/S time ticks to abort the file function with <tt>FR_TIMEOUT</tt> when the wait time exceeds this period. This option has no effect when <tt>FF_FS_REENTRANT == 0</tt>.</p>
</div>
diff --git a/fatfs/documents/doc/dinit.html b/fatfs/documents/doc/dinit.html index a7718bc..c668c66 100644 --- a/fatfs/documents/doc/dinit.html +++ b/fatfs/documents/doc/dinit.html @@ -38,7 +38,7 @@ DSTATUS disk_initialize ( <div class="para desc">
<h4>Description</h4>
<p>This function initializes the storage device and put it ready to generic read/write. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleared.</p>
-<p><em>Remarks: This function needs to be under control of FatFs module. Application program MUST NOT call this function, or FAT structure on the volume can be broken. To re-initialize the filesystem, use <tt>f_mount</tt> function instead.</em></p>
+<p><em>Remarks: This function needs to be under control of FatFs module. Application program MUST NOT call this function while FatFs is in use, or FAT structure on the volume can be broken. To re-initialize the filesystem, use <tt>f_mount</tt> function instead.</em></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
diff --git a/fatfs/documents/doc/dioctl.html b/fatfs/documents/doc/dioctl.html index 15b9c8a..b7ad0aa 100644 --- a/fatfs/documents/doc/dioctl.html +++ b/fatfs/documents/doc/dioctl.html @@ -57,35 +57,35 @@ DRESULT disk_ioctl ( <table class="lst">
<caption>Standard ioctl command used by FatFs</caption>
<tr><th>Command</th><th>Description</th></tr>
-<tr><td>CTRL_SYNC</td><td>Make sure that the device has finished pending write process. If the disk I/O module has a write back cache, the dirty buffers must be written back to the media immediately. Nothing to do for this command if each write operation to the media is completed within the <tt>disk_write</tt> function.</td></tr>
-<tr><td>GET_SECTOR_COUNT</td><td>Returns number of available sectors on the drive into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function to determine the volume/partition size to be created. Required at <tt>FF_USE_MKFS == 1</tt>.</td></tr>
-<tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the device into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. Valid return values for this command are 512, 1024, 2048 and 4096. This command is required only if <tt>FF_MAX_SS > FF_MIN_SS</tt>. When <tt>FF_MAX_SS == FF_MIN_SS</tt>, this command is never used and the device must work at that sector size.</td></tr>
-<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory media in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or non flash memory media. This command is used by only <tt>f_mkfs</tt> function and it attempts to align data area on the erase block boundary. Required at <tt>FF_USE_MKFS == 1</tt>.</td></tr>
-<tr><td>CTRL_TRIM</td><td>Informs the device the data on the block of sectors is no longer needed and it can be erased. The sector block is specified by a <tt>DWORD</tt> array {<start sector>, <end sector>} pointed by <tt class="arg">buff</tt>. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the <tt>f_mkfs</tt> function. Required at <tt>FF_USE_TRIM == 1</tt>.</td></tr>
+<tr><td>CTRL_SYNC</td><td>Makes sure that the device has finished pending write process. If the disk I/O layer or storage device has a write-back cache, the dirty cache data must be committed to the medium immediately. Nothing to do for this command if each write operation to the medium is completed in the <tt>disk_write</tt> function.</td></tr>
+<tr><td>GET_SECTOR_COUNT</td><td>Retrieves number of available sectors, the largest allowable LBA + 1, on the drive into the <tt>LBA_t</tt> variable that pointed by <tt class="arg">buff</tt>. This command is used by <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function to determine the size of volume/partition to be created.</td></tr>
+<tr><td>GET_SECTOR_SIZE</td><td>Retrieves sector size, minimum data unit for generic read/write, into the <tt>WORD</tt> variable that pointed by <tt class="arg">buff</tt>. Valid sector sizes are 512, 1024, 2048 and 4096. This command is required only if <tt>FF_MAX_SS > FF_MIN_SS</tt>. When <tt>FF_MAX_SS == FF_MIN_SS</tt>, this command will never be used and the <tt>disk_read</tt> and <tt>disk_write</tt> function must work in <tt>FF_MAX_SS</tt> bytes/sector.</td></tr>
+<tr><td>GET_BLOCK_SIZE</td><td>Retrieves <em>erase block size in unit of sector</em> of the flash memory media into the <tt>DWORD</tt> variable that pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if it is unknown or in non flash memory media. This command is used by <tt>f_mkfs</tt> function with block size not specified and it attempts to align the data area on the suggested block boundary. Note that FatFs does not have FTL (flash translation layer), so that either disk I/O layter or storage device must have an FTL in it.</td></tr>
+<tr><td>CTRL_TRIM</td><td>Informs the disk I/O layter or the storage device that the data on the block of sectors is no longer needed and it can be erased. The sector block is specified in an <tt>LBA_t</tt> array <tt>{<Start LBA>, <End LBA>}</tt> that pointed by <tt class="arg">buff</tt>. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the <tt>f_mkfs</tt> function. It is required when <tt>FF_USE_TRIM == 1</tt>.</td></tr>
</table>
-<p>FatFs never uses any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.</p>
+<p>FatFs will never use any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.</p>
<table class="lst">
<caption>Example of optional ioctl command</caption>
<tr><th>Command</th><th>Description</th></tr>
-<tr><td>CTRL_FORMAT</td><td>Create a physical format on the media. If <tt class="arg">buff</tt> is not null, it is pointer to the call-back function for progress notification.</td></tr>
-<tr><td>CTRL_POWER_IDLE</td><td>Put the device idle state. <tt>STA_NOINIT</tt> in the current status flags may not be set if the device goes active state by generic read/write function.</td></tr>
-<tr><td>CTRL_POWER_OFF</td><td>Put the device off state. Shut-down the power to the device and deinitialize the device interface if needed. <tt>STA_NOINIT</tt> in the current status flags must be set. The device goes active state by <tt>disk_initialize</tt> function.</td></tr>
-<tr><td>CTRL_LOCK</td><td>Lock media eject mechanism.</td></tr>
-<tr><td>CTRL_UNLOCK</td><td>Unlock media eject mechanism.</td></tr>
-<tr><td>CTRL_EJECT</td><td>Eject media cartridge. <tt>STA_NOINIT</tt> and <tt>STA_NODISK</tt> in status flag are set after the function succeeded.</td></tr>
-<tr><td>CTRL_GET_SMART</td><td>Read SMART information.</td></tr>
-<tr><td>MMC_GET_TYPE</td><td>Get card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
-<tr><td>MMC_GET_CSD</td><td>Read CSD register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
-<tr><td>MMC_GET_CID</td><td>Read CID register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
-<tr><td>MMC_GET_OCR</td><td>Read OCR register into a 4-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
-<tr><td>MMC_GET_SDSTAT</td><td>Read SDSTATUS register into a 64-byte buffer pointed by <tt class="arg">buff</tt>. (SDC specific command)</td></tr>
-<tr><td>ATA_GET_REV</td><td>Get the revision string into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
-<tr><td>ATA_GET_MODEL</td><td>Get the model string into a 40-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
-<tr><td>ATA_GET_SN</td><td>Get the serial number string into a 20-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
-<tr><td>ISDIO_READ</td><td>Read a block of iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
-<tr><td>ISDIO_WRITE</td><td>Write a block of data to iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
-<tr><td>ISDIO_MRITE</td><td>Change bits in an iSDIO register specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
+<tr><td>CTRL_FORMAT</td><td>Creates a physical format on the media. If <tt class="arg">buff</tt> is not null, it is pointer to the call-back function for progress notification.</td></tr>
+<tr><td>CTRL_POWER_IDLE</td><td>Puts the device idle state. <tt>STA_NOINIT</tt> in the current status flags may not be set if the device goes active state by generic read/write function.</td></tr>
+<tr><td>CTRL_POWER_OFF</td><td>Puts the device off state. Shut-down the power to the device and deinitialize the device interface if needed. <tt>STA_NOINIT</tt> in the current status flags must be set. The device goes active state by <tt>disk_initialize</tt> function.</td></tr>
+<tr><td>CTRL_LOCK</td><td>Locks media eject mechanism.</td></tr>
+<tr><td>CTRL_UNLOCK</td><td>Unlocks media eject mechanism.</td></tr>
+<tr><td>CTRL_EJECT</td><td>Ejects media cartridge. <tt>STA_NOINIT</tt> and <tt>STA_NODISK</tt> in status flag are set after the function succeeds.</td></tr>
+<tr><td>CTRL_GET_SMART</td><td>Reads SMART information.</td></tr>
+<tr><td>MMC_GET_TYPE</td><td>Gets card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a <tt>BYTE</tt> variable pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
+<tr><td>MMC_GET_CSD</td><td>Reads CSD register and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
+<tr><td>MMC_GET_CID</td><td>Reads CID register and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
+<tr><td>MMC_GET_OCR</td><td>Reads OCR register and sets it into a 4-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
+<tr><td>MMC_GET_SDSTAT</td><td>Reads SDSTATUS register and sets it into a 64-byte buffer pointed by <tt class="arg">buff</tt>. (SDC specific command)</td></tr>
+<tr><td>ATA_GET_REV</td><td>Reads the revision string and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
+<tr><td>ATA_GET_MODEL</td><td>Reads the model string and sets it into a 40-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
+<tr><td>ATA_GET_SN</td><td>Reads the serial number string and sets it into a 20-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
+<tr><td>ISDIO_READ</td><td>Reads a block of iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
+<tr><td>ISDIO_WRITE</td><td>Writes a block of data to iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
+<tr><td>ISDIO_MRITE</td><td>Changes bits in an iSDIO register specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
</table>
</div>
diff --git a/fatfs/documents/doc/dread.html b/fatfs/documents/doc/dread.html index 75b52c0..1be191b 100644 --- a/fatfs/documents/doc/dread.html +++ b/fatfs/documents/doc/dread.html @@ -13,12 +13,12 @@ <div class="para func">
<h2>disk_read</h2>
-<p>The disk_read function is called to read data from the sector(s) of storage device.</p>
+<p>The disk_read function is called to read data from the storage device.</p>
<pre>
DRESULT disk_read (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read data buffer */</span>
- DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Start sector number */</span>
+ LBA_t <span class="arg">sector</span>, <span class="c">/* [IN] Start sector number */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectros to read */</span>
);
</pre>
@@ -32,7 +32,7 @@ DRESULT disk_read ( <dt>buff</dt>
<dd>Pointer to the first item of the <em>byte array</em> to store read data. Size of read data will be the sector size * <tt class="arg">count</tt> bytes.</dd>
<dt>sector</dt>
-<dd>Start sector number in 32-bit LBA.</dd>
+<dd>Start sector number in LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd>
<dt>count</dt>
<dd>Number of sectors to read.</dd>
</dl>
@@ -56,13 +56,14 @@ DRESULT disk_read ( <div class="para desc">
<h4>Description</h4>
-<p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the read/write function must work at that sector size. When FatFs is configured for variable sector size (<tt>FF_MIN_SS < FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function immediately following <tt>disk_initialize</tt> function succeeded.</p>
-<p>The memory address specified by <tt class="arg">buff</tt> is not that always aligned to word boundary because the argument is defined as <tt>BYTE*</tt>. The unaligned read/write request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.</p>
+<p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the generic read/write function must work at this sector size only. When FatFs is configured for variable sector size (<tt>FF_MIN_SS < FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function after <tt>disk_initialize</tt> function succeeds.</p>
+<p>There are some considerations about the memory addres passed via <tt class="arg">buff</tt>. It is not that always aligned with the word boundary, because the argument is defined as <tt>BYTE*</tt>. The unaligned transfer request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. If it is the case, there are some workarounds described below to avoid this issue.</p>
<ul>
-<li>Convert word transfer to byte transfer in this function if needed. - Recommended.</li>
+<li>Convert word transfer to byte transfer with some trick in this function. - Recommended.</li>
<li>On the <tt>f_read()</tt> calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.</li>
-<li>On the <tt>f_read(fp, dat, btw, bw)</tt> calls, make sure that <tt>(((UINT)dat & 3) == (f_tell(fp) & 3))</tt> is true. - Word alignment of <tt class="arg">buff</tt> is guaranteed no matter dat is not word aligned.</li>
+<li>On the <tt>f_read(fp, data, btw, bw)</tt> calls, make sure that <tt>(((UINT)data & 3) == (f_tell(fp) & 3))</tt> is true. - Word alignment of <tt class="arg">buff</tt> is guaranteed.</li>
</ul>
+<p>Also the memory area may be out of reach in DMA. This is the case if it is located on the tightly coupled memory which is usually used for stack. Use double buffered transfer, or avoid to define file I/O buffer, <tt>FATFS</tt> and <tt>FIL</tt> structure as local variables where on the stack.</p>
<p>Generally, a multiple sector read request must not be split into single sector transactions to the storage device, or read throughput gets worse.</p>
</div>
diff --git a/fatfs/documents/doc/dstat.html b/fatfs/documents/doc/dstat.html index e9926bb..a891489 100644 --- a/fatfs/documents/doc/dstat.html +++ b/fatfs/documents/doc/dstat.html @@ -25,7 +25,7 @@ DSTATUS disk_status ( <h4>Parameter</h4>
<dl class="par">
<dt>pdrv</dt>
-<dd>Physical drive number to identify the target device. Always zero at single drive system.</dd>
+<dd>Physical drive number to identify the target device. Always zero in single drive system.</dd>
</dl>
</div>
@@ -37,9 +37,9 @@ DSTATUS disk_status ( <dt>STA_NOINIT</dt>
<dd>Indicates that the device has not been initialized and not ready to work. This flag is set on system reset, media removal or failure of <a href="dinit.html"><tt>disk_initialize</tt></a> function. It is cleared on <tt>disk_initialize</tt> function succeeded. Any media change that occurs asynchronously must be captured and reflect it to the status flags, or auto-mount function will not work correctly. If the system does not support media change detection, application program needs to explicitly re-mount the volume with <tt>f_mount</tt> function after each media change.</dd>
<dt>STA_NODISK</dt>
-<dd>Indicates that no medium in the drive. This is always cleared at fixed disk drive. Note that FatFs does not refer this flag.</dd>
+<dd>Indicates that no medium in the drive. This is always cleared when the drive is non-removable class. Note that FatFs does not refer this flag.</dd>
<dt>STA_PROTECT</dt>
-<dd>Indicates that the medium is write protected. This is always cleared at the drives without write protect function. Not valid if <tt>STA_NODISK</tt> is set.</dd>
+<dd>Indicates that the medium is write protected. This is always cleared when the drive has no write protect function. Not valid if <tt>STA_NODISK</tt> is set.</dd>
</dl>
</div>
diff --git a/fatfs/documents/doc/dwrite.html b/fatfs/documents/doc/dwrite.html index 51174f9..fef5106 100644 --- a/fatfs/documents/doc/dwrite.html +++ b/fatfs/documents/doc/dwrite.html @@ -13,12 +13,12 @@ <div class="para func">
<h2>disk_write</h2>
-<p>The disk_write function is called to write data to the sector(s) of storage device.</p>
+<p>The disk_write function is called to write data to the storage device.</p>
<pre>
DRESULT disk_write (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
- DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Sector number to write from */</span>
+ LBA_t <span class="arg">sector</span>, <span class="c">/* [IN] Sector number to write from */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectors to write */</span>
);
</pre>
@@ -32,7 +32,7 @@ DRESULT disk_write ( <dt>buff</dt>
<dd>Pointer to the first item of the <em>byte array</em> to be written. The size of data to be written is sector size * <tt class="arg">count</tt> bytes.</dd>
<dt>sector</dt>
-<dd>Start sector number in 32-bit LBA.</dd>
+<dd>Start sector number in LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd>
<dt>count</dt>
<dd>Number of sectors to write.</dd>
</dl>
@@ -60,7 +60,7 @@ DRESULT disk_write ( <h4>Description</h4>
<p>The specified memory address is not that always aligned to word boundary because the argument is defined as <tt>BYTE*</tt>. For more information, refer to the description of <a href="dread.html"><tt>disk_read</tt></a> function.</p>
<p>Generally, a multiple sector write request (<tt class="arg">count</tt><tt> > 1</tt>) must not be split into single sector transactions to the storage device, or the file write throughput will be drastically decreased.</p>
-<p>FatFs expects delayed write function of the disk control layer. The write operation to the media does not need to be completed at return from this function by what write operation is in progress or data is only stored into the write-back cache. But write data on the <tt class="arg">buff</tt> is invalid after return from this function. The write completion request is done by <tt>CTRL_SYNC</tt> command of <tt><a href="dioctl.html">disk_ioctl</a></tt> function. Therefore, if a delayed write function is implemented, the write throughput of the filesystem will be improved.</p>
+<p>FatFs expects delayed write function of the disk control layer. The write operation to the media does not need to be completed when return from this function by what write operation is in progress or data is only stored into the write-back cache. But write data on the <tt class="arg">buff</tt> is invalid after return from this function. The write completion request is done by <tt>CTRL_SYNC</tt> command of <tt><a href="dioctl.html">disk_ioctl</a></tt> function. Therefore, if a delayed write function is implemented, the write throughput of the filesystem will be improved.</p>
<p><em>Remarks: Application program MUST NOT call this function, or FAT structure on the volume can be collapsed.</em></p>
</div>
diff --git a/fatfs/documents/doc/expand.html b/fatfs/documents/doc/expand.html index d64f483..7620ba9 100644 --- a/fatfs/documents/doc/expand.html +++ b/fatfs/documents/doc/expand.html @@ -19,7 +19,7 @@ FRESULT f_expand (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
FSIZE_t <span class="arg">fsz</span>, <span class="c">/* [IN] File size expanded to */</span>
- BYTE <span class="arg">opt</span> <span class="c">/* [IN] Operation mode */</span>
+ BYTE <span class="arg">opt</span> <span class="c">/* [IN] Allocation mode */</span>
);
</pre>
</div>
@@ -32,7 +32,7 @@ FRESULT f_expand ( <dt>fsz</dt>
<dd>Number of bytes in size to prepare or allocate for the file. The data type <tt>FSIZE_t</tt> is an alias of either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>.</dd>
<dt>opt</dt>
-<dd>Operation mode. Prepare only (0) or Allocate now (1).</dd>
+<dd>Allocation mode. Prepare to allocate (0) or Allocate now (1).</dd>
</dl>
</div>
@@ -52,16 +52,16 @@ FRESULT f_expand ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_expand</tt> function prepares or allocates a contiguous data area to the file. When <tt class="arg">opt</tt> is 1, the function allocates a contiguous data area to the file. Unlike expansion of file by <tt>f_lseek</tt> function, the file must be truncated prior to use this function and read/write pointer of the file stays at top of the file after the function. The file content allocated with this function is <em>undefined</em> because no data is written to the file in this process. The function can fail with <tt>FR_DENIED</tt> due to some reasons below.</p>
+<p>The <tt>f_expand</tt> function prepares or allocates a contiguous data area to the file. When <tt class="arg">opt</tt> is 1, the data area is allocated to the file in this function. Unlike expansion of file size by <tt>f_lseek</tt> function, the file must be truncated prior to use this function and read/write pointer of the file stays at offset 0 after the function call. The file content allocated with this function is <em>undefined</em>, because no data is written to the file in this process. The function can fail with <tt>FR_DENIED</tt> due to some reasons below.</p>
<ul>
<li>No free contiguous space was found.</li>
<li>Size of the file was not zero.</li>
<li>The file has been opened in read-only mode.</li>
<li>Not allowable file size. (>= 4 GB on FAT volume)</li>
</ul>
-<p>When <tt class="arg">opt</tt> is 0, the function finds a contiguous data area and set it as suggested point for next allocation instead of allocating it to the file. The next cluster allocation is started at top of the contiguous area found by this function. Thus the write file is guaranteed be contiguous and no allocation delay until the size reaches that size at least unless any other changes to the volume is performed.</p>
-<p>The contiguous file would have an advantage at time-critical read/write operations. It eliminates some overheads in the filesystem and the storage media caused by random access due to fragmented file data. Especially FAT access for the contiguous file on the exFAT volume is completely eliminated and storage media will be accessed sequentially.</p>
-<p>Also the contiguous file can be easily accessed directly via low-level disk functions. But this is not recommended in consideration for future compatibility.</p>
+<p>When <tt class="arg">opt</tt> is 0, the function finds a contiguous data area and set it as suggested point for next allocation. The subsequent cluster allocation begins at top of the contiguous area found by this function. Thus the file allocation is guaranteed be contiguous and without allocation delay until the file size reaches this size unless any other changes to the volume is performed.</p>
+<p>The contiguous file has an advantage for time-critical read/write operations. It eliminates some overheads in the filesystem and the storage device caused by random access for fragmented file.</p>
+<p>Also the contiguous file can be easily accessed directly via low-level disk functions. However, this is not recommended in consideration of portability and future compatibility. If the file has not been confirmed be contiguous, use <a href="../res/app5.c">this function</a> to examine if the file is contiguous or not.</p>
</div>
<div class="para comp">
diff --git a/fatfs/documents/doc/fattime.html b/fatfs/documents/doc/fattime.html index dfc4937..002733a 100644 --- a/fatfs/documents/doc/fattime.html +++ b/fatfs/documents/doc/fattime.html @@ -48,7 +48,30 @@ DWORD get_fattime (void); <div class="para comp">
<h4>QuickInfo</h4>
-<p>This function is not needed when <tt>FF_FS_READONLY == 1</tt> or <tt>FF_FS_NORTC == 1</tt>.</p>
+<p>This function is not needed when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 1</tt> or <tt><a href="config.html#fs_nortc">FF_FS_NORTC</a> == 1</tt>.</p>
+</div>
+
+
+<div class="para use">
+<h4>Example</h4>
+<pre>
+DWORD get_fattime (void)
+{
+ time_t t;
+ struct tm *stm;
+
+
+ t = time(0);
+ stm = localtime(&t);
+
+ return (DWORD)(stm->tm_year - 80) << 25 |
+ (DWORD)(stm->tm_mon + 1) << 21 |
+ (DWORD)stm->tm_mday << 16 |
+ (DWORD)stm->tm_hour << 11 |
+ (DWORD)stm->tm_min << 5 |
+ (DWORD)stm->tm_sec >> 1;
+}
+</pre>
</div>
diff --git a/fatfs/documents/doc/fdisk.html b/fatfs/documents/doc/fdisk.html index 1c0c1e1..d8c40bd 100644 --- a/fatfs/documents/doc/fdisk.html +++ b/fatfs/documents/doc/fdisk.html @@ -16,9 +16,9 @@ <p>The f_fdisk fucntion divides a physical drive.</p>
<pre>
FRESULT f_fdisk (
- BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
- const DWORD* <span class="arg">szt</span>, <span class="c">/* [IN] Partition map table */</span>
- void* <span class="arg">work</span> <span class="c">/* [IN] Work area */</span>
+ BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
+ const LBA_t <span class="arg">ptbl[]</span>, <span class="c">/* [IN] Partition map table */</span>
+ void* <span class="arg">work</span> <span class="c">/* [IN] Work area */</span>
);
</pre>
</div>
@@ -28,10 +28,10 @@ FRESULT f_fdisk ( <dl class="par">
<dt>pdrv</dt>
<dd>Specifies the <em>physical drive</em> to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.</dd>
-<dt>szt</dt>
-<dd>Pointer to the first item of the partition map table.</dd>
+<dt>ptbl</dt>
+<dd>List of partition size to create on the drive. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>.</dd>
<dt>work</dt>
-<dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given, the function allocates a memory block for the working buffer (at only <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>).</dd>
+<dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> = 3</tt>, a memory block is obtained in this function for the working buffer.</dd>
</dl>
</div>
@@ -49,7 +49,8 @@ FRESULT f_fdisk ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format is in generic FDISK format, so that it can create upto four primary partitions. Logical volumes in the extended partition is not supported. The partition map table with four items specifies how to divide the physical drive. The first item specifies the size of first primary partition and fourth item specifies the fourth primary partition. If the value is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. If it is larger than 100, it specifies the partition size in unit of sector. The partitions are located on the drive in order of from first item.</p>
+<p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is truncated at end of the drive.</p>
+<p>By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (<tt>FF_LBA64 = 1</tt>) and the drive size is equal to or larger than <tt><a href="config.html#fs_gptmin">FF_MIN_GPT</a></tt> sectors. It can create over ten partitions on a drive.</p>
</div>
<div class="para comp">
@@ -60,24 +61,26 @@ FRESULT f_fdisk ( <div class="para use">
<h4>Example</h4>
<pre>
- <span class="c">/* Volume management table defined by user (required when FF_MULTI_PARTITION == 1) */</span>
+ <span class="c">/* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */</span>
- PARTITION VolToPart[] = {
- {0, 1}, <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span>
- {0, 2}, <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span>
- {1, 0} <span class="c">/* "2:" ==> Physical drive 1, auto detection */</span>
+ PARTITION VolToPart[FF_VOLUMES] = {
+ {0, 1}, <span class="c">/* "0:" ==> 1st partition in PD#0 */</span>
+ {0, 2}, <span class="c">/* "1:" ==> 2nd partition in PD#0 */</span>
+ {1, 0} <span class="c">/* "2:" ==> PD#1 as removable drive */</span>
};
</pre>
<pre>
<span class="c">/* Initialize a brand-new disk drive mapped to physical drive 0 */</span>
- DWORD plist[] = {50, 50, 0, 0}; <span class="c">/* Divide drive into two partitions */</span>
- BYTE work[FF_MAX_SS];
+ BYTE work[FF_MAX_SS]; <span class="c">/* Working buffer */</span>
+ LBA_t plist[] = {50, 50, 0}; <span class="c">/* Divide the drive into two partitions */</span>
+ <span class="c">/* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */</span>
+ <span class="c">/* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */</span>
<em>f_fdisk</em>(0, plist, work); <span class="c">/* Divide physical drive 0 */</span>
- f_mkfs("0:", FM_ANY, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span>
- f_mkfs("1:", FM_ANY, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span>
+ f_mkfs("0:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span>
+ f_mkfs("1:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span>
</pre>
</div>
diff --git a/fatfs/documents/doc/filename.html b/fatfs/documents/doc/filename.html index dfc285e..8ff028d 100644 --- a/fatfs/documents/doc/filename.html +++ b/fatfs/documents/doc/filename.html @@ -10,16 +10,16 @@ </head>
<body>
-<h1>Path Names on the FatFs</h1>
+<h1>Path Names on the FatFs API</h1>
<div class="para doc" id="nam">
<h3>Format of the Path Names</h3>
<p>The format of path name on the FatFs module is similer to the filename specs of DOS/Windos as follows:</p>
<pre>[<em>drive#</em>:][/]<em>directory</em>/<em>file</em></pre>
-<p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when <tt><a href="config.html#use_lfn">FF_USE_LFN</a> >= 1</tt>. The sub directories are separated with a <tt>\</tt> or <tt>/</tt> in the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the heading drive prefix to specify logical drive is in a numeral + colon. When drive prefix is omitted, the drive number is assumed as <em>default drive</em> (drive 0 or current drive).</p>
-<p>Control characters (<tt>\0</tt> to <tt>\x1F</tt>) are recognized as end of the path name. Leading/embedded white spaces in the path name are valid as a part of the name at LFN configuration but the white space is recognized as end of the path name at non-LFN configuration. Trailing white spaces and dots are ignored at both configurations.</p>
-<p>In default configuration (<tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> == 0</tt>), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name that followed from the root directory. Dot directory names (<tt>".", ".."</tt>) are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.</p>
-<p>When relative path is enabled (<tt>FF_FS_RPATH >= 1</tt>), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the drive set by <a href="chdir.html"><tt>f_chdir</tt></a> function. Dot names are also allowed for the path names. The default drive is the current drive set by <a href="chdrive.html"><tt>f_chdrive</tt></a> function.</p>
+<p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when <tt><a href="config.html#use_lfn">FF_USE_LFN</a> >= 1</tt>. The sub-directories are separated with a <tt>\</tt> or <tt>/</tt> as the same way as DOS/Windows API. Duplicated separator and terminating separator, such as <tt>"/<em>/</em>animal/<em>//</em>cat<em>/</em>"</tt>, are ignored. Only a difference is that the heading drive prefix to specify the <a href="#vol">logical drive</a>, an FAT volume, is in a digit (0-9) + a colon, while it is in an alphabet (A-Z) + a colon in DOS/Windows. The logical drive number is the identifier to specify the volume to be accessed. When drive prefix is omitted, the logical drive number is assumed as <em>default drive</em>.</p>
+<p>Control characters (<tt>\0</tt> to <tt>\x1F</tt>) are recognized as end of the path name. In LFN configuration, leading or embedded white spaces in the file name are valid as part of the file name, but the treminating white space and dot of the file name are ignored and truncated. In non-LFN configuration, white space is recognized as end of the path name.</p>
+<p>In default configuration (<tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> == 0</tt>), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name followed from the root directory. Dot directory names (<tt>".", ".."</tt>) are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.</p>
+<p>When relative path feature is enabled (<tt>FF_FS_RPATH >= 1</tt>), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the default drive. Dot directory name is also allowed for the path name. The current directory is set by <a href="chdir.html"><tt>f_chdir</tt></a> function and the default drive is the current drive set by <a href="chdrive.html"><tt>f_chdrive</tt></a> function.</p>
<table class="lst2">
<tr><td>Path name</td><td>FF_FS_RPATH == 0</td><td>FF_FS_RPATH >= 1</td></tr>
<tr class="lst3"><td>file.txt</td><td>A file in the root directory of the drive 0</td><td>A file in the current directory of the current drive</td></tr>
@@ -35,51 +35,57 @@ <tr><td>dir1/..</td><td>Invalid name</td><td>The current directory</td></tr>
<tr><td>/..</td><td>Invalid name</td><td>The root directory (sticks the top level)</td></tr>
</table>
-<p>Also the drive prefix can be in pre-defined arbitrary string. When the option <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 1</tt>, also arbitrary string volume ID can be used as drive prefix. e.g. <tt>"flash:file1.txt"</tt>, <tt>"ram:temp.dat"</tt> or <tt>"usb:"</tt>. When <tt>FF_STR_VOLUME_ID == 2</tt>, Unix style drive prefix can be used. e.g. <tt>"/flash/file1.txt"</tt>, <tt>"/ram/temp.dat"</tt> or <tt>"/usb"</tt>. However, it cannot traverse the drives such as <tt>"/flash/../ram/temp.dat"</tt>. The Unix style drive prefix may lead a confusion in identification between volume ID and file name. For instance, which does <tt>"/flash"</tt> mean, a file <tt>"flash"</tt> on the root directory without drive prefix or a drive prefix of <tt>"flash"</tt>? If the string following a heading slash matches with any volume ID, it is treated as a drive prefix and skipped over.</p>
-
+<p>Also the drive prefix can be in pre-defined arbitrary string. When the option <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 1</tt>, also arbitrary string volume ID can be used as drive prefix. e.g. <tt>"<em>flash:</em>file1.txt"</tt>, <tt>"<em>ram:</em>temp.dat"</tt> or <tt>"<em>sd:</em>"</tt>. If the srting does not match any volume ID, the function fails with <tt>FR_INVALID_DRIVE</tt>.</p>
+<p>When <tt>FF_STR_VOLUME_ID == 2</tt>, Unix style drive prefix can be used. e.g. <tt>"<em>/flash</em>/file1.txt"</tt>, <tt>"<em>/ram</em>/temp.dat"</tt> or <tt>"<em>/sd</em>"</tt>. If a heading separator is exist, it is treated as start of drive prefix and in absolute path. Any form as "root directory in current drive" and "current directory in specified drive" cannot be used. Double dot name cannot traverse the drives such as <tt>"<em>/flash</em>/..<em>/ram</em>/foo.dat"</tt>.</p>
<p><em>Remark: In this revision, double dot name <tt>".."</tt> cannot follow the parent directory on the exFAT volume. It will work as <tt>"."</tt> and stay there.</em></p>
</div>
<div class="para doc" id="case">
<h3>Legal Characters and Case Sensitivity</h3>
-<p>On the FAT filesystem, legal characters for object name (file/directory name) are, <tt>0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~</tt> and extended characters (<tt>\x80</tt>-<tt>\xFF</tt>). Under LFN supported system, also <tt>+ , ; = [ ]</tt> and white space are legal for the object name and the white spaces and dots can be placed anywhere in the path name except for end of the object name.</p>
-<p>FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, <tt>file.txt</tt>, <tt>File.Txt</tt> and <tt>FILE.TXT</tt>, are identical. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN function is enabled.</p>
-<p>As for the MS-DOS and PC DOS for CJK, it was case-sensitive to the DBCS extended characters. To follow this specification, FatFs works with case-sensitive to the extended characters at only non-LFN with DBCS configuration (DOS/DBCS specs). But at LFN configuration, FatFs works with case-insensitive to the extended character (WindowsNT specs). This can cause a problem on compatibility with Windows system when an object with extended characters is created on the volume at non-LFN and DBCS configuration; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems.</p>
+<p>In the generic FAT filesystems, the legal characters for object name (file/directory name) are, <tt>0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~</tt> in ASCII and extended characters <tt>\x80</tt> to <tt>\xFF</tt>. In the FAT filesystems with LFN extention, also <tt>+ , ; = [ ]</tt>, white space and extended characters <tt>U+000080</tt> to <tt>U+10FFFF</tt> are legal for the object name. White spaces and dots can be placed anywhere in the path name except end of the name. Trailing white spaces and dots are ignored.</p>
+<p>FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, <tt>file.txt</tt>, <tt>File.Txt</tt> and <tt>FILE.TXT</tt>, are identical on the FAT filesystem. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN extension is exist.</p>
+<p>As for the MS-DOS and PC DOS for CJK (DOS/DBCS), extended characters ware recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on compatibility with Windows system when the object with extended characters is created on the volume by DOS/DBCS system; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems. FatFs works with case-sensitive to the extended characters in only non-LFN with DBCS configuration (DOS/DBCS specs). However, FatFs works with case-insensitive to the extended character (WindowsNT specs) in LFN configuration.</p>
</div>
<div class="para doc" id="uni">
<h3>Unicode API</h3>
-<p>The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> by default and the code set used for the path name string is ANSI/OEM specifid by <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>. When <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt> is set to 1, the type of the <tt>TCHAR</tt> is switched to <tt>WCHAR</tt> to support UTF-16 encoded Unicode string. When UTF-16 or UTF-8 is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.</p>
+<p>The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> by default and the code set used for the path name string is ANSI/OEM specifid by <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>. When <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt> is set to 1 or larger, the type of the <tt>TCHAR</tt> is switched to proper type to support the Unicode string. When Unicode API is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭ and any character not in BMP, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to specify the string in proper type. The code shown below is an example to define the literal strings.</p>
<pre>
- f_open(fp, "filename.txt", FA_READ); <span class="c">/* ANSI/OEM string (char) */</span>
- f_open(fp, L"filename.txt", FA_READ); <span class="c">/* UTF-16 string (WCHAR) */</span>
- f_open(fp, u8"filename.txt", FA_READ); <span class="c">/* UTF-8 string (char) */</span>
- f_open(fp, U"filename.txt", FA_READ); <span class="c">/* UTF-32 string (DWORD) */</span>
- f_open(fp, _T("filename.txt"), FA_READ); <span class="c">/* Changed by configuration (TCHAR) */</span>
+ f_open(fp, <span class="e">"filename.txt"</span>, FA_READ); <span class="c">/* ANSI/OEM string (char) */</span>
+ f_open(fp, <span class="e">L"filename.txt"</span>, FA_READ); <span class="c">/* UTF-16 string (WCHAR) */</span>
+ f_open(fp, <span class="e">u8"filename.txt"</span>, FA_READ); <span class="c">/* UTF-8 string (char) */</span>
+ f_open(fp, <span class="e">U"filename.txt"</span>, FA_READ); <span class="c">/* UTF-32 string (DWORD) */</span>
+ f_open(fp, <span class="e">_T("filename.txt")</span>, FA_READ); <span class="c">/* Changed by configuration (TCHAR) */</span>
</pre>
</div>
<div class="para doc" id="vol">
<h3>Volume Management</h3>
-<p>FatFs module requires dynamic work area, <em>filesystem object</em>, for each volume (logical drive). It is registered/unregistered to the FatFs module by <tt>f_mount</tt> function. By default, each logical drive is bound to the physical drive with the same drive number and an FAT volume on the drive is serched by the volume mount process. It reads boot sectors and checks it if it is an FAT boot sector in order of sector 0 as SFD format, 1st partition, 2nd partition, 3rd partition and 4th partition as FDISK format.</p>
-<p>When <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION = 1</a></tt> is specified by configuration option, each individual logical drive is bound to the partition on the physical drive specified by volume management table. The volume management table needs to be defined by user to resolve the mappings of logical drives and partitions. Following code is an example of a volume management table.</p>
+<p>By default, each logical drive is associated with the physical drive in same drive number. An FAT volume on the physical drive is serched in the volume mount process. It reads boot sectors and checks it if it is an FAT VBR in order of LBA 0 as SFD format, 1st partition, 2nd partition, 3rd partition, ..., as MBR or GPT format.</p>
+<p>When multiple partition feature is enabled, <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION = 1</a></tt>, each individual logical drive is associated with arbitrary partition or physical drive specified by volume management table, <tt>VolToPart[]</tt>. The table needs to be defined by user to resolve mappings of the logical drive numbers and the associated partitions or drives. Following code is an example of the volume management table.</p>
<pre>
-Example: "0:", "1:" and "2:" are tied to three pri-partitions on the physical drive 0 (fixed drive)
- "3:" is tied to an FAT volume on the physical drive 1 (removable drive)
+Example: "0:", "1:" and "2:" are associated with three partitions on the physical drive 0 (a non-removable drive)
+ "3:" is associated with physical drive 1 (a removable drive)
PARTITION VolToPart[FF_VOLUMES] = {
- {0, 1}, <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span>
- {0, 2}, <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span>
- {0, 3}, <span class="c">/* "2:" ==> Physical drive 0, 3rd partition */</span>
- {1, 0} <span class="c">/* "3:" ==> Physical drive 1, auto detection */</span>
+ {0, 1}, <span class="c">/* "0:" ==> 1st partition on the pd#0 */</span>
+ {0, 2}, <span class="c">/* "1:" ==> 2nd partition on the pd#0 */</span>
+ {0, 3}, <span class="c">/* "2:" ==> 3rd partition on the pd#0 */</span>
+ {1, 0} <span class="c">/* "3:" ==> pd#1 as removable drive (auto-search) */</span>
};
+
+
+<img src="../res/f7.png" width="900" height="288" alt="relationship between logical drive and physical drive">
</pre>
-<div><img src="../res/f7.png" width="900" height="288" alt="relationship between logical drive and physical drive"></div>
-<p>There are some considerations on using multi-partition configuration.</p>
+<p>There are some considerations when enable the multi-partition configuration.</p>
<ul>
-<li>The physical drive that has two or more mounted partitions must be non-removable. Media change while a system operation is prohibited.</li>
-<li>Only four primary partitions can be specified. Extended partition is not supported.</li>
-<li>Windows does not support multiple volumes on the removable storage. Only first parition will be recognized.</li>
+<li>The physical drive that hosts two or more mounted partitions should be non-removable, or all volumes on the drive must be unmounted when remove the medium.</li>
+<li>When make any change to the <tt>VolToPart[]</tt>, corresponding volume should be unmounted prior to make change the item.</li>
+<li>On the MBR format drive, up to four primary partitions (1-4) can be specified. The partition number 1 specifies the first item in the partition table and the partition number 2 specifies the second one, and so on. The logical patitions (5-) in the extended partition is not supported.</li>
+<li>On the GPT format drive, the partition number 1 specifies the first Microsoft BDP found in the partition table and the partition number 2 specifies the second one found, and so on.</li>
+<li>Windows 10 earlier than 1703 does not support multiple volumes on the physical drive with removable class. Only the first parition found on the drive will be mounted. Windows OS does not support SFD format on the physical drive with non-removable class.</li>
+<li>Some systems manage the on-board storage in non-standard partition format and each partition is mapped as physical drive in <tt>disk_*</tt> functions. For such system, <tt>FF_MULTI_PARTITION</tt> should be always 0.</li>
+<li>For further information about the volume management, refer to the description in <tt><a href="fdisk.html">f_fdisk</a></tt> and <tt><a href="mkfs.html">f_mkfs</a></tt>.</li>
</ul>
</div>
diff --git a/fatfs/documents/doc/findfirst.html b/fatfs/documents/doc/findfirst.html index daa6de6..5f1e344 100644 --- a/fatfs/documents/doc/findfirst.html +++ b/fatfs/documents/doc/findfirst.html @@ -61,12 +61,19 @@ FRESULT f_findfirst ( <div class="para desc">
<h4>Description</h4>
-<p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the name specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the object is stored into the file information structure <tt class="arg">fno</tt>.</p>
-<p>The matching pattern can contain wildcard characters (<tt>?</tt> and <tt>*</tt>). A <tt>?</tt> matches an any character and an <tt>*</tt> matches an any string in length of zero or longer. When support of long file name is enabled, only <tt>fname[]</tt> is tested at <tt>FF_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested at <tt>FF_USE_FIND == 2</tt>. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.</p>
+<p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the matching pattern specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the item is stored into the file information structure <tt class="arg">fno</tt>. If not found, <tt>fno->fname[]</tt> has a null string.</p>
+<p>The matching pattern string can contain wildcards. For example:</p>
<ul>
-<li><tt>"*.*"</tt> never matches any name without extension while it matches any name with or without extension at the standard systems.</li>
-<li>Any pattern terminated with a period never matches any name while it matches any name without extensiton at the standard systems.</li>
-<li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN with ANSI/OEM API.</li>
+<li><tt>?</tt> - An any character.</li>
+<li><tt>???</tt> - An any string in length of three characters.</li>
+<li><tt>*</tt> - An any string in length of zero or longer.</li>
+<li><tt>????*</tt> - An any string in length of four characters or longer.</li>
+</ul>
+<p>Since the matching algorithm uses recursion, number of wildcards in the matching pattern is limited to four to limit the stack usage. Any pattern with too many wildcards does not match any name. In LFN configuration, only <tt>fname[]</tt> is tested when <tt>FF_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested when <tt>FF_USE_FIND == 2</tt>. There are some differences listed below between FatFs and standard systems in matching condition.</p>
+<ul>
+<li><tt>"*.*"</tt> does not match any name without extension while it matches any name with or without extension in standard systems.</li>
+<li>Any pattern terminated with a dot does not match any name while it matches the name without extensiton in standard systems.</li>
+<li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive when LFN is enabled with <tt>!FF_LFN_UNICODE</tt>.</li>
</ul>
</div>
@@ -85,13 +92,13 @@ FRESULT f_findfirst ( void find_image_file (void)
{
FRESULT fr; <span class="c">/* Return value */</span>
- DIR dj; <span class="c">/* Directory search object */</span>
+ DIR dj; <span class="c">/* Directory object */</span>
FILINFO fno; <span class="c">/* File information */</span>
- fr = <em>f_findfirst</em>(&dj, &fno, "", "dsc*.jpg"); <span class="c">/* Start to search for photo files */</span>
+ fr = <em>f_findfirst</em>(&dj, &fno, "", "????????.JPG"); <span class="c">/* Start to search for photo files */</span>
while (fr == FR_OK && fno.fname[0]) { <span class="c">/* Repeat while an item is found */</span>
- printf("%s\n", fno.fname); <span class="c">/* Display the object name */</span>
+ printf("%s\n", fno.fname); <span class="c">/* Print the object name */</span>
fr = f_findnext(&dj, &fno); <span class="c">/* Search for next item */</span>
}
diff --git a/fatfs/documents/doc/forward.html b/fatfs/documents/doc/forward.html index ada0a05..fdb5f49 100644 --- a/fatfs/documents/doc/forward.html +++ b/fatfs/documents/doc/forward.html @@ -54,7 +54,7 @@ FRESULT f_forward ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_forward</tt> function reads the data from the file and forward it to the outgoing stream without data buffer. This is suitable for small memory system because it does not require any data buffer at application module. The file pointer of the file object increases in number of bytes forwarded. In case of <tt class="arg">*bf</tt> is less than <tt class="arg">btf</tt> without error, it means the requested bytes could not be transferred due to end of file or stream goes busy during data transfer.</p>
+<p>The <tt>f_forward</tt> function reads the data from the file and forward it to the outgoing stream. This function is suitable for small memory system, because it does not require any data buffer in the application module. The file pointer of the file object advances in number of bytes forwarded. In case of <tt class="arg">*bf</tt> is less than <tt class="arg">btf</tt> without error, it means the requested size of data could not be transferred due to end of file or stream goes busy during data transfer.</p>
</div>
@@ -65,7 +65,7 @@ FRESULT f_forward ( <div class="para use">
-<h4>Example (Audio playback)</h4>
+<h4>Example</h4>
<pre>
<span class="c">/*------------------------------------------------------------------------*/</span>
<span class="c">/* Sample code of data transfer function to be called back from f_forward */</span>
diff --git a/fatfs/documents/doc/getcwd.html b/fatfs/documents/doc/getcwd.html index d5eab61..6eb9a58 100644 --- a/fatfs/documents/doc/getcwd.html +++ b/fatfs/documents/doc/getcwd.html @@ -50,7 +50,7 @@ FRESULT f_getcwd ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_getcwd</tt> function retrieves full path name of the current directory of the current drive. When <tt><a href="config.html#volumes">FF_VOLUMES</a> >= 2</tt>, a heading drive prefix is added to the path name. The style of drive prefix is depends on <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a></tt>.</p>
+<p>The <tt>f_getcwd</tt> function retrieves full path name of the current directory of the current drive. When <tt><a href="config.html#volumes">FF_VOLUMES</a> >= 2</tt>, a heading drive prefix is added to the path name. The style of drive prefix depends on <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a></tt>.</p>
<p><em>Note: In this revision, this function cannot retrieve the current directory path on the exFAT volume. It always returns the root directory path.</em></p>
</div>
diff --git a/fatfs/documents/doc/getfree.html b/fatfs/documents/doc/getfree.html index cdc730b..5e4f419 100644 --- a/fatfs/documents/doc/getfree.html +++ b/fatfs/documents/doc/getfree.html @@ -53,7 +53,7 @@ FRESULT f_getfree ( <div class="para desc">
<h4>Descriptions</h4>
-<p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. When FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p>
+<p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. In case of FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p>
</div>
diff --git a/fatfs/documents/doc/getlabel.html b/fatfs/documents/doc/getlabel.html index dfe067d..0ec6d0d 100644 --- a/fatfs/documents/doc/getlabel.html +++ b/fatfs/documents/doc/getlabel.html @@ -34,7 +34,7 @@ FRESULT f_getlabel ( <tr><td>Configuration</td><td>FF_FS_EXFAT == 0</td><td>FF_FS_EXFAT == 1</td></tr>
<tr><td>FF_USE_LFN == 0</td><td>12 items</td><td>-</td></tr>
<tr><td>FF_LFN_UNICODE == 0</td><td>12 items</td><td>23 items</td></tr>
-<tr><td>FF_LFN_UNICODE == 1/3</td><td>12 items</td><td>12 items</td></tr>
+<tr><td>FF_LFN_UNICODE == 1,3</td><td>12 items</td><td>12 items</td></tr>
<tr><td>FF_LFN_UNICODE == 2</td><td>34 items</td><td>34 items</td></tr>
</table>
</dd>
diff --git a/fatfs/documents/doc/gets.html b/fatfs/documents/doc/gets.html index 8ab46f4..89d9560 100644 --- a/fatfs/documents/doc/gets.html +++ b/fatfs/documents/doc/gets.html @@ -45,7 +45,7 @@ TCHAR* f_gets ( <div class="para desc">
<h4>Description</h4>
<p>The read operation continues until a <tt>'\n'</tt> is stored, reached end of the file or the buffer is filled with <tt>len - 1</tt> characters. The read string is terminated with a <tt>'\0'</tt>. When no character to read or any error occured during read operation, it returns a null pointer. The status of EOF and error can be examined with <tt>f_eof</tt> and <tt>f_error</tt> function.</p>
-<p>When FatFs is configured to Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt>), data types on the srting fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt>, is also switched to Unicode. The character encoding <em>on the file</em> to be read via this function is assumed as <a href="config.html#strf_encode"><tt>FF_STRF_ENCODE</tt></a>. If the character encoding on the file differs from that on the API, it is converted in this function. In this case, input characters with wrong encoding will be lost.<p>
+<p>When FatFs is configured to Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt>), data types on the srting fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt>, is also switched to Unicode. The character encoding <em>on the file</em> to be read via this function is assumed as <a href="config.html#strf_encode"><tt>FF_STRF_ENCODE</tt></a>. If the character encoding on the file differs from that on the API, it is converted in this function. In this case, input characters with wrong encoding will be lost.</p>
</div>
diff --git a/fatfs/documents/doc/lseek.html b/fatfs/documents/doc/lseek.html index 7173b0e..ffd1f62 100644 --- a/fatfs/documents/doc/lseek.html +++ b/fatfs/documents/doc/lseek.html @@ -18,7 +18,12 @@ <pre>
FRESULT f_lseek (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
- FSIZE_t <span class="arg">ofs</span> <span class="c">/* [IN] File read/write pointer */</span>
+ FSIZE_t <span class="arg">ofs</span> <span class="c">/* [IN] Offset of file read/write pointer to be set */</span>
+);
+</pre>
+<pre>
+FRESULT f_rewind (
+ FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
@@ -48,14 +53,17 @@ FRESULT f_lseek ( <div class="para desc">
<h4>Description</h4>
-<p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file.</p>
-<p>When an offset beyond the file size is specified at write mode, the file size is expanded to the specified offset. The file data in the expanded area is <em>undefined</em> because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.</p>
+<p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file. The <tt>f_rewind</tt> function is impremented as a macro.</p>
+<pre>
+#define <em>f_rewind</em>(fp) f_lseek((fp), 0)
+</pre>
+<p>If an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset. The file data in the expanded part is <em>undefined</em>, because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not pointing expected offset, either of followings has been occured.</p>
<ul>
-<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file has been opened in read-only mode.</li>
+<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file in read-only mode.</li>
<li>Disk full. There is no free space on the volume to expand the file.</li>
</ul>
-<p>The fast seek function enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p>
-<p>The fast seek mode is enabled when the member <tt>cltbl</tt> in the file object is not NULL. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek function. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the first item and call the <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, when the file is fragmented in 5, 12 items in the array will be used. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file.</p>
+<p>The fast seek feature enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p>
+<p>The fast seek mode is available when <tt>FF_USE_FASTSEEK = 1</tt>. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek mode. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the <tt>cltbl[0]</tt> and then call <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the <tt>cltbl[0]</tt>. The number of items needed is (number of the file fragments + 1) * 2. For example, 12 items in the array will be used for the file fragmented in 5 portions. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the size of given array is insufficient for the file.</p>
</div>
@@ -73,16 +81,16 @@ FRESULT f_lseek ( res = f_open(fp, "file.dat", FA_READ|FA_WRITE);
if (res) ...
- <span class="c">/* Move to offset of 5000 from top of the file */</span>
+ <span class="c">/* Set read/write pointer to 5000 */</span>
res = <em>f_lseek</em>(fp, 5000);
- <span class="c">/* Move to end of the file to append data */</span>
+ <span class="c">/* Set read/write pointer to end of the file to append data */</span>
res = <em>f_lseek</em>(fp, f_size(fp));
- <span class="c">/* Forward 3000 bytes */</span>
+ <span class="c">/* Advance read/write pointer 3000 bytes */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) + 3000);
- <span class="c">/* Rewind 2000 bytes (take care on wraparound) */</span>
+ <span class="c">/* Rewind read/write pointer 2000 bytes (take care on wraparound) */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) - 2000);
</pre>
<pre>
@@ -93,17 +101,17 @@ FRESULT f_lseek ( res = <em>f_lseek</em>(fp, PRE_SIZE); <span class="c">/* Expand file size (cluster pre-allocation) */</span>
if (res || f_tell(fp) != PRE_SIZE) ... <span class="c">/* Check if the file has been expanded successfly */</span>
- res = <em>f_lseek</em>(fp, DATA_START); <span class="c">/* Record data stream WITHOUT cluster allocation delay */</span>
+ res = <em>f_lseek</em>(fp, OFS_DATA); <span class="c">/* Record data stream with free from cluster allocation delay */</span>
... <span class="c">/* Write operation should be aligned to sector boundary to optimize the write throughput */</span>
res = f_truncate(fp); <span class="c">/* Truncate unused area */</span>
- res = <em>f_lseek</em>(fp, 0); <span class="c">/* Set file header */</span>
+ res = <em>f_lseek</em>(fp, OFS_HEADER); <span class="c">/* Set file header */</span>
...
res = f_close(fp);
</pre>
<pre>
-<span class="c">/* Using fast seek function */</span>
+<span class="c">/* Using fast seek mode */</span>
DWORD clmt[SZ_TBL]; <span class="c">/* Cluster link map table buffer */</span>
@@ -111,7 +119,7 @@ FRESULT f_lseek ( res = <em>f_lseek</em>(fp, ofs1); <span class="c">/* This is normal seek (cltbl is nulled on file open) */</span>
- fp->cltbl = clmt; <span class="c">/* Enable fast seek function (cltbl != NULL) */</span>
+ fp->cltbl = clmt; <span class="c">/* Enable fast seek mode (cltbl != NULL) */</span>
clmt[0] = SZ_TBL; <span class="c">/* Set table size */</span>
res = <em>f_lseek</em>(fp, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
...
diff --git a/fatfs/documents/doc/mkfs.html b/fatfs/documents/doc/mkfs.html index 8e2bd1c..f40ebb0 100644 --- a/fatfs/documents/doc/mkfs.html +++ b/fatfs/documents/doc/mkfs.html @@ -13,14 +13,13 @@ <div class="para func">
<h2>f_mkfs</h2>
-<p>The f_mkfs fucntion creates an FAT/exFAT volume on the logical drive.</p>
+<p>The f_mkfs function creates an FAT/exFAT volume on the logical drive.</p>
<pre>
FRESULT f_mkfs (
- const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
- BYTE <span class="arg">opt</span>, <span class="c">/* [IN] Format options */</span>
- DWORD <span class="arg">au</span>, <span class="c">/* [IN] Size of the allocation unit */</span>
- void* <span class="arg">work</span>, <span class="c">/* [-] Working buffer */</span>
- UINT <span class="arg">len</span> <span class="c">/* [IN] Size of working buffer */</span>
+ const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
+ const MKFS_PARM* <span class="arg">opt</span>,<span class="c">/* [IN] Format options */</span>
+ void* <span class="arg">work</span>, <span class="c">/* [-] Working buffer */</span>
+ UINT <span class="arg">len</span> <span class="c">/* [IN] Size of working buffer */</span>
);
</pre>
</div>
@@ -29,15 +28,25 @@ FRESULT f_mkfs ( <h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
-<dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it has no drive number in it, it means the default drive. The logical drive may or may not be mounted for the format process.</dd>
+<dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it does not have a drive number in it, it means to specify the default drive. The logical drive may or may not have been mounted for the format process.</dd>
<dt>opt</dt>
-<dd>Specifies the format option in combination of <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format.</dd>
-<dt>au</dt>
-<dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is <em>n</em> times the sector size. The <em>n</em> is power of 2 from 1 to 128 for FAT volume and upto 16MiB for exFAT volume. If zero is given, the default allocation unit size is selected depends on the volume size.</dd>
+<dd>Specifies the format option structure <tt>MKFS_PARM</tt> holding format options. If a null pointer is given, it gives the function every option in default value. The structure has five members in order of described below:<br>
+<dl class="par">
+<dt>BYTE fmt</dt>
+<dd>Specifies a combination of FAT type flags, <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which type of FAT volume to be created. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au_size</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format. The default value is <tt>FM_ANY</tt>.</dd>
+<dt>BYTE n_fat</dt>
+<dd>Specifies number of FAT copies on the FAT/FAT32 volume. Valid value for this member is 1 or 2. The default value (0) and any invaid value gives 1. If the FAT type is exFAT, this member has no effect.</dd>
+<dt>UINT n_align</dt>
+<dd>Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash memory media) in unit of sector. The valid value for this member is between 1 and 32768 inclusive in power of 2. If a zero (the default value) or any invalid value is given, the function obtains the block size from lower layer with <tt>disk_ioctl</tt> function.</dd>
+<dt>DWORD au_size</dt>
+<dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is power of 2 between sector size and 128 * sector size inclusive for FAT/FAT32 volume, or up to 16 MB for exFAT volume. If a zero (default value) or any invalid value is given, the function uses default allocation unit size depends on the volume size.</dd>
+<dt>UINT n_root</dt>
+<dd>Specifies number of root directory entries on the FAT volume. Valid value for this member is up to 32768 and aligned to sector size / 32. The default value (0) and any invaid value gives 512. If the FAT type is FAT32 or exFAT, this member has no effect.</dd>
+</dl>
<dt>work</dt>
-<dd>Pointer to the working buffer used for the format process. When a null pointer is given, the function allocates a memory block for the working buffer and <tt class="arg">len</tt> has no effect (at only <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>).</dd>
+<dd>Pointer to the working buffer used for the format process. If a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>, the function uses a <tt>len</tt> bytes of heap memory in this function.</dd>
<dt>len</dt>
-<dd>Size of the working buffer in unit of byte. It needs to be the sector size of the corresponding physical drive at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.</dd>
+<dd>Size of the working buffer in unit of byte. It needs to be <tt>FF_MAX_SS</tt> at least. Plenty of working buffer reduces number of write transactions to the drive, thus the format process will finish quickly.</dd>
</dl>
</div>
@@ -57,11 +66,12 @@ FRESULT f_mkfs ( <div class="para desc">
<h4>Description</h4>
-<p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with <tt>FR_MKFS_ABORTED</tt>. The minimum drive size is 128 sectors with <tt>FM_SFD</tt> option.</p>
-<p>The allocation unit, also called <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases as the size of allocation unit. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.</p>
-<p>There are three disk partitioning formats, FDISK, SFD and GPT. The FDISK format is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table on the MBR (maser boot record, the first sector of the physical drive). The SFD (super-floppy disk) is non-partitioned disk format. The FAT volume starts at the first sector of the physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some systems support only either one of the two disk formats and the other is not supported. The GPT (GUID Partition Table) is a newly defined format for large storage devices. FatFs does not support the storages with GPT.</p>
-<p>When the logical drive to be formatted is bound to a physical drive and <tt>FM_SFD</tt> is not specified, a primary partition occupies whole drive space is created in FDISK format, and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> is specified, the FAT volume occupies from the first sector of the physical drive is created in SFD format.</p>
-<p>When the logical drive to be formatted is bound to a specific partition (1-4) by support of multiple partition (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 1</tt>), the FAT volume is created on the partition and <tt>FM_SFD</tt> flag is ignored. The physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any other partitioning tools prior to create the FAT volume with this function.</p>
+<p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument is not valid for the volume size, the function will fail with <tt>FR_MKFS_ABORTED</tt>.</p>
+<p>The allocation unit, also known as <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large volumes in GB order, 32768 bytes or larger, automatically selected by default, is recommended for most case unless extremely many small files are created in the volume.</p>
+<p>When the logical drive to be formatted is associated with a physical drive (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 0</tt> or <tt>VolToPart[].pt == 0</tt>) and <tt>FM_SFD</tt> flag is not specified, a partition occupies entire drive space is created and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> flag is specified, the FAT volume is created without any disk partitioning.</p>
+<p>When the logical drive to be formatted is associated with a specific partition by multiple partition feature (<tt>FF_MULTI_PARTITION == 1</tt> and <tt>VolToPart[].pt > 0</tt>), the FAT volume is created in the partition of the physical drive specified by <a href="filename.html#vol">volume mapping table</a> and <tt>FM_SFD</tt> flag is ignored. The hosting physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any partitioning tool prior to create the FAT volume with this function. If the partition is not exist, the function aborts with <tt>FR_MKFS_ABORTED</tt>.</p>
+<p>There are three standard disk partitioning formats, MBR, GPT and SFD. The MBR format, also known as FDISK format, is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table. The GPT, GUID Partition Table, is a newly defined patitioning format for large storage devices. FatFs suppors the GPT only when 64-bit LBA is enabled. The SFD, Super-Floppy Disk, is non-partitioned disk format. The FAT volume is located at LBA 0 and occupies the entire physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some combination of systems and media support only either partitioned format or non-partitioned format and the other is not supported.</p>
+<p>Some systems manage the partitions in the on-board storage in non-standard format. The partitions are mapped as physical drives identified by <tt class="arg">pdrv</tt> in <tt>disk_*</tt> functions. For such systems, SFD format is suitable to create the FAT volume in the partition.</p>
</div>
<div class="para comp">
@@ -82,11 +92,11 @@ int main (void) BYTE work[FF_MAX_SS]; <span class="c">/* Work area (larger is better for processing time) */</span>
- <span class="c">/* Create FAT volume */</span>
- res = <em>f_mkfs</em>("", FM_ANY, 0, work, sizeof work);
+ <span class="c">/* Format the default drive with default parameters */</span>
+ res = <em>f_mkfs</em>("", 0, work, sizeof work);
if (res) ...
- <span class="c">/* Register work area */</span>
+ <span class="c">/* Give a work area to the default drive */</span>
f_mount(&fs, "", 0);
<span class="c">/* Create a file as new */</span>
@@ -109,7 +119,7 @@ int main (void) <div class="para ref">
<h4>See Also</h4>
-<p><a href="../res/mkfs.xls">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p>
+<p><a href="../res/mkfs.xlsx">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
diff --git a/fatfs/documents/doc/mount.html b/fatfs/documents/doc/mount.html index 901ffc0..57f40be 100644 --- a/fatfs/documents/doc/mount.html +++ b/fatfs/documents/doc/mount.html @@ -13,7 +13,7 @@ <div class="para func">
<h2>f_mount</h2>
-<p>The f_mount fucntion registers/unregisters filesystem object to the FatFs module.</p>
+<p>The f_mount fucntion gives work area to the FatFs module.</p>
<pre>
FRESULT f_mount (
FATFS* <span class="arg">fs</span>, <span class="c">/* [IN] Filesystem object */</span>
@@ -21,6 +21,11 @@ FRESULT f_mount ( BYTE <span class="arg">opt</span> <span class="c">/* [IN] Initialization option */</span>
);
</pre>
+<pre>
+FRESULT f_unmount (
+ const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Logical drive number */</span>
+);
+</pre>
</div>
<div class="para arg">
@@ -50,7 +55,7 @@ FRESULT f_mount ( <div class="para desc">
<h4>Description</h4>
-<p>FatFs requires work area (<em>filesystem object</em>) for each logical drives (FAT volumes). Prior to perform file/directory operations, a filesystem object needs to be registered with <tt>f_mount</tt> function to the logical drive. The file/directory API functions get ready to work after this procedure. If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.</p>
+<p>FatFs requires work area (<em>filesystem object</em>) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with <tt>f_mount</tt> function for the logical drive. The file/directory API functions get ready to work after this procedure. Some volume management functions, <tt>f_mkfs</tt>, <tt>f_fdisk</tt> and <tt>f_setcp</tt>, do not want a filesystem object.</p>
<p>The <tt>f_mount</tt> function registers/unregisters a filesystem object to the FatFs module as follows:</p>
<ol>
<li>Determines the logical drive which specified by <tt class="arg">path</tt>.</li>
@@ -58,6 +63,7 @@ FRESULT f_mount ( <li>Clears and registers the new work area to the volume if <tt class="arg">fs</tt> is not NULL.</li>
<li>Performs volume mount process to the volume if forced mounting is specified.</li>
</ol>
+<p>If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.</p>
<p>If forced mounting is not specified (<tt>opt = 0</tt>), this function always succeeds regardless of the physical drive status. It only clears (de-initializes) the given work area and registers its address to the internal table and no activity of the physical drive in this function. The volume mount process will be attempted on subsequent file/directroy function if the filesystem object is not initialized. (delayed mounting) The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and then initialize the work area, is performed in the subsequent file/directory functions when either of following conditions is true.</p>
<ul>
<li>Filesystem object has not been initialized. It is de-initialized by <tt>f_mount</tt> function.</li>
@@ -65,7 +71,10 @@ FRESULT f_mount ( </ul>
<p>If the function with forced mounting (<tt>opt = 1</tt>) failed with <tt>FR_NOT_READY</tt>, it means that the filesystem object has been registered successfully but the volume is currently not ready to work. The volume mount process will be attempted on subsequent file/directroy function.</p>
<p>If implementation of the disk I/O layer lacks asynchronous media change detection, application program needs to perform <tt>f_mount</tt> function after each media change to force cleared the filesystem object.</p>
-<p>To unregister the work area, specify a NULL to the <tt class="arg">fs</tt>, and then the work area can be discarded.</p>
+<p>To unregister the work area, specify a NULL to the <tt class="arg">fs</tt>, and then the work area can be discarded. <tt>f_unmount</tt> function is implemented as a macro.</p>
+<pre>
+#define <em>f_unmount</em>(path) f_mount(0, path, 0)
+</pre>
</div>
diff --git a/fatfs/documents/doc/open.html b/fatfs/documents/doc/open.html index c00c5e4..cc8b87a 100644 --- a/fatfs/documents/doc/open.html +++ b/fatfs/documents/doc/open.html @@ -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>
<table class="lst">
<tr><th>Flags</th><th>Meaning</th></tr>
-<tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.</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_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_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 of POSIX fopen() corresponds to FatFs mode flags as follows:<br>
+Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:<br>
<table class="lst2">
<tr><th>POSIX</th><th>FatFs</th></tr>
<tr><td>"r"</td><td>FA_READ</td></tr>
@@ -86,7 +86,7 @@ Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:<br> <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 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>
+<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>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>
@@ -111,14 +111,14 @@ int main (void) FRESULT fr; <span class="c">/* FatFs return code */</span>
- <span class="c">/* Register work area to the default drive */</span>
+ <span class="c">/* Give a work area to the default drive */</span>
f_mount(&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 all lines and display it */</span>
+ <span class="c">/* Read every line and display it */</span>
while (f_gets(line, sizeof line, &fil)) {
printf(line);
}
@@ -134,16 +134,16 @@ int main (void) int main (void)
{
- FATFS fs[2]; <span class="c">/* Work area (filesystem object) for logical drives */</span>
+ FATFS fs0, fs1; <span class="c">/* Work area (filesystem object) for logical drives */</span>
FIL fsrc, fdst; <span class="c">/* File objects */</span>
BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>
FRESULT fr; <span class="c">/* FatFs function common result code */</span>
UINT br, bw; <span class="c">/* File read/write count */</span>
- <span class="c">/* Register work area for each logical drive */</span>
- f_mount(&fs[0], "0:", 0);
- f_mount(&fs[1], "1:", 0);
+ <span class="c">/* Give work areas to each logical drive */</span>
+ f_mount(&fs0, "0:", 0);
+ f_mount(&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,10 +155,10 @@ 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 source file */</span>
- if (fr || 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>
- if (fr || bw < br) break; <span class="c">/* error or disk full */</span>
+ fr = f_read(&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>
+ if (bw < br) break; <span class="c">/* error or disk full */</span>
}
<span class="c">/* Close open files */</span>
@@ -166,8 +166,8 @@ int main (void) f_close(&fdst);
<span class="c">/* Unregister work area prior to discard it */</span>
- f_mount(NULL, "0:", 0);
- f_mount(NULL, "1:", 0);
+ f_unmount("0:");
+ f_unmount("1:");
return (int)fr;
}
diff --git a/fatfs/documents/doc/printf.html b/fatfs/documents/doc/printf.html index 82be70c..eb64e8d 100644 --- a/fatfs/documents/doc/printf.html +++ b/fatfs/documents/doc/printf.html @@ -39,7 +39,7 @@ int f_printf ( <div class="para ret"> <h4>Return Values</h4> -<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p> +<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or an error, a negative value will be returned.</p> </div> @@ -47,14 +47,30 @@ int f_printf ( <h4>Description</h4> <p>The format control directive is a sub-set of standard library shown as follows:</p> <pre> - %[flag][width][type] + %[flag][width][precision][size]type </pre> <dl> -<dt>flag</dt><dd>Padding options. A <tt>-</tt> specifies left justified. A <tt>0</tt> specifies zero padded.</dd> -<dt>width</dt><dd>Minimum width of the field, <tt>1-99</tt> or <tt>*</tt>. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An <tt>*</tt> specifies the value comes from an argument in int type.</dd> -<dt>type</dt><dd><tt>c s d u o x b</tt> and prefix <tt>l</tt> specify type of the argument, character, string, signed integer in decimal, unsigned integer in decimal, unsigned integer in octal, unsigned integer in hexdecimal and unsigned integer in binary respectively. If <tt>sizeof (long)</tt> is greater than <tt>sizeof (int)</tt> (this is typical of 8/16-bit systems), a prefix <tt>l</tt> needs to be explicitly specified for long integer argument. These characters except for <tt>x</tt> are case insensitive.</dd> +<dt>flag</dt><dd>Padding option. A <tt>-</tt> specifies left-aligned. A <tt>0</tt> specifies zero padded. The default setting is in right-aligned and space padded.</dd> +<dt>width</dt><dd>Minimum width of the field, <tt>1-99</tt> or <tt>*</tt>. If the width of generated string is less than the minimum width, rest field is padded with spaces or zeros. An <tt>*</tt> specifies the value comes from an argument in int type. The default setting is zero.</dd> +<dt>precision</dt><dd>Specifies number of fractional digits or maximum width of string, <tt>.0-.99</tt> or <tt>.*</tt>. If the number is omitted, it is same as <tt>.0</tt>. Default setting is 6 for number and no limit for string.</dd> +<dt>size</dt><dd>Specifies size of integer argument, <tt>l</tt>(long) and <tt>ll</tt>(long long). If <tt>sizeof (long) == sizeof (int)</tt> is true (this is typical of 32-bit systems), prefix <tt>l</tt> can be omitted for long integer argument. The default size is int for integer argument and floating point argument is always assumed double as the default argument promotion.</dd> +<dt>type</dt><dd>Specifies type of the output format and the argument as shown below. The length of generated string is in assumtion of int is 32-bit. +<table class="lst1"> +<tr><th>Type</th><th>Format</th><th>Argument</th><th>Length</th></tr> +<tr><td><tt>c</tt></td><td>Character</td><td rowspan="6"><tt>int</tt>,<br><tt>long</tt>,<br><tt>long long</tt></td><td>1 character.</td></tr> +<tr><td><tt>d</tt></td><td>Signed decimal</td><td>1 to 11 (20 for ll) characters.</td></tr> +<tr><td><tt>u</tt></td><td>Unsigned decimal</td><td>1 to 10 (20 for ll) characters.</td></tr> +<tr><td><tt>o</tt></td><td>Unsigned octal</td><td>1 to 11 (22 for ll) characters.</td></tr> +<tr><td><tt>x X</tt></td><td>Unsigned hexdecimal</td><td>1 to 8 (16 for ll) characters.</td></tr> +<tr><td><tt>b</tt></td><td>Unsigned binary</td><td>1 to 32 characters. Limited to lower 32 digits when ll is specified.</td></tr> +<tr><td><tt>s</tt></td><td>String</td><td><tt>TCHAR*</tt></td><td>As input string. Null pointer generates a null string.</td></tr> +<tr><td><tt>f</tt></td><td>Floating point<br>(decimal)</td><td rowspan="2"><tt>double</tt></td><td>1 to 31 characters. If the number of characters exceeds 31, it writes <tt>"±OV"</tt>. Not a number and infinite write <tt>"NaN"</tt> and <tt>"±INF"</tt>.</td></tr> +<tr><td><tt>e E</tt></td><td>Floating point<br>(e notation)</td><td>4 to 31 characters. If the number of characters exceeds 31 or exponent exceeds +99, it writes <tt>"±OV"</tt>.</td></tr> +</table> +</dd> </dl> <p>When FatFs is configured for Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt>), character encoding on the string fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt> function, is also switched to Unicode. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding <em>on the file</em> to be written via this function is selected by <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a></tt>. The characters with wrong encoding or invalid for the output encoding will be lost.</p> +<p>If <tt>sprintf</tt> is used in the project and code conversion is not needed, <tt>f_write</tt> with <tt>sprintf</tt> will be efficient in code size and performance rather than <tt>f_printf</tt>.</p> </div> @@ -67,23 +83,24 @@ int f_printf ( <div class="para use"> <h4>Example</h4> <pre> - <em>f_printf</em>(&fil, "%d", 1234); <span class="c">/* "1234" */</span> - <em>f_printf</em>(&fil, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span> - <em>f_printf</em>(&fil, "%ld", 12345L); <span class="c">/* "12345" */</span> - <em>f_printf</em>(&fil, "%06d", 25); <span class="c">/* "000025" */</span> - <em>f_printf</em>(&fil, "%06d", -25); <span class="c">/* "000-25" */</span> - <em>f_printf</em>(&fil, "%*d", 5, 100); <span class="c">/* " 100" */</span> - <em>f_printf</em>(&fil, "%-6d", 25); <span class="c">/* "25 " */</span> - <em>f_printf</em>(&fil, "%u", -1); <span class="c">/* "65535" or "4294967295" */</span> - <em>f_printf</em>(&fil, "%04x", 0xAB3); <span class="c">/* "0ab3" */</span> - <em>f_printf</em>(&fil, "%08lX", 0x123ABCL); <span class="c">/* "00123ABC" */</span> - <em>f_printf</em>(&fil, "%04o", 255); <span class="c">/* "0377" */</span> - <em>f_printf</em>(&fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span> - <em>f_printf</em>(&fil, "%s", "String"); <span class="c">/* "String" */</span> - <em>f_printf</em>(&fil, "%8s", "abc"); <span class="c">/* " abc" */</span> - <em>f_printf</em>(&fil, "%-8s", "abc"); <span class="c">/* "abc " */</span> - <em>f_printf</em>(&fil, "%c", 'a'); <span class="c">/* "a" */</span> - <em>f_printf</em>(&fil, "%f", 10.0); <span class="c">/* f_printf lacks floating point support */</span> + <em>f_printf</em>(fp, "%d", 1234); <span class="c">/* "1234" */</span> + <em>f_printf</em>(fp, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span> + <em>f_printf</em>(fp, "%-6u", 100); <span class="c">/* "100 " */</span> + <em>f_printf</em>(fp, "%ld", 12345678); <span class="c">/* "12345678" */</span> + <em>f_printf</em>(fp, "%llu", 0x100000000); <span class="c">/* "4294967296" (<a href="config.html#print_lli">FF_PRINT_LLI</a>) */</span> + <em>f_printf</em>(fp, "%lld", -1LL); <span class="c">/* "-1" (FF_PRINT_LLI) */</span> + <em>f_printf</em>(fp, "%04x", 0xA3); <span class="c">/* "00a3" */</span> + <em>f_printf</em>(fp, "%08lX", 0x123ABC); <span class="c">/* "00123ABC" */</span> + <em>f_printf</em>(fp, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span> + <em>f_printf</em>(fp, "%*d", 6, 100); <span class="c">/* " 100" */</span> + <em>f_printf</em>(fp, "%s", "abcdefg"); <span class="c">/* "abcdefg" */</span> + <em>f_printf</em>(fp, "%5s", "abc"); <span class="c">/* " abc" */</span> + <em>f_printf</em>(fp, "%-5s", "abc"); <span class="c">/* "abc " */</span> + <em>f_printf</em>(fp, "%.5s", "abcdefg"); <span class="c">/* "abcde" */</span> + <em>f_printf</em>(fp, "%-5.2s", "abcdefg"); <span class="c">/* "ab " */</span> + <em>f_printf</em>(fp, "%c", 'a'); <span class="c">/* "a" */</span> + <em>f_printf</em>(fp, "%12f", 10.0); <span class="c">/* " 10.000000" (<a href="config.html#print_fp">FF_PRINT_FLOAT</a>) */</span> + <em>f_printf</em>(fp, "%.4E", 123.45678); <span class="c">/* "1.2346E+02" (FF_PRINT_FLOAT) */</span> </pre> </div> diff --git a/fatfs/documents/doc/putc.html b/fatfs/documents/doc/putc.html index 4d93bf5..747b5fd 100644 --- a/fatfs/documents/doc/putc.html +++ b/fatfs/documents/doc/putc.html @@ -35,7 +35,7 @@ int f_putc ( <div class="para ret">
<h4>Return Values</h4>
-<p>When the character was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
+<p>When the character was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, a negative value will be returned.</p>
</div>
diff --git a/fatfs/documents/doc/puts.html b/fatfs/documents/doc/puts.html index 92c7e74..3695942 100644 --- a/fatfs/documents/doc/puts.html +++ b/fatfs/documents/doc/puts.html @@ -35,7 +35,7 @@ int f_puts ( <div class="para ret">
<h4>Return Value</h4>
-<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an EOF (-1) will be returned.</p>
+<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, a negative value will be returned.</p>
</div>
diff --git a/fatfs/documents/doc/rc.html b/fatfs/documents/doc/rc.html index 05bcf9e..8f7fffa 100644 --- a/fatfs/documents/doc/rc.html +++ b/fatfs/documents/doc/rc.html @@ -11,7 +11,7 @@ <body>
<h1>Return Code of API Functions</h1>
-<p>Most of API functions return common result code as enum type <tt>FRESULT</tt>. When an API function succeeded, it returns zero (<tt>FR_OK</tt>), otherwise it returns non-zero value indicates type of error.</p>
+<p>Most of API functions return common result code in enum type <tt>FRESULT</tt>. When an API function succeeded, it returns zero (<tt>FR_OK</tt>), otherwise it returns non-zero value indicates type of error.</p>
<dl class="ret">
@@ -22,14 +22,14 @@ <dd>The lower layer, <tt>disk_read</tt>, <tt>disk_write</tt> or <tt>disk_ioctl</tt> function, reported that an unrecoverable hard error occured.<br>Note that if once this error occured at any operation to an open file, the file object is aborted and any operations to the file except for close will be rejected.</dd>
<dt id="ie">FR_INT_ERR</dt>
-<dd>Assertion failed. An insanity is detected in the internal process. One of the following possibilities is suspected.
+<dd>Assertion failed and an insanity is detected in the internal process. One of the following possibilities is suspected.
<ul>
-<li>Work area (file system object, file object or etc...) has been broken by stack overflow or any other tasks. This is the reason in most case.</li>
+<li>Work area (file system object, file object or etc...) has been broken by stack overflow or something. This is the reason in most case.</li>
<li>There is an error of the FAT structure on the volume.</li>
<li>There is a bug in the FatFs module itself.</li>
<li>Wrong lower layer implementation.</li>
</ul>
-Note that if once this error occured at any operation to an open file, the file object is aborted and all operations to the file except for close will be rejected.
+Note that if once this error occured in the operation to an open file, the file object is aborted and any operation to the file except for close will be rejected.
</dd>
<dt id="nr">FR_NOT_READY</dt>
@@ -38,46 +38,46 @@ Note that if once this error occured at any operation to an open file, the file <li>No medium in the drive.</li>
<li>Wrong lower layer implementation.</li>
<li>Wrong hardware configuration.</li>
-<li>The storage device has been broken.</li>
+<li>The storage device has broken.</li>
</ul>
</dd>
<dt id="nf">FR_NO_FILE</dt>
-<dd>Could not find the file.</dd>
+<dd>Could not find the file in the directory.</dd>
<dt id="np">FR_NO_PATH</dt>
-<dd>Could not find the path.</dd>
+<dd>Could not find the path. A directory in the path name could not be found.</dd>
<dt id="in">FR_INVALID_NAME</dt>
-<dd>The given string is invalid as the <a href="filename.html">path name</a>. One of the following possibilities is suspected.
+<dd>The given string is invalid as a <a href="filename.html">path name</a>. One of the following possibilities is suspected.
<ul>
-<li>There is any character not allowed for the file name.</li>
-<li>The string is out of 8.3 format. (at non-LFN cfg.)</li>
+<li>There is a character not allowed for the file name.</li>
+<li>The file name is out of 8.3 format. (at non-LFN cfg.)</li>
<li><tt>FF_MAX_LFN</tt> is insufficient for the file name. (at LFN cfg.)</li>
-<li>There is any character encoding error in the string.</li>
+<li>There is a character encoding error in the string.</li>
</ul>
</dd>
<dt id="dn">FR_DENIED</dt>
<dd>The required access was denied due to one of the following reasons:
<ul>
-<li>Write mode open against the read-only file.</li>
-<li>Deleting the read-only file or directory.</li>
-<li>Deleting the non-empty directory or current directory.</li>
-<li>Reading the file opened without <tt>FA_READ</tt> flag.</li>
-<li>Any modification to the file opened without <tt>FA_WRITE</tt> flag.</li>
-<li>Could not create the object due to root directory full or disk full.</li>
-<li>Could not allocate a contiguous area to the file.</li>
+<li>Write mode open against the read-only file. (f_open)</li>
+<li>Deleting the read-only file or directory. (f_unlink)</li>
+<li>Deleting the non-empty directory or current directory. (f_unlink)</li>
+<li>Reading the file opened without <tt>FA_READ</tt> flag. (f_read)</li>
+<li>Any modification to the file opened without <tt>FA_WRITE</tt> flag. (f_write, f_truncate, f_expand)</li>
+<li>Could not create the object due to root directory full or disk full. (f_open, f_mkdir)</li>
+<li>Could not find a contiguous area for the file. (f_expand)</li>
</ul>
</dd>
<dt id="ex">FR_EXIST</dt>
-<dd>Name collision. An object with the same name is already existing.</dd>
+<dd>Name collision. An object with the same name is already existing in the directory.</dd>
<dt id="io">FR_INVALID_OBJECT</dt>
<dd>The file/directory object is invalid or a null pointer is given. There are some reasons as follows:
<ul>
-<li>It has been closed, or collapsed.</li>
+<li>It has been closed, or the structure has been collapsed.</li>
<li>It has been invalidated. Open objects on the volume are invalidated by voulme mount process.</li>
<li>Physical drive is not ready to work due to a media removal.</li>
</ul>
@@ -87,20 +87,25 @@ Note that if once this error occured at any operation to an open file, the file <dd>A write mode operation against the write-protected media.</dd>
<dt id="id">FR_INVALID_DRIVE</dt>
-<dd>Invalid drive number is specified in the path name. A null pointer is given as the path name. (Related option: <tt><a href="config.html#volumes">FF_VOLUMES</a></tt>)</dd>
+<dd>Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: <tt><a href="config.html#volumes">FF_VOLUMES</a></tt>)</dd>
<dt id="ne">FR_NOT_ENABLED</dt>
<dd>Work area for the logical drive has not been registered by <tt>f_mount</tt> function.</dd>
<dt id="ns">FR_NO_FILESYSTEM</dt>
-<dd>There is no valid FAT volume on the drive or wrong lower layer implementation.</dd>
+<dd>Valid FAT volume could not be found in the drive. One of the following possibilities is suspected.
+<ul>
+<li>The FAT volume on the drive is collapsed.</li>
+<li>Wrong lower layer implementation.</li>
+<li>Wrong <tt>VolToPart[]</tt> settings. (<tt>FF_MULTI_PARTITION = 1</tt>)</li>
+</ul></dd>
<dt id="ma">FR_MKFS_ABORTED</dt>
<dd>The <tt>f_mkfs</tt> function aborted before start in format due to a reason as follows:
<ul>
-<li>It is impossible to format with the given parameters.</li>
-<li>The size of volume is too small. 128 sectors minimum with <tt>FM_SFD</tt>.</li>
-<li>The partition bound to the logical drive coulud not be found. (Related option: <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a></tt>)</li>
+<li>It is impossible to create the volume with the given conditions.</li>
+<li>The size of the volume is too small. 128 sectors minimum with <tt>FM_SFD</tt> option.</li>
+<li>The partition associated with the logical drive is not exist. (Related option: <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a></tt>)</li>
</ul>
</dd>
diff --git a/fatfs/documents/doc/read.html b/fatfs/documents/doc/read.html index 3f0d23b..9dff623 100644 --- a/fatfs/documents/doc/read.html +++ b/fatfs/documents/doc/read.html @@ -30,11 +30,11 @@ FRESULT f_read ( <dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>buff</dt>
-<dd>Pointer to the buffer to store read data.</dd>
+<dd>Pointer to the buffer to store the read data.</dd>
<dt>btr</dt>
-<dd>Number of bytes to read in range of <tt>UINT</tt> type.</dd>
+<dd>Number of bytes to read in range of <tt>UINT</tt> type. If the file needs to be read fast, it should be read in large chunk as possible.</dd>
<dt>br</dt>
-<dd>Pointer to the <tt>UINT</tt> variable to return number of bytes read. This value is always valid after the function call regardless of the function return code.</dd>
+<dd>Pointer to the <tt>UINT</tt> variable that receives number of bytes read. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btr</tt>, the function return code should be <tt>FR_OK</tt>.</dd>
</dl>
</div>
@@ -54,7 +54,7 @@ FRESULT f_read ( <div class="para desc">
<h4>Description</h4>
-<p>The function starts to read data from the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, <tt class="arg">*br</tt> should be checked to detect end of the file. In case of <tt class="arg">*br</tt> < <tt class="arg">btr</tt>, it means the read/write pointer reached end of the file during read operation.</p>
+<p>The function starts to read data from the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, <tt class="arg">*br</tt> should be checked to detect end of the file. In case of <tt class="arg">*br</tt> < <tt class="arg">btr</tt>, it means the read/write pointer hit end of the file during read operation.</p>
</div>
@@ -64,6 +64,12 @@ FRESULT f_read ( </div>
+<div class="para use">
+<h4>Example</h4>
+<p>Refer to the example in <tt>f_open</tt>.</p>
+</div>
+
+
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
diff --git a/fatfs/documents/doc/readdir.html b/fatfs/documents/doc/readdir.html index 878cb02..52a96b9 100644 --- a/fatfs/documents/doc/readdir.html +++ b/fatfs/documents/doc/readdir.html @@ -20,6 +20,11 @@ FRESULT f_readdir ( FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] File information structure */</span>
);
</pre>
+<pre>
+FRESULT f_rewinddir (
+ DIR* <span class="arg">dp</span> <span class="c">/* [IN] Directory object */</span>
+);
+</pre>
</div>
<div class="para arg">
@@ -48,15 +53,19 @@ FRESULT f_readdir ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_readdir</tt> function reads a directory item, informations about the object. All items in the directory can be read in sequence by <tt>f_readdir</tt> function calls. Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a nul string is stored into the <tt>fno->fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded.</p>
-<p>When support of long file name (LFN) is enabled, a member <tt>altname[]</tt> is defined in the file information structure to store the short file name of the object. If the long file name is not accessible due to some reason listed below, short file name is stored to the <tt>fname[]</tt> and <tt>altname[]</tt> has a null string.</p>
+<p>The <tt>f_readdir</tt> function reads a directory item, informations about the object, from the open directory. Items in the directory can be read in sequence by <tt>f_readdir</tt> function calls. When all items in the directory have been read and no item to read, a null string is stored into the <tt>fno->fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded. The <tt>f_rewinddir</tt> function is implemented as a macro.</p>
+<pre>
+#define <em>f_rewinddir</em>(dp) f_readdir((dp), 0)
+</pre>
+<p>When LFN is enabled, a member <tt>altname[]</tt> is defined in the file information structure to store the short file name of the object. If the long file name is not accessible due to a reason listed below, short file name is stored to the <tt>fname[]</tt> and the <tt>altname[]</tt> has a null string.</p>
<ul>
-<li>The item has no LFN. (Not the case at exFAT volume)</li>
-<li>Setting of <a href="config.html#max_lfn"><tt>FF_MAX_LFN</tt></a> is insufficient to handle the LFN. (Not the case at <tt>FF_MAX_LFN == 255</tt>)</li>
-<li>Setting of <a href="config.html#lfn_buf"><tt>FF_LFN_BUF</tt></a> is insufficient to store the LFN.</li>
-<li>The LFN contains any character not defined in current code page. (Not the case at <tt>FF_LFN_UNICODE >= 1</tt>)</li>
+<li>The item has no LFN. (Not the case in exFAT volume)</li>
+<li><a href="config.html#max_lfn"><tt>FF_MAX_LFN</tt></a> is insufficient to handle the LFN. (Not the case in <tt>FF_MAX_LFN == 255</tt>)</li>
+<li><a href="config.html#lfn_buf"><tt>FF_LFN_BUF</tt></a> is insufficient to store the LFN.</li>
+<li>The LFN contains some character not defined in current CP. (Not the case in <tt>FF_LFN_UNICODE != 0</tt>)</li>
</ul>
-<p>There is a problem on reading a directory of exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned into the <tt>fname[]</tt> to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt> and <tt>FF_MAX_LFN == 255</tt> to support the full feature of LFN specification.</p>
+<p>There is an issue on read directories in exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned as the file name to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> != 0</tt> and <tt>FF_MAX_LFN == 255</tt> to support the full feature of LFN specification.</p>
+<p>Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory of FAT volume are filtered out and they will never appear in the read items because exFAT lacks dot entries in the sub-directory.</p>
</div>
@@ -94,7 +103,7 @@ FRESULT scan_files ( printf("%s/%s\n", path, fno.fname);
}
}
- f_closedir(&dir)
+ f_closedir(&dir);
}
return res;
diff --git a/fatfs/documents/doc/sdir.html b/fatfs/documents/doc/sdir.html index 53a460d..eb18cc3 100644 --- a/fatfs/documents/doc/sdir.html +++ b/fatfs/documents/doc/sdir.html @@ -19,7 +19,7 @@ FFOBJID obj; <span class="c">/* Object identifier */</span>
DWORD dptr; <span class="c">/* Current read/write offset */</span>
DWORD clust; <span class="c">/* Current cluster */</span>
- DWORD sect; <span class="c">/* Current sector */</span>
+ LBA_t sect; <span class="c">/* Current sector */</span>
BYTE* dir; <span class="c">/* Pointer to the current SFN entry in the win[] */</span>
BYTE* fn; <span class="c">/* Pointer to the SFN buffer (in/out) {file[8],ext[3],status[1]} */</span>
<span class="k">#if</span> FF_USE_LFN
diff --git a/fatfs/documents/doc/setlabel.html b/fatfs/documents/doc/setlabel.html index c50db18..9eb5e78 100644 --- a/fatfs/documents/doc/setlabel.html +++ b/fatfs/documents/doc/setlabel.html @@ -53,9 +53,9 @@ FRESULT f_setlabel ( <ul>
<li>Up to 11 bytes long as conversion of OEM code page at FAT volume.</li>
<li>Up to 11 characters long at exFAT volume.</li>
-<li>Allowable characters for FAT volume are: <tt>! # $ % & ' ( ) - ^ _ ` ~ { } 0-9 A-Z a-z</tt> and extended characters. Low-case characters are up converted.</li>
-<li>Allowable characters for exFAT volume are: characters allowed for FAT volume and <tt>" + , . ; = [ ]</tt>. Low-case characters are preserved.</li>
-<li>Spaces can be contained anywhere in the volume label. Trailing spaces are truncated off at FAT volume.</li>
+<li>Allowable characters for FAT volume are: characters allowed for SFN excludes dot. Low-case characters are up converted.</li>
+<li>Allowable characters for exFAT volume are: characters allowed for LFN includes dot. Low-case characters are preserved.</li>
+<li>Spaces can be embedded anywhere in the volume label. Trailing spaces are truncated off at FAT volume.</li>
</ul>
<p>Remark: The standard system (Windows) has a problem at the volume label with a heading <tt>\xE5</tt> on the FAT volume. To avoid this problem, this function rejects such volume label as invalid name.</p>
</div>
diff --git a/fatfs/documents/doc/sfatfs.html b/fatfs/documents/doc/sfatfs.html index e5207cb..6ecd6e5 100644 --- a/fatfs/documents/doc/sfatfs.html +++ b/fatfs/documents/doc/sfatfs.html @@ -31,7 +31,7 @@ BYTE* dirbuf; <span class="c">/* Directory entry block scratchpad buffer */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_FS_REENTRANT
- FF_SYNC_t sobj; <span class="c">/* Identifier of sync object */</span>
+ FF_SYNC_t sobj; <span class="c">/* Identifier of sync object */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !FF_FS_READONLY
DWORD last_clust; <span class="c">/* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */</span>
@@ -47,11 +47,11 @@ <span class="k">#endif</span>
DWORD n_fatent; <span class="c">/* Number of FAT entries (Number of clusters + 2) */</span>
DWORD fsize; <span class="c">/* Sectors per FAT */</span>
- DWORD volbase; <span class="c">/* Volume base LBA */</span>
- DWORD fatbase; <span class="c">/* FAT base LBA */</span>
- DWORD dirbase; <span class="c">/* Root directory base (LBA|Cluster) */</span>
- DWORD database; <span class="c">/* Data base LBA */</span>
- DWORD winsect; <span class="c">/* Sector LBA appearing in the win[] */</span>
+ LBA_t volbase; <span class="c">/* Volume base LBA */</span>
+ LBA_t fatbase; <span class="c">/* FAT base LBA */</span>
+ LBA_t dirbase; <span class="c">/* Root directory base (LBA|Cluster) */</span>
+ LBA_t database; <span class="c">/* Data base LBA */</span>
+ LBA_t winsect; <span class="c">/* Sector LBA appearing in the win[] */</span>
BYTE win[FF_MAX_SS]; <span class="c">/* Disk access window for directory, FAT (and file data at tiny cfg) */</span>
} FATFS;
</pre>
diff --git a/fatfs/documents/doc/sfile.html b/fatfs/documents/doc/sfile.html index e8a677f..9234d32 100644 --- a/fatfs/documents/doc/sfile.html +++ b/fatfs/documents/doc/sfile.html @@ -22,9 +22,9 @@ BYTE err; <span class="c">/* Abort flag (error code) */</span>
FSIZE_t fptr; <span class="c">/* File read/write pointer (Byte offset origin from top of the file) */</span>
DWORD clust; <span class="c">/* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */</span>
- DWORD sect; <span class="c">/* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/</span>
+ LBA_t sect; <span class="c">/* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/</span>
<span class="k">#if</span> !FF_FS_READONLY
- DWORD dir_sect; <span class="c">/* Sector number containing the directory entry */</span>
+ LBA_t dir_sect; <span class="c">/* Sector number containing the directory entry */</span>
BYTE* dir_ptr; <span class="c">/* Ponter to the directory entry in the window */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_USE_FASTSEEK
diff --git a/fatfs/documents/doc/sfileinfo.html b/fatfs/documents/doc/sfileinfo.html index b4c9063..db0f45e 100644 --- a/fatfs/documents/doc/sfileinfo.html +++ b/fatfs/documents/doc/sfileinfo.html @@ -13,7 +13,7 @@ <div class="para">
<h2>FILINFO</h2>
-<p>The <tt>FILINFO</tt> structure holds information about the object returned by <tt>f_readdir</tt>, <tt>f_findfirst</tt>, <tt>f_findnext</tt> and <tt>f_stat</tt> function. Be careful in the size of structure when LFN is enabled.</p>
+<p>The <tt>FILINFO</tt> structure holds information about the object retrieved by <tt>f_readdir</tt>, <tt>f_findfirst</tt>, <tt>f_findnext</tt> and <tt>f_stat</tt> function. Be careful in the size of structure when LFN is enabled.</p>
<pre>
<span class="k">typedef struct</span> {
FSIZE_t fsize; <span class="c">/* File size */</span>
@@ -33,9 +33,9 @@ <h4>Members</h4>
<dl>
<dt>fsize</dt>
-<dd>Indicates size of the file in unit of byte. <tt>FSIZE_t</tt> is an alias of integer type either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>. Do not care when the item is a directory.</dd>
+<dd>Size of the file in unit of byte. <tt>FSIZE_t</tt> is an alias of integer type either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>. Do not care if the item is a sub-directory.</dd>
<dt>fdate</dt>
-<dd>Indicates the date when the file was modified or the directory was created.<br>
+<dd>The date when the file was modified or the directory was created.<br>
<dl>
<dt>bit15:9</dt>
<dd>Year origin from 1980 (0..127)</dd>
@@ -46,7 +46,7 @@ </dl>
</dd>
<dt>ftime</dt>
-<dd>Indicates the time when the file was modified or the directory was created.<br>
+<dd>The time when the file was modified or the directory was created.<br>
<dl>
<dt>bit15:11</dt>
<dd>Hour (0..23)</dd>
@@ -57,7 +57,7 @@ </dl>
</dd>
<dt>fattrib</dt>
-<dd>Indicates the attribute flags in combination of:<br>
+<dd>The attribute flags in combination of:<br>
<table class="lst">
<tr><th>Flag</th><th>Meaning</th></tr>
<tr><td>AM_RDO</td><td>Read-only. Write mode open and deleting is rejected.</td></tr>
@@ -68,9 +68,9 @@ </table>
</dd>
<dt>fname[]</dt>
-<dd>The null-terminated object name is stored. A null string is stored when no item to read and it indicates this structure is invalid. The size of <tt>fname[]</tt> and <tt>altname[]</tt> each can be configured at LFN configuration.</dd>
+<dd>Null-terminated object name. A null string is stored when no item to read and it indicates this structure is invalid. The size of <tt>fname[]</tt> and <tt>altname[]</tt> each can be configured in LFN configuration.</dd>
<dt>altname[]</dt>
-<dd>Alternative object name is stored if available. This member is not available at non-LFN configuration.</dd>
+<dd>Alternative object name is stored if available. This member is not available in non-LFN configuration.</dd>
</dl>
<p class="foot"><a href="../00index_e.html">Return</a></p>
diff --git a/fatfs/documents/doc/stat.html b/fatfs/documents/doc/stat.html index db63667..a4e4fc8 100644 --- a/fatfs/documents/doc/stat.html +++ b/fatfs/documents/doc/stat.html @@ -28,7 +28,7 @@ FRESULT f_stat ( <dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">object</a> to get its information. The object must not be the root direcotry.</dd>
<dt>fno</dt>
-<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information of the object. Set null pointer if it is not needed.</dd>
+<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information of the object. Set null pointer if this information is not needed.</dd>
</dl>
</div>
@@ -54,7 +54,8 @@ FRESULT f_stat ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_stat</tt> function checks the existence of a file or sub-directory. If not exist, the function returns with <tt>FR_NO_FILE</tt>. If exist, the function returns with <tt>FR_OK</tt> and the informations of the object, file size, timestamp and attribute, are stored to the file information structure. For details of the file information, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir</tt></a> function.</p>
+<p>The <tt>f_stat</tt> function checks the existence of a file or sub-directory in the directory. If it is not exist, the function returns with <tt>FR_NO_FILE</tt>. If it is exist, the function returns with <tt>FR_OK</tt> and the informations about the object, size, timestamp and attribute, is stored to the file information structure. For details of the file information, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir</tt></a> function.</p>
+<p>Note that the file information comes from the meta data in the directory. If the file has been opend and modified, the file will need to be synched or closed in order to obtain the latest file information.</p>
</div>
@@ -69,16 +70,17 @@ FRESULT f_stat ( <pre>
FRESULT fr;
FILINFO fno;
+ const char *fname = "file.txt";
- printf("Test for 'file.txt'...\n");
+ printf("Test for \"%s\"...\n", fname);
- fr = f_stat("file.txt", &fno);
+ fr = <em>f_stat</em>(fname, &fno);
switch (fr) {
case FR_OK:
printf("Size: %lu\n", fno.fsize);
- printf("Timestamp: %u/%02u/%02u, %02u:%02u\n",
+ printf("Timestamp: %u-%02u-%02u, %02u:%02u\n",
(fno.fdate >> 9) + 1980, fno.fdate >> 5 & 15, fno.fdate & 31,
fno.ftime >> 11, fno.ftime >> 5 & 63);
printf("Attributes: %c%c%c%c%c\n",
@@ -90,7 +92,7 @@ FRESULT f_stat ( break;
case FR_NO_FILE:
- printf("It is not exist.\n");
+ printf("\"%s\" is not exist.\n", fname);
break;
default:
diff --git a/fatfs/documents/doc/sync.html b/fatfs/documents/doc/sync.html index a0317d6..9fb42a0 100644 --- a/fatfs/documents/doc/sync.html +++ b/fatfs/documents/doc/sync.html @@ -44,7 +44,30 @@ FRESULT f_sync ( <div class="para desc">
<h4>Description</h4>
-<p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function of periodic or immediataly after <tt>f_write</tt> function can minimize the risk of data loss due to a sudden blackout or an unintentional media removal. For more information, refer to <a href="appnote.html#critical">application note</a>.</p>
+<p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function in certain interval can minimize the risk of data loss due to a sudden blackout, wrong media removal or unrecoverable disk error. For more information, refer to <a href="appnote.html#critical">application note</a>.</p>
+<pre>
+Case 1. Normal write sequence
+
+ Time --> ↓Normal shutdown
+OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC <Power off>
+
+
+Case 2. Without using f_sync()
+
+ Time --> ↓System crush
+O<span class="e">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</span>
+ |<--------------- All data written will be lost ------------------>|
+
+
+Case 3. Using f_sync()
+ Time --> ↓System crush
+OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwS<span class="e">wwwww</span>
+ Data after last f_sync will be lost |<->|
+O - f_open()
+C - f_close()
+w - f_write()
+S - f_sync()
+</pre>
<p>However there is no sense in <tt>f_sync</tt> function immediataly before <tt>f_close</tt> function because it performs <tt>f_sync</tt> function in it. In other words, the differnce between those functions is that the file object is invalidated or not.</p>
</div>
diff --git a/fatfs/documents/doc/unlink.html b/fatfs/documents/doc/unlink.html index 26f3cb9..7809648 100644 --- a/fatfs/documents/doc/unlink.html +++ b/fatfs/documents/doc/unlink.html @@ -13,7 +13,7 @@ <div class="para func">
<h2>f_unlink</h2>
-<p>The f_unlink function removes a file or sub-directory.</p>
+<p>The f_unlink function removes a file or sub-directory from the volume.</p>
<pre>
FRESULT f_unlink (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Object name */</span>
diff --git a/fatfs/documents/doc/write.html b/fatfs/documents/doc/write.html index d451255..3d16674 100644 --- a/fatfs/documents/doc/write.html +++ b/fatfs/documents/doc/write.html @@ -32,9 +32,9 @@ FRESULT f_write ( <dt>buff</dt>
<dd>Pointer to the data to be written.</dd>
<dt>btw</dt>
-<dd>Specifies number of bytes to write in range of <tt>UINT</tt> type.</dd>
+<dd>Specifies number of bytes to write in range of <tt>UINT</tt> type. If the data needs to be written fast, it should be written in large chunk as possible.</dd>
<dt>bw</dt>
-<dd>Pointer to the <tt>UINT</tt> variable to return the number of bytes written. This value is always valid after the function call regardless of the function return code.</dd>
+<dd>Pointer to the <tt>UINT</tt> variable that receives the number of bytes written. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btw</tt>, the function return code should be <tt>FR_OK</tt>.</dd>
</dl>
</div>
@@ -54,7 +54,7 @@ FRESULT f_write ( <div class="para desc">
<h4>Description</h4>
-<p>The function starts to write data to the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, <tt class="arg">*bw</tt> should be checked to detect the disk full. In case of <tt class="arg">*bw</tt> < <tt class="arg">btw</tt>, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.</p>
+<p>The function starts to write data to the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, <tt class="arg">*bw</tt> should be checked to detect the disk full. In case of <tt class="arg">*bw</tt> < <tt class="arg">btw</tt>, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.</p>
</div>
@@ -64,6 +64,12 @@ FRESULT f_write ( </div>
+<div class="para use">
+<h4>Example</h4>
+<p>Refer to the example in <tt>f_open</tt>.</p>
+</div>
+
+
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
diff --git a/fatfs/documents/res/app2.c b/fatfs/documents/res/app2.c index 3de3eee..415c4bc 100644 --- a/fatfs/documents/res/app2.c +++ b/fatfs/documents/res/app2.c @@ -1,65 +1,78 @@ /*------------------------------------------------------------/
-/ Remove all contents of a directory
-/ This function works regardless of FF_FS_RPATH.
-/------------------------------------------------------------*/
+/ Delete a sub-directory even if it contains any file
+/-------------------------------------------------------------/
+/ The delete_node() function is for R0.12+.
+/ It works regardless of FF_FS_RPATH.
+*/
-FILINFO fno;
-
-FRESULT empty_directory (
- char* path /* Working buffer filled with start directory */
+FRESULT delete_node (
+ TCHAR* path, /* Path name buffer with the sub-directory to delete */
+ UINT sz_buff, /* Size of path name buffer (items) */
+ FILINFO* fno /* Name read buffer */
)
{
UINT i, j;
FRESULT fr;
DIR dir;
- fr = f_opendir(&dir, path);
- if (fr == FR_OK) {
- for (i = 0; path[i]; i++) ;
- path[i++] = '/';
- for (;;) {
- fr = f_readdir(&dir, &fno);
- if (fr != FR_OK || !fno.fname[0]) break;
- if (_FS_RPATH && fno.fname[0] == '.') continue;
- j = 0;
- do
- path[i+j] = fno.fname[j];
- while (fno.fname[j++]);
- if (fno.fattrib & AM_DIR) {
- fr = empty_directory(path);
- if (fr != FR_OK) break;
+
+ fr = f_opendir(&dir, path); /* Open the sub-directory to make it empty */
+ if (fr != FR_OK) return fr;
+
+ for (i = 0; path[i]; i++) ; /* Get current path length */
+ path[i++] = _T('/');
+
+ for (;;) {
+ fr = f_readdir(&dir, fno); /* Get a directory item */
+ if (fr != FR_OK || !fno->fname[0]) break; /* End of directory? */
+ j = 0;
+ do { /* Make a path name */
+ if (i + j >= sz_buff) { /* Buffer over flow? */
+ fr = 100; break; /* Fails with 100 when buffer overflow */
}
+ path[i + j] = fno->fname[j];
+ } while (fno->fname[j++]);
+ if (fno->fattrib & AM_DIR) { /* Item is a sub-directory */
+ fr = delete_node(path, sz_buff, fno);
+ } else { /* Item is a file */
fr = f_unlink(path);
- if (fr != FR_OK) break;
}
- path[--i] = '\0';
- closedir(&dir);
+ if (fr != FR_OK) break;
}
+ path[--i] = 0; /* Restore the path name */
+ f_closedir(&dir);
+
+ if (fr == FR_OK) fr = f_unlink(path); /* Delete the empty sub-directory */
return fr;
}
-int main (void)
+
+int main (void) /* How to use */
{
FRESULT fr;
FATFS fs;
- char buff[256]; /* Working buffer */
+ TCHAR buff[256];
+ FILINFO fno;
+ f_mount(&fs, _T("5:"), 0);
- f_mount(&fs, "", 0);
+ /* Directory to be deleted */
+ _tcscpy(buff, _T("5:dir"));
- strcpy(buff, "/"); /* Directory to be emptied */
- fr = empty_directory(buff);
+ /* Delete the directory */
+ fr = delete_node(buff, sizeof buff / sizeof buff[0], &fno);
+ /* Check the result */
if (fr) {
- printf("Function failed. (%u)\n", fr);
+ _tprintf(_T("Failed to delete the directory. (%u)\n"), fr);
return fr;
} else {
- printf("All contents in the %s are successfully removed.\n", buff);
+ _tprintf(_T("The directory and the contents have successfully been deleted.\n"), buff);
return 0;
}
}
diff --git a/fatfs/documents/res/app4.c b/fatfs/documents/res/app4.c index 4209f39..c46d1a0 100644 --- a/fatfs/documents/res/app4.c +++ b/fatfs/documents/res/app4.c @@ -10,9 +10,9 @@ #include "diskio.h" /* Declarations of disk functions */
-static
-DWORD pn ( /* Pseudo random number generator */
- DWORD pns /* 0:Initialize, !0:Read */
+
+static DWORD pn ( /* Pseudo random number generator */
+ DWORD pns /* 0:Initialize, !0:Read */
)
{
static DWORD lfsr;
@@ -50,8 +50,8 @@ int test_diskio ( printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);
- if (sz_buff < _MAX_SS + 4) {
- printf("Insufficient work area to run program.\n");
+ if (sz_buff < FF_MAX_SS + 8) {
+ printf("Insufficient work area to run the program.\n");
return 1;
}
@@ -115,7 +115,7 @@ int test_diskio ( }
/* Single sector write test */
- printf("**** Single sector write test 1 ****\n");
+ printf("**** Single sector write test ****\n");
lba = 0;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
@@ -145,52 +145,56 @@ int test_diskio ( }
for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 10;
}
pns++;
printf("**** Multiple sector write test ****\n");
- lba = 1; ns = sz_buff / sz_sect;
+ lba = 5; ns = sz_buff / sz_sect;
if (ns > 4) ns = 4;
- for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
- printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
- dr = disk_write(pdrv, pbuff, lba, ns);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 11;
- }
- printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
- dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 12;
- }
- memset(pbuff, 0, sz_sect * ns);
- printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
- dr = disk_read(pdrv, pbuff, lba, ns);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 13;
- }
- for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
- if (n == (UINT)(sz_sect * ns)) {
- printf(" Data matched.\n");
+ if (ns > 1) {
+ for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
+ printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
+ dr = disk_write(pdrv, pbuff, lba, ns);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 11;
+ }
+ printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
+ dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 12;
+ }
+ memset(pbuff, 0, sz_sect * ns);
+ printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
+ dr = disk_read(pdrv, pbuff, lba, ns);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 13;
+ }
+ for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
+ if (n == (UINT)(sz_sect * ns)) {
+ printf(" Read data matched.\n");
+ } else {
+ printf(" Read data differs from the data written.\n");
+ return 14;
+ }
} else {
- printf("Failed: Read data differs from the data written.\n");
- return 14;
+ printf(" Test skipped.\n");
}
pns++;
- printf("**** Single sector write test (misaligned address) ****\n");
+ printf("**** Single sector write test (unaligned buffer address) ****\n");
lba = 5;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba);
@@ -220,9 +224,9 @@ int test_diskio ( }
for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 18;
}
pns++;
@@ -274,9 +278,9 @@ int test_diskio ( }
for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;
if (n == (UINT)(sz_sect * 2)) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 24;
}
} else {
diff --git a/fatfs/documents/res/app5.c b/fatfs/documents/res/app5.c new file mode 100644 index 0000000..2739019 --- /dev/null +++ b/fatfs/documents/res/app5.c @@ -0,0 +1,38 @@ +/*----------------------------------------------------------------------/
+/ Test if the file is contiguous /
+/----------------------------------------------------------------------*/
+
+FRESULT test_contiguous_file (
+ FIL* fp, /* [IN] Open file object to be checked */
+ int* cont /* [OUT] 1:Contiguous, 0:Fragmented or zero-length */
+)
+{
+ DWORD clst, clsz, step;
+ FSIZE_t fsz;
+ FRESULT fr;
+
+
+ *cont = 0;
+ fr = f_rewind(fp); /* Validates and prepares the file */
+ if (fr != FR_OK) return fr;
+
+#if FF_MAX_SS == FF_MIN_SS
+ clsz = (DWORD)fp->obj.fs->csize * FF_MAX_SS; /* Cluster size */
+#else
+ clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize;
+#endif
+ fsz = f_size(fp);
+ if (fsz > 0) {
+ clst = fp->obj.sclust - 1; /* A cluster leading the first cluster for first test */
+ while (fsz) {
+ step = (fsz >= clsz) ? clsz : (DWORD)fsz;
+ fr = f_lseek(fp, f_tell(fp) + step); /* Advances file pointer a cluster */
+ if (fr != FR_OK) return fr;
+ if (clst + 1 != fp->clust) break; /* Is not the cluster next to previous one? */
+ clst = fp->clust; fsz -= step; /* Get current cluster for next test */
+ }
+ if (fsz == 0) *cont = 1; /* All done without fail? */
+ }
+
+ return FR_OK;
+}
diff --git a/fatfs/documents/res/app6.c b/fatfs/documents/res/app6.c new file mode 100644 index 0000000..4a3565e --- /dev/null +++ b/fatfs/documents/res/app6.c @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------*/
+/* Raw Read/Write Throughput Checker */
+/*---------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <systimer.h>
+#include "diskio.h"
+#include "ff.h"
+
+
+int test_raw_speed (
+ BYTE pdrv, /* Physical drive number */
+ DWORD lba, /* Start LBA for read/write test */
+ DWORD len, /* Number of bytes to read/write (must be multiple of sz_buff) */
+ void* buff, /* Read/write buffer */
+ UINT sz_buff /* Size of read/write buffer (must be multiple of FF_MAX_SS) */
+)
+{
+ WORD ss;
+ DWORD ofs, tmr;
+
+
+#if FF_MIN_SS != FF_MAX_SS
+ if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) {
+ printf("\ndisk_ioctl() failed.\n");
+ return 0;
+ }
+#else
+ ss = FF_MAX_SS;
+#endif
+
+ printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
+ tmr = systimer();
+ for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
+ if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
+ printf("\ndisk_write() failed.\n");
+ return 0;
+ }
+ }
+ if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) {
+ printf("\ndisk_ioctl() failed.\n");
+ return 0;
+ }
+ tmr = systimer() - tmr;
+ printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr);
+
+ printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
+ tmr = systimer();
+ for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
+ if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
+ printf("\ndisk_read() failed.\n");
+ return 0;
+ }
+ }
+ tmr = systimer() - tmr;
+ printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr);
+
+ printf("Test completed.\n");
+ return 1;
+}
+
diff --git a/fatfs/documents/res/f4.png b/fatfs/documents/res/f4.png Binary files differindex f9a6b46..2c00ddc 100644 --- a/fatfs/documents/res/f4.png +++ b/fatfs/documents/res/f4.png diff --git a/fatfs/documents/res/f5.png b/fatfs/documents/res/f5.png Binary files differindex b110b29..bc0171a 100644 --- a/fatfs/documents/res/f5.png +++ b/fatfs/documents/res/f5.png diff --git a/fatfs/documents/res/funcs.png b/fatfs/documents/res/funcs.png Binary files differindex 022cd74..f381ec5 100644 --- a/fatfs/documents/res/funcs.png +++ b/fatfs/documents/res/funcs.png diff --git a/fatfs/documents/res/layers2.png b/fatfs/documents/res/layers2.png Binary files differindex 406c453..c7dbef4 100644 --- a/fatfs/documents/res/layers2.png +++ b/fatfs/documents/res/layers2.png diff --git a/fatfs/documents/res/mkfatimg.zip b/fatfs/documents/res/mkfatimg.zip Binary files differindex 67d423b..63e6ad7 100644 --- a/fatfs/documents/res/mkfatimg.zip +++ b/fatfs/documents/res/mkfatimg.zip diff --git a/fatfs/documents/res/mkfs.xls b/fatfs/documents/res/mkfs.xls Binary files differdeleted file mode 100644 index ee6b2bf..0000000 --- a/fatfs/documents/res/mkfs.xls +++ /dev/null diff --git a/fatfs/documents/res/mkfs.xlsx b/fatfs/documents/res/mkfs.xlsx Binary files differnew file mode 100644 index 0000000..6024888 --- /dev/null +++ b/fatfs/documents/res/mkfs.xlsx diff --git a/fatfs/documents/res/modules.png b/fatfs/documents/res/modules.png Binary files differindex b1ab987..d7e69a3 100644 --- a/fatfs/documents/res/modules.png +++ b/fatfs/documents/res/modules.png diff --git a/fatfs/documents/res/uniconv.zip b/fatfs/documents/res/uniconv.zip Binary files differnew file mode 100644 index 0000000..be7d84f --- /dev/null +++ b/fatfs/documents/res/uniconv.zip diff --git a/fatfs/documents/updates.html b/fatfs/documents/updates.html new file mode 100644 index 0000000..24b8fd4 --- /dev/null +++ b/fatfs/documents/updates.html @@ -0,0 +1,481 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<meta http-equiv="cache-control" content="no-cache">
+<link rel="start" title="Site Top" href="../../">
+<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
+<title>FatFs - Updates and Migration Notes</title>
+</head>
+<body style="max-width: none;">
+<h2>Updates and Migration Notes</h2>
+<table class="lst4">
+<tr><th>Revision</th><th>Updates</th><th>Migration Notes</th></tr>
+<tr>
+<td>R0.15<br>Nov 6, 2022</td>
+<td>
+Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.<br>
+Fixed a potential error in <tt>f_mount</tt> when <tt>FF_FS_REENTRANT</tt>.<br>
+Fixed file lock control <tt>FF_FS_LOCK</tt> is not mutal excluded when <tt>FF_FS_REENTRANT && FF_VOLUMES > 1</tt> is true.<br>
+Fixed <tt>f_mkfs</tt> creates broken exFAT volume when the size of volume is <tt>>= 2^32</tt> sectors.<br>
+Fixed string functions cannot write the unicode characters not in BMP when <tt>FF_LFN_UNICODE == 2</tt> (UTF-8).<br>
+Fixed a compatibility issue in identification of GPT header.<br>
+</td>
+<td>
+User provided synchronization functions, <tt>ff_cre_syncobj</tt>, <tt>ff_del_syncobj</tt>, <tt>ff_req_grant</tt> and <tt>ff_rel_grant</tt>, needed when <tt>FF_FS_REENTRANT</tt> are replaced with <tt>ff_mutex_create</tt>, <tt>ff_mutex_delete</tt>, <tt>ff_mutex_take</tt> and <tt>ff_mutex_give</tt> respectively. For example, see <tt>ffsystem.c</tt>.<br>
+<tt>FF_SYNC_t</tt> is removed from the configuration options.<br>
+</td>
+</tr>
+<tr>
+<td>R0.14b<br>Apr 17, 2021</td>
+<td>
+Made FatFs uses standard library <tt>string.h</tt> for copy, compare and search instead of built-in string functions.<br>
+Added support for long long integer and floating point to <tt>f_printf</tt>. (<tt>FF_STRF_LLI</tt> and <tt>FF_STRF_FP</tt>)<br>
+Made path name parser ignores the terminating separator to allow <tt>"dir/"</tt>.<br>
+Improved the compatibility in Unix style path name feature.<br>
+Fixed the file gets dead-locked when <tt>f_open</tt> failed with certain conditions. (appeared at R0.12a)<br>
+Fixed <tt>f_mkfs</tt> can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)<br>
+Fixed code page 855 cannot be set by <tt>f_setcp</tt>. (appeared at R0.13)<br>
+Fixed some compiler warnings.<br>
+</td>
+<td>
+From this revision, FatFs depends on <tt>string.h</tt>.<br>
+</td>
+</tr>
+<tr>
+<td>R0.14a<br>Dec 05, 2020</td>
+<td>
+Limited number of recursive calls in <tt>f_findnext</tt> to prevent stack overflow.<br>
+Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.<br>
+Fixed some compiler warnings.<br>
+</td>
+<td>
+Number of wildcards in the matching pattern in <tt>f_findfirst</tt> is limited to 4.<br>
+</td>
+</tr>
+<tr>
+<td>R0.14<br>Oct 14, 2019</td>
+<td>
+Added support for 64-bit LBA and GUID partition table (<tt>FF_LBA64</tt>)<br>
+Changed some API functions, <tt>f_mkfs</tt> and <tt>f_fdisk</tt>.<br>
+Fixed <tt>f_open</tt> cannot find the file with file name in length of <tt>FF_MAX_LFN</tt> characters.<br>
+Fixed <tt>f_readdir</tt> cannot retrieve long file names in length of <tt>FF_MAX_LFN - 1</tt> characters.<br>
+Fixed <tt>f_readdir</tt> returns file names with wrong case conversion. (appeared at R0.12)<br>
+Fixed <tt>f_mkfs</tt> can fail to create exFAT volume in the second partition. (appeared at R0.12)<br>
+</td>
+<td>
+Usage of <tt>f_mkfs</tt> and <tt>f_fdisk</tt> is changed and some features are added to these functions.<br>
+</td>
+</tr>
+<tr>
+<td>R0.13c<br>Oct 14, 2018</td>
+<td>
+Supported <tt>stdint.h</tt> for C99 and later. (<tt>integer.h</tt> was included in <tt>ff.h</tt>)<br>
+Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)<br>
+Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)<br>
+Fixed <tt>f_getcwd</tt> cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)<br>
+</td>
+<td>
+From this revision, FatFs depends on <tt>stdint.h</tt> in C99 or later.<br>
+<tt>integer.h</tt> is removed.<br>
+</td>
+</tr>
+<tr>
+<td>R0.13b<br>Apr 07, 2018</td>
+<td>
+Added support for UTF-32 encoding on the API. (<tt>FF_LFN_UNICODE = 3</tt>)<br>
+Added support for Unix style volume prefix. (<tt>FF_STR_VOLUME_ID = 2</tt>)<br>
+Fixed accesing objects in the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)<br>
+Fixed <tt>f_setlabel</tt> does not reject some invalid characters. (appeared at R0.09b)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.13a<br>Oct 14, 2017</td>
+<td>
+Added support for UTF-8 encoding on the API. (<tt>FF_LFN_UNICODE = 2</tt>)<br>
+Added options for file name output buffer. (<tt>FF_LFN_BUF, FF_SFN_BUF</tt>)<br>
+Added dynamic memory allocation option for working buffer of <tt>f_mkfs</tt> and <tt>f_fdisk</tt>.<br>
+Fixed <tt>f_fdisk</tt> and <tt>f_mkfs</tt> create the partition table with wrong CHS parameters. (appeared at R0.09)<br>
+Fixed <tt>f_unlink</tt> can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)<br>
+Fixed <tt>f_setlabel</tt> rejects some valid characters for exFAT volume. (appeared at R0.12)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.13<br>May 21, 2017</td>
+<td>
+Prefix of configuration item names are changed from <tt>"_"</tt> to <tt>"FF_"</tt>.<br>
+Added <tt>f_setcp</tt>, run-time code page configuration. (<tt>FF_CODE_PAGE = 0</tt>)<br>
+Improved cluster allocation time on stretch a deep buried cluster chain.<br>
+Improved processing time of <tt>f_mkdir</tt> with large cluster size by using <tt>FF_USE_LFN = 3</tt>.<br>
+Improved exFAT <tt>NoFatChain</tt> flag of the fragmented file to be set after it is truncated and got contiguous.<br>
+Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)<br>
+Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)<br>
+Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)<br>
+</td>
+<td>
+ASCII only configuration, <tt>FF_CODE_PAGE = 1</tt>, is removed. Use <tt>FF_CODE_PAGE = 437</tt> instead.<br>
+</td>
+</tr>
+<tr>
+<td>R0.12c<br>Mar 04, 2017</td>
+<td>
+Improved write throughput at the fragmented file on the exFAT volume.<br>
+Made memory usage for exFAT be able to be reduced as decreasing <tt>_MAX_LFN</tt>.<br>
+Fixed successive <tt>f_getfree</tt> can return wrong count on the FAT12/16 volume. (appeared at R0.12)<br>
+Fixed configuration option <tt>_VOLUMES</tt> cannot be set 10. (appeared at R0.10c)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.12b<br>Sep 4, 2016</td>
+<td>
+Made <tt>f_rename</tt> be able to rename objects with the same name but case.<br>
+Fixed an error in the case conversion teble of code page 866. (<tt>ff.c</tt>)<br>
+Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)<br>
+Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)<br>
+Fixed <tt>f_mkfs</tt> creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12a)<br>
+Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)<br>
+Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)<br>
+Fixed some internal errors in <tt>f_expand</tt> and <tt>f_lseek.</tt> (appeared at R0.12)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.12a<br>Jul 10, 2016</td>
+<td>
+Added support for creating exFAT volume with some changes of <tt>f_mkfs</tt>.<br>
+Added a file open method <tt>FA_OPEN_APPEND</tt>.<br>
+<tt>f_forward</tt> is available regardless of <tt>_FS_TINY</tt>.<br>
+Fixed <tt>f_mkfs</tt> creates broken volume. (appeared at R0.12)<br>
+Fixed wrong memory read in <tt>create_name</tt>. (appeared at R0.12)<br>
+Fixed compilation fails at some configurations, <tt>_USE_FASTSEEK</tt> and <tt>_USE_FORWARD</tt>.<br>
+</td>
+<td>
+Usage of <tt>f_mkfs</tt> is changed.<br>
+</td>
+</tr>
+<tr>
+<td>R0.12<br>Apr 12, 2016</td>
+<td>
+Added support for exFAT file system. (<tt>_FS_EXFAT</tt>)<br>
+Added <tt>f_expand</tt>. (<tt>_USE_EXPAND</tt>)<br>
+Changed some members in <tt>FINFO</tt> and behavior of <tt>f_readdir</tt>.<br>
+Added a configuration option <tt>_USE_CHMOD</tt>.<br>
+Fixed errors in the case conversion teble of Unicode (<tt>cc*.c</tt>).<br>
+</td>
+<td>
+Usage and members of <tt>FINFO</tt> sructure used in <tt>f_readdir</tt> is changed.<br>
+Dot entries in the sub-directory are never appear in <tt>f_readdir</tt>.<br>
+<tt>".."</tt> does not work as path name in exFAT volume.<br>
+<tt>f_getcwd</tt> does not work in exFAT volume.</br>
+Many members in <tt>FIL</tt> and <tt>DIR</tt> structure are changed.<br>
+To use <tt>f_chmod</tt>, <tt>_USE_CHMOD</tt> needs to be set.<br>
+<tt>_WORD_ACCESS</tt> is removed from the configuration options.<br>
+</td>
+</tr>
+<tr>
+<td>R0.11a<br>Sep 5, 2015</td>
+<td>
+Fixed wrong media change can lead a deadlock at thread-safe configuration.<br>
+Added code page 771, 860, 861, 863, 864, 865 and 869. (<tt>_CODE_PAGE</tt>)<br>
+Fixed errors in the case conversion teble of code page 437 and 850 (<tt>ff.c</tt>).<br>
+Fixed errors in the case conversion teble of Unicode (<tt>cc*.c</tt>).<br>
+</td>
+<td>
+Removed some code pages actually not exist on the standard systems. (<tt>_CODE_PAGE</tt>)<br>
+</td>
+</tr>
+<tr>
+<td>R0.11<br>Feb 9, 2015</td>
+<td>
+Added <tt>f_findfirst</tt> and <tt>f_findnext.</tt> (<tt>_USE_FIND</tt>)<br>
+Fixed <tt>f_unlink</tt> does not remove cluster chain of the file. (appeared at R0.10c)<br>
+Fixed <tt>_FS_NORTC</tt> option does not work properly. (appeared at R0.10c)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.10c<br>Nov 9, 2014</td>
+<td>
+Added a configuration option for the platforms without RTC. (<tt>_FS_NORTC</tt>)<br>
+Fixed volume label created by Mac OS X cannot be retrieved with <tt>f_getlabel</tt>. (appeared at R0.09b)<br>
+Fixed a potential problem of FAT access that can appear on disk error.<br>
+Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.10b<br>May 19, 2014</td>
+<td>
+Fixed a hard error in the disk I/O layer can collapse the directory entry.<br>
+Fixed LFN entry is not deleted on delete/rename an object with its lossy converted SFN. (appeared at R0.07)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.10a<br>Jan 15, 2014</td>
+<td>
+Added arbitrary strings as drive number in the path name. (<tt>_STR_VOLUME_ID</tt>)<br>
+Added an option for minimum sector size. (<tt>_MIN_SS</tt>)<br>
+2nd argument of <tt>f_rename</tt> can have a drive number and it will be ignored.<br>
+Fixed <tt>f_mount</tt> with forced mount fails when drive number is larger than 0. (appeared at R0.10)<br>
+Fixed <tt>f_close</tt> invalidates the file object without volume lock.<br>
+Fixed volume lock is left acquired after return from <tt>f_closedir</tt>. (appeared at R0.10)<br>
+Fixed creation of a directory entry with LFN fails on too many SFN collisions. (appeared at R0.07)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.10<br>Oct 2, 2013</td>
+<td>
+Added an option for character encoding on the file. (<tt>_STRF_ENCODE</tt>)<br>
+Added f_closedir.<br>
+Added forced full FAT scan option for <tt>f_getfree</tt>. (<tt>_FS_NOFSINFO</tt>)<br>
+Added forced mount option with changes of <tt>f_mount</tt>.<br>
+Improved behavior of volume auto detection.<br>
+Improved write throughput of <tt>f_puts</tt> and <tt>f_printf</tt>.<br>
+Changed argument of <tt>f_chdrive,</tt> <tt>f_mkfs</tt>, <tt>disk_read</tt> and <tt>disk_write</tt>.<br>
+Fixed <tt>f_write</tt> can be truncated when the file size is close to 4 GB.<br>
+Fixed <tt>f_open</tt>, <tt>f_mkdir</tt> and <tt>f_setlabel</tt> can return incorrect result code on error.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.09b<br>Jan 24, 2013</td>
+<td>
+Added <tt>f_getlabel</tt> and <tt>f_setlabel</tt>. (<tt>_USE_LABEL</tt>)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.09a<br>Aug 27, 2012</td>
+<td>
+Fixed assertion failure due to OS/2 EA on FAT12/16 volume.<br>
+Changed file functions reject null object pointer to avoid crash.<br>
+Changed option name <tt>_FS_SHARE</tt> to <tt>_FS_LOCK</tt>.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.09<br>Sep 6, 2011</td>
+<td>
+<tt>f_mkfs</tt> supports multiple partition on a physical drive.<br>
+Added <tt>f_fdisk</tt>. (<tt>_MULTI_PARTITION = 2</tt>)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.08b<br>Jan 15, 2011</td>
+<td>
+Fast seek function is also applied to <tt>f_read</tt> and <tt>f_write</tt>.<br>
+<tt>f_lseek</tt> reports required table size on creating CLMP.<br>
+Extended format syntax of <tt>f_printf</tt>.<br>
+Ignores duplicated directory separators in given path names.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.08a<br>Aug 16, 2010</td>
+<td>
+Added <tt>f_getcwd</tt>. (<tt>_FS_RPATH = 2</tt>)<br>
+Added sector erase function. (<tt>_USE_ERASE</tt>)<br>
+Moved file lock semaphore table from fs object to the bss.<br>
+Fixed <tt>f_mkdir</tt> creates wrong directory on non-LFN cfg when the given name contains <tt>';'</tt>.<br>
+Fixed <tt>f_mkfs</tt> creates wrong FAT32 volume.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.08<br>May 15, 2010</td>
+<td>
+Added an option to <tt>_USE_LFN</tt><br>
+Added support of file lock. (<tt>_FS_SHARE</tt>)<br>
+Added fast seek function. (<tt>_USE_FASTSEEK</tt>)<br>
+Changed a type name on the API, <tt>XCHAR</tt> to <tt>TCHAR</tt>.<br>
+Changed member, <tt>fname</tt>, in the <tt>FILINFO</tt> on Unicode cfg.<br>
+String functions support UTF-8 encoding files on Unicode cfg.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.07e<br>Nov 3, 2009</td>
+<td>
+Separated out configuration options from <tt>ff.h</tt> to <tt>ffconf.h</tt>.<br>
+Added a configuration option, <tt>_LFN_UNICODE</tt>.<br>
+Fixed <tt>f_unlink</tt> fails to remove a sub-dir on <tt>_FS_RPATH</tt>.<br>
+Fixed name matching error on the 13 char boundary.<br>
+Changed <tt>f_readdir</tt> to return the SFN with always upper case on non-LFN cfg.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.07c<br>Jan 21, 2009</td>
+<td>
+Fixed <tt>f_unlink</tt> may return FR_OK on error.<br>
+Fixed wrong cache control in <tt>f_lseek</tt>.<br>
+Added support of relative path.<br>
+Added <tt>f_chdir</tt>.<br>
+Added <tt>f_chdrive</tt>.<br>
+Added proper case conversion to extended characters.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.07a<br>Apr 14, 2009</td>
+<td>
+Separated out OS dependent code on re-entrant configuration.<br>
+Added multiple sector size support.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.07<br>Apr 1, 2009</td>
+<td>
+Merged Tiny-FatFs into FatFs as a buffer configuration option.<br>
+Added support for long file extension.<br>
+Added multiple code page support.<br>
+Added re-entrancy for multitask operation.<br>
+Added auto cluster size selection to <tt>f_mkfs</tt>.<br>
+Added rewind option to <tt>f_readdir</tt>.<br>
+Changed result code of critical errors.<br>
+Renamed string functions to avoid name collision.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.06<br>Apr 1, 2008</td>
+<td>
+Added <tt>f_forward</tt>. (Tiny-FatFs)<br>
+Added string functions: <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>.<br>
+Improved performance of <tt>f_lseek</tt> on moving to the same or following cluster.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.05a<br>Feb 3, 2008</td>
+<td>
+Added <tt>f_truncate</tt>.<br>
+Added <tt>f_utime</tt>.<br>
+Fixed off by one error at FAT sub-type determination.<br>
+Fixed btr in <tt>f_read</tt> can be mistruncated.<br>
+Fixed cached sector is left not flushed when create and close without write.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.05<br>Aug 26, 2007</td>
+<td>
+Changed arguments of <tt>f_read</tt>, <tt>f_write</tt>.<br>
+Changed arguments of <tt>f_mkfs</tt>. (FatFs)<br>
+Fixed <tt>f_mkfs</tt> on FAT32 creates incorrect FSInfo. (FatFs)<br>
+Fixed <tt>f_mkdir</tt> on FAT32 creates broken directory. (FatFs)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.04b<br>May 5, 2007</td>
+<td>
+Added <tt>_USE_NTFLAG</tt> option.<br>
+Added support for FSInfo in FAT32 volume.<br>
+Fixed some problems corresponds to FAT32. (Tiny-FatFs)<br>
+Fixed DBCS name can result <tt>FR_INVALID_NAME</tt>.<br>
+Fixed short seek (<tt><= csize</tt>) collapses the file object.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.04a<br>Apr 1, 2007</td>
+<td>
+Supported multiple partitions on a plysical drive. (FatFs)<br>
+Added minimization level 3.<br>
+Added a capability of extending file size to <tt>f_lseek</tt>.<br>
+Fixed an endian sensitive code in <tt>f_mkfs</tt>. (FatFs)<br>
+Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.04<br>Feb 4, 2007</td>
+<td>
+Supported multiple drive system. (FatFs)<br>
+Changed some APIs for multiple drive system.<br>
+Added <tt>f_mkfs</tt>. (FatFs)<br>
+Added <tt>_USE_FAT32</tt> option. (Tiny-FatFs)<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.03a<br>Dec 11, 2006</td>
+<td>
+Improved cluster scan algolithm to write files fast.<br>
+Fixed <tt>f_mkdir</tt> creates broken directory on FAT32.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.03<br>Sep 22, 2006</td>
+<td>
+Added <tt>f_rename</tt>.
+Changed option <tt>_FS_MINIMUM</tt> to <tt>_FS_MINIMIZE</tt>.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.02a<br>Jun 10, 2006</td>
+<td>
+Added a configuration option <tt>_FS_MINIMUM</tt>.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.02<br>Jun 01, 2006</td>
+<td>
+Added FAT12.<br>
+Removed unbuffered mode.<br>
+Fixed a problem on small (<tt><32M</tt>) patition.<br>
+</td>
+<td>
+</td>
+</tr>
+<tr>
+<td>R0.01<br>Apr 29, 2006</td>
+<td>
+First release.<br>
+</td>
+<td>
+</td>
+</tr>
+</table>
+</body>
+</html>
diff --git a/fatfs/source/00history.txt b/fatfs/source/00history.txt index 2cf6fbf..4fa1d7a 100644 --- a/fatfs/source/00history.txt +++ b/fatfs/source/00history.txt @@ -322,3 +322,48 @@ R0.13b (April 07, 2018) +R0.13c (October 14, 2018)
+ Supported stdint.h for C99 and later. (integer.h was included in ff.h)
+ Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
+ Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
+ Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
+
+
+
+R0.14 (October 14, 2019)
+ Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1)
+ Changed some API functions, f_mkfs() and f_fdisk().
+ Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters.
+ Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
+ Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
+ Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
+
+
+R0.14a (December 5, 2020)
+ Limited number of recursive calls in f_findnext().
+ Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
+ Fixed some compiler warnings.
+
+
+
+R0.14b (April 17, 2021)
+ Made FatFs uses standard library <string.h> for copy, compare and search instead of built-in string functions.
+ Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP)
+ Made path name parser ignore the terminating separator to allow "dir/".
+ Improved the compatibility in Unix style path name feature.
+ Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a)
+ Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
+ Fixed code page 855 cannot be set by f_setcp().
+ Fixed some compiler warnings.
+
+
+
+R0.15 (November 6, 2022)
+ Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
+ FF_SYNC_t is removed from the configuration options.
+ Fixed a potential error in f_mount when FF_FS_REENTRANT.
+ Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
+ Fixed f_mkfs() creates broken exFAT volume when the size of volume is >= 2^32 sectors.
+ Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
+ Fixed a compatibility issue in identification of GPT header.
+
diff --git a/fatfs/source/00readme.txt b/fatfs/source/00readme.txt index 10c8131..39f6c8c 100644 --- a/fatfs/source/00readme.txt +++ b/fatfs/source/00readme.txt @@ -1,4 +1,4 @@ -FatFs Module Source Files R0.13b
+FatFs Module Source Files R0.15
FILES
@@ -10,7 +10,6 @@ FILES ff.h Common include file for FatFs and application module.
diskio.h Common include file for FatFs and disk I/O module.
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
- integer.h Integer type definitions for FatFs.
ffunicode.c Optional Unicode utility functions.
ffsystem.c An example of optional O/S related functions.
diff --git a/fatfs/source/diskio.c b/fatfs/source/diskio.c index 25f5e53..81aaf59 100644 --- a/fatfs/source/diskio.c +++ b/fatfs/source/diskio.c @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------*/
-/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
+/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
@@ -7,7 +7,8 @@ /* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
-#include "diskio.h" /* FatFs lower layer API */
+#include "ff.h" /* Obtains integer types */
+#include "diskio.h" /* Declarations of disk functions */
/* Definitions of physical drive number for each drive */
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
@@ -98,7 +99,7 @@ DSTATUS disk_initialize ( DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
- DWORD sector, /* Start sector in LBA */
+ LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
@@ -143,10 +144,12 @@ DRESULT disk_read ( /* Write Sector(s) */
/*-----------------------------------------------------------------------*/
+#if FF_FS_READONLY == 0
+
DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
- DWORD sector, /* Start sector in LBA */
+ LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
@@ -185,6 +188,7 @@ DRESULT disk_write ( return RES_PARERR;
}
+#endif
/*-----------------------------------------------------------------------*/
diff --git a/fatfs/source/diskio.h b/fatfs/source/diskio.h index e8a4fa2..c22afaa 100644 --- a/fatfs/source/diskio.h +++ b/fatfs/source/diskio.h @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------/
-/ Low level disk interface modlue include file (C)ChaN, 2014 /
+/ Low level disk interface modlue include file (C)ChaN, 2019 /
/-----------------------------------------------------------------------*/
#ifndef _DISKIO_DEFINED
@@ -9,9 +9,6 @@ extern "C" {
#endif
-#include "integer.h"
-
-
/* Status of Disk Functions */
typedef BYTE DSTATUS;
@@ -31,8 +28,8 @@ typedef enum { DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
-DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
-DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
+DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
+DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
diff --git a/fatfs/source/ff.c b/fatfs/source/ff.c index c57a320..07412bb 100644 --- a/fatfs/source/ff.c +++ b/fatfs/source/ff.c @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/
-/ FatFs - Generic FAT Filesystem Module R0.13b /
+/ FatFs - Generic FAT Filesystem Module R0.15 w/patch1 /
/-----------------------------------------------------------------------------/
/
-/ Copyright (C) 2018, ChaN, all right reserved.
+/ Copyright (C) 2022, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
@@ -19,6 +19,7 @@ /----------------------------------------------------------------------------*/
+#include <string.h>
#include "ff.h" /* Declarations of FatFs API */
#include "diskio.h" /* Declarations of device I/O functions */
@@ -29,32 +30,44 @@ ---------------------------------------------------------------------------*/
-#if FF_DEFINED != 63463 /* Revision ID */
+#if FF_DEFINED != 80286 /* Revision ID */
#error Wrong include file (ff.h).
#endif
+/* Limits and boundaries */
+#define MAX_DIR 0x200000 /* Max size of FAT directory */
+#define MAX_DIR_EX 0x10000000 /* Max size of exFAT directory */
+#define MAX_FAT12 0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */
+#define MAX_FAT16 0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */
+#define MAX_FAT32 0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */
+#define MAX_EXFAT 0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */
+
+
/* Character code support macros */
#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z')
#define IsLower(c) ((c) >= 'a' && (c) <= 'z')
#define IsDigit(c) ((c) >= '0' && (c) <= '9')
+#define IsSeparator(c) ((c) == '/' || (c) == '\\')
+#define IsTerminator(c) ((UINT)(c) < (FF_USE_LFN ? ' ' : '!'))
#define IsSurrogate(c) ((c) >= 0xD800 && (c) <= 0xDFFF)
#define IsSurrogateH(c) ((c) >= 0xD800 && (c) <= 0xDBFF)
#define IsSurrogateL(c) ((c) >= 0xDC00 && (c) <= 0xDFFF)
-/* Additional file attribute bits for internal use */
-#define AM_VOL 0x08 /* Volume label */
-#define AM_LFN 0x0F /* LFN entry */
-#define AM_MASK 0x3F /* Mask of defined bits */
-
-
/* Additional file access control and file status flags for internal use */
#define FA_SEEKEND 0x20 /* Seek to end of the file on file open */
#define FA_MODIFIED 0x40 /* File has been modified */
#define FA_DIRTY 0x80 /* FIL.buf[] needs to be written-back */
+/* Additional file attribute bits for internal use */
+#define AM_VOL 0x08 /* Volume label */
+#define AM_LFN 0x0F /* LFN entry */
+#define AM_MASK 0x3F /* Mask of defined bits in FAT */
+#define AM_MASKX 0x37 /* Mask of defined bits in exFAT */
+
+
/* Name status flags in fn[11] */
#define NSFLAG 11 /* Index of the name status byte */
#define NS_LOSS 0x01 /* Out of 8.3 format */
@@ -67,13 +80,13 @@ #define NS_NONAME 0x80 /* Not followed */
-/* Limits and boundaries */
-#define MAX_DIR 0x200000 /* Max size of FAT directory */
-#define MAX_DIR_EX 0x10000000 /* Max size of exFAT directory */
-#define MAX_FAT12 0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */
-#define MAX_FAT16 0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */
-#define MAX_FAT32 0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */
-#define MAX_EXFAT 0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */
+/* exFAT directory entry types */
+#define ET_BITMAP 0x81 /* Allocation bitmap */
+#define ET_UPCASE 0x82 /* Up-case table */
+#define ET_VLABEL 0x83 /* Volume label */
+#define ET_FILEDIR 0x85 /* File and directory */
+#define ET_STREAM 0xC0 /* Stream extension */
+#define ET_FILENAME 0xC1 /* Name extension */
/* FatFs refers the FAT structure as simple byte array instead of structure member
@@ -195,6 +208,27 @@ #define PTE_StLba 8 /* MBR PTE: Start in LBA */
#define PTE_SizLba 12 /* MBR PTE: Size in LBA */
+#define GPTH_Sign 0 /* GPT HDR: Signature (8-byte) */
+#define GPTH_Rev 8 /* GPT HDR: Revision (DWORD) */
+#define GPTH_Size 12 /* GPT HDR: Header size (DWORD) */
+#define GPTH_Bcc 16 /* GPT HDR: Header BCC (DWORD) */
+#define GPTH_CurLba 24 /* GPT HDR: This header LBA (QWORD) */
+#define GPTH_BakLba 32 /* GPT HDR: Another header LBA (QWORD) */
+#define GPTH_FstLba 40 /* GPT HDR: First LBA for partition data (QWORD) */
+#define GPTH_LstLba 48 /* GPT HDR: Last LBA for partition data (QWORD) */
+#define GPTH_DskGuid 56 /* GPT HDR: Disk GUID (16-byte) */
+#define GPTH_PtOfs 72 /* GPT HDR: Partition table LBA (QWORD) */
+#define GPTH_PtNum 80 /* GPT HDR: Number of table entries (DWORD) */
+#define GPTH_PteSize 84 /* GPT HDR: Size of table entry (DWORD) */
+#define GPTH_PtBcc 88 /* GPT HDR: Partition table BCC (DWORD) */
+#define SZ_GPTE 128 /* GPT PTE: Size of partition table entry */
+#define GPTE_PtGuid 0 /* GPT PTE: Partition type GUID (16-byte) */
+#define GPTE_UpGuid 16 /* GPT PTE: Partition unique GUID (16-byte) */
+#define GPTE_FstLba 32 /* GPT PTE: First LBA of partition (QWORD) */
+#define GPTE_LstLba 40 /* GPT PTE: Last LBA of partition (QWORD) */
+#define GPTE_Flags 48 /* GPT PTE: Partition flags (QWORD) */
+#define GPTE_Name 56 /* GPT PTE: Partition name */
+
/* Post process on fatal error in the file operations */
#define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
@@ -203,21 +237,21 @@ /* Re-entrancy related */
#if FF_FS_REENTRANT
#if FF_USE_LFN == 1
-#error Static LFN work area cannot be used at thread-safe configuration
+#error Static LFN work area cannot be used in thread-safe configuration
#endif
-#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
+#define LEAVE_FF(fs, res) { unlock_volume(fs, res); return res; }
#else
#define LEAVE_FF(fs, res) return res
#endif
-/* Definitions of volume - physical location conversion */
+/* Definitions of logical drive - physical location conversion */
#if FF_MULTI_PARTITION
#define LD2PD(vol) VolToPart[vol].pd /* Get physical drive number */
-#define LD2PT(vol) VolToPart[vol].pt /* Get partition index */
+#define LD2PT(vol) VolToPart[vol].pt /* Get partition number (0:auto search, 1..:forced partition number) */
#else
-#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
-#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
+#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is associated with the same physical drive number */
+#define LD2PT(vol) 0 /* Auto partition search */
#endif
@@ -244,15 +278,15 @@ /* File lock controls */
-#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
#if FF_FS_READONLY
#error FF_FS_LOCK must be 0 at read-only configuration
#endif
typedef struct {
- FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */
+ FATFS* fs; /* Object ID 1, volume (NULL:blank entry) */
DWORD clu; /* Object ID 2, containing directory (0:root) */
DWORD ofs; /* Object ID 3, offset in the directory */
- WORD ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */
+ UINT ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */
} FILESEM;
#endif
@@ -397,6 +431,7 @@ typedef struct { /* DBCS code range |----- 1st byte -----| |----------- 2nd byte -----------| */
+/* <------> <------> <------> <------> <------> */
#define TBL_DC932 {0x81, 0x9F, 0xE0, 0xFC, 0x40, 0x7E, 0x80, 0xFC, 0x00, 0x00}
#define TBL_DC936 {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0x80, 0xFE, 0x00, 0x00}
#define TBL_DC949 {0x81, 0xFE, 0x00, 0x00, 0x41, 0x5A, 0x61, 0x7A, 0x81, 0xFE}
@@ -426,24 +461,35 @@ typedef struct { #if FF_VOLUMES < 1 || FF_VOLUMES > 10
#error Wrong FF_VOLUMES setting
#endif
-static FATFS* FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */
+static FATFS *FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */
static WORD Fsid; /* Filesystem mount ID */
#if FF_FS_RPATH != 0
-static BYTE CurrVol; /* Current drive */
+static BYTE CurrVol; /* Current drive set by f_chdrive() */
#endif
#if FF_FS_LOCK != 0
static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */
+#if FF_FS_REENTRANT
+static BYTE SysLock; /* System lock flag (0:no mutex, 1:unlocked, 2:locked) */
+#endif
#endif
#if FF_STR_VOLUME_ID
#ifdef FF_VOLUME_STRS
-static const char* const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-defined volume ID */
+static const char *const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-defined volume ID */
+#endif
+#endif
+
+#if FF_LBA64
+#if FF_MIN_GPT > 0x100000000
+#error Wrong FF_MIN_GPT setting
#endif
+static const BYTE GUID_MS_Basic[16] = {0xA2,0xA0,0xD0,0xEB,0xE5,0xB9,0x33,0x44,0x87,0xC0,0x68,0xB6,0xB7,0x26,0x99,0xC7};
#endif
+
/*--------------------------------*/
/* LFN/Directory working buffer */
/*--------------------------------*/
@@ -517,10 +563,12 @@ static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */ /* Code conversion tables */
/*--------------------------------*/
-#if FF_CODE_PAGE == 0 /* Run-time code page configuration */
+#if FF_CODE_PAGE == 0 /* Run-time code page configuration */
#define CODEPAGE CodePage
static WORD CodePage; /* Current code page */
-static const BYTE *ExCvt, *DbcTbl; /* Pointer to current SBCS up-case table and DBCS code range table below */
+static const BYTE* ExCvt; /* Ptr to SBCS up-case table Ct???[] (null:not used) */
+static const BYTE* DbcTbl; /* Ptr to DBCS code range table Dc???[] (null:not used) */
+
static const BYTE Ct437[] = TBL_CT437;
static const BYTE Ct720[] = TBL_CT720;
static const BYTE Ct737[] = TBL_CT737;
@@ -640,54 +688,7 @@ static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-en /* String functions */
/*-----------------------------------------------------------------------*/
-/* Copy memory to memory */
-static void mem_cpy (void* dst, const void* src, UINT cnt)
-{
- BYTE *d = (BYTE*)dst;
- const BYTE *s = (const BYTE*)src;
-
- if (cnt != 0) {
- do {
- *d++ = *s++;
- } while (--cnt);
- }
-}
-
-
-/* Fill memory block */
-static void mem_set (void* dst, int val, UINT cnt)
-{
- BYTE *d = (BYTE*)dst;
-
- do {
- *d++ = (BYTE)val;
- } while (--cnt);
-}
-
-
-/* Compare memory block */
-static int mem_cmp (const void* dst, const void* src, UINT cnt) /* ZR:same, NZ:different */
-{
- const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src;
- int r = 0;
-
- do {
- r = *d++ - *s++;
- } while (--cnt && r == 0);
-
- return r;
-}
-
-
-/* Check if chr is contained in the string */
-static int chk_chr (const char* str, int chr) /* NZ:contained, ZR:not contained */
-{
- while (*str && *str != chr) str++;
- return *str;
-}
-
-
-/* Test if the character is DBC 1st byte */
+/* Test if the byte is DBC 1st byte */
static int dbc_1st (BYTE c)
{
#if FF_CODE_PAGE == 0 /* Variable code page */
@@ -707,7 +708,7 @@ static int dbc_1st (BYTE c) }
-/* Test if the character is DBC 2nd byte */
+/* Test if the byte is DBC 2nd byte */
static int dbc_2nd (BYTE c)
{
#if FF_CODE_PAGE == 0 /* Variable code page */
@@ -731,8 +732,8 @@ static int dbc_2nd (BYTE c) #if FF_USE_LFN
-/* Get a character from TCHAR string in defined API encodeing */
-static DWORD tchar2uni ( /* Returns character in UTF-16 encoding (>=0x10000 on double encoding unit, 0xFFFFFFFF on decode error) */
+/* Get a Unicode code point from the TCHAR string in defined API encodeing */
+static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on surrogate pair, 0xFFFFFFFF on decode error) */
const TCHAR** str /* Pointer to pointer to TCHAR string in configured encoding */
)
{
@@ -753,20 +754,16 @@ static DWORD tchar2uni ( /* Returns character in UTF-16 encoding (>=0x10000 on d BYTE b;
int nf;
- uc = (BYTE)*p++; /* Get a unit */
+ uc = (BYTE)*p++; /* Get an encoding unit */
if (uc & 0x80) { /* Multiple byte code? */
- if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */
+ if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */
uc &= 0x1F; nf = 1;
- } else {
- if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */
- uc &= 0x0F; nf = 2;
- } else {
- if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */
- uc &= 0x07; nf = 3;
- } else { /* Wrong sequence */
- return 0xFFFFFFFF;
- }
- }
+ } else if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */
+ uc &= 0x0F; nf = 2;
+ } else if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */
+ uc &= 0x07; nf = 3;
+ } else { /* Wrong sequence */
+ return 0xFFFFFFFF;
}
do { /* Get trailing bytes */
b = (BYTE)*p++;
@@ -779,7 +776,7 @@ static DWORD tchar2uni ( /* Returns character in UTF-16 encoding (>=0x10000 on d #elif FF_LFN_UNICODE == 3 /* UTF-32 input */
uc = (TCHAR)*p++; /* Get a unit */
- if (uc >= 0x110000) return 0xFFFFFFFF; /* Wrong code? */
+ if (uc >= 0x110000 || IsSurrogate(uc)) return 0xFFFFFFFF; /* Wrong code? */
if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */
#else /* ANSI/OEM input */
@@ -804,9 +801,9 @@ static DWORD tchar2uni ( /* Returns character in UTF-16 encoding (>=0x10000 on d }
-/* Output a TCHAR string in defined API encoding */
-static BYTE put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */
- DWORD chr, /* UTF-16 encoded character (Double encoding unit char if >=0x10000) */
+/* Store a Unicode char in defined API encoding */
+static UINT put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */
+ DWORD chr, /* UTF-16 encoded character (Surrogate pair if >=0x10000) */
TCHAR* buf, /* Output buffer */
UINT szb /* Size of the buffer */
)
@@ -894,21 +891,45 @@ static BYTE put_utf ( /* Returns number of encoding units written (0:buffer over /*-----------------------------------------------------------------------*/
/* Request/Release grant to access the volume */
/*-----------------------------------------------------------------------*/
-static int lock_fs ( /* 1:Ok, 0:timeout */
- FATFS* fs /* Filesystem object */
+
+static int lock_volume ( /* 1:Ok, 0:timeout */
+ FATFS* fs, /* Filesystem object to lock */
+ int syslock /* System lock required */
)
{
- return ff_req_grant(fs->sobj);
+ int rv;
+
+
+#if FF_FS_LOCK
+ rv = ff_mutex_take(fs->ldrv); /* Lock the volume */
+ if (rv && syslock) { /* System lock reqiered? */
+ rv = ff_mutex_take(FF_VOLUMES); /* Lock the system */
+ if (rv) {
+ SysLock = 2; /* System lock succeeded */
+ } else {
+ ff_mutex_give(fs->ldrv); /* Failed system lock */
+ }
+ }
+#else
+ rv = syslock ? ff_mutex_take(fs->ldrv) : ff_mutex_take(fs->ldrv); /* Lock the volume (this is to prevent compiler warning) */
+#endif
+ return rv;
}
-static void unlock_fs (
+static void unlock_volume (
FATFS* fs, /* Filesystem object */
FRESULT res /* Result code to be returned */
)
{
if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) {
- ff_rel_grant(fs->sobj);
+#if FF_FS_LOCK
+ if (SysLock == 2) { /* Is the system locked? */
+ SysLock = 1;
+ ff_mutex_give(FF_VOLUMES);
+ }
+#endif
+ ff_mutex_give(fs->ldrv); /* Unlock the volume */
}
}
@@ -916,12 +937,12 @@ static void unlock_fs ( -#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
/*-----------------------------------------------------------------------*/
-/* File lock control functions */
+/* File shareing control functions */
/*-----------------------------------------------------------------------*/
-static FRESULT chk_lock ( /* Check if the file can be accessed */
+static FRESULT chk_share ( /* Check if the file can be accessed */
DIR* dp, /* Directory object pointing the file to be checked */
int acc /* Desired access type (0:Read mode open, 1:Write mode open, 2:Delete or rename) */
)
@@ -948,16 +969,16 @@ static FRESULT chk_lock ( /* Check if the file can be accessed */ }
-static int enq_lock (void) /* Check if an entry is available for a new object */
+static int enq_share (void) /* Check if an entry is available for a new object */
{
UINT i;
- for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+ for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; /* Find a free entry */
return (i == FF_FS_LOCK) ? 0 : 1;
}
-static UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */
+static UINT inc_share ( /* Increment object open counter and returns its index (0:Internal error) */
DIR* dp, /* Directory object pointing the file to register or increment */
int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
)
@@ -966,13 +987,13 @@ static UINT inc_lock ( /* Increment object open counter and returns its index (0 for (i = 0; i < FF_FS_LOCK; i++) { /* Find the object */
- if (Files[i].fs == dp->obj.fs &&
- Files[i].clu == dp->obj.sclust &&
- Files[i].ofs == dp->dptr) break;
+ if (Files[i].fs == dp->obj.fs
+ && Files[i].clu == dp->obj.sclust
+ && Files[i].ofs == dp->dptr) break;
}
- if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */
- for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+ if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */
+ for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; /* Find a free entry */
if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */
Files[i].fs = dp->obj.fs;
Files[i].clu = dp->obj.sclust;
@@ -988,30 +1009,32 @@ static UINT inc_lock ( /* Increment object open counter and returns its index (0 }
-static FRESULT dec_lock ( /* Decrement object open counter */
+static FRESULT dec_share ( /* Decrement object open counter */
UINT i /* Semaphore index (1..) */
)
{
- WORD n;
+ UINT n;
FRESULT res;
if (--i < FF_FS_LOCK) { /* Index number origin from 0 */
n = Files[i].ctr;
- if (n == 0x100) n = 0; /* If write mode open, delete the entry */
- if (n > 0) n--; /* Decrement read mode open count */
+ if (n == 0x100) n = 0; /* If write mode open, delete the object semaphore */
+ if (n > 0) n--; /* Decrement read mode open count */
Files[i].ctr = n;
- if (n == 0) Files[i].fs = 0; /* Delete the entry if open count gets zero */
+ if (n == 0) { /* Delete the object semaphore if open count becomes zero */
+ Files[i].fs = 0; /* Free the entry <<<If this memory write operation is not in atomic, FF_FS_REENTRANT == 1 and FF_VOLUMES > 1, there is a potential error in this process >>> */
+ }
res = FR_OK;
} else {
- res = FR_INT_ERR; /* Invalid index nunber */
+ res = FR_INT_ERR; /* Invalid index number */
}
return res;
}
-static void clear_lock ( /* Clear lock entries of the volume */
- FATFS *fs
+static void clear_share ( /* Clear all lock entries of the volume */
+ FATFS* fs
)
{
UINT i;
@@ -1021,7 +1044,7 @@ static void clear_lock ( /* Clear lock entries of the volume */ }
}
-#endif /* FF_FS_LOCK != 0 */
+#endif /* FF_FS_LOCK */
@@ -1036,8 +1059,8 @@ static FRESULT sync_window ( /* Returns FR_OK or FR_DISK_ERR */ FRESULT res = FR_OK;
- if (fs->wflag) { /* Is the disk access window dirty */
- if (disk_write(fs->pdrv, fs->win, fs->winsect, 1) == RES_OK) { /* Write back the window */
+ if (fs->wflag) { /* Is the disk access window dirty? */
+ if (disk_write(fs->pdrv, fs->win, fs->winsect, 1) == RES_OK) { /* Write it back into the volume */
fs->wflag = 0; /* Clear window dirty flag */
if (fs->winsect - fs->fatbase < fs->fsize) { /* Is it in the 1st FAT? */
if (fs->n_fats == 2) disk_write(fs->pdrv, fs->win, fs->winsect + fs->fsize, 1); /* Reflect it to 2nd FAT if needed */
@@ -1052,23 +1075,23 @@ static FRESULT sync_window ( /* Returns FR_OK or FR_DISK_ERR */ static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
- FATFS* fs, /* Filesystem object */
- DWORD sector /* Sector number to make appearance in the fs->win[] */
+ FATFS* fs, /* Filesystem object */
+ LBA_t sect /* Sector LBA to make appearance in the fs->win[] */
)
{
FRESULT res = FR_OK;
- if (sector != fs->winsect) { /* Window offset changed? */
+ if (sect != fs->winsect) { /* Window offset changed? */
#if !FF_FS_READONLY
- res = sync_window(fs); /* Write-back changes */
+ res = sync_window(fs); /* Flush the window */
#endif
if (res == FR_OK) { /* Fill sector window with new data */
- if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK) {
- sector = 0xFFFFFFFF; /* Invalidate window if read data is not valid */
+ if (disk_read(fs->pdrv, fs->win, sect, 1) != RES_OK) {
+ sect = (LBA_t)0 - 1; /* Invalidate window if read data is not valid */
res = FR_DISK_ERR;
}
- fs->winsect = sector;
+ fs->winsect = sect;
}
}
return res;
@@ -1093,14 +1116,13 @@ static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */ if (res == FR_OK) {
if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { /* FAT32: Update FSInfo sector if needed */
/* Create FSInfo structure */
- mem_set(fs->win, 0, SS(fs));
- st_word(fs->win + BS_55AA, 0xAA55);
- st_dword(fs->win + FSI_LeadSig, 0x41615252);
- st_dword(fs->win + FSI_StrucSig, 0x61417272);
- st_dword(fs->win + FSI_Free_Count, fs->free_clst);
- st_dword(fs->win + FSI_Nxt_Free, fs->last_clst);
- /* Write it into the FSInfo sector */
- fs->winsect = fs->volbase + 1;
+ memset(fs->win, 0, sizeof fs->win);
+ st_word(fs->win + BS_55AA, 0xAA55); /* Boot signature */
+ st_dword(fs->win + FSI_LeadSig, 0x41615252); /* Leading signature */
+ st_dword(fs->win + FSI_StrucSig, 0x61417272); /* Structure signature */
+ st_dword(fs->win + FSI_Free_Count, fs->free_clst); /* Number of free clusters */
+ st_dword(fs->win + FSI_Nxt_Free, fs->last_clst); /* Last allocated culuster */
+ fs->winsect = fs->volbase + 1; /* Write it into the FSInfo sector (Next to VBR) */
disk_write(fs->pdrv, fs->win, fs->winsect, 1);
fs->fsi_flag = 0;
}
@@ -1119,21 +1141,21 @@ static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */ /* Get physical sector number from cluster number */
/*-----------------------------------------------------------------------*/
-static DWORD clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */
+static LBA_t clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */
FATFS* fs, /* Filesystem object */
DWORD clst /* Cluster# to be converted */
)
{
clst -= 2; /* Cluster number is origin from 2 */
if (clst >= fs->n_fatent - 2) return 0; /* Is it invalid cluster number? */
- return fs->database + fs->csize * clst; /* Start sector number of the cluster */
+ return fs->database + (LBA_t)fs->csize * clst; /* Start sector number of the cluster */
}
/*-----------------------------------------------------------------------*/
-/* FAT access - Read value of a FAT entry */
+/* FAT access - Read value of an FAT entry */
/*-----------------------------------------------------------------------*/
static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */
@@ -1175,7 +1197,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF case FS_EXFAT :
if ((obj->objsize != 0 && obj->sclust != 0) || obj->stat == 0) { /* Object except root dir must have valid data length */
DWORD cofs = clst - obj->sclust; /* Offset from start cluster */
- DWORD clen = (DWORD)((obj->objsize - 1) / SS(fs)) / fs->csize; /* Number of clusters - 1 */
+ DWORD clen = (DWORD)((LBA_t)((obj->objsize - 1) / SS(fs)) / fs->csize); /* Number of clusters - 1 */
if (obj->stat == 2 && cofs <= clen) { /* Is it a contiguous chain? */
val = (cofs == clen) ? 0x7FFFFFFF : clst + 1; /* No data on the FAT, generate the value */
@@ -1195,7 +1217,8 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF break;
}
}
- /* go to default */
+ val = 1; /* Internal error */
+ break;
#endif
default:
val = 1; /* Internal error */
@@ -1210,7 +1233,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF #if !FF_FS_READONLY
/*-----------------------------------------------------------------------*/
-/* FAT access - Change value of a FAT entry */
+/* FAT access - Change value of an FAT entry */
/*-----------------------------------------------------------------------*/
static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */
@@ -1226,30 +1249,30 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ if (clst >= 2 && clst < fs->n_fatent) { /* Check if in valid range */
switch (fs->fs_type) {
- case FS_FAT12 :
+ case FS_FAT12:
bc = (UINT)clst; bc += bc / 2; /* bc: byte offset of the entry */
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
p = fs->win + bc++ % SS(fs);
- *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Put 1st byte */
+ *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */
fs->wflag = 1;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
p = fs->win + bc % SS(fs);
- *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); /* Put 2nd byte */
+ *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); /* Update 2nd byte */
fs->wflag = 1;
break;
- case FS_FAT16 :
+ case FS_FAT16:
res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)));
if (res != FR_OK) break;
st_word(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */
fs->wflag = 1;
break;
- case FS_FAT32 :
+ case FS_FAT32:
#if FF_FS_EXFAT
- case FS_EXFAT :
+ case FS_EXFAT:
#endif
res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)));
if (res != FR_OK) break;
@@ -1293,7 +1316,7 @@ static DWORD find_bitmap ( /* 0:Not found, 2..:Cluster block found, 0xFFFFFFFF:D if (clst >= fs->n_fatent - 2) clst = 0;
scl = val = clst; ctr = 0;
for (;;) {
- if (move_window(fs, fs->database + val / 8 / SS(fs)) != FR_OK) return 0xFFFFFFFF; /* (assuming bitmap is located top of the cluster heap) */
+ if (move_window(fs, fs->bitbase + val / 8 / SS(fs)) != FR_OK) return 0xFFFFFFFF;
i = val / 8 % SS(fs); bm = 1 << (val % 8);
do {
do {
@@ -1327,13 +1350,13 @@ static FRESULT change_bitmap ( {
BYTE bm;
UINT i;
- DWORD sect;
+ LBA_t sect;
clst -= 2; /* The first bit corresponds to cluster #2 */
- sect = fs->database + clst / 8 / SS(fs); /* Sector address (assuming bitmap is located top of the cluster heap) */
- i = clst / 8 % SS(fs); /* Byte offset in the sector */
- bm = 1 << (clst % 8); /* Bit mask in the byte */
+ sect = fs->bitbase + clst / 8 / SS(fs); /* Sector address */
+ i = clst / 8 % SS(fs); /* Byte offset in the sector */
+ bm = 1 << (clst % 8); /* Bit mask in the byte */
for (;;) {
if (move_window(fs, sect++) != FR_OK) return FR_DISK_ERR;
do {
@@ -1406,7 +1429,7 @@ static FRESULT fill_last_frag ( static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */
FFOBJID* obj, /* Corresponding object */
DWORD clst, /* Cluster to remove a chain from */
- DWORD pclst /* Previous cluster of clst (0:entire chain) */
+ DWORD pclst /* Previous cluster of clst (0 if entire chain) */
)
{
FRESULT res = FR_OK;
@@ -1416,7 +1439,7 @@ static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ DWORD scl = clst, ecl = clst;
#endif
#if FF_USE_TRIM
- DWORD rt[2];
+ LBA_t rt[2];
#endif
if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Check if in valid range */
@@ -1452,9 +1475,9 @@ static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ }
#endif
#if FF_USE_TRIM
- rt[0] = clst2sect(fs, scl); /* Start of data area freed */
- rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area freed */
- disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform device the data in the block is no longer needed */
+ rt[0] = clst2sect(fs, scl); /* Start of data area to be freed */
+ rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area to be freed */
+ disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform storage device that the data in the block may be erased */
#endif
scl = ecl = nxt;
}
@@ -1606,7 +1629,8 @@ static DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ FSIZE_t ofs /* File offset to be converted to cluster# */
)
{
- DWORD cl, ncl, *tbl;
+ DWORD cl, ncl;
+ DWORD *tbl;
FATFS *fs = fp->obj.fs;
@@ -1636,7 +1660,7 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */ DWORD clst /* Directory table to clear */
)
{
- DWORD sect;
+ LBA_t sect;
UINT n, szb;
BYTE *ibuf;
@@ -1644,12 +1668,12 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */ if (sync_window(fs) != FR_OK) return FR_DISK_ERR; /* Flush disk access window */
sect = clst2sect(fs, clst); /* Top of the cluster */
fs->winsect = sect; /* Set window to top of the cluster */
- mem_set(fs->win, 0, SS(fs)); /* Clear window buffer */
+ memset(fs->win, 0, sizeof fs->win); /* Clear window buffer */
#if FF_USE_LFN == 3 /* Quick table clear by using multi-secter write */
/* Allocate a temporary buffer */
for (szb = ((DWORD)fs->csize * SS(fs) >= MAX_MALLOC) ? MAX_MALLOC : fs->csize * SS(fs), ibuf = 0; szb > SS(fs) && (ibuf = ff_memalloc(szb)) == 0; szb /= 2) ;
if (szb > SS(fs)) { /* Buffer allocated? */
- mem_set(ibuf, 0, szb);
+ memset(ibuf, 0, szb);
szb /= SS(fs); /* Bytes -> Sectors */
for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */
ff_memfree(ibuf);
@@ -1685,7 +1709,7 @@ static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */ dp->dptr = ofs; /* Set current offset */
clst = dp->obj.sclust; /* Table start cluster (0:root) */
if (clst == 0 && fs->fs_type >= FS_FAT32) { /* Replace cluster# 0 with root cluster# */
- clst = fs->dirbase;
+ clst = (DWORD)fs->dirbase;
if (FF_FS_EXFAT) dp->obj.stat = 0; /* exFAT: Root dir has an FAT chain */
}
@@ -1781,7 +1805,7 @@ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DEN static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp, /* Pointer to the directory object */
- UINT nent /* Number of contiguous entries to allocate */
+ UINT n_ent /* Number of contiguous entries to allocate */
)
{
FRESULT res;
@@ -1796,16 +1820,16 @@ static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */ res = move_window(fs, dp->sect);
if (res != FR_OK) break;
#if FF_FS_EXFAT
- if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) {
+ if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) { /* Is the entry free? */
#else
- if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) {
+ if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) { /* Is the entry free? */
#endif
- if (++n == nent) break; /* A block of contiguous free entries is found */
+ if (++n == n_ent) break; /* Is a block of contiguous free entries found? */
} else {
- n = 0; /* Not a blank entry. Restart to search */
+ n = 0; /* Not a free entry, restart to search */
}
- res = dir_next(dp, 1);
- } while (res == FR_OK); /* Next entry with table stretch enabled */
+ res = dir_next(dp, 1); /* Next entry with table stretch enabled */
+ } while (res == FR_OK);
}
if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */
@@ -1874,7 +1898,7 @@ static int cmp_lfn ( /* 1:matched, 0:not matched */ for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */
uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */
if (wc != 0) {
- if (i >= FF_MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) { /* Compare it */
+ if (i >= FF_MAX_LFN + 1 || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) { /* Compare it */
return 0; /* Not matched */
}
wc = uc;
@@ -1910,15 +1934,15 @@ static int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */ for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */
uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */
if (wc != 0) {
- if (i >= FF_MAX_LFN) return 0; /* Buffer overflow? */
+ if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */
lfnbuf[i++] = wc = uc; /* Store it */
} else {
if (uc != 0xFFFF) return 0; /* Check filler */
}
}
- if (dir[LDIR_Ord] & LLEF) { /* Put terminator if it is the last LFN part */
- if (i >= FF_MAX_LFN) return 0; /* Buffer overflow? */
+ if (dir[LDIR_Ord] & LLEF && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */
+ if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */
lfnbuf[i] = 0;
}
@@ -1953,7 +1977,7 @@ static void put_lfn ( do {
if (wc != 0xFFFF) wc = lfn[i++]; /* Get an effective character */
st_word(dir + LfnOfs[s], wc); /* Put it */
- if (wc == 0) wc = 0xFFFF; /* Padding characters for left locations */
+ if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */
} while (++s < 13);
if (wc == 0xFFFF || !lfn[i]) ord |= LLEF; /* Last LFN part is the start of LFN sequence */
dir[LDIR_Ord] = ord; /* Set the LFN order */
@@ -1971,7 +1995,7 @@ static void put_lfn ( static void gen_numname (
BYTE* dst, /* Pointer to the buffer to store numbered SFN */
- const BYTE* src, /* Pointer to SFN */
+ const BYTE* src, /* Pointer to SFN in directory form */
const WCHAR* lfn, /* Pointer to LFN */
UINT seq /* Sequence number */
)
@@ -1979,42 +2003,41 @@ static void gen_numname ( BYTE ns[8], c;
UINT i, j;
WCHAR wc;
- DWORD sr;
+ DWORD sreg;
- mem_cpy(dst, src, 11);
+ memcpy(dst, src, 11); /* Prepare the SFN to be modified */
if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */
- sr = seq;
+ sreg = seq;
while (*lfn) { /* Create a CRC as hash value */
wc = *lfn++;
for (i = 0; i < 16; i++) {
- sr = (sr << 1) + (wc & 1);
+ sreg = (sreg << 1) + (wc & 1);
wc >>= 1;
- if (sr & 0x10000) sr ^= 0x11021;
+ if (sreg & 0x10000) sreg ^= 0x11021;
}
}
- seq = (UINT)sr;
+ seq = (UINT)sreg;
}
- /* itoa (hexdecimal) */
+ /* Make suffix (~ + hexadecimal) */
i = 7;
do {
- c = (BYTE)((seq % 16) + '0');
+ c = (BYTE)((seq % 16) + '0'); seq /= 16;
if (c > '9') c += 7;
ns[i--] = c;
- seq /= 16;
- } while (seq);
+ } while (i && seq);
ns[i] = '~';
- /* Append the number to the SFN body */
- for (j = 0; j < i && dst[j] != ' '; j++) {
- if (dbc_1st(dst[j])) {
+ /* Append the suffix to the SFN body */
+ for (j = 0; j < i && dst[j] != ' '; j++) { /* Find the offset to append */
+ if (dbc_1st(dst[j])) { /* To avoid DBC break up */
if (j == i - 1) break;
j++;
}
}
- do {
+ do { /* Append the suffix */
dst[j++] = (i < 8) ? ns[i++] : ' ';
} while (j < 8);
}
@@ -2099,89 +2122,48 @@ static DWORD xsum32 ( /* Returns 32-bit checksum */ #endif
-#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
-/*------------------------------------------------------*/
-/* exFAT: Get object information from a directory block */
-/*------------------------------------------------------*/
-static void get_xfileinfo (
- BYTE* dirb, /* Pointer to the direcotry entry block 85+C0+C1s */
- FILINFO* fno /* Buffer to store the extracted file information */
-)
-{
- WCHAR wc, hs;
- UINT di, si, nc;
-
- /* Get file name from the entry block */
- si = SZDIRE * 2; /* 1st C1 entry */
- nc = 0; hs = 0; di = 0;
- while (nc < dirb[XDIR_NumName]) {
- if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */
- if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */
- wc = ld_word(dirb + si); si += 2; nc++; /* Get a character */
- if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
- hs = wc; continue; /* Get low surrogate */
- }
- wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
- if (wc == 0) { di = 0; break; } /* Buffer overflow or wrong encoding? */
- di += wc;
- hs = 0;
- }
- if (hs != 0) di = 0; /* Broken surrogate pair? */
- if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */
- fno->fname[di] = 0; /* Terminate the name */
- fno->altname[0] = 0; /* exFAT does not support SFN */
-
- fno->fattrib = dirb[XDIR_Attr]; /* Attribute */
- fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(dirb + XDIR_FileSize); /* Size */
- fno->ftime = ld_word(dirb + XDIR_ModTime + 0); /* Time */
- fno->fdate = ld_word(dirb + XDIR_ModTime + 2); /* Date */
-}
-
-#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
-
-
-/*-----------------------------------*/
-/* exFAT: Get a directry entry block */
-/*-----------------------------------*/
+/*------------------------------------*/
+/* exFAT: Get a directory entry block */
+/*------------------------------------*/
static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */
- DIR* dp /* Reading direcotry object pointing top of the entry block to load */
+ DIR* dp /* Reading directory object pointing top of the entry block to load */
)
{
FRESULT res;
UINT i, sz_ent;
- BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory direcotry entry block 85+C0+C1s */
+ BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory directory entry block 85+C0+C1s */
- /* Load 85 entry */
+ /* Load file directory entry */
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
- if (dp->dir[XDIR_Type] != 0x85) return FR_INT_ERR; /* Invalid order */
- mem_cpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE);
+ if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR; /* Invalid order */
+ memcpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE);
sz_ent = (dirb[XDIR_NumSec] + 1) * SZDIRE;
if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR;
- /* Load C0 entry */
+ /* Load stream extension entry */
res = dir_next(dp, 0);
if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be */
if (res != FR_OK) return res;
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
- if (dp->dir[XDIR_Type] != 0xC0) return FR_INT_ERR; /* Invalid order */
- mem_cpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE);
+ if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR; /* Invalid order */
+ memcpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE);
if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR;
- /* Load C1 entries */
- i = 2 * SZDIRE; /* C1 offset to load */
+ /* Load file name entries */
+ i = 2 * SZDIRE; /* Name offset to load */
do {
res = dir_next(dp, 0);
if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be */
if (res != FR_OK) return res;
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
- if (dp->dir[XDIR_Type] != 0xC1) return FR_INT_ERR; /* Invalid order */
- if (i < MAXDIRB(FF_MAX_LFN)) mem_cpy(dirb + i, dp->dir, SZDIRE);
+ if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR; /* Invalid order */
+ if (i < MAXDIRB(FF_MAX_LFN)) memcpy(dirb + i, dp->dir, SZDIRE);
} while ((i += SZDIRE) < sz_ent);
/* Sanity check (do it for only accessible object) */
@@ -2215,7 +2197,7 @@ static void init_alloc_info ( /*------------------------------------------------*/
static FRESULT load_obj_xdir (
- DIR* dp, /* Blank directory object to be used to access containing direcotry */
+ DIR* dp, /* Blank directory object to be used to access containing directory */
const FFOBJID* obj /* Object with its containing directory information */
)
{
@@ -2244,23 +2226,23 @@ static FRESULT load_obj_xdir ( /*----------------------------------------*/
static FRESULT store_xdir (
- DIR* dp /* Pointer to the direcotry object */
+ DIR* dp /* Pointer to the directory object */
)
{
FRESULT res;
UINT nent;
- BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the direcotry entry block 85+C0+C1s */
+ BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the directory entry block 85+C0+C1s */
/* Create set sum */
st_word(dirb + XDIR_SetSum, xdir_sum(dirb));
nent = dirb[XDIR_NumSec] + 1;
- /* Store the direcotry entry block to the directory */
+ /* Store the directory entry block to the directory */
res = dir_sdi(dp, dp->blk_ofs);
while (res == FR_OK) {
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) break;
- mem_cpy(dp->dir, dirb, SZDIRE);
+ memcpy(dp->dir, dirb, SZDIRE);
dp->obj.fs->wflag = 1;
if (--nent == 0) break;
dirb += SZDIRE;
@@ -2272,11 +2254,11 @@ static FRESULT store_xdir ( /*-------------------------------------------*/
-/* exFAT: Create a new directory enrty block */
+/* exFAT: Create a new directory entry block */
/*-------------------------------------------*/
static void create_xdir (
- BYTE* dirb, /* Pointer to the direcotry entry block buffer */
+ BYTE* dirb, /* Pointer to the directory entry block buffer */
const WCHAR* lfn /* Pointer to the object name */
)
{
@@ -2285,19 +2267,19 @@ static void create_xdir ( WCHAR wc;
- /* Create 85,C0 entry */
- mem_set(dirb, 0, 2 * SZDIRE);
- dirb[0 * SZDIRE + XDIR_Type] = 0x85; /* 85 entry */
- dirb[1 * SZDIRE + XDIR_Type] = 0xC0; /* C0 entry */
+ /* Create file-directory and stream-extension entry */
+ memset(dirb, 0, 2 * SZDIRE);
+ dirb[0 * SZDIRE + XDIR_Type] = ET_FILEDIR;
+ dirb[1 * SZDIRE + XDIR_Type] = ET_STREAM;
- /* Create C1 entries */
- i = SZDIRE * 2; /* Top of C1 entries */
+ /* Create file-name entries */
+ i = SZDIRE * 2; /* Top of file_name entries */
nlen = nc1 = 0; wc = 1;
do {
- dirb[i++] = 0xC1; dirb[i++] = 0; /* Entry type C1 */
+ dirb[i++] = ET_FILENAME; dirb[i++] = 0;
do { /* Fill name field */
if (wc != 0 && (wc = lfn[nlen]) != 0) nlen++; /* Get a character if exist */
- st_word(dirb + i, wc); /* Store it */
+ st_word(dirb + i, wc); /* Store it */
i += 2;
} while (i % SZDIRE != 0);
nc1++;
@@ -2318,8 +2300,8 @@ static void create_xdir ( /* Read an object from the directory */
/*-----------------------------------------------------------------------*/
-#define dir_read_file(dp) dir_read(dp, 0)
-#define dir_read_label(dp) dir_read(dp, 1)
+#define DIR_READ_FILE(dp) dir_read(dp, 0)
+#define DIR_READ_LABEL(dp) dir_read(dp, 1)
static FRESULT dir_read (
DIR* dp, /* Pointer to the directory object */
@@ -2328,7 +2310,7 @@ static FRESULT dir_read ( {
FRESULT res = FR_NO_FILE;
FATFS *fs = dp->obj.fs;
- BYTE a, c;
+ BYTE attr, b;
#if FF_USE_LFN
BYTE ord = 0xFF, sum = 0xFF;
#endif
@@ -2336,16 +2318,16 @@ static FRESULT dir_read ( while (dp->sect) {
res = move_window(fs, dp->sect);
if (res != FR_OK) break;
- c = dp->dir[DIR_Name]; /* Test for the entry type */
- if (c == 0) {
+ b = dp->dir[DIR_Name]; /* Test for the entry type */
+ if (b == 0) {
res = FR_NO_FILE; break; /* Reached to end of the directory */
}
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
if (FF_USE_LABEL && vol) {
- if (c == 0x83) break; /* Volume label entry? */
+ if (b == ET_VLABEL) break; /* Volume label entry? */
} else {
- if (c == 0x85) { /* Start of the file entry block? */
+ if (b == ET_FILEDIR) { /* Start of the file entry block? */
dp->blk_ofs = dp->dptr; /* Get location of the block */
res = load_xdir(dp); /* Load the entry block */
if (res == FR_OK) {
@@ -2357,28 +2339,28 @@ static FRESULT dir_read ( } else
#endif
{ /* On the FAT/FAT32 volume */
- dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */
+ dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */
#if FF_USE_LFN /* LFN configuration */
- if (c == DDEM || c == '.' || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
+ if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
ord = 0xFF;
} else {
- if (a == AM_LFN) { /* An LFN entry is found */
- if (c & LLEF) { /* Is it start of an LFN sequence? */
+ if (attr == AM_LFN) { /* An LFN entry is found */
+ if (b & LLEF) { /* Is it start of an LFN sequence? */
sum = dp->dir[LDIR_Chksum];
- c &= (BYTE)~LLEF; ord = c;
+ b &= (BYTE)~LLEF; ord = b;
dp->blk_ofs = dp->dptr;
}
/* Check LFN validity and capture it */
- ord = (c == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
- } else { /* An SFN entry is found */
+ ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
+ } else { /* An SFN entry is found */
if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */
- dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
+ dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
}
break;
}
}
#else /* Non LFN configuration */
- if (c != DDEM && c != '.' && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */
+ if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */
break;
}
#endif
@@ -2418,9 +2400,9 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ UINT di, ni;
WORD hash = xname_sum(fs->lfnbuf); /* Hash value of the name to find */
- while ((res = dir_read_file(dp)) == FR_OK) { /* Read an item */
+ while ((res = DIR_READ_FILE(dp)) == FR_OK) { /* Read an item */
#if FF_MAX_LFN < 255
- if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */
+ if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */
#endif
if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */
for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */
@@ -2458,13 +2440,13 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ }
} else { /* An SFN entry is found */
if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */
- if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
+ if (!(dp->fn[NSFLAG] & NS_LOSS) && !memcmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */
}
}
#else /* Non LFN configuration */
dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;
- if (!(dp->dir[DIR_Attr] & AM_VOL) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
+ if (!(dp->dir[DIR_Attr] & AM_VOL) && !memcmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
#endif
res = dir_next(dp, 0); /* Next entry */
} while (res == FR_OK);
@@ -2487,35 +2469,35 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too FRESULT res;
FATFS *fs = dp->obj.fs;
#if FF_USE_LFN /* LFN configuration */
- UINT n, nlen, nent;
+ UINT n, len, n_ent;
BYTE sn[12], sum;
if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */
- for (nlen = 0; fs->lfnbuf[nlen]; nlen++) ; /* Get lfn length */
+ for (len = 0; fs->lfnbuf[len]; len++) ; /* Get lfn length */
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
- nent = (nlen + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */
- res = dir_alloc(dp, nent); /* Allocate entries */
+ n_ent = (len + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */
+ res = dir_alloc(dp, n_ent); /* Allocate directory entries */
if (res != FR_OK) return res;
- dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1); /* Set the allocated entry block offset */
+ dp->blk_ofs = dp->dptr - SZDIRE * (n_ent - 1); /* Set the allocated entry block offset */
- if (dp->obj.stat & 4) { /* Has the directory been stretched? */
+ if (dp->obj.stat & 4) { /* Has the directory been stretched by new allocation? */
dp->obj.stat &= ~4;
res = fill_first_frag(&dp->obj); /* Fill the first fragment on the FAT if needed */
if (res != FR_OK) return res;
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */
if (res != FR_OK) return res;
- if (dp->obj.sclust != 0) { /* Is it a sub directory? */
+ if (dp->obj.sclust != 0) { /* Is it a sub-directory? */
DIR dj;
res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */
if (res != FR_OK) return res;
- dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
- st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */
+ dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
+ st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize);
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
- fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;
+ fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */
res = store_xdir(&dj); /* Store the object status */
if (res != FR_OK) return res;
}
@@ -2526,7 +2508,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too }
#endif
/* On the FAT/FAT32 volume */
- mem_cpy(sn, dp->fn, 12);
+ memcpy(sn, dp->fn, 12);
if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
dp->fn[NSFLAG] = NS_NOLFN; /* Find only SFN */
for (n = 1; n < 100; n++) {
@@ -2540,19 +2522,19 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too }
/* Create an SFN with/without LFNs. */
- nent = (sn[NSFLAG] & NS_LFN) ? (nlen + 12) / 13 + 1 : 1; /* Number of entries to allocate */
- res = dir_alloc(dp, nent); /* Allocate entries */
- if (res == FR_OK && --nent) { /* Set LFN entry if needed */
- res = dir_sdi(dp, dp->dptr - nent * SZDIRE);
+ n_ent = (sn[NSFLAG] & NS_LFN) ? (len + 12) / 13 + 1 : 1; /* Number of entries to allocate */
+ res = dir_alloc(dp, n_ent); /* Allocate entries */
+ if (res == FR_OK && --n_ent) { /* Set LFN entry if needed */
+ res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE);
if (res == FR_OK) {
sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */
do { /* Store LFN entries in bottom first */
res = move_window(fs, dp->sect);
if (res != FR_OK) break;
- put_lfn(fs->lfnbuf, dp->dir, (BYTE)nent, sum);
+ put_lfn(fs->lfnbuf, dp->dir, (BYTE)n_ent, sum);
fs->wflag = 1;
res = dir_next(dp, 0); /* Next entry */
- } while (res == FR_OK && --nent);
+ } while (res == FR_OK && --n_ent);
}
}
@@ -2565,8 +2547,8 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too if (res == FR_OK) {
res = move_window(fs, dp->sect);
if (res == FR_OK) {
- mem_set(dp->dir, 0, SZDIRE); /* Clean the entry */
- mem_cpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */
+ memset(dp->dir, 0, SZDIRE); /* Clean the entry */
+ memcpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */
#if FF_USE_LFN
dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */
#endif
@@ -2602,7 +2584,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ if (res != FR_OK) break;
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
dp->dir[XDIR_Type] &= 0x7F; /* Clear the entry InUse flag. */
- } else { /* On the FAT/FAT32 volume */
+ } else { /* On the FAT/FAT32 volume */
dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'. */
}
fs->wflag = 1;
@@ -2639,8 +2621,10 @@ static void get_fileinfo ( {
UINT si, di;
#if FF_USE_LFN
+ BYTE lcf;
WCHAR wc, hs;
FATFS *fs = dp->obj.fs;
+ UINT nw;
#else
TCHAR c;
#endif
@@ -2651,22 +2635,53 @@ static void get_fileinfo ( #if FF_USE_LFN /* LFN configuration */
#if FF_FS_EXFAT
- if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
- get_xfileinfo(fs->dirbuf, fno);
+ if (fs->fs_type == FS_EXFAT) { /* exFAT volume */
+ UINT nc = 0;
+
+ si = SZDIRE * 2; di = 0; /* 1st C1 entry in the entry block */
+ hs = 0;
+ while (nc < fs->dirbuf[XDIR_NumName]) {
+ if (si >= MAXDIRB(FF_MAX_LFN)) { /* Truncated directory block? */
+ di = 0; break;
+ }
+ if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */
+ wc = ld_word(fs->dirbuf + si); si += 2; nc++; /* Get a character */
+ if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
+ hs = wc; continue; /* Get low surrogate */
+ }
+ nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
+ if (nw == 0) { /* Buffer overflow or wrong char? */
+ di = 0; break;
+ }
+ di += nw;
+ hs = 0;
+ }
+ if (hs != 0) di = 0; /* Broken surrogate pair? */
+ if (di == 0) fno->fname[di++] = '\?'; /* Inaccessible object name? */
+ fno->fname[di] = 0; /* Terminate the name */
+ fno->altname[0] = 0; /* exFAT does not support SFN */
+
+ fno->fattrib = fs->dirbuf[XDIR_Attr] & AM_MASKX; /* Attribute */
+ fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */
+ fno->ftime = ld_word(fs->dirbuf + XDIR_ModTime + 0); /* Time */
+ fno->fdate = ld_word(fs->dirbuf + XDIR_ModTime + 2); /* Date */
return;
} else
#endif
- { /* On the FAT/FAT32 volume */
+ { /* FAT/FAT32 volume */
if (dp->blk_ofs != 0xFFFFFFFF) { /* Get LFN if available */
- si = di = hs = 0;
+ si = di = 0;
+ hs = 0;
while (fs->lfnbuf[si] != 0) {
wc = fs->lfnbuf[si++]; /* Get an LFN character (UTF-16) */
if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
hs = wc; continue; /* Get low surrogate */
}
- wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in UTF-16 or UTF-8 encoding */
- if (wc == 0) { di = 0; break; } /* Invalid char or buffer overflow? */
- di += wc;
+ nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
+ if (nw == 0) { /* Buffer overflow or wrong char? */
+ di = 0; break;
+ }
+ di += nw;
hs = 0;
}
if (hs != 0) di = 0; /* Broken surrogate pair? */
@@ -2685,10 +2700,14 @@ static void get_fileinfo ( wc = wc << 8 | dp->dir[si++];
}
wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM -> Unicode */
- if (wc == 0) { di = 0; break; } /* Wrong char in the current code page? */
- wc = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in Unicode */
- if (wc == 0) { di = 0; break; } /* Buffer overflow? */
- di += wc;
+ if (wc == 0) { /* Wrong char in the current code page? */
+ di = 0; break;
+ }
+ nw = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in API encoding */
+ if (nw == 0) { /* Buffer overflow? */
+ di = 0; break;
+ }
+ di += nw;
#else /* ANSI/OEM output */
fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
#endif
@@ -2696,12 +2715,13 @@ static void get_fileinfo ( fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */
if (fno->fname[0] == 0) { /* If LFN is invalid, altname[] needs to be copied to fname[] */
- if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccesible */
- fno->fname[di++] = '?';
+ if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccessible */
+ fno->fname[di++] = '\?';
} else {
- for (si = di = 0; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */
+ for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */
wc = (WCHAR)fno->altname[si];
- if (IsUpper(wc) && (dp->dir[DIR_NTres] & ((si >= 9) ? NS_EXT : NS_BODY))) wc += 0x20;
+ if (wc == '.') lcf = NS_EXT;
+ if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20;
fno->fname[di] = (TCHAR)wc;
}
}
@@ -2718,10 +2738,10 @@ static void get_fileinfo ( if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */
fno->fname[di++] = c;
}
- fno->fname[di] = 0;
+ fno->fname[di] = 0; /* Terminate the SFN */
#endif
- fno->fattrib = dp->dir[DIR_Attr]; /* Attribute */
+ fno->fattrib = dp->dir[DIR_Attr] & AM_MASK; /* Attribute */
fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */
fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */
fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */
@@ -2736,7 +2756,10 @@ static void get_fileinfo ( /* Pattern matching */
/*-----------------------------------------------------------------------*/
-static DWORD get_achar ( /* Get a character and advances ptr */
+#define FIND_RECURS 4 /* Maximum number of wildcard terms in the pattern to limit recursion */
+
+
+static DWORD get_achar ( /* Get a character and advance ptr */
const TCHAR** ptr /* Pointer to pointer to the ANSI/OEM or Unicode string */
)
{
@@ -2767,41 +2790,48 @@ static DWORD get_achar ( /* Get a character and advances ptr */ }
-static int pattern_matching ( /* 0:not matched, 1:matched */
+static int pattern_match ( /* 0:mismatched, 1:matched */
const TCHAR* pat, /* Matching pattern */
const TCHAR* nam, /* String to be tested */
- int skip, /* Number of pre-skip chars (number of ?s) */
- int inf /* Infinite search (* specified) */
+ UINT skip, /* Number of pre-skip chars (number of ?s, b8:infinite (* specified)) */
+ UINT recur /* Recursion count */
)
{
- const TCHAR *pp, *np;
- DWORD pc, nc;
- int nm, nx;
+ const TCHAR *pptr;
+ const TCHAR *nptr;
+ DWORD pchr, nchr;
+ UINT sk;
- while (skip--) { /* Pre-skip name chars */
+ while ((skip & 0xFF) != 0) { /* Pre-skip name chars */
if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */
+ skip--;
}
- if (*pat == 0 && inf) return 1; /* (short circuit) */
+ if (*pat == 0 && skip) return 1; /* Matched? (short circuit) */
do {
- pp = pat; np = nam; /* Top of pattern and name to match */
+ pptr = pat; nptr = nam; /* Top of pattern and name to match */
for (;;) {
- if (*pp == '?' || *pp == '*') { /* Wildcard? */
- nm = nx = 0;
- do { /* Analyze the wildcard block */
- if (*pp++ == '?') nm++; else nx = 1;
- } while (*pp == '?' || *pp == '*');
- if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recurs upto number of wildcard blocks in the pattern) */
- nc = *np; break; /* Branch mismatched */
- }
- pc = get_achar(&pp); /* Get a pattern char */
- nc = get_achar(&np); /* Get a name char */
- if (pc != nc) break; /* Branch mismatched? */
- if (pc == 0) return 1; /* Branch matched? (matched at end of both strings) */
+ if (*pptr == '\?' || *pptr == '*') { /* Wildcard term? */
+ if (recur == 0) return 0; /* Too many wildcard terms? */
+ sk = 0;
+ do { /* Analyze the wildcard term */
+ if (*pptr++ == '\?') {
+ sk++;
+ } else {
+ sk |= 0x100;
+ }
+ } while (*pptr == '\?' || *pptr == '*');
+ if (pattern_match(pptr, nptr, sk, recur - 1)) return 1; /* Test new branch (recursive call) */
+ nchr = *nptr; break; /* Branch mismatched */
+ }
+ pchr = get_achar(&pptr); /* Get a pattern char */
+ nchr = get_achar(&nptr); /* Get a name char */
+ if (pchr != nchr) break; /* Branch mismatched? */
+ if (pchr == 0) return 1; /* Branch matched? (matched at end of both strings) */
}
get_achar(&nam); /* nam++ */
- } while (inf && nc); /* Retry until end of name if infinite search is specified */
+ } while (skip && nchr); /* Retry until end of name if infinite search is specified */
return 0;
}
@@ -2821,10 +2851,11 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr {
#if FF_USE_LFN /* LFN configuration */
BYTE b, cf;
- WCHAR wc, *lfn;
+ WCHAR wc;
+ WCHAR *lfn;
+ const TCHAR* p;
DWORD uc;
UINT i, ni, si, di;
- const TCHAR *p;
/* Create LFN into LFN working buffer */
@@ -2834,27 +2865,32 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr if (uc == 0xFFFFFFFF) return FR_INVALID_NAME; /* Invalid code or UTF decode error */
if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16); /* Store high surrogate if needed */
wc = (WCHAR)uc;
- if (wc < ' ' || wc == '/' || wc == '\\') break; /* Break if end of the path or a separator is found */
- if (wc < 0x80 && chk_chr("\"*:<>\?|\x7F", wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */
+ if (wc < ' ' || IsSeparator(wc)) break; /* Break if end of the path or a separator is found */
+ if (wc < 0x80 && strchr("*:<>|\"\?\x7F", (int)wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */
if (di >= FF_MAX_LFN) return FR_INVALID_NAME; /* Reject too long name */
- lfn[di++] = wc; /* Store the Unicode character */
+ lfn[di++] = wc; /* Store the Unicode character */
}
- while (*p == '/' || *p == '\\') p++; /* Skip duplicated separators if exist */
- *path = p; /* Return pointer to the next segment */
- cf = (wc < ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
+ if (wc < ' ') { /* Stopped at end of the path? */
+ cf = NS_LAST; /* Last segment */
+ } else { /* Stopped at a separator */
+ while (IsSeparator(*p)) p++; /* Skip duplicated separators if exist */
+ cf = 0; /* Next segment may follow */
+ if (IsTerminator(*p)) cf = NS_LAST; /* Ignore terminating separator */
+ }
+ *path = p; /* Return pointer to the next segment */
#if FF_FS_RPATH != 0
if ((di == 1 && lfn[di - 1] == '.') ||
(di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */
lfn[di] = 0;
- for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */
+ for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */
dp->fn[i] = (i < di) ? '.' : ' ';
}
- dp->fn[i] = cf | NS_DOT; /* This is a dot entry */
+ dp->fn[i] = cf | NS_DOT; /* This is a dot entry */
return FR_OK;
}
#endif
- while (di) { /* Snip off trailing spaces and dots if exist */
+ while (di) { /* Snip off trailing spaces and dots if exist */
wc = lfn[di - 1];
if (wc != ' ' && wc != '.') break;
di--;
@@ -2867,7 +2903,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr if (si > 0 || lfn[si] == '.') cf |= NS_LOSS | NS_LFN; /* Is there any leading space or dot? */
while (di > 0 && lfn[di - 1] != '.') di--; /* Find last dot (di<=si: no extension) */
- mem_set(dp->fn, ' ', 11);
+ memset(dp->fn, ' ', 11);
i = b = 0; ni = 8;
for (;;) {
wc = lfn[si++]; /* Get an LFN character */
@@ -2888,20 +2924,20 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr continue;
}
- if (wc >= 0x80) { /* Is this a non-ASCII character? */
+ if (wc >= 0x80) { /* Is this an extended character? */
cf |= NS_LFN; /* LFN entry needs to be created */
#if FF_CODE_PAGE == 0
- if (ExCvt) { /* At SBCS */
+ if (ExCvt) { /* In SBCS cfg */
wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
- } else { /* At DBCS */
- wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */
+ } else { /* In DBCS cfg */
+ wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
}
-#elif FF_CODE_PAGE < 900 /* SBCS cfg */
+#elif FF_CODE_PAGE < 900 /* In SBCS cfg */
wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
-#else /* DBCS cfg */
- wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */
+#else /* In DBCS cfg */
+ wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
#endif
}
@@ -2912,7 +2948,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr }
dp->fn[i++] = (BYTE)(wc >> 8); /* Put 1st byte */
} else { /* SBC */
- if (wc == 0 || chk_chr("+,;=[]", wc)) { /* Replace illegal characters for SFN if needed */
+ if (wc == 0 || strchr("+,;=[]", (int)wc)) { /* Replace illegal characters for SFN */
wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */
} else {
if (IsUpper(wc)) { /* ASCII upper case? */
@@ -2941,13 +2977,14 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr #else /* FF_USE_LFN : Non-LFN configuration */
- BYTE c, d, *sfn;
+ BYTE c, d;
+ BYTE *sfn;
UINT ni, si, i;
const char *p;
/* Create file name in directory form */
p = *path; sfn = dp->fn;
- mem_set(sfn, ' ', 11);
+ memset(sfn, ' ', 11);
si = i = 0; ni = 8;
#if FF_FS_RPATH != 0
if (p[si] == '.') { /* Is this a dot entry? */
@@ -2956,8 +2993,8 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr if (c != '.' || si >= 3) break;
sfn[i++] = c;
}
- if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
- *path = p + si; /* Return pointer to the next segment */
+ if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME;
+ *path = p + si; /* Return pointer to the next segment */
sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */
return FR_OK;
}
@@ -2965,8 +3002,8 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr for (;;) {
c = (BYTE)p[si++]; /* Get a byte */
if (c <= ' ') break; /* Break if end of the path name */
- if (c == '/' || c == '\\') { /* Break if a separator is found */
- while (p[si] == '/' || p[si] == '\\') si++; /* Skip duplicated separator if exist */
+ if (IsSeparator(c)) { /* Break if a separator is found */
+ while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */
break;
}
if (c == '.' || i >= ni) { /* End of body or field overflow? */
@@ -2989,16 +3026,16 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr sfn[i++] = c;
sfn[i++] = d;
} else { /* SBC */
- if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */
+ if (strchr("*+,:;<=>[]|\"\?\x7F", (int)c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */
if (IsLower(c)) c -= 0x20; /* To upper */
sfn[i++] = c;
}
}
- *path = p + si; /* Return pointer to the next segment */
+ *path = &p[si]; /* Return pointer to the next segment */
if (i == 0) return FR_INVALID_NAME; /* Reject nul string */
if (sfn[0] == DDEM) sfn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */
- sfn[NSFLAG] = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
+ sfn[NSFLAG] = (c <= ' ' || p[si] <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
return FR_OK;
#endif /* FF_USE_LFN */
@@ -3022,13 +3059,13 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ #if FF_FS_RPATH != 0
- if (*path != '/' && *path != '\\') { /* Without heading separator */
- dp->obj.sclust = fs->cdir; /* Start from current directory */
+ if (!IsSeparator(*path) && (FF_STR_VOLUME_ID != 2 || !IsTerminator(*path))) { /* Without heading separator */
+ dp->obj.sclust = fs->cdir; /* Start at the current directory */
} else
#endif
{ /* With heading separator */
- while (*path == '/' || *path == '\\') path++; /* Strip heading separator */
- dp->obj.sclust = 0; /* Start from root directory */
+ while (IsSeparator(*path)) path++; /* Strip separators */
+ dp->obj.sclust = 0; /* Start from the root directory */
}
#if FF_FS_EXFAT
dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */
@@ -3069,13 +3106,13 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ }
break;
}
- if (ns & NS_LAST) break; /* Last segment matched. Function completed. */
+ if (ns & NS_LAST) break; /* Last segment matched. Function completed. */
/* Get into the sub-directory */
- if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */
+ if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */
res = FR_NO_PATH; break;
}
#if FF_FS_EXFAT
- if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */
+ if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */
dp->obj.c_scl = dp->obj.sclust;
dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
dp->obj.c_ofs = dp->blk_ofs;
@@ -3102,9 +3139,11 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb const TCHAR** path /* Pointer to pointer to the path name */
)
{
- const TCHAR *tp, *tt;
+ const TCHAR *tp;
+ const TCHAR *tt;
TCHAR tc;
- int i, vol = -1;
+ int i;
+ int vol = -1;
#if FF_STR_VOLUME_ID /* Find string volume ID */
const char *sp;
char c;
@@ -3112,7 +3151,9 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb tt = tp = *path;
if (!tp) return vol; /* Invalid path name? */
- do tc = *tt++; while ((UINT)tc >= (FF_USE_LFN ? ' ' : '!') && tc != ':'); /* Find a colon in the path */
+ do { /* Find a colon in the path */
+ tc = *tt++;
+ } while (!IsTerminator(tc) && tc != ':');
if (tc == ':') { /* DOS/Windows style volume ID? */
i = FF_VOLUMES;
@@ -3139,21 +3180,22 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb return vol;
}
#if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */
- if (*tp == '/') {
+ if (*tp == '/') { /* Is there a volume ID? */
+ while (*(tp + 1) == '/') tp++; /* Skip duplicated separator */
i = 0;
do {
- sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */
+ tt = tp; sp = VolumeStr[i]; /* Path name and this string volume ID */
do { /* Compare the volume ID with path name */
- c = *sp++; tc = *(++tp);
+ c = *sp++; tc = *(++tt);
if (IsLower(c)) c -= 0x20;
if (IsLower(tc)) tc -= 0x20;
} while (c && (TCHAR)c == tc);
- } while ((c || (tc != '/' && (UINT)tc >= (FF_USE_LFN ? ' ' : '!'))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */
+ } while ((c || (tc != '/' && !IsTerminator(tc))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */
if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */
vol = i; /* Drive number */
- *path = tp; /* Snip the drive prefix off */
- return vol;
+ *path = tt; /* Snip the drive prefix off */
}
+ return vol;
}
#endif
/* No drive prefix is found */
@@ -3169,27 +3211,168 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb /*-----------------------------------------------------------------------*/
+/* GPT support functions */
+/*-----------------------------------------------------------------------*/
+
+#if FF_LBA64
+
+/* Calculate CRC32 in byte-by-byte */
+
+static DWORD crc32 ( /* Returns next CRC value */
+ DWORD crc, /* Current CRC value */
+ BYTE d /* A byte to be processed */
+)
+{
+ BYTE b;
+
+
+ for (b = 1; b; b <<= 1) {
+ crc ^= (d & b) ? 1 : 0;
+ crc = (crc & 1) ? crc >> 1 ^ 0xEDB88320 : crc >> 1;
+ }
+ return crc;
+}
+
+
+/* Check validity of GPT header */
+
+static int test_gpt_header ( /* 0:Invalid, 1:Valid */
+ const BYTE* gpth /* Pointer to the GPT header */
+)
+{
+ UINT i;
+ DWORD bcc, hlen;
+
+
+ if (memcmp(gpth + GPTH_Sign, "EFI PART" "\0\0\1", 12)) return 0; /* Check signature and version (1.0) */
+ hlen = ld_dword(gpth + GPTH_Size); /* Check header size */
+ if (hlen < 92 || hlen > FF_MIN_SS) return 0;
+ for (i = 0, bcc = 0xFFFFFFFF; i < hlen; i++) { /* Check header BCC */
+ bcc = crc32(bcc, i - GPTH_Bcc < 4 ? 0 : gpth[i]);
+ }
+ if (~bcc != ld_dword(gpth + GPTH_Bcc)) return 0;
+ if (ld_dword(gpth + GPTH_PteSize) != SZ_GPTE) return 0; /* Table entry size (must be SZ_GPTE bytes) */
+ if (ld_dword(gpth + GPTH_PtNum) > 128) return 0; /* Table size (must be 128 entries or less) */
+
+ return 1;
+}
+
+#if !FF_FS_READONLY && FF_USE_MKFS
+
+/* Generate random value */
+static DWORD make_rand (
+ DWORD seed, /* Seed value */
+ BYTE *buff, /* Output buffer */
+ UINT n /* Data length */
+)
+{
+ UINT r;
+
+
+ if (seed == 0) seed = 1;
+ do {
+ for (r = 0; r < 8; r++) seed = seed & 1 ? seed >> 1 ^ 0xA3000000 : seed >> 1; /* Shift 8 bits the 32-bit LFSR */
+ *buff++ = (BYTE)seed;
+ } while (--n);
+ return seed;
+}
+
+#endif
+#endif
+
+
+
+/*-----------------------------------------------------------------------*/
/* Load a sector and check if it is an FAT VBR */
/*-----------------------------------------------------------------------*/
-static BYTE check_fs ( /* 0:FAT, 1:exFAT, 2:Valid BS but not FAT, 3:Not a BS, 4:Disk error */
+/* Check what the sector is */
+
+static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS, 3:Not FAT and invalid BS, 4:Disk error */
FATFS* fs, /* Filesystem object */
- DWORD sect /* Sector# (lba) to load and check if it is an FAT-VBR or not */
+ LBA_t sect /* Sector to load and check if it is an FAT-VBR or not */
)
{
- fs->wflag = 0; fs->winsect = 0xFFFFFFFF; /* Invaidate window */
- if (move_window(fs, sect) != FR_OK) return 4; /* Load boot record */
+ WORD w, sign;
+ BYTE b;
- if (ld_word(fs->win + BS_55AA) != 0xAA55) return 3; /* Check boot record signature (always here regardless of the sector size) */
+ fs->wflag = 0; fs->winsect = (LBA_t)0 - 1; /* Invaidate window */
+ if (move_window(fs, sect) != FR_OK) return 4; /* Load the boot sector */
+ sign = ld_word(fs->win + BS_55AA);
#if FF_FS_EXFAT
- if (!mem_cmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* Check if exFAT VBR */
+ if (sign == 0xAA55 && !memcmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* It is an exFAT VBR */
+#endif
+ b = fs->win[BS_JmpBoot];
+ if (b == 0xEB || b == 0xE9 || b == 0xE8) { /* Valid JumpBoot code? (short jump, near jump or near call) */
+ if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) {
+ return 0; /* It is an FAT32 VBR */
+ }
+ /* FAT volumes formatted with early MS-DOS lack BS_55AA and BS_FilSysType, so FAT VBR needs to be identified without them. */
+ w = ld_word(fs->win + BPB_BytsPerSec);
+ b = fs->win[BPB_SecPerClus];
+ if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS /* Properness of sector size (512-4096 and 2^n) */
+ && b != 0 && (b & (b - 1)) == 0 /* Properness of cluster size (2^n) */
+ && ld_word(fs->win + BPB_RsvdSecCnt) != 0 /* Properness of reserved sectors (MNBZ) */
+ && (UINT)fs->win[BPB_NumFATs] - 1 <= 1 /* Properness of FATs (1 or 2) */
+ && ld_word(fs->win + BPB_RootEntCnt) != 0 /* Properness of root dir entries (MNBZ) */
+ && (ld_word(fs->win + BPB_TotSec16) >= 128 || ld_dword(fs->win + BPB_TotSec32) >= 0x10000) /* Properness of volume sectors (>=128) */
+ && ld_word(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size (MNBZ) */
+ return 0; /* It can be presumed an FAT VBR */
+ }
+ }
+ return sign == 0xAA55 ? 2 : 3; /* Not an FAT VBR (valid or invalid BS) */
+}
+
+
+/* Find an FAT volume */
+/* (It supports only generic partitioning rules, MBR, GPT and SFD) */
+
+static UINT find_volume ( /* Returns BS status found in the hosting drive */
+ FATFS* fs, /* Filesystem object */
+ UINT part /* Partition to fined = 0:find as SFD and partitions, >0:forced partition number */
+)
+{
+ UINT fmt, i;
+ DWORD mbr_pt[4];
+
+
+ fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD format */
+ if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is an FAT VBR as auto scan, not a BS or disk error */
+
+ /* Sector 0 is not an FAT VBR or forced partition number wants a partition */
+
+#if FF_LBA64
+ if (fs->win[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */
+ DWORD n_ent, v_ent, ofs;
+ QWORD pt_lba;
+
+ if (move_window(fs, 1) != FR_OK) return 4; /* Load GPT header sector (next to MBR) */
+ if (!test_gpt_header(fs->win)) return 3; /* Check if GPT header is valid */
+ n_ent = ld_dword(fs->win + GPTH_PtNum); /* Number of entries */
+ pt_lba = ld_qword(fs->win + GPTH_PtOfs); /* Table location */
+ for (v_ent = i = 0; i < n_ent; i++) { /* Find FAT partition */
+ if (move_window(fs, pt_lba + i * SZ_GPTE / SS(fs)) != FR_OK) return 4; /* PT sector */
+ ofs = i * SZ_GPTE % SS(fs); /* Offset in the sector */
+ if (!memcmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */
+ v_ent++;
+ fmt = check_fs(fs, ld_qword(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */
+ if (part == 0 && fmt <= 1) return fmt; /* Auto search (valid FAT volume found first) */
+ if (part != 0 && v_ent == part) return fmt; /* Forced partition order (regardless of it is valid or not) */
+ }
+ }
+ return 3; /* Not found */
+ }
#endif
- if (fs->win[BS_JmpBoot] == 0xE9 || fs->win[BS_JmpBoot] == 0xEB || fs->win[BS_JmpBoot] == 0xE8) { /* Valid JumpBoot code? */
- if (!mem_cmp(fs->win + BS_FilSysType, "FAT", 3)) return 0; /* Is it an FAT VBR? */
- if (!mem_cmp(fs->win + BS_FilSysType32, "FAT32", 5)) return 0; /* Is it an FAT32 VBR? */
+ if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has 4 partitions max */
+ for (i = 0; i < 4; i++) { /* Load partition offset in the MBR */
+ mbr_pt[i] = ld_dword(fs->win + MBR_Table + i * SZ_PTE + PTE_StLba);
}
- return 2; /* Valid BS but not FAT */
+ i = part ? part - 1 : 0; /* Table index to find first */
+ do { /* Find an FAT volume */
+ fmt = mbr_pt[i] ? check_fs(fs, mbr_pt[i]) : 3; /* Check if the partition is FAT */
+ } while (part == 0 && fmt >= 2 && ++i < 4);
+ return fmt;
}
@@ -3199,19 +3382,19 @@ static BYTE check_fs ( /* 0:FAT, 1:exFAT, 2:Valid BS but not FAT, 3:Not a BS, 4: /* Determine logical drive number and mount the volume if needed */
/*-----------------------------------------------------------------------*/
-static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */
+static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
const TCHAR** path, /* Pointer to pointer to the path name (drive number) */
FATFS** rfs, /* Pointer to pointer to the found filesystem object */
- BYTE mode /* !=0: Check write protection for write access */
+ BYTE mode /* Desiered access mode to check write protection */
)
{
- BYTE fmt, *pt;
int vol;
+ FATFS *fs;
DSTATUS stat;
- DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4];
+ LBA_t bsect;
+ DWORD tsect, sysect, fasize, nclst, szbfat;
WORD nrsv;
- FATFS *fs;
- UINT i;
+ UINT fmt;
/* Get logical drive number */
@@ -3223,7 +3406,7 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs = FatFs[vol]; /* Get pointer to the filesystem object */
if (!fs) return FR_NOT_ENABLED; /* Is the filesystem object available? */
#if FF_FS_REENTRANT
- if (!lock_fs(fs)) return FR_TIMEOUT; /* Lock the volume */
+ if (!lock_volume(fs, 1)) return FR_TIMEOUT; /* Lock the volume, and system if needed */
#endif
*rfs = fs; /* Return pointer to the filesystem object */
@@ -3234,16 +3417,15 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check write protection if needed */
return FR_WRITE_PROTECTED;
}
- return FR_OK; /* The filesystem object is valid */
+ return FR_OK; /* The filesystem object is already valid */
}
}
/* The filesystem object is not valid. */
- /* Following code attempts to mount the volume. (analyze BPB and initialize the filesystem object) */
+ /* Following code attempts to mount the volume. (find an FAT volume, analyze the BPB and initialize the filesystem object) */
- fs->fs_type = 0; /* Clear the filesystem object */
- fs->pdrv = LD2PD(vol); /* Bind the logical drive and a physical drive */
- stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */
+ fs->fs_type = 0; /* Invalidate the filesystem object */
+ stat = disk_initialize(fs->pdrv); /* Initialize the volume hosting physical drive */
if (stat & STA_NOINIT) { /* Check if the initialization succeeded */
return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */
}
@@ -3255,29 +3437,18 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS || (SS(fs) & (SS(fs) - 1))) return FR_DISK_ERR;
#endif
- /* Find an FAT partition on the drive. Supports only generic partitioning rules, FDISK and SFD. */
- bsect = 0;
- fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */
- if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */
- for (i = 0; i < 4; i++) { /* Get partition offset */
- pt = fs->win + (MBR_Table + i * SZ_PTE);
- br[i] = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0;
- }
- i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */
- if (i != 0) i--;
- do { /* Find an FAT volume */
- bsect = br[i];
- fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */
- } while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4);
- }
- if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */
+ /* Find an FAT volume on the hosting drive */
+ fmt = find_volume(fs, LD2PT(vol));
+ if (fmt == 4) return FR_DISK_ERR; /* An error occurred in the disk I/O layer */
if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */
+ bsect = fs->winsect; /* Volume offset in the hosting physical drive */
/* An FAT volume is found (bsect). Following code initializes the filesystem object */
#if FF_FS_EXFAT
if (fmt == 1) {
QWORD maxlba;
+ DWORD so, cv, bcl, i;
for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */
if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM;
@@ -3288,8 +3459,8 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ return FR_NO_FILESYSTEM;
}
- maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA + 1 of the volume */
- if (maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be handled in 32-bit LBA) */
+ maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA of the volume + 1 */
+ if (!FF_LBA64 && maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be accessed in 32-bit LBA) */
fs->fsize = ld_dword(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */
@@ -3297,7 +3468,7 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (fs->n_fats != 1) return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */
fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */
- if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768) */
+ if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768 sectors) */
nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */
if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */
@@ -3307,15 +3478,30 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->volbase = bsect;
fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx);
fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx);
- if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size requiered) */
+ if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */
fs->dirbase = ld_dword(fs->win + BPB_RootClusEx);
- /* Check if bitmap location is in assumption (at the first cluster) */
- if (move_window(fs, clst2sect(fs, fs->dirbase)) != FR_OK) return FR_DISK_ERR;
- for (i = 0; i < SS(fs); i += SZDIRE) {
- if (fs->win[i] == 0x81 && ld_dword(fs->win + i + 20) == 2) break; /* 81 entry with cluster #2? */
+ /* Get bitmap location and check if it is contiguous (implementation assumption) */
+ so = i = 0;
+ for (;;) { /* Find the bitmap entry in the root directory (in only first cluster) */
+ if (i == 0) {
+ if (so >= fs->csize) return FR_NO_FILESYSTEM; /* Not found? */
+ if (move_window(fs, clst2sect(fs, (DWORD)fs->dirbase) + so) != FR_OK) return FR_DISK_ERR;
+ so++;
+ }
+ if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */
+ i = (i + SZDIRE) % SS(fs); /* Next entry */
+ }
+ bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */
+ if (bcl < 2 || bcl >= fs->n_fatent) return FR_NO_FILESYSTEM; /* (Wrong cluster#) */
+ fs->bitbase = fs->database + fs->csize * (bcl - 2); /* Bitmap sector */
+ for (;;) { /* Check if bitmap is contiguous */
+ if (move_window(fs, fs->fatbase + bcl / (SS(fs) / 4)) != FR_OK) return FR_DISK_ERR;
+ cv = ld_dword(fs->win + bcl % (SS(fs) / 4) * 4);
+ if (cv == 0xFFFFFFFF) break; /* Last link? */
+ if (cv != ++bcl) return FR_NO_FILESYSTEM; /* Fragmented bitmap? */
}
- if (i == SS(fs)) return FR_NO_FILESYSTEM;
+
#if !FF_FS_READONLY
fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */
#endif
@@ -3400,7 +3586,7 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #endif /* !FF_FS_READONLY */
}
- fs->fs_type = fmt; /* FAT sub-type */
+ fs->fs_type = (BYTE)fmt;/* FAT sub-type (the filesystem object gets valid) */
fs->id = ++Fsid; /* Volume mount ID */
#if FF_USE_LFN == 1
fs->lfnbuf = LfnBuf; /* Static LFN working buffer */
@@ -3411,8 +3597,8 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #if FF_FS_RPATH != 0
fs->cdir = 0; /* Initialize current directory */
#endif
-#if FF_FS_LOCK != 0 /* Clear file lock semaphores */
- clear_lock(fs);
+#if FF_FS_LOCK /* Clear file lock semaphores */
+ clear_share(fs);
#endif
return FR_OK;
}
@@ -3425,7 +3611,7 @@ static FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */ /*-----------------------------------------------------------------------*/
static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */
- FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR object, to check validity */
+ FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR structure, to check validity */
FATFS** rfs /* Pointer to pointer to the owner filesystem object to return */
)
{
@@ -3434,22 +3620,22 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ if (obj && obj->fs && obj->fs->fs_type && obj->id == obj->fs->id) { /* Test if the object is valid */
#if FF_FS_REENTRANT
- if (lock_fs(obj->fs)) { /* Obtain the filesystem object */
- if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
+ if (lock_volume(obj->fs, 0)) { /* Take a grant to access the volume */
+ if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the hosting phsical drive is kept initialized */
res = FR_OK;
} else {
- unlock_fs(obj->fs, FR_OK);
+ unlock_volume(obj->fs, FR_OK); /* Invalidated volume, abort to access */
}
- } else {
+ } else { /* Could not take */
res = FR_TIMEOUT;
}
#else
- if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
+ if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the hosting phsical drive is kept initialized */
res = FR_OK;
}
#endif
}
- *rfs = (res == FR_OK) ? obj->fs : 0; /* Corresponding filesystem object */
+ *rfs = (res == FR_OK) ? obj->fs : 0; /* Return corresponding filesystem object if it is valid */
return res;
}
@@ -3469,9 +3655,9 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ /*-----------------------------------------------------------------------*/
FRESULT f_mount (
- FATFS* fs, /* Pointer to the filesystem object (NULL:unmount)*/
+ FATFS* fs, /* Pointer to the filesystem object to be registered (NULL:unmount)*/
const TCHAR* path, /* Logical drive number to be mounted/unmounted */
- BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */
+ BYTE opt /* Mount option: 0=Do not mount (delayed mount), 1=Mount immediately */
)
{
FATFS *cfs;
@@ -3480,32 +3666,44 @@ FRESULT f_mount ( const TCHAR *rp = path;
- /* Get logical drive number */
+ /* Get volume ID (logical drive number) */
vol = get_ldnumber(&rp);
if (vol < 0) return FR_INVALID_DRIVE;
- cfs = FatFs[vol]; /* Pointer to fs object */
+ cfs = FatFs[vol]; /* Pointer to the filesystem object of the volume */
- if (cfs) {
-#if FF_FS_LOCK != 0
- clear_lock(cfs);
+ if (cfs) { /* Unregister current filesystem object if regsitered */
+ FatFs[vol] = 0;
+#if FF_FS_LOCK
+ clear_share(cfs);
#endif
-#if FF_FS_REENTRANT /* Discard sync object of the current volume */
- if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
+#if FF_FS_REENTRANT /* Discard mutex of the current volume */
+ ff_mutex_delete(vol);
#endif
- cfs->fs_type = 0; /* Clear old fs object */
+ cfs->fs_type = 0; /* Invalidate the filesystem object to be unregistered */
}
- if (fs) {
- fs->fs_type = 0; /* Clear new fs object */
-#if FF_FS_REENTRANT /* Create sync object for the new volume */
- if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
+ if (fs) { /* Register new filesystem object */
+ fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */
+#if FF_FS_REENTRANT /* Create a volume mutex */
+ fs->ldrv = (BYTE)vol; /* Owner volume ID */
+ if (!ff_mutex_create(vol)) return FR_INT_ERR;
+#if FF_FS_LOCK
+ if (SysLock == 0) { /* Create a system mutex if needed */
+ if (!ff_mutex_create(FF_VOLUMES)) {
+ ff_mutex_delete(vol);
+ return FR_INT_ERR;
+ }
+ SysLock = 1; /* System mutex is ready */
+ }
+#endif
#endif
+ fs->fs_type = 0; /* Invalidate the new filesystem object */
+ FatFs[vol] = fs; /* Register new fs object */
}
- FatFs[vol] = fs; /* Register new fs object */
- if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted later */
+ if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted in subsequent file functions */
- res = find_volume(&path, &fs, 0); /* Force mounted the volume */
+ res = mount_volume(&path, &fs, 0); /* Force mounted the volume */
LEAVE_FF(fs, res);
}
@@ -3519,14 +3717,15 @@ FRESULT f_mount ( FRESULT f_open (
FIL* fp, /* Pointer to the blank file object */
const TCHAR* path, /* Pointer to the file name */
- BYTE mode /* Access mode and file open mode flags */
+ BYTE mode /* Access mode and open mode flags */
)
{
FRESULT res;
DIR dj;
FATFS *fs;
#if !FF_FS_READONLY
- DWORD dw, cl, bcs, clst, sc;
+ DWORD cl, bcs, clst, tm;
+ LBA_t sc;
FSIZE_t ofs;
#endif
DEF_NAMBUF
@@ -3536,7 +3735,7 @@ FRESULT f_open ( /* Get logical drive number */
mode &= FF_FS_READONLY ? FA_READ : FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_CREATE_NEW | FA_OPEN_ALWAYS | FA_OPEN_APPEND;
- res = find_volume(&path, &fs, mode);
+ res = mount_volume(&path, &fs, mode);
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -3546,9 +3745,9 @@ FRESULT f_open ( if (dj.fn[NSFLAG] & NS_NONAME) { /* Origin directory itself? */
res = FR_INVALID_NAME;
}
-#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
else {
- res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */
+ res = chk_share(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */
}
#endif
}
@@ -3556,8 +3755,8 @@ FRESULT f_open ( if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) {
if (res != FR_OK) { /* No file, create new */
if (res == FR_NO_FILE) { /* There is no file to open, create a new entry */
-#if FF_FS_LOCK != 0
- res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
+#if FF_FS_LOCK
+ res = enq_share() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
#else
res = dir_register(&dj);
#endif
@@ -3578,8 +3777,8 @@ FRESULT f_open ( fp->obj.fs = fs;
init_alloc_info(fs, &fp->obj);
/* Set directory entry block initial state */
- mem_set(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */
- mem_set(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */
+ memset(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */
+ memset(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */
fs->dirbuf[XDIR_Attr] = AM_ARC;
st_dword(fs->dirbuf + XDIR_CrtTime, GET_FATTIME());
fs->dirbuf[XDIR_GenFlags] = 1;
@@ -3592,17 +3791,19 @@ FRESULT f_open ( #endif
{
/* Set directory entry initial state */
+ tm = GET_FATTIME(); /* Set created time */
+ st_dword(dj.dir + DIR_CrtTime, tm);
+ st_dword(dj.dir + DIR_ModTime, tm);
cl = ld_clust(fs, dj.dir); /* Get current cluster chain */
- st_dword(dj.dir + DIR_CrtTime, GET_FATTIME()); /* Set created time */
dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */
st_clust(fs, dj.dir, 0); /* Reset file allocation info */
st_dword(dj.dir + DIR_FileSize, 0);
fs->wflag = 1;
if (cl != 0) { /* Remove the cluster chain if exist */
- dw = fs->winsect;
+ sc = fs->winsect;
res = remove_chain(&dj.obj, cl, 0);
if (res == FR_OK) {
- res = move_window(fs, dw);
+ res = move_window(fs, sc);
fs->last_clst = cl - 1; /* Reuse the cluster hole */
}
}
@@ -3624,8 +3825,8 @@ FRESULT f_open ( if (mode & FA_CREATE_ALWAYS) mode |= FA_MODIFIED; /* Set file change flag if created or overwritten */
fp->dir_sect = fs->winsect; /* Pointer to the directory entry */
fp->dir_ptr = dj.dir;
-#if FF_FS_LOCK != 0
- fp->obj.lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */
+#if FF_FS_LOCK
+ fp->obj.lockid = inc_share(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */
if (fp->obj.lockid == 0) res = FR_INT_ERR;
#endif
}
@@ -3655,17 +3856,17 @@ FRESULT f_open ( fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize);
}
#if FF_USE_FASTSEEK
- fp->cltbl = 0; /* Disable fast seek mode */
+ fp->cltbl = 0; /* Disable fast seek mode */
#endif
- fp->obj.fs = fs; /* Validate the file object */
+ fp->obj.fs = fs; /* Validate the file object */
fp->obj.id = fs->id;
- fp->flag = mode; /* Set file access mode */
- fp->err = 0; /* Clear error flag */
- fp->sect = 0; /* Invalidate current data sector */
- fp->fptr = 0; /* Set file pointer top of the file */
+ fp->flag = mode; /* Set file access mode */
+ fp->err = 0; /* Clear error flag */
+ fp->sect = 0; /* Invalidate current data sector */
+ fp->fptr = 0; /* Set file pointer top of the file */
#if !FF_FS_READONLY
#if !FF_FS_TINY
- mem_set(fp->buf, 0, FF_MAX_SS); /* Clear sector buffer */
+ memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */
#endif
if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */
fp->fptr = fp->obj.objsize; /* Offset to seek */
@@ -3678,7 +3879,8 @@ FRESULT f_open ( }
fp->clust = clst;
if (res == FR_OK && ofs % SS(fs)) { /* Fill sector buffer if not on the sector boundary */
- if ((sc = clst2sect(fs, clst)) == 0) {
+ sc = clst2sect(fs, clst);
+ if (sc == 0) {
res = FR_INT_ERR;
} else {
fp->sect = sc + (DWORD)(ofs / SS(fs));
@@ -3687,6 +3889,9 @@ FRESULT f_open ( #endif
}
}
+#if FF_FS_LOCK
+ if (res != FR_OK) dec_share(fp->obj.lockid); /* Decrement file open counter if seek failed */
+#endif
}
#endif
}
@@ -3707,15 +3912,16 @@ FRESULT f_open ( /*-----------------------------------------------------------------------*/
FRESULT f_read (
- FIL* fp, /* Pointer to the file object */
- void* buff, /* Pointer to data buffer */
+ FIL* fp, /* Open file to be read */
+ void* buff, /* Data buffer to store the read data */
UINT btr, /* Number of bytes to read */
- UINT* br /* Pointer to number of bytes read */
+ UINT* br /* Number of bytes read */
)
{
FRESULT res;
FATFS *fs;
- DWORD clst, sect;
+ DWORD clst;
+ LBA_t sect;
FSIZE_t remain;
UINT rcnt, cc, csect;
BYTE *rbuff = (BYTE*)buff;
@@ -3728,8 +3934,7 @@ FRESULT f_read ( remain = fp->obj.objsize - fp->fptr;
if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
- for ( ; btr; /* Repeat until btr bytes read */
- btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) {
+ for ( ; btr > 0; btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { /* Repeat until btr bytes read */
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
if (csect == 0) { /* On the cluster boundary? */
@@ -3761,11 +3966,11 @@ FRESULT f_read ( #if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
#if FF_FS_TINY
if (fs->wflag && fs->winsect - sect < cc) {
- mem_cpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
+ memcpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
}
#else
if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) {
- mem_cpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
+ memcpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
}
#endif
#endif
@@ -3780,18 +3985,18 @@ FRESULT f_read ( fp->flag &= (BYTE)~FA_DIRTY;
}
#endif
- if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */
+ if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */
}
#endif
fp->sect = sect;
}
- rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */
+ rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
if (rcnt > btr) rcnt = btr; /* Clip it by btr if needed */
#if FF_FS_TINY
if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
- mem_cpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
+ memcpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
#else
- mem_cpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
+ memcpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
#endif
}
@@ -3807,15 +4012,16 @@ FRESULT f_read ( /*-----------------------------------------------------------------------*/
FRESULT f_write (
- FIL* fp, /* Pointer to the file object */
- const void* buff, /* Pointer to the data to be written */
+ FIL* fp, /* Open file to be written */
+ const void* buff, /* Data to be written */
UINT btw, /* Number of bytes to write */
- UINT* bw /* Pointer to number of bytes written */
+ UINT* bw /* Number of bytes written */
)
{
FRESULT res;
FATFS *fs;
- DWORD clst, sect;
+ DWORD clst;
+ LBA_t sect;
UINT wcnt, cc, csect;
const BYTE *wbuff = (const BYTE*)buff;
@@ -3830,8 +4036,7 @@ FRESULT f_write ( btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);
}
- for ( ; btw; /* Repeat until all data written */
- btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) {
+ for ( ; btw > 0; btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { /* Repeat until all data written */
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */
if (csect == 0) { /* On the cluster boundary? */
@@ -3876,12 +4081,12 @@ FRESULT f_write ( #if FF_FS_MINIMIZE <= 2
#if FF_FS_TINY
if (fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
- mem_cpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));
+ memcpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));
fs->wflag = 0;
}
#else
if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
- mem_cpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
+ memcpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
fp->flag &= (BYTE)~FA_DIRTY;
}
#endif
@@ -3903,14 +4108,14 @@ FRESULT f_write ( #endif
fp->sect = sect;
}
- wcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */
+ wcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
if (wcnt > btw) wcnt = btw; /* Clip it by btw if needed */
#if FF_FS_TINY
if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
- mem_cpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
+ memcpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
fs->wflag = 1;
#else
- mem_cpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
+ memcpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
fp->flag |= FA_DIRTY;
#endif
}
@@ -3928,7 +4133,7 @@ FRESULT f_write ( /*-----------------------------------------------------------------------*/
FRESULT f_sync (
- FIL* fp /* Pointer to the file object */
+ FIL* fp /* Open file to be synced */
)
{
FRESULT res;
@@ -3963,9 +4168,9 @@ FRESULT f_sync ( if (res == FR_OK) {
fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */
fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */
- st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust);
- st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize);
- st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize);
+ st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); /* Update start cluster */
+ st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); /* Update file size */
+ st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); /* (FatFs does not support Valid File Size feature) */
st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Update modified time */
fs->dirbuf[XDIR_ModTime10] = 0;
st_dword(fs->dirbuf + XDIR_AccTime, 0);
@@ -4009,7 +4214,7 @@ FRESULT f_sync ( /*-----------------------------------------------------------------------*/
FRESULT f_close (
- FIL* fp /* Pointer to the file object to be closed */
+ FIL* fp /* Open file to be closed */
)
{
FRESULT res;
@@ -4022,14 +4227,14 @@ FRESULT f_close ( {
res = validate(&fp->obj, &fs); /* Lock volume */
if (res == FR_OK) {
-#if FF_FS_LOCK != 0
- res = dec_lock(fp->obj.lockid); /* Decrement file open counter */
+#if FF_FS_LOCK
+ res = dec_share(fp->obj.lockid); /* Decrement file open counter */
if (res == FR_OK) fp->obj.fs = 0; /* Invalidate file object */
#else
fp->obj.fs = 0; /* Invalidate file object */
#endif
#if FF_FS_REENTRANT
- unlock_fs(fs, FR_OK); /* Unlock volume */
+ unlock_volume(fs, FR_OK); /* Unlock volume */
#endif
}
}
@@ -4075,7 +4280,7 @@ FRESULT f_chdir ( /* Get logical drive */
- res = find_volume(&path, &fs, 0);
+ res = mount_volume(&path, &fs, 0);
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -4110,7 +4315,7 @@ FRESULT f_chdir ( }
FREE_NAMBUF();
if (res == FR_NO_FILE) res = FR_NO_PATH;
-#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed at Unix style volume ID */
+#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */
if (res == FR_OK) {
for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */
CurrVol = (BYTE)i;
@@ -4136,16 +4341,17 @@ FRESULT f_getcwd ( TCHAR *tp = buff;
#if FF_VOLUMES >= 2
UINT vl;
-#endif
#if FF_STR_VOLUME_ID
const char *vp;
#endif
+#endif
FILINFO fno;
DEF_NAMBUF
/* Get logical drive */
- res = find_volume((const TCHAR**)&buff, &fs, 0); /* Get current volume */
+ buff[0] = 0; /* Set null string to get current volume */
+ res = mount_volume((const TCHAR**)&buff, &fs, 0); /* Get current volume */
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -4163,7 +4369,7 @@ FRESULT f_getcwd ( res = dir_sdi(&dj, 0);
if (res != FR_OK) break;
do { /* Find the entry links to the child directory */
- res = dir_read_file(&dj);
+ res = DIR_READ_FILE(&dj);
if (res != FR_OK) break;
if (ccl == ld_clust(fs, dj.dir)) break; /* Found the entry */
res = dir_next(&dj, 0);
@@ -4202,7 +4408,9 @@ FRESULT f_getcwd ( #endif
/* Add current directory path */
if (res == FR_OK) {
- do *tp++ = buff[i++]; while (i < len); /* Copy stacked path string */
+ do { /* Copy stacked path string */
+ *tp++ = buff[i++];
+ } while (i < len);
}
}
FREE_NAMBUF();
@@ -4229,10 +4437,13 @@ FRESULT f_lseek ( {
FRESULT res;
FATFS *fs;
- DWORD clst, bcs, nsect;
+ DWORD clst, bcs;
+ LBA_t nsect;
FSIZE_t ifptr;
#if FF_USE_FASTSEEK
- DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
+ DWORD cl, pcl, ncl, tcl, tlen, ulen;
+ DWORD *tbl;
+ LBA_t dsc;
#endif
res = validate(&fp->obj, &fs); /* Check validity of the file object */
@@ -4396,7 +4607,7 @@ FRESULT f_opendir ( if (!dp) return FR_INVALID_OBJECT;
/* Get logical drive */
- res = find_volume(&path, &fs, 0);
+ res = mount_volume(&path, &fs, 0);
if (res == FR_OK) {
dp->obj.fs = fs;
INIT_NAMBUF(fs);
@@ -4406,7 +4617,7 @@ FRESULT f_opendir ( if (dp->obj.attr & AM_DIR) { /* This object is a sub-directory */
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) {
- dp->obj.c_scl = dp->obj.sclust; /* Get containing directory inforamation */
+ dp->obj.c_scl = dp->obj.sclust; /* Get containing directory inforamation */
dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
dp->obj.c_ofs = dp->blk_ofs;
init_alloc_info(fs, &dp->obj); /* Get object allocation info */
@@ -4422,10 +4633,10 @@ FRESULT f_opendir ( if (res == FR_OK) {
dp->obj.id = fs->id;
res = dir_sdi(dp, 0); /* Rewind directory */
-#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
if (res == FR_OK) {
if (dp->obj.sclust != 0) {
- dp->obj.lockid = inc_lock(dp, 0); /* Lock the sub directory */
+ dp->obj.lockid = inc_share(dp, 0); /* Lock the sub directory */
if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES;
} else {
dp->obj.lockid = 0; /* Root directory need not to be locked */
@@ -4437,7 +4648,7 @@ FRESULT f_opendir ( FREE_NAMBUF();
if (res == FR_NO_FILE) res = FR_NO_PATH;
}
- if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function faild */
+ if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function failed */
LEAVE_FF(fs, res);
}
@@ -4459,14 +4670,14 @@ FRESULT f_closedir ( res = validate(&dp->obj, &fs); /* Check validity of the file object */
if (res == FR_OK) {
-#if FF_FS_LOCK != 0
- if (dp->obj.lockid) res = dec_lock(dp->obj.lockid); /* Decrement sub-directory open counter */
+#if FF_FS_LOCK
+ if (dp->obj.lockid) res = dec_share(dp->obj.lockid); /* Decrement sub-directory open counter */
if (res == FR_OK) dp->obj.fs = 0; /* Invalidate directory object */
#else
dp->obj.fs = 0; /* Invalidate directory object */
#endif
#if FF_FS_REENTRANT
- unlock_fs(fs, FR_OK); /* Unlock volume */
+ unlock_volume(fs, FR_OK); /* Unlock volume */
#endif
}
return res;
@@ -4492,10 +4703,10 @@ FRESULT f_readdir ( res = validate(&dp->obj, &fs); /* Check validity of the directory object */
if (res == FR_OK) {
if (!fno) {
- res = dir_sdi(dp, 0); /* Rewind the directory object */
+ res = dir_sdi(dp, 0); /* Rewind the directory object */
} else {
INIT_NAMBUF(fs);
- res = dir_read_file(dp); /* Read an item */
+ res = DIR_READ_FILE(dp); /* Read an item */
if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory */
if (res == FR_OK) { /* A valid entry is found */
get_fileinfo(dp, fno); /* Get the object information */
@@ -4526,9 +4737,9 @@ FRESULT f_findnext ( for (;;) {
res = f_readdir(dp, fno); /* Get a directory item */
if (res != FR_OK || !fno || !fno->fname[0]) break; /* Terminate if any error or end of directory */
- if (pattern_matching(dp->pat, fno->fname, 0, 0)) break; /* Test for the file name */
+ if (pattern_match(dp->pat, fno->fname, 0, FIND_RECURS)) break; /* Test for the file name */
#if FF_USE_LFN && FF_USE_FIND == 2
- if (pattern_matching(dp->pat, fno->altname, 0, 0)) break; /* Test for alternative name if exist */
+ if (pattern_match(dp->pat, fno->altname, 0, FIND_RECURS)) break; /* Test for alternative name if exist */
#endif
}
return res;
@@ -4578,7 +4789,7 @@ FRESULT f_stat ( /* Get logical drive */
- res = find_volume(&path, &dj.obj.fs, 0);
+ res = mount_volume(&path, &dj.obj.fs, 0);
if (res == FR_OK) {
INIT_NAMBUF(dj.obj.fs);
res = follow_path(&dj, path); /* Follow the file path */
@@ -4610,13 +4821,14 @@ FRESULT f_getfree ( {
FRESULT res;
FATFS *fs;
- DWORD nfree, clst, sect, stat;
+ DWORD nfree, clst, stat;
+ LBA_t sect;
UINT i;
FFOBJID obj;
/* Get logical drive */
- res = find_volume(&path, &fs, 0);
+ res = mount_volume(&path, &fs, 0);
if (res == FR_OK) {
*fatfs = fs; /* Return ptr to the fs object */
/* If free_clst is valid, return it without full FAT scan */
@@ -4629,8 +4841,12 @@ FRESULT f_getfree ( clst = 2; obj.fs = fs;
do {
stat = get_fat(&obj, clst);
- if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }
- if (stat == 1) { res = FR_INT_ERR; break; }
+ if (stat == 0xFFFFFFFF) {
+ res = FR_DISK_ERR; break;
+ }
+ if (stat == 1) {
+ res = FR_INT_ERR; break;
+ }
if (stat == 0) nfree++;
} while (++clst < fs->n_fatent);
} else {
@@ -4640,15 +4856,15 @@ FRESULT f_getfree ( UINT b;
clst = fs->n_fatent - 2; /* Number of clusters */
- sect = fs->database; /* Assuming bitmap starts at cluster 2 */
+ sect = fs->bitbase; /* Bitmap sector */
i = 0; /* Offset in the sector */
do { /* Counts numbuer of bits with zero in the bitmap */
- if (i == 0) {
+ if (i == 0) { /* New sector? */
res = move_window(fs, sect++);
if (res != FR_OK) break;
}
- for (b = 8, bm = fs->win[i]; b && clst; b--, clst--) {
- if (!(bm & 1)) nfree++;
+ for (b = 8, bm = ~fs->win[i]; b && clst; b--, clst--) {
+ nfree += bm & 1;
bm >>= 1;
}
i = (i + 1) % SS(fs);
@@ -4660,7 +4876,7 @@ FRESULT f_getfree ( sect = fs->fatbase; /* Top of the FAT */
i = 0; /* Offset in the sector */
do { /* Counts numbuer of entries with zero in the FAT */
- if (i == 0) {
+ if (i == 0) { /* New sector? */
res = move_window(fs, sect++);
if (res != FR_OK) break;
}
@@ -4675,9 +4891,11 @@ FRESULT f_getfree ( } while (--clst);
}
}
- *nclst = nfree; /* Return the free clusters */
- fs->free_clst = nfree; /* Now free_clst is valid */
- fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */
+ if (res == FR_OK) { /* Update parameters if succeeded */
+ *nclst = nfree; /* Return the free clusters */
+ fs->free_clst = nfree; /* Now free_clst is valid */
+ fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */
+ }
}
}
@@ -4746,9 +4964,9 @@ FRESULT f_unlink ( )
{
FRESULT res;
+ FATFS *fs;
DIR dj, sdj;
DWORD dclst = 0;
- FATFS *fs;
#if FF_FS_EXFAT
FFOBJID obj;
#endif
@@ -4756,7 +4974,7 @@ FRESULT f_unlink ( /* Get logical drive */
- res = find_volume(&path, &fs, FA_WRITE);
+ res = mount_volume(&path, &fs, FA_WRITE);
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -4764,8 +4982,8 @@ FRESULT f_unlink ( if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) {
res = FR_INVALID_NAME; /* Cannot remove dot entry */
}
-#if FF_FS_LOCK != 0
- if (res == FR_OK) res = chk_lock(&dj, 2); /* Check if it is an open object */
+#if FF_FS_LOCK
+ if (res == FR_OK) res = chk_share(&dj, 2); /* Check if it is an open object */
#endif
if (res == FR_OK) { /* The object is accessible */
if (dj.fn[NSFLAG] & NS_NONAME) {
@@ -4788,12 +5006,12 @@ FRESULT f_unlink ( }
if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */
#if FF_FS_RPATH != 0
- if (dclst == fs->cdir) { /* Is it the current directory? */
+ if (dclst == fs->cdir) { /* Is it the current directory? */
res = FR_DENIED;
} else
#endif
{
- sdj.obj.fs = fs; /* Open the sub-directory */
+ sdj.obj.fs = fs; /* Open the sub-directory */
sdj.obj.sclust = dclst;
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) {
@@ -4803,7 +5021,7 @@ FRESULT f_unlink ( #endif
res = dir_sdi(&sdj, 0);
if (res == FR_OK) {
- res = dir_read_file(&sdj); /* Test if the directory is empty */
+ res = DIR_READ_FILE(&sdj); /* Test if the directory is empty */
if (res == FR_OK) res = FR_DENIED; /* Not empty? */
if (res == FR_NO_FILE) res = FR_OK; /* Empty? */
}
@@ -4840,74 +5058,70 @@ FRESULT f_mkdir ( )
{
FRESULT res;
- DIR dj;
FATFS *fs;
- BYTE *dir;
+ DIR dj;
+ FFOBJID sobj;
DWORD dcl, pcl, tm;
DEF_NAMBUF
- /* Get logical drive */
- res = find_volume(&path, &fs, FA_WRITE);
+ res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
res = follow_path(&dj, path); /* Follow the file path */
- if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */
- if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) {
+ if (res == FR_OK) res = FR_EXIST; /* Name collision? */
+ if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) { /* Invalid name? */
res = FR_INVALID_NAME;
}
- if (res == FR_NO_FILE) { /* Can create a new directory */
- dcl = create_chain(&dj.obj, 0); /* Allocate a cluster for the new directory table */
- dj.obj.objsize = (DWORD)fs->csize * SS(fs);
+ if (res == FR_NO_FILE) { /* It is clear to create a new directory */
+ sobj.fs = fs; /* New object id to create a new chain */
+ dcl = create_chain(&sobj, 0); /* Allocate a cluster for the new directory */
res = FR_OK;
- if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster */
- if (dcl == 1) res = FR_INT_ERR;
- if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR;
- if (res == FR_OK) res = sync_window(fs); /* Flush FAT */
+ if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster? */
+ if (dcl == 1) res = FR_INT_ERR; /* Any insanity? */
+ if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; /* Disk error? */
tm = GET_FATTIME();
- if (res == FR_OK) { /* Initialize the new directory table */
+ if (res == FR_OK) {
res = dir_clear(fs, dcl); /* Clean up the new table */
- if (res == FR_OK && (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT)) { /* Create dot entries (FAT only) */
- dir = fs->win;
- mem_set(dir + DIR_Name, ' ', 11); /* Create "." entry */
- dir[DIR_Name] = '.';
- dir[DIR_Attr] = AM_DIR;
- st_dword(dir + DIR_ModTime, tm);
- st_clust(fs, dir, dcl);
- mem_cpy(dir + SZDIRE, dir, SZDIRE); /* Create ".." entry */
- dir[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
- st_clust(fs, dir + SZDIRE, pcl);
- fs->wflag = 1;
+ if (res == FR_OK) {
+ if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */
+ memset(fs->win + DIR_Name, ' ', 11); /* Create "." entry */
+ fs->win[DIR_Name] = '.';
+ fs->win[DIR_Attr] = AM_DIR;
+ st_dword(fs->win + DIR_ModTime, tm);
+ st_clust(fs, fs->win, dcl);
+ memcpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */
+ fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
+ st_clust(fs, fs->win + SZDIRE, pcl);
+ fs->wflag = 1;
+ }
+ res = dir_register(&dj); /* Register the object to the parent directoy */
}
}
if (res == FR_OK) {
- res = dir_register(&dj); /* Register the object to the directoy */
- }
- if (res == FR_OK) {
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* Initialize directory entry block */
st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Created time */
st_dword(fs->dirbuf + XDIR_FstClus, dcl); /* Table start cluster */
- st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)dj.obj.objsize); /* File size needs to be valid */
- st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)dj.obj.objsize);
+ st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs)); /* Directory size needs to be valid */
+ st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs));
fs->dirbuf[XDIR_GenFlags] = 3; /* Initialize the object flag */
fs->dirbuf[XDIR_Attr] = AM_DIR; /* Attribute */
res = store_xdir(&dj);
} else
#endif
{
- dir = dj.dir;
- st_dword(dir + DIR_ModTime, tm); /* Created time */
- st_clust(fs, dir, dcl); /* Table start cluster */
- dir[DIR_Attr] = AM_DIR; /* Attribute */
+ st_dword(dj.dir + DIR_ModTime, tm); /* Created time */
+ st_clust(fs, dj.dir, dcl); /* Table start cluster */
+ dj.dir[DIR_Attr] = AM_DIR; /* Attribute */
fs->wflag = 1;
}
if (res == FR_OK) {
res = sync_fs(fs);
}
} else {
- remove_chain(&dj.obj, dcl, 0); /* Could not register, remove cluster chain */
+ remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */
}
}
FREE_NAMBUF();
@@ -4929,33 +5143,33 @@ FRESULT f_rename ( )
{
FRESULT res;
- DIR djo, djn;
FATFS *fs;
+ DIR djo, djn;
BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
- DWORD dw;
+ LBA_t sect;
DEF_NAMBUF
get_ldnumber(&path_new); /* Snip the drive number of new name off */
- res = find_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
+ res = mount_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
if (res == FR_OK) {
djo.obj.fs = fs;
INIT_NAMBUF(fs);
- res = follow_path(&djo, path_old); /* Check old object */
+ res = follow_path(&djo, path_old); /* Check old object */
if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */
-#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
if (res == FR_OK) {
- res = chk_lock(&djo, 2);
+ res = chk_share(&djo, 2);
}
#endif
- if (res == FR_OK) { /* Object to be renamed is found */
+ if (res == FR_OK) { /* Object to be renamed is found */
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */
BYTE nf, nn;
WORD nh;
- mem_cpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */
- mem_cpy(&djn, &djo, sizeof djo);
+ memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */
+ memcpy(&djn, &djo, sizeof djo);
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
if (res == FR_OK) { /* Is new name already in use by any other object? */
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
@@ -4965,7 +5179,7 @@ FRESULT f_rename ( if (res == FR_OK) {
nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName];
nh = ld_word(fs->dirbuf + XDIR_NameHash);
- mem_cpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */
+ memcpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */
fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn;
st_word(fs->dirbuf + XDIR_NameHash, nh);
if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
@@ -4976,8 +5190,8 @@ FRESULT f_rename ( } else
#endif
{ /* At FAT/FAT32 volume */
- mem_cpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
- mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
+ memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
+ memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
if (res == FR_OK) { /* Is new name already in use by any other object? */
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
@@ -4986,17 +5200,17 @@ FRESULT f_rename ( res = dir_register(&djn); /* Register the new entry */
if (res == FR_OK) {
dir = djn.dir; /* Copy directory entry of the object except name */
- mem_cpy(dir + 13, buf + 13, SZDIRE - 13);
+ memcpy(dir + 13, buf + 13, SZDIRE - 13);
dir[DIR_Attr] = buf[DIR_Attr];
if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
fs->wflag = 1;
if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory if needed */
- dw = clst2sect(fs, ld_clust(fs, dir));
- if (dw == 0) {
+ sect = clst2sect(fs, ld_clust(fs, dir));
+ if (sect == 0) {
res = FR_INT_ERR;
} else {
/* Start of critical section where an interruption can cause a cross-link */
- res = move_window(fs, dw);
+ res = move_window(fs, sect);
dir = fs->win + SZDIRE * 1; /* Ptr to .. entry */
if (res == FR_OK && dir[1] == '.') {
st_clust(fs, dir, djn.obj.sclust);
@@ -5040,12 +5254,12 @@ FRESULT f_chmod ( )
{
FRESULT res;
- DIR dj;
FATFS *fs;
+ DIR dj;
DEF_NAMBUF
- res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */
+ res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -5086,12 +5300,12 @@ FRESULT f_utime ( )
{
FRESULT res;
- DIR dj;
FATFS *fs;
+ DIR dj;
DEF_NAMBUF
- res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */
+ res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */
if (res == FR_OK) {
dj.obj.fs = fs;
INIT_NAMBUF(fs);
@@ -5134,33 +5348,36 @@ FRESULT f_getlabel ( )
{
FRESULT res;
- DIR dj;
FATFS *fs;
+ DIR dj;
UINT si, di;
WCHAR wc;
/* Get logical drive */
- res = find_volume(&path, &fs, 0);
+ res = mount_volume(&path, &fs, 0);
/* Get volume label */
if (res == FR_OK && label) {
dj.obj.fs = fs; dj.obj.sclust = 0; /* Open root directory */
res = dir_sdi(&dj, 0);
if (res == FR_OK) {
- res = dir_read_label(&dj); /* Find a volume label entry */
+ res = DIR_READ_LABEL(&dj); /* Find a volume label entry */
if (res == FR_OK) {
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) {
WCHAR hs;
+ UINT nw;
for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++) { /* Extract volume label from 83 entry */
wc = ld_word(dj.dir + XDIR_Label + si * 2);
if (hs == 0 && IsSurrogate(wc)) { /* Is the code a surrogate? */
hs = wc; continue;
}
- wc = put_utf((DWORD)hs << 16 | wc, &label[di], 4);
- if (wc == 0) { di = 0; break; }
- di += wc;
+ nw = put_utf((DWORD)hs << 16 | wc, &label[di], 4); /* Store it in API encoding */
+ if (nw == 0) { /* Encode error? */
+ di = 0; break;
+ }
+ di += nw;
hs = 0;
}
if (hs != 0) di = 0; /* Broken surrogate pair? */
@@ -5173,10 +5390,11 @@ FRESULT f_getlabel ( wc = dj.dir[si++];
#if FF_USE_LFN && FF_LFN_UNICODE >= 1 /* Unicode output */
if (dbc_1st((BYTE)wc) && si < 11) wc = wc << 8 | dj.dir[si++]; /* Is it a DBC? */
- wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */
- if (wc != 0) wc = put_utf(wc, &label[di], 4); /* Put it in Unicode */
- if (wc == 0) { di = 0; break; }
- di += wc;
+ wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */
+ if (wc == 0) { /* Invalid char in current code page? */
+ di = 0; break;
+ }
+ di += put_utf(wc, &label[di], 4); /* Store it in Unicode */
#else /* ANSI/OEM output */
label[di++] = (TCHAR)wc;
#endif
@@ -5200,10 +5418,12 @@ FRESULT f_getlabel ( if (res == FR_OK) {
switch (fs->fs_type) {
case FS_EXFAT:
- di = BPB_VolIDEx; break;
+ di = BPB_VolIDEx;
+ break;
case FS_FAT32:
- di = BS_VolID32; break;
+ di = BS_VolID32;
+ break;
default:
di = BS_VolID;
@@ -5227,23 +5447,23 @@ FRESULT f_setlabel ( )
{
FRESULT res;
- DIR dj;
FATFS *fs;
+ DIR dj;
BYTE dirvn[22];
UINT di;
WCHAR wc;
- static const char badchr[] = "+.,;=[]/\\\"*:<>\?|\x7F"; /* [0..] for FAT, [7..] for exFAT */
+ static const char badchr[18] = "+.,;=[]" "/*:<>|\\\"\?\x7F"; /* [0..16] for FAT, [7..16] for exFAT */
#if FF_USE_LFN
DWORD dc;
#endif
/* Get logical drive */
- res = find_volume(&label, &fs, FA_WRITE);
+ res = mount_volume(&label, &fs, FA_WRITE);
if (res != FR_OK) LEAVE_FF(fs, res);
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
- mem_set(dirvn, 0, 22);
+ memset(dirvn, 0, 22);
di = 0;
while ((UINT)*label >= ' ') { /* Create volume label */
dc = tchar2uni(&label); /* Get a Unicode character */
@@ -5254,7 +5474,7 @@ FRESULT f_setlabel ( st_word(dirvn + di * 2, (WCHAR)(dc >> 16)); di++;
}
}
- if (dc == 0 || chk_chr(badchr + 7, (int)dc) || di >= 11) { /* Check validity of the volume label */
+ if (dc == 0 || strchr(&badchr[7], (int)dc) || di >= 11) { /* Check validity of the volume label */
LEAVE_FF(fs, FR_INVALID_NAME);
}
st_word(dirvn + di * 2, (WCHAR)dc); di++;
@@ -5262,7 +5482,7 @@ FRESULT f_setlabel ( } else
#endif
{ /* On the FAT/FAT32 volume */
- mem_set(dirvn, ' ', 11);
+ memset(dirvn, ' ', 11);
di = 0;
while ((UINT)*label >= ' ') { /* Create volume label */
#if FF_USE_LFN
@@ -5278,7 +5498,7 @@ FRESULT f_setlabel ( if (wc >= 0x80) wc = ExCvt[wc - 0x80]; /* To upper extended characters (SBCS cfg) */
#endif
#endif
- if (wc == 0 || chk_chr(badchr + 0, (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */
+ if (wc == 0 || strchr(&badchr[0], (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */
LEAVE_FF(fs, FR_INVALID_NAME);
}
if (wc >= 0x100) dirvn[di++] = (BYTE)(wc >> 8);
@@ -5292,14 +5512,14 @@ FRESULT f_setlabel ( dj.obj.fs = fs; dj.obj.sclust = 0; /* Open root directory */
res = dir_sdi(&dj, 0);
if (res == FR_OK) {
- res = dir_read_label(&dj); /* Get volume label entry */
+ res = DIR_READ_LABEL(&dj); /* Get volume label entry */
if (res == FR_OK) {
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) {
dj.dir[XDIR_NumLabel] = (BYTE)di; /* Change the volume label */
- mem_cpy(dj.dir + XDIR_Label, dirvn, 22);
+ memcpy(dj.dir + XDIR_Label, dirvn, 22);
} else {
if (di != 0) {
- mem_cpy(dj.dir, dirvn, 11); /* Change the volume label */
+ memcpy(dj.dir, dirvn, 11); /* Change the volume label */
} else {
dj.dir[DIR_Name] = DDEM; /* Remove the volume label */
}
@@ -5312,14 +5532,14 @@ FRESULT f_setlabel ( if (di != 0) { /* Create a volume label entry */
res = dir_alloc(&dj, 1); /* Allocate an entry */
if (res == FR_OK) {
- mem_set(dj.dir, 0, SZDIRE); /* Clean the entry */
+ memset(dj.dir, 0, SZDIRE); /* Clean the entry */
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) {
- dj.dir[XDIR_Type] = 0x83; /* Create 83 entry */
+ dj.dir[XDIR_Type] = ET_VLABEL; /* Create volume label entry */
dj.dir[XDIR_NumLabel] = (BYTE)di;
- mem_cpy(dj.dir + XDIR_Label, dirvn, 22);
+ memcpy(dj.dir + XDIR_Label, dirvn, 22);
} else {
dj.dir[DIR_Attr] = AM_VOL; /* Create volume label entry */
- mem_cpy(dj.dir, dirvn, 11);
+ memcpy(dj.dir, dirvn, 11);
}
fs->wflag = 1;
res = sync_fs(fs);
@@ -5384,14 +5604,20 @@ FRESULT f_expand ( for (;;) { /* Find a contiguous cluster block */
n = get_fat(&fp->obj, clst);
if (++clst >= fs->n_fatent) clst = 2;
- if (n == 1) { res = FR_INT_ERR; break; }
- if (n == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }
+ if (n == 1) {
+ res = FR_INT_ERR; break;
+ }
+ if (n == 0xFFFFFFFF) {
+ res = FR_DISK_ERR; break;
+ }
if (n == 0) { /* Is it a free cluster? */
if (++ncl == tcl) break; /* Break if a contiguous cluster block is found */
} else {
scl = clst; ncl = 0; /* Not a free cluster */
}
- if (clst == stcl) { res = FR_DENIED; break; } /* No contiguous cluster? */
+ if (clst == stcl) { /* No contiguous cluster? */
+ res = FR_DENIED; break;
+ }
}
if (res == FR_OK) { /* A contiguous free area is found */
if (opt) { /* Allocate it now */
@@ -5441,7 +5667,8 @@ FRESULT f_forward ( {
FRESULT res;
FATFS *fs;
- DWORD clst, sect;
+ DWORD clst;
+ LBA_t sect;
FSIZE_t remain;
UINT rcnt, csect;
BYTE *dbuf;
@@ -5455,8 +5682,7 @@ FRESULT f_forward ( remain = fp->obj.objsize - fp->fptr;
if (btf > remain) btf = (UINT)remain; /* Truncate btf by remaining bytes */
- for ( ; btf && (*func)(0, 0); /* Repeat until all data transferred or stream goes busy */
- fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) {
+ for ( ; btf > 0 && (*func)(0, 0); fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { /* Repeat until all data transferred or stream goes busy */
csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
if (csect == 0) { /* On the cluster boundary? */
@@ -5486,7 +5712,7 @@ FRESULT f_forward ( dbuf = fp->buf;
#endif
fp->sect = sect;
- rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */
+ rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
if (rcnt > btf) rcnt = btf; /* Clip it by btr if needed */
rcnt = (*func)(dbuf + ((UINT)fp->fptr % SS(fs)), rcnt); /* Forward the file data */
if (rcnt == 0) ABORT(fs, FR_INT_ERR);
@@ -5498,138 +5724,334 @@ FRESULT f_forward ( -#if FF_USE_MKFS && !FF_FS_READONLY
+#if !FF_FS_READONLY && FF_USE_MKFS
/*-----------------------------------------------------------------------*/
-/* Create an FAT/exFAT volume */
+/* Create FAT/exFAT volume (with sub-functions) */
/*-----------------------------------------------------------------------*/
+#define N_SEC_TRACK 63 /* Sectors per track for determination of drive CHS */
+#define GPT_ALIGN 0x100000 /* Alignment of partitions in GPT [byte] (>=128KB) */
+#define GPT_ITEMS 128 /* Number of GPT table size (>=128, sector aligned) */
+
+
+/* Create partitions on the physical drive in format of MBR or GPT */
+
+static FRESULT create_partition (
+ BYTE drv, /* Physical drive number */
+ const LBA_t plst[], /* Partition list */
+ BYTE sys, /* System ID for each partition (for only MBR) */
+ BYTE *buf /* Working buffer for a sector */
+)
+{
+ UINT i, cy;
+ LBA_t sz_drv;
+ DWORD sz_drv32, nxt_alloc32, sz_part32;
+ BYTE *pte;
+ BYTE hd, n_hd, sc, n_sc;
+
+ /* Get physical drive size */
+ if (disk_ioctl(drv, GET_SECTOR_COUNT, &sz_drv) != RES_OK) return FR_DISK_ERR;
+
+#if FF_LBA64
+ if (sz_drv >= FF_MIN_GPT) { /* Create partitions in GPT format */
+ WORD ss;
+ UINT sz_ptbl, pi, si, ofs;
+ DWORD bcc, rnd, align;
+ QWORD nxt_alloc, sz_part, sz_pool, top_bpt;
+ static const BYTE gpt_mbr[16] = {0x00, 0x00, 0x02, 0x00, 0xEE, 0xFE, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
+
+#if FF_MAX_SS != FF_MIN_SS
+ if (disk_ioctl(drv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR; /* Get sector size */
+ if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR;
+#else
+ ss = FF_MAX_SS;
+#endif
+ rnd = (DWORD)sz_drv + GET_FATTIME(); /* Random seed */
+ align = GPT_ALIGN / ss; /* Partition alignment for GPT [sector] */
+ sz_ptbl = GPT_ITEMS * SZ_GPTE / ss; /* Size of partition table [sector] */
+ top_bpt = sz_drv - sz_ptbl - 1; /* Backup partition table start sector */
+ nxt_alloc = 2 + sz_ptbl; /* First allocatable sector */
+ sz_pool = top_bpt - nxt_alloc; /* Size of allocatable area */
+ bcc = 0xFFFFFFFF; sz_part = 1;
+ pi = si = 0; /* partition table index, size table index */
+ do {
+ if (pi * SZ_GPTE % ss == 0) memset(buf, 0, ss); /* Clean the buffer if needed */
+ if (sz_part != 0) { /* Is the size table not termintated? */
+ nxt_alloc = (nxt_alloc + align - 1) & ((QWORD)0 - align); /* Align partition start */
+ sz_part = plst[si++]; /* Get a partition size */
+ if (sz_part <= 100) { /* Is the size in percentage? */
+ sz_part = sz_pool * sz_part / 100;
+ sz_part = (sz_part + align - 1) & ((QWORD)0 - align); /* Align partition end (only if in percentage) */
+ }
+ if (nxt_alloc + sz_part > top_bpt) { /* Clip the size at end of the pool */
+ sz_part = (nxt_alloc < top_bpt) ? top_bpt - nxt_alloc : 0;
+ }
+ }
+ if (sz_part != 0) { /* Add a partition? */
+ ofs = pi * SZ_GPTE % ss;
+ memcpy(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16); /* Set partition GUID (Microsoft Basic Data) */
+ rnd = make_rand(rnd, buf + ofs + GPTE_UpGuid, 16); /* Set unique partition GUID */
+ st_qword(buf + ofs + GPTE_FstLba, nxt_alloc); /* Set partition start sector */
+ st_qword(buf + ofs + GPTE_LstLba, nxt_alloc + sz_part - 1); /* Set partition end sector */
+ nxt_alloc += sz_part; /* Next allocatable sector */
+ }
+ if ((pi + 1) * SZ_GPTE % ss == 0) { /* Write the buffer if it is filled up */
+ for (i = 0; i < ss; bcc = crc32(bcc, buf[i++])) ; /* Calculate table check sum */
+ if (disk_write(drv, buf, 2 + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to primary table */
+ if (disk_write(drv, buf, top_bpt + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to secondary table */
+ }
+ } while (++pi < GPT_ITEMS);
+
+ /* Create primary GPT header */
+ memset(buf, 0, ss);
+ memcpy(buf + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16); /* Signature, version (1.0) and size (92) */
+ st_dword(buf + GPTH_PtBcc, ~bcc); /* Table check sum */
+ st_qword(buf + GPTH_CurLba, 1); /* LBA of this header */
+ st_qword(buf + GPTH_BakLba, sz_drv - 1); /* LBA of secondary header */
+ st_qword(buf + GPTH_FstLba, 2 + sz_ptbl); /* LBA of first allocatable sector */
+ st_qword(buf + GPTH_LstLba, top_bpt - 1); /* LBA of last allocatable sector */
+ st_dword(buf + GPTH_PteSize, SZ_GPTE); /* Size of a table entry */
+ st_dword(buf + GPTH_PtNum, GPT_ITEMS); /* Number of table entries */
+ st_dword(buf + GPTH_PtOfs, 2); /* LBA of this table */
+ rnd = make_rand(rnd, buf + GPTH_DskGuid, 16); /* Disk GUID */
+ for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */
+ st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
+ if (disk_write(drv, buf, 1, 1) != RES_OK) return FR_DISK_ERR;
+
+ /* Create secondary GPT header */
+ st_qword(buf + GPTH_CurLba, sz_drv - 1); /* LBA of this header */
+ st_qword(buf + GPTH_BakLba, 1); /* LBA of primary header */
+ st_qword(buf + GPTH_PtOfs, top_bpt); /* LBA of this table */
+ st_dword(buf + GPTH_Bcc, 0);
+ for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */
+ st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
+ if (disk_write(drv, buf, sz_drv - 1, 1) != RES_OK) return FR_DISK_ERR;
+
+ /* Create protective MBR */
+ memset(buf, 0, ss);
+ memcpy(buf + MBR_Table, gpt_mbr, 16); /* Create a GPT partition */
+ st_word(buf + BS_55AA, 0xAA55);
+ if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR;
+
+ } else
+#endif
+ { /* Create partitions in MBR format */
+ sz_drv32 = (DWORD)sz_drv;
+ n_sc = N_SEC_TRACK; /* Determine drive CHS without any consideration of the drive geometry */
+ for (n_hd = 8; n_hd != 0 && sz_drv32 / n_hd / n_sc > 1024; n_hd *= 2) ;
+ if (n_hd == 0) n_hd = 255; /* Number of heads needs to be <256 */
+
+ memset(buf, 0, FF_MAX_SS); /* Clear MBR */
+ pte = buf + MBR_Table; /* Partition table in the MBR */
+ for (i = 0, nxt_alloc32 = n_sc; i < 4 && nxt_alloc32 != 0 && nxt_alloc32 < sz_drv32; i++, nxt_alloc32 += sz_part32) {
+ sz_part32 = (DWORD)plst[i]; /* Get partition size */
+ if (sz_part32 <= 100) sz_part32 = (sz_part32 == 100) ? sz_drv32 : sz_drv32 / 100 * sz_part32; /* Size in percentage? */
+ if (nxt_alloc32 + sz_part32 > sz_drv32 || nxt_alloc32 + sz_part32 < nxt_alloc32) sz_part32 = sz_drv32 - nxt_alloc32; /* Clip at drive size */
+ if (sz_part32 == 0) break; /* End of table or no sector to allocate? */
+
+ st_dword(pte + PTE_StLba, nxt_alloc32); /* Start LBA */
+ st_dword(pte + PTE_SizLba, sz_part32); /* Number of sectors */
+ pte[PTE_System] = sys; /* System type */
+
+ cy = (UINT)(nxt_alloc32 / n_sc / n_hd); /* Start cylinder */
+ hd = (BYTE)(nxt_alloc32 / n_sc % n_hd); /* Start head */
+ sc = (BYTE)(nxt_alloc32 % n_sc + 1); /* Start sector */
+ pte[PTE_StHead] = hd;
+ pte[PTE_StSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
+ pte[PTE_StCyl] = (BYTE)cy;
+
+ cy = (UINT)((nxt_alloc32 + sz_part32 - 1) / n_sc / n_hd); /* End cylinder */
+ hd = (BYTE)((nxt_alloc32 + sz_part32 - 1) / n_sc % n_hd); /* End head */
+ sc = (BYTE)((nxt_alloc32 + sz_part32 - 1) % n_sc + 1); /* End sector */
+ pte[PTE_EdHead] = hd;
+ pte[PTE_EdSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
+ pte[PTE_EdCyl] = (BYTE)cy;
+
+ pte += SZ_PTE; /* Next entry */
+ }
+
+ st_word(buf + BS_55AA, 0xAA55); /* MBR signature */
+ if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR; /* Write it to the MBR */
+ }
+
+ return FR_OK;
+}
+
+
+
FRESULT f_mkfs (
- const TCHAR* path, /* Logical drive number */
- BYTE opt, /* Format option */
- DWORD au, /* Size of allocation unit (cluster) [byte] */
- void* work, /* Pointer to working buffer (null: use heap memory) */
- UINT len /* Size of working buffer [byte] */
+ const TCHAR* path, /* Logical drive number */
+ const MKFS_PARM* opt, /* Format options */
+ void* work, /* Pointer to working buffer (null: use len bytes of heap memory) */
+ UINT len /* Size of working buffer [byte] */
)
{
- const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
- const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
- BYTE fmt, sys, *buf, *pte, pdrv, part;
+ static const MKFS_PARM defopt = {FM_ANY, 0, 0, 0, 0}; /* Default parameter */
+ BYTE fsopt, fsty, sys, pdrv, ipart;
+ BYTE *buf;
+ BYTE *pte;
WORD ss; /* Sector size */
- DWORD szb_buf, sz_buf, sz_blk, n_clst, pau, sect, nsect, n;
- DWORD b_vol, b_fat, b_data; /* Base LBA for volume, fat, data */
- DWORD sz_vol, sz_rsv, sz_fat, sz_dir; /* Size for volume, fat, dir, data */
- UINT i;
+ DWORD sz_buf, sz_blk, n_clst, pau, nsect, n, vsn;
+ LBA_t sz_vol, b_vol, b_fat, b_data; /* Size of volume, Base LBA of volume, fat, data */
+ LBA_t sect, lba[2];
+ DWORD sz_rsv, sz_fat, sz_dir, sz_au; /* Size of reserved, fat, dir, data, cluster */
+ UINT n_fat, n_root, i; /* Index, Number of FATs and Number of roor dir entries */
int vol;
- DSTATUS stat;
-#if FF_USE_TRIM || FF_FS_EXFAT
- DWORD tbl[3];
-#endif
+ DSTATUS ds;
+ FRESULT res;
/* Check mounted drive and clear work area */
vol = get_ldnumber(&path); /* Get target logical drive */
if (vol < 0) return FR_INVALID_DRIVE;
- if (FatFs[vol]) FatFs[vol]->fs_type = 0; /* Clear the volume if mounted */
- pdrv = LD2PD(vol); /* Physical drive */
- part = LD2PT(vol); /* Partition (0:create as new, 1-4:get from partition table) */
-
- /* Check physical drive status */
- stat = disk_initialize(pdrv);
- if (stat & STA_NOINIT) return FR_NOT_READY;
- if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
- if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK || !sz_blk || sz_blk > 32768 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Erase block to align data area */
-#if FF_MAX_SS != FF_MIN_SS /* Get sector size of the medium if variable sector size cfg. */
+ if (FatFs[vol]) FatFs[vol]->fs_type = 0; /* Clear the fs object if mounted */
+ pdrv = LD2PD(vol); /* Hosting physical drive */
+ ipart = LD2PT(vol); /* Hosting partition (0:create as new, 1..:existing partition) */
+
+ /* Initialize the hosting physical drive */
+ ds = disk_initialize(pdrv);
+ if (ds & STA_NOINIT) return FR_NOT_READY;
+ if (ds & STA_PROTECT) return FR_WRITE_PROTECTED;
+
+ /* Get physical drive parameters (sz_drv, sz_blk and ss) */
+ if (!opt) opt = &defopt; /* Use default parameter if it is not given */
+ sz_blk = opt->align;
+ if (sz_blk == 0) disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk); /* Block size from the paramter or lower layer */
+ if (sz_blk == 0 || sz_blk > 0x8000 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Use default if the block size is invalid */
+#if FF_MAX_SS != FF_MIN_SS
if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR;
if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR;
#else
ss = FF_MAX_SS;
#endif
- if ((au != 0 && au < ss) || au > 0x1000000 || (au & (au - 1))) return FR_INVALID_PARAMETER; /* Check if au is valid */
- au /= ss; /* Cluster size in unit of sector */
+
+ /* Options for FAT sub-type and FAT parameters */
+ fsopt = opt->fmt & (FM_ANY | FM_SFD);
+ n_fat = (opt->n_fat >= 1 && opt->n_fat <= 2) ? opt->n_fat : 1;
+ n_root = (opt->n_root >= 1 && opt->n_root <= 32768 && (opt->n_root % (ss / SZDIRE)) == 0) ? opt->n_root : 512;
+ sz_au = (opt->au_size <= 0x1000000 && (opt->au_size & (opt->au_size - 1)) == 0) ? opt->au_size : 0;
+ sz_au /= ss; /* Byte --> Sector */
/* Get working buffer */
+ sz_buf = len / ss; /* Size of working buffer [sector] */
+ if (sz_buf == 0) return FR_NOT_ENOUGH_CORE;
+ buf = (BYTE*)work; /* Working buffer */
#if FF_USE_LFN == 3
- if (!work) { /* Use heap memory for working buffer */
- for (szb_buf = MAX_MALLOC, buf = 0; szb_buf >= ss && (buf = ff_memalloc(szb_buf)) == 0; szb_buf /= 2) ;
- sz_buf = szb_buf / ss; /* Size of working buffer (sector) */
- } else
+ if (!buf) buf = ff_memalloc(sz_buf * ss); /* Use heap memory for working buffer */
#endif
- {
- buf = (BYTE*)work; /* Working buffer */
- sz_buf = len / ss; /* Size of working buffer (sector) */
- szb_buf = sz_buf * ss; /* Size of working buffer (byte) */
- }
- if (!buf || sz_buf == 0) return FR_NOT_ENOUGH_CORE;
+ if (!buf) return FR_NOT_ENOUGH_CORE;
/* Determine where the volume to be located (b_vol, sz_vol) */
- if (FF_MULTI_PARTITION && part != 0) {
- /* Get partition information from partition table in the MBR */
+ b_vol = sz_vol = 0;
+ if (FF_MULTI_PARTITION && ipart != 0) { /* Is the volume associated with any specific partition? */
+ /* Get partition location from the existing partition table */
if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Load MBR */
if (ld_word(buf + BS_55AA) != 0xAA55) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if MBR is valid */
- pte = buf + (MBR_Table + (part - 1) * SZ_PTE);
- if (pte[PTE_System] == 0) LEAVE_MKFS(FR_MKFS_ABORTED); /* No partition? */
- b_vol = ld_dword(pte + PTE_StLba); /* Get volume start sector */
- sz_vol = ld_dword(pte + PTE_SizLba); /* Get volume size */
- } else {
- /* Create a single-partition in this function */
+#if FF_LBA64
+ if (buf[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */
+ DWORD n_ent, ofs;
+ QWORD pt_lba;
+
+ /* Get the partition location from GPT */
+ if (disk_read(pdrv, buf, 1, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Load GPT header sector (next to MBR) */
+ if (!test_gpt_header(buf)) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if GPT header is valid */
+ n_ent = ld_dword(buf + GPTH_PtNum); /* Number of entries */
+ pt_lba = ld_qword(buf + GPTH_PtOfs); /* Table start sector */
+ ofs = i = 0;
+ while (n_ent) { /* Find MS Basic partition with order of ipart */
+ if (ofs == 0 && disk_read(pdrv, buf, pt_lba++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Get PT sector */
+ if (!memcmp(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16) && ++i == ipart) { /* MS basic data partition? */
+ b_vol = ld_qword(buf + ofs + GPTE_FstLba);
+ sz_vol = ld_qword(buf + ofs + GPTE_LstLba) - b_vol + 1;
+ break;
+ }
+ n_ent--; ofs = (ofs + SZ_GPTE) % ss; /* Next entry */
+ }
+ if (n_ent == 0) LEAVE_MKFS(FR_MKFS_ABORTED); /* Partition not found */
+ fsopt |= 0x80; /* Partitioning is in GPT */
+ } else
+#endif
+ { /* Get the partition location from MBR partition table */
+ pte = buf + (MBR_Table + (ipart - 1) * SZ_PTE);
+ if (ipart > 4 || pte[PTE_System] == 0) LEAVE_MKFS(FR_MKFS_ABORTED); /* No partition? */
+ b_vol = ld_dword(pte + PTE_StLba); /* Get volume start sector */
+ sz_vol = ld_dword(pte + PTE_SizLba); /* Get volume size */
+ }
+ } else { /* The volume is associated with a physical drive */
if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_vol) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
- b_vol = (opt & FM_SFD) ? 0 : 63; /* Volume start sector */
- if (sz_vol < b_vol) LEAVE_MKFS(FR_MKFS_ABORTED);
- sz_vol -= b_vol; /* Volume size */
+ if (!(fsopt & FM_SFD)) { /* To be partitioned? */
+ /* Create a single-partition on the drive in this function */
+#if FF_LBA64
+ if (sz_vol >= FF_MIN_GPT) { /* Which partition type to create, MBR or GPT? */
+ fsopt |= 0x80; /* Partitioning is in GPT */
+ b_vol = GPT_ALIGN / ss; sz_vol -= b_vol + GPT_ITEMS * SZ_GPTE / ss + 1; /* Estimated partition offset and size */
+ } else
+#endif
+ { /* Partitioning is in MBR */
+ if (sz_vol > N_SEC_TRACK) {
+ b_vol = N_SEC_TRACK; sz_vol -= b_vol; /* Estimated partition offset and size */
+ }
+ }
+ }
}
if (sz_vol < 128) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if volume size is >=128s */
- /* Pre-determine the FAT type */
- do {
- if (FF_FS_EXFAT && (opt & FM_EXFAT)) { /* exFAT possible? */
- if ((opt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || au > 128) { /* exFAT only, vol >= 64Ms or au > 128s ? */
- fmt = FS_EXFAT; break;
+ /* Now start to create an FAT volume at b_vol and sz_vol */
+
+ do { /* Pre-determine the FAT type */
+ if (FF_FS_EXFAT && (fsopt & FM_EXFAT)) { /* exFAT possible? */
+ if ((fsopt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || sz_au > 128) { /* exFAT only, vol >= 64MS or sz_au > 128S ? */
+ fsty = FS_EXFAT; break;
}
}
- if (au > 128) LEAVE_MKFS(FR_INVALID_PARAMETER); /* Too large au for FAT/FAT32 */
- if (opt & FM_FAT32) { /* FAT32 possible? */
- if ((opt & FM_ANY) == FM_FAT32 || !(opt & FM_FAT)) { /* FAT32 only or no-FAT? */
- fmt = FS_FAT32; break;
+#if FF_LBA64
+ if (sz_vol >= 0x100000000) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too large volume for FAT/FAT32 */
+#endif
+ if (sz_au > 128) sz_au = 128; /* Invalid AU for FAT/FAT32? */
+ if (fsopt & FM_FAT32) { /* FAT32 possible? */
+ if (!(fsopt & FM_FAT)) { /* no-FAT? */
+ fsty = FS_FAT32; break;
}
}
- if (!(opt & FM_FAT)) LEAVE_MKFS(FR_INVALID_PARAMETER); /* no-FAT? */
- fmt = FS_FAT16;
+ if (!(fsopt & FM_FAT)) LEAVE_MKFS(FR_INVALID_PARAMETER); /* no-FAT? */
+ fsty = FS_FAT16;
} while (0);
+ vsn = (DWORD)sz_vol + GET_FATTIME(); /* VSN generated from current time and partitiion size */
+
#if FF_FS_EXFAT
- if (fmt == FS_EXFAT) { /* Create an exFAT volume */
- DWORD szb_bit, szb_case, sum, nb, cl;
+ if (fsty == FS_EXFAT) { /* Create an exFAT volume */
+ DWORD szb_bit, szb_case, sum, nbit, clu, clen[3];
WCHAR ch, si;
UINT j, st;
- BYTE b;
- if (sz_vol < 0x1000) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */
+ if (sz_vol < 0x1000) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume for exFAT? */
#if FF_USE_TRIM
- tbl[0] = b_vol; tbl[1] = b_vol + sz_vol - 1; /* Inform the device the volume area may be erased */
- disk_ioctl(pdrv, CTRL_TRIM, tbl);
+ lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */
+ disk_ioctl(pdrv, CTRL_TRIM, lba);
#endif
/* Determine FAT location, data location and number of clusters */
- if (au == 0) { /* au auto-selection */
- au = 8;
- if (sz_vol >= 0x80000) au = 64; /* >= 512Ks */
- if (sz_vol >= 0x4000000) au = 256; /* >= 64Ms */
+ if (sz_au == 0) { /* AU auto-selection */
+ sz_au = 8;
+ if (sz_vol >= 0x80000) sz_au = 64; /* >= 512Ks */
+ if (sz_vol >= 0x4000000) sz_au = 256; /* >= 64Ms */
}
b_fat = b_vol + 32; /* FAT start at offset 32 */
- sz_fat = ((sz_vol / au + 2) * 4 + ss - 1) / ss; /* Number of FAT sectors */
- b_data = (b_fat + sz_fat + sz_blk - 1) & ~(sz_blk - 1); /* Align data area to the erase block boundary */
- if (b_data >= sz_vol / 2) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */
- n_clst = (sz_vol - (b_data - b_vol)) / au; /* Number of clusters */
+ sz_fat = (DWORD)((sz_vol / sz_au + 2) * 4 + ss - 1) / ss; /* Number of FAT sectors */
+ b_data = (b_fat + sz_fat + sz_blk - 1) & ~((LBA_t)sz_blk - 1); /* Align data area to the erase block boundary */
+ if (b_data - b_vol >= sz_vol / 2) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */
+ n_clst = (DWORD)((sz_vol - (b_data - b_vol)) / sz_au); /* Number of clusters */
if (n_clst <16) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too few clusters? */
if (n_clst > MAX_EXFAT) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters? */
- szb_bit = (n_clst + 7) / 8; /* Size of allocation bitmap */
- tbl[0] = (szb_bit + au * ss - 1) / (au * ss); /* Number of allocation bitmap clusters */
+ szb_bit = (n_clst + 7) / 8; /* Size of allocation bitmap */
+ clen[0] = (szb_bit + sz_au * ss - 1) / (sz_au * ss); /* Number of allocation bitmap clusters */
/* Create a compressed up-case table */
- sect = b_data + au * tbl[0]; /* Table start sector */
- sum = 0; /* Table checksum to be stored in the 82 entry */
+ sect = b_data + sz_au * clen[0]; /* Table start sector */
+ sum = 0; /* Table checksum to be stored in the 82 entry */
st = 0; si = 0; i = 0; j = 0; szb_case = 0;
do {
switch (st) {
@@ -5640,10 +6062,10 @@ FRESULT f_mkfs ( }
for (j = 1; (WCHAR)(si + j) && (WCHAR)(si + j) == ff_wtoupper((WCHAR)(si + j)); j++) ; /* Get run length of no-case block */
if (j >= 128) {
- ch = 0xFFFF; st = 2; break; /* Compress the no-case block if run is >= 128 */
+ ch = 0xFFFF; st = 2; break; /* Compress the no-case block if run is >= 128 chars */
}
st = 1; /* Do not compress short run */
- /* go to next case */
+ /* FALLTHROUGH */
case 1:
ch = si++; /* Fill the short run */
if (--j == 0) st = 0;
@@ -5653,25 +6075,24 @@ FRESULT f_mkfs ( ch = (WCHAR)j; si += (WCHAR)j; /* Number of chars to skip */
st = 0;
}
- sum = xsum32(buf[i + 0] = (BYTE)ch, sum); /* Put it into the write buffer */
+ sum = xsum32(buf[i + 0] = (BYTE)ch, sum); /* Put it into the write buffer */
sum = xsum32(buf[i + 1] = (BYTE)(ch >> 8), sum);
i += 2; szb_case += 2;
- if (si == 0 || i == szb_buf) { /* Write buffered data when buffer full or end of process */
+ if (si == 0 || i == sz_buf * ss) { /* Write buffered data when buffer full or end of process */
n = (i + ss - 1) / ss;
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
sect += n; i = 0;
}
} while (si);
- tbl[1] = (szb_case + au * ss - 1) / (au * ss); /* Number of up-case table clusters */
- tbl[2] = 1; /* Number of root dir clusters */
+ clen[1] = (szb_case + sz_au * ss - 1) / (sz_au * ss); /* Number of up-case table clusters */
+ clen[2] = 1; /* Number of root dir clusters */
/* Initialize the allocation bitmap */
- sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of sectors */
- nb = tbl[0] + tbl[1] + tbl[2]; /* Number of clusters in-use by system */
+ sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of bitmap sectors */
+ nbit = clen[0] + clen[1] + clen[2]; /* Number of clusters in-use by system (bitmap, up-case and root-dir) */
do {
- mem_set(buf, 0, szb_buf);
- for (i = 0; nb >= 8 && i < szb_buf; buf[i++] = 0xFF, nb -= 8) ;
- for (b = 1; nb != 0 && i < szb_buf; buf[i] |= b, b <<= 1, nb--) ;
+ memset(buf, 0, sz_buf * ss); /* Initialize bitmap buffer */
+ for (i = 0; nbit != 0 && i / 8 < sz_buf * ss; buf[i / 8] |= 1 << (i % 8), i++, nbit--) ; /* Mark used clusters */
n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
sect += n; nsect -= n;
@@ -5679,40 +6100,40 @@ FRESULT f_mkfs ( /* Initialize the FAT */
sect = b_fat; nsect = sz_fat; /* Start of FAT and number of FAT sectors */
- j = nb = cl = 0;
+ j = nbit = clu = 0;
do {
- mem_set(buf, 0, szb_buf); i = 0; /* Clear work area and reset write index */
- if (cl == 0) { /* Set entry 0 and 1 */
- st_dword(buf + i, 0xFFFFFFF8); i += 4; cl++;
- st_dword(buf + i, 0xFFFFFFFF); i += 4; cl++;
+ memset(buf, 0, sz_buf * ss); i = 0; /* Clear work area and reset write offset */
+ if (clu == 0) { /* Initialize FAT [0] and FAT[1] */
+ st_dword(buf + i, 0xFFFFFFF8); i += 4; clu++;
+ st_dword(buf + i, 0xFFFFFFFF); i += 4; clu++;
}
do { /* Create chains of bitmap, up-case and root dir */
- while (nb != 0 && i < szb_buf) { /* Create a chain */
- st_dword(buf + i, (nb > 1) ? cl + 1 : 0xFFFFFFFF);
- i += 4; cl++; nb--;
+ while (nbit != 0 && i < sz_buf * ss) { /* Create a chain */
+ st_dword(buf + i, (nbit > 1) ? clu + 1 : 0xFFFFFFFF);
+ i += 4; clu++; nbit--;
}
- if (nb == 0 && j < 3) nb = tbl[j++]; /* Next chain */
- } while (nb != 0 && i < szb_buf);
+ if (nbit == 0 && j < 3) nbit = clen[j++]; /* Get next chain length */
+ } while (nbit != 0 && i < sz_buf * ss);
n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
sect += n; nsect -= n;
} while (nsect);
/* Initialize the root directory */
- mem_set(buf, 0, szb_buf);
- buf[SZDIRE * 0 + 0] = 0x83; /* 83 entry (volume label) */
- buf[SZDIRE * 1 + 0] = 0x81; /* 81 entry (allocation bitmap) */
- st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */
- st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */
- buf[SZDIRE * 2 + 0] = 0x82; /* 82 entry (up-case table) */
- st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */
- st_dword(buf + SZDIRE * 2 + 20, 2 + tbl[0]); /* cluster */
- st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */
- sect = b_data + au * (tbl[0] + tbl[1]); nsect = au; /* Start of the root directory and number of sectors */
+ memset(buf, 0, sz_buf * ss);
+ buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry (no label) */
+ buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */
+ st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */
+ st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */
+ buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */
+ st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */
+ st_dword(buf + SZDIRE * 2 + 20, 2 + clen[0]); /* cluster */
+ st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */
+ sect = b_data + sz_au * (clen[0] + clen[1]); nsect = sz_au; /* Start of the root directory and number of sectors */
do { /* Fill root directory sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
- mem_set(buf, 0, ss);
+ memset(buf, 0, ss); /* Rest of entries are filled with zero */
sect += n; nsect -= n;
} while (nsect);
@@ -5720,19 +6141,19 @@ FRESULT f_mkfs ( sect = b_vol;
for (n = 0; n < 2; n++) {
/* Main record (+0) */
- mem_set(buf, 0, ss);
- mem_cpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */
- st_dword(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */
- st_dword(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */
- st_dword(buf + BPB_FatOfsEx, b_fat - b_vol); /* FAT offset [sector] */
+ memset(buf, 0, ss);
+ memcpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */
+ st_qword(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */
+ st_qword(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */
+ st_dword(buf + BPB_FatOfsEx, (DWORD)(b_fat - b_vol)); /* FAT offset [sector] */
st_dword(buf + BPB_FatSzEx, sz_fat); /* FAT size [sector] */
- st_dword(buf + BPB_DataOfsEx, b_data - b_vol); /* Data offset [sector] */
+ st_dword(buf + BPB_DataOfsEx, (DWORD)(b_data - b_vol)); /* Data offset [sector] */
st_dword(buf + BPB_NumClusEx, n_clst); /* Number of clusters */
- st_dword(buf + BPB_RootClusEx, 2 + tbl[0] + tbl[1]); /* Root dir cluster # */
- st_dword(buf + BPB_VolIDEx, GET_FATTIME()); /* VSN */
+ st_dword(buf + BPB_RootClusEx, 2 + clen[0] + clen[1]); /* Root dir cluster # */
+ st_dword(buf + BPB_VolIDEx, vsn); /* VSN */
st_word(buf + BPB_FSVerEx, 0x100); /* Filesystem version (1.00) */
for (buf[BPB_BytsPerSecEx] = 0, i = ss; i >>= 1; buf[BPB_BytsPerSecEx]++) ; /* Log2 of sector size [byte] */
- for (buf[BPB_SecPerClusEx] = 0, i = au; i >>= 1; buf[BPB_SecPerClusEx]++) ; /* Log2 of cluster size [sector] */
+ for (buf[BPB_SecPerClusEx] = 0, i = sz_au; i >>= 1; buf[BPB_SecPerClusEx]++) ; /* Log2 of cluster size [sector] */
buf[BPB_NumFATsEx] = 1; /* Number of FATs */
buf[BPB_DrvNumEx] = 0x80; /* Drive number (for int13) */
st_word(buf + BS_BootCodeEx, 0xFEEB); /* Boot code (x86) */
@@ -5742,14 +6163,14 @@ FRESULT f_mkfs ( }
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
/* Extended bootstrap record (+1..+8) */
- mem_set(buf, 0, ss);
+ memset(buf, 0, ss);
st_word(buf + ss - 2, 0xAA55); /* Signature (placed at end of sector) */
for (j = 1; j < 9; j++) {
for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
}
/* OEM/Reserved record (+9..+10) */
- mem_set(buf, 0, ss);
+ memset(buf, 0, ss);
for ( ; j < 11; j++) {
for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
@@ -5763,120 +6184,123 @@ FRESULT f_mkfs ( #endif /* FF_FS_EXFAT */
{ /* Create an FAT/FAT32 volume */
do {
- pau = au;
+ pau = sz_au;
/* Pre-determine number of clusters and FAT sub-type */
- if (fmt == FS_FAT32) { /* FAT32 volume */
- if (pau == 0) { /* au auto-selection */
- n = sz_vol / 0x20000; /* Volume size in unit of 128KS */
+ if (fsty == FS_FAT32) { /* FAT32 volume */
+ if (pau == 0) { /* AU auto-selection */
+ n = (DWORD)sz_vol / 0x20000; /* Volume size in unit of 128KS */
for (i = 0, pau = 1; cst32[i] && cst32[i] <= n; i++, pau <<= 1) ; /* Get from table */
}
- n_clst = sz_vol / pau; /* Number of clusters */
+ n_clst = (DWORD)sz_vol / pau; /* Number of clusters */
sz_fat = (n_clst * 4 + 8 + ss - 1) / ss; /* FAT size [sector] */
sz_rsv = 32; /* Number of reserved sectors */
sz_dir = 0; /* No static directory */
if (n_clst <= MAX_FAT16 || n_clst > MAX_FAT32) LEAVE_MKFS(FR_MKFS_ABORTED);
} else { /* FAT volume */
if (pau == 0) { /* au auto-selection */
- n = sz_vol / 0x1000; /* Volume size in unit of 4KS */
+ n = (DWORD)sz_vol / 0x1000; /* Volume size in unit of 4KS */
for (i = 0, pau = 1; cst[i] && cst[i] <= n; i++, pau <<= 1) ; /* Get from table */
}
- n_clst = sz_vol / pau;
+ n_clst = (DWORD)sz_vol / pau;
if (n_clst > MAX_FAT12) {
n = n_clst * 2 + 4; /* FAT size [byte] */
} else {
- fmt = FS_FAT12;
+ fsty = FS_FAT12;
n = (n_clst * 3 + 1) / 2 + 3; /* FAT size [byte] */
}
sz_fat = (n + ss - 1) / ss; /* FAT size [sector] */
sz_rsv = 1; /* Number of reserved sectors */
- sz_dir = (DWORD)n_rootdir * SZDIRE / ss; /* Rootdir size [sector] */
+ sz_dir = (DWORD)n_root * SZDIRE / ss; /* Root dir size [sector] */
}
b_fat = b_vol + sz_rsv; /* FAT base */
- b_data = b_fat + sz_fat * n_fats + sz_dir; /* Data base */
+ b_data = b_fat + sz_fat * n_fat + sz_dir; /* Data base */
- /* Align data base to erase block boundary (for flash memory media) */
- n = ((b_data + sz_blk - 1) & ~(sz_blk - 1)) - b_data; /* Next nearest erase block from current data base */
- if (fmt == FS_FAT32) { /* FAT32: Move FAT base */
+ /* Align data area to erase block boundary (for flash memory media) */
+ n = (DWORD)(((b_data + sz_blk - 1) & ~(sz_blk - 1)) - b_data); /* Sectors to next nearest from current data base */
+ if (fsty == FS_FAT32) { /* FAT32: Move FAT */
sz_rsv += n; b_fat += n;
- } else { /* FAT: Expand FAT size */
- sz_fat += n / n_fats;
+ } else { /* FAT: Expand FAT */
+ if (n % n_fat) { /* Adjust fractional error if needed */
+ n--; sz_rsv++; b_fat++;
+ }
+ sz_fat += n / n_fat;
}
/* Determine number of clusters and final check of validity of the FAT sub-type */
- if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume */
- n_clst = (sz_vol - sz_rsv - sz_fat * n_fats - sz_dir) / pau;
- if (fmt == FS_FAT32) {
- if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32 */
- if (au == 0 && (au = pau / 2) != 0) continue; /* Adjust cluster size and retry */
+ if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */
+ n_clst = ((DWORD)sz_vol - sz_rsv - sz_fat * n_fat - sz_dir) / pau;
+ if (fsty == FS_FAT32) {
+ if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32? */
+ if (sz_au == 0 && (sz_au = pau / 2) != 0) continue; /* Adjust cluster size and retry */
LEAVE_MKFS(FR_MKFS_ABORTED);
}
}
- if (fmt == FS_FAT16) {
+ if (fsty == FS_FAT16) {
if (n_clst > MAX_FAT16) { /* Too many clusters for FAT16 */
- if (au == 0 && (pau * 2) <= 64) {
- au = pau * 2; continue; /* Adjust cluster size and retry */
+ if (sz_au == 0 && (pau * 2) <= 64) {
+ sz_au = pau * 2; continue; /* Adjust cluster size and retry */
}
- if ((opt & FM_FAT32)) {
- fmt = FS_FAT32; continue; /* Switch type to FAT32 and retry */
+ if ((fsopt & FM_FAT32)) {
+ fsty = FS_FAT32; continue; /* Switch type to FAT32 and retry */
}
- if (au == 0 && (au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */
+ if (sz_au == 0 && (sz_au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */
LEAVE_MKFS(FR_MKFS_ABORTED);
}
if (n_clst <= MAX_FAT12) { /* Too few clusters for FAT16 */
- if (au == 0 && (au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */
+ if (sz_au == 0 && (sz_au = pau * 2) <= 128) continue; /* Adjust cluster size and retry */
LEAVE_MKFS(FR_MKFS_ABORTED);
}
}
- if (fmt == FS_FAT12 && n_clst > MAX_FAT12) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters for FAT12 */
+ if (fsty == FS_FAT12 && n_clst > MAX_FAT12) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters for FAT12 */
/* Ok, it is the valid cluster configuration */
break;
} while (1);
#if FF_USE_TRIM
- tbl[0] = b_vol; tbl[1] = b_vol + sz_vol - 1; /* Inform the device the volume area can be erased */
- disk_ioctl(pdrv, CTRL_TRIM, tbl);
+ lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */
+ disk_ioctl(pdrv, CTRL_TRIM, lba);
#endif
/* Create FAT VBR */
- mem_set(buf, 0, ss);
- mem_cpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code (x86), OEM name */
+ memset(buf, 0, ss);
+ memcpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11); /* Boot jump code (x86), OEM name */
st_word(buf + BPB_BytsPerSec, ss); /* Sector size [byte] */
buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */
st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */
- buf[BPB_NumFATs] = (BYTE)n_fats; /* Number of FATs */
- st_word(buf + BPB_RootEntCnt, (WORD)((fmt == FS_FAT32) ? 0 : n_rootdir)); /* Number of root directory entries */
+ buf[BPB_NumFATs] = (BYTE)n_fat; /* Number of FATs */
+ st_word(buf + BPB_RootEntCnt, (WORD)((fsty == FS_FAT32) ? 0 : n_root)); /* Number of root directory entries */
if (sz_vol < 0x10000) {
st_word(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */
} else {
- st_dword(buf + BPB_TotSec32, sz_vol); /* Volume size in 32-bit LBA */
+ st_dword(buf + BPB_TotSec32, (DWORD)sz_vol); /* Volume size in 32-bit LBA */
}
buf[BPB_Media] = 0xF8; /* Media descriptor byte */
st_word(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */
st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */
- st_dword(buf + BPB_HiddSec, b_vol); /* Volume offset in the physical drive [sector] */
- if (fmt == FS_FAT32) {
- st_dword(buf + BS_VolID32, GET_FATTIME()); /* VSN */
+ st_dword(buf + BPB_HiddSec, (DWORD)b_vol); /* Volume offset in the physical drive [sector] */
+ if (fsty == FS_FAT32) {
+ st_dword(buf + BS_VolID32, vsn); /* VSN */
st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */
st_dword(buf + BPB_RootClus32, 2); /* Root directory cluster # (2) */
st_word(buf + BPB_FSInfo32, 1); /* Offset of FSINFO sector (VBR + 1) */
st_word(buf + BPB_BkBootSec32, 6); /* Offset of backup VBR (VBR + 6) */
buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */
buf[BS_BootSig32] = 0x29; /* Extended boot signature */
- mem_cpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
+ memcpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
} else {
- st_dword(buf + BS_VolID, GET_FATTIME()); /* VSN */
+ st_dword(buf + BS_VolID, vsn); /* VSN */
st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */
buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */
buf[BS_BootSig] = 0x29; /* Extended boot signature */
- mem_cpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
+ memcpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
}
st_word(buf + BS_55AA, 0xAA55); /* Signature (offset is fixed here regardless of sector size) */
if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */
/* Create FSINFO record if needed */
- if (fmt == FS_FAT32) {
+ if (fsty == FS_FAT32) {
disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */
- mem_set(buf, 0, ss);
+ memset(buf, 0, ss);
st_dword(buf + FSI_LeadSig, 0x41615252);
st_dword(buf + FSI_StrucSig, 0x61417272);
st_dword(buf + FSI_Free_Count, n_clst - 1); /* Number of free clusters */
@@ -5887,27 +6311,27 @@ FRESULT f_mkfs ( }
/* Initialize FAT area */
- mem_set(buf, 0, (UINT)szb_buf);
+ memset(buf, 0, sz_buf * ss);
sect = b_fat; /* FAT start sector */
- for (i = 0; i < n_fats; i++) { /* Initialize FATs each */
- if (fmt == FS_FAT32) {
- st_dword(buf + 0, 0xFFFFFFF8); /* Entry 0 */
- st_dword(buf + 4, 0xFFFFFFFF); /* Entry 1 */
- st_dword(buf + 8, 0x0FFFFFFF); /* Entry 2 (root directory) */
+ for (i = 0; i < n_fat; i++) { /* Initialize FATs each */
+ if (fsty == FS_FAT32) {
+ st_dword(buf + 0, 0xFFFFFFF8); /* FAT[0] */
+ st_dword(buf + 4, 0xFFFFFFFF); /* FAT[1] */
+ st_dword(buf + 8, 0x0FFFFFFF); /* FAT[2] (root directory) */
} else {
- st_dword(buf + 0, (fmt == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* Entry 0 and 1 */
+ st_dword(buf + 0, (fsty == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* FAT[0] and FAT[1] */
}
nsect = sz_fat; /* Number of FAT sectors */
do { /* Fill FAT sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
- mem_set(buf, 0, ss);
+ memset(buf, 0, ss); /* Rest of FAT all are cleared */
sect += n; nsect -= n;
} while (nsect);
}
/* Initialize root directory (fill with zero) */
- nsect = (fmt == FS_FAT32) ? pau : sz_dir; /* Number of root directory sectors */
+ nsect = (fsty == FS_FAT32) ? pau : sz_dir; /* Number of root directory sectors */
do {
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
@@ -5915,44 +6339,34 @@ FRESULT f_mkfs ( } while (nsect);
}
- /* Determine system ID in the partition table */
- if (FF_FS_EXFAT && fmt == FS_EXFAT) {
- sys = 0x07; /* HPFS/NTFS/exFAT */
+ /* A FAT volume has been created here */
+
+ /* Determine system ID in the MBR partition table */
+ if (FF_FS_EXFAT && fsty == FS_EXFAT) {
+ sys = 0x07; /* exFAT */
+ } else if (fsty == FS_FAT32) {
+ sys = 0x0C; /* FAT32X */
+ } else if (sz_vol >= 0x10000) {
+ sys = 0x06; /* FAT12/16 (large) */
+ } else if (fsty == FS_FAT16) {
+ sys = 0x04; /* FAT16 */
} else {
- if (fmt == FS_FAT32) {
- sys = 0x0C; /* FAT32X */
- } else {
- if (sz_vol >= 0x10000) {
- sys = 0x06; /* FAT12/16 (large) */
- } else {
- sys = (fmt == FS_FAT16) ? 0x04 : 0x01; /* FAT16 : FAT12 */
- }
- }
+ sys = 0x01; /* FAT12 */
}
/* Update partition information */
- if (FF_MULTI_PARTITION && part != 0) { /* Created in the existing partition */
- /* Update system ID in the partition table */
- if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Read the MBR */
- buf[MBR_Table + (part - 1) * SZ_PTE + PTE_System] = sys; /* Set system ID */
- if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it back to the MBR */
- } else { /* Created as a new single partition */
- if (!(opt & FM_SFD)) { /* Create partition table if in FDISK format */
- mem_set(buf, 0, ss);
- st_word(buf + BS_55AA, 0xAA55); /* MBR signature */
- pte = buf + MBR_Table; /* Create partition table for single partition in the drive */
- pte[PTE_Boot] = 0; /* Boot indicator */
- pte[PTE_StHead] = 1; /* Start head */
- pte[PTE_StSec] = 1; /* Start sector */
- pte[PTE_StCyl] = 0; /* Start cylinder */
- pte[PTE_System] = sys; /* System type */
- n = (b_vol + sz_vol) / (63 * 255); /* (End CHS may be invalid) */
- pte[PTE_EdHead] = 254; /* End head */
- pte[PTE_EdSec] = (BYTE)(((n >> 2) & 0xC0) | 63); /* End sector */
- pte[PTE_EdCyl] = (BYTE)n; /* End cylinder */
- st_dword(pte + PTE_StLba, b_vol); /* Start offset in LBA */
- st_dword(pte + PTE_SizLba, sz_vol); /* Size in sectors */
- if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the MBR */
+ if (FF_MULTI_PARTITION && ipart != 0) { /* Volume is in the existing partition */
+ if (!FF_LBA64 || !(fsopt & 0x80)) { /* Is the partition in MBR? */
+ /* Update system ID in the partition table */
+ if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Read the MBR */
+ buf[MBR_Table + (ipart - 1) * SZ_PTE + PTE_System] = sys; /* Set system ID */
+ if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it back to the MBR */
+ }
+ } else { /* Volume as a new single partition */
+ if (!(fsopt & FM_SFD)) { /* Create partition table if not in SFD format */
+ lba[0] = sz_vol; lba[1] = 0;
+ res = create_partition(pdrv, lba, sys, buf);
+ if (res != FR_OK) LEAVE_MKFS(res);
}
}
@@ -5963,6 +6377,7 @@ FRESULT f_mkfs ( +
#if FF_MULTI_PARTITION
/*-----------------------------------------------------------------------*/
/* Create Partition Table on the Physical Drive */
@@ -5970,75 +6385,32 @@ FRESULT f_mkfs ( FRESULT f_fdisk (
BYTE pdrv, /* Physical drive number */
- const DWORD* szt, /* Pointer to the size table for each partitions */
+ const LBA_t ptbl[], /* Pointer to the size table for each partitions */
void* work /* Pointer to the working buffer (null: use heap memory) */
)
{
- UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl;
- BYTE s_hd, e_hd, *p, *buf = (BYTE*)work;
+ BYTE *buf = (BYTE*)work;
DSTATUS stat;
- DWORD sz_disk, sz_part, s_part;
FRESULT res;
+ /* Initialize the physical drive */
stat = disk_initialize(pdrv);
if (stat & STA_NOINIT) return FR_NOT_READY;
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
- if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR;
- buf = (BYTE*)work;
#if FF_USE_LFN == 3
if (!buf) buf = ff_memalloc(FF_MAX_SS); /* Use heap memory for working buffer */
#endif
if (!buf) return FR_NOT_ENOUGH_CORE;
- /* Determine the CHS without any consideration of the drive geometry */
- for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ;
- if (n == 256) n--;
- e_hd = (BYTE)(n - 1);
- sz_cyl = 63 * n;
- tot_cyl = sz_disk / sz_cyl;
-
- /* Create partition table */
- mem_set(buf, 0, FF_MAX_SS);
- p = buf + MBR_Table; b_cyl = 0;
- for (i = 0; i < 4; i++, p += SZ_PTE) {
- p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; /* Number of cylinders */
- if (p_cyl == 0) continue;
- s_part = (DWORD)sz_cyl * b_cyl;
- sz_part = (DWORD)sz_cyl * p_cyl;
- if (i == 0) { /* Exclude first track of cylinder 0 */
- s_hd = 1;
- s_part += 63; sz_part -= 63;
- } else {
- s_hd = 0;
- }
- e_cyl = b_cyl + p_cyl - 1; /* End cylinder */
- if (e_cyl >= tot_cyl) LEAVE_MKFS(FR_INVALID_PARAMETER);
-
- /* Set partition table */
- p[1] = s_hd; /* Start head */
- p[2] = (BYTE)(((b_cyl >> 2) & 0xC0) | 1); /* Start sector */
- p[3] = (BYTE)b_cyl; /* Start cylinder */
- p[4] = 0x07; /* System type (temporary setting) */
- p[5] = e_hd; /* End head */
- p[6] = (BYTE)(((e_cyl >> 2) & 0xC0) | 63); /* End sector */
- p[7] = (BYTE)e_cyl; /* End cylinder */
- st_dword(p + 8, s_part); /* Start sector in LBA */
- st_dword(p + 12, sz_part); /* Number of sectors */
+ res = create_partition(pdrv, ptbl, 0x07, buf); /* Create partitions (system ID is temporary setting and determined by f_mkfs) */
- /* Next partition */
- b_cyl += p_cyl;
- }
- st_word(p, 0xAA55); /* MBR signature (always at offset 510) */
-
- /* Write it to the MBR */
- res = (disk_write(pdrv, buf, 0, 1) == RES_OK && disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR;
LEAVE_MKFS(res);
}
#endif /* FF_MULTI_PARTITION */
-#endif /* FF_USE_MKFS && !FF_FS_READONLY */
+#endif /* !FF_FS_READONLY && FF_USE_MKFS */
@@ -6052,7 +6424,7 @@ FRESULT f_fdisk ( /*-----------------------------------------------------------------------*/
TCHAR* f_gets (
- TCHAR* buff, /* Pointer to the string buffer to read */
+ TCHAR* buff, /* Pointer to the buffer to store read string */
int len, /* Size of string buffer (items) */
FIL* fp /* Pointer to the file object */
)
@@ -6075,49 +6447,57 @@ TCHAR* f_gets ( if (FF_LFN_UNICODE == 2) len -= (FF_STRF_ENCODE == 0) ? 3 : 4;
if (FF_LFN_UNICODE == 3) len -= 1;
while (nc < len) {
-#if FF_STRF_ENCODE == 0 /* Read a character in ANSI/OEM */
- f_read(fp, s, 1, &rc);
- if (rc != 1) break;
+#if FF_STRF_ENCODE == 0 /* Read a character in ANSI/OEM */
+ f_read(fp, s, 1, &rc); /* Get a code unit */
+ if (rc != 1) break; /* EOF? */
wc = s[0];
- if (dbc_1st((BYTE)wc)) {
- f_read(fp, s, 1, &rc);
- if (rc != 1 || !dbc_2nd(s[0])) continue;
+ if (dbc_1st((BYTE)wc)) { /* DBC 1st byte? */
+ f_read(fp, s, 1, &rc); /* Get 2nd byte */
+ if (rc != 1 || !dbc_2nd(s[0])) continue; /* Wrong code? */
wc = wc << 8 | s[0];
}
- dc = ff_oem2uni(wc, CODEPAGE);
- if (dc == 0) continue;
+ dc = ff_oem2uni(wc, CODEPAGE); /* Convert ANSI/OEM into Unicode */
+ if (dc == 0) continue; /* Conversion error? */
#elif FF_STRF_ENCODE == 1 || FF_STRF_ENCODE == 2 /* Read a character in UTF-16LE/BE */
- f_read(fp, s, 2, &rc);
- if (rc != 2) break;
+ f_read(fp, s, 2, &rc); /* Get a code unit */
+ if (rc != 2) break; /* EOF? */
dc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1];
- if (IsSurrogateL(dc)) continue;
- if (IsSurrogateH(dc)) {
- f_read(fp, s, 2, &rc);
- if (rc != 2) break;
+ if (IsSurrogateL(dc)) continue; /* Broken surrogate pair? */
+ if (IsSurrogateH(dc)) { /* High surrogate? */
+ f_read(fp, s, 2, &rc); /* Get low surrogate */
+ if (rc != 2) break; /* EOF? */
wc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1];
- if (!IsSurrogateL(wc)) continue;
- dc = ((dc & 0x3FF) + 0x40) << 10 | (wc & 0x3FF);
+ if (!IsSurrogateL(wc)) continue; /* Broken surrogate pair? */
+ dc = ((dc & 0x3FF) + 0x40) << 10 | (wc & 0x3FF); /* Merge surrogate pair */
}
#else /* Read a character in UTF-8 */
- f_read(fp, s, 1, &rc);
- if (rc != 1) break;
+ f_read(fp, s, 1, &rc); /* Get a code unit */
+ if (rc != 1) break; /* EOF? */
dc = s[0];
- if (dc >= 0x80) { /* Multi-byte character? */
+ if (dc >= 0x80) { /* Multi-byte sequence? */
ct = 0;
- if ((dc & 0xE0) == 0xC0) { dc &= 0x1F; ct = 1; } /* 2-byte? */
- if ((dc & 0xF0) == 0xE0) { dc &= 0x0F; ct = 2; } /* 3-byte? */
- if ((dc & 0xF8) == 0xF0) { dc &= 0x07; ct = 3; } /* 4-byte? */
+ if ((dc & 0xE0) == 0xC0) { /* 2-byte sequence? */
+ dc &= 0x1F; ct = 1;
+ }
+ if ((dc & 0xF0) == 0xE0) { /* 3-byte sequence? */
+ dc &= 0x0F; ct = 2;
+ }
+ if ((dc & 0xF8) == 0xF0) { /* 4-byte sequence? */
+ dc &= 0x07; ct = 3;
+ }
if (ct == 0) continue;
- f_read(fp, s, ct, &rc); /* Get trailing bytes */
+ f_read(fp, s, ct, &rc); /* Get trailing bytes */
if (rc != ct) break;
rc = 0;
- do { /* Merge trailing bytes */
+ do { /* Merge the byte sequence */
if ((s[rc] & 0xC0) != 0x80) break;
dc = dc << 6 | (s[rc] & 0x3F);
} while (++rc < ct);
if (rc != ct || dc < 0x80 || IsSurrogate(dc) || dc >= 0x110000) continue; /* Wrong encoding? */
}
#endif
+ /* A code point is avaialble in dc to be output */
+
if (FF_USE_STRFUNC == 2 && dc == '\r') continue; /* Strip \r off if needed */
#if FF_LFN_UNICODE == 1 || FF_LFN_UNICODE == 3 /* Output it in UTF-16/32 encoding */
if (FF_LFN_UNICODE == 1 && dc >= 0x10000) { /* Out of BMP at UTF-16? */
@@ -6127,38 +6507,34 @@ TCHAR* f_gets ( *p++ = (TCHAR)dc; nc++;
if (dc == '\n') break; /* End of line? */
#elif FF_LFN_UNICODE == 2 /* Output it in UTF-8 encoding */
- if (dc < 0x80) { /* 1-byte */
+ if (dc < 0x80) { /* Single byte? */
*p++ = (TCHAR)dc;
nc++;
if (dc == '\n') break; /* End of line? */
- } else {
- if (dc < 0x800) { /* 2-byte */
- *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F));
- *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
- nc += 2;
- } else {
- if (dc < 0x10000) { /* 3-byte */
- *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F));
- *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
- *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
- nc += 3;
- } else { /* 4-byte */
- *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07));
- *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F));
- *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
- *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
- nc += 4;
- }
- }
- }
-#endif
- }
-
-#else /* Byte-by-byte without any conversion (ANSI/OEM API) */
+ } else if (dc < 0x800) { /* 2-byte sequence? */
+ *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F));
+ *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
+ nc += 2;
+ } else if (dc < 0x10000) { /* 3-byte sequence? */
+ *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F));
+ *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
+ *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
+ nc += 3;
+ } else { /* 4-byte sequence */
+ *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07));
+ *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F));
+ *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
+ *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
+ nc += 4;
+ }
+#endif
+ }
+
+#else /* Byte-by-byte read without any conversion (ANSI/OEM API) */
len -= 1; /* Make a room for the terminator */
while (nc < len) {
- f_read(fp, s, 1, &rc);
- if (rc != 1) break;
+ f_read(fp, s, 1, &rc); /* Get a byte */
+ if (rc != 1) break; /* EOF? */
dc = s[0];
if (FF_USE_STRFUNC == 2 && dc == '\r') continue;
*p++ = (TCHAR)dc; nc++;
@@ -6175,11 +6551,16 @@ TCHAR* f_gets ( #if !FF_FS_READONLY
#include <stdarg.h>
+#define SZ_PUTC_BUF 64
+#define SZ_NUM_BUF 32
+
/*-----------------------------------------------------------------------*/
-/* Put a Character to the File */
+/* Put a Character to the File (with sub-functions) */
/*-----------------------------------------------------------------------*/
-typedef struct { /* Putchar output buffer and work area */
+/* Output buffer and work area */
+
+typedef struct {
FIL *fp; /* Ptr to the writing file */
int idx, nchr; /* Write index of buf[] (-1:error), number of encoding units written */
#if FF_USE_LFN && FF_LFN_UNICODE == 1
@@ -6188,15 +6569,13 @@ typedef struct { /* Putchar output buffer and work area */ BYTE bs[4];
UINT wi, ct;
#endif
- BYTE buf[64]; /* Write buffer */
+ BYTE buf[SZ_PUTC_BUF]; /* Write buffer */
} putbuff;
-static
-void putc_bfd ( /* Buffered write with code conversion */
- putbuff* pb,
- TCHAR c
-)
+/* Buffered file write with code conversion */
+
+static void putc_bfd (putbuff* pb, TCHAR c)
{
UINT n;
int i, nc;
@@ -6204,7 +6583,7 @@ void putc_bfd ( /* Buffered write with code conversion */ WCHAR hs, wc;
#if FF_LFN_UNICODE == 2
DWORD dc;
- TCHAR *tp;
+ const TCHAR* tp;
#endif
#endif
@@ -6213,47 +6592,47 @@ void putc_bfd ( /* Buffered write with code conversion */ }
i = pb->idx; /* Write index of pb->buf[] */
- if (i < 0) return;
+ if (i < 0) return; /* In write error? */
nc = pb->nchr; /* Write unit counter */
#if FF_USE_LFN && FF_LFN_UNICODE
#if FF_LFN_UNICODE == 1 /* UTF-16 input */
- if (IsSurrogateH(c)) {
- pb->hs = c; return;
+ if (IsSurrogateH(c)) { /* Is this a high-surrogate? */
+ pb->hs = c; return; /* Save it for next */
}
hs = pb->hs; pb->hs = 0;
- if (hs != 0) {
- if (!IsSurrogateL(c)) hs = 0;
+ if (hs != 0) { /* Is there a leading high-surrogate? */
+ if (!IsSurrogateL(c)) hs = 0; /* Discard high-surrogate if not a surrogate pair */
} else {
- if (IsSurrogateL(c)) return;
+ if (IsSurrogateL(c)) return; /* Discard stray low-surrogate */
}
wc = c;
#elif FF_LFN_UNICODE == 2 /* UTF-8 input */
for (;;) {
if (pb->ct == 0) { /* Out of multi-byte sequence? */
pb->bs[pb->wi = 0] = (BYTE)c; /* Save 1st byte */
- if ((BYTE)c < 0x80) break; /* 1-byte? */
- if (((BYTE)c & 0xE0) == 0xC0) pb->ct = 1; /* 2-byte? */
- if (((BYTE)c & 0xF0) == 0xE0) pb->ct = 2; /* 3-byte? */
- if (((BYTE)c & 0xF1) == 0xF0) pb->ct = 3; /* 4-byte? */
- return;
+ if ((BYTE)c < 0x80) break; /* Single byte code? */
+ if (((BYTE)c & 0xE0) == 0xC0) pb->ct = 1; /* 2-byte sequence? */
+ if (((BYTE)c & 0xF0) == 0xE0) pb->ct = 2; /* 3-byte sequence? */
+ if (((BYTE)c & 0xF8) == 0xF0) pb->ct = 3; /* 4-byte sequence? */
+ return; /* Wrong leading byte (discard it) */
} else { /* In the multi-byte sequence */
if (((BYTE)c & 0xC0) != 0x80) { /* Broken sequence? */
- pb->ct = 0; continue;
+ pb->ct = 0; continue; /* Discard the sequense */
}
pb->bs[++pb->wi] = (BYTE)c; /* Save the trailing byte */
- if (--pb->ct == 0) break; /* End of multi-byte sequence? */
+ if (--pb->ct == 0) break; /* End of the sequence? */
return;
}
}
- tp = (TCHAR*)pb->bs;
- dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */
- if (dc == 0xFFFFFFFF) return;
- wc = (WCHAR)dc;
+ tp = (const TCHAR*)pb->bs;
+ dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */
+ if (dc == 0xFFFFFFFF) return; /* Wrong code? */
hs = (WCHAR)(dc >> 16);
+ wc = (WCHAR)dc;
#elif FF_LFN_UNICODE == 3 /* UTF-32 input */
- if (IsSurrogate(c) || c >= 0x110000) return;
- if (c >= 0x10000) {
+ if (IsSurrogate(c) || c >= 0x110000) return; /* Discard invalid code */
+ if (c >= 0x10000) { /* Out of BMP? */
hs = (WCHAR)(0xD800 | ((c >> 10) - 0x40)); /* Make high surrogate */
wc = 0xDC00 | (c & 0x3FF); /* Make low surrogate */
} else {
@@ -6261,25 +6640,26 @@ void putc_bfd ( /* Buffered write with code conversion */ wc = (WCHAR)c;
}
#endif
+ /* A code point in UTF-16 is available in hs and wc */
-#if FF_STRF_ENCODE == 1 /* Write a character in UTF-16LE */
- if (hs != 0) {
+#if FF_STRF_ENCODE == 1 /* Write a code point in UTF-16LE */
+ if (hs != 0) { /* Surrogate pair? */
st_word(&pb->buf[i], hs);
i += 2;
nc++;
}
st_word(&pb->buf[i], wc);
i += 2;
-#elif FF_STRF_ENCODE == 2 /* Write a character in UTF-16BE */
- if (hs != 0) {
+#elif FF_STRF_ENCODE == 2 /* Write a code point in UTF-16BE */
+ if (hs != 0) { /* Surrogate pair? */
pb->buf[i++] = (BYTE)(hs >> 8);
pb->buf[i++] = (BYTE)hs;
nc++;
}
pb->buf[i++] = (BYTE)(wc >> 8);
pb->buf[i++] = (BYTE)wc;
-#elif FF_STRF_ENCODE == 3 /* Write it in UTF-8 */
- if (hs != 0) { /* 4-byte */
+#elif FF_STRF_ENCODE == 3 /* Write a code point in UTF-8 */
+ if (hs != 0) { /* 4-byte sequence? */
nc += 3;
hs = (hs & 0x3FF) + 0x40;
pb->buf[i++] = (BYTE)(0xF0 | hs >> 8);
@@ -6287,13 +6667,13 @@ void putc_bfd ( /* Buffered write with code conversion */ pb->buf[i++] = (BYTE)(0x80 | (hs & 3) << 4 | (wc >> 6 & 0x0F));
pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F));
} else {
- if (wc < 0x80) { /* 1-byte */
+ if (wc < 0x80) { /* Single byte? */
pb->buf[i++] = (BYTE)wc;
} else {
- if (wc < 0x800) { /* 2-byte */
+ if (wc < 0x800) { /* 2-byte sequence? */
nc += 1;
pb->buf[i++] = (BYTE)(0xC0 | wc >> 6);
- } else { /* 3-byte */
+ } else { /* 3-byte sequence */
nc += 2;
pb->buf[i++] = (BYTE)(0xE0 | wc >> 12);
pb->buf[i++] = (BYTE)(0x80 | (wc >> 6 & 0x3F));
@@ -6301,17 +6681,17 @@ void putc_bfd ( /* Buffered write with code conversion */ pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F));
}
}
-#else /* Write it in ANSI/OEM */
+#else /* Write a code point in ANSI/OEM */
if (hs != 0) return;
wc = ff_uni2oem(wc, CODEPAGE); /* UTF-16 ==> ANSI/OEM */
- if (wc == 0) return;;
+ if (wc == 0) return;
if (wc >= 0x100) {
pb->buf[i++] = (BYTE)(wc >> 8); nc++;
}
pb->buf[i++] = (BYTE)wc;
#endif
-#else /* ANSI/OEM input (without re-encode) */
+#else /* ANSI/OEM input (without re-encoding) */
pb->buf[i++] = (BYTE)c;
#endif
@@ -6324,27 +6704,24 @@ void putc_bfd ( /* Buffered write with code conversion */ }
-static
-int putc_flush ( /* Flush left characters in the buffer */
- putbuff* pb
-)
+/* Flush remaining characters in the buffer */
+
+static int putc_flush (putbuff* pb)
{
UINT nw;
if ( pb->idx >= 0 /* Flush buffered characters to the file */
&& f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK
&& (UINT)pb->idx == nw) return pb->nchr;
- return EOF;
+ return -1;
}
-static
-void putc_init ( /* Initialize write buffer */
- putbuff* pb,
- FIL* fp
-)
+/* Initialize write buffer */
+
+static void putc_init (putbuff* pb, FIL* fp)
{
- mem_set(pb, 0, sizeof (putbuff));
+ memset(pb, 0, sizeof (putbuff));
pb->fp = fp;
}
@@ -6387,8 +6764,131 @@ int f_puts ( /*-----------------------------------------------------------------------*/
-/* Put a Formatted String to the File */
+/* Put a Formatted String to the File (with sub-functions) */
/*-----------------------------------------------------------------------*/
+#if FF_PRINT_FLOAT && FF_INTDEF == 2
+#include <math.h>
+
+static int ilog10 (double n) /* Calculate log10(n) in integer output */
+{
+ int rv = 0;
+
+ while (n >= 10) { /* Decimate digit in right shift */
+ if (n >= 100000) {
+ n /= 100000; rv += 5;
+ } else {
+ n /= 10; rv++;
+ }
+ }
+ while (n < 1) { /* Decimate digit in left shift */
+ if (n < 0.00001) {
+ n *= 100000; rv -= 5;
+ } else {
+ n *= 10; rv--;
+ }
+ }
+ return rv;
+}
+
+
+static double i10x (int n) /* Calculate 10^n in integer input */
+{
+ double rv = 1;
+
+ while (n > 0) { /* Left shift */
+ if (n >= 5) {
+ rv *= 100000; n -= 5;
+ } else {
+ rv *= 10; n--;
+ }
+ }
+ while (n < 0) { /* Right shift */
+ if (n <= -5) {
+ rv /= 100000; n += 5;
+ } else {
+ rv /= 10; n++;
+ }
+ }
+ return rv;
+}
+
+
+static void ftoa (
+ char* buf, /* Buffer to output the floating point string */
+ double val, /* Value to output */
+ int prec, /* Number of fractional digits */
+ TCHAR fmt /* Notation */
+)
+{
+ int d;
+ int e = 0, m = 0;
+ char sign = 0;
+ double w;
+ const char *er = 0;
+ const char ds = FF_PRINT_FLOAT == 2 ? ',' : '.';
+
+
+ if (isnan(val)) { /* Not a number? */
+ er = "NaN";
+ } else {
+ if (prec < 0) prec = 6; /* Default precision? (6 fractional digits) */
+ if (val < 0) { /* Negative? */
+ val = 0 - val; sign = '-';
+ } else {
+ sign = '+';
+ }
+ if (isinf(val)) { /* Infinite? */
+ er = "INF";
+ } else {
+ if (fmt == 'f') { /* Decimal notation? */
+ val += i10x(0 - prec) / 2; /* Round (nearest) */
+ m = ilog10(val);
+ if (m < 0) m = 0;
+ if (m + prec + 3 >= SZ_NUM_BUF) er = "OV"; /* Buffer overflow? */
+ } else { /* E notation */
+ if (val != 0) { /* Not a true zero? */
+ val += i10x(ilog10(val) - prec) / 2; /* Round (nearest) */
+ e = ilog10(val);
+ if (e > 99 || prec + 7 >= SZ_NUM_BUF) { /* Buffer overflow or E > +99? */
+ er = "OV";
+ } else {
+ if (e < -99) e = -99;
+ val /= i10x(e); /* Normalize */
+ }
+ }
+ }
+ }
+ if (!er) { /* Not error condition */
+ if (sign == '-') *buf++ = sign; /* Add a - if negative value */
+ do { /* Put decimal number */
+ if (m == -1) *buf++ = ds; /* Insert a decimal separator when get into fractional part */
+ w = i10x(m); /* Snip the highest digit d */
+ d = (int)(val / w); val -= d * w;
+ *buf++ = (char)('0' + d); /* Put the digit */
+ } while (--m >= -prec); /* Output all digits specified by prec */
+ if (fmt != 'f') { /* Put exponent if needed */
+ *buf++ = (char)fmt;
+ if (e < 0) {
+ e = 0 - e; *buf++ = '-';
+ } else {
+ *buf++ = '+';
+ }
+ *buf++ = (char)('0' + e / 10);
+ *buf++ = (char)('0' + e % 10);
+ }
+ }
+ }
+ if (er) { /* Error condition */
+ if (sign) *buf++ = sign; /* Add sign if needed */
+ do { /* Put error symbol */
+ *buf++ = *er++;
+ } while (*er);
+ }
+ *buf = 0; /* Term */
+}
+#endif /* FF_PRINT_FLOAT && FF_INTDEF == 2 */
+
+
int f_printf (
FIL* fp, /* Pointer to the file object */
@@ -6398,10 +6898,17 @@ int f_printf ( {
va_list arp;
putbuff pb;
- BYTE f, r;
- UINT i, j, w;
+ UINT i, j, w, f, r;
+ int prec;
+#if FF_PRINT_LLI && FF_INTDEF == 2
+ QWORD v;
+#else
DWORD v;
- TCHAR c, d, str[32], *p;
+#endif
+ TCHAR *tp;
+ TCHAR tc, pad;
+ TCHAR nul = 0;
+ char d, str[SZ_NUM_BUF];
putc_init(&pb, fp);
@@ -6409,88 +6916,131 @@ int f_printf ( va_start(arp, fmt);
for (;;) {
- c = *fmt++;
- if (c == 0) break; /* End of string */
- if (c != '%') { /* Non escape character */
- putc_bfd(&pb, c);
+ tc = *fmt++;
+ if (tc == 0) break; /* End of format string */
+ if (tc != '%') { /* Not an escape character (pass-through) */
+ putc_bfd(&pb, tc);
continue;
}
- w = f = 0;
- c = *fmt++;
- if (c == '0') { /* Flag: '0' padding */
- f = 1; c = *fmt++;
- } else {
- if (c == '-') { /* Flag: left justified */
- f = 2; c = *fmt++;
- }
+ f = w = 0; pad = ' '; prec = -1; /* Initialize parms */
+ tc = *fmt++;
+ if (tc == '0') { /* Flag: '0' padded */
+ pad = '0'; tc = *fmt++;
+ } else if (tc == '-') { /* Flag: Left aligned */
+ f = 2; tc = *fmt++;
}
- if (c == '*') { /* Minimum width by argument */
+ if (tc == '*') { /* Minimum width from an argument */
w = va_arg(arp, int);
- c = *fmt++;
+ tc = *fmt++;
} else {
- while (IsDigit(c)) { /* Minimum width */
- w = w * 10 + c - '0';
- c = *fmt++;
- }
- }
- if (c == 'l' || c == 'L') { /* Type prefix: Size is long int */
- f |= 4; c = *fmt++;
- }
- if (c == 0) break;
- d = c;
- if (IsLower(d)) d -= 0x20;
- switch (d) { /* Atgument type is... */
- case 'S' : /* String */
- p = va_arg(arp, TCHAR*);
- for (j = 0; p[j]; j++) ;
- if (!(f & 2)) { /* Right padded */
- while (j++ < w) putc_bfd(&pb, ' ') ;
- }
- while (*p) putc_bfd(&pb, *p++) ; /* String body */
- while (j++ < w) putc_bfd(&pb, ' ') ; /* Left padded */
- continue;
-
- case 'C' : /* Character */
- putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue;
-
- case 'B' : /* Unsigned binary */
+ while (IsDigit(tc)) { /* Minimum width */
+ w = w * 10 + tc - '0';
+ tc = *fmt++;
+ }
+ }
+ if (tc == '.') { /* Precision */
+ tc = *fmt++;
+ if (tc == '*') { /* Precision from an argument */
+ prec = va_arg(arp, int);
+ tc = *fmt++;
+ } else {
+ prec = 0;
+ while (IsDigit(tc)) { /* Precision */
+ prec = prec * 10 + tc - '0';
+ tc = *fmt++;
+ }
+ }
+ }
+ if (tc == 'l') { /* Size: long int */
+ f |= 4; tc = *fmt++;
+#if FF_PRINT_LLI && FF_INTDEF == 2
+ if (tc == 'l') { /* Size: long long int */
+ f |= 8; tc = *fmt++;
+ }
+#endif
+ }
+ if (tc == 0) break; /* End of format string */
+ switch (tc) { /* Atgument type is... */
+ case 'b': /* Unsigned binary */
r = 2; break;
- case 'O' : /* Unsigned octal */
+ case 'o': /* Unsigned octal */
r = 8; break;
- case 'D' : /* Signed decimal */
- case 'U' : /* Unsigned decimal */
+ case 'd': /* Signed decimal */
+ case 'u': /* Unsigned decimal */
r = 10; break;
- case 'X' : /* Unsigned hexdecimal */
+ case 'x': /* Unsigned hexadecimal (lower case) */
+ case 'X': /* Unsigned hexadecimal (upper case) */
r = 16; break;
+ case 'c': /* Character */
+ putc_bfd(&pb, (TCHAR)va_arg(arp, int));
+ continue;
+
+ case 's': /* String */
+ tp = va_arg(arp, TCHAR*); /* Get a pointer argument */
+ if (!tp) tp = &nul; /* Null ptr generates a null string */
+ for (j = 0; tp[j]; j++) ; /* j = tcslen(tp) */
+ if (prec >= 0 && j > (UINT)prec) j = prec; /* Limited length of string body */
+ for ( ; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
+ while (*tp && prec--) putc_bfd(&pb, *tp++); /* Body */
+ while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
+ continue;
+#if FF_PRINT_FLOAT && FF_INTDEF == 2
+ case 'f': /* Floating point (decimal) */
+ case 'e': /* Floating point (e) */
+ case 'E': /* Floating point (E) */
+ ftoa(str, va_arg(arp, double), prec, tc); /* Make a floating point string */
+ for (j = strlen(str); !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
+ for (i = 0; str[i]; putc_bfd(&pb, str[i++])) ; /* Body */
+ while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
+ continue;
+#endif
default: /* Unknown type (pass-through) */
- putc_bfd(&pb, c); continue;
+ putc_bfd(&pb, tc); continue;
}
- /* Get an argument and put it in numeral */
- v = (f & 4) ? (DWORD)va_arg(arp, long) : ((d == 'D') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int));
- if (d == 'D' && (v & 0x80000000)) {
- v = 0 - v;
- f |= 8;
+ /* Get an integer argument and put it in numeral */
+#if FF_PRINT_LLI && FF_INTDEF == 2
+ if (f & 8) { /* long long argument? */
+ v = (QWORD)va_arg(arp, long long);
+ } else if (f & 4) { /* long argument? */
+ v = (tc == 'd') ? (QWORD)(long long)va_arg(arp, long) : (QWORD)va_arg(arp, unsigned long);
+ } else { /* int/short/char argument */
+ v = (tc == 'd') ? (QWORD)(long long)va_arg(arp, int) : (QWORD)va_arg(arp, unsigned int);
+ }
+ if (tc == 'd' && (v & 0x8000000000000000)) { /* Negative value? */
+ v = 0 - v; f |= 1;
+ }
+#else
+ if (f & 4) { /* long argument? */
+ v = (DWORD)va_arg(arp, long);
+ } else { /* int/short/char argument */
+ v = (tc == 'd') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int);
}
+ if (tc == 'd' && (v & 0x80000000)) { /* Negative value? */
+ v = 0 - v; f |= 1;
+ }
+#endif
i = 0;
- do {
- d = (TCHAR)(v % r); v /= r;
- if (d > 9) d += (c == 'x') ? 0x27 : 0x07;
+ do { /* Make an integer number string */
+ d = (char)(v % r); v /= r;
+ if (d > 9) d += (tc == 'x') ? 0x27 : 0x07;
str[i++] = d + '0';
- } while (v && i < sizeof str / sizeof *str);
- if (f & 8) str[i++] = '-';
- j = i; d = (f & 1) ? '0' : ' ';
- if (!(f & 2)) {
- while (j++ < w) putc_bfd(&pb, d); /* Right pad */
- }
- do {
- putc_bfd(&pb, str[--i]); /* Number body */
+ } while (v && i < SZ_NUM_BUF);
+ if (f & 1) str[i++] = '-'; /* Sign */
+ /* Write it */
+ for (j = i; !(f & 2) && j < w; j++) { /* Left pads */
+ putc_bfd(&pb, pad);
+ }
+ do { /* Body */
+ putc_bfd(&pb, (TCHAR)str[--i]);
} while (i);
- while (j++ < w) putc_bfd(&pb, d); /* Left pad */
+ while (j++ < w) { /* Right pads */
+ putc_bfd(&pb, ' ');
+ }
}
va_end(arp);
@@ -6512,13 +7062,13 @@ FRESULT f_setcp ( WORD cp /* Value to be set as active code page */
)
{
- static const WORD validcp[] = { 437, 720, 737, 771, 775, 850, 852, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0};
- static const BYTE* const tables[] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0};
+ static const WORD validcp[22] = { 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0};
+ static const BYTE *const tables[22] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct855, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0};
UINT i;
for (i = 0; validcp[i] != 0 && validcp[i] != cp; i++) ; /* Find the code page */
- if (validcp[i] != cp) return FR_INVALID_PARAMETER; /* Not found? */
+ if (validcp[i] != cp) return FR_INVALID_PARAMETER; /* Not found? */
CodePage = cp;
if (cp >= 900) { /* DBCS */
diff --git a/fatfs/source/ff.h b/fatfs/source/ff.h index 9fa1178..d88febc 100644 --- a/fatfs/source/ff.h +++ b/fatfs/source/ff.h @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/
-/ FatFs - Generic FAT Filesystem module R0.13b /
+/ FatFs - Generic FAT Filesystem module R0.15 /
/-----------------------------------------------------------------------------/
/
-/ Copyright (C) 2018, ChaN, all right reserved.
+/ Copyright (C) 2022, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
@@ -20,13 +20,12 @@ #ifndef FF_DEFINED
-#define FF_DEFINED 63463 /* Revision ID */
+#define FF_DEFINED 80286 /* Revision ID */
#ifdef __cplusplus
extern "C" {
#endif
-#include "integer.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
#if FF_DEFINED != FFCONF_DEF
@@ -34,29 +33,59 @@ extern "C" { #endif
+/* Integer types used for FatFs API */
+
+#if defined(_WIN32) /* Windows VC++ (for development only) */
+#define FF_INTDEF 2
+#include <windows.h>
+typedef unsigned __int64 QWORD;
+#include <float.h>
+#define isnan(v) _isnan(v)
+#define isinf(v) (!_finite(v))
+
+#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
+#define FF_INTDEF 2
+#include <stdint.h>
+typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
+typedef unsigned char BYTE; /* char must be 8-bit */
+typedef uint16_t WORD; /* 16-bit unsigned integer */
+typedef uint32_t DWORD; /* 32-bit unsigned integer */
+typedef uint64_t QWORD; /* 64-bit unsigned integer */
+typedef WORD WCHAR; /* UTF-16 character type */
+
+#else /* Earlier than C99 */
+#define FF_INTDEF 1
+typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
+typedef unsigned char BYTE; /* char must be 8-bit */
+typedef unsigned short WORD; /* 16-bit unsigned integer */
+typedef unsigned long DWORD; /* 32-bit unsigned integer */
+typedef WORD WCHAR; /* UTF-16 character type */
+#endif
-/* Definitions of volume management */
-#if FF_MULTI_PARTITION /* Multiple partition configuration */
-typedef struct {
- BYTE pd; /* Physical drive number */
- BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
-} PARTITION;
-extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
-#endif
+/* Type of file size and LBA variables */
-#if FF_STR_VOLUME_ID
-#ifndef FF_VOLUME_STRS
-extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
+#if FF_FS_EXFAT
+#if FF_INTDEF != 2
+#error exFAT feature wants C99 or later
#endif
+typedef QWORD FSIZE_t;
+#if FF_LBA64
+typedef QWORD LBA_t;
+#else
+typedef DWORD LBA_t;
+#endif
+#else
+#if FF_LBA64
+#error exFAT needs to be enabled when enable 64-bit LBA
+#endif
+typedef DWORD FSIZE_t;
+typedef DWORD LBA_t;
#endif
-/* Type of path name strings on FatFs API */
-
-#ifndef _INC_TCHAR
-#define _INC_TCHAR
+/* Type of path name strings on FatFs API (TCHAR) */
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
typedef WCHAR TCHAR;
@@ -78,16 +107,22 @@ typedef char TCHAR; #define _TEXT(x) x
#endif
-#endif
+/* Definitions of volume management */
-/* Type of file size variables */
+#if FF_MULTI_PARTITION /* Multiple partition configuration */
+typedef struct {
+ BYTE pd; /* Physical drive number */
+ BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
+} PARTITION;
+extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
+#endif
-#if FF_FS_EXFAT
-typedef QWORD FSIZE_t;
-#else
-typedef DWORD FSIZE_t;
+#if FF_STR_VOLUME_ID
+#ifndef FF_VOLUME_STRS
+extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
+#endif
#endif
@@ -95,11 +130,12 @@ typedef DWORD FSIZE_t; /* Filesystem object structure (FATFS) */
typedef struct {
- BYTE fs_type; /* Filesystem type (0:N/A) */
- BYTE pdrv; /* Physical drive number */
+ BYTE fs_type; /* Filesystem type (0:not mounted) */
+ BYTE pdrv; /* Volume hosting physical drive */
+ BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
BYTE n_fats; /* Number of FATs (1 or 2) */
- BYTE wflag; /* win[] flag (b0:dirty) */
- BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
+ BYTE wflag; /* win[] status (b0:dirty) */
+ BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */
WORD id; /* Volume mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */
@@ -112,9 +148,6 @@ typedef struct { #if FF_FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
#endif
-#if FF_FS_REENTRANT
- FF_SYNC_t sobj; /* Identifier of sync object */
-#endif
#if !FF_FS_READONLY
DWORD last_clst; /* Last allocated cluster */
DWORD free_clst; /* Number of free clusters */
@@ -128,12 +161,15 @@ typedef struct { #endif
#endif
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
- DWORD fsize; /* Size of an FAT [sectors] */
- DWORD volbase; /* Volume base sector */
- DWORD fatbase; /* FAT base sector */
- DWORD dirbase; /* Root directory base sector/cluster */
- DWORD database; /* Data base sector */
- DWORD winsect; /* Current sector appearing in the win[] */
+ DWORD fsize; /* Number of sectors per FAT */
+ LBA_t volbase; /* Volume base sector */
+ LBA_t fatbase; /* FAT base sector */
+ LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
+ LBA_t database; /* Data base sector */
+#if FF_FS_EXFAT
+ LBA_t bitbase; /* Allocation bitmap base sector */
+#endif
+ LBA_t winsect; /* Current sector appearing in the win[] */
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS;
@@ -143,9 +179,9 @@ typedef struct { typedef struct {
FATFS* fs; /* Pointer to the hosting volume of this object */
- WORD id; /* Hosting volume mount ID */
+ WORD id; /* Hosting volume's mount ID */
BYTE attr; /* Object attribute */
- BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:flagmented in this session, b2:sub-directory stretched) */
+ BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
#if FF_FS_EXFAT
@@ -170,9 +206,9 @@ typedef struct { BYTE err; /* Abort flag (error code) */
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
- DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
+ LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
#if !FF_FS_READONLY
- DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
+ LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
#endif
#if FF_USE_FASTSEEK
@@ -191,7 +227,7 @@ typedef struct { FFOBJID obj; /* Object identifier */
DWORD dptr; /* Current read/write offset */
DWORD clust; /* Current cluster */
- DWORD sect; /* Current sector (0:Read operation has terminated) */
+ LBA_t sect; /* Current sector (0:Read operation has terminated) */
BYTE* dir; /* Pointer to the directory item in the win[] */
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
#if FF_USE_LFN
@@ -212,7 +248,7 @@ typedef struct { WORD ftime; /* Modified time */
BYTE fattrib; /* File attribute */
#if FF_USE_LFN
- TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
+ TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
#else
TCHAR fname[12 + 1]; /* File name */
@@ -221,6 +257,18 @@ typedef struct { +/* Format parameter structure (MKFS_PARM) */
+
+typedef struct {
+ BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
+ BYTE n_fat; /* Number of FATs */
+ UINT align; /* Data area alignment (sector) */
+ UINT n_root; /* Number of root directory entries */
+ DWORD au_size; /* Cluster size (byte) */
+} MKFS_PARM;
+
+
+
/* File function return code (FRESULT) */
typedef enum {
@@ -248,8 +296,10 @@ typedef enum { +
+/*--------------------------------------------------------------*/
+/* FatFs Module Application Interface */
/*--------------------------------------------------------------*/
-/* FatFs module application interface */
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_close (FIL* fp); /* Close an open file object */
@@ -276,16 +326,18 @@ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get numbe FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
-FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
+FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
-FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
-FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
+FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
+FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
FRESULT f_setcp (WORD cp); /* Set current code page */
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
+/* Some API fucntions are implemented as macro */
+
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
@@ -295,46 +347,47 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil #define f_rmdir(path) f_unlink(path)
#define f_unmount(path) f_mount(0, path, 0)
-#ifndef EOF
-#define EOF (-1)
-#endif
-
/*--------------------------------------------------------------*/
-/* Additional user defined functions */
+/* Additional Functions */
+/*--------------------------------------------------------------*/
-/* RTC function */
+/* RTC function (provided by user) */
#if !FF_FS_READONLY && !FF_FS_NORTC
-DWORD get_fattime (void);
+DWORD get_fattime (void); /* Get current time */
#endif
-/* LFN support functions */
-#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
+
+/* LFN support functions (defined in ffunicode.c) */
+
+#if FF_USE_LFN >= 1
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
#endif
-#if FF_USE_LFN == 3 /* Dynamic memory allocation */
-void* ff_memalloc (UINT msize); /* Allocate memory block */
-void ff_memfree (void* mblock); /* Free memory block */
-#endif
-/* Sync functions */
-#if FF_FS_REENTRANT
-int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
-int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
-void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
-int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
+
+/* O/S dependent functions (samples available in ffsystem.c) */
+
+#if FF_USE_LFN == 3 /* Dynamic memory allocation */
+void* ff_memalloc (UINT msize); /* Allocate memory block */
+void ff_memfree (void* mblock); /* Free memory block */
+#endif
+#if FF_FS_REENTRANT /* Sync functions */
+int ff_mutex_create (int vol); /* Create a sync object */
+void ff_mutex_delete (int vol); /* Delete a sync object */
+int ff_mutex_take (int vol); /* Lock sync object */
+void ff_mutex_give (int vol); /* Unlock sync object */
#endif
/*--------------------------------------------------------------*/
-/* Flags and offset address */
-
+/* Flags and Offset Address */
+/*--------------------------------------------------------------*/
/* File access mode and open method flags (3rd argument of f_open) */
#define FA_READ 0x01
diff --git a/fatfs/source/ffconf.h b/fatfs/source/ffconf.h index fe582ce..46abe70 100644 --- a/fatfs/source/ffconf.h +++ b/fatfs/source/ffconf.h @@ -1,8 +1,8 @@ /*---------------------------------------------------------------------------/
-/ FatFs - Configuration file
+/ Configurations of FatFs Module
/---------------------------------------------------------------------------*/
-#define FFCONF_DEF 63463 /* Revision ID */
+#define FFCONF_DEF 80286 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function Configurations
@@ -25,14 +25,6 @@ / 3: f_lseek() function is removed in addition to 2. */
-#define FF_USE_STRFUNC 0
-/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
-/
-/ 0: Disable string functions.
-/ 1: Enable without LF-CRLF conversion.
-/ 2: Enable with LF-CRLF conversion. */
-
-
#define FF_USE_FIND 0
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
@@ -64,6 +56,30 @@ /* This option switches f_forward() function. (0:Disable or 1:Enable) */
+#define FF_USE_STRFUNC 0
+#define FF_PRINT_LLI 1
+#define FF_PRINT_FLOAT 1
+#define FF_STRF_ENCODE 3
+/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
+/ f_printf().
+/
+/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
+/ 1: Enable without LF-CRLF conversion.
+/ 2: Enable with LF-CRLF conversion.
+/
+/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
+/ makes f_printf() support floating point argument. These features want C99 or later.
+/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
+/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
+/ to be read/written via those functions.
+/
+/ 0: ANSI/OEM in current CP
+/ 1: Unicode in UTF-16LE
+/ 2: Unicode in UTF-16BE
+/ 3: Unicode in UTF-8
+*/
+
+
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
@@ -102,7 +118,7 @@ /* The FF_USE_LFN switches the support for LFN (long file name).
/
/ 0: Disable LFN. FF_MAX_LFN has no effect.
-/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
+/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
@@ -110,11 +126,11 @@ / requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
-/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
+/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
/ specification.
/ When use stack for the working buffer, take care on stack overflow. When use heap
/ memory for the working buffer, memory management functions, ff_memalloc() and
-/ ff_memfree() in ffsystem.c, need to be added to the project. */
+/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
#define FF_LFN_UNICODE 0
@@ -137,19 +153,6 @@ / on character encoding. When LFN is not enabled, these options have no effect. */
-#define FF_STRF_ENCODE 3
-/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
-/ f_putc(), f_puts and f_printf() convert the character encoding in it.
-/ This option selects assumption of character encoding ON THE FILE to be
-/ read/written via those functions.
-/
-/ 0: ANSI/OEM in current CP
-/ 1: Unicode in UTF-16LE
-/ 2: Unicode in UTF-16BE
-/ 3: Unicode in UTF-8
-*/
-
-
#define FF_FS_RPATH 0
/* This option configures support for relative path.
/
@@ -175,7 +178,7 @@ / logical drives. Number of items must not be less than FF_VOLUMES. Valid
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
-/ not defined, a user defined volume string table needs to be defined as:
+/ not defined, a user defined volume string table is needed as:
/
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/
@@ -187,37 +190,35 @@ / number and only an FAT volume found on the physical drive will be mounted.
/ When this function is enabled (1), each logical drive number can be bound to
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
-/ funciton will be available. */
+/ function will be available. */
#define FF_MIN_SS 512
#define FF_MAX_SS 512
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
-/ harddisk. But a larger value may be required for on-board flash memory and some
+/ harddisk, but a larger value may be required for on-board flash memory and some
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
/ for variable sector size mode and disk_ioctl() function needs to implement
/ GET_SECTOR_SIZE command. */
+#define FF_LBA64 0
+/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
+/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
+
+
+#define FF_MIN_GPT 0x10000000
+/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
+/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
+
+
#define FF_USE_TRIM 0
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */
-#define FF_FS_NOFSINFO 0
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/ option, and f_getfree() function at first time after volume mount will force
-/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
-/
-/ bit0=0: Use free cluster count in the FSINFO if available.
-/ bit0=1: Do not trust free cluster count in the FSINFO.
-/ bit1=0: Use last allocated cluster number in the FSINFO if available.
-/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
-*/
-
-
/*---------------------------------------------------------------------------/
/ System Configurations
@@ -232,22 +233,34 @@ #define FF_FS_EXFAT 0
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
-/ To enable exFAT, also LFN needs to be enabled.
+/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
#define FF_FS_NORTC 0
#define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1
-#define FF_NORTC_YEAR 2018
-/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
-/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
-/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
+#define FF_NORTC_YEAR 2022
+/* The option FF_FS_NORTC switches timestamp feature. If the system does not have
+/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the
+/ timestamp feature. Every object modified by FatFs will have a fixed timestamp
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
-/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
+/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
+
+
+#define FF_FS_NOFSINFO 0
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
+/ option, and f_getfree() function at the first time after volume mount will force
+/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
+/
+/ bit0=0: Use free cluster count in the FSINFO if available.
+/ bit0=1: Do not trust free cluster count in the FSINFO.
+/ bit1=0: Use last allocated cluster number in the FSINFO if available.
+/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
+*/
#define FF_FS_LOCK 0
@@ -264,25 +277,19 @@ #define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000
-#define FF_SYNC_t HANDLE
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
-/ to the same volume is under control of this function.
+/ to the same volume is under control of this featuer.
/
-/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
+/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
-/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/ function, must be added to the project. Samples are available in
-/ option/syscall.c.
+/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give()
+/ function, must be added to the project. Samples are available in ffsystem.c.
/
-/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
-/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
-/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
-/ included somewhere in the scope of ff.h. */
-
-/* #include <windows.h> // O/S definitions */
+/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick.
+*/
diff --git a/fatfs/source/ffsystem.c b/fatfs/source/ffsystem.c index 2baf922..2657fe2 100644 --- a/fatfs/source/ffsystem.c +++ b/fatfs/source/ffsystem.c @@ -1,171 +1,208 @@ /*------------------------------------------------------------------------*/
-/* Sample Code of OS Dependent Functions for FatFs */
-/* (C)ChaN, 2017 */
+/* A Sample Code of User Provided OS Dependent Functions for FatFs */
/*------------------------------------------------------------------------*/
-
#include "ff.h"
-
-#if FF_USE_LFN == 3 /* Dynamic memory allocation */
+#if FF_USE_LFN == 3 /* Use dynamic memory allocation */
/*------------------------------------------------------------------------*/
-/* Allocate a memory block */
+/* Allocate/Free a Memory Block */
/*------------------------------------------------------------------------*/
-void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
+#include <stdlib.h> /* with POSIX API */
+
+
+void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
- return malloc(msize); /* Allocate a new memory block with POSIX API */
+ return malloc((size_t)msize); /* Allocate a new memory block */
}
-/*------------------------------------------------------------------------*/
-/* Free a memory block */
-/*------------------------------------------------------------------------*/
-
void ff_memfree (
- void* mblock /* Pointer to the memory block to free (nothing to do for null) */
+ void* mblock /* Pointer to the memory block to free (no effect if null) */
)
{
- free(mblock); /* Free the memory block with POSIX API */
+ free(mblock); /* Free the memory block */
}
#endif
-#if FF_FS_REENTRANT /* Mutal exclusion */
+#if FF_FS_REENTRANT /* Mutal exclusion */
/*------------------------------------------------------------------------*/
-/* Create a Synchronization Object */
+/* Definitions of Mutex */
/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to create a new
-/ synchronization object for the volume, such as semaphore and mutex.
-/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
-*/
-//const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */
+#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
+
+#if OS_TYPE == 0 /* Win32 */
+#include <windows.h>
+static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
+
+#elif OS_TYPE == 1 /* uITRON */
+#include "itron.h"
+#include "kernel.h"
+static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
+
+#elif OS_TYPE == 2 /* uc/OS-II */
+#include "includes.h"
+static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
+
+#elif OS_TYPE == 3 /* FreeRTOS */
+#include "FreeRTOS.h"
+#include "semphr.h"
+static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
+
+#elif OS_TYPE == 4 /* CMSIS-RTOS */
+#include "cmsis_os.h"
+static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
+
+#endif
+
+
+
+/*------------------------------------------------------------------------*/
+/* Create a Mutex */
+/*------------------------------------------------------------------------*/
+/* This function is called in f_mount function to create a new mutex
+/ or semaphore for the volume. When a 0 is returned, the f_mount function
+/ fails with FR_INT_ERR.
+*/
-int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
- BYTE vol, /* Corresponding volume (logical drive number) */
- FF_SYNC_t* sobj /* Pointer to return the created sync object */
+int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
+ int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
- /* Win32 */
- *sobj = CreateMutex(NULL, FALSE, NULL);
- return (int)(*sobj != INVALID_HANDLE_VALUE);
-
- /* uITRON */
-// T_CSEM csem = {TA_TPRI,1,1};
-// *sobj = acre_sem(&csem);
-// return (int)(*sobj > 0);
-
- /* uC/OS-II */
-// OS_ERR err;
-// *sobj = OSMutexCreate(0, &err);
-// return (int)(err == OS_NO_ERR);
-
- /* FreeRTOS */
-// *sobj = xSemaphoreCreateMutex();
-// return (int)(*sobj != NULL);
-
- /* CMSIS-RTOS */
-// *sobj = osMutexCreate(Mutex + vol);
-// return (int)(*sobj != NULL);
+#if OS_TYPE == 0 /* Win32 */
+ Mutex[vol] = CreateMutex(NULL, FALSE, NULL);
+ return (int)(Mutex[vol] != INVALID_HANDLE_VALUE);
+
+#elif OS_TYPE == 1 /* uITRON */
+ T_CMTX cmtx = {TA_TPRI,1};
+
+ Mutex[vol] = acre_mtx(&cmtx);
+ return (int)(Mutex[vol] > 0);
+
+#elif OS_TYPE == 2 /* uC/OS-II */
+ OS_ERR err;
+
+ Mutex[vol] = OSMutexCreate(0, &err);
+ return (int)(err == OS_NO_ERR);
+
+#elif OS_TYPE == 3 /* FreeRTOS */
+ Mutex[vol] = xSemaphoreCreateMutex();
+ return (int)(Mutex[vol] != NULL);
+
+#elif OS_TYPE == 4 /* CMSIS-RTOS */
+ osMutexDef(cmsis_os_mutex);
+
+ Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
+ return (int)(Mutex[vol] != NULL);
+
+#endif
}
/*------------------------------------------------------------------------*/
-/* Delete a Synchronization Object */
+/* Delete a Mutex */
/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to delete a synchronization
-/ object that created with ff_cre_syncobj() function. When a 0 is returned,
-/ the f_mount() function fails with FR_INT_ERR.
+/* This function is called in f_mount function to delete a mutex or
+/ semaphore of the volume created with ff_mutex_create function.
*/
-int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
- FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
+void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
+ int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
- /* Win32 */
- return (int)CloseHandle(sobj);
+#if OS_TYPE == 0 /* Win32 */
+ CloseHandle(Mutex[vol]);
- /* uITRON */
-// return (int)(del_sem(sobj) == E_OK);
+#elif OS_TYPE == 1 /* uITRON */
+ del_mtx(Mutex[vol]);
- /* uC/OS-II */
-// OS_ERR err;
-// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
-// return (int)(err == OS_NO_ERR);
+#elif OS_TYPE == 2 /* uC/OS-II */
+ OS_ERR err;
- /* FreeRTOS */
-// vSemaphoreDelete(sobj);
-// return 1;
+ OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err);
- /* CMSIS-RTOS */
-// return (int)(osMutexDelete(sobj) == osOK);
+#elif OS_TYPE == 3 /* FreeRTOS */
+ vSemaphoreDelete(Mutex[vol]);
+
+#elif OS_TYPE == 4 /* CMSIS-RTOS */
+ osMutexDelete(Mutex[vol]);
+
+#endif
}
/*------------------------------------------------------------------------*/
-/* Request Grant to Access the Volume */
+/* Request a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
-/* This function is called on entering file functions to lock the volume.
+/* This function is called on enter file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/
-int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
- FF_SYNC_t sobj /* Sync object to wait */
+int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
+ int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
- /* Win32 */
- return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
+#if OS_TYPE == 0 /* Win32 */
+ return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0);
+
+#elif OS_TYPE == 1 /* uITRON */
+ return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK);
+
+#elif OS_TYPE == 2 /* uC/OS-II */
+ OS_ERR err;
- /* uITRON */
-// return (int)(wai_sem(sobj) == E_OK);
+ OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err));
+ return (int)(err == OS_NO_ERR);
- /* uC/OS-II */
-// OS_ERR err;
-// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
-// return (int)(err == OS_NO_ERR);
+#elif OS_TYPE == 3 /* FreeRTOS */
+ return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE);
- /* FreeRTOS */
-// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
+#elif OS_TYPE == 4 /* CMSIS-RTOS */
+ return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
- /* CMSIS-RTOS */
-// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
+#endif
}
+
/*------------------------------------------------------------------------*/
-/* Release Grant to Access the Volume */
+/* Release a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
-/* This function is called on leaving file functions to unlock the volume.
+/* This function is called on leave file functions to unlock the volume.
*/
-void ff_rel_grant (
- FF_SYNC_t sobj /* Sync object to be signaled */
+void ff_mutex_give (
+ int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
- /* Win32 */
- ReleaseMutex(sobj);
+#if OS_TYPE == 0 /* Win32 */
+ ReleaseMutex(Mutex[vol]);
- /* uITRON */
-// sig_sem(sobj);
+#elif OS_TYPE == 1 /* uITRON */
+ unl_mtx(Mutex[vol]);
- /* uC/OS-II */
-// OSMutexPost(sobj);
+#elif OS_TYPE == 2 /* uC/OS-II */
+ OSMutexPost(Mutex[vol]);
- /* FreeRTOS */
-// xSemaphoreGive(sobj);
+#elif OS_TYPE == 3 /* FreeRTOS */
+ xSemaphoreGive(Mutex[vol]);
- /* CMSIS-RTOS */
-// osMutexRelease(sobj);
-}
+#elif OS_TYPE == 4 /* CMSIS-RTOS */
+ osMutexRelease(Mutex[vol]);
#endif
+}
+
+#endif /* FF_FS_REENTRANT */
diff --git a/fatfs/source/ffunicode.c b/fatfs/source/ffunicode.c index 7b4b996..54ad526 100644 --- a/fatfs/source/ffunicode.c +++ b/fatfs/source/ffunicode.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------*/
-/* Unicode handling functions for FatFs R0.13b */
+/* Unicode Handling Functions for FatFs R0.13 and Later */
+/*------------------------------------------------------------------------*/
+/* This module will occupy a huge memory in the .rodata section when the */
+/* FatFs is configured for LFN with DBCS. If the system has a Unicode */
+/* library for the code conversion, this module should be modified to use */
+/* it to avoid silly memory consumption. */
/*------------------------------------------------------------------------*/
-/* This module will occupy a huge memory in the .const section when the /
-/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
-/ utilitiy for the code conversion, this module should be modified to use /
-/ that function to avoid silly memory consumption. /
-/-------------------------------------------------------------------------*/
/*
-/ Copyright (C) 2018, ChaN, all right reserved.
+/ Copyright (C) 2022, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
@@ -25,11 +25,7 @@ #include "ff.h"
-#if FF_USE_LFN /* This module is blanked when non-LFN configuration */
-
-#if FF_DEFINED != 63463 /* Revision ID */
-#error Wrong include file (ff.h).
-#endif
+#if FF_USE_LFN != 0 /* This module will be blanked if in non-LFN configuration */
#define MERGE2(a, b) a ## b
#define CVTBL(tbl, cp) MERGE2(tbl, cp)
@@ -15218,8 +15214,8 @@ static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */ /*------------------------------------------------------------------------*/
-/* OEM <==> Unicode conversions for static code page configuration */
-/* SBCS fixed code page */
+/* OEM <==> Unicode Conversions for Static Code Page Configuration with */
+/* SBCS Fixed Code Page */
/*------------------------------------------------------------------------*/
#if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900
@@ -15229,7 +15225,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ )
{
WCHAR c = 0;
- const WCHAR *p = CVTBL(uc, FF_CODE_PAGE);
+ const WCHAR* p = CVTBL(uc, FF_CODE_PAGE);
if (uni < 0x80) { /* ASCII? */
@@ -15245,13 +15241,13 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ return c;
}
-WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
+WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
WCHAR oem, /* OEM code to be converted */
WORD cp /* Code page for the conversion */
)
{
WCHAR c = 0;
- const WCHAR *p = CVTBL(uc, FF_CODE_PAGE);
+ const WCHAR* p = CVTBL(uc, FF_CODE_PAGE);
if (oem < 0x80) { /* ASCII? */
@@ -15271,8 +15267,8 @@ WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ /*------------------------------------------------------------------------*/
-/* OEM <==> Unicode conversions for static code page configuration */
-/* DBCS fixed code page */
+/* OEM <==> Unicode Conversions for Static Code Page Configuration with */
+/* DBCS Fixed Code Page */
/*------------------------------------------------------------------------*/
#if FF_CODE_PAGE >= 900
@@ -15281,7 +15277,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ WORD cp /* Code page for the conversion */
)
{
- const WCHAR *p;
+ const WCHAR* p;
WCHAR c = 0, uc;
UINT i = 0, n, li, hi;
@@ -15312,12 +15308,12 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ }
-WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
+WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
WCHAR oem, /* OEM code to be converted */
WORD cp /* Code page for the conversion */
)
{
- const WCHAR *p;
+ const WCHAR* p;
WCHAR c = 0;
UINT i = 0, n, li, hi;
@@ -15350,7 +15346,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ /*------------------------------------------------------------------------*/
-/* OEM <==> Unicode conversions for dynamic code page configuration */
+/* OEM <==> Unicode Conversions for Dynamic Code Page Configuration */
/*------------------------------------------------------------------------*/
#if FF_CODE_PAGE == 0
@@ -15364,7 +15360,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ WORD cp /* Code page for the conversion */
)
{
- const WCHAR *p;
+ const WCHAR* p;
WCHAR c = 0, uc;
UINT i, n, li, hi;
@@ -15411,12 +15407,12 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ }
-WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
+WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
WCHAR oem, /* OEM code to be converted (DBC if >=0x100) */
WORD cp /* Code page for the conversion */
)
{
- const WCHAR *p;
+ const WCHAR* p;
WCHAR c = 0;
UINT i, n, li, hi;
@@ -15462,14 +15458,14 @@ WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */ /*------------------------------------------------------------------------*/
-/* Unicode up-case conversion */
+/* Unicode Up-case Conversion */
/*------------------------------------------------------------------------*/
DWORD ff_wtoupper ( /* Returns up-converted code point */
DWORD uni /* Unicode code point to be up-converted */
)
{
- const WORD *p;
+ const WORD* p;
WORD uc, bc, nc, cmd;
static const WORD cvt1[] = { /* Compressed up conversion table for U+0000 - U+0FFF */
/* Basic Latin */
@@ -15594,4 +15590,4 @@ DWORD ff_wtoupper ( /* Returns up-converted code point */ }
-#endif /* #if FF_USE_LFN */
+#endif /* #if FF_USE_LFN != 0 */
diff --git a/fatfs/source/integer.h b/fatfs/source/integer.h deleted file mode 100644 index f55a7c6..0000000 --- a/fatfs/source/integer.h +++ /dev/null @@ -1,36 +0,0 @@ -/*-------------------------------------------*/
-/* Integer type definitions for FatFs module */
-/*-------------------------------------------*/
-
-#ifndef FF_INTEGER
-#define FF_INTEGER
-
-#ifdef _WIN32 /* FatFs development platform */
-
-#include <windows.h>
-typedef unsigned __int64 QWORD;
-
-#else /* Embedded platform */
-
-/* These types MUST be 16-bit or 32-bit */
-typedef int INT;
-typedef unsigned int UINT;
-
-/* This type MUST be 8-bit */
-typedef unsigned char BYTE;
-
-/* These types MUST be 16-bit */
-typedef short SHORT;
-typedef unsigned short WORD;
-typedef unsigned short WCHAR;
-
-/* These types MUST be 32-bit */
-typedef long LONG;
-typedef unsigned long DWORD;
-
-/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
-typedef unsigned long long QWORD;
-
-#endif
-
-#endif
|