fatsfs v0.10a Jan 15,2014:

- Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
- Added a configuration option of minimum sector size. (_MIN_SS)
- 2nd argument of f_rename() can have a drive number and it will be ignored.
- Fixed f_mount() with forced mount fails when drive number is >= 1.
- Fixed f_close() invalidates the file object without volume lock.
- Fixed f_closedir() returns but the volume lock is left acquired.
- Fixed creation of an entry with LFN fails on too many SFN collisions.
This commit is contained in:
savelij13 2025-09-11 10:01:14 +03:00
parent f9a05f6eda
commit 93faa45738
63 changed files with 995 additions and 532 deletions

View File

@ -42,6 +42,7 @@
<h3>Application Interface</h3>
<p>FatFs module provides following functions to the applications. In other words, this list describes what FatFs can do to access the FAT volumes.</p>
<ul>
<li><a href="en/mount.html">f_mount</a> - Register/Unregister a work area</li>
<li><a href="en/open.html">f_open</a> - Open/Create a file</li>
<li><a href="en/close.html">f_close</a> - Close an open file</li>
<li><a href="en/read.html">f_read</a> - Read file</li>
@ -65,7 +66,6 @@
<li><a href="en/getfree.html">f_getfree</a> - Get free clusters</li>
<li><a href="en/getlabel.html">f_getlabel</a> - Get volume label</li>
<li><a href="en/setlabel.html">f_setlabel</a> - Set volume label</li>
<li><a href="en/mount.html">f_mount</a> - Register/Unregister a work area</li>
<li><a href="en/mkfs.html">f_mkfs</a> - Create a file system on the drive</li>
<li><a href="en/fdisk.html">f_fdisk</a> - Divide a physical drive</li>
<li><a href="en/gets.html">f_gets</a> - Read a string</li>
@ -82,10 +82,10 @@
<div class="para">
<h3>Disk I/O Interface</h3>
<p>Since the FatFs module is completely separated from disk I/O layer, it requires following functions to access the physical media. When O/S related feature is enabled, it will require process/memory functions in addition. However the low level disk I/O module is not a part of FatFs module, so that it must be provided by user. The sample implementations are also available in the downloads.</p>
<p>Since the FatFs module is completely separated from disk I/O layer, it requires following functions to access the storage device. When O/S related feature is enabled, it will require process/memory functions in addition. However the low level disk I/O module is not a part of FatFs module, so that it must be provided by user. The sample implementations are also available in the downloads.</p>
<ul>
<li><a href="en/dinit.html">disk_initialize</a> - Initialize disk drive</li>
<li><a href="en/dstat.html">disk_status</a> - Get disk status</li>
<li><a href="en/dstat.html">disk_status</a> - Get device status</li>
<li><a href="en/dinit.html">disk_initialize</a> - Initialize device</li>
<li><a href="en/dread.html">disk_read</a> - Read sector(s)</li>
<li><a href="en/dwrite.html">disk_write</a> - Write sector(s)</li>
<li><a href="en/dioctl.html">disk_ioctl</a> - Control device dependent features</li>
@ -99,7 +99,7 @@
<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><a href="http://elm-chan.org/fsw/ff/bd/"><em>FatFs User Forum</em></a></li>
<li>Read first: <a href="en/appnote.html">FatFs module application note</a> <span class="mfd">October 2, 2013</span></li>
<li>Read first: <a href="en/appnote.html">FatFs module application note</a></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://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="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FAT32 Specification by Microsoft</a> (The reference document on FAT file system)</li>
@ -107,12 +107,11 @@
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to Use MMC/SDC</a></li>
<li><a href="img/rwtest.png">Benchmark 1</a> (ATmega64/9.2MHz with MMC via SPI, HDD/CFC via GPIO)</li>
<li><a href="img/rwtest2.png">Benchmark 2</a> (LPC2368/72MHz with MMC via MCI)</li>
<li><a href="http://members.jcom.home.ne.jp/felm/fd.mp4">Demo movie of an application</a> (this project is in ffsample.zip/lpc23xx)</li>
</ul>
</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">Go to FatFs home page</a></p>
</body>
</html>

View File

@ -41,6 +41,7 @@
<h3>上位レイヤ・インターフェース</h3>
<p>FatFsモジュールは、アプリケーション・レイヤに対し、次のファイル操作関数(API)を提供します。つまり、このリストはFatFsにできることをシンプルに示しています。</p>
<ul>
<li><a href="ja/mount.html">f_mount</a> - ワークエリアの登録・削除</li>
<li><a href="ja/open.html">f_open</a> - ファイルのオープン・作成</li>
<li><a href="ja/close.html">f_close</a> - ファイルのクローズ</li>
<li><a href="ja/read.html">f_read</a> - ファイルの読み出し</li>
@ -49,22 +50,21 @@
<li><a href="ja/truncate.html">f_truncate</a> - ファイル・サイズの切り詰め</li>
<li><a href="ja/sync.html">f_sync</a> - キャッシュされたデータのフラッシュ</li>
<li><a href="ja/forward.html">f_forward</a> - ファイル・データをストリーム関数に転送</li>
<li><a href="ja/stat.html">f_stat</a> - ファイル/サブディレクトリの存在チェックと情報の取得</li>
<li><a href="ja/stat.html">f_stat</a> - ファイル/サブディレクトリの存在チェックと情報の取得</li>
<li><a href="ja/opendir.html">f_opendir</a> - ディレクトリのオープン</li>
<li><a href="ja/closedir.html">f_closedir</a> - ディレクトリのクローズ</li>
<li><a href="ja/readdir.html">f_readdir</a> - ディレクトリの読み出し</li>
<li><a href="ja/mkdir.html">f_mkdir</a> - サブディレクトリの作成</li>
<li><a href="ja/unlink.html">f_unlink</a> - ファイル/サブディレクトリの削除</li>
<li><a href="ja/chmod.html">f_chmod</a> - ファイル/サブディレクトリの属性の変更</li>
<li><a href="ja/utime.html">f_utime</a> - ファイル/サブディレクトリのタイムスタンプの変更</li>
<li><a href="ja/rename.html">f_rename</a> - ファイル/サブディレクトリの名前変更・移動</li>
<li><a href="ja/mkdir.html">f_mkdir</a> - サブディレクトリの作成</li>
<li><a href="ja/unlink.html">f_unlink</a> - ファイル/サブディレクトリの削除</li>
<li><a href="ja/chmod.html">f_chmod</a> - ファイル/サブディレクトリの属性の変更</li>
<li><a href="ja/utime.html">f_utime</a> - ファイル/サブディレクトリのタイムスタンプの変更</li>
<li><a href="ja/rename.html">f_rename</a> - ファイル/サブディレクトリの名前変更・移動</li>
<li><a href="ja/chdir.html">f_chdir</a> - カレント・ディレクトリの変更</li>
<li><a href="ja/chdrive.html">f_chdrive</a> - カレント・ドライブの変更</li>
<li><a href="ja/getcwd.html">f_getcwd</a> - カレント・ディレクトリの取得</li>
<li><a href="ja/getfree.html">f_getfree</a> - ボリューム空き領域の取得</li>
<li><a href="ja/getlabel.html">f_getlabel</a> - ボリューム・ラベルの取得</li>
<li><a href="ja/setlabel.html">f_setlabel</a> - ボリューム・ラベルの設定</li>
<li><a href="ja/mount.html">f_mount</a> - ワークエリアの登録・削除</li>
<li><a href="ja/mkfs.html">f_mkfs</a> - 論理ドライブのフォーマット</li>
<li><a href="ja/fdisk.html">f_fdisk</a> - 物理ドライブの分割</li>
<li><a href="ja/gets.html">f_gets</a> - 文字列の読み出し</li>
@ -81,13 +81,13 @@
<div class="para">
<h3>下位レイヤ・インターフェース</h3>
<p>FatFsモジュールは、単なるファイル・システム・レイヤなので、メディア制御レイヤは含まれません。使用するメディアに対応した制御関数は、ユーザによって提供される必要があります。FatFsモジュールは、下位レイヤに対し少なくとも次のインターフェースを要求します。OS関連機能を有効にしたときは、加えてプロセス/メモリ関連関数も必要になります。サンプル・プロジェクトに下位レイヤの実装例を示します。</p>
<p>FatFsモジュールは、単なるファイル・システム・レイヤなので、ストレージ・デバイス制御レイヤは含まれません。使用するストレージに対応した制御関数は、ユーザによって提供される必要があります。FatFsモジュールは、下位レイヤに対し少なくとも次のインターフェースを要求します。OS関連機能を有効にしたときは、これに加えてプロセス/メモリ関連関数も必要になります。サンプル・プロジェクトに下位レイヤの実装例を示します。</p>
<ul>
<li><a href="ja/dinit.html">disk_initialize</a> - ドライブの初期化</li>
<li><a href="ja/dstat.html">disk_status</a> - ドライブの状態取得</li>
<li><a href="ja/dstat.html">disk_status</a> - デバイスの状態取得</li>
<li><a href="ja/dinit.html">disk_initialize</a> - デバイスの初期化</li>
<li><a href="ja/dread.html">disk_read</a> - データの読み出し</li>
<li><a href="ja/dwrite.html">disk_write</a> - データの書き込み</li>
<li><a href="ja/dioctl.html">disk_ioctl</a> - その他のドライブ制御</li>
<li><a href="ja/dioctl.html">disk_ioctl</a> - その他のデバイス制御</li>
<li><a href="ja/fattime.html">get_fattime</a> - 日付・時刻の取得</li>
</ul>
</div>
@ -98,7 +98,7 @@
<p>FatFsモジュールはフリー・ソフトウェアとして教育・研究・開発用に公開しています。どのような利用目的個人利用から商用まででも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。詳しくはアプリケーション・ートを参照してください。</p>
<ul>
<li><a href="http://elm-chan.org/fsw/ff/bd/"><em>FatFsユーザ・フォーラム</em></a></li>
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール・アプリケーション・ート</a> <span class="mfd">2013. 10. 2</span></li>
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール・アプリケーション・ート</a></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://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="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FATファイル・システム仕様書 by Microsoft</a> (The reference document on FAT file system)</li>
@ -111,6 +111,6 @@
<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ホームページへ</a></p>
</body>
</html>

View File

@ -36,6 +36,9 @@ a.imglnk img {border: 1px solid;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
.ral {text-align: right; }
.lal {text-align: left; }
.cal {text-align: center; }
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}

View File

@ -39,6 +39,9 @@ a.imglnk img {border: 1px solid;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
.ral {text-align: right; }
.lal {text-align: left; }
.cal {text-align: center; }
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}

View File

@ -23,7 +23,7 @@
<li><a href="#fs1">Performance Effective File Access</a></li>
<li><a href="#fs2">Considerations on Flash Memory Media</a></li>
<li><a href="#critical">Critical Section</a></li>
<li><a href="#fs3">Extended Use of APIs</a></li>
<li><a href="#fs3">Extended Use of FatFs API</a></li>
<li><a href="#license">About FatFs License</a></li>
</ol>
<hr>
@ -43,15 +43,17 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<h4>System organizations</h4>
<p>The dependency diagram shown below is a typical configuration of the embedded system with FatFs module.</p>
<p><img src="../img/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="680" height="450" 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 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 in read-only configuration. Following table shows which function is required depends on configuration options.</p>
<table class="lst2">
<tr><th>Function</th><th>Required when:</th><th>Note</th></tr>
<tr><td>disk_initialize<br>disk_status<br>disk_read</td><td>Always</td><td rowspan="5">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
<tr><td>disk_status<br>disk_initialize<br>disk_read</td><td>Always</td><td rowspan="5">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
<tr><td>disk_write<br>get_fattime<br>disk_ioctl (CTRL_SYNC)</td><td>_FS_READONLY == 0</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_COUNT)<br>disk_ioctl (GET_BLOCK_SIZE)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS &gt; 512</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS != _MIN_SS</td></tr>
<tr><td>disk_ioctl (CTRL_ERASE_SECTOR)</td><td>_USE_ERASE == 1</td></tr>
<tr><td>ff_convert<br>ff_wtoupper</td><td>_USE_LFN &gt;= 1</td><td>Unicode support functions.<br>Available in option/cc*.c.</td></tr>
<tr><td>ff_cre_syncobj<br>ff_del_syncobj<br>ff_req_grant<br>ff_rel_grant</td><td>_FS_REENTRANT == 1</td><td rowspan="2">O/S dependent functions.<br>Samples available in option/syscall.c.</td></tr>
@ -68,7 +70,7 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<li>File size: Depends on FAT specs. (upto 4G-1 bytes)</li>
<li>Volume size: Depends on FAT specs. (upto 2T bytes at 512 bytes/sector)</li>
<li>Cluster size: Depends on FAT specs. (upto 64K bytes at 512 bytes/sector)</li>
<li>Sector size: Depends on FAT specs. (upto 4K bytes)</li>
<li>Sector size: Depends on FAT specs. (512..4096 bytes)</li>
</ul>
</div>
@ -76,34 +78,34 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<h3>Memory Usage</h3>
<table class="lst2">
<tr><th></th><th>ARM7<small><br>32bit</small></th><th>ARM7<small><br>Thumb</small></th><th>CM3<small><br>Thumb-2</small></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>RL78</th><th>V850ES</th><th>SH-2A</th><th>RX600</th><th>IA-32</th></tr>
<tr><td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>VC6</td></tr>
<tr><td>_WORD_ACCESS</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>
<!-- *ARM *Thumb *CM3 *AVR *H8 *PIC24 *RL78 *V850ES *SH-2A *RX600 *IA-32 -->
<tr class="lst3"><td>text (Full, R/W)</td><td>10591</td><td>7119</td><td>6565</td><td>13240</td><td>10864</td><td>11619</td><td>13192</td><td>8031</td><td>8960</td><td>5977</td><td>7856</td></tr>
<tr> <td>text (Min, R/W)</td> <td>6671</td><td>4595</td><td>4293</td> <td>8512</td> <td>7232</td> <td>7674</td> <td>9033</td><td>5235</td><td>5768</td><td>3923</td><td>5129</td></tr>
<tr> <td>text (Full, R/O)</td> <td>4695</td><td>3121</td><td>2861</td> <td>6218</td> <td>5162</td> <td>5466</td> <td>6418</td><td>3799</td><td>3964</td><td>2847</td><td>3687</td></tr>
<tr> <td>text (Min, R/O)</td> <td>3523</td><td>2463</td><td>2275</td> <td>4558</td> <td>4058</td> <td>4212</td> <td>4948</td><td>2959</td><td>3096</td><td>2199</td><td>2857</td></tr>
<tr> <td>bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr> <td>Work area<br>(_FS_TINY == 0)</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td></tr>
<tr class="cal"> <td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>VC6</td></tr>
<tr class="cal"> <td>_WORD_ACCESS</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>
<!-- ARM Thumb CM3 AVR H8 PIC24 RL78 V850ES SH-2A RX600 IA-32 -->
<tr class="lst3 ral"><td class="cal">text (Full, R/W)</td><td>10675</td><td>7171</td><td>6617</td><td>13355</td><td>10940</td><td>11722</td><td>13262</td><td>8113</td><td>9048</td><td>6032</td><td>7952</td></tr>
<tr class="ral"> <td class="cal">text (Min, R/W)</td> <td>6727</td><td>4631</td><td>4331</td> <td>8569</td> <td>7262</td> <td>7720</td> <td>9088</td><td>5287</td><td>5800</td><td>3948</td><td>5183</td></tr>
<tr class="ral"> <td class="cal">text (Full, R/O)</td> <td>4731</td><td>3147</td><td>2889</td> <td>6235</td> <td>5170</td> <td>5497</td> <td>6482</td><td>3833</td><td>3972</td><td>2862</td><td>3719</td></tr>
<tr class="ral"> <td class="cal">text (Min, R/O)</td> <td>3559</td><td>2485</td><td>2295</td> <td>4575</td> <td>4064</td> <td>4240</td> <td>5019</td><td>2993</td><td>3104</td><td>2214</td><td>2889</td></tr>
<tr class="ral"> <td class="cal">bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr class="ral"> <td class="cal">Work area<br>(_FS_TINY == 0)</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td></tr>
<tr class="ral"> <td class="cal">Work area<br>(_FS_TINY == 1)</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td></tr>
</table>
<p>These are the memory usage on some target systems with following condition. The memory sizes are in unit of byte, <em>V</em> denotes number of volumes and <em>F</em> denotes number of open files. All samples are optimezed in code size.</p>
<pre>
FatFs R0.10 options:
_FS_READONLY 0 (R/W), 1 (R/O)
_FS_MINIMIZE 0 (Full function), 3 (Minimized function)
FatFs R0.10a options:
_FS_READONLY 0 (R/W) or 1 (R/O)
_FS_MINIMIZE 0 (Full function) or 3 (Minimized function)
_USE_STRFUNC 0 (Disable string functions)
_USE_MKFS 0 (Disable f_mkfs function)
_USE_FORWARD 0 (Disable f_forward function)
_USE_FASTSEEK 0 (Disable fast seek feature)
_CODE_PAGE 932 (Japanese Shift-JIS)
_USE_LFN 0 (Disable LFN)
_USE_LFN 0 (Disable LFN feature)
_MAX_SS 512 (Fixed sector size)
_FS_RPATH 0 (Disable relative path feature)
_FS_LABEL 0 (Disable volume label functions)
_VOLUMES V (Number of logical drives to be used)
_MULTI_PARTITION 0 (Single partition per drive)
_FS_REENTRANT 0 (Disable reentrancy)
_FS_REENTRANT 0 (Disable thread safe)
_FS_LOCK 0 (Disable file lock control)
</pre>
</div>
@ -178,8 +180,8 @@ _FS_LOCK 0 (Disable file lock control)
<div class="para" id="dup">
<h3>Duplicated File Access</h3>
<p>FatFs module does not support the shareing controls of duplicated file access in default. It is permitted when open method to a file is only read mode. The duplicated open in write mode to a file is always prohibited and open file must not be renamed, deleted, or the FAT structure on the volume can be collapted.</p>
<p>The file shareing control can also be available when <tt>_FS_LOCK</tt> is set to 1 or grater. The value specifies the number of files to manage simultaneously. In this case, if any open, rename or remove that violating the file shareing rule that described above is attempted, the file function will fail with <tt>FR_LOCKED</tt>. If number of open objects gets larger than <tt>_FS_LOCK</tt>, the <tt>f_open()/f_opendir()</tt> function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</p>
<p>FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed and deleted. A violation of these rules can cause data colluption.</p>
<p>The file lock control can also be available by <tt>_FS_LOCK</tt> option. The value defines the number of open objects to manage simultaneously. In this case, if any open, rename or remove that violating the file shareing rule that described above is attempted, the file function will fail with <tt>FR_LOCKED</tt>. If number of open files and sub-directories gets larger than <tt>_FS_LOCK</tt>, the open function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</p>
</div>
<div class="para" id="fs1">
@ -214,7 +216,7 @@ Figure 6. Comparison between Multiple/Single Sector Write<br>
<div class="para" id="critical">
<h3>Critical Section</h3>
<p>If a write operation to the FAT volume is interrupted due to any accidental failure, such as sudden blackout, incorrect disk removal and unrecoverable disk error, the FAT structure on the volume can be collapted. Following images shows the critical section of the FatFs module.</p>
<p>If a write operation to the FAT volume is interrupted due to any accidental failure, such as sudden blackout, incorrect disk 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">
@ -226,7 +228,7 @@ Figure 5. Minimized critical section<br>
<br class="clr">
<p>An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.</p>
<ul>
<li>The file data being rewrited is collapted.</li>
<li>The file data being rewrited is collapsed.</li>
<li>The file being appended returns initial state.</li>
<li>The file created as new is gone.</li>
<li>The file created as new or overwritten remains but no content.</li>
@ -236,26 +238,27 @@ Figure 5. Minimized critical section<br>
</div>
<div class="para" id="fs3">
<h3>Extended Use of APIs</h3>
<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></li>
<li><a href="../img/app4.c">Function/Compatible checker for low level disk I/O module</a></li>
</ol>
</div>
<div class="para" id="license">
<h3>About FatFs License</h3>
<p>This is a copy of the FatFs license document that included in the source codes.</p>
<p>FatFs has being developped as a personal project of author, ChaN. It is free from the code anyone else wrote. 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.10 (C)ChaN, 2013
/ FatFs - FAT file system module R0.10a (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
/ developments under license policy of following trems.
/
/ Copyright (C) 2013, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
@ -263,7 +266,7 @@ Figure 5. Minimized critical section<br>
/ * Redistributions of source code must retain the above copyright notice.
/
/-----------------------------------------------------------------------------/</pre>
<p>Therefore FatFs license is one of the BSD-style license but there is a significant feature. Because FatFs is for embedded projects, the conditions for redistributions in binary form, such as embedded code, hex file and binary library, are not specified to increase its usability. The documentation of the distributions need not include about FatFs and its license document, and it may also. This is equivalent to the BSD 1-Clause License. Of course FatFs is compatible with the projects under GNU GPL. When redistribute the FatFs with any modification, the license can also be changed to GNU GPL or BSD-style license.</p>
<p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. Because FatFs is for embedded projects, the conditions of redistributions in binary form, such as embedded code, hex file, binary library and any form without source code, are not specified in order to extend usability to commercial use. The documentation of the distributions need not include about FatFs and its license document, and it may also. This is equivalent to the BSD 1-Clause License. Of course FatFs is compatible with the projects under GNU GPL. When redistribute the FatFs with any modification, the license can also be changed to GNU GPL or BSD-style license.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -39,7 +39,7 @@ FRESULT f_chmod (
</table>
</dd>
<dt>mask</dt>
<dd>Attribute mask that specifies which attribute is changed. The specified aattributes are set or cleard.</dd>
<dd>Attribute mask that specifies which attribute is changed. The specified attributes are set or cleard and others are left unchanged.</dd>
</dl>
</div>
@ -79,7 +79,7 @@ FRESULT f_chmod (
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Set read-only flag, clear archive flag and others are retained. */</span>
<span class="c">/* Set read-only flag, clear archive flag and others are left unchanged. */</span>
f_chmod("file.txt", AR_RDO, AR_RDO | AR_ARC);
</pre>
</div>

View File

@ -43,8 +43,8 @@ FRESULT f_closedir (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_closedir()</tt> function closes an open directory object. After the function succeeded, the file object is no longer valid and it can be discarded.</p>
<p>Note that the directory object can also be discarded without this process unless <tt>_FS_LOCK</tt> option is not enabled. However it is not recommended for future compatibility.</p>
<p>The <tt>f_closedir()</tt> function closes an open directory object. After the function succeeded, the directory object is no longer valid and it can be discarded.</p>
<p>Note that the directory object can also be discarded without this process if <tt>_FS_LOCK</tt> option is not enabled. However it is not recommended for future compatibility.</p>
</div>

View File

@ -38,7 +38,7 @@ DSTATUS disk_initialize (
<div class="para desc">
<h4>Description</h4>
<p>This function initializes a physical drive and put it ready to generic read/write data. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleared.</p>
<p><em>Application program MUST NOT call this function while FatFs is in use, or FAT structure on the volume can be corrapted. To re-initialize the file system, use <tt>f_mount()</tt> function instead.</em> This function is called on volume mount process by FatFs module to manage the media change.</p>
<p><em>Application program MUST NOT call this function, or FAT structure on the volume can be broken. To re-initialize the file system, use <tt>f_mount()</tt> function instead.</em> This function is called on volume mount process by FatFs module to manage the media change.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -27,11 +27,11 @@ DRESULT disk_ioctl (
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the drive number (0-9).</dd>
<dd>Physical drive number to identify the target device.</dd>
<dt>cmd</dt>
<dd>Specifies the command code.</dd>
<dd>Command code.</dd>
<dt>buff</dt>
<dd>Pointer to the parameter buffer depends on the command code. Set NULL if not used.</dd>
<dd>Pointer to the parameter depends on the command code. Do not care if no parameter to be passed.</dd>
</dl>
</div>
@ -42,28 +42,34 @@ DRESULT disk_ioctl (
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any error occured.</dd>
<dd>An error occured.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid command code or parameter.</dd>
<dd>The command code or parameter is invalid.</dd>
<dt>RES_NOTRDY</dt>
<dd>The disk drive has not been initialized.</dd>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The FatFs module uses only device independent commands described below. Any device dependent function is not used.</p>
<p>The FatFs module uses only device independent commands described below. Any device dependent functions and user defined functions are not used.</p>
<table class="lst">
<tr><th>Command</th><th>Description</th></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the disk drive has finished pending write process. When the disk I/O module has a write back cache, flush the dirty sector immediately. This command is not used in read-only configuration.</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the drive into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. This command is not used in fixed sector size configuration, <tt>_MAX_SS</tt> is 512.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Returns number of available sectors on the drive into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by only <tt>f_mkfs()</tt> function to determine the volume size to be created.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or disk devices. This command is used by only <tt>f_mkfs()</tt> function and it attempts to align data area to the erase block boundary.</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>Erases a part of the flash memory specified by a <tt>DWORD</tt> array {&lt;start sector&gt;, &lt;end sector&gt;} pointed by <tt class="arg">buff</tt>. This is similar command to Trim command of ATA command set. When this feature is not supported or not a flash memory media, this command has no effect. The FatFs does not check the result code and the file function is not affected even if the sectors are not erased well. This command is called on removing a cluster chain when <tt>_USE_ERASE</tt> is 1.</td></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the device has finished pending write process. If the disk I/O module has a write back cache, the dirty buffers must be written back to the media immediately. If each write operation to the media is completed within the <tt>disk_write()</tt> function, nothing to do for this command.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Returns number of available sectors on the drive into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by only <tt>f_mkfs()</tt> and <tt>f_fdisk()</tt> function to determine the volume/partition size to be created.</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the media into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. Valid return values of this command are 512, 1024, 2048 or 4096. This command is never used at fixed sector size configuration, <tt>_MAX_SS == _MIN_SS</tt>, and it must work at that sector size.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is from 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or disk media. This command is used by only <tt>f_mkfs()</tt> function and it attempts to align data area to the erase block boundary.</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>Erases a part of the flash memory specified by a <tt>DWORD</tt> array {&lt;start sector&gt;, &lt;end sector&gt;} pointed by <tt class="arg">buff</tt>. This is similar command to Trim command of ATA device. When this feature is not supported or not a flash memory media, nothing to do for this command. The FatFs does not check the result code and the file function is not affected even if the sectors ware not erased well. This command is called on removing a cluster chain and <tt>f_mkfs()</tt> function when <tt>_USE_ERASE</tt> is 1.</td></tr>
</table>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This function is not needed when <tt>_FS_READONLY == 1</tt> and <tt>_MAX_SS == _MIN_SS</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>disk_read</h2>
<p>The disk_read function reads sector(s) from the disk drive.</p>
<p>The disk_read function reads sector(s) from the storage device.</p>
<pre>
DRESULT disk_read (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
@ -28,13 +28,13 @@ DRESULT disk_read (
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the physical drive number.</dd>
<dd>Physical drive number to identify the target device.</dd>
<dt>buff</dt>
<dd>Pointer to the <em>byte array</em> to store the read data. The size of buffer must be in sector size * sector count.</dd>
<dd>Pointer to the <em>byte array</em> to store the read data.</dd>
<dt>sector</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dd>Start sector number in logical block address (LBA).</dd>
<dt>count</dt>
<dd>Specifies number of sectors to read. FatFs specifis with 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you may not get good read performance.</dd>
<dd>Number of sectors to read. FatFs specifis it in range of from 1 to 128.</dd>
</dl>
</div>
@ -49,7 +49,7 @@ DRESULT disk_read (
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The disk drive has not been initialized.</dd>
<dd>The device has not been initialized.</dd>
</dl>
</div>
@ -62,6 +62,7 @@ DRESULT disk_read (
<li>For <tt>f_read()</tt>, avoid long read request that includes a whole of sector. - Direct transfer will never occure.</li>
<li>For <tt>f_read(fp, buff, btr, &amp;br)</tt>, make sure that <tt>(((UINT)buff &amp; 3) == (f_tell(fp) &amp; 3))</tt> is true. - Word aligned direct transfer is guaranteed.</li>
</ul>
<p>Generally, a multiple sector transfer request must not be split into single sector transactions to the storage device, or you will not get good read throughput.</p>
</div>

View File

@ -25,21 +25,21 @@ DSTATUS disk_status (
<h4>Parameter</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the physical drive number to be confirmed.</dd>
<dd>Physical drive number to identify the target device.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>The disk status is returned in combination of following flags. FatFs refers only <tt>STA_NOINIT</tt> and <tt>STA_PROTECTED</tt>.</p>
<p>The disk status is returned in combination of following flags. FatFs refers only <tt>STA_NOINIT</tt> and <tt>STA_PROTECT</tt>.</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>Indicates that the disk drive is not initialized. This flag is set on system reset, media removal or failure of <tt>disk_initialize()</tt> function. It is cleared on <tt>disk_initialize()</tt> function succeeded. Media change that occurs asynchronously must be captured and reflect it to the status flags, or auto-mount feature will not work correctly. When media change detection feature is not supported, application program needs to de-initialize the file system object with <tt>f_mount()</tt> function after the media change.</dd>
<dd>Indicates that the device is not initialized. This flag is set on system reset, media removal or failure of <tt>disk_initialize()</tt> function. It is cleared on <tt>disk_initialize()</tt> function succeeded. Media change that occurs asynchronously must be captured and reflect it to the status flags, or auto-mount feature will not work correctly. When media change detection feature is not supported, application program needs to de-initialize the file system object with <tt>f_mount()</tt> function after the media change.</dd>
<dt>STA_NODISK</dt>
<dd>Indicates that no medium in the drive. This is always cleared on fixed disk drive. Note that FatFs does not refer this flag.</dd>
<dt>STA_PROTECTED</dt>
<dd>Indicates that the medium is write protected. This is always cleared on the drive that does not support write protect notch. Not valid while no medium in the drive.</dd>
<dt>STA_PROTECT</dt>
<dd>Indicates that the medium is write protected. This is always cleared on the drive without write protect feature. Not valid while no medium in the drive.</dd>
</dl>
</div>

View File

@ -13,12 +13,12 @@
<div class="para func">
<h2>disk_write</h2>
<p>The disk_write writes sector(s) to the disk.</p>
<p>The disk_write writes sector(s) to the storage device.</p>
<pre>
DRESULT disk_write (
BYTE <span class="arg">drv</span>, <span class="c">/* [IN] Physical drive number */</span>
const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Write data (may be non aligned) */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Sector number to write */</span>
const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Sector number to write from */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectors to write */</span>
);
</pre>
@ -28,13 +28,13 @@ DRESULT disk_write (
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the physical drive number.</dd>
<dd>Physical drive number to identify the target device.</dd>
<dt>buff</dt>
<dd>Pointer to the <em>byte array</em> to be written.</dd>
<dd>Pointer to the <em>byte array</em> to be written. The size of data to be written is sector size * <tt class="arg">count</tt> bytes.</dd>
<dt>sector</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dd>Start sector number in logical block address (LBA).</dd>
<dt>count</dt>
<dd>Specifies the number of sectors to write. FatFs specifis 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you will never get good write performance.</dd>
<dd>Number of sectors to write. FatFs specifis it in range of from 1 to 128.</dd>
</dl>
</div>
@ -51,15 +51,23 @@ DRESULT disk_write (
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The disk drive has not been initialized.</dd>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>This function is not required in read only configuration. The specified memory address is not that always aligned to word boundary because the type of pointer is defined as <tt>BYTE</tt>. For more information, read <a href="dread.html">description in disk_read function</a>.</p>
<p><em>Application program MUST NOT call this function while FatFs is in use, or FAT structure on the volume can be corrapted.</em></p>
<p>The specified memory address is not that always aligned to word boundary because the type of pointer is defined as <tt>BYTE</tt>. For more information, refer to the description of <a href="dread.html"><tt>disk_read()</tt></a> function.</p>
<p>Generally, a multiple sector transfer request must not be split into single sector transactions to the storage device, or you will never get good write throughput.</p>
<p>FatFs expects delayed write feature of the disk functions. The write operation to the media need not to be completed due to write operation is in progress or only stored it into the cache buffer when return from this function. But data on the <tt class="arg">buff</tt> is invalid after return from this function. The write completion request is done by <tt>CTRL_SYNC</tt> command of <tt><a href="dioctl.html">disk_ioctl()</a></tt> function. Therefore, if delayed write feature is implemented, the write throughput may be improved.</p>
<p><em>Application program MUST NOT call this function, or FAT structure on the volume can be collapsed.</em></p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This function is not needed when <tt>_FS_READONLY == 1</tt>.</p>
</div>

View File

@ -25,11 +25,11 @@ DWORD get_fattime (void);
<p>Currnet time is returned with packed into a <tt>DWORD</tt> value. The bit field is as follows:</p>
<dl class="ret">
<dt>bit31:25</dt>
<dd>Year from 1980 (0..127)</dd>
<dd>Year origin from the 1980 (0..127)</dd>
<dt>bit24:21</dt>
<dd>Month (1..12)</dd>
<dt>bit20:16</dt>
<dd>Day in month(1..31)</dd>
<dd>Day of the month(1..31)</dd>
<dt>bit15:11</dt>
<dd>Hour (0..23)</dd>
<dt>bit10:5</dt>
@ -42,7 +42,13 @@ DWORD get_fattime (void);
<div class="para desc">
<h4>Description</h4>
<p>The <tt>get_fattime()</tt> function must return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid time. This fucntion is not required in read only configuration.</p>
<p>The <tt>get_fattime()</tt> function shall return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid timestamp.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This function is not needed when <tt>_FS_READONLY == 1</tt>.</p>
</div>

View File

@ -35,6 +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>_STR_VOLUME_ID</tt> is specified, also pre-defined strings can be used as drive identifier in the path name instead of a numeral.</p>
</div>
<p><br></p>
@ -63,12 +64,13 @@ PARTITION VolToPart[] = {
{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>
};
</pre>
<img src="../img/f7.png" width="828" height="288" alt="relationship between logical drive and physical drive">
</pre>
<p>There are some considerations on using <tt>_MULTI_PARTITION</tt> configuration.</p>
<ul>
<li>Only four primary partitions can be specified. Logical partition is not supported.</li>
<li>The physical drive that has two or more partitions must be non-removable class.</li>
<li>The physical drive that has two or more mounted partitions must be non-removable. Media change while a system operation is prohibited.</li>
</ul>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_getfree</h2>
<p>The f_getfree function gets number of the free clusters.</p>
<p>The f_getfree function gets number of the free clusters on the volume.</p>
<pre>
FRESULT f_getfree (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>

View File

@ -54,7 +54,7 @@ FRESULT f_lseek (
<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 insufficient free space on the volume to expand the file.</li>
</ul>
<p>Fast seek feature is enabled when <tt>_USE_FASTSEEK</tt> is set to 1 and the member <tt>cltbl</tt> in the file object is not NULL. This feature enables fast backward/long seek operations without FAT access by using cluster link map table (CLMT). It is also applied to <tt>f_read()/f_write()</tt> function. In this mode, the file cannot be expanded by <tt>f_write()/f_lseek()</tt> function.</p>
<p>Fast seek feature is enabled when <tt>_USE_FASTSEEK</tt> is set to 1 and the member <tt>cltbl</tt> in the file object is not NULL. This feature enables fast backward/long seek operations without FAT access by using CLMT (cluster link map table). The fast seek feature is also applied to <tt>f_read()/f_write()</tt> function, however, the file size cannot be expanded by <tt>f_write()/f_lseek()</tt> function.</p>
<p>The CLMT must be created in the user defined <tt>DWORD</tt> array prior to use the fast seek feature. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the file object, set the array size in unit of items into the first item and call the <tt>f_lseek()</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read()/f_write()/f_lseek()</tt> function to the file. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file and number of items required is returned into the first item of the array. The required array size is (number of fragments + 1) * 2 items. For example, when the file is fragmented in 5, 12 items will be required for the CLMT.</p>
</div>
@ -107,9 +107,9 @@ FRESULT f_lseek (
DWORD clmt[SZ_TBL]; <span class="c">/* Cluster link map table buffer */</span>
res = f_lseek(fp, ofs1); <span class="c">/* This is normal seek (cltbl member is nulled on file open) */</span>
res = f_lseek(fp, ofs1); <span class="c">/* This is normal seek (cltbl is nulled on file open) */</span>
fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek feature */</span>
fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek feature (cltbl != NULL) */</span>
clmt[0] = SZ_TBL; <span class="c">/* Set table size */</span>
res = f_lseek(fp, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
...

View File

@ -60,7 +60,7 @@ FRESULT f_mount (
<p>If forced mount is not specified, this function always succeeds regardless of the physical drive status due to delayed mount feature. It only clears (de-initializes) the given work area and registers its address to the internal table. No activity of the physical drive in this function. It can also be used to force de-initialized the registered work area of a logical drive. The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and initialize the work area, is performed in the subsequent file access functions when either or both of following condition is true.</p>
<ul>
<li>File system object is not initialized. It is cleared by <tt>f_mount()</tt>.</li>
<li>Physical drive is not initialized. It is de-initialized by system reset or media removal.</li>
<li>Physical drive is not initialized. It is de-initialized by system reset or media change.</li>
</ul>
<p>If the function with forced mount failed, it means that the file system object is registered but the volume is currently not available. Mount process will also be attempted in subsequent file access functions.</p>
<p>If implementation of the disk I/O layer lacks media change detection, application program needs to perform a <tt>f_mount()</tt> after media change to force cleared the file system object.</p>

View File

@ -31,7 +31,7 @@ FRESULT f_open (
<dt>path</dt>
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to create or open.</dd>
<dt>mode</dt>
<dd>Specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
<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><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file. Combine with <tt>FA_WRITE</tt> for read-write access.</td></tr>
@ -40,7 +40,7 @@ FRESULT f_open (
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file is created.<br>
To append data to the file, use <a href="lseek.html"><tt>f_lseek()</tt></a> function after file open in this method.</td></tr>
<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 is truncated and overwritten.</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>
</table>
</dd>
</dl>
@ -74,7 +74,7 @@ To append data to the file, use <a href="lseek.html"><tt>f_lseek()</tt></a> func
<div class="para desc">
<h4>Description</h4>
<p>After <tt>f_open()</tt> function succeeded, the file object is valid. The file object is used for subsequent read/write functions to identify the file. To close an open file, use <a href="close.html"><tt>f_close()</tt></a> function. If the file is modified and not closed properly, the file data will be collapted.</p>
<p>After <tt>f_open()</tt> function succeeded, the file object is valid. The file object is used for subsequent read/write functions to identify the file. To close an open file, use <a href="close.html"><tt>f_close()</tt></a> function. If the file is modified and not closed properly, the file data will be collapsed.</p>
<p>If duplicated file open is needed, read <a href="appnote.html#dup">here</a> carefully. However duplicated open of a file with write mode flag is always prohibited.</p>
<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>
</div>
@ -104,15 +104,15 @@ int main (void)
f_mount(&amp;FatFs, "", 0);
<span class="c">/* Open a text file */</span>
fr = f_open(&fil, "message.txt", FA_READ);
fr = f_open(&amp;fil, "message.txt", FA_READ);
if (fr) return (int)fr;
<span class="c">/* Read all lines and display it */</span>
while (f_gets(line, sizeof line, &fil))
while (f_gets(line, sizeof line, &amp;fil))
printf(line);
<span class="c">/* Close the file */</span>
f_close(&fil);
f_close(&amp;fil);
return 0;
}

View File

@ -26,7 +26,7 @@ FRESULT f_opendir (
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the blank directory object to be created.</dd>
<dd>Pointer to the blank directory object to create a new one.</dd>
<dt>path</dt>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
</dl>
@ -47,7 +47,8 @@ FRESULT f_opendir (
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>

View File

@ -66,14 +66,17 @@ int f_printf (
<pre>
f_printf(&amp;fil, "%d", 1234); <span class="c">/* "1234" */</span>
f_printf(&amp;fil, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span>
f_printf(&amp;fil, "%-6u", 100); <span class="c">/* "100 " */</span>
f_printf(&amp;fil, "%ld", 12345678L); <span class="c">/* "12345678" */</span>
f_printf(&amp;fil, "%04x", 0xAB); <span class="c">/* "00ab" */</span>
f_printf(&amp;fil, "%ld", 12345L); <span class="c">/* "12345" */</span>
f_printf(&amp;fil, "%06d", 25); <span class="c">/* "000025" */</span>
f_printf(&amp;fil, "%06d", -25); <span class="c">/* "000-25" */</span>
f_printf(&amp;fil, "%-6d", 25); <span class="c">/* "25 " */</span>
f_printf(&amp;fil, "%u", -1); <span class="c">/* "65535" or "4294967295" */</span>
f_printf(&amp;fil, "%04x", 0xAB3); <span class="c">/* "0ab3" */</span>
f_printf(&amp;fil, "%08LX", 0x123ABCL); <span class="c">/* "00123ABC" */</span>
f_printf(&amp;fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span>
f_printf(&amp;fil, "%s", "String"); <span class="c">/* "String" */</span>
f_printf(&amp;fil, "%5s", "abc"); <span class="c">/* " abc" */</span>
f_printf(&amp;fil, "%-5s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%8s", "abc"); <span class="c">/* " abc" */</span>
f_printf(&amp;fil, "%-8s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%c", 'a'); <span class="c">/* "a" */</span>
f_printf(&amp;fil, "%f", 10.0); <span class="c">/* f_printf lacks floating point support */</span>
</pre>

View File

@ -17,7 +17,7 @@
<dt id="ok">FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt id="de">FR_DISK_ERR</dt>
<dd>An unrecoverable error occured in the lower layer, <tt>disk_read()</tt>, <tt>disk_write()</tt> or <tt>disk_ioctl()</tt> function.</dd>
<dd>An unrecoverable hard error occured in the lower layer, <tt>disk_read()</tt>, <tt>disk_write()</tt> or <tt>disk_ioctl()</tt> function.</dd>
<dt id="ie">FR_INT_ERR</dt>
<dd>Assertion failed. An insanity is detected in the internal process. One of the following possibilities are suspected.
<ul>
@ -38,7 +38,7 @@
<dd>The required access was denied due to one of the following reasons:
<ul>
<li>Write mode open against the read-only file.</li>
<li>Deleting the read-only file or directory.</li>
<li>Deleting the read-only file or directory.</li>
<li>Deleting the non-empty directory or current directory.</li>
<li>Reading the file opened without <tt>FA_READ</tt> flag.</li>
<li>Any modification to the file opened without <tt>FA_WRITE</tt> flag.</li>
@ -47,13 +47,13 @@
</ul>
</dd>
<dt id="ex">FR_EXIST</dt>
<dd>Any file or directory that has the same name is already existing.</dd>
<dd>Name collision. Any object that has the same name is already existing.</dd>
<dt id="io">FR_INVALID_OBJECT</dt>
<dd>The file/directory object is invalid or a null pointer is given.</dd>
<dd>The file/directory object structure is invalid or a null pointer is given. All open objects of the logical drive are invalidated by the voulme mount process.</dd>
<dt id="wp">FR_WRITE_PROTECTED</dt>
<dd>Any write mode action against the write-protected media.</dd>
<dt id="id">FR_INVALID_DRIVE</dt>
<dd>Invalid drive number is specified in the path name. (Related option: <tt>_VOLUMES</tt>)</dd>
<dd>Invalid drive number is specified in the path name. A null pointer is given as the path name. (Related option: <tt>_VOLUMES</tt>)</dd>
<dt id="ne">FR_NOT_ENABLED</dt>
<dd>Work area for the logical drive has not been registered by <tt>f_mount()</tt> function.</dd>
<dt id="ns">FR_NO_FILESYSTEM</dt>
@ -61,24 +61,24 @@
<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 size is too small.</li>
<li>Not allowable cluster size for this disk. This can occure when number of clusters gets near the 0xFF7 and 0xFFF7.</li>
<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>_MULTI_PARTITION</tt>)</li>
</ul>
</dd>
<dt id="tm">FR_TIMEOUT</dt>
<dd>The function canceled due to a timeout of <a href="appnote.html#reentrant">thread-safe control</a>. (Related option: <tt>_TIMEOUT</tt>)</dd>
<dd>The function was canceled due to a timeout of <a href="appnote.html#reentrant">thread-safe control</a>. (Related option: <tt>_TIMEOUT</tt>)</dd>
<dt id="lo">FR_LOCKED</dt>
<dd>The file access is rejected by <a href="appnote.html#dup">file sharing control</a>. (Related option: <tt>_FS_LOCK</tt>)</dd>
<dd>The function was rejected by <a href="appnote.html#dup">file sharing control</a>. (Related option: <tt>_FS_LOCK</tt>)</dd>
<dt id="nc">FR_NOT_ENOUGH_CORE</dt>
<dd>Not enough memory for the operation. There is one of the following reasons:
<ul>
<li>Could not allocate a memory for LFN working buffer. (Related option: <tt>_USE_LFN</tt>)</li>
<li>Given CLMT is insufficient size for the required size.</li>
<li>Size of the given CLMT buffer is insufficient for the file fragments.</li>
</ul>
</dd>
<dt id="tf">FR_TOO_MANY_OPEN_FILES</dt>
<dd>Number of open files has been reached maximum value and no more file can be opened. (Related option: <tt>_FS_LOCK</tt>)</dd>
<dd>Number of open objects has been reached maximum value and no more object can be opened. (Related option: <tt>_FS_LOCK</tt>)</dd>
<dt id="ip">FR_INVALID_PARAMETER</dt>
<dd>The given parameter is invalid or there is any inconsistent.</dd>
</dl>

View File

@ -30,7 +30,7 @@ FRESULT f_read (
<dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>buff</dt>
<dd>Pointer to the buffer to store read data</dd>
<dd>Pointer to the buffer to store read data.</dd>
<dt>btr</dt>
<dd>Number of bytes to read in range of <tt>UINT</tt> type.</dd>
<dt>br</dt>

View File

@ -54,7 +54,7 @@ FRESULT f_readdir (
<ul>
<li>The directory item has no LFN information.</li>
<li>Either the size of read buffer or LFN working buffer is insufficient for the LFN.</li>
<li>The LFN contains Unicode charactrer that cannot be converted to OEM code. (not the case on Unicode API)</li>
<li>The LFN contains any Unicode charactrer that cannot be converted to OEM code. (not the case at Unicode API cfg.)</li>
</ul>
<p>When the directory item has no LFN information, lower case characters can be contained in the <tt>fname[]</tt>.</p>
</div>

View File

@ -26,9 +26,9 @@ FRESULT f_rename (
<h4>Parameters</h4>
<dl class="par">
<dt>old_name</dt>
<dd>Pointer to a null-terminated string that specifies the old <a href="filename.html">object name</a> to be renamed.</dd>
<dd>Pointer to a null-terminated string that specifies an existing <a href="filename.html">file or sub-directory</a> to be renamed.</dd>
<dt>new_name</dt>
<dd>Pointer to a null-terminated string tha specifies the new object name without drive number.</dd>
<dd>Pointer to a null-terminated string that specifies the new object name. The drive number specified in this string is ignored and one determined by <tt class="arg">old_name</tt> is used instead.</dd>
</dl>
</div>
@ -58,7 +58,7 @@ FRESULT f_rename (
<div class="para desc">
<h4>Description</h4>
<p>Renames a file or sub-directory and can also move it to other directory. The logical drive number is determined by old name, new name must not contain a logical drive number. <em>Do not rename open objects</em> or directry table can be collapted.</p>
<p>Renames a file or sub-directory and can also move it to other directory within the same logical drive. <em>Do not rename open objects</em> or directry table can be broken.</p>
</div>

View File

@ -24,7 +24,7 @@
BYTE fsi_flag; <span class="c">/* FSINFO flags (b7:Disabled, b0:Dirty) */</span>
WORD id; <span class="c">/* File system mount ID */</span>
WORD n_rootdir; <span class="c">/* Number of root directory entries (FAT12/16) */</span>
<span class="k">#if</span> _MAX_SS != 512
<span class="k">#if</span> _MAX_SS != _MIN_SS
WORD ssize; <span class="c">/* Sector size (512,1024,2048 or 4096) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_REENTRANT

View File

@ -60,7 +60,7 @@
<dt>fname[]</dt>
<dd>Indicates the file/directory name in 8.3 format null-terminated string. It is always returnd with upper case in non-LFN configuration but it can be returned with lower case in LFN configuration.</dd>
<dt>lfname</dt>
<dd>Pointer to the LFN buffer to store the read LFN. This member must be initialized by application prior to use this structure. Not available in non-LFN configuration.</dd>
<dd>Pointer to the LFN buffer to store the read LFN. This member must be initialized by application prior to use this structure. Set null pointer if LFN is not needed. Not available in non-LFN configuration.</dd>
<dt>lfsize</dt>
<dd>Size of the LFN buffer in unit of TCHAR. This member must be initialized by application prior to use this structure. Not available in non-LFN configuration.</dd>
</dl>

View File

@ -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 exist, the function returns with <tt>FR_OK</tt> and the information of the object is stored to the file information structure. If not exist, the function returns with <tt>FR_NO_FILE</tt>. For details, 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, size, timestamp and attribute, are stored to the file information structure. For details, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir()</tt></a> function. </p>
</div>

View File

@ -57,9 +57,9 @@ FRESULT f_unlink (
<h4>Description</h4>
<p>
If condition of the object to be removed is applicable to the following terms, the function will be rejected.<ul>
<li>The object must not have read-only attribute (<tt>AM_RDO</tt>) or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The sub-directory must be empty and must not be current directory or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The file or directory must not have been opened or the <em>FAT volume can be collapted</em>. It will able to be rejected with <tt>FR_LOCKED</tt> when <a href="appnote.html#dup">file lock feature</a> is enabled.</li>
<li>The file/sub-directory must not have read-only attribute (<tt>AM_RDO</tt>), or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The sub-directory must be empty and must not be current directory, or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The file/sub-directory must not be opened, or the <em>FAT volume can be collapsed</em>. It can also be rejected with <tt>FR_LOCKED</tt> when <a href="appnote.html#dup">file lock feature</a> is enabled.</li>
</ul>
</div>

View File

@ -6,7 +6,7 @@
/ If the file has been opened without FA_WRITE flag, it only checks if
/ the file is contiguous and returns the resulut. */
#if _FATFS != 80960 /* Check if R0.10 */
#if _FATFS != 29000 /* Check if R0.10a */
#error This function may not be compatible with this revision of FatFs module.
#endif
@ -96,7 +96,7 @@ int main (void)
/* Now you can read/write the file with disk functions bypassing the file system layer. */
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512Ki bytes from top of the file */
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512KiB from top of the file */
...

318
doc/img/app4.c Normal file
View File

@ -0,0 +1,318 @@
/*----------------------------------------------------------------------/
/ Low level disk I/O module function checker
/-----------------------------------------------------------------------/
/ WARNING: The data on the target drive will be lost!
*/
#include <stdio.h>
#include <string.h>
#include "ff.h"
#include "diskio.h"
static
DWORD pn (
DWORD pns
)
{
static DWORD lfsr;
UINT n;
if (pns) {
lfsr = pns;
for (n = 0; n < 32; n++) pn(0);
}
if (lfsr & 1) {
lfsr >>= 1;
lfsr ^= 0x80200003;
} else {
lfsr >>= 1;
}
return lfsr;
}
int test_diskio (
BYTE pdrv, /* Physical drive number to be checked (all data on the drive will be lost) */
UINT ncyc, /* Number of test cycles */
DWORD* buff, /* Pointer to the working buffer */
UINT sz_buff /* Size of the working buffer in unit of byte */
)
{
UINT n, cc, ns;
DWORD sz_drv, lba, lba2, pns = 1;
WORD sz_sect, sz_eblk;
BYTE *pbuff = (BYTE*)buff;
DSTATUS ds;
DRESULT dr;
printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);
if (sz_buff < _MAX_SS + 4) {
printf("Insufficient work area to test.\n");
return 1;
}
for (cc = 1; cc <= ncyc; cc++) {
printf("**** Test cycle %u of %u start ****\n", cc, ncyc);
/* Initialization */
printf(" disk_initalize(%u)", pdrv);
ds = disk_initialize(pdrv);
if (ds & STA_NOINIT) {
printf(" - failed.\n");
return 2;
} else {
printf(" - ok.\n");
}
/* Get drive size */
printf("**** Get drive size ****\n");
printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv, (UINT)&sz_drv);
sz_drv = 0;
dr = disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_drv);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 3;
}
if (sz_drv < 128) {
printf("Failed: Insufficient drive size to test.\n");
return 4;
}
printf(" Number of sectors on the drive %u is %lu.\n", pdrv, sz_drv);
#if _MAX_SS != _MIN_SS
/* Get sector size */
printf("**** Get sector size ****\n");
printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv, (UINT)&sz_sect);
sz_sect = 0;
dr = disk_ioctl(pdrv, GET_SECTOR_SIZE, &sz_sect);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 5;
}
printf(" Size of sector is %u bytes.\n", sz_sect);
#else
sz_sect = _MAX_SS;
#endif
/* Get erase block size */
printf("**** Get block size ****\n");
printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv, (UINT)&sz_eblk);
sz_eblk = 0;
dr = disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_eblk);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
}
if (dr == RES_OK || sz_eblk >= 2) {
printf(" Size of the erase block is %u sectors.\n", sz_eblk);
} else {
printf(" Size of the erase block is unknown.\n");
}
/* Single sector write test */
printf("**** Single sector write test 1 ****\n");
lba = 0;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_write(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 6;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 7;
}
memset(pbuff, 0, sz_sect);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_read(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 8;
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
printf(" Data matched.\n");
} else {
printf("Failed: Read data differs from the data written.\n");
return 10;
}
pns++;
/* Multiple sector write test */
printf("**** Multiple sector write test ****\n");
lba = 1; ns = sz_buff / sz_sect;
if (ns > 4) ns = 4;
for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
dr = disk_write(pdrv, pbuff, lba, ns);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 11;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 12;
}
memset(pbuff, 0, sz_sect * ns);
printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
dr = disk_read(pdrv, pbuff, lba, ns);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 13;
}
for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == (UINT)(sz_sect * ns)) {
printf(" Data matched.\n");
} else {
printf("Failed: Read data differs from the data written.\n");
return 14;
}
pns++;
/* Single sector write test (misaligned memory address) */
printf("**** Single sector write test 2 ****\n");
lba = 5;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba);
dr = disk_write(pdrv, pbuff+3, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 15;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 16;
}
memset(pbuff+5, 0, sz_sect);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+5), lba);
dr = disk_read(pdrv, pbuff+5, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 17;
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
printf(" Data matched.\n");
} else {
printf("Failed: Read data differs from the data written.\n");
return 18;
}
pns++;
/* 4GB barrier test */
printf("**** 4GB barrier test ****\n");
if (sz_drv >= 128 + 0x80000000 / (sz_sect / 2)) {
lba = 6; lba2 = lba + 0x80000000 / (sz_sect / 2);
for (n = 0, pn(pns); n < (UINT)(sz_sect * 2); n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_write(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 19;
}
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
dr = disk_write(pdrv, pbuff+sz_sect, lba2, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 20;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 21;
}
memset(pbuff, 0, sz_sect * 2);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_read(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 22;
}
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
dr = disk_read(pdrv, pbuff+sz_sect, lba2, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 23;
}
for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;
if (n == (UINT)(sz_sect * 2)) {
printf(" Data matched.\n");
} else {
printf("Failed: Read data differs from the data written.\n");
return 24;
}
} else {
printf(" Test skipped.\n");
}
pns++;
printf("**** Test cycle %u of %u completed ****\n\n", cc, ncyc);
}
return 0;
}
int main (int argc, char* argv[])
{
int rc;
DWORD buff[512]; /* 2048 byte working buffer */
/* Check function/compatibility of the physical drive #0 */
rc = test_diskio(0, 1, buff, sizeof buff);
if (res) {
printf("Sorry the function/compatibility test failed.\nFatFs will not work on this disk driver.\n");
} else {
printf("Congratulations! The disk I/O layer works well.\n");
}
return rc;
}

BIN
doc/img/funcs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -44,15 +44,17 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
<h4>システム構成</h4>
<p>下に示す依存関係図は、FatFsモジュール利用の組み込みシステムにおける代表的な構成を示します。</p>
<p><img src="../img/modules.png" width="580" height="280" alt="システム構成図"></p>
<p>(a) FatFs用に書かれたディスク・モジュールがある場合は、そのまま接続するだけです。 (b) しかし、多くの既存のディスク・モジュールはそのAPIをFatFsに合わせるため、グルー関数が必要になるでしょう。</p>
<p><img src="../img/funcs.png" width="680" height="450" alt="functional diagram"></p>
<h4>ユーザの作成する関数</h4>
<p>必要なのは FatFsモジュールの要求するディスク関数を用意することだけで、それ以外にすることはありません。既に動作しているディスク関数があるなら、その APIを FatFsに合わせるかグルー関数でつなぐだけで済みますが、無い場合はほかから移植するか最初から書くかする必要があります。定義されている全ての関数が常に必要なわけではありません。例えば、リード・オンリー構成では書き込み系関数は必要ありません。次の表に構成オプションと要求される関数の対応を示します。</p>
<table class="lst2">
<tr><th>ユーザ作成関数</th><th>必要となる条件</th><th>備考</th></tr>
<tr><td>disk_initialize<br>disk_status<br>disk_read</td><td>常時</td><td rowspan="5">ffsample.zip (サンプル)<br>その他web上に多数</td></tr>
<tr><td>disk_status<br>disk_initialize<br>disk_read</td><td>常時</td><td rowspan="5">ffsample.zip (サンプル)<br>その他web上に多数</td></tr>
<tr><td>disk_write<br>get_fattime<br>disk_ioctl (CTRL_SYNC)</td><td>_FS_READONLY == 0</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_COUNT)<br>disk_ioctl (GET_BLOCK_SIZE)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS &gt;= 1024</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS != _MIN_SS</td></tr>
<tr><td>disk_ioctl (CTRL_ERASE_SECTOR)</td><td>_USE_ERASE == 1</td></tr>
<tr><td>ff_convert<br>ff_wtoupper</td><td>_USE_LFN &gt;= 1</td><td>option/cc*.c</td></tr>
<tr><td>ff_cre_syncobj<br>ff_rel_grant<br>ff_req_grant<br>ff_del_syncobj</td><td>_FS_REENTRANT == 1</td><td rowspan="2">option/syscall.c (サンプル)</td></tr>
@ -69,7 +71,7 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
<li>ファイル・サイズ: FAT規格に依存。(最大 4G-1バイト)</li>
<li>ボリューム・サイズ: FAT規格に依存。(最大 2Tバイト(512バイト/セクタ時))</li>
<li>クラスタ・サイズ: FAT規格に依存。(最大 64Kバイト(512バイト/セクタ時))</li>
<li>セクタ・サイズ: FAT規格に依存。(最大 4Kバイト)</li>
<li>セクタ・サイズ: FAT規格に依存。(5124096バイト)</li>
</ul>
</div>
@ -78,33 +80,33 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
<p>次の表にいくつかのターゲットにおけるメモリ使用量の例を示します。テスト時の構成オプションはその下の通りです。数値の単位はバイトで、<em>V</em>はボリューム数、<em>F</em>は同時オープン・ファイル数を示します。コンパイラの最適化オプションはコード・サイズとしています。</p>
<table class="lst2">
<tr><th></th><th>ARM7<small><br>32bit</small></th><th>ARM7<small><br>Thumb</small></th><th>CM3<small><br>Thumb-2</small></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>RL78</th><th>V850ES</th><th>SH-2A</th><th>RX600</th><th>IA-32</th></tr>
<tr><td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>VC6</td></tr>
<tr><td>_WORD_ACCESS</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>
<!-- *ARM *Thumb *CM3 *AVR *H8 *PIC24 *RL78 *V850ES *SH-2A *RX600 *IA-32 -->
<tr class="lst3"><td>text (Full, R/W)</td><td>10591</td><td>7119</td><td>6565</td><td>13240</td><td>10864</td><td>11619</td><td>13192</td><td>8031</td><td>8960</td><td>5977</td><td>7856</td></tr>
<tr> <td>text (Min, R/W)</td> <td>6671</td><td>4595</td><td>4293</td> <td>8512</td> <td>7232</td> <td>7674</td> <td>9033</td><td>5235</td><td>5768</td><td>3923</td><td>5129</td></tr>
<tr> <td>text (Full, R/O)</td> <td>4695</td><td>3121</td><td>2861</td> <td>6218</td> <td>5162</td> <td>5466</td> <td>6418</td><td>3799</td><td>3964</td><td>2847</td><td>3687</td></tr>
<tr> <td>text (Min, R/O)</td> <td>3523</td><td>2463</td><td>2275</td> <td>4558</td> <td>4058</td> <td>4212</td> <td>4948</td><td>2959</td><td>3096</td><td>2199</td><td>2857</td></tr>
<tr> <td>bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr> <td>Work area<br>(_FS_TINY == 0)</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*544</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td><td>V*560 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*32</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td><td>V*560 +<br>F*36</td></tr>
<tr class="cal"> <td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>VC6</td></tr>
<tr class="cal"> <td>_WORD_ACCESS</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>
<!-- ARM Thumb CM3 AVR H8 PIC24 RL78 V850ES SH-2A RX600 IA-32 -->
<tr class="lst3 ral"><td class="cal">text (Full, R/W)</td><td>10675</td><td>7171</td><td>6617</td><td>13355</td><td>10940</td><td>11722</td><td>13262</td><td>8113</td><td>9048</td><td>6032</td><td>7952</td></tr>
<tr class="ral"> <td class="cal">text (Min, R/W)</td> <td>6727</td><td>4631</td><td>4331</td> <td>8569</td> <td>7262</td> <td>7720</td> <td>9088</td><td>5287</td><td>5800</td><td>3948</td><td>5183</td></tr>
<tr class="ral"> <td class="cal">text (Full, R/O)</td> <td>4731</td><td>3147</td><td>2889</td> <td>6235</td> <td>5170</td> <td>5497</td> <td>6482</td><td>3833</td><td>3972</td><td>2862</td><td>3719</td></tr>
<tr class="ral"> <td class="cal">text (Min, R/O)</td> <td>3559</td><td>2485</td><td>2295</td> <td>4575</td> <td>4064</td> <td>4240</td> <td>5019</td><td>2993</td><td>3104</td><td>2214</td><td>2889</td></tr>
<tr class="ral"> <td class="cal">bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr class="ral"> <td class="cal">Work area<br>(_FS_TINY == 0)</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*544</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td><td>V*560<br>+ F*550</td></tr>
<tr class="ral"> <td class="cal">Work area<br>(_FS_TINY == 1)</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*32</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td><td>V*560<br>+ F*36</td></tr>
</table>
<pre>
FatFs R0.10 options:
_FS_READONLY 0 (R/W), 1 (R/O)
_FS_MINIMIZE 0 (Full function), 3 (Minimized function)
FatFs R0.10a options:
_FS_READONLY 0 (R/W) or 1 (R/O)
_FS_MINIMIZE 0 (Full function) or 3 (Minimized function)
_USE_STRFUNC 0 (Disable string functions)
_USE_MKFS 0 (Disable f_mkfs function)
_USE_FORWARD 0 (Disable f_forward function)
_USE_FASTSEEK 0 (Disable fast seek feature)
_CODE_PAGE 932 (Japanese Shift-JIS)
_USE_LFN 0 (Disable LFN)
_USE_LFN 0 (Disable LFN feature)
_MAX_SS 512 (Fixed sector size)
_FS_RPATH 0 (Disable relative path feature)
_FS_LABEL 0 (Disable volume label functions)
_VOLUMES V (Number of logical drives to be used)
_MULTI_PARTITION 0 (Single partition per drive)
_FS_REENTRANT 0 (Disable reentrancy)
_FS_REENTRANT 0 (Disable thread safe)
_FS_LOCK 0 (Disable file lock control)
</pre>
</div>
@ -186,7 +188,7 @@ _FS_LOCK 0 (Disable file lock control)
<div class="para" id="dup">
<h3>多重ファイル・アクセス</h3>
<p>FatFsモジュールではデフォルトでは多重アクセス制御機能をサポートしていません。ファイルに対する多重アクセスは、そのアクセス・モードによって制限されます。一つのファイルに対する多重オープンは、それらが全てリード・モードのときに限って許可されます。書き込みモードを含む多重オープン、また開かれているファイルに対するリネームや削除を行ってはなりません。さもないと、そのボリュームのFAT構造が破壊される可能性があります。</p>
<p><tt>_FS_LOCK</tt>に1以上の値(値は同時に管理できるファイル数)をセットすることで多重アクセス制御機能が有効になり、ファイル単位のアクセス制御を自動で行うこともできます。この場合、上記のルールを破ったオープン・リネーム・削除を試みると、その関数は<tt>FR_LOCKED</tt>で失敗します。また、<tt>_FS_LOCK</tt>を越える数のファイルやディレクトリを同時にオープンしようとすると、<tt>FR_TOO_MANY_OPEN_FILES</tt>で失敗します。</p>
<p><tt>_FS_LOCK</tt>に1以上の値(値は同時に管理できるファイル数)をセットすることで多重アクセス制御機能が有効になり、ファイル単位のアクセス制御を自動で行うこともできます。この場合、上記のルールを破ったオープン・リネーム・削除を試みると、その関数は<tt>FR_LOCKED</tt>で失敗します。また、<tt>_FS_LOCK</tt>を越える数のファイルやサブ・ディレクトリを同時にオープンしようとすると、<tt>FR_TOO_MANY_OPEN_FILES</tt>で失敗します。</p>
</div>
<div class="para" id="fs1">
@ -249,6 +251,7 @@ _FS_LOCK 0 (Disable file lock control)
<li><a href="../img/app1.c">追記モードでのオープン/新規作成</a></li>
<li><a href="../img/app2.c">ディレクトリを空にする</a></li>
<li><a href="../img/app3.c">ファイルに連続領域を割り当てる</a></li>
<li><a href="../img/app4.c">ディスクI/Oモジュールの機能/互換性チェッカー</a></li>
</ol>
</div>
@ -256,13 +259,13 @@ _FS_LOCK 0 (Disable file lock control)
<h3>FatFsのライセンスについて</h3>
<p>ソース・ファイルのヘッダにライセンス条件が記述されているので、利用の際はそれに従うこと。英語を読めない方のために以下に日本語訳を示しておきます。</p>
<pre>/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.10 (C)ChaN, 2013
/ FatFs - FAT file system module R0.10a (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ FatFsモジュールは、小規模な組み込みシステム向けの汎用FATファイルシステム・
/ モジュールです。これはフリー・ソフトウェアとして、教育・研究・開発のために
/ 以下のライセンス・ポリシーの下で公開されています。
/
/ Copyright (C) 2013, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * FatFsモジュールはフリー・ソフトウェアであり、また<em>無保証です</em>
/ * 用途に制限はありません。<em>あなたの責任の下において</em>、個人的・非営利的な

View File

@ -50,7 +50,7 @@ FRESULT f_chdir (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>各ボリュームのカレント・ディレクトリを変更します。カレント・ディレクトリはファイル・システム・オブジェクトの初期化が行われたとき、ルート・ディレクトリに設定されます。カレント・ディレクトリは、ファイル・システム・オブジェクトに保持されるため、そのボリュームを使用する全てのタスクに対して影響を与えます。</p>
<p>各ボリュームのカレント・ディレクトリを変更します。カレント・ディレクトリは、そのボリュームのマウント動作が行われたとき、ルート・ディレクトリに初期設定されます。カレント・ディレクトリは、ファイル・システム・オブジェクトに保持されるため、そのボリュームを使用する全てのタスクに対して影響を与えます。</p>
</div>

View File

@ -41,13 +41,13 @@ FRESULT f_chdrive (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>カレント・ドライブを変更します。システム起動時の初期値は0です。この設定はFatFsモジュールの静的変数に記録されるため、全てのタスクに対して影響を与えます。</p>
<p>カレント・ドライブを変更します。システム起動時の初期値はドライブ0です。この設定はFatFsモジュールの静的変数に記録されるため、全てのタスクに対して影響を与えます。</p>
</div>
<div class="para comp">
<h4>Ήž<EFBFBD>î•ñ</h4>
<p><tt>_FS_RPATH == 1</tt>のときに使用可能となります。</p>
<p><tt>_FS_RPATH == 1</tt>で、且つ<tt>_VOLUMES &gt; 1</tt>のときに使用可能となります。</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>disk_initialize</h2>
<p>ディスク・ドライブを初期化します。</p>
<p>ストレージ・デバイスを初期化します。</p>
<pre>
DSTATUS disk_initialize (
BYTE <span class="arg">pdrv</span> <span class="c">/* [IN] 物理ドライブ番号 */</span>
@ -25,7 +25,7 @@ DSTATUS disk_initialize (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>初期化する物理ドライブ番号(0-9)が指定されます。</dd>
<dd>対象のデバイスを示す物理ドライブ番号(0-9)が指定されます。</dd>
</dl>
</div>
@ -37,8 +37,8 @@ DSTATUS disk_initialize (
<div class="para desc">
<h4>解説</h4>
<p>ディスク・ドライブを初期化します。関数が成功すると、戻り値の<tt>STA_NOINIT</tt>フラグがクリアされます。</p>
<p><em>FatFsを使用中はアプリケーションからはこの関数を呼び出してはなりません。さもないと、FATボリュームが破壊されます。エラー等により再初期化が必要なときは、<tt>f_mount()</tt>を使用してください。</em>FatFsモジュールは、自動マウント動作により、必要に応じてこの関数を呼び出します。</p>
<p>ストレージ・デバイスを初期化し、データの読み書きなど全ての動作が可能な状態にします。関数が成功すると、戻り値の<tt>STA_NOINIT</tt>フラグがクリアされます。</p>
<p><em>アプリケーションからはこの関数を呼び出してはなりません。さもないと、FATボリュームが破壊される可能性があります。エラー等により再初期化が必要なときは、<tt>f_mount()</tt>を使用してください。</em>FatFsモジュールは、自動マウント動作により、必要に応じてこの関数を呼び出します。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>disk_ioctl</h2>
<p>セクタの読み書き以外のディスク・ドライブ自体に対する様々な制御をします。</p>
<p>一般的なセクタ読み書き以外のストレージ・デバイス自体に対する様々な制御を行います。</p>
<pre>
DRESULT disk_ioctl (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
@ -27,11 +27,11 @@ DRESULT disk_ioctl (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>物理ドライブ番号(0-9)が指定されます。</dd>
<dd>対象のデバイスを示す物理ドライブ番号(0-9)が指定されます。</dd>
<dt>cmd</dt>
<dd>制御コマンド・コードが指定されます。</dd>
<dt>buff</dt>
<dd>制御コマンドに依存したパラメータを授受するバッファを指すポインタが指定されます。ータの授受のないコマンドの場合は、値に意味はありません。</dd>
<dd>制御コマンドに依存したパラメータを授受するバッファを指すポインタが指定されます。パラメータの授受のないコマンドの場合は、値に意味はありません。</dd>
</dl>
</div>
@ -51,18 +51,24 @@ DRESULT disk_ioctl (
<div class="para desc">
<h4>解説</h4>
<p>物理ドライブの種類によりサポートされるコマンドは異なりますが、FatFsモジュールでは、次の汎用コマンドのみ使用し、特定のハードウェアに依存した制御は行いません</p>
<p>ストレージ・デバイスの種類によりサポートされるコマンドは異なりますが、FatFsモジュール自体は、次の汎用コマンドのみ使用し、特定のデバイスに依存した制御は行いません。アプリケーション上でこれ以外の制御が必要なときは、必要に応じてユーザ定義コマンドを追加してください</p>
<table class="lst">
<tr><th>コマンド</th><th>解説</th></tr>
<tr><td>CTRL_SYNC</td><td>ドライブ内のデータ書き込み処理の完了待ち。ライト・バック・キャッシュなどが存在する場合は、書き込まれていないデータを即時書き戻します。リード・オンリー構成では使用されません。</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td><tt class="arg">buff</tt>の指す<tt>WORD</tt>型変数にドライブのセクタ・サイズ(バイト単位)を返します。セクタ・サイズが固定(<tt>_MAX_SS</tt>が512)のときはこのコマンドは使われません。</td></tr>
<tr><td>CTRL_SYNC</td><td>ストレージ・デバイスのデータ書き込み処理を完了させます。ライト・バック・キャッシュなどが存在する場合は、書き込まれていないデータを即時書き込みます。メディア上への書き込みがそれぞれ<tt>disk_write</tt>関数内で完了する場合は、このコマンドに対してすることはありません。</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td><tt class="arg">buff</tt>の指す<tt>DWORD</tt>型変数にドライブ上の総セクタ数を返します。<tt>f_mkfs()</tt>内で呼び出され、作成するボリュームのサイズを決定するために使用されます。</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td><tt class="arg">buff</tt>の指す<tt>WORD</tt>型変数にドライブのセクタ・サイズを返します。有効値は512、1024、2048または4096です。セクタ・サイズ固定構成(<tt>_MAX_SS ==_MIN_SS</tt>)のときはこのコマンドは使われることはなく、常にそのセクタ・サイズで動作しなければなりません。</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td><tt class="arg">buff</tt>の指す<tt>DWORD</tt>型変数にフラッシュ・メモリの消去ブロック・サイズ(セクタ単位)を返します。1から32768の範囲で2の累乗の値でなければなりません。不明な場合またはフラッシュ・メモリ以外のメディアでは1を返します。<tt>f_mkfs()</tt>内でのみ使用され、ボリュームのデータ領域はこの境界にアライメントされます。</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>フラッシュ・メモリ上の指定領域の消去。<tt class="arg">buff</tt>の指す<tt>DWORD</tt>型配列には消去する領域 {開始セクタ,終了セクタ} を指定して呼び出されます。<tt>_USE_ERASE</tt>が1のとき、クラスタが解放されるときに呼び出されます。これは、ATAコマンド・セットのTrimコマンドと等価で、この機能をサポートしない場合は何もする必要はありません。また、戻り値はチェックされず、消去が完全に行われなかったとしてもFatFsの動作には影響ありません。</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>フラッシュ・メモリ上の領域の明示的消去。<tt class="arg">buff</tt>の指す<tt>DWORD</tt>型配列には消去する領域 {開始セクタ,終了セクタ} を指定して呼び出されます。<tt>_USE_ERASE</tt>が1のとき、クラスタが解放されるときに呼び出されます。これは、ATAコマンド・セットのTrimコマンドと等価で、この機能をサポートしない場合は何もする必要はありません。また、戻り値はチェックされず、消去が完全に行われなかったとしてもFatFsの動作には影響ありません。</td></tr>
</table>
</div>
<div class="para comp">
<h4>対応情報</h4>
<p>リード・オンリー構成で、かつセクタ・サイズ固定構成のときは、この関数は必要とされません。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>disk_read</h2>
<p>ドライブからセクタを読み出します。</p>
<p>ストレージ・デバイスからセクタを読み出します。</p>
<pre>
DRESULT disk_read (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
@ -28,13 +28,13 @@ DRESULT disk_read (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>物理ドライブ番号(0-9)が指定されます。</dd>
<dd>対象のデバイスを示す物理ドライブ番号(0-9)が指定されます。</dd>
<dt>buff</dt>
<dd>ディスクから読み出したデータを格納する<em>バイト配列</em>で、読み出されるバイト数分のサイズが必要です。</dd>
<dd>ストレージ・デバイスから読み出したデータを格納する<em>バイト配列</em>が指定されます。</dd>
<dt>sector</dt>
<dd>読み出しを開始するセクタ番号。LBAで指定されます。</dd>
<dt>count</dt>
<dd>読み出すセクタ数。 1128の範囲の値で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ読み出しに分解した場合、スループットが低下することがあります。</dd>
<dd>読み出すセクタ数。FatFsからの呼び出しでは1128の範囲に限られます。</dd>
</dl>
</div>
@ -62,6 +62,8 @@ DRESULT disk_read (
<li><tt>f_read()</tt>において、セクタ全体を含む転送を避ける - 直接転送が発生しない</li>
<li><tt>f_read(fp, buff, btr, &amp;br)</tt>において、<tt>(((UINT)buff &amp; 3) == (f_tell(fp) &amp; 3))</tt>を満足させる - <tt class="arg">buff</tt>のワード・アライメントが保証される</li>
</ul>
<p>一般的に、複数セクタの転送要求は、ストレージ・デバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ読み出しに分解された場合、スループットが低下することがあります。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -25,7 +25,7 @@ DSTATUS disk_status (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>ステータスを取得する物理ドライブ番号が指定されます。</dd>
<dd>対象のデバイスを示す物理ドライブ番号(0-9)が指定されます。</dd>
</dl>
</div>
@ -38,7 +38,7 @@ DSTATUS disk_status (
<dd>ドライブが初期化されていないことを示すフラグ。システム・リセットやメディアの取り外し等でセットされ、<tt>disk_initialize()</tt>の正常終了でクリア、失敗でセットされます。メディア交換は非同期に発生するイベントなので、過去にメディア交換があった場合もこのフラグに反映させる必要があります。FatFsモジュールは、このフラグを参照して自動マウント動作を行うかどうかを判断します。</dd>
<dt>STA_NODISK</dt>
<dd>メディアが存在しないことを示すフラグ。メディアが取り外されている間はセットされ、セットされている間はクリアされます。固定ディスクでは常にクリアします。なお、このフラグはFatFsモジュールでは参照されません。</dd>
<dt>STA_PROTECTED</dt>
<dt>STA_PROTECT</dt>
<dd>メディアがライト・プロテクトされていることを示すフラグ。ライト・プロテクト機能をサポートしないときは、常にクリアします。リード・オンリ構成では参照されません。</dd>
</dl>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>disk_write</h2>
<p>ディスクにデータを書き込みます。</p>
<p>ストレージ・デバイスのセクタに書き込みます。</p>
<pre>
DRESULT disk_write (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
@ -28,13 +28,13 @@ DRESULT disk_write (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>物理ドライブ番号(0-9)が指定されます。</dd>
<dd>対象のデバイスを示す物理ドライブ番号(0-9)が指定されます。</dd>
<dt>buff</dt>
<dd>ディスクに書き込む<em>バイト配列</em>が指定されます。<em>アドレスは常にワード・アライメントされているとは限りません</em></dd>
<dd>ストレージ・デバイスに書き込むセクタ・データが格納された<em>バイト配列</em>が指定されます。バイト数は、セクタ・サイズ*<tt class="arg">count</tt>となります</dd>
<dt>sector</dt>
<dd>書き込みを開始するセクタ番号。LBAで指定されます。</dd>
<dt>count</dt>
<dd>書き込むセクタ数。 1128の範囲の値で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ書き込みに分解した場合、スループットが極端に低下することがあります。</dd>
<dd>書き込むセクタ数。FatFsからの呼び出しでは1128の範囲に限られます。</dd>
</dl>
</div>
@ -51,15 +51,23 @@ DRESULT disk_write (
<dt>RES_PARERR</dt>
<dd>パラメータが不正。</dd>
<dt>RES_NOTRDY</dt>
<dd>ドライブが動作可能状態ではない(初期化されていない)。</dd>
<dd>デバイスが動作可能状態ではない(初期化されていない)。</dd>
</dl>
</div>
<div class="para desc">
<h4>解説</h4>
<p>リード・オンリー構成ではこの関数は必要とされません。</p>
<p><em>FatFsの使用中はアプリケーションからはこの関数を呼び出してはなりません。さもないと、FATボリュームが破壊されます。エラー等により再初期化が必要なときは、<tt>f_mount()</tt>を使用してください。</em>FatFsモジュールは、自動マウント動作により、必要に応じてこの関数を呼び出します。</p>
<p><tt class="arg">buff</tt>に指定されるアドレスは<em>常にワード・アライメントされているとは限りません</em>。詳細は、<a href="dread.html"><tt>disk_read()</tt></a>の解説を参照してください。</p>
<p>一般的に、複数セクタの転送要求は、デバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ書き込みに分解された場合、スループットが著しく低下することがあります。</p>
<p>FatFsはディスク関数が遅延書き込み機能を持つことも想定しています。この関数から戻るとき、デバイスが書き込み中とかキャッシュに書き込まれただけなど、必ずしもデータの書き込みが完了している必要はありません。ただし、<tt class="arg">buff</tt>のデータは、この関数から戻ると無効となります。書き込み完了の要求は、<tt><a href="dioctl.html">disk_ioctl()</a></tt><tt>CTRL_SYNC</tt>コマンドによって行われます。このような遅延書き込み機能が実装された場合、スループットをさらに向上させることができます。</p>
<p><em>アプリケーションからはこの関数を呼び出してはなりません。さもないと、FATボリュームが破壊される可能性があります。</em></p>
</div>
<div class="para comp">
<h4>対応情報</h4>
<p>リード・オンリー構成(<tt>_FS_READONLY == 1</tt>)ではこの関数は必要とされません。</p>
</div>

View File

@ -22,27 +22,33 @@ DWORD get_fattime (void);
<div class="para ret">
<h4>戻り値</h4>
<p>現在のローカル・タイム<tt>DWORD</tt>値にパックされて返されます。ビット・フィールドは次に示すようになります。</p>
<p>現在のローカル・タイム<tt>DWORD</tt>値にパックして返しす。ビット・フィールドは次に示すようになります。</p>
<dl>
<dt>bit31:25</dt>
<dd>1980年を起点とした年が 0..127 で入ります</dd>
<dd>1980年を起点とした年を 0..127 でセット</dd>
<dt>bit24:21</dt>
<dd>が 1..12 の値で入ります</dd>
<dd>を 1..12 の値でセット</dd>
<dt>bit20:16</dt>
<dd>が 1..31 の値で入ります</dd>
<dd>を 1..31 の値でセット</dd>
<dt>bit15:11</dt>
<dd>が 0..23 の値で入ります</dd>
<dd>を 0..23 の値でセット</dd>
<dt>bit10:5</dt>
<dd>が 0..59 の値で入ります</dd>
<dd>を 0..59 の値でセット</dd>
<dt>bit4:0</dt>
<dd>秒/2が 0..29 の値で入ります。</dd>
<dd>秒/2を 0..29 の値でセット</dd>
</dl>
</div>
<div class="para desc">
<h4>解説</h4>
<p>RTCをサポートしないシステムでも、何らかの日付として有効な値を返さなければなりません。0を返した場合、そのファイルは日付を持ちません。リード・オンリー構成ではこの関数は必要とされません。</p>
<p>RTCをサポートしないシステムでも、ダミーとして何らかの日付として有効な値を返すべきです。0などを返した場合、そのファイルのタイムスタンプは無効になります。</p>
</div>
<div class="para comp">
<h4>対応情報</h4>
<p>リード・オンリー構成(<tt>_FS_READONLY == 1</tt>)ではこの関数は必要とされません。</p>
</div>

View File

@ -16,9 +16,9 @@
<p>FatFsモジュールでのファイル、ディレクトリ、ドライブの指定方法はDOS/Windows APIとほぼ同じです。パス名のフォーマットは次の通りです。</p>
<pre>"[論理ドライブ番号:][/]ディレクトリ名/ファイル名"</pre>
<p>FatFsモジュールは長いファイル名(LFN)および8.3形式ファイル名(SFN)に対応しています。LFNは、(<tt>_USE_LFN &gt; 0</tt>)のとき使用可能になります。ディレクトリ・セパレータにはDOS/Windows APIと同じく<tt>'/'</tt><tt>'\'</tt>を使用します。連続したセパレータは無視され1個として扱われます。唯一の違いは、論理ドライブの指定だけです。論理ドライブ番号は、<tt>'0'</tt><tt>'9'</tt>の一文字の数字とコロンで指定し、省略した場合は<em>デフォルト・ドライブ</em>(0またはカレント・ドライブ)が選択されます。</p>
<p>ヌル文字制御文字(<tt>'\0'</tt><tt>'\x1F'</tt>)は、パス名の終端として認識されます。パス名に先行あるいは中に含まれるスペースは、LFN構成では名前の一部として有効ですが、非LFN構成ではスペースはパス名の終端として認識されます。</p>
<p>ヌル文字制御文字(<tt>'\0'</tt><tt>'\x1F'</tt>)は、パス名の終端として認識されます。パス名に先行あるいは中に含まれるスペースは、LFN構成では名前の一部として有効ですが、非LFN構成ではスペースはパス名の終端として認識されます。</p>
<p>標準構成(<tt>_FS_RPATH == 0</tt>)のときは、全てのオブジェクトがルート・ディレクトリから辿る絶対パスで指定されます。OS指向なカレント・ディレクトリという概念は無く、またドット・ディレクトリ(&quot;.&quot;&quot;..&quot;)は使用できません。パス名先頭のセパレータは無視されます。デフォルト・ドライブ番号は常に0になります。</p>
<p>相対パスを有効(<tt>_FS_RPATH == 1</tt>)にしたときは、先行するセパレータの有無によって検索開始ディレクトリが変わり、セパレータがある場合はルート・ディレクトリから、無い場合は<a href="chdir.html">f_chdir関数</a>で設定されるカレント・ディレクトリからになります。またパス名にドット・ディレクトリが使用できます。デフォルト・ドライブ番号は<a href="chdrive.html">f_chdrive関数</a>で設定された値となります。</p>
<p>相対パスを有効(<tt>_FS_RPATH == 1</tt>)にしたときは、先行するセパレータの有無によって検索開始ディレクトリが変わり、セパレータがある場合はルート・ディレクトリから、無い場合は<a href="chdir.html"><tt>f_chdir()</tt></a>で設定されるカレント・ディレクトリからになります。またパス名にドット・ディレクトリが使用できます。デフォルト・ドライブ番号は<a href="chdrive.html"><tt>f_chdrive()</tt></a>で設定された値となります。</p>
<table class="lst2">
<tr><td>パス名の例</td><td>_FS_RPATH == 0</td><td>_FS_RPATH == 1</td></tr>
<tr class="lst3"><td>file.txt</td><td>ドライブ0のルート・ディレクトリ下のファイル</td><td>カレント・ドライブのカレント・ディレクトリ下のファイル</td></tr>
@ -33,12 +33,13 @@
<tr><td>dir1/..</td><td>無効</td><td>カレント・ディレクトリ</td></tr>
<tr><td>/..</td><td>無効</td><td>ルート・ディレクトリ(その上は辿れない)</td></tr>
</table>
<p>また、<tt>_STR_VOLUME_ID</tt>オプションを有効にすることでドライブ番号の識別には数字のほか、任意の文字列を使用することも可能になります。</p>
</div>
<p><br></p>
<div class="para" id="uni">
<h3>Unicode API</h3>
<p>ファイル関数の入出力のうちファイル名やパス名を指定する引数の型は、<tt>TCHAR</tt>で定義されていますが、これは通常は<tt>char</tt>のエリアスになっています。そして、<tt>_CODE_PAGE</tt>で指定されるANSI/OEMコード(SBCSまたはDBCS)の文字列として扱われます。ファイル名入出力をUnicodeとする構成(<tt>_LFN_UNICODE == 1</tt>)にしたときは、<tt>TCHAR</tt>はワイド文字(<tt>WCHAR, unsigned short</tt>)に切り替わり、パス名の入出力にUnicodeを使用するようになります。これによりLFN規格に完全対応となり、ANSI/OEMコードにない文字(たとえば ✝☪✡☸☭など)も使用できます。この設定は文字列入出力関数のデータ型とエンコーディングにも影響を与えます。リテラル文字列を定義するとき、次に示すように<tt>_T(s)</tt>および<tt>_TEXT(s)</tt>マクロを使ってANSI/OEMとUnicodeを自動切り替えすることができます。</p>
<p>ファイル関数の入出力のうちファイル名やパス名を指定する引数の型は、<tt>TCHAR</tt>で定義されていますが、これは通常は<tt>char</tt>のエリアスになっています。そして、<tt>_CODE_PAGE</tt>で指定されるANSI/OEMコード(SBCSまたはDBCS)の文字列として扱われます。ファイル名入出力をUnicodeとする構成(<tt>_LFN_UNICODE == 1</tt>)にしたときは、<tt>TCHAR</tt>はワイド文字(<tt>WCHAR, unsigned short</tt>)に切り替わり、パス名の入出力にUnicodeを使用するようになります。これによりLFN規格に完全対応となり、ANSI/OEMコードにない文字(たとえば ✝☪✡☸☭など)も使用できます。この設定は文字列入出力関数のデータ型とファイル上のエンコーディングにも影響を与えます。リテラル文字列を定義するとき、次に示すように<tt>_T(s)</tt>および<tt>_TEXT(s)</tt>マクロを使ってANSI/OEMとUnicodeを自動切り替えすることができます。</p>
<pre>
f_open(fp, "filename.txt", FA_READ); <span class="c">/* ANSI/OEM専用コード */</span>
f_open(fp, L"filename.txt", FA_READ); <span class="c">/* Unicode専用コード */</span>
@ -49,7 +50,7 @@
<p><br></p>
<div class="para" id="vol">
<h3>ボリューム管理</h3>
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、自動検出機能によりその物理ドライブ上の一つのFATボリュームがマウントされます。FATボリュームの検出は、セクタ0、第一区画、第二区画、第三区画、第四区画の順に行われます。</p>
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、自動検出機能によりその物理ドライブ上の一つのFATボリュームがマウントされます。FATボリュームの検出は、セクタ0、第一区画第四区画の順に行われます。</p>
<p><tt>_MULTI_PARTITION</tt>に1を指定すると、それぞれの論理ドライブに対して個別に物理ドライブ番号と区画を指定できるようになります。この構成では、論理ドライブと区画の対応を解決するためのテーブルを次に示すように定義する必要があります。</p>
<pre>
例:論理ドライブ02を物理ドライブ0(非リムーバブル)の3つの基本区画に割り当て、
@ -61,12 +62,13 @@ PARTITION VolToPart[] = {
{0, 3}, <span class="c">/* 論理ドライブ 2 ==> 物理ドライブ 0, 第3区画 */</span>
{1, 0} <span class="c">/* 論理ドライブ 3 ==> 物理ドライブ 1, 自動検出 */</span>
};
</pre>
<img src="../img/f7.png" width="828" height="288" alt="論理ドライブと物理ドライブの関係">
</pre>
<p>複数区画指定を使用する場合、次の点に注意しなければなりません。
<ul>
<li>マウント可能な区画は基本区画のみで、拡張区画内には対応しない。</li>
<li>複数の区画を持つ物理ドライブは、非リムーバブルでなければならない</li>
<li>複数のマウントされた区画を持つ物理ドライブは、非リムーバブルでなければならず、システム動作中のメディア交換は禁止</li>
</ul>
</div>

View File

@ -26,7 +26,7 @@ FRESULT f_getcwd (
<h4>引数</h4>
<dl class="par">
<dt>buff</dt>
<dd>カレント・ディレクトリの文字列を格納するバッファ</dd>
<dd>カレント・ディレクトリのパス名文字列を格納するバッファ</dd>
<dt>len</dt>
<dd>TCHAR単位のバッファ・サイズ</dd>
</dl>
@ -50,7 +50,7 @@ FRESULT f_getcwd (
<div class="para desc">
<h4>解説</h4>
<p>カレント・ドライブのカレント・ディレクトリのフル・パス文字列を取得します。<tt>_VOLUMES</tt>が2以上のときは、論理ドライブ番号の付加されたフル・パス名となります。</p>
<p>カレント・ドライブのカレント・ディレクトリのフル・パス文字列を取得します。<tt>_VOLUMES</tt>が2以上のときは、論理ドライブ番号の付加されたパス名となります。</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_getfree</h2>
<p>論理ドライブ上の未使用クラスタ数を取得します。</p>
<p>ボリューム上の未使用クラスタ数を取得します。</p>
<pre>
FRESULT f_getfree (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] 対象ドライブを指定します */</span>
@ -29,7 +29,7 @@ FRESULT f_getfree (
<dt>path</dt>
<dd>調べる対象の論理ドライブを示す<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。ヌル文字列はカレント・ドライブを意味します。</dd>
<dt>nclst</dt>
<dd>空きクラスタ数を格納する<tt>DWORD</tt>変数へのポインタを指定します。</dd>
<dd>空きクラスタ数を格納する<tt>DWORD</tt>変数へのポインタを指定します。</dd>
<dt>fatfs</dt>
<dd>対象ドライブのファイル・システム・オブジェクトを指すポインタが返されます。</dd>
</dl>
@ -53,7 +53,7 @@ FRESULT f_getfree (
<div class="para desc">
<h4>解説</h4>
<p>論理ドライブ上の空きクラスタ数を取得します。返されたファイル・システム・オブジェクトの<tt>csize</tt>メンバがクラスタあたりのセクタ数を示しているので、これを元に実際の空きサイズが計算できます。FAT32ボリュームにおいては、FSINFOが実際の状態と同期していない場合、不正確な空きサイズを返す可能性があります。この問題を避けるため、<tt>_FS_NOFSINFO</tt>オプションでFSINFOを無視して初回はフルFATスキャンをするように設定することもできます。</p>
<p>論理ドライブ上の空きクラスタ数を取得します。返されたファイル・システム・オブジェクトの<tt>csize</tt>メンバがクラスタあたりのセクタ数を示しているので、これを元にセクタ単位の空きサイズが計算できます。FAT32ボリュームにおいては、FSINFOの情報が実際の空きクラスタ数と同期していない場合、不正確な値を返す可能性があります。この問題を避けるため、<tt>_FS_NOFSINFO</tt>オプションでFSINFOを無視して初回はフルFATスキャンをするように構成することもできます。</p>
</div>

View File

@ -31,7 +31,7 @@ FRESULT f_getlabel (
<dt>name</dt>
<dd>ボリューム名を格納する配列へのポインタを指定します。少なくとも12要素のサイズが必要です。ボリューム名がない場合はヌル文字列が返されます。この情報が不要なときはヌル・ポインタを指定してください。</dd>
<dt>sn</dt>
<dd>ボリューム・シリアル番号を格納する<tt>DWORD</tt>変数へのポインタを指定します。この情報が不要なときはヌル・ポインタを指定してください。</dd>
<dd>ボリューム・シリアル番号を格納する<tt>DWORD</tt>変数へのポインタを指定します。この情報が不要なときはヌル・ポインタを指定してください。</dd>
</dl>
</div>

View File

@ -45,7 +45,7 @@ TCHAR* f_gets (
<div class="para desc">
<h4>解説</h4>
<p>この関数は<a href="read.html"><tt>f_read()</tt></a>のラッパー関数です。読み出し動作は、最初の<tt>'\n'</tt>を読み込むか、ファイル終端に達するか、<tt>len - 1</tt>文字を読み出すまで続きます。読み込まれた文字列の終端には<tt>'\0'</tt>が付加されます。既にファイル終端で1文字も読み込まれなかったとき、または何らかのエラーが発生したときは関数は失敗しヌル・ポインタを返します。ファイル終端かエラーかは<tt>f_eof()</tt>,<tt>f_error()</tt>マクロで調べられます。</p>
<p>APIにUnicodeが選択(<tt>_LFN_UNICODE</tt>が1)されているときは、<span class="arg">buff</span>はUTF-16文字列になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で読み出します。</p>
<p>Unicode API構成(<tt>_LFN_UNICODE == 1</tt>)が選択されているときは、<tt class="arg">buff</tt>はUTF-16文字列になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で読み出します。</p>
</div>

View File

@ -49,10 +49,10 @@ FRESULT f_mkfs (
<div class="para desc">
<h4>説明</h4>
<p>物理ドライブ上にFATボリュームを作成します。FDISK形式が指定された場合は、物理ドライブ全体を占める基本区画(パーテーション)が作成され、その中にFATボリュームが作成されます。SFD形式では、FATボリューム物理ドライブの先頭セクタからベタで作成されます。</p>
<p>マルチパーテーション機能(<tt>_MULTI_PARTITION</tt>)により、指定された論理ドライブが特定の区画(14)に結び付けられている場合、その区画の中に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タイプになるかはドライブ・サイズとクラスタ・サイズに依存します。クラスタ・サイズは大きくするほど性能が上がり、ディスク利用効率は落ちます。</p>
<p>物理ドライブ上にFATボリュームを作成します。FDISK形式が指定された場合は、物理ドライブ全体を占める基本区画(パーテーション)が作成され、その中にFATボリュームが作成されます。SFD形式では、FATボリューム物理ドライブの先頭セクタからベタで作成されます。</p>
<p>フォーマットする論理ドライブがマルチパーテーション機能(<tt>_MULTI_PARTITION</tt>)によって特定の区画(14)に結び付けられている場合、その区画の中に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タイプになるかはボリューム・サイズとクラスタ・サイズに依存します。クラスタ・サイズは大きくするほど性能が上がります。</p>
<p>クラスタ数がFATタイプの境界に近くなるときは、<tt>FR_MKFS_ABORTED</tt>で関数が失敗する可能性があります。</p>
</div>

View File

@ -59,7 +59,7 @@ FRESULT f_mount (
<p><tt class="arg">opt</tt>に0を指定すると、マウント動作(物理ドライブの初期化、FATボリュームの検索、BPBを解析しファイル・システム・オブジェクトを初期化)は行われず、関数は物理ドライブの状態に関わらず常に成功します。関数内では下位レイヤへのアクセスは発生せず、指定されたファイル・システム・オブジェクトをクリア(無効化)し、そのアドレスを内部配列に登録するだけです。単に登録済みのファイル・システム・オブジェクトをクリアする目的にも使えます。そして、続いてボリュームへのアクセスが行われたとき次のうちいずれかでも真の場合は、実際のマウント動作が行われます。</p>
<ul>
<li>ファイル・システム・オブジェクトがクリア(無効)状態(<tt>f_mount()</tt>の実行による)</li>
<li>物理ドライブが未初期化状態(システム・リセットやメディアの取り外しによる)</li>
<li>物理ドライブが未初期化状態(システム・リセットやメディアの交換による)</li>
</ul>
<p><tt class="arg">opt</tt>に1を指定すると、登録に続いてマウント動作が行われます。マウントに失敗すると対応するエラーを返しますが、登録は有効なので続くボリュームへのアクセスで再びマウント動作が実行されます。<p>
<p>下位レイヤの実装上メディア交換の検出がサポートされない(<tt>disk_status()</tt>に反映されない)ときは、アプリケーションはメディア交換の後この関数でファイル・システム・オブジェクトを明示的にクリアして再マウントが正常に行えるようにする必要があります。</p>

View File

@ -103,15 +103,15 @@ int main (void)
f_mount(&amp;FatFs, "", 0);
<span class="c">/* テキスト・ファイルを開く */</span>
fr = f_open(&fil, "message.txt", FA_READ);
fr = f_open(&amp;fil, "message.txt", FA_READ);
if (fr) return (int)fr;
<span class="c">/* 1行ずつ読み出して表示 */</span>
while (f_gets(line, sizeof line, &fil))
while (f_gets(line, sizeof line, &amp;fil))
printf(line);
<span class="c">/* ファイルを閉じる */</span>
f_close(&fil);
f_close(&amp;fil);
return 0;
}

View File

@ -47,8 +47,10 @@ FRESULT f_opendir (
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>

View File

@ -66,14 +66,17 @@ int f_printf (
<pre>
f_printf(&amp;fil, "%d", 1234); <span class="c">/* "1234" */</span>
f_printf(&amp;fil, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span>
f_printf(&amp;fil, "%-6u", 100); <span class="c">/* "100 " */</span>
f_printf(&amp;fil, "%ld", 12345678L); <span class="c">/* "12345678" */</span>
f_printf(&amp;fil, "%04x", 0xAB); <span class="c">/* "00ab" */</span>
f_printf(&amp;fil, "%ld", 12345L); <span class="c">/* "12345" */</span>
f_printf(&amp;fil, "%06d", 25); <span class="c">/* "000025" */</span>
f_printf(&amp;fil, "%06d", -25); <span class="c">/* "000-25" */</span>
f_printf(&amp;fil, "%-6d", 25); <span class="c">/* "25 " */</span>
f_printf(&amp;fil, "%u", -1); <span class="c">/* "65535" or "4294967295" */</span>
f_printf(&amp;fil, "%04x", 0xAB3); <span class="c">/* "0ab3" */</span>
f_printf(&amp;fil, "%08LX", 0x123ABCL); <span class="c">/* "00123ABC" */</span>
f_printf(&amp;fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span>
f_printf(&amp;fil, "%s", "String"); <span class="c">/* "String" */</span>
f_printf(&amp;fil, "%5s", "abc"); <span class="c">/* " abc" */</span>
f_printf(&amp;fil, "%-5s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%8s", "abc"); <span class="c">/* " abc" */</span>
f_printf(&amp;fil, "%-8s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%c", 'a'); <span class="c">/* "a" */</span>
f_printf(&amp;fil, "%f", 10.0); <span class="c">/* 浮動小数点は未サポート */</span>
</pre>

View File

@ -49,11 +49,11 @@
<dt id="ex">FR_EXIST</dt>
<dd>新しく作成しようとしたオブジェクトと同じ名前のオブジェクトが既に存在する。</dd>
<dt id="io">FR_INVALID_OBJECT</dt>
<dd>指定されたファイル・オブジェクトやディレクトリ・オブジェクトが無効(オープンされていない、破損しているなど)、またはヌル・ポインタが渡された。</dd>
<dd>指定されたファイル・オブジェクトやディレクトリ・オブジェクトが無効(オープンされていない、既に閉じられた、破損しているなど)、またはヌル・ポインタが渡された。また、開かれたままのオブジェクトは、そのボリュームのマウント動作により無効となります</dd>
<dt id="wp">FR_WRITE_PROTECTED</dt>
<dd>物理ドライブが書き込み禁止状態のとき、書き込み系の操作を行おうとした。</dd>
<dt id="id">FR_INVALID_DRIVE</dt>
<dd>パス名で指定されたドライブ番号が無効。(関連オプション: <tt>_VOLUMES</tt>)</dd>
<dd>パス名で指定されたドライブ番号が無効、またはパス名にヌル・ポインタが渡された。(関連オプション: <tt>_VOLUMES</tt>)</dd>
<dt id="ne">FR_NOT_ENABLED</dt>
<dd>そのボリュームの操作に必要なワーク・エリア(ファイル・システム・オブジェクト構造体)が与えられていない。</dd>
<dt id="ns">FR_NO_FILESYSTEM</dt>

View File

@ -26,9 +26,9 @@ FRESULT f_rename (
<h4>ˆø<EFBFBD></h4>
<dl class="par">
<dt>old_name</dt>
<dd>変更対象のオブジェクト<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。</dd>
<dd>変更対象のファイルまたはサブ・ディレクトリ<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。</dd>
<dt>new_name</dt>
<dd>新しいオブジェクトのパス名を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。既に存在する名前は使えません。また、ドライブ番号は指定できず<tt class="arg">old_name</tt>指定された論理ドライブ上のオブジェクトとして扱われます。<br>
<dd>新しいパス名を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。既に存在するオブジェクトと同じ名前は使えません。また、ドライブ番号は指定しても無視され<tt class="arg">old_name</tt>決められた論理ドライブ上のオブジェクトとして扱われます。</dd>
</dl>
</div>
@ -56,7 +56,7 @@ FRESULT f_rename (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>ファイルまたはサブ・ディレクトリの名前を変更します。また、同時に別のディレクトリへの移動も可能です。<em>開かれているオブジェクトに対して使用してはなりません</em></p>
<p>ファイルまたはサブ・ディレクトリの名前を変更します。また、同時に別のディレクトリへの移動も可能ですが、異なるドライブへの移動はできません<em>開かれているオブジェクトに対して使用してはなりません</em></p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para">
<h2>FATFS</h2>
<p><tt>FATFS</tt>構造体(ファイル・システム・オブジェクト)は、個々の論理ドライブのダイナミック・ワーク・エリアを保持し、<tt>f_mount()</tt>でFatFsモジュールに登録されます。初期化が行われるタイミングは、<tt>f_mount()</tt>またはメディア交換の後の最初のファイル・アクセスの時です。アプリケーションは、この構造体のメンバを書き換えてはなりません。</p>
<p><tt>FATFS</tt>構造体(ファイル・システム・オブジェクト)は、個々の論理ドライブのダイナミック・ワーク・エリアを保持し、<tt>f_mount()</tt>でFatFsモジュールに登録されます。初期化が行われるタイミングは、<tt>f_mount()</tt>(強制マウント指定)の実行またはメディア交換の後の最初のファイル・アクセスの時です。アプリケーションは、この構造体のメンバを書き換えてはなりません。</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> {
@ -25,7 +25,7 @@
BYTE fsi_flag; <span class="c">/* FSINFOフラグ (b7:Disabled, b0:Dirty)*/</span>
WORD id; <span class="c">/* ファイル・システム・マウントID */</span>
WORD n_rootdir; <span class="c">/* ルート・ディレクトリのエントリ数 (FAT12/16) */</span>
<span class="k">#if</span> _MAX_SS != 512
<span class="k">#if</span> _MAX_SS != _MIN_SS
WORD ssize; <span class="c">/* セクタ・サイズ (512, 1024, 2048 or 4096) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_REENTRANT

View File

@ -54,7 +54,7 @@ FRESULT f_stat (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>指定されたファイルまたはサブ・ディレクトリの存在を調べ、それ関する情報(サイズ、タイムスタンプおよび属性)を得ます。存在する場合は<tt>FR_OK</tt>が帰り、ファイル情報構造体にその情報がストアされます。存在しない場合は、<tt>FR_NO_FILE</tt>が帰ります。</p>
<p>指定されたファイルまたはサブ・ディレクトリの存在を調べます。存在しない場合は、<tt>FR_NO_FILE</tt>が帰ります。存在する場合は<tt>FR_OK</tt>が帰り、ファイル情報構造体にそれ関する情報(サイズ、タイムスタンプおよび属性)がストアされます。</p>
</div>

View File

@ -57,8 +57,8 @@ FRESULT f_unlink (
<p>削除対象のオブジェクトが次の条件に当てはまる場合、そのアクセスは拒否(<tt>FR_DENIED</tt>または<tt>FR_LOCKED</tt>)され関数は失敗します。
<ul>
<li>リード・オンリー属性(<tt>AM_RDO</tt>)を持っている。</li>
<li>空でないサブ・ディレクトリまたはカレント・ディレクトリ。</li>
<li>開かれているファイルまたはサブ・ディレクトリ。<a href="appnote.html#dup">多重アクセス制御</a>が有効なときは安全に拒否されますが、そうでないときは不正な操作となり、<em>FAT構造が破壊される可能性</em>があります。</li>
<li>空でないサブ・ディレクトリまたはカレント・ディレクトリである</li>
<li>開かれているファイルまたはサブ・ディレクトリである<a href="appnote.html#dup">多重アクセス制御</a>が有効なときは安全に拒否されますが、そうでないときは不正な操作となり、<em>FAT構造が破壊される可能性</em>があります。</li>
</ul>
</p>
</div>

View File

@ -1,3 +1,12 @@
R0.10a, Jan 15,'14
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
Added a configuration option of minimum sector size. (_MIN_SS)
2nd argument of f_rename() can have a drive number and it will be ignored.
Fixed f_mount() with forced mount fails when drive number is >= 1.
Fixed f_close() invalidates the file object without volume lock.
Fixed f_closedir() returns but the volume lock is left acquired.
Fixed creation of an entry with LFN fails on too many SFN collisions.
R0.10, Oct 02,'13
Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().

View File

@ -1,4 +1,4 @@
FatFs Module Source Files R0.10 (C)ChaN, 2013
FatFs Module Source Files R0.10a (C)ChaN, 2014
FILES
@ -24,7 +24,7 @@ AGREEMENTS
small embedded systems. This is a free software and is opened for education,
research and commercial developments under license policy of following trems.
Copyright (C) 2013, ChaN, all right reserved.
Copyright (C) 2014, ChaN, all right reserved.
* The FatFs module is a free software and there is NO WARRANTY.
* No restriction on use. You can use, modify and redistribute it for
@ -134,7 +134,7 @@ REVISION HISTORY
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
Changed option name _FS_SHARE to _FS_LOCK.
Jan 23,'13 R0.09b Added f_getlabel() and f_setlabel(). (_USE_LABEL == 1)
Jan 23,'13 R0.09b Added f_getlabel() and f_setlabel(). (_USE_LABEL)
Oct 02,'13 R0.10 Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().
@ -145,3 +145,11 @@ REVISION HISTORY
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
Fixed f_write() can be truncated when the file size is close to 4GB.
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
Jan 15,'14 R0.10a Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
Added a configuration option of minimum sector size. (_MIN_SS)
2nd argument of f_rename() can have a drive number and it will be ignored.
Fixed f_mount() with forced mount fails when drive number is >= 1.
Fixed f_close() invalidates the file object without volume lock.
Fixed f_closedir() returns but the volume lock is left acquired.
Fixed creation of an entry with LFN fails on too many SFN collisions.

View File

@ -1,5 +1,5 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file (C)ChaN, 2013
/*-----------------------------------------------------------------------/
/ Low level disk interface modlue include file (C)ChaN, 2013 /
/-----------------------------------------------------------------------*/
#ifndef _DISKIO_DEFINED
@ -34,12 +34,13 @@ typedef enum {
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, UINT count);
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
/* Disk Status Bits (DSTATUS) */
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
@ -72,15 +73,6 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */
/* MMC card type flags (MMC_GET_TYPE) */
#define CT_MMC 0x01 /* MMC ver 3 */
#define CT_SD1 0x02 /* SD ver 1 */
#define CT_SD2 0x04 /* SD ver 2 */
#define CT_SDC (CT_SD1|CT_SD2) /* SD */
#define CT_BLOCK 0x08 /* Block addressing */
#ifdef __cplusplus
}
#endif

485
src/ff.c
View File

@ -1,11 +1,11 @@
/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.10 (C)ChaN, 2013
/ FatFs - FAT file system module R0.10a (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
/ developments under license policy of following terms.
/
/ Copyright (C) 2013, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
@ -104,34 +104,32 @@
/ Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
/ Fixed f_write() can be truncated when the file size is close to 4GB.
/ Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
/ Jan 15,'14 R0.10a Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
/ Added a configuration option of minimum sector size. (_MIN_SS)
/ 2nd argument of f_rename() can have a drive number and it will be ignored.
/ Fixed f_mount() with forced mount fails when drive number is >= 1.
/ Fixed f_close() invalidates the file object without volume lock.
/ Fixed f_closedir() returns but the volume lock is left acquired.
/ Fixed creation of an entry with LFN fails on too many SFN collisions.
/---------------------------------------------------------------------------*/
#include "ff.h" /* Declarations of FatFs API */
#include "diskio.h" /* Declarations of disk I/O functions */
/*--------------------------------------------------------------------------
Module Private Definitions
---------------------------------------------------------------------------*/
#if _FATFS != 80960 /* Revision ID */
#if _FATFS != 29000 /* Revision ID */
#error Wrong include file (ff.h).
#endif
/* Definitions on sector size */
#if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
#error Wrong sector size.
#endif
#if _MAX_SS != 512
#define SS(fs) ((fs)->ssize) /* Variable sector size */
#else
#define SS(fs) 512U /* Fixed sector size */
#endif
/* Reentrancy related */
#if _FS_REENTRANT
#if _USE_LFN == 1
@ -147,6 +145,17 @@
#define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
/* Definitions of sector size */
#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
#error Wrong sector size configuration.
#endif
#if _MAX_SS == _MIN_SS
#define SS(fs) ((UINT)_MIN_SS) /* Fixed sector size */
#else
#define SS(fs) ((fs)->ssize) /* Variable sector size */
#endif
/* File access control feature */
#if _FS_LOCK
#if _FS_READONLY
@ -466,27 +475,29 @@ typedef struct {
#define NDDE 0x05 /* Replacement of the character collides with DDE */
/*------------------------------------------------------------*/
/* Module private work area */
/*------------------------------------------------------------*/
/* Note that uninitialized variables with static duration are
/ zeroed/nulled at start-up. If not, the compiler or start-up
/ routine is out of ANSI-C standard.
/ guaranteed zero/null as initial value. If not, either the
/ compiler or start-up routine is out of ANSI-C standard.
*/
#if _VOLUMES
#if _VOLUMES >= 1 || _VOLUMES <= 10
static
FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
#else
#error Number of volumes must not be 0.
#error Number of volumes must be 1 to 10.
#endif
static
WORD Fsid; /* File system mount ID */
WORD Fsid; /* File system mount ID */
#if _FS_RPATH && _VOLUMES >= 2
static
BYTE CurrVol; /* Current drive */
BYTE CurrVol; /* Current drive */
#endif
#if _FS_LOCK
@ -879,6 +890,9 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status
if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break;
p = &fs->win[clst * 4 % SS(fs)];
return LD_DWORD(p) & 0x0FFFFFFF;
default:
return 1;
}
return 0xFFFFFFFF; /* An error occurred at the disk I/O layer */
@ -1023,7 +1037,8 @@ DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk err
}
else { /* Stretch the current chain */
cs = get_fat(fs, clst); /* Check the cluster status */
if (cs < 2) return 1; /* It is an invalid cluster */
if (cs < 2) return 1; /* Invalid value */
if (cs == 0xFFFFFFFF) return cs; /* A disk error occurred */
if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */
scl = clst;
}
@ -1031,7 +1046,7 @@ DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk err
ncl = scl; /* Start cluster */
for (;;) {
ncl++; /* Next cluster */
if (ncl >= fs->n_fatent) { /* Wrap around */
if (ncl >= fs->n_fatent) { /* Check wrap around */
ncl = 2;
if (ncl > scl) return 0; /* No free cluster */
}
@ -1099,42 +1114,42 @@ DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */
static
FRESULT dir_sdi (
DIR* dp, /* Pointer to directory object */
WORD idx /* Index of directory table */
UINT idx /* Index of directory table */
)
{
DWORD clst;
WORD ic;
DWORD clst, sect;
UINT ic;
dp->index = idx;
clst = dp->sclust;
dp->index = (WORD)idx; /* Current index */
clst = dp->sclust; /* Table start cluster (0:root) */
if (clst == 1 || clst >= dp->fs->n_fatent) /* Check start cluster range */
return FR_INT_ERR;
if (!clst && dp->fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */
clst = dp->fs->dirbase;
if (clst == 0) { /* Static table (root-directory in FAT12/16) */
dp->clust = clst;
if (idx >= dp->fs->n_rootdir) /* Index is out of range */
if (idx >= dp->fs->n_rootdir) /* Is index out of range? */
return FR_INT_ERR;
dp->sect = dp->fs->dirbase + idx / (SS(dp->fs) / SZ_DIR); /* Sector# */
sect = dp->fs->dirbase;
}
else { /* Dynamic table (sub-dirs or root-directory in FAT32) */
else { /* Dynamic table (root-directory in FAT32 or sub-directory) */
ic = SS(dp->fs) / SZ_DIR * dp->fs->csize; /* Entries per cluster */
while (idx >= ic) { /* Follow cluster chain */
clst = get_fat(dp->fs, clst); /* Get next cluster */
if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */
if (clst < 2 || clst >= dp->fs->n_fatent) /* Reached to end of table or int error */
if (clst < 2 || clst >= dp->fs->n_fatent) /* Reached to end of table or internal error */
return FR_INT_ERR;
idx -= ic;
}
dp->clust = clst;
dp->sect = clust2sect(dp->fs, clst) + idx / (SS(dp->fs) / SZ_DIR); /* Sector# */
sect = clust2sect(dp->fs, clst);
}
dp->clust = clst; /* Current cluster# */
if (!sect) return FR_INT_ERR;
dp->sect = sect + idx / (SS(dp->fs) / SZ_DIR); /* Sector# of the directory entry */
dp->dir = dp->fs->win + (idx % (SS(dp->fs) / SZ_DIR)) * SZ_DIR; /* Ptr to the entry in the sector */
return FR_OK; /* Seek succeeded */
return FR_OK;
}
@ -1151,11 +1166,11 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
)
{
DWORD clst;
WORD i;
UINT i;
i = dp->index + 1;
if (!i || !dp->sect) /* Report EOT when index has reached 65535 */
if (!(i & 0xFFFF) || !dp->sect) /* Report EOT when index has reached 65535 */
return FR_NO_FILE;
if (!(i % (SS(dp->fs) / SZ_DIR))) { /* Sector changed? */
@ -1172,7 +1187,7 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
if (clst >= dp->fs->n_fatent) { /* If it reached end of dynamic table, */
#if !_FS_READONLY
BYTE c;
UINT c;
if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT */
clst = create_chain(dp->fs, dp->clust); /* Stretch cluster chain */
if (clst == 0) return FR_DENIED; /* No free cluster */
@ -1189,7 +1204,7 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
}
dp->fs->winsect -= c; /* Rewind window offset */
#else
if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT */
if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT (this is to suppress warning) */
return FR_NO_FILE; /* Report EOT */
#endif
}
@ -1199,7 +1214,7 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
}
}
dp->index = i; /* Current index */
dp->index = (WORD)i; /* Current index */
dp->dir = dp->fs->win + (i % (SS(dp->fs) / SZ_DIR)) * SZ_DIR; /* Current entry in the window */
return FR_OK;
@ -1390,11 +1405,12 @@ void fit_lfn (
/* Create numbered name */
/*-----------------------------------------------------------------------*/
#if _USE_LFN
static
void gen_numname (
BYTE* dst, /* Pointer to generated SFN */
const BYTE* src, /* Pointer to source SFN to be modified */
BYTE* dst, /* Pointer to the buffer to store numbered SFN */
const BYTE* src, /* Pointer to SFN */
const WCHAR* lfn, /* Pointer to LFN */
WORD seq /* Sequence number */
UINT seq /* Sequence number */
)
{
BYTE ns[8], c;
@ -1404,7 +1420,18 @@ void gen_numname (
mem_cpy(dst, src, 11);
if (seq > 5) { /* On many collisions, generate a hash number instead of sequential number */
do seq = (seq >> 1) + (seq << 15) + (WORD)*lfn++; while (*lfn);
WCHAR wc;
DWORD sr = seq;
while (*lfn) { /* Create a CRC */
wc = *lfn++;
for (i = 0; i < 16; i++) {
sr = (sr << 1) + (wc & 1);
wc >>= 1;
if (sr & 0x10000) sr ^= 0x11021;
}
}
seq = (UINT)sr;
}
/* itoa (hexdecimal) */
@ -1584,7 +1611,7 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
{
FRESULT res;
#if _USE_LFN /* LFN configuration */
WORD n, ne;
UINT n, nent;
BYTE sn[12], *fn, sum;
WCHAR *lfn;
@ -1609,23 +1636,23 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
if (sn[NS] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */
for (n = 0; lfn[n]; n++) ;
ne = (n + 25) / 13;
nent = (n + 25) / 13;
} else { /* Otherwise allocate an entry for an SFN */
ne = 1;
nent = 1;
}
res = dir_alloc(dp, ne); /* Allocate entries */
res = dir_alloc(dp, nent); /* Allocate entries */
if (res == FR_OK && --ne) { /* Set LFN entry if needed */
res = dir_sdi(dp, (WORD)(dp->index - ne));
if (res == FR_OK && --nent) { /* Set LFN entry if needed */
res = dir_sdi(dp, dp->index - nent);
if (res == FR_OK) {
sum = sum_sfn(dp->fn); /* Sum value of the SFN tied to the LFN */
do { /* Store LFN entries in bottom first */
res = move_window(dp->fs, dp->sect);
if (res != FR_OK) break;
fit_lfn(dp->lfn, dp->dir, (BYTE)ne, sum);
fit_lfn(dp->lfn, dp->dir, (BYTE)nent, sum);
dp->fs->wflag = 1;
res = dir_next(dp, 0); /* Next entry */
} while (res == FR_OK && --ne);
} while (res == FR_OK && --nent);
}
}
#else /* Non LFN configuration */
@ -1662,15 +1689,16 @@ FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */
{
FRESULT res;
#if _USE_LFN /* LFN configuration */
WORD i;
UINT i;
i = dp->index; /* SFN index */
res = dir_sdi(dp, (WORD)((dp->lfn_idx == 0xFFFF) ? i : dp->lfn_idx)); /* Goto the SFN or top of the LFN entries */
res = dir_sdi(dp, (dp->lfn_idx == 0xFFFF) ? i : dp->lfn_idx); /* Goto the SFN or top of the LFN entries */
if (res == FR_OK) {
do {
res = move_window(dp->fs, dp->sect);
if (res != FR_OK) break;
*dp->dir = DDE; /* Mark the entry "deleted" */
mem_set(dp->dir, 0, SZ_DIR); /* Clear and mark the entry "deleted" */
*dp->dir = DDE;
dp->fs->wflag = 1;
if (dp->index >= i) break; /* When reached SFN, all entries of the object has been deleted. */
res = dir_next(dp, 0); /* Next entry */
@ -1683,7 +1711,8 @@ FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */
if (res == FR_OK) {
res = move_window(dp->fs, dp->sect);
if (res == FR_OK) {
*dp->dir = DDE; /* Mark the entry "deleted" */
mem_set(dp->dir, 0, SZ_DIR); /* Clear and mark the entry "deleted" */
*dp->dir = DDE;
dp->fs->wflag = 1;
}
}
@ -1696,6 +1725,76 @@ FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */
/*-----------------------------------------------------------------------*/
/* Get file information from directory entry */
/*-----------------------------------------------------------------------*/
#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
static
void get_fileinfo ( /* No return code */
DIR* dp, /* Pointer to the directory object */
FILINFO* fno /* Pointer to the file information to be filled */
)
{
UINT i;
TCHAR *p, c;
p = fno->fname;
if (dp->sect) { /* Get SFN */
BYTE *dir = dp->dir;
i = 0;
while (i < 11) { /* Copy name body and extension */
c = (TCHAR)dir[i++];
if (c == ' ') continue; /* Skip padding spaces */
if (c == NDDE) c = (TCHAR)DDE; /* Restore replaced DDE character */
if (i == 9) *p++ = '.'; /* Insert a . if extension is exist */
#if _USE_LFN
if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
c += 0x20; /* To lower */
#if _LFN_UNICODE
if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
c = c << 8 | dir[i++];
c = ff_convert(c, 1); /* OEM -> Unicode */
if (!c) c = '?';
#endif
#endif
*p++ = c;
}
fno->fattrib = dir[DIR_Attr]; /* Attribute */
fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */
fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */
fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */
}
*p = 0; /* Terminate SFN string by a \0 */
#if _USE_LFN
if (fno->lfname) {
WCHAR w, *lfn;
i = 0; p = fno->lfname;
if (dp->sect && fno->lfsize && dp->lfn_idx != 0xFFFF) { /* Get LFN if available */
lfn = dp->lfn;
while ((w = *lfn++) != 0) { /* Get an LFN character */
#if !_LFN_UNICODE
w = ff_convert(w, 0); /* Unicode -> OEM */
if (!w) { i = 0; break; } /* No LFN if it could not be converted */
if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */
p[i++] = (TCHAR)(w >> 8);
#endif
if (i >= fno->lfsize - 1) { i = 0; break; } /* No LFN if buffer overflow */
p[i++] = (TCHAR)w;
}
}
p[i] = 0; /* Terminate LFN string by a \0 */
}
#endif
}
#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2*/
/*-----------------------------------------------------------------------*/
/* Pick a segment and create the object name in directory form */
/*-----------------------------------------------------------------------*/
@ -1906,108 +2005,6 @@ FRESULT create_name (
/*-----------------------------------------------------------------------*/
/* Get file information from directory entry */
/*-----------------------------------------------------------------------*/
#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
static
void get_fileinfo ( /* No return code */
DIR* dp, /* Pointer to the directory object */
FILINFO* fno /* Pointer to the file information to be filled */
)
{
UINT i;
TCHAR *p, c;
p = fno->fname;
if (dp->sect) { /* Get SFN */
BYTE *dir = dp->dir;
i = 0;
while (i < 11) { /* Copy name body and extension */
c = (TCHAR)dir[i++];
if (c == ' ') continue; /* Skip padding spaces */
if (c == NDDE) c = (TCHAR)DDE; /* Restore replaced DDE character */
if (i == 9) *p++ = '.'; /* Insert a . if extension is exist */
#if _USE_LFN
if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
c += 0x20; /* To lower */
#if _LFN_UNICODE
if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
c = c << 8 | dir[i++];
c = ff_convert(c, 1); /* OEM -> Unicode */
if (!c) c = '?';
#endif
#endif
*p++ = c;
}
fno->fattrib = dir[DIR_Attr]; /* Attribute */
fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */
fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */
fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */
}
*p = 0; /* Terminate SFN string by a \0 */
#if _USE_LFN
if (fno->lfname) {
WCHAR w, *lfn;
i = 0; p = fno->lfname;
if (dp->sect && fno->lfsize && dp->lfn_idx != 0xFFFF) { /* Get LFN if available */
lfn = dp->lfn;
while ((w = *lfn++) != 0) { /* Get an LFN character */
#if !_LFN_UNICODE
w = ff_convert(w, 0); /* Unicode -> OEM */
if (!w) { i = 0; break; } /* No LFN if it could not be converted */
if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */
p[i++] = (TCHAR)(w >> 8);
#endif
if (i >= fno->lfsize - 1) { i = 0; break; } /* No LFN if buffer overflow */
p[i++] = (TCHAR)w;
}
}
p[i] = 0; /* Terminate LFN string by a \0 */
}
#endif
}
#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2*/
/*-----------------------------------------------------------------------*/
/* Get logical drive number from path name */
/*-----------------------------------------------------------------------*/
static
int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */
const TCHAR** path /* Pointer to pointer to the path name */
)
{
int vol = -1;
if (*path) {
vol = (*path)[0] - '0';
if ((UINT)vol < 9 && (*path)[1] == ':') { /* There is a drive number */
*path += 2; /* Get value and strip it */
if (vol >= _VOLUMES) vol = -1; /* Check if the drive number is valid */
} else { /* No drive number use default drive */
#if _FS_RPATH && _VOLUMES >= 2
vol = CurrVol; /* Current drive */
#else
vol = 0; /* Drive 0 */
#endif
}
}
return vol;
}
/*-----------------------------------------------------------------------*/
/* Follow a file path */
/*-----------------------------------------------------------------------*/
@ -2070,6 +2067,65 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
/*-----------------------------------------------------------------------*/
/* Get logical drive number from path name */
/*-----------------------------------------------------------------------*/
static
int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */
const TCHAR** path /* Pointer to pointer to the path name */
)
{
const TCHAR *tp, *tt;
UINT i;
int vol = -1;
if (*path) { /* If the pointer is not a null */
for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ; /* Find ':' in the path */
if (*tt == ':') { /* If a ':' is exist in the path name */
tp = *path;
i = *tp++ - '0';
if (i < 10 && tp == tt) { /* Is there a numeric drive id? */
if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */
vol = (int)i;
*path = ++tt;
}
} else { /* No numeric drive number */
#if _STR_VOLUME_ID /* Find string drive id */
static const char* const str[] = {_VOLUME_STRS};
const char *sp;
char c;
TCHAR tc;
i = 0; tt++;
do {
sp = str[i]; tp = *path;
do { /* Compare a string drive id with path name */
c = *sp++; tc = *tp++;
if (IsLower(tc)) tc -= 0x20;
} while (c && (TCHAR)c == tc);
} while ((c || tp != tt) && ++i < _VOLUMES); /* Repeat for each id until pattern match */
if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */
vol = (int)i;
*path = tt;
}
#endif
}
return vol;
}
#if _FS_RPATH && _VOLUMES >= 2
vol = CurrVol; /* Current drive */
#else
vol = 0; /* Drive 0 */
#endif
}
return vol;
}
/*-----------------------------------------------------------------------*/
/* Load a sector and check if it is an FAT boot sector */
/*-----------------------------------------------------------------------*/
@ -2148,9 +2204,9 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */
if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */
return FR_WRITE_PROTECTED;
#if _MAX_SS != 512 /* Get sector size (variable sector size cfg only) */
if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &fs->ssize) != RES_OK)
return FR_DISK_ERR;
#if _MAX_SS != _MIN_SS /* Get sector size (multiple sector size cfg only) */
if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
|| SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR;
#endif
/* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */
bsect = 0;
@ -2218,14 +2274,14 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
if (fmt == FS_FAT32) {
if (fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */
fs->dirbase = LD_DWORD(fs->win+BPB_RootClus); /* Root directory start cluster */
szbfat = fs->n_fatent * 4; /* (Required FAT size) */
szbfat = fs->n_fatent * 4; /* (Needed FAT size) */
} else {
if (!fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */
fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */
szbfat = (fmt == FS_FAT16) ? /* (Required FAT size) */
szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */
fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
}
if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than required) */
if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than needed) */
return FR_NO_FILESYSTEM;
#if !_FS_READONLY
@ -2234,6 +2290,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
/* Get fsinfo if available */
fs->fsi_flag = 0x80;
#if (_FS_NOFSINFO & 3) != 3
if (fmt == FS_FAT32 /* Enable FSINFO only if FAT32 and BPB_FSInfo is 1 */
&& LD_WORD(fs->win+BPB_FSInfo) == 1
&& move_window(fs, bsect + 1) == FR_OK)
@ -2243,17 +2300,20 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
&& LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252
&& LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272)
{
#if !_FS_NOFSINFO
#if (_FS_NOFSINFO & 1) == 0
fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count);
#endif
#if (_FS_NOFSINFO & 2) == 0
fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free);
#endif
}
}
#endif
#endif
fs->fs_type = fmt; /* FAT sub-type */
fs->id = ++Fsid; /* File system mount ID */
#if _FS_RPATH
fs->cdir = 0; /* Current directory (root dir) */
fs->cdir = 0; /* Set current directory to root */
#endif
#if _FS_LOCK /* Clear file lock semaphores */
clear_lock(fs);
@ -2312,9 +2372,10 @@ FRESULT f_mount (
FATFS *cfs;
int vol;
FRESULT res;
const TCHAR *rp = path;
vol = get_ldnumber(&path);
vol = get_ldnumber(&rp);
if (vol < 0) return FR_INVALID_DRIVE;
cfs = FatFs[vol]; /* Pointer to fs object */
@ -2331,7 +2392,7 @@ FRESULT f_mount (
if (fs) {
fs->fs_type = 0; /* Clear new fs object */
#if _FS_REENTRANT /* Create sync object for the new volume */
if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
#endif
}
FatFs[vol] = fs; /* Register new fs object */
@ -2762,34 +2823,27 @@ FRESULT f_close (
FRESULT res;
#if _FS_READONLY
res = validate(fp);
{
#if _FS_REENTRANT
FATFS *fs = 0;
if (res == FR_OK) fs = fp->fs; /* Get corresponding file system object */
#endif
if (res == FR_OK) fp->fs = 0; /* Invalidate file object */
LEAVE_FF(fs, res);
}
#else
#if !_FS_READONLY
res = f_sync(fp); /* Flush cached data */
#if _FS_LOCK
if (res == FR_OK) { /* Decrement open counter */
#if _FS_REENTRANT
res = validate(fp);
if (res == FR_OK)
#endif
{
res = validate(fp); /* Lock volume */
if (res == FR_OK) {
res = dec_lock(fp->lockid);
unlock_fs(fp->fs, FR_OK);
#if _FS_REENTRANT
FATFS *fs = fp->fs;
#endif
#if _FS_LOCK
res = dec_lock(fp->lockid); /* Decrement file open counter */
if (res == FR_OK)
#endif
fp->fs = 0; /* Invalidate file object */
#if _FS_REENTRANT
unlock_fs(fs, FR_OK); /* Unlock volume */
#endif
}
#else
res = dec_lock(fp->lockid);
#endif
}
#endif
if (res == FR_OK) fp->fs = 0; /* Invalidate file object */
return res;
#endif
}
@ -3156,16 +3210,20 @@ FRESULT f_closedir (
res = validate(dp);
#if _FS_LOCK
if (res == FR_OK) { /* Decrement open counter */
if (dp->lockid)
res = dec_lock(dp->lockid);
if (res == FR_OK) {
#if _FS_REENTRANT
unlock_fs(dp->fs, FR_OK);
FATFS *fs = dp->fs;
#endif
#if _FS_LOCK
if (dp->lockid) /* Decrement sub-directory open counter */
res = dec_lock(dp->lockid);
if (res == FR_OK)
#endif
dp->fs = 0; /* Invalidate directory object */
#if _FS_REENTRANT
unlock_fs(fs, FR_OK); /* Unlock volume */
#endif
}
#endif
if (res == FR_OK) dp->fs = 0; /* Invalidate directory object */
return res;
}
@ -3606,7 +3664,7 @@ FRESULT f_utime (
/*-----------------------------------------------------------------------*/
FRESULT f_rename (
const TCHAR* path_old, /* Pointer to the old name */
const TCHAR* path_old, /* Pointer to the object to be renamed */
const TCHAR* path_new /* Pointer to the new name */
)
{
@ -3632,15 +3690,18 @@ FRESULT f_rename (
if (!djo.dir) { /* Is root dir? */
res = FR_NO_FILE;
} else {
mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except for name */
mem_cpy(&djn, &djo, sizeof (DIR)); /* Check new object */
res = follow_path(&djn, path_new);
mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except name */
mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */
res = follow_path(&djn, path_new); /* and check if new object is exist */
else
res = FR_INVALID_DRIVE;
if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */
if (res == FR_NO_FILE) { /* Is it a valid path and no name collision? */
/* Start critical section that any interruption can cause a cross-link */
res = dir_register(&djn); /* Register the new entry */
if (res == FR_OK) {
dir = djn.dir; /* Copy object information except for name */
dir = djn.dir; /* Copy object information except name */
mem_cpy(dir+13, buf+2, 19);
dir[DIR_Attr] = buf[0] | AM_ARC;
djo.fs->wflag = 1;
@ -3707,7 +3768,7 @@ FRESULT f_getlabel (
if (res == FR_OK) {
res = dir_read(&dj, 1); /* Get an entry with AM_VOL */
if (res == FR_OK) { /* A volume label is exist */
#if _LFN_UNICODE
#if _USE_LFN && _LFN_UNICODE
WCHAR w;
i = j = 0;
do {
@ -3774,7 +3835,7 @@ FRESULT f_setlabel (
if (sl) { /* Create volume label in directory form */
i = j = 0;
do {
#if _LFN_UNICODE
#if _USE_LFN && _LFN_UNICODE
w = ff_convert(ff_wtoupper(label[i++]), 0);
#else
w = (BYTE)label[i++];
@ -3942,8 +4003,8 @@ FRESULT f_mkfs (
stat = disk_initialize(pdrv);
if (stat & STA_NOINIT) return FR_NOT_READY;
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
#if _MAX_SS != 512 /* Get disk sector size */
if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS)
#if _MAX_SS != _MIN_SS /* Get disk sector size */
if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS)
return FR_DISK_ERR;
#endif
if (_MULTI_PARTITION && part) {
@ -4118,7 +4179,7 @@ FRESULT f_mkfs (
}
/* Initialize root directory */
i = (fmt == FS_FAT32) ? au : n_dir;
i = (fmt == FS_FAT32) ? au : (UINT)n_dir;
do {
if (disk_write(pdrv, tbl, wsect++, 1))
return FR_DISK_ERR;
@ -4240,7 +4301,7 @@ TCHAR* f_gets (
while (n < len - 1) { /* Read characters until buffer gets filled */
#if _LFN_UNICODE
#if _USE_LFN && _LFN_UNICODE
#if _STRF_ENCODE == 3 /* Read a character in UTF-8 */
f_read(fp, s, 1, &rc);
if (rc != 1) break;
@ -4328,7 +4389,7 @@ void putc_bfd (
i = pb->idx; /* Buffer write index (-1:error) */
if (i < 0) return;
#if _LFN_UNICODE
#if _USE_LFN && _LFN_UNICODE
#if _STRF_ENCODE == 3 /* Write a character in UTF-8 */
if (c < 0x80) { /* 7-bit */
pb->buf[i++] = (BYTE)c;

View File

@ -1,11 +1,11 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.10 (C)ChaN, 2013
/ FatFs - FAT file system module include file R0.10a (C)ChaN, 2014
/----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
/ developments under license policy of following terms.
/
/ Copyright (C) 2013, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
@ -15,7 +15,7 @@
/----------------------------------------------------------------------------*/
#ifndef _FATFS
#define _FATFS 80960 /* Revision ID */
#define _FATFS 29000 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@ -83,7 +83,7 @@ typedef struct {
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
#if _MAX_SS != 512
#if _MAX_SS != _MIN_SS
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
#endif
#if _FS_REENTRANT

View File

@ -1,23 +1,20 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.10 (C)ChaN, 2013
/----------------------------------------------------------------------------/
/
/ CAUTION! Do not forget to make clean the project after any changes to
/ the configuration options.
/
/----------------------------------------------------------------------------*/
/ FatFs - FAT file system module configuration file R0.10a (C)ChaN, 2014
/---------------------------------------------------------------------------*/
#ifndef _FFCONF
#define _FFCONF 80960 /* Revision ID */
#define _FFCONF 29000 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Functions and Buffer Configurations
/----------------------------------------------------------------------------*/
/---------------------------------------------------------------------------*/
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
/ object instead of the sector buffer in the individual file object for file
/ data transfer. This reduces memory consumption 512 bytes each file object. */
/* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
/ file object. For file data transfer, FatFs uses the common sector buffer in
/ the file system object (FATFS) instead of private sector buffer eliminated
/ from the file object (FIL). */
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
@ -58,7 +55,7 @@
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/----------------------------------------------------------------------------*/
/---------------------------------------------------------------------------*/
#define _CODE_PAGE 932
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
@ -89,20 +86,19 @@
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
/ 1 - ASCII (Valid for only non-LFN cfg.)
*/
/ 1 - ASCII (Valid for only non-LFN cfg.) */
#define _USE_LFN 0 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN feature.
/
/ 0: Disable LFN feature. _MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ To enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
/ When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
/ function must be added to the project.
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
/ working buffer, take care on stack overflow. When use heap memory for the working
@ -111,15 +107,15 @@
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
/* To switch the character encoding on the FatFs API to Unicode, enable LFN feature
/ and set _LFN_UNICODE to 1. */
/* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
/ feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
/ functions. */
#define _STRF_ENCODE 3 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
/* When Unicode API is enabled, character encoding on the all FatFs API is switched
/ to Unicode. This option selects the character encoding on the file to be read/written
/ via string functions, f_gets(), f_putc(), f_puts and f_printf().
/ This option has no effect when _LFN_UNICODE is 0. */
/* When Unicode API is enabled by _LFN_UNICODE option, 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(). This option has no effect when Unicode API is not enabled. */
#define _FS_RPATH 0 /* 0 to 2 */
@ -134,24 +130,34 @@
/*---------------------------------------------------------------------------/
/ Drive/Volume Configurations
/----------------------------------------------------------------------------*/
/---------------------------------------------------------------------------*/
#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
/* When _STR_VOLUME_ID is set to 1, also pre-defined string can be used as drive number
/ in the path name. _VOLUME_STRS defines the drive ID strings for each logical drives.
/ Number of items must be equal to _VOLUMES. Valid characters for the drive ID strings
/ are: 0-9 and A-Z. */
#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Enable multiple partition */
/* When set to 0, each volume is bound to the same physical drive number and
/ it can mount only first primaly partition. When it is set to 1, each volume
/ is tied to the partitions listed in VolToPart[]. */
/* By default(0), each logical drive number is bound to the same physical drive number
/ and only a FAT volume found on the physical drive is mounted. When it is set to 1,
/ each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
*/
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for on-board flash memory, floppy disk and optical disk.
/ When _MAX_SS is larger than 512, it configures FatFs to variable sector size
/ and GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
#define _MIN_SS 512
#define _MAX_SS 512
/* These options configure the sector size to be supported. (512, 1024, 2048 or 4096)
/ Always set both 512 for most systems, all memory card and hard disk. But a larger
/ value may be required for on-board flash memory and some type of optical media.
/ When _MIN_SS != _MAX_SS, FatFs is configured to multiple sector size and
/ GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
@ -159,20 +165,22 @@
/ should be added to the disk_ioctl() function. */
#define _FS_NOFSINFO 0 /* 0 or 1 */
/* If you need to know the correct free space on the FAT32 volume, set this
/ option to 1 and f_getfree() function at first time after volume mount will
/ force a full FAT scan.
#define _FS_NOFSINFO 0 /* 0 to 3 */
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
/ option and f_getfree() function at first time after volume mount will force
/ a full FAT scan. Bit 1 controls the last allocated cluster number as bit 0.
/
/ 0: Load all informations in the FSINFO if available.
/ 1: Do not trust free cluster count in the FSINFO.
/ bit0=0: Use free cluster count in the FSINFO if available.
/ bit0=1: Do not trust free cluster count in the FSINFO.
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
*/
/*---------------------------------------------------------------------------/
/ System Configurations
/----------------------------------------------------------------------------*/
/---------------------------------------------------------------------------*/
#define _WORD_ACCESS 0 /* 0 or 1 */
/* The _WORD_ACCESS option is an only platform dependent option. It defines
@ -181,32 +189,34 @@
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ * Address misaligned memory access is always allowed for all instructions.
/ * Byte order on the memory is little-endian.
/ * Address miss-aligned word access is always allowed for all instructions.
/
/ If it is the case, _WORD_ACCESS can also be set to 1 to improve performance
/ and reduce code size.
*/
/* A header file that defines sync object types on the O/S, such as
/ windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */
#define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
/* To enable file lock control feature, set _FS_LOCK to 1 or greater.
/ The value defines how many files/sub-directories can be opened simultaneously.
/ This feature consumes _FS_LOCK * 12 bytes of bss area. */
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
#define _SYNC_t HANDLE /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID and etc.. */
/*#include <windows.h>*/
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
/* A header file that defines sync object types on the O/S, such as windows.h,
/ ucos_ii.h and semphr.h, should be included here when enable this option.
/ The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
/
/ 0: Disable re-entrancy. _SYNC_t and _FS_TIMEOUT have no effect.
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function must be added to the project. */
#define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
/* To enable file lock control feature, set _FS_LOCK to 1 or greater.
The value defines how many files can be opened simultaneously. */
/ function must be added to the project.
*/
#endif /* _FFCONFIG */

View File

@ -13,33 +13,30 @@
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new
/ synchronization object, such as semaphore and mutex. When a FALSE is
/ returned, the f_mount function fails with FR_INT_ERR.
/* This function is called by f_mount() function to create a new
/ synchronization object, such as semaphore and mutex. When a 0 is
/ returned, the f_mount() function fails with FR_INT_ERR.
*/
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */
BYTE vol, /* Corresponding logical drive being processed */
_SYNC_t *sobj /* Pointer to return the created sync object */
_SYNC_t* sobj /* Pointer to return the created sync object */
)
{
int ret;
// static _SYNC_t sem[_VOLUMES]; /* FreeRTOS */
*sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
ret = (*sobj != INVALID_HANDLE_VALUE);
ret = (int)(*sobj != INVALID_HANDLE_VALUE);
// *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */
// ret = 1; /* The initial value of the semaphore must be 1. */
// *sobj = SyncObjects[vol]; /* uITRON (give a static created semaphore) */
// ret = 1;
// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// ret = (int)(err == OS_NO_ERR);
// if (!sem[vol]) /* FreeRTOS */
// sem[vol] = xSemaphoreCreateMutex();
// *sobj = sem[vol];
// ret = (*sobj != NULL);
// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
// ret = (int)(*sobj != NULL);
return ret;
}
@ -49,9 +46,9 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any erro
/*------------------------------------------------------------------------*/
/* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a synchronization
/ object that created with ff_cre_syncobj function. When a FALSE is
/ returned, the f_mount function fails with FR_INT_ERR.
/* This function is called in f_mount() function to delete a synchronization
/ object that created with ff_cre_syncobj() function. When a 0 is
/ returned, the f_mount() function fails with FR_INT_ERR.
*/
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
@ -66,9 +63,10 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any erro
// ret = 1; /* uITRON (nothing to do) */
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// ret = (int)(err == OS_NO_ERR);
// ret = 1; /* FreeRTOS (nothing to do) */
// xSemaphoreDelete(sobj); /* FreeRTOS */
// ret = 1;
return ret;
}
@ -88,14 +86,14 @@ int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get
{
int ret;
ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
// ret = (wai_sem(sobj) == E_OK); /* uITRON */
// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// ret = (int)(err == OS_NO_ERR);
// ret = (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
// ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
return ret;
}