fatfs v0.12a July 10, 2016:
- Added support for creating exFAT volume with some changes of f_mkfs(). - Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed. - f_forward() is available regardless of _FS_TINY. - Fixed f_mkfs() creates wrong volume. - Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD. - Fixed wrong memory read in create_name().
@ -18,14 +18,14 @@
|
||||
<hr>
|
||||
|
||||
<div class="abst">
|
||||
<img src="img/layers.png" class="rset" width="245" height="255" alt="layer">
|
||||
<p>FatFs is a generic FAT file system module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk I/O layer. Therefore it is independent of the platform. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, 78K and etc. Also Petit FatFs module for tiny microcontrollers is available <a href="http://elm-chan.org/fsw/ff/00index_p.html">here</a>.</p>
|
||||
<img src="res/layers.png" class="rset" width="245" height="255" alt="layer">
|
||||
<p>FatFs is a generic FAT/exFAT file system module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk I/O layer. Therefore it is independent of the platform. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, 78K and etc. Also Petit FatFs module for tiny microcontrollers is available <a href="http://elm-chan.org/fsw/ff/00index_p.html">here</a>.</p>
|
||||
|
||||
<h4>Features</h4>
|
||||
<ul>
|
||||
<li>Windows compatible FAT/exFAT file system.</li>
|
||||
<li>Platform independent. Easy to port.</li>
|
||||
<li>Very small footprint for code and work area.</li>
|
||||
<li>Very small footprint for program code and work area.</li>
|
||||
<li>Various <a href="en/config.html">configuration options</a> to support for:
|
||||
<ul>
|
||||
<li>Multiple volumes (physical drives and partitions).</li>
|
||||
@ -43,7 +43,7 @@
|
||||
|
||||
<div class="para">
|
||||
<h3>Application Interface</h3>
|
||||
<img src="img/layers1.png" class="rset" width="245" height="220" alt="layer">
|
||||
<img src="res/layers1.png" class="rset" width="245" height="220" alt="layer">
|
||||
<ul>
|
||||
<li>File Access
|
||||
<ul>
|
||||
@ -104,7 +104,7 @@
|
||||
|
||||
<div class="para">
|
||||
<h3>Device Control Interface</h3>
|
||||
<img src="img/layers2.png" class="rset" width="245" height="220" alt="layer">
|
||||
<img src="res/layers2.png" class="rset" width="245" height="220" alt="layer">
|
||||
<p>Since the FatFs module is a file system layer, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. FatFs accesses the storage devices via a simple interface shown below. The low level device control module is <em>not a part of FatFs module</em>. It is provided by implementer. Also sample implementations for some platforms are available in the downloads.</p>
|
||||
<ul>
|
||||
<li><a href="en/dstat.html">disk_status</a> - Get device status</li>
|
||||
@ -121,25 +121,21 @@
|
||||
<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>
|
||||
<ul>
|
||||
<li>Read first: <a href="en/appnote.html">FatFs module application note</a> <span class="mfd">April 12, 2016</span></li>
|
||||
<li>Download: <a href="ff12.zip">FatFs R0.12</a> | <a href="updates.txt">Updates</a> | <a href="patches.html">Patches</a> <span class="mfd">April 12, 2016</span></li>
|
||||
<li>Download: <a href="ffsample.zip">FatFs sample projects for various platforms</a> <span class="mfd">April 12, 2016</span></li>
|
||||
<li>Download: <a href="archives.html">Old Releases</a></li>
|
||||
<li>Read first: <a href="en/appnote.html">FatFs module application note</a></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 file system)</li>
|
||||
<li><a href="http://elm-chan.org/docs/fat.html">The basics of FAT file system [ja]</a></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://stm32f4-discovery.com/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="http://nemuisan.blog.bai.ne.jp/">Nemuisan's Blog</a>↗ (Well written implementations for STM32F/SDIO and LPC2300/MCI)</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://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/index.html">ARM-Projects by Martin THOMAS</a>↗ (Examples for LPC2000, AT91SAM and STM32)</li>
|
||||
<li><a href="img/rwtest1.png">Benchmark 1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li>
|
||||
<li><a href="img/rwtest2.png">Benchmark 2</a> (LPC2368/72MHz with MMC via MCI)</li>
|
||||
<li><a href="rc/fd.mp4">Demo movie of an application</a> (this project is in ffsample.zip/lpc23xx)</li></ul>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
||||
<hr>
|
||||
<p class="foot"><a href="../../fsw_e.html">Return</a></p>
|
||||
<p class="foot"><a href="http://elm-chan.org/fsw/ff/00index_e.html">Latest Information</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
<hr>
|
||||
|
||||
<div class="abst">
|
||||
<img src="img/layers.png" class="rset" width="245" height="255" alt="layer">
|
||||
<p>FatFsは小規模な組み込みシステム向けの汎用FATファイルシステム モジュールです。ANSI C(C89)準拠でハードウェア アーキテクチャには依存しないので、必要なワーク エリアが確保できれば、8051, PIC, AVR, SH, Z80, 68k, H8, ARMなど安価なマイコンでも使用可能です。このほか、FatFsを極小マイコン向けにシュリンクした<a href="http://elm-chan.org/fsw/ff/00index_p.html">ぷちFatFs</a>もあります。</p>
|
||||
<img src="res/layers.png" class="rset" width="245" height="255" alt="layer">
|
||||
<p>FatFsは小規模な組み込みシステム向けの汎用FAT/exFATファイルシステム モジュールです。ANSI C(C89)準拠でハードウェア アーキテクチャには依存しないので、必要なワーク エリアが確保できれば、8051, PIC, AVR, SH, Z80, 68k, H8, ARMなど安価なマイコンでも使用可能です。このほか、FatFsを極小マイコン向けにシュリンクした<a href="http://elm-chan.org/fsw/ff/00index_p.html">ぷちFatFs</a>もあります。</p>
|
||||
<h4>FatFsモジュールの特徴</h4>
|
||||
<ul>
|
||||
<li>Windows互換 FAT/exFATファイルシステム</li>
|
||||
@ -42,7 +42,7 @@
|
||||
|
||||
<div class="para">
|
||||
<h3>上位レイヤ インターフェース</h3>
|
||||
<img src="img/layers1.png" class="rset" width="245" height="220" alt="layer">
|
||||
<img src="res/layers1.png" class="rset" width="245" height="220" alt="layer">
|
||||
<ul>
|
||||
<li>ファイル アクセス
|
||||
<ul>
|
||||
@ -103,8 +103,8 @@
|
||||
|
||||
<div class="para">
|
||||
<h3>下位レイヤ インターフェース</h3>
|
||||
<img src="img/layers2.png" class="rset" width="245" height="220" alt="layer">
|
||||
<p>FatFsモジュールは、単なるファイル システム レイヤなので、その下位に当たるストレージ デバイス制御レイヤは含まれません。プラットフォームやストレージ デバイスに対応した制御レイヤは、インプリメンタによって提供される必要があります。FatFsモジュールは、下位レイヤに対し標準的には次のインターフェースを要求します。一部の拡張機能、たとえばOS関連機能を有効にしたときは、加えてプロセス/メモリ操作関数なども必要になります。サンプル プロジェクトに下位レイヤの実装例を示します。</p>
|
||||
<img src="res/layers2.png" class="rset" width="245" height="220" alt="layer">
|
||||
<p>FatFsモジュールは、単なるファイルシステム レイヤなので、その下位のストレージ デバイス制御レイヤはそれに含まれません。それぞれのプラットフォームやストレージ デバイスに対応した制御レイヤは、インプリメンタによって提供される必要があります。FatFsモジュールは、下位レイヤに対し標準的には次のインターフェースを要求します。一部の拡張機能、たとえばOS関連機能を有効にしたときは、加えてプロセス/メモリ操作関数なども必要になります。サンプル プロジェクトに下位レイヤの実装例を示します。</p>
|
||||
<ul>
|
||||
<li><a href="ja/dstat.html">disk_status</a> - デバイスの状態取得</li>
|
||||
<li><a href="ja/dinit.html">disk_initialize</a> - デバイスの初期化</li>
|
||||
@ -120,26 +120,22 @@
|
||||
<h3>資料</h3>
|
||||
<p>FatFsモジュールはフリー ソフトウェアとして教育・研究・開発用に公開しています。どのような利用目的(個人利用から商用まで)でも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。詳しくはアプリケーション ノートを参照してください。</p>
|
||||
<ul>
|
||||
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール アプリケーション ノート</a> <span class="mfd">2016. 4. 12</span></li>
|
||||
<li>ダウンロード: <a href="ff12.zip">FatFs R0.12</a> | <a href="updates.txt">変更点</a> | <a href="patches.html">パッチ</a> <span class="mfd">2016. 4. 12</span></li>
|
||||
<li>ダウンロード: <a href="ffsample.zip">サンプル プロジェクト</a> <span class="mfd">2016. 4. 12</span></li>
|
||||
<li>ダウンロード: <a href="archives.html">旧バージョン</a></li>
|
||||
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール アプリケーション ノート</a></li>
|
||||
<li>コミュニティ: <a href="http://elm-chan.org/fsw/ff/bd/">FatFsユーザ フォーラム</a></li>
|
||||
<li><a href="https://msdn.microsoft.com/en-us/windows/hardware/gg463080.aspx">FATファイルシステム仕様 by Microsoft</a>↗ (The reference document on FAT file system)</li>
|
||||
<li><a href="http://elm-chan.org/docs/fat.html">FATファイルシステム概要</a> (↑を読むためのガイド)</li>
|
||||
<li><a href="http://elm-chan.org/docs/mmc/mmc.html">MMCの使いかた</a></li>
|
||||
<li><a href="http://elm-chan.org/junk/fa/faff.html">FlashAirとFatFs [ja]</a></li>
|
||||
<li><a href="http://elm-chan.org/junk/fa/faff.html">FlashAirとFatFs [en]</a></li>
|
||||
<li><a href="http://stm32f4-discovery.com/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="http://nemuisan.blog.bai.ne.jp/">ねむいさんのぶろぐ</a>↗ (Well written implementations for STM32F/SDIO and LPC2300/MCI)</li>
|
||||
<li><a href="http://nemuisan.blog.bai.ne.jp/">ねむいさんのぶろぐ</a>↗ (Well written implementations for STM32F/SPI & SDIO and LPC4088/SDMMC)</li>
|
||||
<li><a href="http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/index.html">ARM-Projects by Martin THOMAS</a>↗ (Examples for LPC2000, AT91SAM and STM32)</li>
|
||||
<li><a href="img/rwtest1.png">パフォーマンス テスト1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li>
|
||||
<li><a href="img/rwtest2.png">パフォーマンス テスト2</a> (LPC2368/72MHz with MMC via MCI)</li>
|
||||
<li><a href="rc/fd.mp4">応用例のデモ動画</a> (This project is in ffsample.zip/lpc23xx)</li></ul>
|
||||
<li><a href="res/rwtest1.png">パフォーマンス テスト1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li>
|
||||
<li><a href="res/rwtest2.png">パフォーマンス テスト2</a> (LPC2368/72MHz with MMC via MCI)</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<hr>
|
||||
<p class="foot"><a href="../../fsw.html">戻る</a></p>
|
||||
<p class="foot"><a href="http://elm-chan.org/fsw/ff/00index_j.html">FatFs Home Page</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -42,9 +42,9 @@ The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt>
|
||||
|
||||
<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><img src="../img/modules.png" width="580" height="280" alt="dependency diagram"></p>
|
||||
<p><img src="../res/modules.png" width="580" height="280" alt="dependency diagram"></p>
|
||||
<p>(a) If a working disk module with FatFs API is provided, no additional function is needed. (b) To attach existing disk drivers with different API, glue functions are needed to translate the APIs between FatFs and the drivers.</p>
|
||||
<p><img src="../img/funcs.png" width="750" height="420" alt="functional diagram"></p>
|
||||
<p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p>
|
||||
|
||||
<h4>Which function is required?</h4>
|
||||
<p>You need to provide only low level disk I/O functions that required by FatFs module and nothing else. If a working disk module for the target system is already existing, you need to write only glue functions to attach it to the FatFs module. If not, you need to port any other disk module or write it from scratch. Most of defined functions are not that always required. For example, disk write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</p>
|
||||
@ -69,7 +69,7 @@ The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt>
|
||||
<li>Number of volumes: Upto 10.</li>
|
||||
<li>Volume size: Upto 2 TiB at 512 bytes/sector.</li>
|
||||
<li>File size: Upto 4 GiB - 1 on FAT volume and virtually unlimited on exFAT volume.</li>
|
||||
<li>Cluster size: Upto 128 sector on FAT volume, upto 32768 sectors on exFAT volume.</li>
|
||||
<li>Cluster size: Upto 128 sectors on FAT volume and upto 16 MiB on exFAT volume.</li>
|
||||
<li>Sector size: 512, 1024, 2048 and 4096 bytes.</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -144,7 +144,7 @@ And any 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">_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>option/unicode.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">_MAX_LFN</a></tt> according to the available memory. The length of an LFN will be up to 255 characters, so that the <tt>_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>_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>(_MAX_LFN + 1) * 2</tt> bytes.</p>
|
||||
<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">_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>option/unicode.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">_MAX_LFN</a></tt> according to the available memory. The length of an LFN will be up to 255 characters, so that the <tt>_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>_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>(_MAX_LFN + 1) * 2</tt> bytes and additional 608 bytes when exFAT enabled.</p>
|
||||
<table class="lst2 rset">
|
||||
<caption>With LFN at CM3+gcc</caption>
|
||||
<tr><th><tt>_CODE_PAGE</tt></th><th>Code size</th></tr>
|
||||
@ -166,9 +166,9 @@ And any other options are left unchanged from original setting.
|
||||
<div class="para doc" id="exfat">
|
||||
<h3>exFAT File System</h3>
|
||||
<p>The exFAT (Microsoft's Extended File Allocation Table) file system is a replacement of the FAT file system which has been widely used in the embedded systems and consumer devices. It is adopted by SDA (SD Association) as a recommended file system for high capacity SD cards (>32GB) and they are being shipped with this format, so that the exFAT will soon become one of the standard file systems for removable media.</p>
|
||||
<p>The exFAT file system allows the file size larger than 4 GiB limit what FAT file system allows upto and some file system overhead, especially file allocation delay, are reduced as well. This feature improves the write throughput to the file. However a problem on the current implementation of FatFs is that write throughput on the fragmented file with extension of size gets less than the throughput on the FAT volume. Pre-allocating a contiguous block with <tt>f_expand</tt> function may be a workaround of this problem.</p>
|
||||
<p>The exFAT file system allows the file size larger than 4 GiB limit what FAT file system allows upto and some file system overhead, especially file allocation delay, are reduced as well. This feature improves the write throughput to the file. However a problem on the current implementation of FatFs is that write throughput at writing to the growing edge of the fragmented file gets less than the throughput on the FAT volume. Pre-allocating a contiguous block with <tt>f_expand</tt> function may be a workaround of this problem.</p>
|
||||
<p>Note that the exFAT is a patent of Microsoft Corporation. The exFAT function of FatFs is an implementation based on US. Pat. App. Pub. No. 2009/0164440 A1. FatFs module can swich the exFAT on or off by configuration option. When enable the exFAT on the commercial products, you will need to be licensed by Microsoft depends on the final destination of the products.</p></div>
|
||||
<p><em>Remark: Enabling exFAT discards C89 compatibility due to need for 64-bit integer type.</em></p>
|
||||
<p><em>Remark: Enabling exFAT discards C89 compatibility because of need for 64-bit integer type.</em></p>
|
||||
|
||||
<div class="para doc" id="reentrant">
|
||||
<h3>Re-entrancy</h3>
|
||||
@ -189,13 +189,13 @@ And any other options are left unchanged from original setting.
|
||||
<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 misaligned read (short)<br>
|
||||
<img src="../img/f1.png" width="490" height="110" alt="">
|
||||
<img src="../res/f1.png" width="490" height="110" alt="">
|
||||
</p>
|
||||
<p>Figure 2. Sector misaligned read (long)<br>
|
||||
<img src="../img/f2.png" width="490" height="140" alt="">
|
||||
<img src="../res/f2.png" width="490" height="140" alt="">
|
||||
</p>
|
||||
<p>Figure 3. Fully sector aligned read<br>
|
||||
<img src="../img/f3.png" width="490" height="119" alt="">
|
||||
<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 file system object. The buffer configuration option <tt><a href="config.html#fs_tiny">_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>_MAX_SS</tt> bytes each file object. In this case, FatFs module uses only a sector buffer in the file system 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 misaligned 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>
|
||||
@ -208,12 +208,12 @@ And any other options are left unchanged from original setting.
|
||||
<h4>Using Mutiple-Sector Write</h4>
|
||||
<div class="rset">
|
||||
Figure 6. Comparison between Multiple/Single Sector Write<br>
|
||||
<img src="../img/f6.png" width="630" height="148" alt="fig.6">
|
||||
<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="../img/rwtest2.png">This graph</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>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 graph</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_remove</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 is forced erased on removing the file, those data blocks will be turned in to 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">_USE_TRIM</a></tt> to 1. Note that this is an expectation of internal process of the flash memory storage and not that always effective. Also <tt>f_remove</tt> function will take a time when remove a large file. Most applications will not need this function.</p>
|
||||
<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">_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">
|
||||
@ -221,11 +221,11 @@ Figure 6. Comparison between Multiple/Single Sector Write<br>
|
||||
<p>If a write operation to the FAT volume is interrupted due to any 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="../img/f4.png" width="320" height="436" alt="fig.4">
|
||||
<img src="../res/f4.png" width="320" height="436" alt="fig.4">
|
||||
</div>
|
||||
<div class="lset">
|
||||
Figure 5. Minimized critical section<br>
|
||||
<img src="../img/f5.png" width="320" height="436" alt="fig.5">
|
||||
<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>
|
||||
@ -243,11 +243,11 @@ Figure 5. Minimized critical section<br>
|
||||
<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="../img/app1.c">Open or create a file for append</a></li>
|
||||
<li><a href="../img/app2.c">Empty a directory</a></li>
|
||||
<li><a href="../img/app3.c">Allocate contiguous area to the file</a> (R0.11a and older)</li>
|
||||
<li><a href="../img/app4.c">Function/Compatible checker for low level disk I/O module</a></li>
|
||||
<li><a href="../img/mkfatimg.zip">FAT image creator</a></li>
|
||||
<li><a href="../res/app1.c">Open or create a file for append</a> (for R0.12 and older)</li>
|
||||
<li><a href="../res/app2.c">Empty a directory</a></li>
|
||||
<li><a href="../res/app3.c">Allocate contiguous area to the file</a> (for R0.11a and older)</li>
|
||||
<li><a href="../res/app4.c">Function/compatibility checker for low level disk I/O module</a></li>
|
||||
<li><a href="../res/mkfatimg.zip">FAT image creator</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
@ -256,13 +256,15 @@ Figure 5. Minimized critical section<br>
|
||||
<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 - FAT file system module R0.12 (C)ChaN, 2016
|
||||
/ FatFs - Generic FAT file system module R0.12a /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/ FatFs module is a free software that opened under license policy of
|
||||
/ following conditions.
|
||||
/
|
||||
/ Copyright (C) 2016, 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.
|
||||
/
|
||||
@ -272,7 +274,7 @@ Figure 5. Minimized critical section<br>
|
||||
/ 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 or any forms without source code, does not need to explain about use of FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most open source software licenses including GNU GPL. When you redistribute the FatFs source code with any modification or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software licenses that not conflict with FatFs license.</p>
|
||||
<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 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 licenses that not conflict with FatFs license.</p>
|
||||
</div>
|
||||
|
||||
<p class="foot"><a href="../00index_e.html">Return Home</a></p>
|
||||
|
||||
@ -45,7 +45,7 @@ FRESULT f_close (
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_close</tt> function closes an open file object. If any data has been written to the file, the cached information of the file is written back to the volume. After the function succeeded, the file object is no longer valid and it can be discarded.</p>
|
||||
<p>Note that if the file object is in read-only mode and <tt>_FS_LOCK</tt> option is not enabled, the file object can also be discarded without this process. However this is not recommended for future compatibility.</p>
|
||||
<p>Note that if the file object is in read-only mode and <tt>_FS_LOCK</tt> is not enabled, the file object can also be discarded without this process. However this is not recommended for future compatibility.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<p>Disable (0) or Enable (1) volume label functions, <tt>f_getlabel</tt> and <tt>f_setlabel</tt>.</p>
|
||||
|
||||
<h4 id="use_forward">_USE_FORWARD</h4>
|
||||
<p>Disable (0) or Enable (1) <tt>f_forward</tt> function. Also <tt>_FS_TINY</tt> needs to be 1.</p>
|
||||
<p>Disable (0) or Enable (1) <tt>f_forward</tt> function.</p>
|
||||
|
||||
</div>
|
||||
|
||||
@ -172,13 +172,13 @@
|
||||
<p>Normal (0) or Tiny (1). At the tiny configuration, size of the file object <tt>FIL</tt> is reduced <tt>_MAX_SS</tt> bytes. Instead of private data buffer eliminated from the file object, common sector buffer in the file system object <tt>FATFS</tt> is used for the file data transfer.</p>
|
||||
|
||||
<h4 id="fs_exfat">_FS_EXFAT</h4>
|
||||
<p>This option switches support for the exFAT file system in addition to the FAT file system, Enabled(1) or Disabled(1). To enable the exFAT, also LFN must be enabled. When enable exFAT, configureing <tt>_LFN_UNICODE = 1</tt> and <tt>_MAX_LFN = 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards C89 compatibility due to need for 64-bit integer type.</p>
|
||||
<p>This option switches support for the exFAT file system in addition to the FAT file system, Enabled(1) or Disabled(1). To enable this feature, also LFN must be enabled and configureing <tt>_LFN_UNICODE = 1</tt> and <tt>_MAX_LFN = 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards C89 compatibility because of need for 64-bit integer type.</p>
|
||||
|
||||
<h4 id="fs_nortc">_FS_NORTC</h4>
|
||||
<p>Use RTC (0) or Do not use RTC (1). This option controls timestamp function. If the system does not have an RTC function or valid timestamp is not needed, set <tt>_FS_NORTC</tt> to 1 to disable the timestamp function. Any object modified by FatFs will have a fixed timestamp value defined by <tt>_NORTC_MON</tt>, <tt>_NORTC_MDAY</tt> and <tt>_NORTC_YEAR</tt>. To use the timestamp function, set <tt>_FS_NORTC = 0</tt> and add <tt>get_fattime</tt> function to the project to get the current time form real-time clock. This option has no effect at read-only configuration.</p>
|
||||
|
||||
<h4 id="nortc_time">_NORTC_MON, _NORTC_MDAY, _NORTC_YEAR</h4>
|
||||
<p>This set of options defines default timestamp to be used at no RTC systems. This option has no effect at read-only configuration or <tt>_FS_NORTC = 0</tt>.</p>
|
||||
<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>_FS_NORTC = 0</tt>.</p>
|
||||
|
||||
<h4 id="fs_lock">_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>
|
||||
@ -189,7 +189,7 @@
|
||||
</table>
|
||||
|
||||
<h4 id="fs_reentrant">_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 file system object, is under control of this function. To enable this function, 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>option/syscall.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 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 file system 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>option/syscall.c</tt>.</p>
|
||||
|
||||
<h4 id="fs_timeout">_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>_FS_REENTRANT = 0</tt>.</p>
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
<div class="para func">
|
||||
<h2>f_expand</h2>
|
||||
<p>The f_expand function prepare or allocates a contiguous data area to the file.</p>
|
||||
<p>The f_expand function prepares or allocates a contiguous data area to the file.</p>
|
||||
|
||||
<pre>
|
||||
FRESULT f_expand (
|
||||
@ -30,7 +30,7 @@ FRESULT f_expand (
|
||||
<dt>fp</dt>
|
||||
<dd>Pointer to the open file object.</dd>
|
||||
<dt>fsz</dt>
|
||||
<dd>Number of bytes in size to prepare or be allocated to 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>_FS_EXFAT</tt>.</dd>
|
||||
<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>_FS_EXFAT</tt>.</dd>
|
||||
<dt>opt</dt>
|
||||
<dd>Operation mode. Prepare only (0) or Allocate now (1).</dd>
|
||||
</dl>
|
||||
@ -52,16 +52,16 @@ FRESULT f_expand (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_expand</tt> function prepare 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 file 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 undefined. The function can be failed 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 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>
|
||||
<ul>
|
||||
<li>No free contiguous space for the file was found.</li>
|
||||
<li>Size of the file was not zero on expand.</li>
|
||||
<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. (>= 4GiB 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 allocation point instead of allocating it to the file. The next cluster allocation is started at top of the contiguous data area. Thus the write file is guaranteed be contiguous and no allocation delay at least until the size reaches that size unless any other operation to the volume with changes of FAT is performed.</p>
|
||||
<p>The contiguous file would have an advantage at time-critical read/write operations. It reduces some overheads in the file system and the storage media caused by random access due to fragmented file data. Especially at the exFAT volume, any FAT access for the contiguous file is completely eliminated and storage media will be accessed sequentially.</p>
|
||||
<p>Also the contiguous file data can be accessed directory via low-level disk functions but it 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 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 operation to the volume with changes of FAT is performed.</p>
|
||||
<p>The contiguous file would have an advantage at time-critical read/write operations. It reduces some overheads in the file system and the storage media caused by random access due to fragmented file data. Especially, at the exFAT volume, any FAT access for the contiguous file is completely eliminated and storage media will be accessed sequentially.</p>
|
||||
<p>Also the contiguous file data can be easily accessed directly via low-level disk functions but it is not recommended in consideration for future compatibility.</p>
|
||||
</div>
|
||||
|
||||
<div class="para comp">
|
||||
@ -85,6 +85,7 @@ FRESULT f_expand (
|
||||
<span class="c">/* Alloacte a 100 MiB of contiguous area to the file */</span>
|
||||
res = f_expand(fp, 104857600, 1);
|
||||
if (res) { <span class="c">/* Check if the file has been expanded */</span>
|
||||
...
|
||||
free(fp);
|
||||
...
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<pre>
|
||||
FRESULT f_fdisk (
|
||||
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
|
||||
const DWORD <span class="arg">part[]</span>, <span class="c">/* [IN] Partition size */</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>
|
||||
);
|
||||
</pre>
|
||||
@ -27,9 +27,9 @@ FRESULT f_fdisk (
|
||||
<h4>Parameters</h4>
|
||||
<dl class="par">
|
||||
<dt>pdrv</dt>
|
||||
<dd>Specifies the <em>physical drive</em> to be divided.</dd>
|
||||
<dt>part[]</dt>
|
||||
<dd>Partition map table. It must have four items.</dd>
|
||||
<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>work</dt>
|
||||
<dd>Pointer to the function work area. The size must be at least <tt>_MAX_SS</tt> bytes.</dd>
|
||||
</dl>
|
||||
@ -48,7 +48,7 @@ FRESULT f_fdisk (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_fdisk</tt> function creates a partition table into the MBR of the physical drive. The partitioning rule is in generic FDISK format, so that it can create upto four primary partitions. Logical volumes in the extended partition is not supported. The <tt class="arg">part[]</tt> 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 percentage of the partition in the entire disk space. If it is larger than 100, it specifies the partition size in unit of sector.</p>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div class="para comp">
|
||||
@ -76,13 +76,8 @@ FRESULT f_fdisk (
|
||||
|
||||
f_fdisk(0, plist, work); <span class="c">/* Divide physical drive 0 */</span>
|
||||
|
||||
f_mount(&fs, "0:", 0); <span class="c">/* Register work area to the logical drive 0 */</span>
|
||||
f_mkfs("0:", 0, 0); <span class="c">/* Create FAT volume on the logical drive 0. 2nd argument is ignored. */</span>
|
||||
f_mount(0, "0:", 0); <span class="c">/* Unregister work area from the logical drive 0 */</span>
|
||||
|
||||
f_mount(&fs, "1:", 0); <span class="c">/* Register a work area to the logical drive 1 */</span>
|
||||
f_mkfs("1:", 0, 0); <span class="c">/* Create FAT volume on the logical drive 1. 2nd argument is ignored. */</span>
|
||||
f_mount(0, "1:", 0); <span class="c">/* Unregister work area from the logical drive 1 */</span>
|
||||
f_mkfs("0:", FMT_ANY, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span>
|
||||
f_mkfs("1:", FMT_ANY, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span>
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
<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>When option <tt><a href="config.html#str_volume_id">_STR_VOLUME_ID</a></tt> is specified, also pre-defined strings can be used as drive identifier in the path name instead of a numeral. e.g. <tt>"sd:file1.txt"</tt> or <tt>"ram:swapfile.dat"</tt>.</p>
|
||||
<p>When option <tt><a href="config.html#str_volume_id">_STR_VOLUME_ID</a></tt> is specified, also pre-defined strings can be used as drive identifier in the path name instead of a numeral. e.g. <tt>"sd:file1.txt"</tt>, <tt>"ram:swapfile.dat"</tt> and DOS/Windows style drive letter, of course.</p>
|
||||
<p><em>Remark: In this revision, R0.12, 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>
|
||||
|
||||
@ -58,25 +58,25 @@
|
||||
|
||||
<div class="para doc" id="vol">
|
||||
<h3>Volume Management</h3>
|
||||
<p>The FatFs module needs dynamic work area called <em>file system object</em> for each volume (logical drive). It is registered 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 volume mount process. It loads 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>FatFs module needs dynamic work area, <em>file system 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">_MULTI_PARTITION</a> == 1</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 must be defined by user to resolve the relationship between logical drives and partitions. Following code is an example of a volume management table.</p>
|
||||
<pre>
|
||||
Example: Logical drive 0-2 are tied to three pri-partitions on the physical drive 0 (fixed disk)
|
||||
Logical drive 3 is tied to an FAT volume on the physical drive 1 (removable disk)
|
||||
Example: Logical drive 0-2 are tied to three pri-partitions on the physical drive 0 (fixed drive)
|
||||
Logical drive 3 is tied to an FAT volume on the physical drive 1 (removable drive)
|
||||
|
||||
PARTITION VolToPart[] = {
|
||||
{0, 1}, <span class="c">/* Logical drive 0 ==> Physical drive 0, 1st partition */</span>
|
||||
{0, 2}, <span class="c">/* Logical drive 1 ==> Physical drive 0, 2nd partition */</span>
|
||||
{0, 3}, <span class="c">/* Logical drive 2 ==> Physical drive 0, 3rd partition */</span>
|
||||
{1, 0} <span class="c">/* Logical drive 3 ==> Physical drive 1 (auto detection) */</span>
|
||||
{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>
|
||||
};
|
||||
</pre>
|
||||
<div><img src="../img/f7.png" width="828" height="288" alt="relationship between logical drive and physical drive"></div>
|
||||
<div><img src="../res/f7.png" width="828" height="288" alt="relationship between logical drive and physical drive"></div>
|
||||
<p>There are some considerations on using 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 mounted.</li>
|
||||
<li>Windows does not support multiple volumes on the removable storage. Only first parition will be recognized.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@ -66,14 +66,14 @@ FRESULT f_findfirst (
|
||||
<ul>
|
||||
<li><tt>"*.*"</tt> never matches any name without extension while it matches any names at the standard systems.</li>
|
||||
<li>Any patterns terminated with a period never matches any name while it matches any names without extensiton at the standard systems.</li>
|
||||
<li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN and non-Unicode configuration.</li>
|
||||
<li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN with non-Unicode configuration.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="para comp">
|
||||
<h4>QuickInfo</h4>
|
||||
<p>This is a wrapper function of <a href="opendir.html"><tt>f_opendir</tt></a> and <a href="readdir.html"><tt>f_readdir</tt></a> function. Available when <tt>_USE_FIND <= 1</tt> and <tt>_FS_MINIMIZE <= 1</tt>.</p>
|
||||
<p>This is a wrapper function of <a href="opendir.html"><tt>f_opendir</tt></a> and <a href="readdir.html"><tt>f_readdir</tt></a> function. Available when <tt>_USE_FIND >= 1</tt> and <tt>_FS_MINIMIZE <= 1</tt>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ FRESULT f_forward (
|
||||
|
||||
<div class="para comp">
|
||||
<h4>QuickInfo</h4>
|
||||
<p>Available when <tt>_USE_FORWARD == 1</tt> and <tt>_FS_TINY == 1</tt>.</p>
|
||||
<p>Available when <tt>_USE_FORWARD == 1</tt>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ FRESULT f_getlabel (
|
||||
<dt>path</dt>
|
||||
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. Null-string specifies the default drive.</dd>
|
||||
<dt>label</dt>
|
||||
<dd>Pointer to the buffer to store the volume label. The buffer size must be at least 24 items at <tt>_LFN_UNICODE == 0</tt>, 12 items at <tt>_LFN_UNICODE == 1</tt>. If the volume has no label, a null-string will be returned. Set null pointer if this information is not needed.</dd>
|
||||
<dd>Pointer to the buffer to store the volume label. The buffer size must be at least 24 items at <tt>_LFN_UNICODE == 0</tt> or 12 items at <tt>_LFN_UNICODE == 1</tt>. If the volume has no label, a null-string will be returned. Set null pointer if this information is not needed.</dd>
|
||||
<dt>vsn</dt>
|
||||
<dd>Pointer to the <tt>DWORD</tt> variable to store the volume serial number. Set null pointer if this information is not needed.</dd>
|
||||
</dl>
|
||||
|
||||
@ -48,7 +48,7 @@ FRESULT f_lseek (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_lseek</tt> function moves the file read/write pointer of an open file. The offset can be specified in only origin from top of the file. 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 undefined because no data is written to the file. This is suitable to pre-allocate a cluster chain 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>The <tt>f_lseek</tt> function moves the file read/write pointer of an open file. The offset can be specified in only origin from top of the file. 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 cluster chain 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>
|
||||
<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>Disk full. There is no free space on the volume to expand the file.</li>
|
||||
|
||||
@ -13,12 +13,14 @@
|
||||
|
||||
<div class="para func">
|
||||
<h2>f_mkfs</h2>
|
||||
<p>The f_mkfs fucntion creates an FAT volume on the logical drive.</p>
|
||||
<p>The f_mkfs fucntion 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">sfd</span>, <span class="c">/* [IN] Partitioning rule */</span>
|
||||
UINT <span class="arg">au</span> <span class="c">/* [IN] Size of the allocation unit */</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>
|
||||
);
|
||||
</pre>
|
||||
</div>
|
||||
@ -27,11 +29,15 @@ FRESULT f_mkfs (
|
||||
<h4>Parameters</h4>
|
||||
<dl class="par">
|
||||
<dt>path</dt>
|
||||
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a> to be formatted. If there is no drive number, it means the default drive.</dd>
|
||||
<dt>sfd</dt>
|
||||
<dd>Specifies partitioning rule, FDISK format (0) or SFD format (1). This argument will be ignored on some case.</dd>
|
||||
<dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If there is no drive number in it, it means the default drive. The logical drive does not need to be mounted.</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. The flag <tt>FM_SFD</tt> specifies to place the volume on the drive in SFD format.</dd>
|
||||
<dt>au</dt>
|
||||
<dd>Specifies size of the allocation unit (cluter) in number of bytes or sectors. When the value is from 1 to 128, it specifies it in number of sectors. When the value is <tt>>= _MIN_SS</tt>, it specifies it in number of bytes. If any invalid value, zero or not power of 2, is given, the cluster size is automatically determined depends on the volume size.</dd>
|
||||
<dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is N times the sector size. N 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>
|
||||
<dt>work</dt>
|
||||
<dd>Pointer to the working buffer for the format process.</dd>
|
||||
<dt>len</dt>
|
||||
<dd>Size of the working buffer in unit of byte. It needs to be the sector size at least. Plenty of working buffer reduces number of write transaction to the device and the format process will be finished quickly.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
@ -43,7 +49,6 @@ FRESULT f_mkfs (
|
||||
<a href="rc.html#nr">FR_NOT_READY</a>,
|
||||
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
|
||||
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
|
||||
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
|
||||
<a href="rc.html#ma">FR_MKFS_ABORTED</a>,
|
||||
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>
|
||||
</p>
|
||||
@ -51,11 +56,11 @@ FRESULT f_mkfs (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>The <tt>f_mkfs</tt> function creates an FAT volume on the specified logical drive. When FDISK format is specified, a primary partition occupies entire space of the physical drive and then an FAT volume is created on the partition. When SFD format is specified, the FAT volume starts from the first sector of the physical drive.</p>
|
||||
<p>There are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable drive. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is usually used for floppy disk, Microdrive, optical disk and any type of super-floppy media.</p>
|
||||
<p>If the logical drive to be formatted is bound to the specific partition (1-4) by support of multiple partition, <tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>, the FAT volume is created into the partition. In this case, the second argument <tt class="arg">sfd</tt> has no effect. The physical drive must have been 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, is determined by only number of clusters on the volume, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the volume size and the specified cluster size. The cluster size affects read/write throughput and space usage efficiency. Larger cluster size increases the read/write throughput and decreases the space usage efficiency of the volume. In case of the number of clusters comes on the FAT sub-type boundaries, the function can fail with <tt>FR_MKFS_ABORTED</tt>.</p>
|
||||
<p><em>Remark: Creating exFAT volume is not supported at current revision, R0.12.</em></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 which FAT sub-type is selected, is depends on the volume size and the specified 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>.</p>
|
||||
<p>The allocation unit, also called 'cluster', 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 allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger cluster (this is automatically selected by default) is recommended for most case unless extremely many files are created on a volume.</p>
|
||||
<p>There are two disk formats, FDISK and SFD. The FDISK format is usually used for harddisk, MMC, SDC, CFC 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, Microdrive, optical disk and most type of super-floppy media. Some systems support only either one of two formats and other is not supported.</p>
|
||||
<p>When <tt>FM_SFD</tt> is not specified, a primary partition occupies whole drive space is created and then the FAT volume is created in it. When <tt>FM_SFD</tt> is specified, the FAT volume occupies from the first sector of the drive is created.</p>
|
||||
<p>If the logical drive to be formatted is bound to the specific partition (1-4) by support of multiple partition, <tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>, the FAT volume is created into 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>
|
||||
</div>
|
||||
|
||||
<div class="para comp">
|
||||
@ -69,19 +74,20 @@ FRESULT f_mkfs (
|
||||
<span class="c">/* Format default drive and create a file */</span>
|
||||
int main (void)
|
||||
{
|
||||
FATFS fs; <span class="c">/* File system object (volume work area) */</span>
|
||||
FATFS fs; <span class="c">/* File system object */</span>
|
||||
FIL fil; <span class="c">/* File object */</span>
|
||||
FRESULT res; <span class="c">/* API result code */</span>
|
||||
UINT bw; <span class="c">/* Bytes written */</span>
|
||||
BYTE work[_MAX_SS]; <span class="c">/* Work area (larger is better for process time) */</span>
|
||||
|
||||
|
||||
<span class="c">/* Register work area (do not care about error) */</span>
|
||||
f_mount(&fs, "", 0);
|
||||
|
||||
<span class="c">/* Create FAT volume with default cluster size */</span>
|
||||
res = f_mkfs("", 0, 0);
|
||||
<span class="c">/* Create FAT volume */</span>
|
||||
res = f_mkfs("", FM_ANY, 0, work, sizeof work);
|
||||
if (res) ...
|
||||
|
||||
<span class="c">/* Register work area */</span>
|
||||
f_mount(&fs, "", 0);
|
||||
|
||||
<span class="c">/* Create a file as new */</span>
|
||||
res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
|
||||
if (res) ...
|
||||
@ -95,12 +101,14 @@ int main (void)
|
||||
|
||||
<span class="c">/* Unregister work area */</span>
|
||||
f_mount(0, "", 0);
|
||||
|
||||
...
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="para ref">
|
||||
<h4>See Also</h4>
|
||||
<p><tt><a href="filename.html#vol">Volume management</a>, <a href="fdisk.html">f_fdisk</a></tt></p>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<p class="foot"><a href="../00index_e.html">Return</a></p>
|
||||
|
||||
@ -33,14 +33,14 @@ FRESULT f_open (
|
||||
<dt>mode</dt>
|
||||
<dd>Mode flags that specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
|
||||
<table class="lst">
|
||||
<tr><th>Value</th><th>Description</th></tr>
|
||||
<tr><th>Value</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_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file will be created.<br>
|
||||
To append data to the file, use <a href="lseek.html"><tt>f_lseek</tt></a> function after the file open in this method.</td></tr>
|
||||
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails with <tt>FR_EXIST</tt> if the file is existing.</td></tr>
|
||||
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it will be truncated and overwritten.</td></tr>
|
||||
<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 read/write pointer is set end of the file.</td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
@ -74,7 +74,7 @@ To append data to the file, use <a href="lseek.html"><tt>f_lseek</tt></a> functi
|
||||
|
||||
<div class="para desc">
|
||||
<h4>Description</h4>
|
||||
<p>Before using any file function, a work area (file system object) must be registered to the logical drive with <a href="mount.html"><tt>f_mount</tt></a> function. All API functions except for <a href="fdisk.html"><tt>f_fdisk</tt></a> function can work after this procedure.</p>
|
||||
<p>Before using any file function, a work area (file system object) must be registered to the logical drive with <a href="mount.html"><tt>f_mount</tt></a> function. All API functions except for <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function can work after this procedure.</p>
|
||||
<p>After <tt>f_open</tt> function succeeded, the file object is valid. The file object is used for subsequent operations to the file to identify the file. Open file must be closed prior to power down, media removal or re-mount, or the file can be collapsed. To close an open file, use <a href="close.html"><tt>f_close</tt></a> function.</p>
|
||||
<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>
|
||||
@ -82,7 +82,7 @@ To append data to the file, use <a href="lseek.html"><tt>f_lseek</tt></a> functi
|
||||
|
||||
<div class="para comp">
|
||||
<h4>QuickInfo</h4>
|
||||
<p>Always available. The mode flags, <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_CREATE_NEW and FA_OPEN_ALWAYS</tt>, are not available when <tt>_FS_READONLY == 1</tt>.</p>
|
||||
<p>Always available. Only <tt>FA_READ</tt> and <tt>FA_OPEN_EXISTING</tt> are supported when <tt>_FS_READONLY == 1</tt>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -82,9 +82,10 @@ Note that if once this error occured at any operation to an open file, the file
|
||||
<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>The disk/partition size is too small.</li>
|
||||
<li>Not allowable cluster size for this disk. This can occure when number of clusters gets near the boundaries of FAT sub-types.</li>
|
||||
<li>There is no partition related to the logical drive. (Related option: <tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>)</li>
|
||||
<li>It is pmpossible to formart with the given parameters.</li>
|
||||
<li>The size of volume is too small.</li>
|
||||
<li>The size of given work area is too small.</li>
|
||||
<li>The partition bound to the logical drive coulud not be found. (Related option: <tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>)</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
|
||||
@ -49,13 +49,13 @@ 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. In case of any condition listed below, short file name is stored into the <tt>fname[]</tt> and <tt>altname[]</tt> has a null string.</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. In case of the some conditions listed below, short file name is stored into the <tt>fname[]</tt> and <tt>altname[]</tt> has a null string.</p>
|
||||
<ul>
|
||||
<li>The item has no long file name. (Not the case at exFAT volume)</li>
|
||||
<li>Setting of <tt>_MAX_LFN</tt> is insufficient for the long file name. (Not the case at <tt>_MAX_LFN == 255</tt>)</li>
|
||||
<li>The long file name contains any character not allowed in ANSI/OEM code. (Not the case at <tt>_LFN_UNICODE == 1</tt>)</li>
|
||||
</ul>
|
||||
<p>There is a problem on reading directory of exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition avobe. If it is the case, a "?" is returned as file name to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt>_LFN_UNICODE = 1</tt> and <tt>_MAX_LFN = 255</tt> to support the full feature of LFN specification.</p>
|
||||
<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, a "?" is returned as file name to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt>_LFN_UNICODE = 1</tt> and <tt>_MAX_LFN = 255</tt> to support the full feature of LFN specification.</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -84,7 +84,8 @@ FRESULT scan_files (
|
||||
res = f_readdir(&dir, &fno); <span class="c">/* Read a directory item */</span>
|
||||
if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>
|
||||
if (fno.fattrib & AM_DIR) { <span class="c">/* It is a directory */</span>
|
||||
sprintf(&path[i = strlen(path)], "/%s", fno.fname);
|
||||
i = strlen(path);
|
||||
sprintf(&path[i], "/%s", fno.fname);
|
||||
res = scan_files(path); <span class="c">/* Enter the directory */</span>
|
||||
if (res != FR_OK) break;
|
||||
path[i] = 0;
|
||||
@ -106,7 +107,7 @@ int main (void)
|
||||
char buff[256];
|
||||
|
||||
|
||||
res = f_mount(&fs, "", 1);
|
||||
res = f_mount(&fs, "", 1);
|
||||
if (res == FR_OK) {
|
||||
strcpy(buff, "/");
|
||||
res = scan_files(buff);
|
||||
|
||||
@ -54,7 +54,7 @@ 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, attribute and SFN, 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. 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>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ FRESULT f_truncate (
|
||||
<a href="rc.html#ok">FR_OK</a>,
|
||||
<a href="rc.html#de">FR_DISK_ERR</a>,
|
||||
<a href="rc.html#ie">FR_INT_ERR</a>,
|
||||
<a href="rc.html#dn">FR_DENIED</a>,
|
||||
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
|
||||
<a href="rc.html#tm">FR_TIMEOUT</a>
|
||||
</p>
|
||||
|
||||
BIN
doc/img/f7.png
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
@ -42,9 +42,9 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
|
||||
|
||||
<h4>システム構成</h4>
|
||||
<p>下に示す依存関係図は、FatFsモジュール利用の組み込みシステムにおける代表的な構成を示します。</p>
|
||||
<p><img src="../img/modules.png" width="580" height="280" alt="システム構成図"></p>
|
||||
<p><img src="../res/modules.png" width="580" height="280" alt="システム構成図"></p>
|
||||
<p>(a) FatFs用に書かれたディスク モジュールがある場合は、そのまま追加するだけです。 (b) しかし、多くの既存のディスク モジュールはそのAPIをFatFsに合わせるため、グルー関数が必要になるでしょう。</p>
|
||||
<p><img src="../img/funcs.png" width="750" height="420" alt="functional diagram"></p>
|
||||
<p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p>
|
||||
|
||||
<h4>ユーザの作成する関数</h4>
|
||||
<p>ポーティング作業は、要求されるデバイス制御関数を用意することが全てで、それ以外にすることは何もありません。既に動作しているデバイス制御モジュールがあるなら、そのAPIをFatFsに合わせるかグルー関数を介してつなぐだけで済みますが、無い場合はほかから移植するか最初から書くかする必要があります。定義されている全ての関数が常に必要なわけではありません。例えば、リード オンリ構成では書き込み系関数は必要ありません。次の表に構成オプションと要求される関数の対応を示します。</p>
|
||||
@ -67,9 +67,9 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
|
||||
<li>ファイルシステム: FAT12, FAT16, FAT32(r0.0) および exFAT(r1.0)。</li>
|
||||
<li>同時オープン ファイル数: 無制限。(利用可能メモリによる)</li>
|
||||
<li>同時マウント ボリューム数: 最大 10。</li>
|
||||
<li>ファイル サイズ: 最大 4GiB-1(FATボリューム) または 事実上無制限(exFATボリューム)。</li>
|
||||
<li>ファイル サイズ: 最大 4GiB - 1 (FATボリューム) および、事実上無制限(exFATボリューム)。</li>
|
||||
<li>ボリューム サイズ: 最大 2TiB (512B/セクタ時)。</li>
|
||||
<li>クラスタ サイズ: 最大 128セクタ (FATボリューム) または 32768セクタ (exFATボリューム)。</li>
|
||||
<li>クラスタ サイズ: 最大 128セクタ (FATボリューム) および、最大 16MiB (exFATボリューム)。</li>
|
||||
<li>セクタ サイズ: 512B, 1KiB, 2KiB, 4KiB。</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -89,7 +89,6 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
|
||||
<tr class="ral"><td class="cal">Work area<br><small>(_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>(_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 option <tt>_VOLUMES</tt> and <em>F</em> denotes number of open files. All samples here are optimezed in code size.</p>
|
||||
<pre>
|
||||
FatFs R0.12 options:
|
||||
_FS_READONLY 0 (R/W) or 1 (R/O)
|
||||
@ -145,7 +144,7 @@ And any other options are left not changed from default setting.
|
||||
<div class="para doc" id="lfn">
|
||||
<h3>長いファイル名</h3>
|
||||
<p>FatFsモジュールは、長いファイル名(LFN)をサポートします。ファイルに付けられた2つの異なる名前(短いファル名と長いファイル名)は、<tt>f_readdir</tt>関数を除くファイル操作関数において透過です。デフォルト構成では、LFN機能はOFFになっています。LFN機能を有効にするには、<tt><a href="config.html#use_lfn">_USE_LFN</a></tt>を1,2または3に設定し、<tt>option/unicode.c</tt>をプロジェクトに追加します。LFN機能は、加えてある程度のワーク エリア(LFN操作バッファ)を必要とします。バッファ長は使用できるメモリに応じて<tt><a href="config.html#max_lfn">_MAX_LFN</a></tt>で構成されることができます。LFNの長さは最大255文字に達するので、LFN完全対応のためには<tt>_MAX_LFN</tt>は255に設定されるべきです。与えられたファイル名に対してバッファ長が不足した場合、ファイル関数は<tt>FR_INVALID_NAME</tt>で失敗します。</p>
|
||||
<p>ファイル関数に再入を行う条件の下でLFN機能を使用する場合は、<tt>_USE_LFN</tt>は2または3に設定されなければなりません。この場合、ファイル関数はワーク エリアを動的に確保(スタックまたはヒープ)します。ワーク エリアのサイズは、<tt>(_MAX_LFN + 1) * 2</tt>バイトになるので、スタック等のサイズはそれを考慮した十分な余裕がなければなりません。</p>
|
||||
<p>ファイル関数に再入を行う条件の下でLFN機能を使用する場合は、<tt>_USE_LFN</tt>は2または3に設定されなければなりません。この場合、ファイル関数はワーク エリアを動的に確保(スタックまたはヒープ)します。ワーク エリアのサイズは、<tt>(_MAX_LFN + 1) * 2</tt>バイト(exFAT利用時はさらに+608バイト)になるので、スタック等のサイズはそれを考慮した十分な余裕がなければなりません。</p>
|
||||
<table class="lst2 rset">
|
||||
<caption>LFN構成 at CM3</caption>
|
||||
<tr><th><tt>_CODE_PAGE</tt></th><th>追加コード</th></tr>
|
||||
@ -191,13 +190,13 @@ And any other options are left not changed from default setting.
|
||||
<h3>効率的なファイル アクセス</h3>
|
||||
<p>小規模な組込システムでのファイルの読み書きにおける効率の良いアクセスのため、アプリケーション プログラマはFatFsモジュールの中でどのような処理が行われているか考慮すべきです。ストレージ上のデータは<tt>f_read</tt>関数により次のシーケンスで転送されます。</p>
|
||||
<p>図1. セクタ ミスアラインド リード (ショート)<br>
|
||||
<img src="../img/f1.png" width="490" height="110" alt="fig.1">
|
||||
<img src="../res/f1.png" width="490" height="110" alt="fig.1">
|
||||
</p>
|
||||
<p>図2. セクタ ミスアラインド リード (ロング)<br>
|
||||
<img src="../img/f2.png" width="490" height="140" alt="fig.2">
|
||||
<img src="../res/f2.png" width="490" height="140" alt="fig.2">
|
||||
</p>
|
||||
<p>図3. セクタ アラインド リード<br>
|
||||
<img src="../img/f3.png" width="490" height="119" alt="fig.3">
|
||||
<img src="../res/f3.png" width="490" height="119" alt="fig.3">
|
||||
</p>
|
||||
<p>ファイルI/Oバッファはセクタの一部のデータを読み書きするためのセクタ バッファを意味します。セクタ バッファは、それぞれのファイル オブジェクト内のプライベート セクタ バッファまたはファイルシステム オブジェクト内の共有セクタ バッファのどちらかです。バッファ構成オプションの<tt><a href="config.html#fs_tiny">_FS_TINY</a></tt>は、データ転送にどちらを使うかを決定します。タイニー バッファ(1)が選択されるとデータ メモリの消費はそれぞれのファイル オブジェクトで<tt>_MAX_SS</tt>バイト減少されます。この場合、FatFsモジュールはファイル データの転送とFAT/ディレクトリ アクセスにファイルシステム オブジェクト内のセクタ バッファだけを使用します。タイニー バッファの欠点は、セクタ バッファにキャッシュされたFATデータがファイル データの転送により失われ、クラスタ境界の毎にリロードされなければならないことです。でも、悪くない性能と少ないメモリ消費の視点から多くのアプリケーションに適するでしょう。</p>
|
||||
<p>図1はセクタの一部のデータがファイルI/Oバッファを経由で転送されることを示します。図2に示される長いデータの転送では、転送データの中間の1セクタまたはそれ以上のセクタにまたがる転送データがアプリケーション バッファに直接転送されています。図3は転送データ全体がセクタ境界にアライメントされている場合を示しています。この場合、ファイルI/Oバッファは使用されません。直接転送においては最大の範囲のセクタが<tt>disk_read</tt>関数で一度に読み込まれますが、クラスタ境界を越えるマルチ セクタ転送はそれが隣接であっても行われません。</p>
|
||||
@ -210,9 +209,9 @@ And any other options are left not changed from default setting.
|
||||
<h4>マルチ セクタ書き込み</h4>
|
||||
<div class="rset">
|
||||
図6. マルチ/シングル セクタ ライトの比較<br>
|
||||
<img src="../img/f6.png" width="630" height="148" alt="fig.6">
|
||||
<img src="../res/f6.png" width="630" height="148" alt="fig.6">
|
||||
</div>
|
||||
<p>フラッシュ メモリ メディアの書き込み速度はシングル セクタ書き込みの時に最も低いものになり、一回のトランザクションで転送されるセクタ数が大きくなるほど書き込み速度は向上します(図6)。この効果はバス速度が高速になるほど大きく、10倍以上の差が現れることも珍しくありません。<a href="../img/rwtest2.png">テスト結果</a>は、マルチ セクタ書き込み(W:16K, 32 sectors)がシングル セクタ書き込み(W:100, 1 sector)よりどの程度速いかを明確に示しています。大容量メディアほどシングル セクタ書き込みが遅くなる点もまた重要です。書き込みトランザクションの回数はまた、メディアの寿命にも影響してきます。つまり、同じ量のデータを書き込む場合、図6上のシングル セクタ書き込みは、図6下のマルチ セクタ書き込みに比べて16倍早くフラッシュ メモリ メディアを消耗させてしまうということです。</p>
|
||||
<p>フラッシュ メモリ メディアの書き込み速度はシングル セクタ書き込みの時に最も低いものになり、一回のトランザクションで転送されるセクタ数が大きくなるほど書き込み速度は向上します(図6)。この効果はバス速度が高速になるほど大きく、10倍以上の差が現れることも珍しくありません。<a href="../res/rwtest2.png">テスト結果</a>は、マルチ セクタ書き込み(W:16K, 32 sectors)がシングル セクタ書き込み(W:100, 1 sector)よりどの程度速いかを明確に示しています。大容量メディアほどシングル セクタ書き込みが遅くなる点もまた重要です。書き込みトランザクションの回数はまた、メディアの寿命にも影響してきます。つまり、同じ量のデータを書き込む場合、図6上のシングル セクタ書き込みは、図6下のマルチ セクタ書き込みに比べて16倍早くフラッシュ メモリ メディアを消耗させてしまうということです。</p>
|
||||
<p>このように、アプリケーションはなるべく大きなブロック(クラスタ サイズまたは2の累乗セクタ境界にアライメントした)で読み書きを行う必要があります。もちろん、アプリケーションからメディアに至る全てのレイヤがマルチ セクタ転送に対応していないと意味がありません。残念ながら、既存のオープン ソースのドライバの多くはマルチ セクタ転送に未対応です。なお、FatFsモジュールおよびサンプル ドライバはマルチ セクタ転送に対応しています。</p>
|
||||
<h4>明示的なメモリ消去</h4>
|
||||
<p>通常のファイル消去では、記録されたデータに対して何らかの処理が行われるわけではなく、単にFAT上にその領域を未使用と記録しているだけです。このため、ファイルが消去されたあともそれらは有効なデータ ブロックとしてフラッシュ メモリ上に残ります。そこで、ファイルを消去するとき、占有していたデータ セクタを明示的に消去(つまり未使用ブロックにする)することにより、メディア内の空きブロックを増やすことができます。これにより、次にそのブロックに書き込むときの消去動作が無くなり、書き込み性能が向上する可能性があります。また、ウェアレベリングに使えるブロックが増え、メディアの耐久性も向上するかも知れません。この機能を有効にするには、<tt><a href="config.html#use_trim">_USE_TRIM</a></tt>に1を設定します。これはフラッシュ メモリ ドライブの内部動作に期待した制御なので、効果があるとは限りません。また、ファイル消去の時間が延びることも考慮に入れるべきです。</p>
|
||||
@ -223,11 +222,11 @@ And any other options are left not changed from default setting.
|
||||
<p>ストレージ上のFAT構造を操作している途中で、停電、不正なメディアの取り外し、回復不能なデータ エラー等の障害が発生すると、処理が中途半端な状態で中断され、その結果としてFATボリュームの構造が破壊される可能性があります。次にFatFsモジュールにおけるクリチカル セクションと、その間の障害により起きうるエラーの状態を示します。</p>
|
||||
<div class="lset">
|
||||
図4. 長いクリチカル セクション<br>
|
||||
<img src="../img/f4.png" width="320" height="436" alt="fig.4">
|
||||
<img src="../res/f4.png" width="320" height="436" alt="fig.4">
|
||||
</div>
|
||||
<div class="lset">
|
||||
図5. 最小化したクリチカル セクション<br>
|
||||
<img src="../img/f5.png" width="320" height="436" alt="fig.5">
|
||||
<img src="../res/f5.png" width="320" height="436" alt="fig.5">
|
||||
</div>
|
||||
<br class="clr">
|
||||
<p>赤で示したセクションを実行中に中断が発生した場合、クロス リンクが発生して操作中のファイルやディレクトリが失われる可能性があります。黄色で示したセクションを実行中に中断が発生した場合、次のうちいずれかまたは複数の結果が生じる可能性があります。</p>
|
||||
@ -245,11 +244,11 @@ And any other options are left not changed from default setting.
|
||||
<h3>APIの拡張的使用例</h3>
|
||||
<p>FatFs APIの拡張的使用例です。有用なコードがあった場合は、随時追加していきます。。</p>
|
||||
<ol>
|
||||
<li><a href="../img/app1.c">追記モードでのオープン/新規作成</a></li>
|
||||
<li><a href="../img/app2.c">ディレクトリを空にする</a></li>
|
||||
<li><a href="../img/app3.c">ファイルに連続領域を割り当てる</a>(R0.11a以前)</li>
|
||||
<li><a href="../img/app4.c">ディスクI/Oモジュールの機能/互換性チェッカー</a></li>
|
||||
<li><a href="../img/mkfatimg.zip">FATイメージ作成ツール</a></li>
|
||||
<li><a href="../res/app1.c">追記モードでのオープン/新規作成</a>(R0.12以前)</li>
|
||||
<li><a href="../res/app2.c">ディレクトリを空にする</a></li>
|
||||
<li><a href="../res/app3.c">ファイルに連続領域を割り当てる</a>(R0.11a以前)</li>
|
||||
<li><a href="../res/app4.c">ディスクI/Oモジュールの機能/互換性チェッカー</a></li>
|
||||
<li><a href="../res/mkfatimg.zip">FATイメージ作成ツール</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
@ -258,14 +257,17 @@ And any other options are left not changed from default setting.
|
||||
<p>FatFsは、作者(ChaN)の個人プロジェクトとして開発されています。現在のリビジョンにおいてコントリビューターはいないため、作者の書いたソース コード以外は含まれません。ソース ファイルにライセンス条件が記述されているので、利用の際はそれに従うこと。原文は英語ですが、参考までに以下に日本語訳を示しておきます。</p>
|
||||
<pre>
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module R0.12 (C)ChaN, 2016
|
||||
/ FatFs - Generic FAT file system module R0.12a /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/ FatFsモジュールはフリーソフトウェアで、次に示す条件の下に公開されています。
|
||||
/
|
||||
/ Copyright (C) 2016, ChaN, all right reserved.
|
||||
/
|
||||
/ 1. ソースコードで再配布するときは、その中に上記の著作権表示、この条文、および
|
||||
/ 次の免責事項を保持すること
|
||||
/ FatFsモジュールはオープンソースソフトウェアです。FatFsの再配布および使用は、
|
||||
/ ソースコードかバイナリ形式か、また変更の有無にかかわらず、次の条件が満たされ
|
||||
/ る場合に限り許可されます。
|
||||
/
|
||||
/ 1. ソースコードで再配布するときは、その中に上記の著作権表示、この条件、および
|
||||
/ 次の免責事項を保持すること。
|
||||
/
|
||||
/ このソフトウェアは、著作権者らおよびコントリビューターらによって<em>現状のまま</em>
|
||||
/ 提供されており、<em>いかなる保証もありません</em>。
|
||||
|
||||
@ -61,7 +61,7 @@ div.doc h4 {margin-top: 2em }
|
||||
<p>ボリューム ラベル操作機能の構成(0:無効 または 1:有効)。有効にすると、<tt>f_getlabel</tt>、<tt>f_setlabel</tt>関数(<tt>_FS_READONLY == 0</tt>のとき)が利用可能になります。</p>
|
||||
|
||||
<h4 id="use_forward">_USE_FORWARD</h4>
|
||||
<p>ストリーミング読み出し機能の構成(0:無効 または 1:有効)。これと<tt>_FS_TINY</tt>を1にすることで<tt>f_forward</tt>関数が利用可能になります。</p>
|
||||
<p>ストリーミング読み出し機能(<tt>f_forward</tt>関数)の構成(0:無効 または 1:有効)。</p>
|
||||
|
||||
</div>
|
||||
|
||||
@ -176,7 +176,7 @@ div.doc h4 {margin-top: 2em }
|
||||
<p>ファイル データ転送バッファの構成(0:ノーマル または 1:タイニ)。タイニ構成では、ファイル オブジェクト<tt>FIL</tt>内のプライベート セクタ バッファが削除され、<tt>_MAX_SS</tt>バイト小さくなります。ファイル データの転送には、代わりにファイル システム オブジェクト<tt>FATFS</tt>内のボリューム共有セクタ バッファが使われます。</p>
|
||||
|
||||
<h4 id="fs_exfat">_FS_EXFAT</h4>
|
||||
<p>exFATのサポート(0:使用しない または 1:使用する)。exFATを使用するには、LFN機能を有効にしなければなりません。また、exFATの完全サポートのためには、<tt>_LFN_UNICODE = 1</tt>と<tt>_MAX_LFN = 255</tt>の設定が推奨されます。exFAT機能では64-bit整数を使用するため、これを有効にするとC89(ANSI C)互換が失われます。</p>
|
||||
<p>exFATのサポート(0:使用しない または 1:使用する)。exFATを使用するには、LFN機能を有効にしなければなりません。また、exFATの完全サポートのためには、<tt>_LFN_UNICODE = 1</tt>と<tt>_MAX_LFN = 255</tt>の設定が推奨されます。exFAT機能では64ビット整数を使用するため、これを有効にするとC89(ANSI C)互換が失われます。</p>
|
||||
|
||||
<h4 id="fs_nortc">_FS_NORTC</h4>
|
||||
<p>RTC機能の使用の設定(0:使用する または 1:使用しない)。システムがRTC(カレンダ時計)をサポートしない場合は、1をセットします。この場合、FatFsが変更を加えたオブジェクトのタイムスタンプはデフォルトの日時を持ちます。RTCが使用可能なときは、0を設定し、<tt>get_fattime</tt>関数をプロジェクトに加えます。リード オンリ構成ではこのオプションは意味を持ちません。</p>
|
||||
|
||||
@ -52,10 +52,10 @@ FRESULT f_expand (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>解説</h4>
|
||||
<p><tt class="arg">opt</tt>に1を指定すると、ファイルに連続したデータ領域を割り当てます。<tt>f_lseek</tt>によるサイズ拡張とは異なり、対象ファイルのサイズは0(つまりデータ領域未割り当て)でなければなりません。リード/ライト ポインタは、ファイルの先頭に留まります。この関数により割り当てられたファイルの内容は未定義なので、それに対して何の前提も持つべきではありません。この関数は、次の理由により<tt>FR_DENIED</tt>で失敗することがあります。</p>
|
||||
<p><tt class="arg">opt</tt>に1を指定すると、ファイルに連続したデータ領域を割り当てます。<tt>f_lseek</tt>によるサイズ拡張とは異なり、対象ファイルのサイズは0(つまりデータ領域未割り当て)でなければなりません。また、リード/ライト ポインタは、ファイル先頭に留まります。この関数により割り当てられたファイルの内容は未定義なので、それに対して何の前提も持つべきではありません。この関数は、次の理由により<tt>FR_DENIED</tt>で失敗することがあります。</p>
|
||||
<ul>
|
||||
<li>ボリューム上に連続した空き領域が見つからなかった。</li>
|
||||
<li>対象ファイルのサイズが0ではなかった。</li>
|
||||
<li>ファイルのサイズが0ではなかった。</li>
|
||||
<li>ファイルが非書き込みモードで開かれている。</li>
|
||||
<li>指定されたファイル サイズが無効。(FATボリューム上で >=4GiB)</li>
|
||||
</ul>
|
||||
@ -85,6 +85,7 @@ FRESULT f_expand (
|
||||
<span class="c">/* 100 MiB の連続領域を割り当てる */</span>
|
||||
res = f_expand(fp, 104857600, 1);
|
||||
if (res) { <span class="c">/* 割り当てられたかチェック */</span>
|
||||
...
|
||||
free(fp);
|
||||
...
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<pre>
|
||||
FRESULT f_fdisk (
|
||||
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
|
||||
const DWORD <span class="arg">part[]</span>, <span class="c">/* [IN] 区画マップ テーブル */</span>
|
||||
const DWORD* <span class="arg">szt</span>, <span class="c">/* [IN] 区画サイズ テーブル */</span>
|
||||
void* <span class="arg">work</span> <span class="c">/* [-] ワークエリア */</span>
|
||||
);
|
||||
</pre>
|
||||
@ -27,9 +27,9 @@ FRESULT f_fdisk (
|
||||
<h4>引数</h4>
|
||||
<dl class="par">
|
||||
<dt>pdrv</dt>
|
||||
<dd>分割する<em>物理ドライブ</em>のドライブ番号を指定します。</dd>
|
||||
<dt>part[]</dt>
|
||||
<dd>区画マップ テーブルへのポインタを指定します。</dd>
|
||||
<dd>分割する<em>物理ドライブ</em>を指定します。これは論理ドライブ番号ではなく、ディスク関数に渡される物理ドライブ番号です。</dd>
|
||||
<dt>szt</dt>
|
||||
<dd>区画サイズ テーブルの先頭項目へのポインタを指定します。</dd>
|
||||
<dt>work</dt>
|
||||
<dd>ワークエリアへのポインタを指定します。サイズは<tt>_MAX_SS</tt>バイト必要です。</dd>
|
||||
</dl>
|
||||
@ -48,7 +48,7 @@ FRESULT f_fdisk (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>説明</h4>
|
||||
<p>この関数は、指定された物理ドライブのMBRに区画テーブルを作成します。区画分けは一般的なFDISK形式で行うため、最大4つの基本区画を作成することができます。拡張区画には対応していません。区画マップテーブル<tt class="arg">part[]</tt>にはドライブをどのように分割するか指定して渡します。この配列は4つの項目から成り、先頭の項目が1番目の、最後の項目が4番目の区画のサイズを示します。値が100以下の場合、ドライブの総容量に対する割合をパーセント単位で指定します。100を超える値の場合はセクタ数の直接指定になります。</p>
|
||||
<p>この関数は、指定された物理ドライブのMBRに区画テーブルを作成します。区画分けは一般的なFDISK形式で行うため、最大4つの基本区画を作成することができます。拡張区画には対応していません。区画サイズ テーブルにはドライブをどのように分割するか指定します。この配列は4つの項目から成り、先頭の項目が1番目の区画のサイズを示します。項目の値が100以下の場合、その区画のドライブの総容量に対する割合をパーセント単位で指定します。100を超える値の場合はセクタ数の直接指定になります。ドライブ上への区画の配置順は、項目順になります。</p>
|
||||
</div>
|
||||
|
||||
<div class="para comp">
|
||||
@ -71,27 +71,22 @@ FRESULT f_fdisk (
|
||||
<span class="c">/* 新しい物理ドライブ(0)の初期化 */</span>
|
||||
|
||||
FATFS fs;
|
||||
DWORD plist[] = {50, 50, 0, 0}; <span class="c">/* 2分割 */</span>
|
||||
DWORD plist[] = {50, 50, 0, 0}; <span class="c">/* 第1区画,第2区画それぞれに50%ずつ割り当て */</span>
|
||||
BYTE work[_MAX_SS];
|
||||
|
||||
f_fdisk(0, plist, work); <span class="c">/* 物理ドライブ 0 の分割 */</span>
|
||||
|
||||
f_mount(&fs "0:", 0);
|
||||
f_mkfs("0:", 0, 0); <span class="c">/* 論理ドライブ 0 のフォーマット. 第二引数は無視される. */</span>
|
||||
f_mount(0, "0:", 0);
|
||||
|
||||
f_mount(&fs, "1:", 0);
|
||||
f_mkfs("1:", 0, 0); <span class="c">/* 論理ドライブ 0 のフォーマット. 第二引数は無視される. */</span>
|
||||
f_mount(0, "1:", 0);
|
||||
f_mkfs("0:", FMT_ANY, work, sizeof work); <span class="c">/* 論理ドライブ 0: のフォーマット */</span>
|
||||
f_mkfs("1:", FMT_ANY, work, sizeof work); <span class="c">/* 論理ドライブ 1: のフォーマット */</span>
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="para ref">
|
||||
<h4>See Also</h4>
|
||||
<p><tt><a href="filename.html#vol">Volume management</a>, <a href="mkfs.html">f_mkfs</a></tt></p>
|
||||
<h4>参照</h4>
|
||||
<p><tt><a href="filename.html#vol">ボリューム管理</a>, <a href="mkfs.html">f_mkfs</a></tt></p>
|
||||
</div>
|
||||
|
||||
<p class="foot"><a href="../00index_j.html">Return</a></p>
|
||||
<p class="foot"><a href="../00index_j.html">戻る</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<tr><td>dir1/..</td><td>無効</td><td>カレント ディレクトリ</td></tr>
|
||||
<tr><td>/..</td><td>無効</td><td>ルート ディレクトリ(その上は辿れない)</td></tr>
|
||||
</table>
|
||||
<p>また、<tt><a href="config.html#str_volume_id">_STR_VOLUME_ID</a></tt>オプションを有効にすることでドライブ番号の識別には数字のほか、<tt>"sd:file1.txt"</tt>や<tt>"ram:swapfile.dat"</tt>のように、任意の文字列を使用することも可能になります。</p>
|
||||
<p>また、<tt><a href="config.html#str_volume_id">_STR_VOLUME_ID</a></tt>オプションを有効にすることでドライブ番号の識別には数字のほか、<tt>"sd:file1.txt"</tt>や<tt>"ram:swapfile.dat"</tt>のように、任意の文字列(もちろんDOS/Windowsライクなドライブ文字も)を使用することも可能になります。</p>
|
||||
<p><em>【注意】現リビジョン(R0.12)では、exFATボリューム上においてダブル ドット<tt>".."</tt>はシングル ドット<tt>"."</tt>として機能し、親ディレクトリを辿ることはできません。</em></p>
|
||||
</div>
|
||||
|
||||
@ -56,20 +56,20 @@
|
||||
|
||||
<div class="para doc" id="vol">
|
||||
<h3>ボリューム管理</h3>
|
||||
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、自動検出機能によりその物理ドライブ上の一つのFATボリュームがマウントされます。FATボリュームの検出は、セクタ0、第一区画~第四区画の順に行われます。</p>
|
||||
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、自動検出機能によりその物理ドライブ上の一つのFATボリュームがマウントされます。FATボリュームの検出は、セクタ0(SFD)、第一区画~第四区画(FDISK)の順に行われます。</p>
|
||||
<p><tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>に1を指定すると、それぞれの論理ドライブに対して個別に物理ドライブ番号と区画を指定できるようになります。この構成では、論理ドライブと区画の対応を解決するためのテーブルを次に示すように定義する必要があります。</p>
|
||||
<pre>
|
||||
例:論理ドライブ0~2を物理ドライブ0(非リムーバブル)の3つの基本区画に割り当て、
|
||||
論理ドライブ3を物理ドライブ1(リムーバブル)に割り当てる場合。
|
||||
|
||||
PARTITION VolToPart[] = {
|
||||
{0, 1}, <span class="c">/* 論理ドライブ 0 ==> 物理ドライブ 0, 第1区画 */</span>
|
||||
{0, 2}, <span class="c">/* 論理ドライブ 1 ==> 物理ドライブ 0, 第2区画 */</span>
|
||||
{0, 3}, <span class="c">/* 論理ドライブ 2 ==> 物理ドライブ 0, 第3区画 */</span>
|
||||
{1, 0} <span class="c">/* 論理ドライブ 3 ==> 物理ドライブ 1, 自動検出 */</span>
|
||||
{0, 1}, <span class="c">/* "0:" ==> 物理ドライブ 0, 第1区画 */</span>
|
||||
{0, 2}, <span class="c">/* "1:" ==> 物理ドライブ 0, 第2区画 */</span>
|
||||
{0, 3}, <span class="c">/* "2:" ==> 物理ドライブ 0, 第3区画 */</span>
|
||||
{1, 0} <span class="c">/* "3:" ==> 物理ドライブ 1, 自動検出 */</span>
|
||||
};
|
||||
</pre>
|
||||
<div><img src="../img/f7.png" width="828" height="288" alt="論理ドライブと物理ドライブの関係"></div>
|
||||
<div><img src="../res/f7.png" width="828" height="288" alt="論理ドライブと物理ドライブの関係"></div>
|
||||
<p>複数区画指定を使用する場合、次の点に注意しなければなりません。
|
||||
<ul>
|
||||
<li>複数のマウントされた区画を持つ物理ドライブは、非リムーバブルでなければならず、システム動作中のメディア交換は禁止。</li>
|
||||
|
||||
@ -62,7 +62,7 @@ FRESULT f_findfirst (
|
||||
<div class="para desc">
|
||||
<h4>解説</h4>
|
||||
<p><tt class="arg">path</tt>で指定されるディレクトリを開き、そのディレクトリ内の項目の検索を開始します。正常終了すると、ディレクトリ オブジェクト構造体が作成され、最初に検索名文字列に名前がマッチした項目の情報が<tt class="arg">fno</tt>の指定するファイル情報構造体にストアされます。名前のマッチする項目が見つからなかった場合は、<tt>fno->fname[]</tt>にヌル文字列が返されます。ファイル情報構造体の使い方については、<a href="readdir.html"><tt>f_readdir</tt></a>関数を参照してください。</p>
|
||||
<p>マッチ パターン文字列は、ワイルドカード文字(<tt>?</tt>と<tt>*</tt>)を含むことができます。<tt>?</tt>は任意の1文字に、<tt>*</tt>は0文字以上の任意の文字列にマッチします。LFN構成では、SFNとLFN(あれば)の両方に対してテストを行います。現リビジョンではパターン マッチングにおいて次の点で標準システムとは異なる動作となります。</p>
|
||||
<p>マッチ パターン文字列は、ワイルドカード文字(<tt>?</tt>と<tt>*</tt>)を含むことができます。<tt>?</tt>は任意の1文字に、<tt>*</tt>は0文字以上の任意の文字列にマッチします。LFN構成では、<tt>_USE_FIND = 1</tt>のとき<tt>fname[]</tt>のみテストし、<tt>_USE_FIND = 2</tt>のときは<tt>altname[]</tt>もテストします。現リビジョンではパターン マッチングにおいて次の点で標準システムとは異なる動作となります。</p>
|
||||
<ul>
|
||||
<li><tt>"*.*"</tt>は拡張子なしの名前にマッチしない。(標準システムでは全ての名前にマッチ)</li>
|
||||
<li>ピリオドで終わるパターンは、どの名前にもマッチしない。(標準システムでは拡張子無しの名前にマッチ)</li>
|
||||
@ -73,7 +73,7 @@ FRESULT f_findfirst (
|
||||
|
||||
<div class="para comp">
|
||||
<h4>対応情報</h4>
|
||||
<p>この関数は、<a href="opendir.html"><tt>f_opendir</tt></a>関数および<a href="readdir.html"><tt>f_readdir</tt></a>関数のラッパー関数です。<tt>_USE_FIND == 1</tt>で、かつ<tt>_FS_MINIMIZE <= 1</tt>のとき使用可能になります。</p>
|
||||
<p>この関数は、<a href="opendir.html"><tt>f_opendir</tt></a>関数および<a href="readdir.html"><tt>f_readdir</tt></a>関数のラッパー関数です。<tt>_USE_FIND >= 1</tt>で、かつ<tt>_FS_MINIMIZE <= 1</tt>のとき使用可能になります。</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -84,23 +84,14 @@ FRESULT f_findfirst (
|
||||
|
||||
void find_image (void)
|
||||
{
|
||||
FRESULT fr; <span class="c">/* 戻り値 */</span>
|
||||
FRESULT fr; <span class="c">/* API戻り値 */</span>
|
||||
DIR dj; <span class="c">/* ディレクトリ オブジェクト */</span>
|
||||
FILINFO fno; <span class="c">/* ファイル情報構造体 */</span>
|
||||
<span class="k">#if</span> _USE_LFN
|
||||
char lfn[_MAX_LFN + 1];
|
||||
fno.lfname = lfn;
|
||||
fno.lfsize = _MAX_LFN + 1;
|
||||
<span class="k">#endif</span>
|
||||
FILINFO fno; <span class="c">/* ファイル情報 */</span>
|
||||
|
||||
fr = f_findfirst(&dj, &fno, "", "dsc*.jpg"); <span class="c">/* "dsc"で始まるJPEGファイルを検索 */</span>
|
||||
|
||||
while (fr == FR_OK && fno.fname[0]) { <span class="c">/* 見つかる間繰り返し */</span>
|
||||
<span class="k">#if</span> _USE_LFN
|
||||
printf("%s %s\n", fno.fname, fno.lfname);<span class="c">/* 見つけた項目の名前を表示 */</span>
|
||||
<span class="k">#else</span>
|
||||
printf("%s\n", fno.fname);
|
||||
<span class="k">#endif</span>
|
||||
printf("%s\n", fno.fname); <span class="c">/* 見つけた項目の名前を表示 */</span>
|
||||
fr = f_findnext(&dj, &fno); <span class="c">/* 次を検索 */</span>
|
||||
}
|
||||
f_closedir(&dj);
|
||||
|
||||
@ -54,7 +54,7 @@ FRESULT f_findnext (
|
||||
|
||||
<div class="para comp">
|
||||
<h4>対応情報</h4>
|
||||
<p>この関数は、<a href="readdir.html"><tt>f_readdir</tt></a>関数のラッパー関数です。<tt>_USE_FIND == 1</tt>で、かつ<tt>_FS_MINIMIZE <= 1</tt>のとき使用可能になります。</p>
|
||||
<p>この関数は、<a href="readdir.html"><tt>f_readdir</tt></a>関数のラッパー関数です。<tt>_USE_FIND >= 1</tt>で、かつ<tt>_FS_MINIMIZE <= 1</tt>のとき使用可能になります。</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ FRESULT f_forward (
|
||||
|
||||
<div class="para comp">
|
||||
<h4>対応情報</h4>
|
||||
<p><tt>_USE_FORWARD == 1</tt>で、且つ<tt>_FS_TINY == 1</tt>のときに使用可能です。</p>
|
||||
<p><tt>_USE_FORWARD == 1</tt>のときに使用可能です。</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ FRESULT f_getlabel (
|
||||
<dt>path</dt>
|
||||
<dd>対象となる論理ドライブの<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。ヌル文字列の場合は、デフォルト ドライブを指定したことになります。</dd>
|
||||
<dt>label</dt>
|
||||
<dd>ボリューム名を格納する配列へのポインタを指定します。<tt>_LFN_UNICODE == 0</tt>では少なくとも24バイト、<tt>_LFN_UNICODE == 1</tt>では少なくとも12文字のサイズが必要です。ボリューム名がない場合はヌル文字列が返されます。この情報が不要なときはヌル ポインタを指定してください。</dd>
|
||||
<dd>ボリューム名を格納する配列へのポインタを指定します。<tt>_LFN_UNICODE == 0</tt>では少なくとも24要素、<tt>_LFN_UNICODE == 1</tt>では少なくとも12要素のサイズが必要です。ボリューム名がない場合はヌル文字列が返されます。この情報が不要なときはヌル ポインタを指定してください。</dd>
|
||||
<dt>vsn</dt>
|
||||
<dd>ボリューム シリアル番号を格納する<tt>DWORD</tt>型変数へのポインタを指定します。この情報が不要なときはヌル ポインタを指定してください。</dd>
|
||||
</dl>
|
||||
@ -60,7 +60,7 @@ FRESULT f_getlabel (
|
||||
<div class="para use">
|
||||
<h4>使用例</h4>
|
||||
<pre>
|
||||
char str[12];
|
||||
char str[24];
|
||||
|
||||
<span class="c">/* デフォルト ドライブのボリューム名を得る */</span>
|
||||
f_getlabel("", str, 0);
|
||||
|
||||
@ -13,12 +13,14 @@
|
||||
|
||||
<div class="para func">
|
||||
<h2>f_mkfs</h2>
|
||||
<p>論理ドライブ上にFATボリュームを作成します。</p>
|
||||
<p>論理ドライブ上にFAT/exFATボリュームを作成(フォーマット)します。</p>
|
||||
<pre>
|
||||
FRESULT f_mkfs (
|
||||
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] 論理ドライブ番号 */</span>
|
||||
BYTE <span class="arg">sfd</span>, <span class="c">/* [IN] 区画作成方法 */</span>
|
||||
UINT <span class="arg">au</span> <span class="c">/* [IN] クラス タサイズ */</span>
|
||||
BYTE <span class="arg">opt</span>, <span class="c">/* [IN] フォーマット オプション */</span>
|
||||
DWORD <span class="arg">au</span>, <span class="c">/* [IN] クラスタ サイズ */</span>
|
||||
void* <span class="arg">work</span>, <span class="c">/* [-] ワーク エリア */</span>
|
||||
UINT <span class="arg">len</span> <span class="c">/* [IN] ワーク エリアのサイズ */</span>
|
||||
);
|
||||
</pre>
|
||||
</div>
|
||||
@ -27,11 +29,15 @@ FRESULT f_mkfs (
|
||||
<h4>引数</h4>
|
||||
<dl class="par">
|
||||
<dt>path</dt>
|
||||
<dd>対象の論理ドライブを示す<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。ドライブ番号を含まない場合は、カレント ドライブを意味します。</dd>
|
||||
<dt>sfd</dt>
|
||||
<dd>パーテーション形式。(0(FDISK) または 1(SFD))</dd>
|
||||
<dd>フォーマット対象の論理ドライブを示す<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。ドライブ番号を含まない場合は、デフォルト ドライブを意味します。論理ドライブには<tt>f_mount</tt>関数でワークエリアが与えられている必要はありません。</dd>
|
||||
<dt>opt</dt>
|
||||
<dd>フォーマット オプション。<tt>FM_FAT, FM_FAT32, FM_EXFAT</tt>の各フラグの組み合わせ(<tt>FM_ANY</tt>は、これらのOR値)で作成するFATボリュームのタイプを指定します。複数のタイプが指定された場合、その中のいずれかが自動選択されます。exFATが無効のときは、<tt>FM_EXFAT</tt>は無視されます。<tt>FM_SFD</tt>フラグを指定すると、SFD形式(後述)でボリュームを配置します。</dd>
|
||||
<dt>au</dt>
|
||||
<dd>クラスタ サイズをバイト数またはセクタ数で指定します。値が1~128の範囲場合は、セクタ数を示します。値が<tt>_MIN_SS</tt>以上の場合は、バイト数を示します。無効値(0または2の累乗でない値など)を指定した場合、ボリュームのサイズに応じたデフォルトのクラスタ サイズが自動選択されます。</dd>
|
||||
<dd>クラスタ サイズをバイト単位で指定します。有効値は、セクタ サイズのN倍となります。Nは2の累乗で、FAT/FAT32ボリュームでは1~128、exFATボリュームでは1~32768です。0を指定した場合は、ボリュームのサイズと選択されたFATタイプに応じたデフォルトのクラスタ サイズが選択されます。</dd>
|
||||
<dt>work</dt>
|
||||
<dd>ワークエリアへのポインタを指定します。</dd>
|
||||
<dt>len</dt>
|
||||
<dd>ワークエリアのサイズをバイト単位で指定します。ワークエリアのサイズは少なくとも関連するドライブのセクタサイズは必要です。また、十分に大きなサイズを与えることにより、書き込みトランザクションの回数が減ってフォーマット時間を短縮できます。</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
@ -41,7 +47,6 @@ FRESULT f_mkfs (
|
||||
<a href="rc.html#ok">FR_OK</a>,
|
||||
<a href="rc.html#de">FR_DISK_ERR</a>,
|
||||
<a href="rc.html#nr">FR_NOT_READY</a>,
|
||||
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
|
||||
<a href="rc.html#ma">FR_MKFS_ABORTED</a>,
|
||||
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>
|
||||
</p>
|
||||
@ -49,14 +54,13 @@ FRESULT f_mkfs (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>説明</h4>
|
||||
<p>物理ドライブ上にFATボリュームを作成(フォーマット)します。FDISK形式が指定された場合は、物理ドライブ全体を占める基本区画(パーテーション)が作成され、その中にFATボリュームが作成されます。SFD形式では、FATボリュームが物理ドライブの先頭セクタからベタで作成されます。</p>
|
||||
<p>マルチ パーテーション機能(<tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>)により、フォーマット対象の論理ドライブが特定の区画(1~4)に結び付けられている場合は、その区画の中にFATボリュームが作成されます。<tt class="arg">sfd</tt>は無視され、その物理ドライブはこれに先立ち、<tt>f_fdisk</tt>関数または他のツールで適切に区画設定されている必要があります。</p>
|
||||
<p>パーテーション形式には、FDISK形式とSFD形式の二通りあります。FDISK形式は、ハードディスク、MMC、SDC、CFC、U Diskなどで標準的に使用されます。FDISK形式では一台の物理ドライブ上に一つまたは複数の区画を作成することができます。区画管理情報はMBR(物理ドライブの先頭セクタ)に記録されます。SFD形式は単に何の分割も行わない形式で、ボリュームは物理ドライブの先頭セクタから開始します。SFD形式は、フロッピー ディスク、マイクロドライブ、光学ディスク、およびその他スーパー フロッピー メディアで標準的に使用されています。</p>
|
||||
<p>FATタイプ(FAT12/FAT16/FAT32)は、そのボリューム上の<em>クラスタ数によってのみ決定</em>される決まり[FAT仕様書より]になっていて、それ以外の要因はありません。したがって、どのFATタイプになるかはボリューム サイズとクラスタ サイズに依存します。クラスタ サイズは大きくするほど性能が上がります。クラスタ数がFATタイプの境界に近くなるときは、<tt>FR_MKFS_ABORTED</tt>で関数が失敗する可能性があります。</p>
|
||||
<p><em>現リビジョン(R0.12)では、exFATボリュームの作成はサポートされません。</em></p>
|
||||
<p>exFAT以外のボリュームのFATタイプ(FAT12/FAT16/FAT32)は、そのボリューム上の<em>クラスタ数によってのみ決定</em>される決まり[FAT仕様書より]になっていて、それ以外の要因はありません。したがって、どのFATタイプになるかはボリューム サイズとクラスタ サイズに依存します。そのボリュームのサイズにおいて、指定されたFATタイプとクラスタ サイズの組み合わせが成立し得ないときは、関数は<tt>FR_MKFS_ABORTED</tt>で失敗します。</p>
|
||||
<p>クラスタとは、データ格納領域の管理の単位のことで、これを単位にファイルにデータ領域が割り当てられます。たとえば、クラスタ サイズが32768のときは、100バイトのファイルも32768バイトのスペースを消費することになります。このように、クラスタ サイズを大きくするほどボリュームの利用効率が悪くなりますが、その一方で読み書きの性能は上がります。クラスタ サイズによる利用効率と性能はトレード オフの関係にあります。GBクラスのストレージでは、極端に多くのファイルを扱わない限り32768バイト以上に(デフォルト指定ではそのようになる)しておくとよいでしょう。</p>
|
||||
<p>パーテーション形式には、FDISK形式とSFD形式の二通りあります。FDISK形式は、ハードディスク、マルチメディアカード、SDカード、CFカード、USBメモリなどで標準的に使用されます。FDISK形式では一台の物理ドライブ上に一つまたは複数の区画を作成することができ、区画管理情報はMBR(物理ドライブの先頭セクタ)に記録されます。SFD形式は単に何の分割も行わない形式で、ボリュームは物理ドライブの先頭セクタから開始します。SFD形式は、フロッピー ディスク、マイクロドライブ、光学ディスク、およびその他スーパー フロッピー メディアで標準的に使用されています。システムによっては、FDISK形式またはSFD形式のどちらか一方のみをサポートし他方をサポートしません。</p>
|
||||
<p><tt>FM_SFD</tt>が指定されないときはFDISK形式となり、その物理ドライブ全体を占める1個の基本区画(パーテーション)が作成され、その中にFATボリュームが作成されます。<tt>FM_SFD</tt>が指定されたときはSFD形式となり、FATボリュームがその物理ドライブの先頭セクタからベタで作成されます。</p>
|
||||
<p>マルチ パーテーション機能(<tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>)により、その論理ドライブが特定の区画(1~4)に結び付けられている場合は、その区画の中にFATボリュームが作成されます。<tt>FM_SFD</tt>の指定は無視され、その物理ドライブはこれに先立ち、<tt>f_fdisk</tt>関数または他のツールで適切に区画設定されている必要があります。</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="para comp">
|
||||
<h4>対応情報</h4>
|
||||
<p><tt>_FS_READONLY == 0</tt>で、且つ<tt>_USE_MKFS == 1</tt>のとき使用可能です。</p>
|
||||
@ -69,19 +73,20 @@ FRESULT f_mkfs (
|
||||
<span class="c">/* Format default drive and create a file */</span>
|
||||
int main (void)
|
||||
{
|
||||
FATFS fs; <span class="c">/* File system object (volume work area) */</span>
|
||||
FATFS fs; <span class="c">/* File system object */</span>
|
||||
FIL fil; <span class="c">/* File object */</span>
|
||||
FRESULT res; <span class="c">/* API result code */</span>
|
||||
UINT bw; <span class="c">/* Bytes written */</span>
|
||||
BYTE work[_MAX_SS]; <span class="c">/* Work area (larger is better for process time) */</span>
|
||||
|
||||
|
||||
<span class="c">/* Register work area (do not care about error) */</span>
|
||||
f_mount(&fs, "", 0);
|
||||
|
||||
<span class="c">/* Create FAT volume with default cluster size */</span>
|
||||
res = f_mkfs("", 0, 0);
|
||||
<span class="c">/* Create FAT volume */</span>
|
||||
res = f_mkfs("", FM_ANY, 0, work, sizeof work);
|
||||
if (res) ...
|
||||
|
||||
<span class="c">/* Register work area */</span>
|
||||
f_mount(&fs, "", 0);
|
||||
|
||||
<span class="c">/* Create a file as new */</span>
|
||||
res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
|
||||
if (res) ...
|
||||
@ -93,15 +98,14 @@ int main (void)
|
||||
<span class="c">/* Close the file */</span>
|
||||
f_close(&fil);
|
||||
|
||||
<span class="c">/* Unregister work area */</span>
|
||||
f_mount(0, "", 0);
|
||||
...
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="para ref">
|
||||
<h4>参照</h4>
|
||||
<p><tt><a href="filename.html#vol">ボリューム管理</a>, <a href="fdisk.html">f_fdisk</a></tt></p>
|
||||
<p><a href="../res/mkfs.xls">ボリューム サイズとフォーマット パラメータ</a>, <a href="filename.html#vol">ボリューム管理</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -37,9 +37,10 @@ FRESULT f_open (
|
||||
<tr><td>FA_READ</td><td>読み出しモードで開きます。読み書きする場合は<tt>FA_WRITE</tt>と共に指定します。</td></tr>
|
||||
<tr><td>FA_WRITE</td><td>書き込みモードで開きます。読み書きする場合は<tt>FA_READ</tt>と共に指定します。</td></tr>
|
||||
<tr><td>FA_OPEN_EXISTING</td><td>既存のファイルを開きます。ファイルが無いときはエラーになります。(デフォルト)</td></tr>
|
||||
<tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。追記の場合は、この方法でオープンした後、<a href="lseek.html"><tt>f_lseek</tt></a>関数でファイルの最後尾に移動してください。</td></tr>
|
||||
<tr><td>FA_CREATE_NEW</td><td>ファイルを作成します。同名のファイルがある場合は、<tt>FR_EXIST</tt>で失敗します。</td></tr>
|
||||
<tr><td>FA_CREATE_ALWAYS</td><td>ファイルを作成します。同名のファイルがある場合は、サイズを0にしてから開きます。</td></tr>
|
||||
<tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。</td></tr>
|
||||
<tr><td>FA_OPEN_APPEND</td><td><tt>FA_OPEN_ALWAYS</tt>と同じですが、リード/ライト ポインタはファイルの最後尾にセットされます。</td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
@ -75,13 +76,13 @@ FRESULT f_open (
|
||||
<h4>解説</h4>
|
||||
<p>既存のファイルを開いたり、新しいファイルを作成します。関数が成功するとファイル オブジェクトが作成され、以降そのファイルに対するアクセスに使用します。ファイルを閉じるときは、<a href="close.html"><tt>f_close</tt></a>関数を使用します。何らかの変更が行われたファイルがその後正しく閉じられなかった場合、そのファイルが破損する場合があります。</p>
|
||||
<p>既に開かれているファイルを開く必要がある場合は、<a href="appnote.html#dup">多重アクセス制御</a>を参照してください。しかし、一つのファイルに対する書き込みモードを含む重複オープンは常に禁止です。</p>
|
||||
<p>ファイル アクセスを開始する前に、<a href="mount.html"><tt>f_mount</tt></a>関数を使ってそれぞれの論理ドライブにワーク エリア(ファイル システム オブジェクト)を与える必要があります。この初期化の後、その論理ドライブに対して全てのファイル関数が使えるようになります。</p>
|
||||
<p>ファイル アクセスを開始する前に、<a href="mount.html"><tt>f_mount</tt></a>関数を使ってそれぞれの論理ドライブにワーク エリア(ファイル システム オブジェクト)を与える必要があります。この初期化の後、その論理ドライブに対して全てのファイル関数が使えるようになります。<tt>f_mkfs</tt>関数と<tt>f_fdsk</tt>関数は、ワークエリア無しでも使えます。</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="para comp">
|
||||
<h4>対応情報</h4>
|
||||
<p>全ての構成で使用可能です。<tt>_FS_READONLY == 1</tt>のときは、<tt>FA_WRITE, FA_CREATE_ALWAYS, FA_CREATE_NEW, FA_OPEN_ALWAYS</tt>の各フラグはサポートされません。</p>
|
||||
<p>全ての構成で使用可能です。<tt>_FS_READONLY == 1</tt>のときは、<tt>FA_READ</tt>と<tt>FA_OPEN_EXISTING</tt>以外の各フラグはサポートされません。</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -65,8 +65,9 @@
|
||||
<dt id="ma">FR_MKFS_ABORTED</dt>
|
||||
<dd><tt>f_mkfs</tt>関数の処理が開始前に中断された。原因としては次のようなことが考えられます。
|
||||
<ul>
|
||||
<li>ボリュームが小さすぎる。</li>
|
||||
<li>FATタイプの計算に矛盾が見つかった。クラスタ数がFATタイプの境界付近になるときに発生する場合があります。</li>
|
||||
<li>指定されたパラメータでのフォーマットが不可能。</li>
|
||||
<li>ボリュームのサイズが小さすぎる。</li>
|
||||
<li>与えられたワークエリアが小さすぎる。</li>
|
||||
<li>その論理ドライブに対応する区画が見つからなかった。(関連オプション: <tt><a href="config.html#multi_partition">_MULTI_PARTITION</a></tt>)</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
@ -26,9 +26,9 @@ FRESULT f_readdir (
|
||||
<h4>引数</h4>
|
||||
<dl class="par">
|
||||
<dt>dp</dt>
|
||||
<dd><tt>f_opendir</tt>関数で作成された有効なディレクトリ オブジェクトへのポインタ、またはヌル ポインタを指定します。</dd>
|
||||
<dd><tt>f_opendir</tt>関数で作成された有効なディレクトリ オブジェクトへのポインタを指定します。</dd>
|
||||
<dt>fno</dt>
|
||||
<dd>読み出したディレクトリ項目を格納する<a href="sfileinfo.html">ファイル情報構造体</a>へのポインタを指定します。</dd>
|
||||
<dd>読み出したディレクトリ項目を格納する<a href="sfileinfo.html">ファイル情報構造体</a>へのポインタ、またはヌル ポインタを指定します。</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
@ -86,7 +86,8 @@ FRESULT scan_files (
|
||||
res = f_readdir(&dir, &fno); <span class="c">/* ディレクトリ項目を1個読み出す */</span>
|
||||
if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* エラーまたは項目無しのときは抜ける */</span>
|
||||
if (fno.fattrib & AM_DIR) { <span class="c">/* ディレクトリ */</span>
|
||||
sprintf(&path[i = strlen(path)], "/%s", fno.fname);
|
||||
i = strlen(path);
|
||||
sprintf(&path[i], "/%s", fno.fname);
|
||||
res = scan_files(path); <span class="c">/* 一つ下へ */</span>
|
||||
if (res != FR_OK) break;
|
||||
path[i] = 0;
|
||||
@ -106,7 +107,7 @@ int main (void)
|
||||
FRESULT res;
|
||||
|
||||
|
||||
res = f_mount(&fs, "", 1);
|
||||
res = f_mount(&fs, "", 1);
|
||||
if (res == FR_OK) {
|
||||
strcpy(buff, "/");
|
||||
res = scan_files(buff);
|
||||
|
||||
@ -54,7 +54,7 @@ FRESULT f_stat (
|
||||
|
||||
<div class="para desc">
|
||||
<h4>解説</h4>
|
||||
<p>指定されたファイルまたはサブ ディレクトリの存在を調べます。存在しない場合は、<tt>FR_NO_FILE</tt>が帰ります。存在する場合は<tt>FR_OK</tt>が帰り、ファイル情報構造体にそれ関する情報(サイズ、タイムスタンプ、属性および短いファイル名)がストアされます。</p>
|
||||
<p>指定されたファイルまたはサブ ディレクトリの存在を調べます。存在しない場合は、<tt>FR_NO_FILE</tt>が帰ります。存在する場合は<tt>FR_OK</tt>が帰り、それ関する情報(サイズ、タイムスタンプおよび属性)がファイル情報構造体にストアされます。</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*------------------------------------------------------------/
|
||||
/ Open or create a file in append mode
|
||||
/ (This function was sperseded by FA_OPEN_APPEND at FatFs R0.12a)
|
||||
/------------------------------------------------------------*/
|
||||
|
||||
FRESULT open_append (
|
||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
BIN
doc/res/f7.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
BIN
doc/res/mkfs.xls
Normal file
BIN
doc/res/modules.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
@ -10,7 +10,7 @@ R0.00 (February 26, 2006)
|
||||
|
||||
R0.01 (April 29, 2006)
|
||||
|
||||
First stable version.
|
||||
The first release.
|
||||
|
||||
|
||||
|
||||
@ -246,9 +246,22 @@ R0.11a (September 05, 2015)
|
||||
|
||||
R0.12 (April 12, 2016)
|
||||
|
||||
Added support of exFAT file system. (_FS_EXFAT)
|
||||
Added support for exFAT file system. (_FS_EXFAT)
|
||||
Added f_expand(). (_USE_EXPAND)
|
||||
Changed some members in FINFO structure and behavior of f_readdir().
|
||||
Added an option _USE_CHMOD and removed an option _WORD_ACCESS.
|
||||
Fixed errors in the case conversion teble of Unicode (cc*.c).
|
||||
Added an option _USE_CHMOD.
|
||||
Removed an option _WORD_ACCESS.
|
||||
Fixed errors in the case conversion table of Unicode (cc*.c).
|
||||
|
||||
|
||||
|
||||
R0.12a (July 10, 2016)
|
||||
|
||||
Added support for creating exFAT volume with some changes of f_mkfs().
|
||||
Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed.
|
||||
f_forward() is available regardless of _FS_TINY.
|
||||
Fixed f_mkfs() creates wrong volume.
|
||||
Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
|
||||
Fixed wrong memory read in create_name().
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
FatFs Module Source Files R0.12
|
||||
FatFs Module Source Files R0.12a
|
||||
|
||||
|
||||
FILES
|
||||
|
||||
53
src/diskio.c
@ -8,14 +8,11 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h" /* FatFs lower layer API */
|
||||
#include "usbdisk.h" /* Example: Header file of existing USB MSD control module */
|
||||
#include "atadrive.h" /* Example: Header file of existing ATA harddisk control module */
|
||||
#include "sdcard.h" /* Example: Header file of existing MMC/SDC contorl module */
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define ATA 0 /* Example: Map ATA harddisk to physical drive 0 */
|
||||
#define MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
|
||||
#define USB 2 /* Example: Map USB MSD to physical drive 2 */
|
||||
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
|
||||
#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
|
||||
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
@ -30,21 +27,21 @@ DSTATUS disk_status (
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case ATA :
|
||||
result = ATA_disk_status();
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case MMC :
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case USB :
|
||||
case DEB_USB :
|
||||
result = USB_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
@ -68,21 +65,21 @@ DSTATUS disk_initialize (
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case ATA :
|
||||
result = ATA_disk_initialize();
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case MMC :
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case USB :
|
||||
case DEV_USB :
|
||||
result = USB_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
@ -101,7 +98,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, /* Sector address in LBA */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
@ -109,16 +106,16 @@ DRESULT disk_read (
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case ATA :
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
|
||||
result = ATA_disk_read(buff, sector, count);
|
||||
result = RAM_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
|
||||
result = MMC_disk_read(buff, sector, count);
|
||||
@ -127,7 +124,7 @@ DRESULT disk_read (
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
|
||||
result = USB_disk_read(buff, sector, count);
|
||||
@ -149,7 +146,7 @@ DRESULT disk_read (
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
@ -157,16 +154,16 @@ DRESULT disk_write (
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case ATA :
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
|
||||
result = ATA_disk_write(buff, sector, count);
|
||||
result = RAM_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
|
||||
result = MMC_disk_write(buff, sector, count);
|
||||
@ -175,7 +172,7 @@ DRESULT disk_write (
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
|
||||
result = USB_disk_write(buff, sector, count);
|
||||
@ -204,19 +201,19 @@ DRESULT disk_ioctl (
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case ATA :
|
||||
case DEV_RAM :
|
||||
|
||||
// Process of the command for the ATA drive
|
||||
// Process of the command for the RAM drive
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
case DEV_MMC :
|
||||
|
||||
// Process of the command for the MMC/SD card
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
case DEV_USB :
|
||||
|
||||
// Process of the command the USB drive
|
||||
|
||||
|
||||
102
src/ff.h
@ -1,11 +1,13 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module include R0.12 (C)ChaN, 2016
|
||||
/----------------------------------------------------------------------------/
|
||||
/ FatFs module is a free software that opened under license policy of
|
||||
/ following conditions.
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT file system module R0.12a /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2016, 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.
|
||||
/
|
||||
@ -13,11 +15,11 @@
|
||||
/ 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.
|
||||
/---------------------------------------------------------------------------*/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _FATFS
|
||||
#define _FATFS 88100 /* Revision ID */
|
||||
#define _FATFS 80186 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -25,6 +27,7 @@ extern "C" {
|
||||
|
||||
#include "integer.h" /* Basic integer types */
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if _FATFS != _FFCONF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
@ -52,7 +55,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#if _LFN_UNICODE /* Unicode string */
|
||||
#if _LFN_UNICODE /* Unicode (UTF-16) string */
|
||||
#if _USE_LFN == 0
|
||||
#error _LFN_UNICODE must be 0 at non-LFN cfg.
|
||||
#endif
|
||||
@ -61,14 +64,25 @@ typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#endif
|
||||
|
||||
#else /* ANSI/OEM string */
|
||||
#ifndef _INC_TCHAR
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables */
|
||||
|
||||
#if _FS_EXFAT
|
||||
#if _USE_LFN == 0
|
||||
#error LFN must be enabled when enable exFAT
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#else
|
||||
typedef DWORD FSIZE_t;
|
||||
#endif
|
||||
|
||||
|
||||
@ -87,6 +101,9 @@ typedef struct {
|
||||
#if _MAX_SS != _MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if _USE_LFN != 0
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if _FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer */
|
||||
#endif
|
||||
@ -117,19 +134,6 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables and object identifier */
|
||||
|
||||
#if _FS_EXFAT
|
||||
#if _USE_LFN == 0
|
||||
#error LFN must be enabled when enable exFAT
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#else
|
||||
typedef DWORD FSIZE_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Object ID and allocation information (_FDID) */
|
||||
|
||||
typedef struct {
|
||||
@ -159,14 +163,14 @@ typedef struct {
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fprt is 0) */
|
||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
|
||||
#endif
|
||||
#if _USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
#endif
|
||||
#if !_FS_TINY
|
||||
BYTE buf[_MAX_SS]; /* File private data read/write window */
|
||||
@ -183,10 +187,9 @@ typedef struct {
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE* fn; /* Pointer to the SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if _USE_LFN != 0
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
WCHAR* lfn; /* Pointer to the LFN working buffer */
|
||||
#endif
|
||||
#if _USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
@ -229,7 +232,7 @@ typedef enum {
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
@ -244,11 +247,11 @@ typedef enum {
|
||||
|
||||
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 */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of a file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
@ -258,8 +261,8 @@ FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of the file/dir */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
@ -269,8 +272,8 @@ 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_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
|
||||
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 */
|
||||
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 */
|
||||
@ -323,40 +326,37 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access control and file status flags (FIL.flag) */
|
||||
|
||||
/* File access mode and open method flags (3rd argument of f_open) */
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define _FA_MODIFIED 0x20
|
||||
#define _FA_DIRTY 0x40
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
|
||||
/* FAT sub type (FATFS.fs_type) */
|
||||
/* Format options (2nd argument of f_mkfs) */
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
|
||||
/* File attribute bits for directory entry */
|
||||
|
||||
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_MASK 0x3F /* Mask of defined bits */
|
||||
|
||||
|
||||
/* Fast seek controls */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
15
src/ffconf.h
@ -1,8 +1,8 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module configuration file R0.12 (C)ChaN, 2016
|
||||
/ FatFs - FAT file system module configuration file
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _FFCONF 88100 /* Revision ID */
|
||||
#define _FFCONF 80186 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
@ -62,8 +62,7 @@
|
||||
|
||||
|
||||
#define _USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable)
|
||||
/ To enable it, also _FS_TINY need to be 1. */
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
@ -118,13 +117,13 @@
|
||||
|
||||
|
||||
#define _LFN_UNICODE 0
|
||||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
|
||||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16)
|
||||
/ To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
|
||||
/ This option also affects behavior of string I/O functions. */
|
||||
|
||||
|
||||
#define _STRF_ENCODE 3
|
||||
/* When _LFN_UNICODE == 1, this option selects the character encoding on the file to
|
||||
/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to
|
||||
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
|
||||
/
|
||||
/ 0: ANSI/OEM
|
||||
@ -153,7 +152,7 @@
|
||||
|
||||
|
||||
#define _STR_VOLUME_ID 0
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
|
||||
/* _STR_VOLUME_ID switches string support of volume ID.
|
||||
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
|
||||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
|
||||
@ -217,7 +216,7 @@
|
||||
|
||||
|
||||
#define _FS_NORTC 0
|
||||
#define _NORTC_MON 3
|
||||
#define _NORTC_MON 1
|
||||
#define _NORTC_MDAY 1
|
||||
#define _NORTC_YEAR 2016
|
||||
/* The option _FS_NORTC switches timestamp functiton. If the system does not have
|
||||
|
||||