fatfs v0.10 Oct 02,2013:

- Added selection of character encoding on the file. (_STRF_ENCODE)
- Added f_closedir().
- Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
- Added forced mount feature with changes of f_mount().
- Improved behavior of volume auto detection.
- Improved write throughput of f_puts() and f_printf().
- 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.
This commit is contained in:
savelij13 2025-09-11 09:58:52 +03:00
parent 750225eb33
commit f9a05f6eda
83 changed files with 1636 additions and 1121 deletions

View File

@ -42,36 +42,37 @@
<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 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>
<li><a href="en/write.html">f_write</a> - Write file</li>
<li><a href="en/lseek.html">f_lseek</a> - Move read/write pointer, Expand file size</li>
<li><a href="en/truncate.html">f_truncate</a> - Truncate file size</li>
<li><a href="en/sync.html">f_sync</a> - Flush cached data</li>
<li><a href="en/forward.html">f_forward</a> - Forward file data to the stream</li>
<li><a href="en/stat.html">f_stat</a> - Check existance of a file or sub-directory</li>
<li><a href="en/opendir.html">f_opendir</a> - Open a directory</li>
<li><a href="en/closedir.html">f_closedir</a> - Close an open directory</li>
<li><a href="en/readdir.html">f_readdir</a> - Read a directory item</li>
<li><a href="en/getfree.html">f_getfree</a> - Get free clusters</li>
<li><a href="en/stat.html">f_stat</a> - Get file status</li>
<li><a href="en/mkdir.html">f_mkdir</a> - Create a directory</li>
<li><a href="en/unlink.html">f_unlink</a> - Remove a file or directory</li>
<li><a href="en/mkdir.html">f_mkdir</a> - Create a sub-directory</li>
<li><a href="en/unlink.html">f_unlink</a> - Remove a file or sub-directory</li>
<li><a href="en/chmod.html">f_chmod</a> - Change attribute</li>
<li><a href="en/utime.html">f_utime</a> - Change timestamp</li>
<li><a href="en/rename.html">f_rename</a> - Rename/Move a file or directory</li>
<li><a href="en/rename.html">f_rename</a> - Rename/Move a file or sub-directory</li>
<li><a href="en/chdir.html">f_chdir</a> - Change current directory</li>
<li><a href="en/chdrive.html">f_chdrive</a> - Change current drive</li>
<li><a href="en/getcwd.html">f_getcwd</a> - Retrieve the current directory</li>
<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/forward.html">f_forward</a> - Forward file data to the stream directly</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>
<li><a href="en/putc.html">f_putc</a> - Write a character</li>
<li><a href="en/puts.html">f_puts</a> - Write a string</li>
<li><a href="en/printf.html">f_printf</a> - Write a formatted string</li>
<li><a href="en/tell.html">f_tell</a> - Get the current read/write pointer</li>
<li><a href="en/tell.html">f_tell</a> - Get current read/write pointer</li>
<li><a href="en/eof.html">f_eof</a> - Test for end-of-file on a file</li>
<li><a href="en/size.html">f_size</a> - Get size of a file</li>
<li><a href="en/error.html">f_error</a> - Test for an error on a file</li>
@ -81,7 +82,7 @@
<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 at least 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 drivers are also available in the resources.</p>
<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>
<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>
@ -98,10 +99,20 @@
<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">April 20, 2013</span></li>
<li>Read first: <a href="en/appnote.html">FatFs module application note</a> <span class="mfd">October 2, 2013</span></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>
<li><a href="http://elm-chan.org/docs/fat.html">The basics of FAT file system [ja]</a></li>
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to Use MMC/SDC</a></li>
<li><a href="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>
</body>
</html>

View File

@ -8,7 +8,7 @@
<link rel="up" title="Freewares" href="../../fsw.html">
<link rel="alternate" hreflang="en" title="英文" href="00index_e.html">
<link rel="stylesheet" href="css_j.css" type="text/css" media="screen" title="ELM Default">
<title>ELM - FatFs 汎用FATファイルシステム・モジュール</title>
<title>FatFs 汎用FATファイルシステム・モジュール</title>
</head>
<body>
@ -41,7 +41,6 @@
<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,21 +48,23 @@
<li><a href="ja/lseek.html">f_lseek</a> - リード/ライト・ポインタの移動, ファイルの拡張</li>
<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/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/getfree.html">f_getfree</a> - ボリューム空き領域の取得</li>
<li><a href="ja/stat.html">f_stat</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/forward.html">f_forward</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>
@ -97,10 +98,19 @@
<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. 4. 20</span></li>
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール・アプリケーション・ート</a> <span class="mfd">2013. 10. 2</span></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>
<li><a href="http://elm-chan.org/docs/fat.html">FATファイル・システム概要</a> (↑を読むためのガイド)</li>
<li><a href="http://elm-chan.org/docs/mmc/mmc.html">MMCの使いかた</a></li>
<li><a href="img/rwtest.png">パフォーマンス・テスト1</a> (ATmega64/9.2MHz with MMC via SPI, HDD/CFC via GPIO)</li>
<li><a href="img/rwtest2.png">パフォーマンス・テスト2</a> (LPC2368/72MHz with MMC via MCI)</li>
</ul>
</div>
<hr>
<p class="foot"><a href="../../fsw.html">戻る</a></p>
</body>
</html>

View File

@ -42,7 +42,7 @@ 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="507" height="224" alt="dependency diagram"></p>
<p><img src="../img/modules.png" width="580" height="280" alt="dependency 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>
@ -66,8 +66,8 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<li>Number of open files: Unlimited, depends on available memory.</li>
<li>Number of volumes: Upto 10.</li>
<li>File size: Depends on FAT specs. (upto 4G-1 bytes)</li>
<li>Volume size: Depends on FAT specs. (upto 2T bytes on 512 bytes/sector)</li>
<li>Cluster size: Depends on FAT specs. (upto 64K bytes on 512 bytes/sector)</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>
</ul>
</div>
@ -78,18 +78,18 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<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>10395</td><td>7037</td><td>6555</td><td>13362</td><td>10609</td><td>11364</td><td>12884</td><td>7814</td><td>8783</td><td>5826</td><td>7659</td></tr>
<tr> <td>text (Min, R/W)</td> <td>6519</td><td>4747</td><td>4315</td> <td>8608</td> <td>7043</td> <td>7539</td> <td>8860</td><td>5070</td><td>5723</td><td>3821</td><td>5038</td></tr>
<tr> <td>text (Full, R/O)</td> <td>4563</td><td>3147</td><td>2911</td> <td>6174</td> <td>4925</td> <td>5340</td> <td>6136</td><td>3628</td><td>3863</td><td>2721</td><td>3534</td></tr>
<tr> <td>text (Min, R/O)</td> <td>3311</td><td>2463</td><td>2209</td> <td>4610</td> <td>3817</td> <td>4029</td> <td>4641</td><td>2762</td><td>3003</td><td>2068</td><td>2722</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*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</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>
</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.09b options:
FatFs R0.10 options:
_FS_READONLY 0 (R/W), 1 (R/O)
_FS_MINIMIZE 0 (Full function), 3 (Minimized function)
_USE_STRFUNC 0 (Disable string functions)
@ -104,7 +104,7 @@ _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_LOCK 0 (Disable shareing control)
_FS_LOCK 0 (Disable file lock control)
</pre>
</div>
@ -122,6 +122,7 @@ _FS_LOCK 0 (Disable shareing control)
<tr><td>f_sync</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_lseek</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_opendir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_closedir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_readdir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_stat</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_getfree</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
@ -150,7 +151,7 @@ _FS_LOCK 0 (Disable shareing control)
<h3>Long File Name</h3>
<p>The FatFs module has started to support long file name (LFN) at revision 0.07. The two different file names, SFN and LFN, of a file is transparent in the file functions except for f_readdir function. To enable LFN feature, set <tt>_USE_LFN</tt> to 1, 2 or 3, and add a Unicode code conversion function <tt>ff_convert()</tt> and <tt>ff_wtoupper()</tt> to the project. The LFN feature requiers a certain working buffer in addition. The buffer size can be configured by <tt>_MAX_LFN</tt> corresponding to the available memory size. The size of long file name will reach up to 255 characters, so that the <tt>_MAX_LFN</tt> should be set to 255 for full featured LFN operation. If the size of working buffer is insufficient for the given file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When enable the LFN feature with re-entrant feature, <tt>_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The working buffer occupies <tt>(_MAX_LFN + 1) * 2</tt> bytes.</p>
<table class="lst2 rset">
<caption>LFN cfg on ARM7</caption>
<caption>LFN cfg on ARM7TDMI</caption>
<tr><th>Code page</th><th>Program size</th></tr>
<tr><td>SBCS</td><td>+3.7K</td></tr>
<tr><td>932(Shift-JIS)</td><td>+62K</td></tr>
@ -164,26 +165,26 @@ _FS_LOCK 0 (Disable shareing control)
<div class="para" id="unicode">
<h3>Unicode API</h3>
<p>In default, FatFs supports ANSI/OEM code set on the API but FatFs can also switch the code set to Unicode. This means the FatFs supports the True LFN feature. For more information, refer to the description in the <a href="filename.html">file name</a>.</p>
<p>By default, FatFs uses ANSI/OEM code set on the API under LFN configuration. FatFs can also switch the character encoding to Unicode on the API (<tt>_LFN_UNICODE</tt>). This means the FatFs supports the True-LFN feature. For more information, refer to the description in the <a href="filename.html">file name</a>.</p>
</div>
<div class="para" id="reentrant">
<h3>Re-entrancy</h3>
<p>The file operations to the different volume is always re-entrant and can work simultaneously. The file operations to the same volume is not re-entrant but it can also be configured to thread-safe with <tt>_FS_REENTRANT</tt> option. In this case, also the OS dependent synchronization object control functions, <tt>ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant()</tt> must be added to the project.</p>
<p>When a file function is called while the volume is in use by any other task, the file function is suspended until that task leaves file function. If wait time exceeded a period defined by <tt>_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout feature might not be supported on some RTOS.</p>
<p>There is an exception on <tt>f_mount()</tt> and <tt>f_mkfs()</tt> function. These functions are not re-entrant to the same volume. When use these functions, all other task must close the corresponding file on the volume and avoid to access the volume.</p>
<p>Note that this section describes on the re-entrancy of the FatFs module itself but also the low level disk I/O layer must be re-entrant.</p>
<p>When a file function is called while the volume is in use by any other task, the file function is suspended until that task leaves file function. If wait time exceeded a period defined by <tt>_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout feature might not be supported by some RTOS.</p>
<p>There is an exception for <tt>f_mount(), f_mkfs(), f_fdisk()</tt> function. These functions are not re-entrant to the same volume or corresponding physical drive. When use these functions, all other tasks must unmount the volume and avoid to access the volume.</p>
<p>Note that this section describes on the re-entrancy of the FatFs module itself but also the low level disk I/O layer will need to be re-entrant.</p>
</div>
<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 files gets larger than <tt>_FS_LOCK</tt>, the <tt>f_open()</tt> function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</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>
</div>
<div class="para" id="fs1">
<h3>Performance Effective File Access</h3>
<p>For good performance on reading/writing files on the small embedded system, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by <tt>f_read()</tt> function.</p>
<p>For good performance to read/write files on the small embedded system, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by <tt>f_read()</tt> function.</p>
<p>Figure 1. Sector miss-aligned read (short)<br>
<img src="../img/f1.png" width="490" height="110" alt="">
</p>
@ -193,9 +194,9 @@ _FS_LOCK 0 (Disable shareing control)
<p>Figure 3. Sector aligned read<br>
<img src="../img/f3.png" width="490" height="119" alt="">
</p>
<p>The file I/O buffer is a sector buffer to read/write a partial data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer on the file system object. The buffer configuration option <tt>_FS_TINY</tt> determins which sector buffer is used for the file data transfer. When tiny buffer (1) is selected, data memory consumption is reduced 512 bytes each file object. In this case, FatFs module uses only a sector buffer on the file system object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.</p>
<p>Figure 1 shows that a partial sector is transferred via the file I/O buffer. On long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with <tt>disk_read()</tt> function at a time but the multiple sector transfer never across the cluster boundary even if it is contiguous.</p>
<p>Therefore taking effort to sector aligned read/write accesss avoids buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer on the tiny configuration so that it can achieve same performance as non-tiny configuration with small memory footprint.</p>
<p>The file I/O buffer is a sector buffer to read/write a partial data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the file system object. The buffer configuration option <tt>_FS_TINY</tt> determins which sector buffer is used for the file data transfer. When tiny buffer (1) is selected, data memory consumption is reduced 512 bytes each file object. In this case, FatFs module uses only a sector buffer in the file system object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.</p>
<p>Figure 1 shows that a partial sector, sector mis-aligned part of the file, is transferred via the file I/O buffer. On long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with <tt>disk_read()</tt> function at a time but the multiple sector transfer never across the cluster boundary even if it is contiguous.</p>
<p>Therefore taking effort to sector aligned read/write accesss avoids buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.</p>
</div>
<div class="para" id="fs2">
@ -231,7 +232,7 @@ Figure 5. Minimized critical section<br>
<li>The file created as new or overwritten remains but no content.</li>
<li>Efficiency of disk use gets worse due to lost clusters.</li>
</ul>
<p>Each case does not affect the files that not opened in write mode. To minimize risk of data loss, the critical section can be minimized like shown in Figure 5 by minimizing the time that file is opened in write mode or using <tt>f_sync()</tt> function properly.</p>
<p>Each case does not affect the files that not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using <tt>f_sync()</tt> function as shown in Figure 5.</p>
</div>
<div class="para" id="fs3">
@ -248,7 +249,7 @@ Figure 5. Minimized critical section<br>
<h3>About FatFs License</h3>
<p>This is a copy of the FatFs license document that included in the source codes.</p>
<pre>/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.09b (C)ChaN, 2013
/ FatFs - FAT file system module R0.10 (C)ChaN, 2013
/-----------------------------------------------------------------------------/
/ 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
@ -262,7 +263,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 big difference. Because FatFs is for embedded projects, the conditions for redistributions in binary form, such as embedded code, hex file and binary library, is not specified to increase its usability. The documentation of the distributions need not include about FatFs and its license document, and it may also. Of course FatFs is compatible with the projects under GNU GPL. When redistribute it 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 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>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -16,7 +16,7 @@
<p>The f_chdrive function changes the current drive.</p>
<pre>
FRESULT f_chdrive (
BYTE <span class="arg">vol</span> <span class="c">/* [IN] Logical drive number */</span>
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Logical drive number */</span>
);
</pre>
</div>
@ -24,7 +24,7 @@ FRESULT f_chdrive (
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>vol</dt>
<dt>path</dt>
<dd>Specifies the <a href="filename.html">logical drive number</a> to be set as the current drive.</dd>
</dl>
</div>
@ -46,7 +46,7 @@ FRESULT f_chdrive (
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt>_FS_RPATH >= 1</tt>.</p>
<p>Available when <tt>_FS_RPATH >= 1</tt> and <tt>_VOLUMES >= 2</tt>.</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_chmod</h2>
<p>The f_chmod function changes the attribute of a file or directory.</p>
<p>The f_chmod function changes the attribute of a file or sub-directory.</p>
<pre>
FRESULT f_chmod (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
@ -27,7 +27,7 @@ FRESULT f_chmod (
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be changed</dd>
<dd>Pointer to the null-terminated string that specifies an <a href="filename.html">object</a> to be changed</dd>
<dt>attr</dt>
<dd>Attribute flags to be set in one or more combination of the following flags. The specified flags are set and others are cleard.<br>
<table class="lst">
@ -66,7 +66,7 @@ FRESULT f_chmod (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_chmod()</tt> function changes the attribute of a file or directory.</p>
<p>The <tt>f_chmod()</tt> function changes the attribute of a file or sub-directory.</p>
</div>

View File

@ -45,7 +45,8 @@ FRESULT f_close (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_close()</tt> function closes an open file object. If any data has been written to the file, the cached information of the file is written back to the disk. After the function succeeded, the file object is no longer valid and it can be discarded.</p>
<p>The <tt>f_close()</tt> function closes an open file object. If any data has been written to the file, the cached information of the file is written back to the volume. After the function succeeded, the file object is no longer valid and it can be discarded.</p>
<p>Note that if the file object is in read-only mode and <tt>_FS_LOCK</tt> option is not enabled, the file object can also be discarded without this process. However it is not recommended for future compatibility.</p>
</div>

64
doc/en/closedir.html Normal file
View File

@ -0,0 +1,64 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/close.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_closedir</title>
</head>
<body>
<div class="para func">
<h2>f_closedir</h2>
<p>The f_closedir function closes an open directory.</p>
<pre>
FRESULT f_closedir (
DIR* <span class="arg">dp</span> <span class="c">/* [IN] Pointer to the directory object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the open directory object structure to be closed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<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>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt>_FS_MINIMIZE &lt;= 1</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -32,7 +32,7 @@ DSTATUS disk_initialize (
<div class="para ret">
<h4>Return Values</h4>
<p>This function returns a disk status as the result. For details of the disk status, refer to the <a href="dstat.html">disk_status</a> function.</p>
<p>This function returns a disk status as the result. For details of the disk status, refer to the <a href="dstat.html">disk_status()</a> function.</p>
</div>
<div class="para desc">

View File

@ -19,7 +19,7 @@ DRESULT disk_read (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read data buffer */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Start sector number */</span>
BYTE <span class="arg">count</span> <span class="c">/* [IN] Number of sectros to read */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectros to read */</span>
);
</pre>
</div>
@ -34,7 +34,7 @@ DRESULT disk_read (
<dt>sector</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dt>count</dt>
<dd>Specifies number of sectors to read. The value can be 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>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>
</dl>
</div>

View File

@ -19,7 +19,7 @@ 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>
BYTE <span class="arg">count</span> <span class="c">/* [IN] Number of sectors to write */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectors to write */</span>
);
</pre>
</div>
@ -34,7 +34,7 @@ DRESULT disk_write (
<dt>sector</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dt>count</dt>
<dd>Specifies the number of sectors to write. The value can be 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>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>
</dl>
</div>

View File

@ -33,7 +33,7 @@ int f_error (
<div class="para ret">
<h4>Return Values</h4>
<p>Returns a non-zero value if an error has occured; otherwise it returns a zero.</p>
<p>Returns a non-zero value if a hard error has occured; otherwise it returns a zero.</p>
</div>

View File

@ -17,7 +17,7 @@
<pre>
FRESULT f_fdisk (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
const DWORD <em>part[]</em>, <span class="c">/* [IN] Partition size */</span>
const DWORD <span class="arg">part[]</span>, <span class="c">/* [IN] Partition size */</span>
void* <span class="arg">work</span> <span class="c">/* [IN] Work area */</span>
);
</pre>
@ -48,7 +48,7 @@ FRESULT f_fdisk (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_fdisk()</tt> function creates a partition table into the MBR of the physical drive. The partitioning rule is in generic FDISK format so that it can create upto four primary partitions. Extended partition is not supported. The <tt class="arg">part[]</tt> array with four items specifies how to divide the physical drive. The first item specifies the size of first primary partition and fourth item specifies the fourth primary partition. If the value is less than or equal to 100, it means percentage of the partition in the entire disk space. If it is larger than 100, it means partition size in unit of sector.</p>
<p>The <tt>f_fdisk()</tt> function creates a partition table into the MBR of the physical drive. The partitioning rule is in generic FDISK format, so that it can create upto four primary partitions. Extended partition is not supported. The <tt class="arg">part[]</tt> array with four items specifies how to divide the physical drive. The first item specifies the size of first primary partition and fourth item specifies the fourth primary partition. If the value is less than or equal to 100, it means percentage of the partition in the entire disk space. If it is larger than 100, it means partition size in unit of sector.</p>
</div>
<div class="para comp">
@ -70,19 +70,19 @@ FRESULT f_fdisk (
<pre>
<span class="c">/* Initialize a brand-new disk drive mapped to physical drive 0 */</span>
FATFS Fatfs;
FATFS fs;
DWORD plist[] = {50, 50, 0, 0}; <span class="c">/* Divide drive into two partitions */</span>
BYTE work[_MAX_SS];
f_fdisk(0, plist, work); <span class="c">/* Divide physical drive 0 */</span>
f_mount(0, &amp;Fatfs);
f_mkfs(0, 0, 0); <span class="c">/* Create an FAT volume on the logical drive 0. 2nd argument is ignored. */</span>
f_mount(0, 0);
f_mount(&amp;fs, "0:", 0); <span class="c">/* Register work area to the logical drive 0 */</span>
f_mkfs("0:", 0, 0); <span class="c">/* Create FAT volume on the logical drive 0. 2nd argument is ignored. */</span>
f_mount(0, "0:", 0); <span class="c">/* Unregister work area from the logical drive 0 */</span>
f_mount(1, &amp;Fatfs);
f_mkfs(1, 0, 0);
f_mount(1, 0);
f_mount(&amp;fs, "1:", 0); <span class="c">/* Give a work area to the logical drive 1 */</span>
f_mkfs("1:", 0, 0); <span class="c">/* Create FAT volume on the logical drive 1. 2nd argument is ignored. */</span>
f_mount(0, "1:", 0); <span class="c">/* Unregister work area from the logical drive 1 */</span>
</pre>
</div>

View File

@ -17,7 +17,7 @@
<p>The format of path name on the FatFs module is similer to the filename specs of DOS/Windos as follows:</p>
<pre>"[drive#:][/]directory/file"</pre>
<p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when LFN feature is enabled (<tt>_USE_LFN &gt; 0</tt>). The sub directories are separated with a \ or / in the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the logical drive is specified in a numeral with a colon. When the drive number is omitted, it is assumed as <em>default drive</em> (drive 0 or current drive).</p>
<p>Control characters (<tt>'\0'</tt> to <tt>'\x1F'</tt>) are recognized as end of the path name. Leading/embedded spaces in the path name are valid as a part of the name on LFN configuration but they are recognized as end of the path name on non-LFN configuration. Trailing spaces and dots are ignored.</p>
<p>Control characters (<tt>'\0'</tt> to <tt>'\x1F'</tt>) are recognized as end of the path name. Leading/embedded spaces in the path name are valid as a part of the name at LFN configuration but they are recognized as end of the path name at non-LFN configuration. Trailing spaces and dots are ignored.</p>
<p>In default configuration (<tt>_FS_RPATH == 0</tt>), it does not have a concept of current directory like OS oriented file system. All objects on the volume are always specified in full path name that follows from the root directory. Dot directory names are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive number is fixed to 0.</p>
<p>When relative path feature is enabled (<tt>_FS_RPATH == 1</tt>), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory set with <a href="chdir.html">f_chdir</a> function. Dot names are also allowed for the path name. The default drive is the current drive set with <a href="chdrive.html">f_chdrive</a> function.</p>
<table class="lst2">
@ -40,21 +40,22 @@
<p><br></p>
<div class="para" id="uni">
<h3>Unicode API</h3>
<p>The path names are input/output in either ANSI/OEM code (SBCS/DBCS) or Unicode depends on the configuration options. The type of arguments that specifies the file names are defined as <tt>TCHAR</tt> which is an alias of <tt>char</tt> in default. The code set of the file name string is the ANSI/OEM code set specifid by <tt>_CODE_PAGE</tt>. When <tt>_LFN_UNICODE</tt> is set to 1, the type of the <tt>TCHAR</tt> is switched to <tt>WCHAR, unsigned short</tt> (UCS-2 character) to support Unicode. In this case, the LFN feature is fully supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.</p>
<p>The path names are input/output in either ANSI/OEM code (SBCS/DBCS) or Unicode depends on the configuration options. The type of arguments which specify the file names are defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> in default. The code set used to the file name string is ANSI/OEM specifid by <tt>_CODE_PAGE</tt>. When <tt>_LFN_UNICODE</tt> is set to 1, the type of the <tt>TCHAR</tt> is switched to <tt>WCHAR</tt> to support Unicode (UTF-16 encoding). In this case, the LFN feature is fully supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.</p>
<pre>
f_open(fp, "filename.txt", FA_READ); <span class="c">/* ANSI/OEM only */</span>
f_open(fp, L"filename.txt", FA_READ); <span class="c">/* Unicode only */</span>
f_open(fp, "filename.txt", FA_READ); <span class="c">/* ANSI/OEM string */</span>
f_open(fp, L"filename.txt", FA_READ); <span class="c">/* Unicode string */</span>
f_open(fp, _T("filename.txt"), FA_READ); <span class="c">/* Changed by configuration */</span>
</pre>
</div>
<p><br></p>
<div class="para" id="vol">
<h3>Correspondence between logical and physical drives</h3>
<p>The FatFs module has work areas that called <em>file system object</em> for each volume (logical drive). In default, each logical drive is bound to the physical drive that has same drive number. It attempts to mount a volume as SFD format and first FDISK partition. When <tt>_MULTI_PARTITION &gt;= 1</tt> is specified in configuration option, each individual logical drive is bound to any physical drive/partition. In this case, a volume management table must be defined by user. It is used to resolve relationship between logical drives and partitions as follows:</p>
<h3>Volume Management</h3>
<p>The FatFs module needs dynamic work area called <em>file system object</em> for each volume (logical drive). It is registered to the FatFs module by <tt>f_mount()</tt> function. By default, each logical drive is bound to the physical drive with the same drive number and an FAT volume on the drive is serched by auto detect feature. It loads boot sectors and checks it if it is an FAT boot sector in order of sector 0 as SFD format, 1st partition, 2nd partition, 3rd partition and 4th partition as FDISK format.</p>
<p>When <tt>_MULTI_PARTITION == 1</tt> is specified by configuration option, each individual logical drive is bound to the partition on the physical drive specified by volume management table. The volume management table must be defined by user to resolve relationship between logical drives and partitions. Following code is an example of a volume management table.</p>
<pre>
Example: Logical drive 0-2 are assigned to three pri-partitions on the physical drive 0 (fixed disk)
Logical drive 3 is assigned to physical drive 1 (removable disk)
Example: Logical drive 0-2 are tied to three pri-partitions on the physical drive 0 (fixed disk)
Logical drive 3 is tied to an FAT volume on the physical drive 1 (removable disk)
PARTITION VolToPart[] = {
{0, 1}, <span class="c">/* Logical drive 0 ==> Physical drive 0, 1st partition */</span>
@ -64,9 +65,9 @@ PARTITION VolToPart[] = {
};
</pre>
<img src="../img/f7.png" width="828" height="288" alt="relationship between logical drive and physical drive">
<p>There are some considerations when use <tt>_MULTI_PARTITION</tt> configuration.</p>
<p>There are some considerations on using <tt>_MULTI_PARTITION</tt> configuration.</p>
<ul>
<li>Only four pri-partitions can be mounted. Extended partition is not supported.</li>
<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>
</ul>
</div>

View File

@ -50,7 +50,7 @@ FRESULT f_getcwd (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_getcwd()</tt> function retrieves the current directory of the current drive in full path string including drive number.</p>
<p>The <tt>f_getcwd()</tt> function retrieves full path name of the current directory of the current drive. When <tt>_VOLUMES</tt> is larger than 1, a logical drive number is added to top of the path name.</p>
</div>

View File

@ -27,7 +27,7 @@ FRESULT f_getfree (
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. A null-string means the current drive.</dd>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. A null-string means the default drive.</dd>
<dt>nclst</dt>
<dd>Pointer to the <tt>DWORD</tt> variable to store number of free clusters.</dd>
<dt>fatfs</dt>
@ -53,7 +53,7 @@ FRESULT f_getfree (
<div class="para desc">
<h4>Descriptions</h4>
<p>The <tt>f_getfree()</tt> function gets number of free clusters on the drive. The member <tt>csize</tt> in the file system object is refrecting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. When FSInfo structure on FAT32 volume is not in sync, this function can return an incorrect free cluster count.</p>
<p>The <tt>f_getfree()</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the file system object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. When FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt>_FS_NOFSINFO</tt> option.</p>
</div>
@ -78,8 +78,8 @@ FRESULT f_getfree (
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
<span class="c">/* Print free space in unit of KiB (assuming 512 bytes/sector) */</span>
printf("%lu KB total drive space.\n%lu KB available.\n",
<span class="c">/* Print the free space (assuming 512 bytes/sector) */</span>
printf("%10lu KiB total drive space.\n%10lu KiB available.\n",
tot_sect / 2, fre_sect / 2);
</pre>
</div>

View File

@ -16,7 +16,7 @@
<p>The f_getlabel function returns volume label and volume serial number of a drive.</p>
<pre>
FRESULT f_getlabel (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Path name */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Drive number */</span>
TCHAR* <span class="arg">buff</span>, <span class="c">/* [OUT] Volume label */</span>
DWORD* <span class="arg">sn</span> <span class="c">/* [OUT] Volume serial number */</span>
);
@ -27,9 +27,9 @@ FRESULT f_getlabel (
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the nul-terminated string specifying the logical drive. Null-string specifies the default drive.</dd>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. Null-string specifies the default drive.</dd>
<dt>buff</dt>
<dd>Pointer to the buffer to store the volume label. The buffer size must be at least 12 items. If no volume label, a nul-string will be returned. Set null pointer if this information is not needed.</dd>
<dd>Pointer to the buffer to store the volume label. The buffer size must be at least 12 items. If the volume has no label, a null-string will be returned. Set null pointer if this information is not needed.</dd>
<dt>sn</dt>
<dd>Pointer to the <tt>DWORD</tt> variable to store the volume serial number. Set null pointer if this information is not needed.</dd>
</dl>

View File

@ -44,8 +44,8 @@ TCHAR* f_gets (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_gets()</tt> function is a wrapper function of <a href="read.html">f_read()</a> function. The read operation continues until a <tt>'\n'</tt> is stored, reached end of the file or the buffer is filled with <tt>len - 1</tt> characters. The read string is terminated with a <tt>'\0'</tt>. When no character to read or any error occured during read operation, it returns a null pointer. The status of eof and error can be examined with <tt>f_eof()</tt> and <tt>f_error()</tt> macros.</p>
<p>When the FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), the file is read in assumption of UTF-8 encoding and stored it to the buffer in UCS-2. If not the case, the file will be read in one byte per character without any code conversion.</p>
<p>The <tt>f_gets()</tt> function is a wrapper function of <a href="read.html"><tt>f_read()</tt></a> function. The read operation continues until a <tt>'\n'</tt> is stored, reached end of the file or the buffer is filled with <tt>len - 1</tt> characters. The read string is terminated with a <tt>'\0'</tt>. When no character to read or any error occured during read operation, it returns a null pointer. The status of EOF and error can be examined with <tt>f_eof()</tt> and <tt>f_error()</tt> macros.</p>
<p>When FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), data types on the srting fuctions, <tt>f_putc()</tt>, <tt>f_puts()</tt>, <tt>f_printf()</tt> and <tt>f_gets()</tt>, is also switched to Unicode. The character encoding on the file to be read/written via those functions is selected by <tt>_STRF_ENCODE</tt> option.</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_lseek</h2>
<p>The f_lseek function moves the file read/write pointer of an open file object. It can also be used to increase the file size (cluster pre-allocation). </p>
<p>The f_lseek function moves the file read/write pointer of an open file object. It can also be used to expand the file size (cluster pre-allocation). </p>
<pre>
FRESULT f_lseek (
@ -49,13 +49,13 @@ FRESULT f_lseek (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_lseek()</tt> function moves the file read/write pointer of an open file. The offset can be specified in only origin from top of the file. When an offset above the file size is specified in write mode, the file size is increased to the offset and the data in the expanded area is undefined. This is suitable to create a large file quickly, for fast write operation. After the <tt>f_lseek()</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer was moved correctry. In case of the current read/write pointer is not the expected value, either of followings has been occured.</p>
<p>The <tt>f_lseek()</tt> function moves the file read/write pointer of an open file. The offset can be specified in only origin from top of the file. When an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset. The file data in the expanded area is undefined because no data is written to the file. This is suitable to pre-allocate a cluster chain quickly, for fast write operation. After the <tt>f_lseek()</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the current read/write pointer is not the expected value, either of followings has been occured.</p>
<ul>
<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file is in read-only mode.</li>
<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> functions. In this mode, the file cannot be expanded by <tt>f_write()/f_lseek()</tt> functions.</p>
<p>The CLMT must be created in the user defined <tt>DWORD</tt> array prior to use fast seek feature. To create the CLMT, set pointer to 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> functions 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>
<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>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>
@ -82,7 +82,7 @@ FRESULT f_lseek (
<span class="c">/* Forward 3000 bytes */</span>
res = f_lseek(fp, f_tell(fp) + 3000);
<span class="c">/* Rewind 2000 bytes (take care on overflow) */</span>
<span class="c">/* Rewind 2000 bytes (take care on wraparound) */</span>
res = f_lseek(fp, f_tell(fp) - 2000);
</pre>
<pre>
@ -105,12 +105,12 @@ FRESULT f_lseek (
<pre>
<span class="c">/* Using fast seek feature */</span>
DWORD lktbl[SZ_TBL]; <span class="c">/* Link map table buffer */</span>
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>
fp-&gt;cltbl = lktbl; <span class="c">/* Enable fast seek feature (cltbl != NULL) */</span>
lktbl[0] = SZ_TBL; <span class="c">/* Set table size */</span>
fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek feature */</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

@ -16,7 +16,7 @@
<p>The f_mkfs fucntion creates an FAT file system on the logical drive.</p>
<pre>
FRESULT f_mkfs (
BYTE <span class="arg">vol</span>, <span class="c">/* [IN] Logical drive number */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
BYTE <span class="arg">sfd</span>, <span class="c">/* [IN] Partitioning rule */</span>
UINT <span class="arg">au</span> <span class="c">/* [IN] Size of the allocation unit */</span>
);
@ -26,12 +26,12 @@ FRESULT f_mkfs (
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>vol</dt>
<dd>Logical drive number to be formatted. (0 to <tt>_VOLUMES - 1</tt>)</dd>
<dt>path</dt>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">logical drive</a> to be formatted. If there is no drive number, it means the default drive.</dd>
<dt>sfd</dt>
<dd>Specifies partitioning rule (FDISK(0) or SFD(1)). This argument is ignored on some case.</dd>
<dd>Specifies partitioning rule (FDISK(0) or SFD(1)). This argument will be ignored on some case.</dd>
<dt>au</dt>
<dd>Force the size of allocation unit (cluter) in unit of byte. The value must be sector size * n (n = 1 to 128 and power of 2). When a zero is given, the cluster size is determined depends on the volume size.</dd>
<dd>Specifies size of the allocation unit (cluter) in unit of byte. The value must be sector size * n (n is 1 to 128 and power of 2). When a zero is given, the cluster size is determined depends on the volume size.</dd>
</dl>
</div>
@ -52,8 +52,8 @@ FRESULT f_mkfs (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_mkfs()</tt> function creates an FAT volume on the logical drive. When FDISK format is specified, a primary partition occupies the entire disk space is created and then an FAT volume is created on the partition. When SFD format is specified, the FAT volume starts from the first sector of the physical drive.</p>
<p>If the logical drive is being bound to any partition (1-4) by multiple partition feature (<tt>_MULTI_PARTITION</tt>), the FAT volume is created into the specified partition. In this case, the second argument <tt class="arg">sfd</tt> is ignored. The physical drive must have been partitioned with f_fdisk function or any other partitioning tool prior to use this function.</p>
<p>Note that there are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC and CFC. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable media. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is used for floppy disk, Microdrive, optical disk and super-floppy media.</p>
<p>If the logical drive has been bound to any partition (1-4) by multiple partition feature (<tt>_MULTI_PARTITION</tt>), the FAT volume is created into the specified partition. In this case, the second argument <tt class="arg">sfd</tt> is ignored. The physical drive must have been partitioned with <tt>f_fdisk()</tt> function or any other partitioning tool prior to use this function.</p>
<p>Note that there are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable media. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is usually used for floppy disk, Microdrive, optical disk and super-floppy media.</p>
<p>The FAT sub-type, FAT12/FAT16/FAT32, is determined by number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the volume size and the specified cluster size. The cluster size affects performance of the file system and large cluster increases the performance.</p>
<p>When the number of clusters gets near the FAT sub-type boundaries, the function can fail with <tt>FR_MKFS_ABORTED</tt>.</p>
</div>

View File

@ -16,8 +16,9 @@
<p>The f_mount fucntion registers/unregisters file system object (work area) to the FatFs module.</p>
<pre>
FRESULT f_mount (
BYTE <span class="arg">vol</span>, <span class="c">/* [IN] Logical drive number */</span>
FATFS* <span class="arg">fatfs</span> <span class="c">/* [IN] File system object */</span>
FATFS* <span class="arg">fatfs</span>, <span class="c">/* [IN] File system object */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
BYTE <span class="arg">opt</span> <span class="c">/* [IN] Initialization option */</span>
);
</pre>
</div>
@ -25,10 +26,12 @@ FRESULT f_mount (
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>vol</dt>
<dd>Logical drive number to register/unregister file system object. (0 to <tt>_VOLUMES - 1</tt>)</dd>
<dt>fatfs</dt>
<dd>Pointer to the file system object to be registered. Null pointer unregisters the registered file system object.</dd>
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. If there is no drive number, it means the default drive.</dd>
<dt>opt</dt>
<dd>Initialization option. 0: Do not mount now (to be mounted later), 1: Force mounted the volume to check if the volume is available.</dd>
</dl>
</div>
@ -36,20 +39,31 @@ FRESULT f_mount (
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_mount()</tt> function registers/unregisters a file system object to the FatFs module. The file system object is the work area needed for each logical drive. It must be given to the logical drive with this function prior to use any other file functions. To unregister a work area, specify a NULL to the <tt class="arg">fatfs</tt>, and then the work area can be discarded.</p>
<p>This function always succeeds regardless of the physical drive status. No media access is occured in this function. It only de-initializes the given work area and registers its address to the internal table. It can also be used to force de-initialized the registered work area of a logical drive. The volume mount process, initialize the corresponding physical drive, find the FAT volume in it and initialize the work area, is performed when either or both of following condition is true:</p>
<p>The <tt>f_mount()</tt> function registers/unregisters a file system object used for the logical drive to the FatFs module as follows:</p>
<ol>
<li>Determines the logical drive which specified by <tt class="arg">path</tt>.</li>
<li>Clears and unregisters the regsitered work area of the drive.</li>
<li>Clears and registers the work area to the drive if <tt class="arg">fatfs</tt> is not NULL.</li>
<li>Performs volume mount process to the drive if forced mount is specified.</li>
</ol>
<p>The file system object is the work area needed for each logical drive. It must be given to the logical drive with this function prior to use any other file functions. To unregister a work area, specify a NULL to the <tt class="arg">fatfs</tt>, and then the work area can be discarded. </p>
<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. (by <tt>f_mount()</tt>)</li>
<li>Physical drive is not initialized. (by system reset or media removal)</li>
<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>
</ul>
<p>If the disk I/O layer does not detect media change, application program needs to perform <tt>f_mount()</tt> every media change.</p>
<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>
</div>
@ -61,7 +75,7 @@ FRESULT f_mount (
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
<p><tt><a href="open.html">f_open</a></tt>, <tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -16,7 +16,7 @@
<p>The f_open function creates a <em>file object</em> to be used to access the file.</p>
<pre>
FRESULT f_open (
FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] File object structure */</span>
FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] Pointer to the file object structure */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] File name */</span>
BYTE <span class="arg">mode</span> <span class="c">/* [IN] Mode flags */</span>
);
@ -27,7 +27,7 @@ FRESULT f_open (
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the file object structure to be created.</dd>
<dd>Pointer to the blank file object structure to be created.</dd>
<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>
@ -87,35 +87,66 @@ To append data to the file, use <a href="lseek.html"><tt>f_lseek()</tt></a> func
<div class="para use">
<h4>Example (File Copy)</h4>
<h4>Example</h4>
<pre>
void main (void)
<span class="c">/* Read a text file and display it */</span>
FATFS FatFs; <span class="c">/* Work area (file system object) for logical drive */</span>
int main (void)
{
FIL fil; <span class="c">/* File object */</span>
char line[82]; <span class="c">/* Line buffer */</span>
FRESULT fr; <span class="c">/* FatFs return code */</span>
<span class="c">/* Register work area to the default drive */</span>
f_mount(&amp;FatFs, "", 0);
<span class="c">/* Open a text file */</span>
fr = f_open(&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))
printf(line);
<span class="c">/* Close the file */</span>
f_close(&fil);
return 0;
}
</pre>
<pre>
<span class="c">/* Copy a file "file.bin" on the drive 1 to drive 0 */</span>
int main (void)
{
FATFS fs[2]; <span class="c">/* Work area (file system object) for logical drives */</span>
FIL fsrc, fdst; <span class="c">/* file objects */</span>
BYTE buffer[4096]; <span class="c">/* file copy buffer */</span>
FRESULT res; <span class="c">/* FatFs function common result code */</span>
FIL fsrc, fdst; <span class="c">/* File objects */</span>
BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>
FRESULT fr; <span class="c">/* FatFs function common result code */</span>
UINT br, bw; <span class="c">/* File read/write count */</span>
<span class="c">/* Register work area for each volume (Always succeeds regardless of disk status) */</span>
f_mount(0, &amp;fs[0]);
f_mount(1, &amp;fs[1]);
<span class="c">/* Register work area for each logical drive */</span>
f_mount(&amp;fs[0], "0:", 0);
f_mount(&amp;fs[1], "1:", 0);
<span class="c">/* Open source file on the drive 1 */</span>
res = f_open(&amp;fsrc, "1:srcfile.dat", FA_OPEN_EXISTING | FA_READ);
if (res) die(res);
fr = f_open(&amp;fsrc, "1:file.bin", FA_OPEN_EXISTING | FA_READ);
if (fr) return (int)fr;
<span class="c">/* Create destination file on the drive 0 */</span>
res = f_open(&amp;fdst, "0:dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (res) die(res);
fr = f_open(&amp;fdst, "0:file.bin", FA_CREATE_ALWAYS | FA_WRITE);
if (fr) return (int)fr;
<span class="c">/* Copy source to destination */</span>
for (;;) {
res = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of src file */</span>
if (res || br == 0) break; <span class="c">/* error or eof */</span>
res = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* Write it to the dst file */</span>
if (res || bw &lt; br) break; <span class="c">/* error or disk full */</span>
fr = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of source file */</span>
if (fr || br == 0) break; <span class="c">/* error or eof */</span>
fr = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* Write it to the destination file */</span>
if (fr || bw &lt; br) break; <span class="c">/* error or disk full */</span>
}
<span class="c">/* Close open files */</span>
@ -123,8 +154,10 @@ void main (void)
f_close(&amp;fdst);
<span class="c">/* Unregister work area prior to discard it */</span>
f_mount(0, NULL);
f_mount(1, NULL);
f_mount(NULL, "0:", 0);
f_mount(NULL, "1:", 0);
return (int)fr;
}
</pre>
</div>

View File

@ -16,7 +16,7 @@
<p>The f_opendir function opens a directory.</p>
<pre>
FRESULT f_opendir (
DIR* <span class="arg">dj</span>, <span class="c">/* [OUT] Blank directory object */</span>
DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] Pointer to the directory object structure */</span>
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Directory name */</span>
);
</pre>
@ -25,7 +25,7 @@ FRESULT f_opendir (
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dj</dt>
<dt>dp</dt>
<dd>Pointer to the blank directory object to be created.</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>
@ -42,6 +42,7 @@ FRESULT f_opendir (
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
@ -53,7 +54,7 @@ FRESULT f_opendir (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_opendir()</tt> function opens an exsisting directory and creates the directory object for subsequent calls. The directory object structure can be discarded at any time without any procedure.</p>
<p>The <tt>f_opendir()</tt> function opens an exsisting directory and creates the directory object for subsequent calls.</p>
</div>
@ -65,7 +66,7 @@ FRESULT f_opendir (
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt></p>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -39,13 +39,13 @@ int f_printf (
<div class="para ret">
<h4>Return Values</h4>
<p>When the function succeeded, number of characters written is returned. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
<p>When the function succeeded, it returns number of characters written. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_printf()</tt> is a wrapper function of <a href="putc.html"><tt>f_putc()</tt></a> and <a href="puts.html"><tt>f_puts()</tt></a>. The format control directive is a sub-set of standard library shown as follos:</p>
<p>The <tt>f_printf()</tt> is a wrapper function of <a href="write.html"><tt>f_write()</tt></a>. The format control directive is a sub-set of standard library shown as follos:</p>
<ul>
<li>Type: <tt>c C s S d D u U x X b B</tt></li>
<li>Size: <tt>l L</tt></li>
@ -57,7 +57,7 @@ int f_printf (
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt>_FS_READONLY == 0</tt> and <tt>_USE_STRFUNC</tt> is 1 or 2. When it is set to 2, <tt>'\n'</tt>s contained in the output are converted to <tt>"\r\n"</tt>.</p>
<p>When the FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), the generated UCS-2 string is written to the file in UTF-8 encoding. If not the case, the byte characters will be written directly.</p>
<p>When FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), data types on the srting fuctions, <tt>f_putc()</tt>, <tt>f_puts()</tt>, <tt>f_printf()</tt> and <tt>f_gets()</tt>, is also switched to Unicode. The character encoding on the file to be read/written via those functions is selected by <tt>_STRF_ENCODE</tt> option.</p>
</div>
@ -68,12 +68,12 @@ int f_printf (
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", 0xA3); <span class="c">/* "00a3" */</span>
f_printf(&amp;fil, "%08LX", 0x123ABC); <span class="c">/* "00123ABC" */</span>
f_printf(&amp;fil, "%04x", 0xAB); <span class="c">/* "00ab" */</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, "%-4s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%4s", "abc"); <span class="c">/* " abc" */</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, "%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

@ -35,8 +35,8 @@ int f_putc (
<div class="para ret">
<h4>Return Values</h4>
<p>When the character was written successfuly, the function returns 1. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
<p>When the FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), the UCS-2 character is written to the file in UTF-8 encoding. If not the case, the byte will be written directly.</p>
<p>When the character was written successfuly, it returns number of characters written. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
<p>When FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), character encoding on the string fuctions, <tt>f_putc()</tt>, <tt>f_puts()</tt>, <tt>f_printf()</tt> and <tt>f_gets()</tt>, is also switched to Unicode. The character encoding on the file to be read/written via those functions is selected by <tt>_STRF_ENCODE</tt> option.</p>
</div>

View File

@ -35,14 +35,14 @@ int f_puts (
<div class="para ret">
<h4>Return Value</h4>
<p>When the function succeeded, number of characters written that is not minus value is returned. When the write operation is aborted due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
<p>When the FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), the UCS-2 string is written to the file in UTF-8 encoding. If not the case, the byte stream will be written directly.</p>
<p>When the function succeeded, it returns number of characters written. When the write operation is aborted due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
<p>When FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), character encoding on the srting fuctions, <tt>f_putc()</tt>, <tt>f_puts()</tt>, <tt>f_printf()</tt> and <tt>f_gets()</tt>, is also switched to Unicode. The character encoding on the file to be read/written via those functions is selected by <tt>_STRF_ENCODE</tt> option.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_puts()</tt> function is a wrapper function of <a href="putc.html"><tt>f_putc()</tt></a> function.</p>
<p>The <tt>f_puts()</tt> function is a wrapper function of <a href="write.html"><tt>f_write()</tt></a> function.</p>
</div>

View File

@ -53,7 +53,7 @@
<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. (Related option: <tt>_VOLUMES</tt>)</dd>
<dd>Invalid drive number is specified in 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>

View File

@ -16,7 +16,7 @@
<p>The f_readdir function reads directory entries.</p>
<pre>
FRESULT f_readdir (
DIR* <span class="arg">dj</span>, <span class="c">/* [IN] Directory object */</span>
DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Directory object */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] File information structure */</span>
);
</pre>
@ -25,7 +25,7 @@ FRESULT f_readdir (
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dj</dt>
<dt>dp</dt>
<dd>Pointer to the open directory object.</dd>
<dt>fno</dt>
<dd>Pointer to the file information structure to store the read item.</dd>
@ -49,9 +49,14 @@ FRESULT f_readdir (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_readdir()</tt> function reads directory items, file and directory, in sequence. All items in the directory can be read by calling <tt>f_readdir()</tt> function repeatedly. When all directory items have been read and no item to read, the function returns a null string into <tt>fname[]</tt> member without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object will be rewinded.</p>
<p>When LFN feature is enabled, <tt>lfname</tt> and <tt>lfsize</tt> in the file information structure must be initialized with valid value prior to use it. The <tt>lfname</tt> is a pointer to the string buffer to return the long file name. The <tt>lfsize</tt> is the size of the string buffer in unit of <tt>TCHAR</tt>. If either the size of read buffer or LFN working buffer is insufficient for the LFN or the object has no LFN, a null string will be returned to the LFN read buffer. If the LFN contains any charactrer that cannot be converted to OEM code, a null string will be returned but this is not the case on Unicode API configuration. When <tt>lfname</tt> is a null, nothing of the LFN is returned. When the object has no LFN, some small capitals can be contained in the SFN in the <tt>fname[]</tt>.</p>
<p>When relative path feature is enabled (<tt>_FS_RPATH == 1</tt>), dot entries ("." and "..") are not filtered out and they will appear in the read items.</p>
<p>The <tt>f_readdir()</tt> function reads directory items, file and directory, in sequence. All items in the directory can be read by calling <tt>f_readdir()</tt> function repeatedly. When relative path feature is enabled (<tt>_FS_RPATH &gt;= 1</tt>), dot entries ("." and "..") are not filtered out and they will appear in the read items. When all directory items have been read and no item to read, a null string is returned into the <tt>fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded.</p>
<p>When LFN feature is enabled, <tt>lfname</tt> and <tt>lfsize</tt> in the file information structure must be initialized with valid value prior to use it. The <tt>lfname</tt> is a pointer to the LFN read buffer. The <tt>lfsize</tt> is size of the LFN read buffer in unit of <tt>TCHAR</tt>. If the LFN is not needed, set a null pointer to the <tt>lfname</tt> and the LFN is not returned. A null string will be returned into the LFN read buffer in case of following conditions.</p>
<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>
</ul>
<p>When the directory item has no LFN information, lower case characters can be contained in the <tt>fname[]</tt>.</p>
</div>
@ -101,6 +106,7 @@ FRESULT scan_files (
printf("%s/%s\n", path, fn);
}
}
f_closedir(&amp;dir)
}
return res;
@ -111,7 +117,7 @@ FRESULT scan_files (
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="closedir.html">f_closedir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_rename</h2>
<p>Renames an object.</p>
<p>Renames a file or sub-directory.</p>
<pre>
FRESULT f_rename (
const TCHAR* <span class="arg">old_name</span>, <span class="c">/* [IN] Old object name */</span>
@ -26,9 +26,9 @@ FRESULT f_rename (
<h4>Parameters</h4>
<dl class="par">
<dt>old_name</dt>
<dd>Pointer to a null-terminated string specifies the old <a href="filename.html">object name</a> to be renamed.</dd>
<dd>Pointer to a null-terminated string that specifies the old <a href="filename.html">object name</a> to be renamed.</dd>
<dt>new_name</dt>
<dd>Pointer to a null-terminated string specifies the new object name without drive number.</dd>
<dd>Pointer to a null-terminated string tha specifies the new object name without drive number.</dd>
</dl>
</div>
@ -58,7 +58,7 @@ FRESULT f_rename (
<div class="para desc">
<h4>Description</h4>
<p>Renames an object (file or 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. 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>
</div>

View File

@ -19,14 +19,17 @@
FATFS* fs; <span class="c">/* Pointer to the owner file system object */</span>
WORD id; <span class="c">/* Owner file system mount ID */</span>
WORD index; <span class="c">/* Index of directory entry to start to search next */</span>
DWORD sclust; <span class="c">/* Table start cluster (0:Root dir) */</span>
DWORD sclust; <span class="c">/* Table start cluster (0:Root directory) */</span>
DWORD clust; <span class="c">/* Current cluster */</span>
DWORD sect; <span class="c">/* Current sector */</span>
BYTE* dir; <span class="c">/* Pointer to the current SFN entry in the win[] */</span>
BYTE* fn; <span class="c">/* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */</span>
<span class="k">#if</span> _FS_LOCK
UINT lockid; <span class="c">/* Sub-directory lock ID (0:Root directory) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _USE_LFN
WCHAR* lfn; <span class="c">/* Pointer to the LFN working buffer */</span>
WORD lfn_idx; <span class="c">/* Index of last matched LFN entry (0xFFFF:No LFN) */</span>
WORD lfn_idx; <span class="c">/* Index of top of last matched LFN entris (0xFFFF:No LFN) */</span>
<span class="k">#endif</span>
} DIR;
</pre>

View File

@ -25,7 +25,7 @@ FRESULT f_setlabel (
<h4>Parameters</h4>
<dl class="par">
<dt>name</dt>
<dd>Pointer to the nul-terminated string specifying the volume label to be set.</dd>
<dd>Pointer to the null-terminated string that specifies the volume label to be set.</dd>
</dl>
</div>
@ -49,7 +49,7 @@ FRESULT f_setlabel (
<div class="para desc">
<h4>Description</h4>
<p>When the string has a drive number, the volume label will be set to the volume specified by the drive number. If the volume label is a null-string, the volume label on the volume will be removed. The format of the volume label is similar to the SFN but there are some difference shown below:</p>
<p>When the string has a drive number, the volume label will be set to the volume specified by the drive number. If the volume label is a null-string, the volume label on the volume will be removed. The format of the volume label is similar to the SFN but there are some differences shown below:</p>
<ul>
<li>11 bytes or less in length as local character code.</li>
<li>Cannot contain period.</li>

View File

@ -18,10 +18,10 @@
<span class="k">typedef</span> <span class="k">struct</span> {
BYTE fs_type; <span class="c">/* FAT sub-type (0:Not mounted) */</span>
BYTE drv; <span class="c">/* Physical drive number */</span>
BYTE csize; <span class="c">/* Sectors per cluster (1,2,4...128) */</span>
BYTE csize; <span class="c">/* Sectors per cluster (1,2,4,...,128) */</span>
BYTE n_fats; <span class="c">/* Number of FAT copies (1,2) */</span>
BYTE wflag; <span class="c">/* win[] dirty flag */</span>
BYTE fsi_flag; <span class="c">/* fsinfo dirty flag */</span>
BYTE wflag; <span class="c">/* win[] flag (b0:win[] is dirty) */</span>
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
@ -31,12 +31,11 @@
_SYNC_t sobj; <span class="c">/* Identifier of sync object */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !_FS_READONLY
DWORD last_clust; <span class="c">/* Last allocated cluster */</span>
DWORD free_clust; <span class="c">/* Number of free clusters */</span>
DWORD fsi_sector; <span class="c">/* fsinfo sector (FAT32) */</span>
DWORD last_clust; <span class="c">/* FSINFO: Last allocated cluster */</span>
DWORD free_clust; <span class="c">/* FSINFO: Number of free clusters */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_RPATH
DWORD cdir; <span class="c">/* Current directory cluster (0:root) */</span>
DWORD cdir; <span class="c">/* Current directory start cluster (0:root) */</span>
<span class="k">#endif</span>
DWORD n_fatent; <span class="c">/* Number of FAT entries (== Number of clusters + 2) */</span>
DWORD fsize; <span class="c">/* Sectors per FAT */</span>
@ -45,7 +44,7 @@
DWORD dirbase; <span class="c">/* Root directory area start sector (FAT32: Cluster#) */</span>
DWORD database; <span class="c">/* Data area start sector */</span>
DWORD winsect; <span class="c">/* Current sector appearing in the win[] */</span>
BYTE win[_MAX_SS]; <span class="c">/* Disk access window for Directory, FAT (and file data on tiny cfg) */</span>
BYTE win[_MAX_SS]; <span class="c">/* Disk access window for directory, FAT (and file data at tiny cfg) */</span>
} FATFS;
</pre>
</div>

View File

@ -13,16 +13,16 @@
<div class="para">
<h2>FIL</h2>
<p>The <tt>FIL</tt> structure (file object) holds state of an open file. It is created by <tt>f_open()</tt> function and discarded by <tt>f_close()</tt> function. Application program must not modify any member in this structure except for <tt>cltbl</tt>. Note that a sector buffer is defined in this structure under non-tiny configuration, so that the <tt>FIL</tt> structures should not be defined as auto variable.</p>
<p>The <tt>FIL</tt> structure (file object) holds state of an open file. It is created by <tt>f_open()</tt> function and discarded by <tt>f_close()</tt> function. Application program must not modify any member in this structure except for <tt>cltbl</tt>. Note that a sector buffer is defined in this structure at non-tiny configuration, so that the <tt>FIL</tt> structures should not be defined as auto variable.</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> {
FATFS* fs; <span class="c">/* Pointer to the owner file system object */</span>
WORD id; <span class="c">/* Owner file system mount ID */</span>
BYTE flag; <span class="c">/* File status flags */</span>
BYTE pad1;
BYTE flag; <span class="c">/* File object status flags */</span>
BYTE err; <span class="c">/* Abort flag (error code) */</span>
DWORD fptr; <span class="c">/* File read/write pointer (Byte offset origin from top of the file) */</span>
DWORD fsize; <span class="c">/* File size */</span>
DWORD fsize; <span class="c">/* File size in unit of byte */</span>
DWORD sclust; <span class="c">/* File start cluster */</span>
DWORD clust; <span class="c">/* Current cluster */</span>
DWORD dsect; <span class="c">/* Current data sector */</span>
@ -33,11 +33,11 @@
<span class="k">#if</span> _USE_FASTSEEK
DWORD* cltbl; <span class="c">/* Pointer to the cluster link map table (Nulled on file open) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_SHARE
UINT lockid; <span class="c">/* File lock ID */</span>
<span class="k">#if</span> _FS_LOCK
UINT lockid; <span class="c">/* Fle lock ID */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !_FS_TINY
BYTE buf[_MAX_SS]; <span class="c">/* Data read/write buffer */</span>
BYTE buf[_MAX_SS]; <span class="c">/* File private data transfer buffer */</span>
<span class="k">#endif</span>
} FIL;
</pre>

View File

@ -58,11 +58,11 @@
<dt>fattrib</dt>
<dd>Indicates the file/directory attribute in combination of <tt>AM_DIR</tt>, <tt>AM_RDO</tt>, <tt>AM_HID</tt>, <tt>AM_SYS</tt> and <tt>AM_ARC</tt>.</dd>
<dt>fname[]</dt>
<dd>Indicates the file/directory name in 8.3 format null-terminated string. It is always returnd with upper case on non-LFN configuration but it can be returned with lower case on LFN configuration.</dd>
<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 on 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. 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 on non-LFN configuration.</dd>
<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>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_stat</h2>
<p>The f_stat gets the file status.</p>
<p>The f_stat function checks the existence of a file or sub-directory.</p>
<pre>
FRESULT f_stat (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
@ -26,9 +26,9 @@ FRESULT f_stat (
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">file or directory</a> to get its information.</dd>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">object</a> to get its information.</dd>
<dt>fno</dt>
<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information.</dd>
<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information of the object. Set null pointer if it is not needed.</dd>
</dl>
</div>
@ -54,7 +54,7 @@ FRESULT f_stat (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_stat()</tt> function gets the size, timestamp and attribute of a file or directory. For details of the infomation, 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 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>
</div>

View File

@ -45,7 +45,8 @@ FRESULT f_sync (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_sync()</tt> function performs the same process as <tt>f_close()</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync()</tt> function of periodic or immediataly after <tt>f_write()</tt> function can minimize the risk of data loss due to a sudden blackout or an unintentional media removal. However the <tt>f_sync()</tt> function immediataly before <tt>f_close()</tt> function has no advantage because it performs <tt>f_sync()</tt> function in it. In other words, the differnce between those functions is that the file object is invalidated or not. </p>
<p>The <tt>f_sync()</tt> function performs the same process as <tt>f_close()</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync()</tt> function of periodic or immediataly after <tt>f_write()</tt> function can minimize the risk of data loss due to a sudden blackout or an unintentional media removal. For more information, refer to <a href="appnote.html#critical">application note</a>.</p>
<p>However the <tt>f_sync()</tt> function immediataly before <tt>f_close()</tt> function has no advantage because it performs <tt>f_sync()</tt> function in it. In other words, the differnce between those functions is that the file object is invalidated or not.</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_unlink</h2>
<p>The f_unlink function removes a file or directory.</p>
<p>The f_unlink function removes a file or sub-directory.</p>
<pre>
FRESULT f_unlink (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Object name */</span>
@ -56,10 +56,10 @@ FRESULT f_unlink (
<div class="para desc">
<h4>Description</h4>
<p>
If condition of the object to be removed is applicable to the following terms, the function will fail with error.<ul>
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 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 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 shareing control</a> is enabled.</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>
</ul>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_utime</h2>
<p>The f_utime function changes the timestamp of a file or directory.</p>
<p>The f_utime function changes the timestamp of a file or sub-directory.</p>
<pre>
FRESULT f_utime (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
@ -26,7 +26,7 @@ FRESULT f_utime (
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be changed.</dd>
<dd>Pointer to the null-terminated string that specifies an <a href="filename.html">object</a> to be changed.</dd>
<dt>fno</dt>
<dd>Pointer to the file information structure that has a timestamp to be set in member fdate and ftime. Do not care any other members.</dd>
</dl>
@ -55,7 +55,7 @@ FRESULT f_utime (
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_utime()</tt> function changes the timestamp of a file or directory</p>
<p>The <tt>f_utime()</tt> function changes the timestamp of a file or sub-directory</p>
</div>

View File

@ -24,12 +24,11 @@ FRESULT open_append (
int main (void)
{
FRESULT fr;
FATFS fs;
FIL fil;
f_mount(0, &Fatfs);
/* Open or create a log file and ready to append */
f_mount(&fs, "", 0);
fr = open_append(&fil, "logfile.txt");
if (fr != FR_OK) return 1;

View File

@ -14,7 +14,7 @@ FRESULT empty_directory (
FILINFO fno;
#if _USE_LFN
fno.lfname = 0; /* Set null pointer because LFN is not needed */
fno.lfname = 0; /* Eliminate LFN output */
#endif
fr = f_opendir(&dir, path);
if (fr == FR_OK) {
@ -36,6 +36,7 @@ FRESULT empty_directory (
if (fr != FR_OK) break;
}
path[--i] = '\0';
closedir(&dir);
}
return fr;
@ -46,10 +47,12 @@ FRESULT empty_directory (
int main (void)
{
FRESULT fr;
FATFS fs;
char buff[64]; /* Working buffer */
f_mount(0, &Fatfs);
f_mount(&fs, "", 0);
strcpy(buff, "/"); /* Directory to be emptied */
fr = empty_directory(buff);

View File

@ -1,23 +1,29 @@
/*------------------------------------------------------------/
/*----------------------------------------------------------------------/
/ Allocate a contiguous area to the file
/------------------------------------------------------------*/
/-----------------------------------------------------------------------/
/ This function checks if the file is contiguous with desired size.
/ If not, a block of contiguous sectors is allocated to the file.
/ 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 */
#error This function may not be compatible with this revision of FatFs module.
#endif
/* Declarations of FatFs internal functions accessible from applications.
/ This is intended to be used by disk checking/fixing or dirty hacks :-) */
/ This is intended to be used for disk checking/fixing or dirty hacks :-) */
DWORD clust2sect (FATFS* fs, DWORD clst);
DWORD get_fat (FATFS* fs, DWORD clst);
FRESULT put_fat (FATFS* fs, DWORD clst, DWORD val);
DWORD allocate_contiguous_clusters ( /* Returns file start sector number */
DWORD allocate_contiguous_clusters ( /* Returns the first sector in LBA (0:error or not contiguous) */
FIL* fp, /* Pointer to the open file object */
DWORD len /* Number of bytes to allocate */
)
{
DWORD csz, tcl, ncl, ccl, cl;
#if _FATFS != 82786 /* Check if R0.09b */
#error This function may not be compatible with this revision of FatFs module.
#endif
if (f_lseek(fp, 0) || !len) /* Check if the given parameters are valid */
return 0;
@ -37,7 +43,9 @@ DWORD allocate_contiguous_clusters ( /* Returns file start sector number */
if (ncl == tcl) /* Is the file contiguous? */
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
}
#if _FS_READONLY
return 0;
#else
if (f_truncate(fp)) return 0; /* Remove the existing chain */
/* Find a free contiguous area */
@ -59,6 +67,7 @@ DWORD allocate_contiguous_clusters ( /* Returns file start sector number */
if (f_lseek(fp, len)) return 0;
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
#endif
}
@ -66,18 +75,18 @@ int main (void)
{
FRESULT fr;
DRESULT dr;
FATFS fs;
FIL fil;
DWORD org;
f_mount(0, &Fatfs);
/* Open or create a file */
fr = f_open(&fil, "pagefile.dat", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
f_mount(&fs, "", 0);
fr = f_open(&fil, "swapfile.sys", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if (fr) return 1;
/* Check if the file is 64MB in size and occupies a contiguous area.
/ If not, a contiguous area is re-allocated to the file. */
/ If not, a contiguous area will be re-allocated to the file. */
org = allocate_contiguous_clusters(&fil, 0x4000000);
if (!org) {
printf("Function failed due to any error or insufficient contiguous area.\n");
@ -85,14 +94,13 @@ int main (void)
return 1;
}
/* Now you can read/write the file with disk functions bypassing the file system layer.
/ Note that 4th argument of the disk read/write function is BYTE, so that you may need
/ to bypass the disk functions for large number of multiple sector transfer. */
/* Now you can read/write the file with disk functions bypassing the file system layer. */
dr = disk_write(fil.fs->drv, Buff, org, 128); /* Write 64K bytes from top of the file */
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512Ki bytes from top of the file */
...
f_close(&fil);
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -43,7 +43,7 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
<h4>システム構成</h4>
<p>下に示す依存関係図は、FatFsモジュール利用の組み込みシステムにおける代表的な構成を示します。</p>
<p><img src="../img/modules.png" width="507" height="224" alt="システム構成図"></p>
<p><img src="../img/modules.png" width="580" height="280" alt="システム構成図"></p>
<h4>ユーザの作成する関数</h4>
<p>必要なのは FatFsモジュールの要求するディスク関数を用意することだけで、それ以外にすることはありません。既に動作しているディスク関数があるなら、その APIを FatFsに合わせるかグルー関数でつなぐだけで済みますが、無い場合はほかから移植するか最初から書くかする必要があります。定義されている全ての関数が常に必要なわけではありません。例えば、リード・オンリー構成では書き込み系関数は必要ありません。次の表に構成オプションと要求される関数の対応を示します。</p>
@ -80,17 +80,17 @@ FatFsモジュールはANSI C(C89)準拠で記述されているので、普通
<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>10395</td><td>7037</td><td>6555</td><td>13362</td><td>10609</td><td>11364</td><td>12884</td><td>7814</td><td>8783</td><td>5826</td><td>7659</td></tr>
<tr> <td>text (Min, R/W)</td> <td>6519</td><td>4747</td><td>4315</td> <td>8608</td> <td>7043</td> <td>7539</td> <td>8860</td><td>5070</td><td>5723</td><td>3821</td><td>5038</td></tr>
<tr> <td>text (Full, R/O)</td> <td>4563</td><td>3147</td><td>2911</td> <td>6174</td> <td>4925</td> <td>5340</td> <td>6136</td><td>3628</td><td>3863</td><td>2721</td><td>3534</td></tr>
<tr> <td>text (Min, R/O)</td> <td>3311</td><td>2463</td><td>2209</td> <td>4610</td> <td>3817</td> <td>4029</td> <td>4641</td><td>2762</td><td>3003</td><td>2068</td><td>2722</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*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*544</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td><td>V*564 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*32</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</td><td>V*564 +<br>F*36</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>
</table>
<pre>
FatFs R0.09b options:
FatFs R0.10 options:
_FS_READONLY 0 (R/W), 1 (R/O)
_FS_MINIMIZE 0 (Full function), 3 (Minimized function)
_USE_STRFUNC 0 (Disable string functions)
@ -123,6 +123,7 @@ _FS_LOCK 0 (Disable file lock control)
<tr><td>f_sync</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_lseek</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_opendir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_closedir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_readdir</td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_stat</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_getfree</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
@ -161,7 +162,7 @@ _FS_LOCK 0 (Disable file lock control)
<tr><td>950(Big5)</td><td>+111497</td></tr>
</table>
<p>LFN機能の上手な使い方は、それを使わないということです。実際、組み込み用途ではLFN機能がどうしても必要になるということはほとんど無いはずです。LFNを有効にすると、選択されたコード・ページに応じてモジュール・サイズが増大されます。右の表に各コード・ページにおけるLFNを有効にしたときのモジュール・サイズの違いを示します。特に、CJK地域では数万の文字が使われていますが、不幸なことにそれは巨大なOEMUnicode相互変換テーブルを要求し、モジュール・サイズは劇的に増大されます。その結果、それらのコード・ページにおいてLFNを有効にしたFatFsモジュールは、AVRを含む殆どの8ビット・マイコンにインプリメントされることができません。</p>
<p>注: マイクロソフト社はFATファイル・システムについていくつかの特許を保有しています。いずれもLFNの実装に関するもので、LFN機能に対して$0.25/unitのライセンス料を要求しています。最近のFAT32ドライバの多くはLFN機能を含んでいるため、それらの使用に当たってライセンスが必要になりますが、FatFsではLFN機能の有効・無効を任意に構成できます。このため、商用製品でLFN機能を有効にするときは、最終仕向地によってはライセンスが必要かも知れません</p>
<p>LFN機能のハードルはそれだけではありません。マイクロソフト社はFATファイル・システムについていくつかの特許を保有しています。いずれもLFN機能の実装に関するもので、その利用に対して$0.25/unitのライセンス料を要求しています。このため、商用製品でLFN機能を利用するときは、最終仕向地によってはライセンスが必要になります。最近のFAT32ドライバの多くはLFN機能を含んでいるため、それらの使用に当たってライセンスが必要になりますが、FatFsではLFN機能を構成オプションで任意にON/OFFできるため、無効にしてライセンス問題を回避することもできます</p>
</div>
<div class="para" id="jap">
@ -171,21 +172,21 @@ _FS_LOCK 0 (Disable file lock control)
<div class="para" id="unicode">
<h3>Unicode入出力への対応</h3>
<p>API上におけるファイル名の入出力はデフォルトではANSI/OEMコードで行われますが、これをUnicodeに切り替えることもできます。つまり、これはFatFsがLFN機能に完全対応していることを意味します。Unicodeのファイル名に関する詳細は、<a href="filename.html">ファイル名</a>を参照してください。</p>
<p>FatFs API上におけるファイル名等の文字列データの入出力はデフォルトではANSI/OEMコードで行われますが、これをUnicode(UTF-16)に切り替えることもできます(<tt>_LFN_UNICODE</tt>オプションで設定)。つまり、これはFatFsがLFN機能に完全対応していることを意味します。Unicodeのファイル名に関する詳細は、<a href="filename.html">ファイル名</a>を参照してください。</p>
</div>
<div class="para" id="reentrant">
<h3>リエントランシー</h3>
<p>互いに異なるボリュームに対するファイル操作はリエントラントで、常に同時平行に動作できます。同じボリュームに対してはデフォルトではリエントラントではありませんが、<tt>_FS_REENTRANT</tt>オプションでリエントラント(スレッド・セーフ)にすることはできます。この場合、OS依存の同期オブジェクト操作関数<tt>ff_cre_syncobj, ff_del_syncobj, ff_req_grant</tt><tt>ff_rel_grant</tt>もまたプロジェクトに追加されなければなりません。サンプル・コードと解説は<tt>option/syncobj.c</tt>にあります。</p>
<p>互いに異なるボリュームに対するファイル操作はリエントラントで、常に同時平行に動作できます。同じボリュームに対してはデフォルトではリエントラントではありませんが、<tt>_FS_REENTRANT</tt>オプションでリエントラント(スレッド・セーフ)にすることはできます。この場合、OS依存の同期オブジェクト操作関数<tt>ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant(), ff_rel_grant()</tt>もまたプロジェクトに追加されなければなりません。サンプル・コードと解説は<tt>option/syncobj.c</tt>にあります。</p>
<p>この場合、あるタスクがボリュームを使用中に他のタスクからそのボリュームに対するファイル関数が呼び出されると、そのアクセスは先のタスクがファイル関数を抜けるまでブロックされます。もし、待ち時間が<tt>_TIMEOUT</tt>で指定された期間を越すと、その関数は<tt>FR_TIMEOUT</tt>でアボートします。いくつかのRTOSではタイムアウト機能はサポートされないかも知れません。</p>
<p>ひとつの例外が<tt>f_mount()</tt><tt>f_mkfs()</tt>にあります。これらの関数は同じボリュームに対してリエントラントではありません。これらの関数を使用するときは、アプリケーション・レベルで排他制御しなければなりません。</p>
<p>注: このセクションはFatFsモジュールそれ自体のリエントランシーについて説明しています。ディスクI/Oモジュールのリエントランシーに関しては何の前提もありません。</p>
<p>ひとつの例外が<tt>f_mount(), f_mkfs(), f_fdisk()</tt>にあります。これらの関数は同じボリューム(または関連する物理ドライブ)に対してリエントラントではありません。これらの関数を使用するときは、アプリケーション・レベルで排他制御しなければなりません。</p>
<p>注: このセクションはFatFsモジュールそれ自体のリエントランシーについて説明しています。その下位のディスクI/Oモジュールのリエントランシーに関しては何の前提もありません。</p>
</div>
<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">
@ -255,7 +256,7 @@ _FS_LOCK 0 (Disable file lock control)
<h3>FatFsのライセンスについて</h3>
<p>ソース・ファイルのヘッダにライセンス条件が記述されているので、利用の際はそれに従うこと。英語を読めない方のために以下に日本語訳を示しておきます。</p>
<pre>/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.09b (C)ChaN, 2013
/ FatFs - FAT file system module R0.10 (C)ChaN, 2013
/-----------------------------------------------------------------------------/
/ FatFsモジュールは、小規模な組み込みシステム向けの汎用FATファイルシステム・
/ モジュールです。これはフリー・ソフトウェアとして、教育・研究・開発のために
@ -269,7 +270,7 @@ _FS_LOCK 0 (Disable file lock control)
/ * ソース・コードを再配布するときは、上記の著作権表示を保持しなければなりません。
/
/-----------------------------------------------------------------------------/</pre>
<p>要するにFatFsはタダで自由に使えるということです。ソース・コードを再配布するときは、このブロックをそのまま保持しておくこと。このようにFatFsはBSDライクなライセンスとしていますが、一つ大きな違いがあります。特に組み込み用途での利用価値を高めるため、バイナリ形式(ソース・コードを含まない形式全て)での再配布については、条件は設けていません。その場合は、FatFsおよびそのライセンス文書についてはドキュメントに明記してもしなくてもかまいません。もちろんGNU GPLプロジェクトとも共存可能です。何らかの変更を加えて再配布する際は、矛盾しない他のライセンス(GNU GPLやBSDライセンスなど)に変更することも可能です。</p>
<p>要するにFatFsはタダで自由に使えるということです。ソース・コードを再配布するときは、このブロックをそのまま保持しておくこと。このようにFatFsはBSDライクなライセンスとしていますが、一つ大きな違いがあります。特に組み込み用途での利用価値を高めるため、バイナリ形式(ソース・コードを含まない形式全て)での再配布については、条件は設けていません。その場合は、FatFsおよびそのライセンス文書についてはドキュメントに明記してもしなくてもかまいません。これは、一条項BSDライセンスと等価ということです。もちろんGNU GPLプロジェクトとも共存可能です。何らかの変更を加えて再配布する際は、矛盾しない他のライセンス(GNU GPLや修正BSDライセンスなど)に変更することも可能です。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -16,7 +16,7 @@
<p>カレント・ドライブを変更します。</p>
<pre>
FRESULT f_chdrive (
BYTE <span class="arg">vol</span> <span class="c">/* [IN] 論理ドライブ番号 */</span>
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] 対象ドライブを指定します */</span>
);
</pre>
</div>
@ -24,8 +24,8 @@ FRESULT f_chdrive (
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>vol</dt>
<dd>カレント・ドライブに設定する<a href="filename.html">論理ドライブ番号</a>を指定します。</dd>
<dt>path</dt>
<dd>カレント・ドライブに設定する<a href="filename.html">論理ドライブ番号</a>を指定するパス名を指定します。</dd>
</dl>
</div>

View File

@ -13,10 +13,10 @@
<div class="para func">
<h2>f_chmod</h2>
<p>ファイルまたはディレクトリの属性を変更します。</p>
<p>ファイルまたはサブ・ディレクトリの属性を変更します。</p>
<pre>
FRESULT f_chmod (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] ファイルまたはディレクトリ名へのポインタ */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] オブジェクト名へのポインタ */</span>
BYTE <span class="arg">attr</span>, <span class="c">/* [IN] 設定値 */</span>
BYTE <span class="arg">mask</span> <span class="c">/* [IN] 変更マスク */</span>
);
@ -27,7 +27,7 @@ FRESULT f_chmod (
<h4>引数</h4>
<dl class="par">
<dt>path</dt>
<dd>属性変更対象のファイルまたはディレクトリ<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列を指定します。</dd>
<dd>属性変更対象のオブジェクトの<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列を指定します。</dd>
<dt>attr</dt>
<dd>設定する属性。指定可能な属性は次の通りで、これらの組み合わせで指定します。指定されなかった属性は解除されます。<br>
<table class="lst">
@ -64,12 +64,6 @@ FRESULT f_chmod (
</div>
<div class="para desc">
<h4>解説</h4>
<p>ファイルまたはディレクトリの属性を変更します。</p>
</div>
<div class="para comp">
<h4>対応情報</h4>
<p><tt>_FS_READONLY == 0</tt>で、且つ<tt>_FS_MINIMIZE == 0</tt>のとき使用可能です。</p>

View File

@ -46,6 +46,7 @@ FRESULT f_close (
<div class="para desc">
<h4>解説</h4>
<p>ファイルを閉じます。何らかの書き込みの行われたファイルの場合、キャッシュされた状態(リード/ライト・バッファ上のデータ、変更されたFATやディレクトリ項目)はディスクに書き戻されます。関数が正常終了すると、そのファイル・オブジェクトは無効になり、そのメモリも解放できます。</p>
<p>ファイル・オブジェクトが読み出し専用モードで、<tt>_FS_LOCK</tt>オプションが選択されていない場合は、ファイルを閉じずにファイル・オブジェクトを破棄することもできます。しかし、これは将来の互換性の点で推奨はされません。</p>
</div>

64
doc/ja/closedir.html Normal file
View File

@ -0,0 +1,64 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="alternate" hreflang="en" title="English" href="../en/close.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_closedir</title>
</head>
<body>
<div class="para func">
<h2>f_closedir</h2>
<p>ディレクトリを閉じます。</p>
<pre>
FRESULT f_closedir (
DIR* <span class="arg">dp</span> <span class="c">/* [IN] ディレクトリ・オブジェクトへのポインタ */</span>
);
</pre>
</div>
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>dp</dt>
<dd>閉じようとするディレクトリのディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
</dl>
</div>
<div class="para ret">
<h4>戻り値</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>解説</h4>
<p>ディレクトリを閉じます。関数が正常終了すると、そのディレクトリ・オブジェクトは無効になり、そのメモリも解放できます。</p>
<p><tt>_FS_LOCK</tt>オプションが選択されていない場合は、この処理を行わずにディレクトリ・オブジェクトを破棄することもできます。しかし、これは将来の互換性の点で推奨はされません。</p>
</div>
<div class="para comp">
<h4>対応情報</h4>
<p><tt>_FS_MINIMIZE &lt;= 1</tt>のとき使用可能になります。</p>
</div>
<div class="para ref">
<h4>参照</h4>
<tt><a href="opendir.html">f_opendir</a>, <a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>

View File

@ -54,11 +54,11 @@ DRESULT disk_ioctl (
<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>GET_SECTOR_COUNT</td><td><tt class="arg">buff</tt>の指す<tt>DWORD</tt>変数にドライブ上の総セクタ数を返します。<tt>f_mkfs()</tt>内で作成するボリュームのサイズを決定するために使用されます。</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>フラッシュ・メモリの消去ブロック・サイズを<tt class="arg">buff</tt>の指すDWORD変数にセクタ単位で返します。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>配列には消去する領域 {開始セクタ,終了セクタ} を指定して呼び出します。これは、ATAコマンド・セットのTrimコマンドと等価で、<tt>_USE_ERASE</tt>が1のとき、クラスタが解放されるときに呼び出されます。この機能をサポートしない場合やフラッシュ・メモリ以外のメディアでは何もしません。この機能の戻り値はチェックされず、また、指定領域の消去が完全に行われなかったとしてもFatFsの動作には影響ありません。</td></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>GET_SECTOR_COUNT</td><td><tt class="arg">buff</tt>の指す<tt>DWORD</tt>変数にドライブ上の総セクタ数を返します。<tt>f_mkfs()</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>
</table>
</div>

View File

@ -13,13 +13,13 @@
<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>
BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] 読み出しバッファへのポインタ */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] 読み出し開始セクタ番号 */</span>
BYTE <span class="arg">count</span> <span class="c">/* [IN] 読み出セクタ数 */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] 読み出セクタ数 */</span>
);
</pre>
</div>
@ -30,11 +30,11 @@ DRESULT disk_read (
<dt>pdrv</dt>
<dd>物理ドライブ番号(0-9)が指定されます。</dd>
<dt>buff</dt>
<dd>ディスクから読み出したデータを格納する<em>バイト配列</em>で、読み出されるバイト数分のサイズが必要です。指定されるアドレスは<em>常にワード・アライメントされているとは限りません</em></dd>
<dd>ディスクから読み出したデータを格納する<em>バイト配列</em>で、読み出されるバイト数分のサイズが必要です。</dd>
<dt>sector</dt>
<dd>読み出しを開始するセクタ番号。LBAで指定されます。</dd>
<dt>count</dt>
<dd>読み出すセクタ数。 1128の範囲で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ読み出しに分解した場合、スループットが低下することがあります。</dd>
<dd>読み出すセクタ数。 1128の範囲の値で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ読み出しに分解した場合、スループットが低下することがあります。</dd>
</dl>
</div>
@ -54,6 +54,16 @@ DRESULT disk_read (
</div>
<div class="para desc">
<h4>解説</h4>
<p><tt class="arg">buff</tt><tt>BYTE</tt>型なので、指定されるアドレスは<em>常にワード・アライメントされているとは限りません</em>。非アライメント・アドレスへの転送は、<a href="appnote.html#fs1">直接転送</a>において発生することがあります。もしも、ハードウェア上の制約でそのような転送が不可能なときは、この関数内で二段転送するなどして解決するか、または別の方法で対応しなければなりません。次にいくつかの対応方法を示します(いずれか一つでOK)。</p>
<ul>
<li>この関数内で解決する - 推奨</li>
<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 class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>

View File

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

View File

@ -19,7 +19,7 @@ DRESULT disk_write (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] 書き込むデータへのポインタ */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] 書き込み開始セクタ番号 */</span>
BYTE <span class="arg">count</span> <span class="c">/* [IN] 書き込セクタ数 */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] 書き込セクタ数 */</span>
);
</pre>
</div>
@ -34,7 +34,7 @@ DRESULT disk_write (
<dt>sector</dt>
<dd>書き込みを開始するセクタ番号。LBAで指定されます。</dd>
<dt>count</dt>
<dd>書き込むセクタ数。 1128の範囲で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ書き込みに分解した場合、スループットが極端に低下することがあります。</dd>
<dd>書き込むセクタ数。 1128の範囲の値で指定されます。一般的に、複数セクタの転送要求はデバイスに対して可能な限りマルチ・セクタ転送しなければなりません。複数のシングル・セクタ書き込みに分解した場合、スループットが極端に低下することがあります。</dd>
</dl>
</div>

View File

@ -33,7 +33,7 @@ int f_error (
<div class="para ret">
<h4>戻り値</h4>
<p>ファイル操作中のエラーで処理が中断されている場合は、0以外の値を返します。それ以外の時は0を返します。</p>
<p>ファイルが操作中のエラーによって処理が中断されている場合は、0以外の値を返します。それ以外の時は0を返します。</p>
</div>

View File

@ -17,7 +17,7 @@
<pre>
FRESULT f_fdisk (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] 物理ドライブ番号 */</span>
const DWORD <em>part[]</em>, <span class="c">/* [IN] 区画マップ・テーブル */</span>
const DWORD <span class="arg">part[]</span>, <span class="c">/* [IN] 区画マップ・テーブル */</span>
void* <span class="arg">work</span> <span class="c">/* [-] ワークエリア */</span>
);
</pre>
@ -27,7 +27,7 @@ FRESULT f_fdisk (
<h4>引数</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>分割する<em>物理ドライブ</em>を指定します。</dd>
<dd>分割する<em>物理ドライブ</em>のドライブ番号を指定します。</dd>
<dt>part[]</dt>
<dd>区画マップ・テーブルへのポインタを指定します。</dd>
<dt>work</dt>
@ -70,19 +70,19 @@ FRESULT f_fdisk (
<pre>
<span class="c">/* 新しい物理ドライブ(0)の初期化 */</span>
FATFS Fatfs;
FATFS fs;
DWORD plist[] = {50, 50, 0, 0}; <span class="c">/* 2分割 */</span>
BYTE work[_MAX_SS];
f_fdisk(0, plist, work); <span class="c">/* 物理ドライブ 0 の分割 */</span>
f_mount(0, &amp;Fatfs);
f_mkfs(0, 0, 0); <span class="c">/* 論理ドライブ 0 の初期化. 第二引数は無視される. */</span>
f_mount(0, 0);
f_mount(&amp;fs "0:", 0);
f_mkfs("0:", 0, 0); <span class="c">/* 論理ドライブ 0 のフォーマット. 第二引数は無視される. */</span>
f_mount(0, "0:", 0);
f_mount(1, &amp;Fatfs);
f_mkfs(1, 0, 0);
f_mount(1, 0);
f_mount(&amp;fs, "1:", 0);
f_mkfs("1:", 0, 0); <span class="c">/* 論理ドライブ 0 のフォーマット. 第二引数は無視される. */</span>
f_mount(0, "1:", 0);
</pre>
</div>

View File

@ -48,11 +48,12 @@
<p><br></p>
<div class="para" id="vol">
<h3>論理ドライブ(ボリューム)と物理ドライブ(ディスク装置)の対応</h3>
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、SFDとしてまたは第1区画のボリュームがマウントされます。<tt>_MULTI_PARTITION</tt>に 1以上を指定すると、個々の論理ドライブに対して個別に物理ドライブ番号・区画を指定できるようになります。この構成では、論理ドライブと区画の対応を解決するためのテーブルを次に示すように定義する必要があります。</p>
<h3>ボリューム管理</h3>
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、自動検出機能によりその物理ドライブ上の一つのFATボリュームがマウントされます。FATボリュームの検出は、セクタ0、第一区画、第二区画、第三区画、第四区画の順に行われます。</p>
<p><tt>_MULTI_PARTITION</tt>に1を指定すると、それぞれの論理ドライブに対して個別に物理ドライブ番号と区画を指定できるようになります。この構成では、論理ドライブと区画の対応を解決するためのテーブルを次に示すように定義する必要があります。</p>
<pre>
例:論理ドライブ02を物理ドライブ0(固定ディスク)の3つの基本区画に割り当て、
論理ドライブ3を物理ドライブ1(リムーバブル・ディスク)に割り当てる場合。
例:論理ドライブ02を物理ドライブ0(非リムーバブル)の3つの基本区画に割り当て、
論理ドライブ3を物理ドライブ1(リムーバブル)に割り当てる場合。
PARTITION VolToPart[] = {
{0, 1}, <span class="c">/* 論理ドライブ 0 ==> 物理ドライブ 0, 第1区画 */</span>
@ -61,13 +62,13 @@ PARTITION VolToPart[] = {
{1, 0} <span class="c">/* 論理ドライブ 3 ==> 物理ドライブ 1, 自動検出 */</span>
};
</pre>
<img src="../img/f7.png" width="828" height="288" alt="論理ドライブと物理ドライブの関係">
<p>複数区画指定を使用する場合、次の点に注意しなければなりません。
<ul>
<li>マウント可能な区画は基本区画のみで、拡張区画内には対応しない。</li>
<li>複数の区画を持つ物理ドライブは、非リムーバブルでなければならない。</li>
</ul>
</div>
<img src="../img/f7.png" width="828" height="288" alt="論理ドライブと物理ドライブの関係">
</body>
</html>

View File

@ -50,7 +50,7 @@ FRESULT f_getcwd (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>カレント・ドライブのカレント・ディレクトリのパス文字列を取得します。パス文字列は、ドライブ番号を含んだフル・パス名です。</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>
@ -53,7 +53,7 @@ FRESULT f_getfree (
<div class="para desc">
<h4>解説</h4>
<p>論理ドライブ上の空きクラスタ数を取得します。返されたファイル・システム・オブジェクトの<tt>csize</tt>メンバがクラスタあたりのセクタ数を示しているので、これを元に実際の空きサイズが計算できます。FAT32ボリュームにおいては、FSINFOセクタの状態によっては不正確な値を返したり、処理に時間がかかったりする可能性があります。</p>
<p>論理ドライブ上の空きクラスタ数を取得します。返されたファイル・システム・オブジェクトの<tt>csize</tt>メンバがクラスタあたりのセクタ数を示しているので、これを元に実際の空きサイズが計算できます。FAT32ボリュームにおいては、FSINFOが実際の状態と同期していない場合、不正確な空きサイズを返す可能性があります。この問題を避けるため、<tt>_FS_NOFSINFO</tt>オプションでFSINFOを無視して初回はフルFATスキャンをするように設定することもできます。</p>
</div>
@ -78,8 +78,8 @@ FRESULT f_getfree (
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
<span class="c">/* ボリュームとと空きのサイズをKiB単位で表示 (512バイト/セクタと仮定) */</span>
printf("%lu KB total drive space.\n%lu KB available.\n",
<span class="c">/* ボリューム全体のサイズと空きのサイズを表示 (512バイト/セクタと仮定) */</span>
printf("%10lu KiB total drive space.\n%10lu KiB available.\n",
tot_sect / 2, fre_sect / 2);
</pre>
</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)ときは、UTF-8エンコードのテキスト・ファイルとしてUCS-2に変換してバッファに読み込みます。それ以外の時は無変換(1文字1バイト)で読み込みます。</p>
<p>APIにUnicodeが選択(<tt>_LFN_UNICODE</tt>が1)されているときは、<span class="arg">buff</span>はUTF-16文字列になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で読み出します。</p>
</div>

View File

@ -54,7 +54,7 @@ FRESULT f_lseek (
<li>非書き込みモードまたは高速シーク・モードのため、ファイル・サイズでクリップされた。</li>
<li>ファイル拡張中にディスクが満杯になった。</li>
</ul>
<p><tt>_USE_FASTSEEK</tt>が1で、且つファイル・オブジェクトの<tt>cltbl</tt>メンバがNULL以外(<tt>f_open(</tt>)でNULLに設定される)のとき、高速シーク・モードになります。これはファイルのクラスタ配置情報(CLMT)をメモリ上に保持しておくことにより、FATにアクセスすることなく後方シークやロング・シークを高速に行う機能です。高速シーク・モードは、<tt>f_read()/f_wtite()</tt>の動作にも適用されます。高速シーク・モードでは<tt>f_wtite()/f_lseek()</tt>によるファイル・サイズの拡張はできません。</p>
<p><tt>_USE_FASTSEEK</tt>が1で、且つファイル・オブジェクトの<tt>cltbl</tt>メンバがNULL以外(<tt>f_open()</tt>でNULLに設定される)のとき、高速シーク・モードになります。これはファイルのクラスタ配置情報(CLMT)をメモリ上に保持しておくことにより、FATにアクセスすることなく後方シークやロング・シークを高速に行う機能です。高速シーク・モードは、<tt>f_read()/f_wtite()</tt>の動作にも適用されます。高速シーク・モードでは<tt>f_wtite()/f_lseek()</tt>によるファイル・サイズの拡張はできません。</p>
<p>高速シーク動作を行う前に、CLMTを作成しておく必要があります。これを作成するには、まずCLMT格納バッファ(<tt>DWORD</tt>型配列)を準備し、<tt>cltbl</tt>メンバにそのポインタをセットします。そして、配列の先頭要素にその配列のサイズ(要素数)を入れ、<tt>f_lseek()</tt><tt class="arg">ofs</tt><tt>CREATE_LINKMAP</tt>を指定して呼び出します。関数が成功するとCLMTが作成され、以降の<tt>f_read()/f_write()/f_lseek()</tt>ではFATへのアクセスは発生しません。<tt>FR_NOT_ENOUGH_CORE</tt>で失敗したときは配列サイズが不足で、先頭要素には実際に必要となる要素数が返されます。必要な要素数は、(ファイルの分割数 + 1) * 2 です。たとえば、ファイルが5つのフラグメントに分断されているときに必要な要素数は、12となります。</p>
</div>
@ -82,7 +82,7 @@ FRESULT f_lseek (
<span class="c">/* 3000バイト進める */</span>
res = f_lseek(fp, f_tell(fp) + 3000);
<span class="c">/* 2000バイト戻す (オーバーフローに注意) */</span>
<span class="c">/* 2000バイト戻す (ラップアラウンドに注意) */</span>
res = f_lseek(fp, f_tell(fp) - 2000);
</pre>
<pre>
@ -105,16 +105,16 @@ FRESULT f_lseek (
<pre>
<span class="c">/* 高速シーク機能を使う */</span>
DWORD lktbl[SZ_TBL]; <span class="c">/* リンク・マップ・テーブル格納バッファ */</span>
DWORD clmt[SZ_TBL]; <span class="c">/* リンク・マップ・テーブル格納バッファ */</span>
res = f_lseek(fp, ofs1); <span class="c">/* 通常シーク (オープン時、cltblはNULLに初期化される) */</span>
fp-&gt;cltbl = lktbl; <span class="c">/* 高速シーク機能の有効化 (cltbl != NULL) */</span>
lktbl[0] = SZ_TBL; <span class="c">/* 先頭要素に配列要素数をセット */</span>
fp-&gt;cltbl = clmt; <span class="c">/* 高速シーク機能の有効化 */</span>
clmt[0] = SZ_TBL; <span class="c">/* 先頭要素に配列要素数をセット */</span>
res = f_lseek(fp, CREATE_LINKMAP); <span class="c">/* CLMTの作成 */</span>
...
res = f_lseek(fp, ofs2); <span class="c">/* 以降、f_read/f_write/f_lseekでFATアクセス発生しない */</span>
res = f_lseek(fp, ofs2); <span class="c">/* 以降、f_read/f_write/f_lseekでFATアクセス発生しない */</span>
</pre>
</div>

View File

@ -16,7 +16,7 @@
<p>論理ドライブ上にFATボリュームを作成(フォーマット)します。</p>
<pre>
FRESULT f_mkfs (
BYTE <span class="arg">vol</span>, <span class="c">/* [IN] 論理ドライブ番号 */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] 論理ドライブ番号 */</span>
BYTE <span class="arg">sfd</span>, <span class="c">/* [IN] 区画作成方法 */</span>
UINT <span class="arg">au</span> <span class="c">/* [IN] クラス・タサイズ */</span>
);
@ -26,10 +26,10 @@ FRESULT f_mkfs (
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>vol</dt>
<dd>フォーマットする論理ドライブ。(0 <tt>_VOLUMES - 1</tt>)</dd>
<dt>path</dt>
<dd>フォーマット対象の論理ドライブを示す<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。ドライブ番号を含まない場合は、カレント・ドライブを意味します。</dd>
<dt>sfd</dt>
<dd>パーテーション形式。(0(FDISK) or 1(SFD))</dd>
<dd>パーテーション形式。(0(FDISK) または 1(SFD))</dd>
<dt>au</dt>
<dd>クラスタ・サイズをバイト単位で指定します。対象ドライブのセクタ・サイズのn倍(n = 1128で、2の累乗)でなければなりません。0を指定した場合、ボリュームのサイズに応じたデフォルトのクラスタ・サイズが選択されます。</dd>
</dl>
@ -51,7 +51,7 @@ FRESULT f_mkfs (
<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などで使用されます。FDISK形式では一台の物理ドライブ上に一つまたは複数の区画を作成することができます。管理情報はMBR(物理ドライブの先頭セクタ)に記録されます。SFD形式は単に何の分割も行わない形式で、ボリュームは物理ドライブの先頭セクタから開始します。SFD形式は、フロッピーディスク、マイクロドライブ、光学ディスク、およびその他スーパーフロッピーメディアで使用されています。</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

@ -16,8 +16,9 @@
<p>論理ドライブにファイル・システム・オブジェクトを登録・抹消します。</p>
<pre>
FRESULT f_mount (
BYTE <span class="arg">vol</span>, <span class="c">/* [IN] 論理ドライブ番号 */</span>
FATFS* <span class="arg">fatfs</span> <span class="c">/* [IN] ワーク・エリアへのポインタ */</span>
FATFS* <span class="arg">fatfs</span>, <span class="c">/* [IN] ファイル・システム・オブジェクト */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] 論理ドライブ番号 */</span>
BYTE <span class="arg">opt</span> <span class="c">/* [IN] オプション */</span>
);
</pre>
</div>
@ -25,10 +26,12 @@ FRESULT f_mount (
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>vol</dt>
<dd>論理ドライブ番号(0 <tt>_VOLUMES - 1</tt>)。</dd>
<dt>fatfs</dt>
<dd>登録するファイル・システム・オブジェクトへのポインタ。</dd>
<dt>path</dt>
<dd>対象となる論理ドライブの<a href="filename.html">パス名</a>を示すヌル文字'\0'終端の文字列へのポインタを指定します。ドライブ番号を含まない場合は、デフォルト・ドライブを指定したことになります。</dd>
<dt>opt</dt>
<dd>ファイル・システム・オブジェクトの登録と同時にマウント動作を行うかどうかを指定するフラグ。登録抹消のときは意味を持ちません。</dd>
</dl>
</div>
@ -36,20 +39,30 @@ FRESULT f_mount (
<h4>戻り値</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>
</p>
</div>
<div class="para desc">
<h4>解説</h4>
<p>FatFsモジュールでは、それぞれの論理ドライブにファイル・システム・オブジェクトというワーク・エリアが必要です。この関数は論理ドライブにそのワーク・エリアを登録したり抹消したりします。何らかのファイル関数を使用する前に、この関数でその論理ドライブのワーク・エリアを与えておかなければなりません。<tt class="arg">fatfs</tt>にヌル・ポインタを指定するとワーク・エリアの登録は抹消され、登録されていたワーク・エリアは破棄できます。操作対象のドライブに対して開かれているファイルやディレクトリがあった場合、それらは全て無効になります。</p>
<p>この関数は、物理ドライブの状態に関わらず常に成功します。関数内では下位レイヤへのアクセスは発生せず、指定されたワーク・エリアをクリア(無効化)し、そのアドレスを内部配列に登録するだけです。単に登録済みのワーク・エリアをクリアする目的にも使えます。ボリュームへのアクセス開始のとき次のうちいずれかまたは両方の条件が真のとき、実際のマウント動作(物理ドライブの初期化、FATボリュームの検索、BPBに従いワーク・エリアを初期化)が行われます。</p>
<p>FatFsモジュールでは、それぞれの論理ドライブに<em>ファイル・システム・オブジェクト</em>というワーク・エリアが必要です。この関数は論理ドライブにファイル・システム・オブジェクトを登録したり抹消したりします。何らかのファイル関数を使用する前に、この関数でその論理ドライブのファイル・システム・オブジェクトを与えておかなければなりません。<tt class="arg">fatfs</tt>にヌル・ポインタを指定すると、その論理ドライブのファイル・システム・オブジェクトの登録は抹消されるだけです。登録抹消されたファイル・システム・オブジェクトのメモリは解放できます。操作対象の論理ドライブ上に開かれているファイルやディレクトリがあった場合、それらは全て無効になります。この関数の内部処理は次のような順に行われます。</p>
<ol>
<li>対象の論理ドライブを<tt class="arg">path</tt>から得る。</li>
<li>既に登録されているファイル・システム・オブジェクトはクリアし、登録を解除する。</li>
<li><tt class="arg">fatfs</tt>が有効なポインタのときは、そのファイル・システム・オブジェクトをクリアし登録する。</li>
<li>マウント動作が指定されているときは、それを実行する。</li>
</ol>
<p><tt class="arg">opt</tt>に0を指定すると、マウント動作(物理ドライブの初期化、FATボリュームの検索、BPBを解析しファイル・システム・オブジェクトを初期化)は行われず、関数は物理ドライブの状態に関わらず常に成功します。関数内では下位レイヤへのアクセスは発生せず、指定されたファイル・システム・オブジェクトをクリア(無効化)し、そのアドレスを内部配列に登録するだけです。単に登録済みのファイル・システム・オブジェクトをクリアする目的にも使えます。そして、続いてボリュームへのアクセスが行われたとき次のうちいずれかでも真の場合は、実際のマウント動作が行われます。</p>
<ul>
<li>ファイル・システム・オブジェクトが未初期化(<tt>f_mount()</tt>による)</li>
<li>物理ドライブが未初期化(システム・リセットやメディアの取り外しによる)</li>
<li>ファイル・システム・オブジェクトがクリア(無効)状態(<tt>f_mount()</tt>の実行による)</li>
<li>物理ドライブが未初期化状態(システム・リセットやメディアの取り外しによる)</li>
</ul>
<p>下位レイヤがメディア交換の検出をサポートしないときは、アプリケーションはメディア交換のたびに<tt>f_mount()</tt>を実行する必要があります。</p>
<p><tt class="arg">opt</tt>に1を指定すると、登録に続いてマウント動作が行われます。マウントに失敗すると対応するエラーを返しますが、登録は有効なので続くボリュームへのアクセスで再びマウント動作が実行されます。<p>
<p>下位レイヤの実装上メディア交換の検出がサポートされない(<tt>disk_status()</tt>に反映されない)ときは、アプリケーションはメディア交換の後この関数でファイル・システム・オブジェクトを明示的にクリアして再マウントが正常に行えるようにする必要があります。</p>
</div>
@ -61,7 +74,7 @@ FRESULT f_mount (
<div class="para ref">
<h4>参照</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
<p><tt><a href="open.html">f_open</a></tt>, <tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -86,33 +86,64 @@ FRESULT f_open (
<div class="para use">
<h4>使用例(ファイル・コピー)</h4>
<h4>使用例</h4>
<pre>
void main (void)
<span class="c">/* テキストファイルを読み出して表示 */</span>
FATFS FatFs; <span class="c">/* 論理ドライブのワーク・エリア(ファイル・システム・オブジェクト) */</span>
int main (void)
{
FATFS fs[2]; <span class="c">/* 論理ドライブのワーク・エリア(ファイル・システム・オブジェクト) */</span>
FIL fil; <span class="c">/* ファイル・オブジェクト */</span>
char line[82]; <span class="c">/* 行バッファ */</span>
FRESULT fr; <span class="c">/* 戻り値 */</span>
<span class="c">/* デフォルト・ドライブにワークエリアを与える */</span>
f_mount(&amp;FatFs, "", 0);
<span class="c">/* テキスト・ファイルを開く */</span>
fr = f_open(&fil, "message.txt", FA_READ);
if (fr) return (int)fr;
<span class="c">/* 1行ずつ読み出して表示 */</span>
while (f_gets(line, sizeof line, &fil))
printf(line);
<span class="c">/* ファイルを閉じる */</span>
f_close(&fil);
return 0;
}
</pre>
<pre>
<span class="c">/* ドライブ1のファイル "file.bin" をドライブ0へコピー */</span>
int main (void)
{
FATFS fs[2]; <span class="c">/* 論理ドライブのワークエリア(ファイル・システム・オブジェクト) */</span>
FIL fsrc, fdst; <span class="c">/* ファイル・オブジェクト */</span>
BYTE buffer[4096]; <span class="c">/* file copy buffer */</span>
FRESULT res; <span class="c">/* FatFs function common result code */</span>
BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>
FRESULT fr; <span class="c">/* FatFs function common result code */</span>
UINT br, bw; <span class="c">/* File R/W count */</span>
<span class="c">/* ドライブ0,1にワーク・エリアを与える (常に成功する) */</span>
f_mount(0, &amp;fs[0]);
f_mount(1, &amp;fs[1]);
<span class="c">/* ドライブ0,1にワーク・エリアを与える */</span>
f_mount(&amp;fs[0], "0:", 0);
f_mount(&amp;fs[1], "1:", 0);
<span class="c">/* ドライブ1のソース・ファイルを開く */</span>
res = f_open(&amp;fsrc, "1:srcfile.dat", FA_OPEN_EXISTING | FA_READ);
if (res) die(res);
<span class="c">/* ドライブ1のコピー元ファイルを開く */</span>
res = f_open(&amp;fsrc, "1:file.dat", FA_OPEN_EXISTING | FA_READ);
if (fr) return (int)fr;
<span class="c">/* ドライブ0にデスティネーション・ファイルを作成する */</span>
res = f_open(&amp;fdst, "0:dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (res) die(res);
<span class="c">/* ドライブ0にコピー先ファイルを作成する */</span>
res = f_open(&amp;fdst, "0:file.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (fr) return (int)fr;
<span class="c">/* ソースからデスティネーションにコピーする */</span>
<span class="c">/* コピー元からコピー先にデータ転送する */</span>
for (;;) {
res = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br);
res = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* コピー元からから読み出す */</span>
if (res || br == 0) break; <span class="c">/* エラーかファイル終端 */</span>
res = f_write(&amp;fdst, buffer, br, &amp;bw);
res = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* それをコピー先に書き込む */</span>
if (res || bw &lt; br) break; <span class="c">/* エラーかディスク満杯 */</span>
}
@ -121,8 +152,10 @@ void main (void)
f_close(&amp;fdst);
<span class="c">/* ワーク・エリアを開放する */</span>
f_mount(0, NULL);
f_mount(1, NULL);
f_mount(NULL, "0:", 0);
f_mount(NULL, "1:", 0);
return (int)fr;
}
</pre>
</div>

View File

@ -16,7 +16,7 @@
<p>ディレクトリを開きます。</p>
<pre>
FRESULT f_opendir (
DIR* <span class="arg">dj</span>, <span class="c">/* [OUT] ディレクトリ・ブジェクト構造体へのポインタ */</span>
DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] ディレクトリ・ブジェクト構造体へのポインタ */</span>
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] ディレクトリ名へのポインタ */</span>
);
</pre>
@ -25,8 +25,8 @@ FRESULT f_opendir (
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>dj</dt>
<dd>初期化するディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
<dt>dp</dt>
<dd>空のディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
<dt>path</dt>
<dd>オープンするディレクトリの<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列へのポインタを指定します。</dd>
</dl>
@ -42,6 +42,7 @@ FRESULT f_opendir (
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
@ -53,7 +54,7 @@ FRESULT f_opendir (
<div class="para desc">
<h4>解説</h4>
<p>ディレクトリを開きます。正常終了したら、作成された<tt>DIR</tt>構造体を使ってこのディレクトリの項目を順次読み出せます。作成されたディレクトリ・オブジェクトは、不要になったら任意の時点で破棄できます。</p>
<p>ディレクトリを開きます。正常終了したら、作成された<tt>DIR</tt>構造体を使ってこのディレクトリの項目を順次読み出せます。</p>
</div>
@ -65,7 +66,7 @@ FRESULT f_opendir (
<div class="para ref">
<h4>参照</h4>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt></p>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -45,7 +45,7 @@ int f_printf (
<div class="para desc">
<h4>解説</h4>
<p>この関数は、<a href="putc.html"><tt>f_putc()</tt></a>および<a href="puts.html"><tt>f_puts()</tt></a>のラッパー関数です。書式制御機能はサブセットとなっていて、書式制御文字は次に示すものが使用可能です。</p>
<p>この関数は、<a href="putc.html"><tt>f_putc()</tt></a>および<a href="puts.html"><tt>f_puts()</tt></a>のラッパー関数です。書式制御機能はC標準ライブラリのサブセットとなっていて、書式制御文字は次に示すものが使用可能です。</p>
<ul>
<li>タイプ: <tt>c C s S d D u U x X b B</tt></li>
<li>精度指定: <tt>l L</tt></li>
@ -57,7 +57,7 @@ int f_printf (
<div class="para comp">
<h4>対応情報</h4>
<p><tt>_FS_READONLY == 0</tt>で、且つ<tt>_USE_STRFUNC</tt>が 1または 2のとき使用可能になります。2の時は、出力に含まれる<tt>'\n'</tt><tt>"\r\n"</tt>に展開されてファイルに書き込まれます。</p>
<p>APIにUnicodeが選択されている(<tt>_LFN_UNICODE</tt>が1)ときは、UTF-8エンコードでファイルに書き込みます。それ以外の時は無変換(1文字1バイト)で書き込みます。</p>
<p>APIにUnicodeが選択(<tt>_LFN_UNICODE</tt>が1)されているときは、<span class="arg">fmt</span>はUnicode文字列になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で書き込みます。</p>
</div>
@ -68,12 +68,12 @@ int f_printf (
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", 0xA3); <span class="c">/* "00a3" */</span>
f_printf(&amp;fil, "%08LX", 0x123ABC); <span class="c">/* "00123ABC" */</span>
f_printf(&amp;fil, "%04x", 0xAB); <span class="c">/* "00ab" */</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, "%-4s", "abc"); <span class="c">/* "abc " */</span>
f_printf(&amp;fil, "%4s", "abc"); <span class="c">/* " abc" */</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, "%c", 'a'); <span class="c">/* "a" */</span>
f_printf(&amp;fil, "%f", 10.0); <span class="c">/* 浮動小数点は未サポート */</span>
</pre>

View File

@ -35,8 +35,8 @@ int f_putc (
<div class="para ret">
<h4>戻り値</h4>
<p>文字が正常に書き込まれると書き込んだ文字数(1)が返されます。ディスクが満杯またはエラーにより書き込まれなかったときは<tt>EOF (-1)</tt>が返されます。</p>
<p>APIにUnicodeが選択されている(<tt>_LFN_UNICODE</tt>が1)ときは、UTF-8エンコードでファイルに書き込みます。それ以外の時は無変換(1文字1バイト)で書き込みます。</p>
<p>文字が正常に書き込まれると書き込んだ文字数が返されます。ディスクが満杯またはエラーにより書き込まれなかったときは<tt>EOF (-1)</tt>が返されます。</p>
<p>APIにUnicodeが選択(<tt>_LFN_UNICODE</tt>が1)されているときは、<span class="arg">chr</span>はUTF-16文字になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で書き込みます。</p>
</div>

View File

@ -36,13 +36,13 @@ int f_puts (
<div class="para ret">
<h4>戻り値</h4>
<p>文字列が正常に書き込まれると、書き込まれた文字数が返されます。ディスクが満杯またはエラーにより書き込みが中断されたときは<tt>EOF (-1)</tt>が返されます。</p>
<p>APIにUnicodeが選択されている(<tt>_LFN_UNICODE</tt>が1)ときは、UTF-8エンコードでファイルに書き込みます。それ以外の時は無変換(1文字1バイト)で書き込みます。</p>
<p>APIにUnicodeが選択(<tt>_LFN_UNICODE</tt>が1)されているときは、<span class="arg">str</span>はUTF-16文字列になりますが、ファイル上のエンコードは、<tt>_STRF_ENCODE</tt>オプションで選択できます。それ以外の時は無変換(1バイト/1文字)で書き込みます。</p>
</div>
<div class="para desc">
<h4>解説</h4>
<p>文字列をファイルに書き込みます。この関数は<a href="putc.html"><tt>f_putc()</tt></a>のラッパー関数です。</p>
<p>文字列をファイルに書き込みます。この関数は<a href="write.html"><tt>f_write()</tt></a>のラッパー関数です。</p>
</div>

View File

@ -53,7 +53,7 @@
<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

@ -16,7 +16,7 @@
<p>ディレクトリ項目を読み出します</p>
<pre>
FRESULT f_readdir (
DIR* <span class="arg">dj</span>, <span class="c">/* [IN] ディレクトリ・ブジェクト構造体へのポインタ */</span>
DIR* <span class="arg">dp</span>, <span class="c">/* [IN] ディレクトリ・ブジェクト構造体へのポインタ */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] ファイル情報構造体へのポインタ */</span>
);
</pre>
@ -25,7 +25,7 @@ FRESULT f_readdir (
<div class="para arg">
<h4>引数</h4>
<dl class="par">
<dt>dj</dt>
<dt>dp</dt>
<dd>有効なディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
<dt>fno</dt>
<dd>読み出したディレクトリ項目を格納するファイル情報構造体へのポインタを指定します。</dd>
@ -49,14 +49,14 @@ FRESULT f_readdir (
<div class="para desc">
<h4>解説</h4>
<p>ディレクトリの項目(ファイルとディレクトリ)を順次読み出します。この関数を繰り返し実行することによりそのディレクトリの全ての項目を読み出すことができます。全ての項目を読み出し、読み出す項目がもう無いときは、<tt>fname[]</tt>メンバにヌル文字列が返されます。ドット・エントリ("."、"..")は、相対パスが有効なとき(<tt>_FS_RPATH == 1</tt>)にのみ現れます。得られるファイル情報の詳細については <tt>FILINFO</tt>構造体を参照してください。<tt class="arg">fno</tt>にヌル・ポインタを指定すると、そのディレクトリのリード・インデックスを巻き戻します。</p>
<p>LFN機能が有効な時は、<tt>f_readdir()</tt>関数の呼び出しに先立って<tt>FILINFO</tt>構造体の<tt>lfname</tt><tt>lfsize</tt>が有効な値で初期化されていなければなりません。<tt>lfname</tt>はLFNを格納するバッファで、<tt>lfsize</tt>はそのバッファの要素数です。次の条件に一つでも該当する場合は、LFN格納バッファにヌル文字列が返されます。</p>
<p>ディレクトリの項目(ファイルとディレクトリ)を順次読み出します。この関数を繰り返し実行することによりそのディレクトリの全ての項目を読み出すことができます。全ての項目が読み出され、読み出す項目がもう無いときは、<tt>fname[]</tt>メンバにヌル文字列が返されます。ドット・エントリ("."、"..")は、相対パスが有効なとき(<tt>_FS_RPATH &gt;= 1</tt>)にのみ現れます。得られるファイル情報の詳細については <tt>FILINFO</tt>構造体を参照してください。<tt class="arg">fno</tt>にヌル・ポインタを指定すると、そのディレクトリのリード・インデックスを先頭に巻き戻します。</p>
<p>LFN機能が有効な時は、<tt>f_readdir()</tt>関数の呼び出しに先立って<tt>FILINFO</tt>構造体の<tt>lfname</tt><tt>lfsize</tt>が有効な値で初期化されていなければなりません。<tt>lfname</tt>はLFNを格納するバッファで、<tt>lfsize</tt>はそのバッファの要素数です。LFNを読み出す必要がないときは、<tt>lfname</tt>にヌル・ポインタをセットしてください。次の条件に一つでも該当する場合は、LFN格納バッファにヌル文字列が返されます。</p>
<ul>
<li>そのディレクトリ項目にLFNが存在しない。</li>
<li>ディレクトリ項目にLFN情報が存在しない。</li>
<li>LFNの長さに対してLFN格納バッファまたはLFN操作バッファのサイズが不十分。</li>
<li>LFNに現在のOEMコードに存在しない文字が含まれている。(Unicode APIではないとき)</li>
<li>LFNに現在のOEMコードに存在しない文字が含まれている。(非Unicode構成のとき)</li>
</ul>
<p>また、<tt>lfname</tt>にヌル・ポインタを指定した場合は、LFNに関して何も返されません。LFNが存在しないときは、<tt>fname[]</tt>メンバのSFNASCII英小文字が含まれる場合があります。</p>
<p>また、ディレクトリ項目にLFN情報が存在しない場合は、<tt>fname[]</tt>に英小文字が含まれる場合があります。</p>
</div>
@ -106,6 +106,7 @@ FRESULT scan_files (
printf("%s/%s\n", path, fn);
}
}
f_closedir(&amp;dir);
}
return res;
@ -116,7 +117,7 @@ FRESULT scan_files (
<div class="para ref">
<h4>参照</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="closedir.html">f_closedir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_rename</h2>
<p>オブジェクトの名前の変更または移動。</p>
<p>ファイルまたはサブ・ディレクトリの名前の変更または移動。</p>
<pre>
FRESULT f_rename (
const TCHAR* <span class="arg">old_name</span>, <span class="c">/* [IN] 古いオブジェクト名 */</span>
@ -26,7 +26,7 @@ FRESULT f_rename (
<h4>引数</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>
</dl>
@ -56,7 +56,7 @@ FRESULT f_rename (
<div class="para desc">
<h4>解説</h4>
<p>オブジェクトの名前を変更します。また、同時に別のディレクトリへの移動も可能です。<em>開かれているオブジェクトに対して使用してはなりません</em></p>
<p>ファイルまたはサブ・ディレクトリの名前を変更します。また、同時に別のディレクトリへの移動も可能です。<em>開かれているオブジェクトに対して使用してはなりません</em></p>
</div>

View File

@ -18,15 +18,18 @@
<span class="k">typedef</span> <span class="k">struct</span> {
FATFS* fs; <span class="c">/* 親ファイル・システム・オブジェクトへのポインタ */</span>
WORD id; <span class="c">/* 親ファイル・システム・オブジェクトのマウントID */</span>
WORD index; <span class="c">/* 次に読み出すディレクトリ・インデックス番号 */</span>
DWORD sclust; <span class="c">/* ディレクトリ開始クラスタ (0:ルート) */</span>
WORD index; <span class="c">/* 次に検索開始するディレクトリ・インデックス番号 */</span>
DWORD sclust; <span class="c">/* テーブル開始クラスタ (0:ルート) */</span>
DWORD clust; <span class="c">/* 現在のクラスタ番号 */</span>
DWORD sect; <span class="c">/* 現在のセクタ番号 */</span>
BYTE* dir; <span class="c">/* 現在のSFNエントリへのポインタ */</span>
BYTE* fn; <span class="c">/* SFNバッファへのポインタ (in/out) {file[8],ext[3],status[1]} */</span>
<span class="k">#if</span> _FS_LOCK
UINT lockid; <span class="c">/* ロックID */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _USE_LFN
WCHAR* lfn; <span class="c">/* LFNバッファへのポインタ */</span>
WORD lfn_idx; <span class="c">/* 最後にマッチしたLFNエントリのインデックス (0xFFFF:無効) */</span>
WORD lfn_idx; <span class="c">/* 最後にマッチしたLFNエントリの先頭インデックス (0xFFFF:無効) */</span>
<span class="k">#endif</span>
} DIR;
</pre>

View File

@ -19,10 +19,10 @@
<span class="k">typedef</span> <span class="k">struct</span> {
BYTE fs_type; <span class="c">/* FATタイプ */</span>
BYTE drv; <span class="c">/* 物理ドライブ番号 */</span>
BYTE csize; <span class="c">/* クラスタ当たりのセクタ数 */</span>
BYTE n_fats; <span class="c">/* FATの多重化数 */</span>
BYTE csize; <span class="c">/* クラスタ当たりのセクタ数 (1,2,4,8,...,128)*/</span>
BYTE n_fats; <span class="c">/* FATの多重化数 (1,2) */</span>
BYTE wflag; <span class="c">/* win[]ダーティ・フラグ */</span>
BYTE fsi_flag; <span class="c">/* fsinfoダーティ・フラグ */</span>
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
@ -32,18 +32,17 @@
_SYNC_t sobj; <span class="c">/* 同期オブジェクトID */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !_FS_READONLY
DWORD last_clust; <span class="c">/* 最後に割り当てられたクラスタ番号 */</span>
DWORD free_clust; <span class="c">/* 空きクラスタ数 */</span>
DWORD fsi_sector; <span class="c">/* fsinfoセクタ (FAT32) */</span>
DWORD last_clust; <span class="c">/* FSINFO: 最後に割り当てられたクラスタ番号 */</span>
DWORD free_clust; <span class="c">/* FSINFO: 空きクラスタ数 */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_RPATH
DWORD cdir; <span class="c">/* カレント・ディレクトリのクラスタ (0:ルート) */</span>
<span class="k">#endif</span>
DWORD n_fatent; <span class="c">/* FATのエントリ数 (== クラスタ数 + 2) */</span>
DWORD fsize; <span class="c">/* FAT 1個当たりのセクタ数 */</span>
DWORD n_fatent; <span class="c">/* FATエントリ数 (総クラスタ数 + 2) */</span>
DWORD fsize; <span class="c">/* FAT 1個のセクタ数 */</span>
DWORD volbase; <span class="c">/* ボリューム開始セクタ */</span>
DWORD fatbase; <span class="c">/* FAT領域開始セクタ */</span>
DWORD dirbase; <span class="c">/* ルート・ディレクトリ開始セクタ/クラスタ */</span>
DWORD dirbase; <span class="c">/* ルート・ディレクトリ領域開始セクタ(クラスタ) */</span>
DWORD database; <span class="c">/* データ領域開始セクタ */</span>
DWORD winsect; <span class="c">/* win[]に現れているセクタ番号 */</span>
BYTE win[_MAX_SS]; <span class="c">/* ディスク・アクセス・ウィンドウ */</span>

View File

@ -20,24 +20,24 @@
FATFS* fs; <span class="c">/* 親ファイル・システム・オブジェクトへのポインタ */</span>
WORD id; <span class="c">/* 親ファイル・システム・オブジェクトのマウントID */</span>
BYTE flag; <span class="c">/* ファイル・ステータス・フラグ */</span>
BYTE pad1;
BYTE err; <span class="c">/* エラー中断フラグ */</span>
DWORD fptr; <span class="c">/* ファイル読み書きポインタ (ファイル先頭からのバイト・オフセット) */</span>
DWORD fsize; <span class="c">/* ファイル・サイズ(バイト単位) */</span>
DWORD sclust; <span class="c">/* ファイル開始クラスタ番号 (set 0 if fsize==0) */</span>
DWORD sclust; <span class="c">/* ファイル開始クラスタ番号 (0:割り当て無し) */</span>
DWORD clust; <span class="c">/* 現在のクラスタ */</span>
DWORD dsect; <span class="c">/* 現在のデータ・セクタ */</span>
<span class="k">#if</span> _FS_READONLY == 0
<span class="k">#if</span> !_FS_READONLY
DWORD dir_sect; <span class="c">/* このファイルのディレクトリ・エントリのあるセクタ */</span>
BYTE* dir_ptr; <span class="c">/* このファイルのディレクトリへのポインタ */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _USE_FASTSEEK
DWORD* cltbl; <span class="c">/* ファイルのクラスタ・リンク情報へのポインタ (Nulled on file open) */</span>
DWORD* cltbl; <span class="c">/* ファイルのクラスタ・リンク情報へのポインタ (オープン時にNULLがセットされる) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> _FS_SHARE
<span class="k">#if</span> _FS_LOCK
UINT lockid; <span class="c">/* ファイル・ロックID */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !_FS_TINY
BYTE buf[_MAX_SS]; <span class="c">/* データ転送バッファ */</span>
BYTE buf[_MAX_SS]; <span class="c">/* ファイル・プライベート・データ転送バッファ */</span>
<span class="k">#endif</span>
} FIL;
</pre>

View File

@ -62,7 +62,7 @@
<dt>lfname</dt>
<dd>返される長いファイル名を格納するバッファへのポインタ。この構造体を使用する前にアプリケーションにより初期化されなければなりません。このメンバにNULLが設定されるとLFNは返されません。非LFN構成のときはこのメンバは存在しません。</dd>
<dt>lfsize</dt>
<dd>長いファイル名を格納するバッファのサイズ(文字数)。この構造体を使用する前にアプリケーションにより初期化されなければなりません。非LFN構成のときはこのメンバは存在しません。</dd>
<dd>長いファイル名を格納するバッファのサイズ(要素数)。この構造体を使用する前にアプリケーションにより初期化されなければなりません。非LFN構成のときはこのメンバは存在しません。</dd>
</dl>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -13,9 +13,10 @@
<div class="para func">
<h2>f_stat</h2>
<p>ファイルまたはサブ・ディレクトリの存在を調べ、またその情報を取得します。</p>
<pre>
FRESULT f_stat (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] ファイルまたはディレクトリ名へのポインタ */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] オブジェクト名へのポインタ */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] ファイル情報構造体へのポインタ */</span>
);
</pre>
@ -25,9 +26,9 @@ FRESULT f_stat (
<h4>引数</h4>
<dl class="par">
<dt>path</dt>
<dd>情報を得るファイルまたはディレクトリ名を示すヌル文字<tt>'\0'</tt>終端の文字列を指すポインタを指定します。</dd>
<dd>チェックするオブジェクト名を示すヌル文字<tt>'\0'</tt>終端の文字列を指すポインタを指定します。</dd>
<dt>fno</dt>
<dd>読み出したファイル情報を格納するファイル情報構造体へのポインタを指定します。</dd>
<dd>オブジェクトが存在したときにその情報を格納するファイル情報構造体へのポインタを指定します。この情報が不要なときはヌル・ポインタを指定してください</dd>
</dl>
</div>
@ -53,7 +54,7 @@ FRESULT f_stat (
<div class="para desc">
<h4>解説</h4>
<p>指定されたファイルまたはディレクトリに関する情報(サイズ、タイムスタンプおよび属性)を得ます。ディレクトリのサイズ情報は無効で常に0です。</p>
<p>指定されたファイルまたはサブ・ディレクトリの存在を調べ、それ関する情報(サイズ、タイムスタンプおよび属性)を得ます。存在する場合は<tt>FR_OK</tt>が帰り、ファイル情報構造体にその情報がストアされます。存在しない場合は、<tt>FR_NO_FILE</tt>が帰ります。</p>
</div>

View File

@ -45,7 +45,8 @@ FRESULT f_sync (
<div class="para desc">
<h4>‰ð<EFBFBD>à</h4>
<p>この関数は<tt>f_close()</tt>と同じ処理を実行しますが、ファイルは引き続き開かれたままになり、読み書きを続行できます。ロギングなど、書き込みモードで長時間ファイルが開かれているアプリケーションにおいて、定期的または区切りの良いところでこの関数を使用することにより、不意の電源断やメディアの取り外しにより失われるデータを最小にすることができます。実際のところ、<tt>f_close()</tt>内ではこの関数を呼び出した後ファイル・オブジェクトを無効化しているだけなので、<tt>f_close()</tt>直前の<tt>f_sync()</tt>は意味がありません。</p>
<p>この関数は<tt>f_close()</tt>と同じ処理を実行しますが、ファイルは引き続き開かれたままになり、読み書きを続行できます。ロギングなど、書き込みモードで長時間ファイルが開かれているアプリケーションにおいて、定期的または区切りの良いところでこの関数を使用することにより、不意の電源断やメディアの取り外しにより失われるデータを最小にすることができます。この背景については、<a href="appnote.html#critical">アプリケーション・ノート</a>も参照してください。</p>
<p>実際のところ、<tt>f_close()</tt>内ではこの関数を呼び出した後ファイル・オブジェクトを無効化しているだけなので、<tt>f_close()</tt>直前の<tt>f_sync()</tt>は意味がありません。</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_unlink</h2>
<p>ファイルまたはディレクトリを削除します。</p>
<p>ファイルまたはサブ・ディレクトリを削除します。</p>
<pre>
FRESULT f_unlink (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] オブジェクト名へのポインタ */</span>
@ -54,11 +54,11 @@ FRESULT f_unlink (
<div class="para desc">
<h4>解説</h4>
<p>削除対象のオブジェクが次の条件に当てはまる場合、そのアクセスは拒否され関数は失敗します。
<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

@ -13,7 +13,7 @@
<div class="para func">
<h2>f_utime</h2>
<p>オブジェクトのタイムスタンプを変更します。</p>
<p>ファイルまたはサブ・ディレクトリのタイムスタンプを変更します。</p>
<pre>
FRESULT f_utime (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] オブジェクト名へのポインタ */</span>
@ -26,7 +26,7 @@ FRESULT f_utime (
<h4>引数</h4>
<dl class="par">
<dt>path</dt>
<dd>変更対象のファイルまたはディレクトリ<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列を指定します。</dd>
<dd>変更対象のオブジェクト<a href="filename.html">パス名</a>を示すヌル文字<tt>'\0'</tt>終端の文字列を指定します。</dd>
<dt>fno</dt>
<dd>設定する日付と時間を<tt>fdate</tt><tt>ftime</tt>メンバに設定された<tt>FILINFO</tt>構造体へのポインタ。他のメンバはこの関数では意味を持ちません。</dd>
</dl>

View File

@ -1,3 +1,14 @@
R0.10, Oct 02,'13
Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
Added forced mount feature with changes of f_mount().
Improved behavior of volume auto detection.
Improved write throughput of f_puts() and f_printf().
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.
R0.09b, Jan 24, 2013
Added f_getlabel() and f_setlabel(). (_USE_LABEL = 1)

View File

@ -1,4 +1,4 @@
FatFs Module Source Files R0.09b (C)ChaN, 2013
FatFs Module Source Files R0.10 (C)ChaN, 2013
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) 2012, ChaN, all right reserved.
Copyright (C) 2013, 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
@ -136,3 +136,12 @@ REVISION HISTORY
Jan 23,'13 R0.09b Added f_getlabel() and f_setlabel(). (_USE_LABEL == 1)
Oct 02,'13 R0.10 Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
Added forced mount feature with changes of f_mount().
Improved behavior of volume auto detection.
Improved write throughput of f_puts() and f_printf().
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.

View File

@ -102,7 +102,7 @@ DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..128) */
UINT count /* Number of sectors to read (1..128) */
)
{
DRESULT res;
@ -150,7 +150,7 @@ DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..128) */
UINT count /* Number of sectors to write (1..128) */
)
{
DRESULT res;

View File

@ -34,8 +34,8 @@ typedef enum {
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, BYTE count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, BYTE 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);

1285
src/ff.c

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.09b (C)ChaN, 2013
/ FatFs - FAT file system module include file R0.10 (C)ChaN, 2013
/----------------------------------------------------------------------------/
/ 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
@ -15,7 +15,7 @@
/----------------------------------------------------------------------------*/
#ifndef _FATFS
#define _FATFS 82786 /* Revision ID */
#define _FATFS 80960 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@ -43,7 +43,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
#else /* Single partition configuration */
#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
#define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */
#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
#endif
@ -78,9 +78,9 @@ typedef struct {
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
BYTE drv; /* Physical drive number */
BYTE csize; /* Sectors per cluster (1,2,4...128) */
BYTE n_fats; /* Number of FAT copies (1,2) */
BYTE wflag; /* win[] dirty flag (1:must be written back) */
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
BYTE n_fats; /* Number of FAT copies (1 or 2) */
BYTE wflag; /* win[] flag (b0:dirty) */
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
@ -92,7 +92,6 @@ typedef struct {
#if !_FS_READONLY
DWORD last_clust; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */
DWORD fsi_sector; /* fsinfo sector (FAT32) */
#endif
#if _FS_RPATH
DWORD cdir; /* Current directory start cluster (0:root) */
@ -104,7 +103,7 @@ typedef struct {
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
DWORD database; /* Data start sector */
DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS;
@ -115,8 +114,8 @@ typedef struct {
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
WORD id; /* Owner file system mount ID (**do not change order**) */
BYTE flag; /* File status flags */
BYTE pad1;
DWORD fptr; /* File read/write pointer (0ed on file open) */
BYTE err; /* Abort flag (error code) */
DWORD fptr; /* File read/write pointer (Zeroed on file open) */
DWORD fsize; /* File size */
DWORD sclust; /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */
DWORD clust; /* Current cluster of fpter */
@ -126,7 +125,7 @@ typedef struct {
BYTE* dir_ptr; /* Pointer to the directory entry in the window */
#endif
#if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
#endif
#if _FS_LOCK
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
@ -149,6 +148,9 @@ typedef struct {
DWORD sect; /* Current sector */
BYTE* dir; /* Pointer to the current SFN entry in the win[] */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
#if _FS_LOCK
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
#endif
#if _USE_LFN
WCHAR* lfn; /* Pointer to the LFN working buffer */
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
@ -203,30 +205,31 @@ typedef enum {
/*--------------------------------------------------------------*/
/* FatFs module application interface */
FRESULT f_mount (BYTE vol, FATFS* fs); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
FRESULT f_close (FIL* fp); /* Close an open file object */
FRESULT f_opendir (DIR* dj, const TCHAR* path); /* Open an existing directory */
FRESULT f_readdir (DIR* dj, FILINFO* fno); /* Read a directory item */
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
FRESULT f_truncate (FIL* fp); /* Truncate file */
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
FRESULT f_closedir (DIR* dp); /* Close an open directory */
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
FRESULT f_mkdir (const TCHAR* path); /* Create a new directory */
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask); /* Change attribute of the file/dir */
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_chdrive (BYTE drv); /* Change current drive */
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* sn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
FRESULT f_mkfs (BYTE vol, BYTE sfd, UINT au); /* Create a file system on the drive */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
@ -234,7 +237,7 @@ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
@ -282,7 +285,6 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#define FA__ERROR 0x80
#if !_FS_READONLY
#define FA_WRITE 0x02

View File

@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.09b (C)ChaN, 2013
/ 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
@ -7,7 +7,7 @@
/
/----------------------------------------------------------------------------*/
#ifndef _FFCONF
#define _FFCONF 82786 /* Revision ID */
#define _FFCONF 80960 /* Revision ID */
/*---------------------------------------------------------------------------/
@ -22,18 +22,18 @@
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
/ f_truncate and useless f_getfree. */
/ writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
/ f_rename(), f_truncate() and useless f_getfree(). */
#define _FS_MINIMIZE 0 /* 0 to 3 */
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
/* The _FS_MINIMIZE option defines minimization level to remove API functions.
/
/ 0: Full function.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
/ are removed.
/ 2: f_opendir and f_readdir are removed in addition to 1.
/ 3: f_lseek is removed in addition to 2. */
/ 0: All basic functions are enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
/ f_truncate() and f_rename() function are removed.
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/ 3: f_lseek() function is removed in addition to 2. */
#define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
@ -41,7 +41,7 @@
#define _USE_MKFS 0 /* 0:Disable or 1:Enable */
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
/* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
#define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
@ -53,7 +53,7 @@
#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
/* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
/*---------------------------------------------------------------------------/
@ -89,65 +89,84 @@
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
/ 1 - ASCII only (Valid for 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 support.
/* The _USE_LFN option switches the LFN feature.
/
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 0: Disable LFN feature. _MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
/ Unicode handling functions ff_convert() and ff_wtoupper() must be added
/ to the project. When enable to use heap, memory control functions
/ ff_memalloc() and ff_memfree() must be added to the project. */
/ To 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
/ buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
/ to the project. */
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
/* To switch the character code set on FatFs API to Unicode,
/ enable LFN feature and set _LFN_UNICODE to 1. */
/* To switch the character encoding on the FatFs API to Unicode, enable LFN feature
/ and set _LFN_UNICODE to 1. */
#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. */
#define _FS_RPATH 0 /* 0 to 2 */
/* The _FS_RPATH option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
/ 1: Enable relative path. f_chdrive() and f_chdir() are available.
/ 2: f_getcwd() is available in addition to 1.
/ 1: Enable relative path. f_chdrive() and f_chdir() function are available.
/ 2: f_getcwd() function is available in addition to 1.
/
/ Note that output of the f_readdir fnction is affected by this option. */
/ Note that output of the f_readdir() fnction is affected by this option. */
/*---------------------------------------------------------------------------/
/ Physical Drive Configurations
/ Drive/Volume Configurations
/----------------------------------------------------------------------------*/
#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
#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 implememted to the disk_ioctl function. */
#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[]. */
#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 _USE_ERASE 0 /* 0:Disable or 1:Enable */
/* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
/ should be added to the disk_ioctl functio. */
/* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
/ 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.
/
/ 0: Load all informations in the FSINFO if available.
/ 1: Do not trust free cluster count in the FSINFO.
*/
@ -156,16 +175,17 @@
/----------------------------------------------------------------------------*/
#define _WORD_ACCESS 0 /* 0 or 1 */
/* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS
/ option defines which access method is used to the word data on the FAT volume.
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access.
/ 1: Word access. Do not choose this unless following condition is met.
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ When the byte order on the memory is big-endian or address miss-aligned word
/ access results incorrect behavior, the _WORD_ACCESS must be set to 0.
/ If it is not the case, the value can also be set to 1 to improve the
/ performance and code size.
/ * 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.
*/
@ -176,11 +196,11 @@
#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.. */
/* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module.
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
/
/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
/ 1: Enable reentrancy. Also user provided synchronization handlers,
/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
/ 0: Disable re-entrancy. _SYNC_t and _FS_TIMEOUT have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/ function must be added to the project. */

View File

@ -2,8 +2,8 @@
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/
#ifndef _INTEGER
#define _INTEGER
#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifdef _WIN32 /* FatFs development platform */
@ -12,24 +12,20 @@
#else /* Embedded platform */
/* These types must be 16-bit, 32-bit or larger integer */
typedef int INT;
typedef unsigned int UINT;
/* These types must be 8-bit integer */
typedef char CHAR;
typedef unsigned char UCHAR;
/* This type MUST be 8 bit */
typedef unsigned char BYTE;
/* These types must be 16-bit integer */
/* These types MUST be 16 bit */
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types must be 32-bit integer */
/* These types MUST be 16 bit or 32 bit */
typedef int INT;
typedef unsigned int UINT;
/* These types MUST be 32 bit */
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
#endif