fatfs v0.08a Aug 16,2010:

- Added f_getcwd(). (_FS_RPATH = 2)
- Added sector erase feature. (_USE_ERASE)
- Moved file lock semaphore table from fs object to the bss.
- Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
- Fixed f_mkfs() creates wrong FAT32 volume.
This commit is contained in:
savelij13 2025-09-11 09:43:16 +03:00
parent 46155916b1
commit 625f3adcbb
55 changed files with 865 additions and 869 deletions

View File

@ -4,15 +4,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="description" content="Open souece FAT file system module for embedded projects">
<link rel="start" title="Site Top" href="../../">
<link rel="up" title="Freewares" href="../../fsw_e.html">
<link rel="alternate" hreflang="ja" title="Japanese version" href="00index_j.html">
<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
<title>ELM - FAT File System Module</title>
<title>ELM - FatFs Generic File System Module</title>
</head>
<body>
<h1>FAT File System Module</h1>
<h1>FatFs Generic File System Module</h1>
<hr>
<div class="abst">
@ -28,7 +26,7 @@
<ul>
<li>Multiple volumes (physical drives and partitions).</li>
<li>Multiple ANSI/OEM code pages including DBCS.</li>
<li>Long file name support in SBCS/DBCS or Unicode.</li>
<li>Long file name support in ANSI/OEM or Unicode.</li>
<li>RTOS support.</li>
<li>Multiple sector size support.</li>
<li>Read-only, minimized API, I/O buffer and etc...</li>
@ -42,27 +40,28 @@
<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/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 R/W 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/opendir.html">f_opendir</a> - Open a 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/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/mkfs.html">f_mkfs</a> - Create a File System on the Drive</li>
<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/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 zize</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/opendir.html">f_opendir</a> - Open a 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/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/mkfs.html">f_mkfs</a> - Create a file system on the drive</li>
<li><a href="en/forward.html">f_forward</a> - Forward file data to the stream directly</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/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>
@ -90,8 +89,9 @@
<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">May 15, 2010</span></li>
<li><a href="http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/">ARM-Projects by Martin THOMAS</a> (examples for LPC2000, AT91SAM and STM32)</li>
<li>Read first: <a href="en/appnote.html">FatFs module application note</a></li>
<li>Download: <a href="ffsample.zip">FatFs sample projects</a> (AVR, PIC24, LPC2000, H8/300H, SH-2A, V850ES and Win32)</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/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>

View File

@ -4,15 +4,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="description" content="組み込みシステム向けFATファイル・システム">
<link rel="start" title="Site Top" href="../../index_j.html">
<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 - 汎用FATファイルシステム・モジュール</title>
<title>ELM - FatFs 汎用FATファイルシステム・モジュール</title>
</head>
<body>
<h1>FATファイルシステム・モジュール</h1>
<h1>FatFs 汎用FATファイルシステム・モジュール</h1>
<hr>
<div class="abst">
@ -44,14 +42,14 @@
<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>
<li><a href="ja/read.html">f_read</a> - ファイルの読み出し</li>
<li><a href="ja/write.html">f_write</a> - ファイルの書き込み</li>
<li><a href="ja/lseek.html">f_lseek</a> - R/Wポインタの移動, ファイル・サイズの拡張</li>
<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/opendir.html">f_opendir</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/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>
@ -61,8 +59,9 @@
<li><a href="ja/mkfs.html">f_mkfs</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/forward.html">f_forward</a> - ファイル・データをストリーム関数に直接転送する</li>
<li><a href="ja/gets.html">f_gets</a> - 文字列の読み込み</li>
<li><a href="ja/getcwd.html">f_getcwd</a> - カレント・ディレクトリの取得</li>
<li><a href="ja/forward.html">f_forward</a> - ファイル・データをストリーム関数に転送</li>
<li><a href="ja/gets.html">f_gets</a> - 文字列の読み出し</li>
<li><a href="ja/putc.html">f_putc</a> - 文字の書き込み</li>
<li><a href="ja/puts.html">f_puts</a> - 文字列の書き込み</li>
<li><a href="ja/printf.html">f_printf</a> - 書式化文字列の書き込み</li>
@ -89,8 +88,9 @@
<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">2010. 5. 15</span></li>
<li><a href="http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/">ARM-Projects by Martin THOMAS</a> (examples for LPC2000, AT91SAM and STM32)</li>
<li>最初に読め: <a href="ja/appnote.html">FatFsモジュール・アプリケーション・ート</a></li>
<li>ダウンロード: <a href="ffsample.zip">サンプル・プロジェクト</a> (AVR, PIC24, LPC2000, H8/300H, SH-2A, V850ES and Win32)</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> (FATの理解・実装に必要な唯一のリファレンス)</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>

View File

@ -46,9 +46,9 @@ small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border-style: solid; border-width: 2px; border-color: black; }
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
td {background-color: white; border-style: solid; border-width: 1px; border-color: black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-family: monospace;}
table.lst2 td {font-family: monospace;}
table caption {font-family: sans-serif; font-weight: bold;}

View File

@ -49,9 +49,9 @@ small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border-style: solid; border-width: 2px; border-color: black; letter-spacing: 0;}
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; letter-spacing: 0;}
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top;}
td {background-color: white; border-style: solid; border-width: 1px; border-color: black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-family: monospace; white-space: nowrap;}
table.lst2 td {font-family: monospace; white-space: nowrap;}
table caption {font-family: sans-serif; font-weight: bold;}

View File

@ -11,16 +11,30 @@
<body>
<h1>FatFs Module Application Note</h1>
<ol class="toc">
<li><a href="#port">How to Port</a></li>
<li><a href="#limits">Limits</a></li>
<li><a href="#memory">Memory Usage</a></li>
<li><a href="#reduce">Module Size Reduction</a></li>
<li><a href="#lfn">Long File Name</a></li>
<li><a href="#unicode">Unicode API</a></li>
<li><a href="#reentrant">Re-entrancy</a></li>
<li><a href="#dup">Duplicated File Access</a></li>
<li><a href="#fs1">Performance Effective File Access</a></li>
<li><a href="#fs2">Considerations on Flash Memory Media</a></li>
<li><a href="#critical">Critical Section</a></li>
<li><a href="#license">About FatFs License</a></li>
</ol>
<hr>
<div class="para">
<h3>How to port</h3>
<div class="para" id="port">
<h3>How to Port</h3>
<h4>Basic considerations</h4>
<p>The FatFs module is assuming following conditions on portability.</p>
<ul>
<li>ANSI C<br>
The FatFs module is a middleware which is written in ANSI C. There is no platform dependence, so long as the compiler is in compliance with ANSI C.</li>
The FatFs module is a middleware which is written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with ANSI C.</li>
<li>Size of integer types<br>
The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is 16 or 32 bit. These correspondence are defined in integer.h. This will not be a problem on most compilers. When any conflict with existing definitions is occured, you must resolve it with care.</li>
</ul>
@ -29,7 +43,7 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<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. All defined functions are not that always required. For example, disk write function is not required in read-only configuration. Following table shows which function is required depends on configuration options.</p>
<table class="lst2">
<tr><th>Function</th><th>Required when:</th><th>Note</th></tr>
<tr><td>disk_initialize</td><td>Always</td><td rowspan="9">Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
<tr><td>disk_initialize</td><td>Always</td><td rowspan="10">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
<tr><td>disk_status</td><td>Always</td></tr>
<tr><td>disk_read</td><td>Always</td></tr>
<tr><td>disk_write</td><td>_FS_READONLY == 0</td></tr>
@ -37,10 +51,11 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
<tr><td>disk_ioctl (GET_SECTOR_COUNT)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS &gt;= 1024</td></tr>
<tr><td>disk_ioctl (GET_BLOCK_SIZE)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (CTRL_ERASE_SECTOR)</td><td>_USE_ERASE == 1</td></tr>
<tr><td>get_fattime</td><td>_FS_READONLY == 0</td></tr>
<tr><td>ff_convert</td><td>_USE_LFN &gt;= 1</td><td rowspan="2">Available in option/cc*.c.</td></tr>
<tr><td>ff_convert</td><td>_USE_LFN &gt;= 1</td><td rowspan="2">Unicode support functions.<br>Available in option/cc*.c.</td></tr>
<tr><td>ff_wtoupper</td><td>_USE_LFN &gt;= 1</td></tr>
<tr><td>ff_cre_syncobj</td><td>_FS_REENTRANT == 1</td><td rowspan="6">Samples available in option/syscall.c.</td></tr>
<tr><td>ff_cre_syncobj</td><td>_FS_REENTRANT == 1</td><td rowspan="6">O/S dependent functions.<br>Samples available in option/syscall.c.</td></tr>
<tr><td>ff_del_syncobj</td><td>_FS_REENTRANT == 1</td></tr>
<tr><td>ff_req_grant</td><td>_FS_REENTRANT == 1</td></tr>
<tr><td>ff_rel_grant</td><td>_FS_REENTRANT == 1</td></tr>
@ -49,7 +64,7 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
</table>
</div>
<div class="para">
<div class="para" id="limits">
<h3>Limits</h3>
<ul>
<li>FAT sub-types: FAT12, FAT16 and FAT32.</li>
@ -62,16 +77,16 @@ The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is
</ul>
</div>
<div class="para">
<h3>Memory Usage (R0.08)</h3>
<div class="para" id="memory">
<h3>Memory Usage (R0.08a)</h3>
<table class="lst2">
<tr><th></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>V850ES</th><th>SH-2A</th><th>ARM7</th><th>x86</th></tr>
<tr><td>Compiler</td><td>WinAVR(gcc)</td><td>CH38</td><td>C30(gcc)</td><td>CA850</td><td>SHC</td><td>WinARM(gcc)</td><td>VC6</td></tr>
<tr><td>_WORD_ACCESS</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td></tr>
<tr class="lst3"><td>text (Full, R/W)</td><td>12700</td><td>10686</td><td>11376</td><td>7730</td><td>8592</td><td>10520</td><td>7545</td></tr>
<tr> <td>text (Min, R/W)</td><td>8386</td><td>6980</td><td>7395</td><td>4930</td><td>5600</td><td>6636</td><td>4923</td></tr>
<tr><td>text (Full, R/O)</td><td>6012</td><td>4874</td><td>5250</td><td>3556</td><td>3848</td><td>4656</td><td>3450</td></tr>
<tr> <td>text (Min, R/O)</td><td>4384</td><td>3774</td><td>3939</td><td>2684</td><td>2996</td><td>3416</td><td>2664</td></tr>
<tr class="lst3"><td>text (Full, R/W)</td><td>12646</td><td>10686</td><td>11430</td><td>7732</td><td>8752</td><td>10560</td><td>7545</td></tr>
<tr> <td>text (Min, R/W)</td><td>8306</td><td>6986</td><td>7413</td><td>4938</td><td>5576</td><td>6680</td><td>4923</td></tr>
<tr><td>text (Full, R/O)</td><td>5960</td><td>4876</td><td>5250</td><td>3554</td><td>3804</td><td>4688</td><td>3450</td></tr>
<tr> <td>text (Min, R/O)</td><td>4366</td><td>3770</td><td>3939</td><td>2684</td><td>2940</td><td>3452</td><td>2664</td></tr>
<tr><td>bss</td><td>D*2 + 2</td><td>D*4 + 2</td><td>D*2 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td></tr>
<tr><td>Work area<br>(_FS_TINY == 0)</td><td>D*560 +<br>F*544</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*544</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>D*560 +<br>F*32</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*32</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td></tr>
@ -94,41 +109,42 @@ _FS_SHARE 0 (Disable shareing control)
</pre>
</div>
<div class="para">
<div class="para" id="reduce">
<h3>Module Size Reduction</h3>
<p>Follwing table shows which function is removed by configuration options for the module size reduction.</p>
<p>Follwing table shows which API function is removed by configuration options for the module size reduction.</p>
<table class="lst2">
<tr><td rowspan="2">Function</td><td colspan="3">_FS_MINIMIZE</td><td>_FS_READONLY</td><td>_USE_STRFUNC</td><td>_FS_RPATH</td><td>_USE_MKFS</td><td>_USE_FORWARD</td></tr>
<tr><td>1</td><td>2</td><td>3</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr class="lst3"><td>f_mount</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_open</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_close</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_read</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_write</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_sync</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_lseek</td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_opendir</td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_readdir</td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_stat</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_getfree</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_truncate</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_unlink</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_mkdir</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_chmod</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_utime</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_rename</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_chdir</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>f_chdrive</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>f_mkfs</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td>x</td><td></td></tr>
<tr><td>f_forward</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>x</td></tr>
<tr><td>f_putc</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_puts</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_printf</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_gets</td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td></tr>
<tr><td rowspan="2">Function</td><td colspan="4">_FS_MINIMIZE</td><td colspan="2">_FS_READONLY</td><td colspan="2">_USE_STRFUNC</td><td colspan="3">_FS_RPATH</td><td colspan="2">_USE_MKFS</td><td colspan="2">_USE_FORWARD</td></tr>
<tr><td>0</td><td>1</td><td>2</td><td>3</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>
<tr class="lst3"><td>f_mount</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_open</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_close</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_read</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_write</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></tr>
<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></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></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></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></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></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></tr>
<tr><td>f_truncate</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></tr>
<tr><td>f_unlink</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></tr>
<tr><td>f_mkdir</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></tr>
<tr><td>f_chmod</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></tr>
<tr><td>f_utime</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></tr>
<tr><td>f_rename</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></tr>
<tr><td>f_chdir</td><td></td><td></td><td></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></tr>
<tr><td>f_chdrive</td><td></td><td></td><td></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></tr>
<tr><td>f_getcwd</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_mkfs</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>x</td><td></td><td></td><td></td></tr>
<tr><td>f_forward</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>x</td><td></td></tr>
<tr><td>f_putc</td><td></td><td></td><td></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></tr>
<tr><td>f_puts</td><td></td><td></td><td></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></tr>
<tr><td>f_printf</td><td></td><td></td><td></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></tr>
<tr><td>f_gets</td><td></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></tr>
</table>
</div>
<div class="para">
<div class="para" id="lfn">
<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">
@ -144,27 +160,27 @@ _FS_SHARE 0 (Disable shareing control)
<p>Note that the LFN feature on the FAT file system is a patent of Microsoft Corporation. When enable it on the commercial products, a license from Microsoft may be required depends on the final destination.</p>
</div>
<div class="para">
<div class="para" id="unicode">
<h3>Unicode API</h3>
<p>FatFs supports ANSI/OEM code set on the API in default but FatFs can also switch the code set to Unicode. For more information, refer to the description in the <a href="filename.html">file name</a>.</p>
</div>
<div class="para">
<div class="para" id="reentrant">
<h3>Re-entrancy</h3>
<p>The file operations to the different volume can always work simultaneously regardless of re-entrancy setting. The re-entrancy to the same volume can be enabled with <tt>_FS_REENTRANT</tt> option. In this case, also the OS dependent synchronization object control functions, ff_cre_syncobj, ff_del_syncobj, ff_req_grant and ff_rel_grant must be added to the project.</p>
<p>The file operations to the different volume is always re-entrant ant 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, ff_cre_syncobj, ff_del_syncobj, ff_req_grant and ff_rel_grant 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 access is blocked until the 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 f_mount and f_mkfs 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. There is no assumtion on the re-entrancy of low level disk I/O module.</p>
</div>
<div class="para">
<h3>Duplicated file access</h3>
<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, otherwise the FAT structure on the volume can be collapted. Also current directory must not be deleted.</p>
<p>The file shareing control can also be available when <tt>_FS_SHARE</tt> is set to 1 or grater. 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>.</p>
</div>
<div class="para">
<h3>Performance effective file access</h3>
<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 disk is transferred in following sequence by f_read function.</p>
<p>Figure 1. Sector miss-aligned read (short)<br>
<img src="../img/f1.png" width="490" height="73" alt="">
@ -180,7 +196,20 @@ _FS_SHARE 0 (Disable shareing control)
<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>
</div>
<div class="para">
<div class="para" id="fs2">
<h3>Considerations on Flash Memory Media</h3>
<p>To maximize the write performance of flash memory media, such as SDC and CFC, it must be controlled in consideration of its characteristitcs.</p>
<h4>Using Mutiple-Sector Write</h4>
<div class="rset">
Figure 6. Comparison between Multiple/Single Sector Write<br>
<img src="../img/f6.png" width="630" height="148" alt="fig.6">
</div>
<p>The write throughput of the flash memory media becomes the worst at single sector write and it increases proportional to the number of sectors per a write transaction. This effect more appers at more fast bus clock and its ratio often becomes grater than ten. The number of write transaction also affects the life time of the media. Therefore the application program should write the data in large block as possible. The ideal block size is cluster size or power of 2 bytes and the byte offset should be aligned to the block. Of course all layers between the application and the media must support multiple sector write feature, however most of open-source disk drivers lack it. Do not split a multiple sector write request into single sector writes or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write.</p>
<h4>Forcing Memory Erase</h4>
<p>When remove a file via f_remove function, the data clusters occupied by the file are maeked 'free' on the FAT. But the data sectors containing the file data are not that applied any process so that the file data left occupies a part of the media as live blocks. If the file data is forced erased on removing the file, the number of free blocks on the media will be increased. This may skip internal block erase operation to the data block on next write. As the result the write performance might be improved. To enable this feature, set <tt>_USE_ERASE</tt> to 1. Note that this is a feature with expectation of internal process of the flash memory media. It may not always effective and f_remove function will take a time on removing a large file.</p>
</div>
<div class="para" id="critical">
<h3>Critical Section</h3>
<p>If a write operation to the FAT file system is interrupted due to any accidental failure, such as sudden blackout, incorrect disk removal and unrecoverable disk error, the FAT structure can be collapted. Following images shows the critical section on the FatFs application.</p>
<div class="lset">
@ -198,16 +227,16 @@ Figure 5. Minimized critical section<br>
<li>A file being appended returns initial state.</li>
<li>A file created as new is gone.</li>
<li>A file created as new or in overwritten remains with no content.</li>
<li>Efficiency of disk use gets worse due to lost chain.</li>
<li>Efficiency of disk use gets worse due to lost clusters.</li>
</ul>
<p>Each case does not affect the files that not in write mode open. 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 f_sync function properly.</p>
</div>
<div class="para">
<div class="para" id="license">
<h3>About FatFs License</h3>
<p>This is a copy of the FatFs license document that included in the source codes.</p>
<pre>/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.08 (C)ChaN, 2010
/ FatFs - FAT file system module R0.08a (C)ChaN, 2010
/-----------------------------------------------------------------------------/
/ 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

View File

@ -63,7 +63,7 @@ FRESULT f_chdir (
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_FS_RPATH == 1</tt>.</p>
<p>Available when <tt>_FS_RPATH >= 1</tt>.</p>
</div>
@ -80,7 +80,7 @@ FRESULT f_chdir (
<div class="para">
<h4>See Also</h4>
<p><tt><a href="chdrive.html">f_chdrive</a></tt></p>
<p><tt><a href="chdrive.html">f_chdrive</a>, <a href="getcwd.html">f_getcwd</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -48,13 +48,13 @@ FRESULT f_chdrive (
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_FS_RPATH == 1</tt>.</p>
<p>Available when <tt>_FS_RPATH >= 1</tt>.</p>
</div>
<div class="para">
<h4>See Also</h4>
<p><tt><a href="chdir.html">f_chdir</a></tt></p>
<p><tt><a href="chdir.html">f_chdir</a>, <a href="getcwd.html">f_getcwd</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -49,7 +49,7 @@ FRESULT f_close (
<div class="para">
<h4>Description</h4>
<p>The f_close 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. If the file object has been opened in read-only mode, it may be discarded without closing process by this function but not recommended.</p>
<p>The f_close 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>
</div>

View File

@ -37,8 +37,8 @@ DSTATUS disk_initialize (
<div class="para">
<h4>Description</h4>
<p>The disk_initialize function initializes a physical drive. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleard.</p>
<p>This function is called on volume mount process in the FatFs module to manage the media change. <em>Application program should not call this function, or FAT structure on the volume can be collapted. To re-initialize the file system, use f_mount function.</em></p>
<p>The disk_initialize function initializes a physical drive and put it ready to read/write. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleard.</p>
<p><em>Application program should not call this function, or FAT structure on the volume can be collapted. To re-initialize the file system, use f_mount function.</em>This function is called on volume mount process in the FatFs module to manage the media change.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -56,10 +56,11 @@ DRESULT disk_ioctl (
<p>The FatFs module uses only device independent commands described below. Any device dependent function is not used.</p>
<table class="lst">
<tr><th>Command</th><th>Description</th></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the disk drive has finished pending write process. When the disk I/O module has a write back cache, flush the dirty sector immediately. This command is not required in read-only configuration.</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the drive into the WORD variable pointed by <tt>Buffer</tt>. This command is not required in single sector size configuration, _MAX_SS is 512.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Returns total sectors on the drive into the DWORD variable pointed by <tt>Buffer</tt>. This command is used by only f_mkfs function to determine the volume size to be created.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory in unit of sector into the DWORD variable pointed by <tt>Buffer</tt>. This command is used by only f_mkfs function and it attempts to align data area to the erase block boundary. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or disk devices.</td></tr>
<tr><td>CTRL_SYNC</td><td>Make sure that the disk drive has finished pending write process. When the disk I/O module has a write back cache, flush the dirty sector immediately. This command is not used in read-only configuration.</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the drive into the WORD variable pointed by <tt>Buffer</tt>. This command is not used in fixed sector size configuration, <tt>_MAX_SS</tt> is 512.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Returns number of available sectors on the drive into the DWORD variable pointed by <tt>Buffer</tt>. This command is used by only f_mkfs function to determine the volume size to be created.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory in unit of sector into the DWORD variable pointed by <tt>Buffer</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or disk devices. This command is used by only f_mkfs function and it attempts to align data area to the erase block boundary.</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>Erases a part of the flash memory specified by a DWORD array {&lt;start sector&gt;, &lt;end sector&gt;} pointed by <tt>Buffer</tt>. When this feature is not supported or not a flash memory media, this command has no effect. The FatFs does not check the result code and the file function is not affected even if the sectors are not erased well. This command is called on removing a cluster chain when <tt>_USE_ERASE</tt> is 1.</td></tr>
</table>
</div>

View File

@ -30,11 +30,11 @@ DRESULT disk_read (
<dt>Drive</dt>
<dd>Specifies the physical drive number.</dd>
<dt>Buffer</dt>
<dd>Pointer to the byte array to store the read data. The buffer size of number of bytes to be read, sector size * sector count, is required. The memory address specified by upper layer may or may not be aligned to word boundary.</dd>
<dd>Pointer to the <em>byte array</em> to store the read data. The buffer size of number of bytes to be read, sector size * sector count, is required. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function.</dd>
<dt>SectorNumber</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dt>SectorCount</dt>
<dd>Specifies number of sectors to read. The value can be 1 to 255.</dd>
<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>
</dl>
</div>

View File

@ -30,11 +30,11 @@ DRESULT disk_write (
<dt>Drive</dt>
<dd>Specifies the physical drive number.</dd>
<dt>Buffer</dt>
<dd>Pointer to the byte array to be written. The memory address specified by upper layer may or may not be aligned to word boundary.</dd>
<dd>Pointer to the <em>byte array</em> to be written. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function.</dd>
<dt>SectorNumber</dt>
<dd>Specifies the start sector number in logical block address (LBA).</dd>
<dt>SectorCount</dt>
<dd>Specifies the number of sectors to write. The value can be 1 to 255.</dd>
<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>
</dl>
</div>

View File

@ -12,21 +12,22 @@
<body>
<div class="para">
<h2>Format of the path names</h2>
<h3>Format of the path names</h3>
<p>The path name format on the FatFs module is similer to the filename specs of DOS/Windos as follows:</p>
<p><tt>"[drive#:][/]directory/file"</tt></p>
<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 differences between FatFs and DOS/Windows are directory separator and logical drive number. The sub directories are separated with a / or \. The logical drive is specified in a numeral with a colon. When the drive number is omitted, it is assumed as default drive (0 or current drive).</p>
<p>Nul character and control characters (\0 to \x1F) 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.</p>
<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. 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 default drive (0 or current drive).</p>
<p>Control characters (\0 to \x1F) 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>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, the path is followed from the current directory set with <a href="chdir.html">f_chdir</a> function. Dot names are also allowed for the directory name. The default drive number is the current drive number set with <a href="chdrive.html">f_chdrive</a> function.</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">
<tr><td>Path name</td><td>_FS_RPATH == 0</td><td>_FS_RPATH == 1</td></tr>
<tr class="lst3"><td>file.txt</td><td>A file in the root directory on the drive 0</td><td>A file in the current directory on the current drive</td></tr>
<tr><td>/file.txt</td><td>A file in the root directory on the drive 0</td><td>A file in the root directory on the current drive</td></tr>
<tr><td></td><td>The root directory on the drive 0</td><td>The current directory on the current drive</td></tr>
<tr><td>2:</td><td>The root directory on the drive 2</td><td>The current directory on the drive 2</td></tr>
<tr><td>2:file.txt</td><td>A file in the root directory on the drive 2</td><td>A file in the current directory on the drive 2</td></tr>
<tr><td>2:/</td><td>The root directory on the drive 2</td><td>The root directory on the drive 2</td></tr>
<tr class="lst3"><td>file.txt</td><td>A file in the root directory of the drive 0</td><td>A file in the current directory of the current drive</td></tr>
<tr><td>/file.txt</td><td>A file in the root directory of the drive 0</td><td>A file in the root directory of the current drive</td></tr>
<tr><td></td><td>The root directory of the drive 0</td><td>The current directory of the current drive</td></tr>
<tr><td>/</td><td>The root directory of the drive 0</td><td>The root directory of the current drive</td></tr>
<tr><td>2:</td><td>The root directory of the drive 2</td><td>The current directory of the drive 2</td></tr>
<tr><td>2:/</td><td>The root directory of the drive 2</td><td>The root directory of the drive 2</td></tr>
<tr><td>2:file.txt</td><td>A file in the root directory of the drive 2</td><td>A file in the current directory of the drive 2</td></tr>
<tr><td>../file.txt</td><td>Invalid name</td><td>A file in the parent directory</td></tr>
<tr><td>.</td><td>Invalid name</td><td>This directory</td></tr>
<tr><td>..</td><td>Invalid name</td><td>Parent directory of the current directory</td></tr>
@ -37,7 +38,7 @@
<p><br></p>
<div class="para">
<h2>Unicode API</h2>
<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 under LFN configuration, the type of the <tt>TCHAR</tt> is switched to <tt>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>
<pre>
f_open(fp, "filename.txt", FA_READ); <span>/* ANSI/OEM only */</span>
@ -48,7 +49,7 @@
<p><br></p>
<div class="para">
<h2>Correspondence between logical and physical drives</h2>
<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, the logical drive is bound to the physical drive that has same drive number, and the first partition is mounted. When <tt>_MULTI_PARTITION == 1</tt> is specified in configuration option, each individual logical drive can be bound to any physical drive/partition. In this case, a drive number resolution table must be defined as follows:</p>
<pre>
Example: Logical drive 0-2 are assigned to three pri-partitions on the physical drive 0 (fixed disk)

View File

@ -81,7 +81,7 @@ FRESULT f_getfree (
if (res) die(res);
<span>/* Get total sectors and free sectors */</span>
tot_sect = (fs->max_clust - 2) * fs->csize;
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
<span>/* Print free space in unit of KB (assuming 512 bytes/sector) */</span>

View File

@ -44,7 +44,7 @@ FRESULT f_mkdir (
<dt>FR_DENIED</dt>
<dd>The directory cannot be created due to directory table or disk is full.</dd>
<dt>FR_EXIST</dt>
<dd>A file or directory that has same name is already existing.</dd>
<dd>An object that has same name is already existing.</dd>
<dt>FR_NOT_READY</dt>
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_WRITE_PROTECTED</dt>

View File

@ -55,7 +55,7 @@ FRESULT f_mkfs (
<ul>
<li>The disk size is too small.</li>
<li>Invalid parameter was given to any parameter.</li>
<li>Not allowable cluster size for this drive. This can occure when number of clusters becomes around 0xFF7 and 0xFFF7.</li>
<li>Not allowable cluster size for this drive. This can occure when number of clusters gets near the 0xFF7 and 0xFFF7.</li>
</ul>
</dd>
</dl>
@ -65,6 +65,7 @@ FRESULT f_mkfs (
<h4>Description</h4>
<p>The f_mkfs function creates an FAT volume on the drive. There are two partitioning rules, FDISK and SFD, for removable media. The FDISK format is recommended for the most case. This function currently <em>does not support multiple partition</em>, so that existing partitions on the physical dirve will be deleted and re-created a new partition occupies entire disk space.</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 FR_MKFS_ABORTED.</p>
</div>

View File

@ -46,7 +46,7 @@ FRESULT f_mount (
<div class="para">
<h4>Description</h4>
<p>The f_mount function registers/unregisters a work area to the FatFs module. The work area must be given to the each volume with this function prior to use any other file function. To unregister a work area, specify a NULL to the <em>FileSystemObject</em>, and then the work area can be discarded.</p>
<p>This function only initializes the given work area and registers its address to the internal table, any access to the disk I/O layer does not occure. The volume mount process is performed on first file access after f_mount function or media change.</p>
<p>This function always succeeds regardless of the drive status. No media access is occured in this function and it only initializes the given work area and registers its address to the internal table. The volume mount process is performed on first file access after f_mount function or media change.</p>
</div>

View File

@ -39,7 +39,7 @@ FRESULT f_open (
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file is not existing. (Default)</td></tr>
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file is created.<br>
To append data to the file, use f_lseek function after file open in this method.</td></tr>
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails if the file is already existing.</td></tr>
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails with FR_EXIST if the file is existing.</td></tr>
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it is truncated and overwritten.</td></tr>
</table>
</dd>
@ -65,8 +65,8 @@ To append data to the file, use f_lseek function after file open in this method.
<dt>FR_DENIED</dt>
<dd>The required access was denied due to one of the following reasons:
<ul><li>Write mode open against a read-only file.</li>
<li>File cannot be created due to a read-only file or same directory name is existing.</li>
<li>File cannot be created due to the directory table or volume is full.</li></ul></dd>
<li>File cannot be created due to a directory or read-only file is existing.</li>
<li>File cannot be created due to the directory table is full.</li></ul></dd>
<dt>FR_NOT_READY</dt>
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_WRITE_PROTECTED</dt>
@ -80,7 +80,7 @@ To append data to the file, use f_lseek function after file open in this method.
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT volume on the drive.</dd>
<dt>FR_LOCKED</dt>
<dd>The function was rejected due to file shareing policy.</dd>
<dd>The function was rejected due to file shareing policy (_FS_SHARE).</dd>
</dl>
</div>
@ -110,7 +110,7 @@ void main (void)
UINT br, bw; <span>/* File read/write count */</span>
<span>/* Register work area for logical drives */</span>
<span>/* 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]);

View File

@ -63,14 +63,14 @@ FRESULT f_rename (
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT volume on the drive.</dd>
<dt>FR_LOCKED</dt>
<dd>The function was rejected due to file shareing policy.</dd>
<dd>The function was rejected due to file shareing policy (_FS_SHARE).</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>Renames an object 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>.</p>
<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>.</p>
</div>

View File

@ -31,7 +31,7 @@ typedef struct {
BYTE* dir_ptr; <span>/* Ponter to the directory entry in the window */</span>
#endif
#if _USE_FASTSEEK
DWORD* cltbl; <span>/* Pointer to the cluster link map table */</span>
DWORD* cltbl; <span>/* Pointer to the cluster link map table (Nulled on file open) */</span>
#endif
#if _FS_SHARE
UINT lockid; <span>/* File lock ID */</span>

View File

@ -23,7 +23,7 @@ typedef struct {
TCHAR fname[13]; <span>/* Short file name (8.3 format) */</span>
#if _USE_LFN
TCHAR* lfname; <span>/* Pointer to the LFN buffer */</span>
int lfsize; <span>/* Size of LFN buffer [characters] */</span>
int lfsize; <span>/* Size of the LFN buffer in unit of TCHAR */</span>
#endif
} FILINFO;
</pre>

View File

@ -51,7 +51,7 @@ FRESULT f_truncate (
<div class="para">
<h4>Description</h4>
<p>The f_truncate function truncates the file size to the current file R/W point. When the file R/W pointer is already pointing end of the file, this function has no effect.</p>
<p>The f_truncate function truncates the file size to the current file read/write point. This function has no effect if the file read/write pointer is already pointing end of the file.</p>
</div>

View File

@ -13,7 +13,7 @@
<div class="para">
<h2>f_unlink</h2>
<p>The f_unlink removes an object.</p>
<p>The f_unlink function removes an object.</p>
<pre>
FRESULT f_unlink (
const TCHAR* <em>FileName</em> <span>/* Pointer to the object name */</span>
@ -45,7 +45,7 @@ FRESULT f_unlink (
<dd>The drive number is invalid.</dd>
<dt>FR_DENIED</dt>
<dd>The function was denied due to either of following reasons:
<ul><li>The object has read-only attribute</li><li>The directory is not empty.</li></ul></dd>
<ul><li>The object has read-only attribute</li><li>Not empty directory</li><li>Current directory</li></ul></dd>
<dt>FR_NOT_READY</dt>
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_WRITE_PROTECTED</dt>
@ -59,14 +59,14 @@ FRESULT f_unlink (
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT volume on the drive.</dd>
<dt>FR_LOCKED</dt>
<dd>The function was rejected due to file shareing policy.</dd>
<dd>The function was rejected due to file shareing policy (_FS_SHARE).</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The f_unlink function removes an object. <em>Do not remove open objects and current directory</em>.</p>
<p>The f_unlink function removes an object. <em>Do not remove open objects</em>.</p>
</div>

View File

@ -86,7 +86,7 @@ FRESULT set_timestamp (
fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);
return f_utime(obj, &fno);
return f_utime(obj, &amp;fno);
}
</pre>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -11,25 +11,38 @@
<body>
<h1>FatFsモジュール アプリケーション・ノート</h1>
<ol class="toc">
<li><a href="#port">ポーティングの際に配慮すべきこと</a></li>
<li><a href="#limits">限界値</a></li>
<li><a href="#memory">メモリ使用量</a></li>
<li><a href="#reduce">モジュール・サイズの縮小</a></li>
<li><a href="#lfn">長いファイル名</a></li>
<li><a href="#jap">日本語ファイル名の大文字変換</a></li>
<li><a href="#unicode">Unicode入出力への対応</a></li>
<li><a href="#reentrant">リエントランシー</a></li>
<li><a href="#dup">多重ファイル・アクセス</a></li>
<li><a href="#fs1">効率的なファイル・アクセス</a></li>
<li><a href="#fs2">フラッシュ・メモリの特性への配慮</a></li>
<li><a href="#critical">クリチカル・セクション</a></li>
<li><a href="#license">FatFsのライセンスについて</a></li>
</ol>
<hr>
<div class="para">
<div class="para" id="port">
<h3>ポーティングの際に配慮すべきこと</h3>
<h4>移植の際の前提条件</h4>
<p>FatFsモジュールは移植性に関して次の点を前提としています。</p>
<ul>
<li>処理系はANSI C準拠であること。<br>
FatFsモジュールはANSI C準拠で記述されているので、ANSI C準拠のコンパイラなら特に処理系依存な点はありません。</li>
FatFsモジュールはANSI C(C89)準拠で記述されているので、ANSI Cに準拠したまともなコンパイラなら特に処理系依存になる点はありません。</li>
<li>char/short/longのサイズは、それぞれ8/16/32ビットで、intは16または32ビットであること。<br>
サイズを明示する整数の型が integer.h 内で定義されています。整数の型とサイズに関しては、まっとうな処理系なら問題ないはずですが、既存の定義と衝突した場合はユーザによって解決されなければなりません。</li>
</ul>
</div>
<div class="para">
<h3>ポーティングのしかた</h3>
<h4>ユーザの作成する関数</h4>
<p>必要なのは FatFsモジュールの要求するディスク関数を用意することだけで、それ以外にすることはありません。既に動作しているディスク関数があるならその APIを FatFsに合わせるだけで済みますが、無い場合はほかから移植するか、最初から書くかする必要があります。定義されている全ての関数が常に必要なわけではありません。例えば、リード・オンリー構成では書き込み系関数は必要ありません。次の表に構成オプションと要求される関数の対応を示します。</p>
<table class="lst2">
<tr><th>ユーザ作成関数</th><th>必要となる条件</th><th>備考</th></tr>
<tr><td>disk_initialize</td><td>常時</td><td rowspan="9">ffsample.zip (サンプル)<br>その他web上に多数</td></tr>
<tr><td>disk_initialize</td><td>常時</td><td rowspan="10">ffsample.zip (サンプル)<br>その他web上に多数</td></tr>
<tr><td>disk_status</td><td>常時</td></tr>
<tr><td>disk_read</td><td>常時</td></tr>
<tr><td>disk_write</td><td>_FS_READONLY == 0</td></tr>
@ -37,6 +50,7 @@ FatFsモジュールはANSI C準拠で記述されているので、ANSI C準拠
<tr><td>disk_ioctl (GET_SECTOR_COUNT)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>_MAX_SS &gt;= 1024</td></tr>
<tr><td>disk_ioctl (GET_BLOCK_SIZE)</td><td>_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (CTRL_ERASE_SECTOR)</td><td>_USE_ERASE == 1</td></tr>
<tr><td>get_fattime</td><td>_FS_READONLY == 0</td></tr>
<tr><td>ff_convert</td><td>_USE_LFN &gt;= 1</td><td rowspan="2">option/cc*.c</td></tr>
<tr><td>ff_wtoupper</td><td>_USE_LFN &gt;= 1</td></tr>
@ -49,7 +63,7 @@ FatFsモジュールはANSI C準拠で記述されているので、ANSI C準拠
</table>
</div>
<div class="para">
<div class="para" id="limits">
<h3>限界値</h3>
<ul>
<li>FATタイプ: FAT12, FAT16, FAT32。</li>
@ -62,17 +76,17 @@ FatFsモジュールはANSI C準拠で記述されているので、ANSI C準拠
</ul>
</div>
<div class="para">
<h3>メモリ使用量 (R0.08)</h3>
<div class="para" id="memory">
<h3>メモリ使用量 (R0.08a)</h3>
<p>次の表にいくつかのターゲットにおけるメモリ使用量の例を示します。テスト時の構成オプションはその下の通りです。数値の単位はバイトで、<em>D</em>は論理ボリューム数、<em>F</em>は同時オープン・ファイル数を示します。コンパイラの最適化オプションはコード・サイズとしています。</p>
<table class="lst2">
<tr><th></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>V850ES</th><th>SH-2A</th><th>ARM7</th><th>x86</th></tr>
<tr><td>Compiler</td><td>WinAVR(gcc)</td><td>CH38</td><td>C30(gcc)</td><td>CA850</td><td>SHC</td><td>WinARM(gcc)</td><td>VC6</td></tr>
<tr><td>_WORD_ACCESS</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td></tr>
<tr class="lst3"><td>text (Full, R/W)</td><td>12700</td><td>10686</td><td>11376</td><td>7730</td><td>8592</td><td>10520</td><td>7545</td></tr>
<tr> <td>text (Min, R/W)</td><td>8386</td><td>6980</td><td>7395</td><td>4930</td><td>5600</td><td>6636</td><td>4923</td></tr>
<tr><td>text (Full, R/O)</td><td>6012</td><td>4874</td><td>5250</td><td>3556</td><td>3848</td><td>4656</td><td>3450</td></tr>
<tr> <td>text (Min, R/O)</td><td>4384</td><td>3774</td><td>3939</td><td>2684</td><td>2996</td><td>3416</td><td>2664</td></tr>
<tr class="lst3"><td>text (Full, R/W)</td><td>12646</td><td>10686</td><td>11430</td><td>7732</td><td>8752</td><td>10560</td><td>7545</td></tr>
<tr> <td>text (Min, R/W)</td><td>8306</td><td>6986</td><td>7413</td><td>4938</td><td>5576</td><td>6680</td><td>4923</td></tr>
<tr><td>text (Full, R/O)</td><td>5960</td><td>4876</td><td>5250</td><td>3554</td><td>3804</td><td>4688</td><td>3450</td></tr>
<tr> <td>text (Min, R/O)</td><td>4366</td><td>3770</td><td>3939</td><td>2684</td><td>2940</td><td>3452</td><td>2664</td></tr>
<tr><td>bss</td><td>D*2 + 2</td><td>D*4 + 2</td><td>D*2 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td><td>D*4 + 2</td></tr>
<tr><td>Work area<br>(_FS_TINY == 0)</td><td>D*560 +<br>F*544</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*544</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td><td>D*560 +<br>F*550</td></tr>
<tr><td>Work area<br>(_FS_TINY == 1)</td><td>D*560 +<br>F*32</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*32</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td><td>D*560 +<br>F*36</td></tr>
@ -94,41 +108,42 @@ _FS_SHARE 0 (Disable shareing control)
</pre>
</div>
<div class="para">
<div class="para" id="reduce">
<h3>モジュール・サイズの縮小</h3>
<p>次の表は構成オプションの設定値によりどの機能が削除されるかを示します。</p>
<table class="lst2">
<tr><td rowspan="2">Function</td><td colspan="3">_FS_MINIMIZE</td><td>_FS_READONLY</td><td>_USE_STRFUNC</td><td>_FS_RPATH</td><td>_USE_MKFS</td><td>_USE_FORWARD</td></tr>
<tr><td>1</td><td>2</td><td>3</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr class="lst3"><td>f_mount</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_open</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_close</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_read</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_write</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_sync</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_lseek</td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_opendir</td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_readdir</td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_stat</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_getfree</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_truncate</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_unlink</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_mkdir</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_chmod</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_utime</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_rename</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_chdir</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>f_chdrive</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>f_mkfs</td><td></td><td></td><td></td><td>x</td><td></td><td></td><td>x</td><td></td></tr>
<tr><td>f_forward</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>x</td></tr>
<tr><td>f_putc</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_puts</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_printf</td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>f_gets</td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td></tr>
<tr><td rowspan="2">Function</td><td colspan="4">_FS_MINIMIZE</td><td colspan="2">_FS_READONLY</td><td colspan="2">_USE_STRFUNC</td><td colspan="3">_FS_RPATH</td><td colspan="2">_USE_MKFS</td><td colspan="2">_USE_FORWARD</td></tr>
<tr><td>0</td><td>1</td><td>2</td><td>3</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>
<tr class="lst3"><td>f_mount</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_open</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_close</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_read</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_write</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></tr>
<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></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></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></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></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></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></tr>
<tr><td>f_truncate</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></tr>
<tr><td>f_unlink</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></tr>
<tr><td>f_mkdir</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></tr>
<tr><td>f_chmod</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></tr>
<tr><td>f_utime</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></tr>
<tr><td>f_rename</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></tr>
<tr><td>f_chdir</td><td></td><td></td><td></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></tr>
<tr><td>f_chdrive</td><td></td><td></td><td></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></tr>
<tr><td>f_getcwd</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>f_mkfs</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>x</td><td></td><td></td><td></td></tr>
<tr><td>f_forward</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>x</td><td></td></tr>
<tr><td>f_putc</td><td></td><td></td><td></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></tr>
<tr><td>f_puts</td><td></td><td></td><td></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></tr>
<tr><td>f_printf</td><td></td><td></td><td></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></tr>
<tr><td>f_gets</td><td></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></tr>
</table>
</div>
<div class="para">
<div class="para" id="lfn">
<h3>長いファイル名</h3>
<p>FatFsモジュールはR0.07から長いファイル名(LFN)をサポートしました。ファイルに付けられた2つの異なる名前(短いファル名と長いファイル名)は、f_readdir関数を除くファイル操作関数において透過です。LFN機能を有効にするには、<tt>_USE_LFN</tt>を1,2または3に設定し、Unicode変換関数<tt>ff_convert(), ff_wtoupper()</tt>をプロジェクトに追加します。これらの関数は、<tt>option/cc*.c</tt>に含まれています。LFN機能は、加えてある程度のワーク・エリア(LFN操作バッファ)を必要とします。バッファ長は使用できるメモリに応じて<tt>_MAX_LFN</tt>オプションで構成されることができます。LFNの長さは最大255文字に達するので、LFN完全対応のためには<tt>_MAX_LFN</tt>は255に設定されるべきです。与えられたファイル名に対してバッファ長が不足した場合、ファイル関数は<tt>FR_INVALID_NAME</tt>で失敗します。</p>
<p>LFN機能をリエントラント構成で使用する場合は、<tt>_USE_LFN</tt>は2または3に設定されなければなりません。この場合、ファイル関数はバッファをスタックやヒープに確保します。バッファ・サイズは、<tt>(_MAX_LFN + 1) * 2</tt>バイトになるので、スタック等のサイズはそれを考慮した十分なサイズでなければなりません。</p>
@ -141,37 +156,37 @@ _FS_SHARE 0 (Disable shareing control)
<tr><td>949(Korean)</td><td>+139857</td></tr>
<tr><td>950(Big5)</td><td>+111497</td></tr>
</table>
<p>LFNを有効にすると、選択されたコード・ページに応じてモジュール・サイズが増大されます。右の表に各コード・ページにおけるLFNを有効にしたときのモジュール・サイズの違いを示します。私たち日本人、中国人および韓国人は数万の文字を持ちます。不幸なことに、それは巨大なOEMUnicode相互変換テーブルを要求し、モジュール・サイズは劇的に増大されます。その結果、LFNを有効にしたFatFsモジュールは、AVRを含む殆どの8ビット・マイコンにインプリメントされることができません。<small>これは長い間私がLFNをインプリメントすることに興味を持ってこなかった理由です。</small></p>
<p>注: FATファイル・システム上のLFN機能はマイクロソフト社の特許です。商用製品でそれを有効にするときは、最終仕向地によってはライセンスが必要かも知れません。</p>
<p>LFN機能の上手な使い方は、それを使わないということです。実際、組み込み用途ではLFN機能がどうしても必要になるということはほとんど無いはずです。LFNを有効にすると、選択されたコード・ページに応じてモジュール・サイズが増大されます。右の表に各コード・ページにおけるLFNを有効にしたときのモジュール・サイズの違いを示します。私たち日本人、中国人および韓国人は数万の文字を持ちます。不幸なことに、それは巨大なOEMUnicode相互変換テーブルを要求し、モジュール・サイズは劇的に増大されます。その結果、LFNを有効にしたFatFsモジュールは、AVRを含む殆どの8ビット・マイコンにインプリメントされることができません。<small>これは長い間私がLFNをインプリメントすることに興味を持ってこなかった理由です。</small></p>
<p>注: マイクロソフト社はFATファイル・システムについていくつかの特許を保有しています。いずれもLFNの実装に関するもので、LFN機能に対して$0.25/unitのライセンス料を要求しています。このため、商用製品でLFN機能有効にするときは、最終仕向地によってはライセンスが必要かも知れません。</p>
</div>
<div class="para">
<div class="para" id="jap">
<h3>日本語ファイル名の大文字変換</h3>
<p>CP932(Shift_JIS)でかつ非LFN構成のときは、拡張文字の小文字(2バイト英字・キリル文字・ギリシャ文字)に対して大文字変換を行わず、小文字のままSFNエントリに記録・検索されます。これは日本語MSDOSと同じ仕様となります。このため、非LFN構成で全角小文字を含むファイルを作成すると、NT系Windowsでそのファイルを開けなくなります。LFN構成では大文字変換を行います(NT系Windows仕様)。</p>
<p>CP932(Shift_JIS)でかつ非LFN構成のときは、拡張文字の小文字(2バイト英字・キリル文字・ギリシャ文字)に対して大文字変換を行わず、小文字のままSFNエントリに記録・検索されます(日本語MSDOS仕様)。このため、非LFN構成で全角小文字を含むファイルを作成すると、NT系Windowsでそのファイルを開けなくなります。LFN構成では大文字変換を行います(NT系Windows仕様)。</p>
</div>
<div class="para">
<div class="para" id="unicode">
<h3>Unicode入出力への対応</h3>
<p>ファイル関数のファイル名入出力はデフォルトでは ANSI/OEMコードですが、これをUnicodeに切り替えることもできます。Unicodeファイル名に関する詳細は、<a href="filename.html">ファイル名</a>を参照してください。</p>
</div>
<div class="para">
<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</tt><tt>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>
</div>
<div class="para">
<div class="para" id="dup">
<h3>多重ファイル・アクセス</h3>
<p>FatFsモジュールではデフォルトでは多重アクセス制御機能をサポートしていません。ファイルに対する多重アクセスは、そのアクセス・モードによって制限されます。一つのファイルに対する多重オープンは、それらが全てリード・モードのときに限って許可されます。書き込みモードを含む多重オープン、また開かれているファイルに対するリネームや削除、カレント・ディレクトリの削除を行ってはなりません。さもないと、そのボリュームのFAT構造が破壊される可能性があります。</p>
<p><tt>_FS_SHARE</tt>に1以上の値をセットすることにより、ファイル単位の排他制御を自動で行うこともできます。この場合、上記のルールを破ったオープン・リネーム・削除を試みると、その関数は<tt>FR_LOCKED</tt>で失敗します。</p>
</div>
<div class="para">
<div class="para" id="fs1">
<h3>効率的なファイル・アクセス</h3>
<p>小規模な組込システムでのファイルの読み書きにおける効率の良いアクセスのため、アプリケーション・プログラマはFatFsモジュールの中でどのような処理が行われているか考慮すべきです。ディスク上のデータはf_read関数により次のシーケンスで転送されます。</p>
<p>小規模な組込システムでのファイルの読み書きにおける効率の良いアクセスのため、アプリケーション・プログラマはFatFsモジュールの中でどのような処理が行われているか考慮すべきです。ストレージ上のデータはf_read関数により次のシーケンスで転送されます。</p>
<p>図1. セクタ・ミスアラインド・リード (ショート)<br>
<img src="../img/f1.png" width="490" height="73" alt="fig.1">
</p>
@ -186,9 +201,22 @@ _FS_SHARE 0 (Disable shareing control)
<p>このように、セクタにアライメントしたファイルの読み書きへの配慮はバッファ経由のデータ転送を避け、読み書き性能は改善されるでしょう。その効果に加え、タイニー構成でキャッシュされたFATデータがファイル・データの転送によりフラッシュされず、非タイニー構成と同じ性能を小さなメモリ・フットプリントで達成できます。</p>
</div>
<div class="para">
<div class="para" id="fs2">
<h3>フラッシュ・メモリの特性への配慮</h3>
<p>HDDなどのディスク・メディアとは異なり、SDCやCFCなどのフラッシュ・メモリ・メディアの性能を引き出すには、その特性を意識した制御が必要になります。</p>
<h4>マルチ・セクタ書き込み</h4>
<div class="rset">
図6. マルチ/シングル・セクタ・ライトの比較<br>
<img src="../img/f6.png" width="630" height="148" alt="fig.6">
</div>
<p>フラッシュ・メモリ・メディアの書き込み速度はシングル・セクタ書き込みの時に最も低いものになり、一回のトランザクションで転送されるセクタ数が大きくなるほど書き込み速度は向上します。この効果はバス速度が高速になるほど顕著で、10倍以上の差が現れることも珍しくありません。書き込みトランザクションの回数はまた、メディアの寿命にも影響してきます。このため、アプリケーションはなるべく大きなブロック(クラスタ・サイズまたは2の累乗セクタ境界にアライメントした)で読み書きを行う必要があります。もちろん、アプリケーションからメディアに至る全てのレイヤがマルチ・セクタ転送に対応していないと意味がありません。残念ながら、既存のオープン・ソースのドライバの多くはマルチ・セクタ転送に未対応です。なお、FatFsモジュールおよびそれ用のサンプル・ドライバはマルチ・セクタ転送に対応しています。</p>
<h4>明示的なメモリ消去</h4>
<p>通常のファイル消去では、記録されたデータに対して何らかの制御が行われるわけではなく、単にFAT上に未使用クラスタとして記録されているだけです。このため、ファイルが消去されたあともそれらは有効なメモリ・ブロックとしてフラッシュ・メモリ上に残ります。そこで、ファイルを消去するとき、占有していたデータ・セクタを明示的に消去(つまり未使用ブロックにする)することにより、メディア内の空きブロックを増やすことができます。これにより、次にそのブロックに書き込むときの消去動作が無くなり、書き込み性能が向上する可能性があります。また、ウェアレベリングに使えるブロックが増え、メディアの耐久性も向上するかも知れません。この機能を有効にするには、構成オプションの<tt>_USE_ERASE</tt>に1を設定します。これはフラッシュ・メモリ・メディアの内部動作に期待した制御なので、効果があるとは限りません。また、ファイル消去の時間が延びることも考慮に入れるべきです。</p>
</div>
<div class="para" id="critical">
<h3>クリチカル・セクション</h3>
<p>ディスク上のFAT構造を操作している途中で、停電、不正なメディアの取り外し、回復不能なデータ・エラー等の障害が発生すると、処理が中途半端な状態で中断され、その結果としてFAT構造が破壊される可能性があります。次にFatFsモジュールにおけるクリチカル・セクションと、その間の障害により起きうるエラーの状態を示します。</p>
<p>ストレージ上のFAT構造を操作している途中で、停電、不正なメディアの取り外し、回復不能なデータ・エラー等の障害が発生すると、処理が中途半端な状態で中断され、その結果としてFAT構造が破壊される可能性があります。次にFatFsモジュールにおけるクリチカル・セクションと、その間の障害により起きうるエラーの状態を示します。</p>
<div class="lset">
図4. 長いクリチカル・セクション<br>
<img src="../img/f4.png" width="320" height="436" alt="fig.4">
@ -204,22 +232,22 @@ _FS_SHARE 0 (Disable shareing control)
<li>追記中のファイルがオープン前の状態に戻る。</li>
<li>新規に作成されたファイルが消える。</li>
<li>新規または上書きで作成されたファイルの長さがゼロになって残る。</li>
<li>ロストチェーンの発生によりディスクの利用効率が悪化する。</li>
<li>ロストチェーンの発生によりボリュームの利用効率が悪化する。</li>
</ul>
<p>いずれも書き込み中や操作対象でないファイルには影響はありません。これらのクリチカル・セクションは、ファイルを書き込みモードで開いている時間を最小限にするか、f_sync()を適宜使用することで図5のようにリスクを最小化することができます。</p>
</div>
<div class="para">
<div class="para" id="license">
<h3>FatFsのライセンスについて</h3>
<p>ソース・ファイルのヘッダにライセンス条件が記述されているので、利用の際はそれに従うこと。英語を読めない方のために以下に日本語訳を示しておきます。</p>
<pre>/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.08 (C)ChaN, 2009
/ FatFs - FAT file system module R0.08a (C)ChaN, 2010
/-----------------------------------------------------------------------------/
/ FatFsモジュールは、小規模な組み込みシステム向けの汎用FATファイルシステム・
/ モジュールです。これはフリー・ソフトウェアとして、教育・研究・開発のために
/ 以下のライセンス・ポリシーの下で公開されています。
/
/ Copyright (C) 2009, ChaN, all right reserved.
/ Copyright (C) 2010, ChaN, all right reserved.
/
/ * FatFsモジュールはフリー・ソフトウェアであり、また<em>無保証です</em>
/ * 用途に制限はありません。<em>あなたの責任の下において</em>、個人的・非営利的な

View File

@ -49,7 +49,7 @@ FRESULT f_close (
<div class="para">
<h4>‰ð<EFBFBD>à</h4>
<p>ファイルを閉じます。何らかの書き込みの行われたファイルの場合、キャッシュされた状態(リード/ライト・バッファ上のデータ、変更されたFATやディレクトリ項目)はディスクに書き戻されます。関数が正常終了すると、そのファイル・オブジェクトは無効になり、そのメモリも解放できます。読み込み専用モードで開かれたファイル・オブジェクトは、この関数によるクローズ処理を経ずに破棄することもできますが、推奨はされません。</p>
<p>ファイルを閉じます。何らかの書き込みの行われたファイルの場合、キャッシュされた状態(リード/ライト・バッファ上のデータ、変更されたFATやディレクトリ項目)はディスクに書き戻されます。関数が正常終了すると、そのファイル・オブジェクトは無効になり、そのメモリも解放できます。</p>
</div>

View File

@ -38,7 +38,7 @@ DSTATUS disk_initialize (
<div class="para">
<h4>解説</h4>
<p>ディスク・ドライブを初期化します。関数が成功すると、戻り値の<tt>STA_NOINIT</tt>フラグがクリアされます。</p>
<p>FatFsモジュールは、自動マウント動作により必要に応じてこの関数を呼び出します。<em>アプリケーションからこの関数を呼び出してはなりません。さもないとFAT構造が破壊される可能性があります。エラー等により再初期化が必要なときは、<tt>f_mount()</tt>を使用します。</em></p>
<p><em>アプリケーションからこの関数を呼び出すと、FATボリュームが破壊される可能性があります。エラー等により再初期化が必要なときは、<tt>f_mount()</tt>を使用します。</em>FatFsモジュールは、自動マウント動作により、必要に応じてこの関数を呼び出します。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -31,7 +31,7 @@ DRESULT disk_ioctl (
<dt>Command</dt>
<dd>制御コマンド・コードを指定します。</dd>
<dt>Buffer</dt>
<dd>制御コマンドに依存したパラメータを授受するバッファを指すポインタを指定します。バッファを使用しないコマンドの場合は、NULLを指定します。</dd>
<dd>制御コマンドに依存したパラメータを授受するバッファを指すポインタを指定します。データの授受のないコマンドの場合は、NULLを指定します。</dd>
</dl>
</div>
@ -51,14 +51,14 @@ DRESULT disk_ioctl (
<div class="para">
<h4>解説</h4>
<p>物理ドライブの種類によりサポートされるコマンドは異なりますが、FatFsモジュールでは、次の汎用コマンドのみ使用し、ドライブの種類に依存した制御は行いません。</p>
<p>この関数はリード・オンリー構成では必要とされません。</p>
<p>物理ドライブの種類によりサポートされるコマンドは異なりますが、FatFsモジュールでは、次の汎用コマンドのみ使用し、特定のハードウェアに依存した制御は行いません。</p>
<table class="lst">
<tr><th>コマンド</th><th>解説</th></tr>
<tr><td>CTRL_SYNC</td><td>ドライブがデータの書き込み処理を完了するのを待ちます。また、ライト・バック・キャッシュが存在する場合は、書き込まれていないデータを即時書き戻します。</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td><tt>Buffer</tt>の指すWORD変数にドライブのセクタ・サイズを返します。セクタサイズが固定(_MAX_SSが512)のときはこのコマンドは必要ありません。</td></tr>
<tr><td>CTRL_SYNC</td><td>ドライブがデータの書き込み処理を完了するのを待ちます。また、ライト・バック・キャッシュが存在する場合は、書き込まれていないデータを即時書き戻します。リード・オンリー構成では使用されません。</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td><tt>Buffer</tt>の指すWORD変数にドライブのセクタ・サイズを返します。セクタ・サイズが固定(<tt>_MAX_SS</tt>が512)のときはこのコマンドは使われません。</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td><tt>Buffer</tt>の指すDWORD変数にドライブ上の総セクタ数を返します。f_mkfs関数内で作成するボリュームのサイズを決定するために使用されます。</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>フラッシュ・メモリ・アレーの消去ブロック・サイズが分かる場合は、<tt>Buffer</tt>の指すDWORD変数にそれをセクタ単位で返します。1から32768でかつ2の累乗の値でなければなりません。f_mkfs関数内でのみ使用され、データ領域はこの境界にアライメントされます。不明な場合またはディスク・ドライブでは1を返します。</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>フラッシュ・メモリの消去ブロック・サイズを<tt>Buffer</tt>の指すDWORD変数にセクタ単位で返します。1から32768でかつ2の累乗の値でなければなりません。不明な場合またはフラッシュ・メモリ以外のメディアでは1を返します。f_mkfs関数内でのみ使用され、ボリュームのデータ領域はこの境界にアライメントされます。</td></tr>
<tr><td>CTRL_ERASE_SECTOR</td><td>フラッシュ・メモリの一部の領域を消去します。<tt>Buffer</tt>の指すDWORD配列には消去する領域 {開始セクタ,終了セクタ} を指定して呼び出します。この機能をサポートしない場合やフラッシュ・メモリ以外のメディアでは何もしません。この機能の戻り値はチェックされず、また、指定領域の消去が完全に行われなかったとしてもファイル・システムの動作には影響ありません。<tt>_USE_ERASE</tt>が1のとき、クラスタが解放されるときに呼び出されます。</td></tr>
</table>
</div>

View File

@ -30,11 +30,11 @@ DRESULT disk_read (
<dt>Drive</dt>
<dd>物理ドライブ番号(0-9)を指定します。</dd>
<dt>Buffer</dt>
<dd>ディスクから読み出したデータを格納するバイト配列で、読み出されるバイト数分のサイズが必要です。アドレスはアライメントされているとは限りません。</dd>
<dd>ディスクから読み出したデータを格納する<em>バイト配列</em>で、読み出されるバイト数分のサイズが必要です。指定されるアドレスはワード・アライメントされているとは限りません。</dd>
<dt>SectorNumber</dt>
<dd>読み出しを開始するセクタ番号。LBAで指定します。</dd>
<dt>SectorCount</dt>
<dd>読み出すセクタ数。 1255の範囲で設定します</dd>
<dd>読み出すセクタ数。 1128の範囲で指定します。一般的に、複数セクタの転送要求はデバイスに対してマルチ・セクタ転送しなければなりません。複数のシングル・セクタ転送に分解した場合、読み出し速度が低下します。</dd>
</dl>
</div>

View File

@ -30,11 +30,11 @@ DRESULT disk_write (
<dt>Drive</dt>
<dd>物理ドライブ番号(0-9)を指定します。</dd>
<dt>Buffer</dt>
<dd>ディスクに書き込むバイト配列を指定します。アドレスはアライメントされているとは限りません。</dd>
<dd>ディスクに書き込む<em>バイト配列</em>を指定します。指定されるアドレスはワード・アライメントされているとは限りません。</dd>
<dt>SectorNumber</dt>
<dd>書き込みを開始するセクタ番号。LBAで指定します。</dd>
<dt>SectorCount</dt>
<dd>書き込むセクタ数。 1255で設定します。</dd>
<dd>書き込むセクタ数。 1128で指定します。一般的に、複数セクタの転送要求はデバイスに対してマルチ・セクタ転送しなければなりません。複数のシングル・セクタ転送に分解した場合、書き込み速度は極端に低下します。</dd>
</dl>
</div>

View File

@ -11,7 +11,7 @@
<body>
<div class="para">
<h2>ファイル・ディレクトリの指定方法</h2>
<h3>ファイル・ディレクトリの指定方法</h3>
<p>FatFsモジュールでのファイル、ディレクトリ、ドライブの指定方法はDOS/Windowsとほぼ同じです。パス名のフォーマットは次の通りです。</p>
<p><tt>"[論理ドライブ番号:][/]ディレクトリ名/ファイル名"</tt></p>
<p>FatFsモジュールは長いファイル名(LFN)および8.3形式ファイル名(SFN)に対応しています。LFNは、<tt>(_USE_LFN &gt; 0)</tt>のとき使用可能になります。DOS/Windowsとの違いは、ディレクトリ・セパレータと論理ドライブ番号の指定です。ディレクトリ・セパレータには / または \ を使用します。論理ドライブ番号は、'0''9'の一文字の数字とコロンで指定し、省略した場合はデフォルト・ドライブ(0またはカレント・ドライブ)が選択されます。</p>
@ -36,7 +36,7 @@
<p><br></p>
<div class="para">
<h2>Unicode API</h2>
<h3>Unicode API</h3>
<p>ファイル関数の入出力のうちファイル名やパス名を指定する引数の型は、<tt>TCHAR</tt>で定義されていますが、これは<tt>char</tt>のエリアスになっています。そして、<tt>_CODE_PAGE</tt>で指定される ANSI/OEMコード(SBCSまたはDBCS)の文字列として扱われます。ファイル名入出力をUnicodeとする構成(LFN構成で、かつ<tt>_LFN_UNICODE</tt>を 1)にしたときは、<tt>TCHAR</tt>はワイド文字(<tt>unsigned short</tt>)に切り替わり、パス名にUnicodeを使用するようになります。これにより LFNフル対応となり、ANSI/OEMコードにない文字(たとえば ✝☪✡☸☭など)も使用できます。この設定は文字列入出力関数のデータ型とエンコーディングにも影響を与えます。リテラル文字列を定義するとき、次に示すように<tt>_T(s)</tt>および<tt>_TEXT(s)</tt>マクロを使ってANSI/OEMとUnicodeを自動切り替えすることができます。</p>
<pre>
f_open(fp, "filename.txt", FA_READ); <span>/* ANSI/OEM専用コード */</span>
@ -47,7 +47,7 @@
<p><br></p>
<div class="para">
<h2>論理ドライブ(ボリューム)と物理ドライブ(ディスク装置)の対応</h2>
<h3>論理ドライブ(ボリューム)と物理ドライブ(ディスク装置)の対応</h3>
<p>デフォルトの構成では、それぞれの論理ドライブは同じ番号の物理ドライブに1:1で結びつけられていて、物理ドライブの先頭の区画にあるボリュームがマウントされます。<tt>_MULTI_PARTITION</tt>に 1を指定すると、個々の論理ドライブに対して個別に物理ドライブ番号・区画を指定できるようになります。この構成では、論理ドライブと区画の対応を解決するためのテーブルを次に示すように定義する必要があります。</p>
<pre>
例:論理ドライブ02を物理ドライブ0(固定ディスク)の3つの基本区画に割り当て、

View File

@ -60,7 +60,7 @@ FRESULT f_forward (
<div class="para">
<h4>解説</h4>
<p>ファイルのデータをバッファに読み出さずに送信ストリームに直接転送します。アプリケーション側でデータ・バッファを必要としないので、メモリの限られた環境で有効です。転送開始位置は、現在のファイルR/Wポインタからになります。ファイルR/Wポインタは転送されたバイト数だけ進みます。指定されたバイト数の転送中にファイルの終端に達した場合や送信ストリームがビジーになった場合、<tt>*ByteFwd</tt><tt>ByteToFwd</tt>よりも小さくなります。</p>
<p>ファイルのデータをバッファに読み出さずに送信ストリームに直接転送します。アプリケーション側でデータ・バッファを必要としないので、メモリの限られた環境で有効です。リード/ライト・ポインタは転送されたバイト数だけ進みます。指定されたバイト数の転送中にファイルの終端に達した場合や送信ストリームがビジーになった場合、<tt>*ByteFwd</tt><tt>ByteToFwd</tt>よりも小さくなります。</p>
</div>
@ -129,7 +129,7 @@ FRESULT play_file (
<span>/* ファイルを閉じて戻る */</span>
f_close(&amp;fil);
return rc; <span>
return rc;
}
</pre>
</div>

View File

@ -81,7 +81,7 @@ FRESULT f_getfree (
if (res) die(res);
<span>/* 全セクタ数と空きセクタ数を計算 */</span>
tot_sect = (fs->max_clust - 2) * fs->csize;
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
<span>/* ドライブサイズと空きサイズの表示 (512バイト/セクタと仮定) */</span>

View File

@ -106,7 +106,7 @@ FRESULT f_lseek (
DWORD lktbl[SZ_TBL]; <span>/* リンク・マップ・テーブル格納バッファ */</span>
res = f_lseek(&amp;file, ofs1); <span>/* 通常シーク (オープン時file.cltbl == NULL) */</span>
res = f_lseek(&amp;file, ofs1); <span>/* 通常シーク (オープン時file.cltbl == NULL) */</span>
file.cltbl = lktbl; <span>/* 高速シーク機能の有効化 */</span>
lktbl[0] = SZ_TBL; <span>/* 先頭要素に配列要素数をセット */</span>

View File

@ -44,7 +44,7 @@ FRESULT f_mkdir (
<dt>FR_DENIED</dt>
<dd>ディスクやディレクトリ・エントリが満杯の場合など。</dd>
<dt>FR_EXIST</dt>
<dd>同名のディレクトリやファイルが存在する。</dd>
<dd>同名のオブジェクトが存在する。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>

View File

@ -13,7 +13,7 @@
<div class="para">
<h2>f_mkfs</h2>
<p>ドライブ上にFATファイル・システムを作成(フォーマット)します。</p>
<p>物理ドライブ上にFATボリュームを作成(フォーマット)します。</p>
<pre>
FRESULT f_mkfs (
BYTE <em>Drive</em>, <span>/* 論理ドライブ番号 */</span>
@ -29,7 +29,7 @@ FRESULT f_mkfs (
<dt>Drive</dt>
<dd>フォーマットする論理ドライブ(0-9)。</dd>
<dt>PartitioningRule</dt>
<dd>0を指定すると、ドライブの全領域を占める基本DOS区画を作成したあと、その区画にファイル・システムを作成します(FDISKフォーマット)。1を指定すると、区画テーブルを作成せず物理ドライブの先頭セクタから直接ファイル・システムを作成します(super floppy (SFD) フォーマット)。</dd>
<dd>0を指定すると、ドライブの全領域を占める基本DOS区画を作成したあと、そこにFATボリュームを作成します(FDISKフォーマット)。1を指定すると、区画テーブルを作成せず物理ドライブの先頭セクタから直接ファイル・システムを作成します(super floppy (SFD) フォーマット)。</dd>
<dt>AllocSize</dt>
<dd>クラスタ・サイズをバイト単位で指定します。2の累乗、且つセクタ・サイズ以上、且つセクタ・サイズの128倍以下でなければなりません。無効な値を指定した場合、ドライブ・サイズに応じたデフォルトのクラスタ・サイズが選択されます。特に指定しない場合は、0を指定して自動選択とします。</dd>
</dl>
@ -55,7 +55,7 @@ FRESULT f_mkfs (
<ul>
<li>ディスク・サイズが小さすぎる。</li>
<li>何らかの引数が不正。</li>
<li>そのクラスタ・サイズが使えない。クラスタ数が0xFF7と0xFFF7近辺になるとき発生する可能性がある。</li>
<li>そのクラスタ・サイズが使えない。クラスタ数がFATタイプの境界に近くなるとき発生する可能性がある。</li>
</ul>
</dd>
</dl>
@ -63,8 +63,9 @@ FRESULT f_mkfs (
<div class="para">
<h4>説明</h4>
<p>f_mkfs関数はFATファイル・システムをドライブ上に作成します。リムーバブル・メディアのパーテーショニング・ルールとしてはFDISK形式とSFD形式があり、メモリ・カードではFDISK形式が普通です。この関数は<em>複数区画には対応していない</em>ので、その物理ドライブの既存の区画は全て削除され、全体が一つの区画になります。</p>
<p>f_mkfs関数は物理ドライブ上にFATボリュームを作成します。リムーバブル・メディアのパーテーショニング・ルールとしてはFDISK形式とSFD形式があり、メモリ・カードではFDISK形式が普通です。この関数は<em>複数区画には対応していない</em>ので、その物理ドライブの既存の区画は全て削除され、全体が一つの区画になります。</p>
<p>FATタイプ(FAT12/FAT16/FAT32)は、その論理ドライブ上の<em>クラスタ数によってのみ決定</em>される決まり[FAT仕様書より]になっていて、それ以外の要因はありません。したがって、どのFATタイプになるかはドライブ・サイズとクラスタ・サイズに依存します。クラスタ・サイズは大きくするほど性能が上がり、逆にディスク利用効率は落ちます。</p>
<p>クラスタ数がFATタイプの境界に近くなるときは、FR_MKFS_ABORTEDで関数が失敗する可能性があります。</p>
</div>

View File

@ -46,7 +46,7 @@ FRESULT f_mount (
<div class="para">
<h4>解説</h4>
<p>FatFsモジュールではそれぞれの論理ドライブにファイル・システム・オブジェクトというワーク・エリアが必要です。この関数は論理ドライブにそのワーク・エリアを登録したり抹消したりします。何らかのファイル関数を使用する前にこの関数でその論理ドライブのワーク・エリアを与えておかなければなりません。<tt>FileSystemObject</tt>にヌル・ポインタを指定するとその論理ドライブのワーク・エリアの登録は抹消され、登録されていたワーク・エリアは破棄できます。操作対象のドライブに対して開かれているファイルやディレクトリがあった場合、それらは全て無効になります。</p>
<p>この関数内では下位レイヤ(物理ドライブ)へのアクセスは発生せず、ワーク・エリアを初期化して内部配列にそのアドレスを登録するだけです。実際のマウント動作は、f_mount()またはメディア交換後、最初のファイル・アクセスのときに行われます。</p>
<p>この関数は、ドライブの状態に関わらず常に成功します。関数内では下位レイヤ(物理ドライブ)へのアクセスは発生せず、ワーク・エリアを初期化して内部配列にそのアドレスを登録するだけです。実際のマウント動作は、この関数の実行またはメディア交換発生の後、最初のファイル・アクセスのときに行われます。</p>
</div>

View File

@ -37,8 +37,8 @@ FRESULT f_open (
<tr><td>FA_READ</td><td>読み出しモードで開きます。読み書きする場合は<tt>FA_WRITE</tt>と共に指定します。</td></tr>
<tr><td>FA_WRITE</td><td>書き込みモードで開きます。読み書きする場合は<tt>FA_READ</tt>と共に指定します。</td></tr>
<tr><td>FA_OPEN_EXISTING</td><td>既存のファイルを開きます。ファイルが無いときはエラーになります。(デフォルト)</td></tr>
<tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。追記する場合は、この方法でオープンした後、<tt>f_lseek()</tt>でファイルの最後尾に移動してください。</td></tr>
<tr><td>FA_CREATE_NEW</td><td>ファイルを作成します。同名のファイルがある場合は、エラーになります。</td></tr>
<tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。追記操作する場合は、この方法でオープンした後、<tt>f_lseek()</tt>でファイルの最後尾に移動してください。</td></tr>
<tr><td>FA_CREATE_NEW</td><td>ファイルを作成します。同名のファイルがある場合は、エラー(FR_EXIST)になります。</td></tr>
<tr><td>FA_CREATE_ALWAYS</td><td>ファイルを作成します。同名のファイルがある場合は、サイズを0にしてから開きます。</td></tr>
</table>
</dd>
@ -60,9 +60,15 @@ FRESULT f_open (
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_EXIST</dt>
<dd>同名のファイルが既にる。</dd>
<dd>同名のファイルが既に存在する。</dd>
<dt>FR_DENIED</dt>
<dd>アクセスが拒否された。リード・オンリー・ファイルの書き込みモード・オープン、同名のディレクトリまたはリード・オンリー・ファイルがある状態でのファイル作成、ディスクまたはディレクトリ・テーブルが満杯でファイルを作成できないなど。</dd>
<dd>アクセスが拒否された。
<ul>
<li>リード・オンリー・ファイルの書き込みモード・オープン。</li>
<li>同名のディレクトリまたはリード・オンリー・ファイルがある状態でのファイル作成。</li>
<li>ディレクトリ・テーブルが満杯でファイルを作成できない。</li>
</ul>
</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
@ -76,7 +82,7 @@ FRESULT f_open (
<dt>FR_NO_FILESYSTEM</dt>
<dd>有効なFATボリュームが見つからない。</dd>
<dt>FR_LOCKED</dt>
<dd>ファイル共有機能によるアクセス拒否。</dd>
<dd>ファイル共有機能(_FS_SHARE)によるアクセス拒否。</dd>
</dl>
</div>
@ -105,7 +111,7 @@ void main (void)
FRESULT res; <span>/* FatFs function common result code */</span>
UINT br, bw; <span>/* File R/W count */</span>
<span>/* ドライブ0,1にワーク・エリアを与える */</span>
<span>/* ドライブ0,1にワーク・エリアを与える (常に成功する) */</span>
f_mount(0, &amp;fs[0]);
f_mount(1, &amp;fs[1]);

View File

@ -26,7 +26,7 @@ FRESULT f_readdir (
<h4>引数</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>ディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
<dd>有効なディレクトリ・オブジェクト構造体へのポインタを指定します。</dd>
<dt>FileInfo</dt>
<dd>読み出したディレクトリ項目を格納するファイル情報構造体へのポインタを指定します。</dd>
</dl>

View File

@ -13,11 +13,11 @@
<div class="para">
<h2>f_rename</h2>
<p>ファイルまたはディレクトリの名前の変更または移動。</p>
<p>オブジェクトの名前の変更または移動。</p>
<pre>
FRESULT f_rename (
const TCHAR* <em>OldName</em>, <span>/* 古いファイルまたはディレクトリ名 */</span>
const TCHAR* <em>NewName</em> <span>/* 新しいファイルまたはディレクトリ名 */</span>
const TCHAR* <em>OldName</em>, <span>/* 古いオブジェクト名 */</span>
const TCHAR* <em>NewName</em> <span>/* 新しいオブジェクト名 */</span>
);
</pre>
</div>
@ -28,7 +28,7 @@ FRESULT f_rename (
<dt>OldName</dt>
<dd>変更対象のオブジェクト(ファイルまたはディレクトリ)への<a href="filename.html">パス名</a>の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
<dt>NewName</dt>
<dd>新しいファイルまたはディレクトリのフルパス名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。既に存在する名前は使えません。また、ドライブ番号は指定できず、<tt>OldName</tt>で指定された論理ドライブ上のオブジェクトとして扱われます。<br>
<dd>新しいオブジェクトのフルパス名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。既に存在する名前は使えません。また、ドライブ番号は指定できず、<tt>OldName</tt>で指定された論理ドライブ上のオブジェクトとして扱われます。<br>
</dl>
</div>
@ -62,13 +62,15 @@ FRESULT f_rename (
<dd>論理ドライブにワークエリアが割り当てられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>有効なFATボリュームが見つからない。</dd>
<dt>FR_LOCKED</dt>
<dd>ファイル共有機能(_FS_SHARE)によるアクセス拒否。</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>オブジェクトの名前を変更します。また、別のディレクトリへの移動(同じドライブ内のみ)も可能です。<em>開かれているオブジェクトに対して使用してはなりません</em></p>
<p>オブジェクトの名前を変更します。また、別のディレクトリへの移動も可能です。<em>開かれているオブジェクトに対して使用してはなりません</em></p>
</div>

View File

@ -21,9 +21,9 @@ typedef struct {
WORD id; <span>/* 親ファイル・システム・オブジェクトのマウントID */</span>
BYTE flag; <span>/* ファイル・ステータス・フラグ */</span>
BYTE pad1;
DWORD fptr; <span>/* ファイル読み書きポインタ(ファイル先頭からのバイト・オフセット) */</span>
DWORD fptr; <span>/* ファイル読み書きポインタ (ファイル先頭からのバイト・オフセット) */</span>
DWORD fsize; <span>/* ファイル・サイズ(バイト単位) */</span>
DWORD org_clust; <span>/* ファイル開始クラスタ番号 (0: fsize==0) */</span>
DWORD org_clust; <span>/* ファイル開始クラスタ番号 (0 on fsize==0) */</span>
DWORD curr_clust; <span>/* 現在のクラスタ */</span>
DWORD dsect; <span>/* 現在のデータ・セクタ */</span>
#if _FS_READONLY == 0
@ -31,7 +31,7 @@ typedef struct {
BYTE* dir_ptr; <span>/* このファイルのディレクトリへのポインタ */</span>
#endif
#if _USE_FASTSEEK
DWORD* cltbl; <span>/* ファイルのクラスタ・リンク情報へのポインタ */</span>
DWORD* cltbl; <span>/* ファイルのクラスタ・リンク情報へのポインタ (Nulled on file open) */</span>
#endif
#if _FS_SHARE
UINT lockid; <span>/* ファイル・ロックID */</span>

View File

@ -16,7 +16,7 @@
<pre>
FRESULT f_stat (
const TCHAR* <em>FileName</em>, <span>/* ファイルまたはディレクトリ名へのポインタ */</span>
FILINFO* <em>FileInfo</em> <span>/* ファイル情報構造体へのポインタ *
FILINFO* <em>FileInfo</em> <span>/* ファイル情報構造体へのポインタ */</span>
);
</pre>
</div>

View File

@ -51,7 +51,7 @@ FRESULT f_truncate (
<div class="para">
<h4>‰ð<EFBFBD>à</h4>
<p>ファイルの長さが現在のファイルR/Wポインタに切り詰められます。ファイルR/Wポインタがファイルの終端を指しているときは、この関数は何の効果も持ちません。</p>
<p>ファイルの長さが現在のリード/ライト・ポインタに切り詰められます。リード/ライト・ポインタが既にファイルの終端を指しているときは、この関数は何の効果も持ちません。</p>
</div>

View File

@ -44,7 +44,7 @@ FRESULT f_unlink (
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_DENIED</dt>
<dd>対象オブジェクトがリード・オンリー属性、ディレクトリの場合は空でない場合など</dd>
<dd>対象オブジェクトがリード・オンリー属性、空でないディレクトリやカレント・ディレクトリ</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
@ -58,14 +58,14 @@ FRESULT f_unlink (
<dt>FR_NO_FILESYSTEM</dt>
<dd>有効なFATボリュームが見つからない。</dd>
<dt>FR_LOCKED</dt>
<dd>ファイル共有機能によるアクセス拒否。</dd>
<dd>ファイル共有機能(_FS_SHARE)によるアクセス拒否。</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>オブジェクトを削除します。<em>開かれているオブジェクトやカレント・ディレクトリは削除してはなりません</em></p>
<p>オブジェクトを削除します。<em>開かれているオブジェクトは削除してはなりません</em></p>
</div>
<div class="para">

View File

@ -86,7 +86,7 @@ FRESULT set_timestamp (
fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);
return f_utime(obj, &fno);
return f_utime(obj, &amp;fno);
}
</pre>
</div>

View File

@ -44,14 +44,14 @@ FRESULT f_write (
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_DENIED</dt>
<dd>非書き込みモードで開かれたファイルに書き込もうとした。</dd>
<dt>FR_DISK_ERR</dt>
<dd>ディスク・エラーによる失敗。</dd>
<dt>FR_INT_ERR</dt>
<dd>不正なFAT構造または内部エラーによる失敗。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_DENIED</dt>
<dd>非書き込みモードで開かれたファイルに書き込もうとした。</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイルオブジェクト。</dd>
</dl>

View File

@ -1,3 +1,10 @@
R0.08a, Aug 16, 2010
Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss.
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
Fixed f_mkfs() creates wrong FAT32 volume.
R0.08, May 15, 2010
Added a memory configuration option. (_USE_LFN)
Added file lock feature. (_FS_SHARE)

View File

@ -1,4 +1,4 @@
FatFs Module Source Files R0.08 (C)ChaN, 2010
FatFs Module Source Files R0.08a (C)ChaN, 2010
FILES
@ -7,7 +7,6 @@ FILES
ff.h Common include file for FatFs and application module.
ff.c FatFs module.
diskio.h Common include file for FatFs and disk I/O module.
diskio.c Skeleton of low level disk I/O module.
integer.h Alternative type definitions for integer variables.
option Optional external functions.
@ -115,3 +114,10 @@ REVISION HISTORY
Changed some types on the API, XCHAR->TCHAR.
Changed fname member in the FILINFO structure on Unicode cfg.
String functions support UTF-8 encoding files on Unicode cfg.
Aug 16,'10 R0.08a Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss.
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
Fixed f_mkfs() creates wrong FAT32 volume.

View File

@ -1,213 +0,0 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
/*-----------------------------------------------------------------------*/
/* This is a stub disk I/O module that acts as front end of the existing */
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/
#include "diskio.h"
/*-----------------------------------------------------------------------*/
/* Correspondence between physical drive number and physical drive. */
/*-----------------------------------------------------------------------*/
#define ATA 0
#define MMC 1
#define USB 2
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
)
{
DSTATUS stat;
int result;
switch (drv) {
case ATA :
result = ATA_disk_initialize();
// translate the reslut code here
return stat;
case MMC :
result = MMC_disk_initialize();
// translate the reslut code here
return stat;
case USB :
result = USB_disk_initialize();
// translate the reslut code here
return stat;
}
return STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{
DSTATUS stat;
int result;
switch (drv) {
case ATA :
result = ATA_disk_status();
// translate the reslut code here
return stat;
case MMC :
result = MMC_disk_status();
// translate the reslut code here
return stat;
case USB :
result = USB_disk_status();
// translate the reslut code here
return stat;
}
return STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE drv, /* 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..255) */
)
{
DRESULT res;
int result;
switch (drv) {
case ATA :
result = ATA_disk_read(buff, sector, count);
// translate the reslut code here
return res;
case MMC :
result = MMC_disk_read(buff, sector, count);
// translate the reslut code here
return res;
case USB :
result = USB_disk_read(buff, sector, count);
// translate the reslut code here
return res;
}
return RES_PARERR;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
/* The FatFs module will issue multiple sector transfer request
/ (count > 1) to the disk I/O layer. The disk function should process
/ the multiple sector transfer properly Do. not translate it into
/ multiple single sector transfers to the media, or the data read/write
/ performance may be drasticaly decreased. */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
DRESULT res;
int result;
switch (drv) {
case ATA :
result = ATA_disk_write(buff, sector, count);
// translate the reslut code here
return res;
case MMC :
result = MMC_disk_write(buff, sector, count);
// translate the reslut code here
return res;
case USB :
result = USB_disk_write(buff, sector, count);
// translate the reslut code here
return res;
}
return RES_PARERR;
}
#endif /* _READONLY */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
int result;
switch (drv) {
case ATA :
// pre-process here
result = ATA_disk_ioctl(ctrl, buff);
// post-process here
return res;
case MMC :
// pre-process here
result = MMC_disk_ioctl(ctrl, buff);
// post-process here
return res;
case USB :
// pre-process here
result = USB_disk_ioctl(ctrl, buff);
// post-process here
return res;
}
return RES_PARERR;
}

View File

@ -1,11 +1,11 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009
/ Low level disk interface modlue include file (C)ChaN, 2010
/-----------------------------------------------------------------------*/
#ifndef _DISKIO
#define _READONLY 0 /* 1: Read-only mode */
#define _USE_IOCTL 1
#define _READONLY 0 /* 1: Remove write functions */
#define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */
#include "integer.h"
@ -26,6 +26,7 @@ typedef enum {
/*---------------------------------------*/
/* Prototypes for disk control functions */
int assign_drives (int, int);
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
@ -43,26 +44,34 @@ DRESULT disk_ioctl (BYTE, BYTE, void*);
#define STA_PROTECT 0x04 /* Write protected */
/* Command code for disk_ioctrl() */
/* Command code for disk_ioctrl fucntion */
/* Generic command (defined for FatFs) */
#define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
#define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
#define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
#define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
/* Generic command */
#define CTRL_SYNC 0 /* Mandatory for write functions */
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
#define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
#define CTRL_POWER 4
#define CTRL_LOCK 5
#define CTRL_EJECT 6
/* MMC/SDC command */
#define MMC_GET_TYPE 10
#define MMC_GET_CSD 11
#define MMC_GET_CID 12
#define MMC_GET_OCR 13
#define MMC_GET_SDSTAT 14
/* ATA/CF command */
#define ATA_GET_REV 20
#define ATA_GET_MODEL 21
#define ATA_GET_SN 22
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
/* MMC/SDC specific ioctl command */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */
/* NAND specific ioctl command */
#define NAND_FORMAT 30 /* Create physical format */
#define _DISKIO

717
src/ff.c

File diff suppressed because it is too large Load Diff

120
src/ff.h
View File

@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.08 (C)ChaN, 2010
/ FatFs - FAT file system module include file R0.08a (C)ChaN, 2010
/----------------------------------------------------------------------------/
/ 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 8085 /* Revision ID */
#define _FATFS 8255 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@ -224,20 +224,20 @@ extern "C" {
/* Definitions corresponds to volume management */
/* Definitions of volume management */
#if _MULTI_PARTITION /* Multiple partition configuration */
#define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
#define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive# */
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition# */
typedef struct {
BYTE pd; /* Physical drive# */
BYTE pt; /* Partition # (0-3) */
} PARTITION;
extern const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
extern const PARTITION VolToPart[]; /* Volume - Physical location resolution table */
#else /* Single partition configuration */
#define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */
#define LD2PT(drv) 0 /* Always mounts the 1st partition */
#define LD2PD(vol) (vol) /* Logical drive# is bound to the same physical drive# */
#define LD2PT(vol) 0 /* Always mounts the 1st partition */
#endif
@ -266,21 +266,6 @@ typedef char TCHAR;
/* Definitions corresponds to file shareing feature */
#if _FS_SHARE
#if _FS_READONLY
#error _FS_SHARE must be 0 on R/O cfg.
#endif
typedef struct {
DWORD clu; /* File ID 1, directory */
WORD idx; /* File ID 2, index in the directory */
WORD ctr; /* File open counter, 0:none, 0x01..0xFF:read open count, 0x100:in write open */
} FILESEM;
#endif
/* File system object structure (FATFS) */
typedef struct {
@ -313,9 +298,6 @@ typedef struct {
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) */
#if _FS_SHARE
FILESEM flsem[_FS_SHARE]; /* File lock semaphores */
#endif
} FATFS;
@ -327,7 +309,7 @@ typedef struct {
WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */
BYTE pad1;
DWORD fptr; /* File read/write pointer */
DWORD fptr; /* File read/write pointer (0 on file open) */
DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster (0 when fsize==0) */
DWORD curr_clust; /* Current cluster */
@ -337,10 +319,10 @@ typedef struct {
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
#if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table */
DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
#endif
#if _FS_SHARE
UINT lockid; /* File lock ID */
UINT lockid; /* File lock ID (index of file semaphore table) */
#endif
#if !_FS_TINY
BYTE buf[_MAX_SS]; /* File data read/write buffer */
@ -378,7 +360,7 @@ typedef struct {
TCHAR fname[13]; /* Short file name (8.3 format) */
#if _USE_LFN
TCHAR* lfname; /* Pointer to the LFN buffer */
int lfsize; /* Size of LFN buffer [chrs] */
UINT lfsize; /* Size of LFN buffer in TCHAR */
#endif
} FILINFO;
@ -421,6 +403,7 @@ FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */
#if !_FS_READONLY
FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
@ -432,28 +415,36 @@ FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/d
FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */
#endif
#if _USE_FORWARD
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
#endif
#if _USE_MKFS
FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */
#endif
#if _FS_RPATH
FRESULT f_chdir (const TCHAR*); /* Change current directory */
FRESULT f_chdrive (BYTE); /* Change current drive */
FRESULT f_chdir (const TCHAR*); /* Change current directory */
FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */
#endif
#if _USE_STRFUNC
int f_putc (TCHAR, FIL*); /* Put a character to the file */
int f_puts (const TCHAR*, FIL*); /* Put a string to the file */
int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR*, int, FIL*); /* 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)
#ifndef EOF
#define EOF (-1)
#endif
#endif
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
/*--------------------------------------------------------------*/
@ -528,69 +519,6 @@ void ff_rel_grant (_SYNC_t); /* Unlock sync object */
#define CREATE_LINKMAP 0xFFFFFFFF
/* FatFs refers the members in the FAT structures with byte offset instead of
/ structure member because there are incompatibility of the packing option
/ between various compilers. */
#define BS_jmpBoot 0
#define BS_OEMName 3
#define BPB_BytsPerSec 11
#define BPB_SecPerClus 13
#define BPB_RsvdSecCnt 14
#define BPB_NumFATs 16
#define BPB_RootEntCnt 17
#define BPB_TotSec16 19
#define BPB_Media 21
#define BPB_FATSz16 22
#define BPB_SecPerTrk 24
#define BPB_NumHeads 26
#define BPB_HiddSec 28
#define BPB_TotSec32 32
#define BS_55AA 510
#define BS_DrvNum 36
#define BS_BootSig 38
#define BS_VolID 39
#define BS_VolLab 43
#define BS_FilSysType 54
#define BPB_FATSz32 36
#define BPB_ExtFlags 40
#define BPB_FSVer 42
#define BPB_RootClus 44
#define BPB_FSInfo 48
#define BPB_BkBootSec 50
#define BS_DrvNum32 64
#define BS_BootSig32 66
#define BS_VolID32 67
#define BS_VolLab32 71
#define BS_FilSysType32 82
#define FSI_LeadSig 0
#define FSI_StrucSig 484
#define FSI_Free_Count 488
#define FSI_Nxt_Free 492
#define MBR_Table 446
#define DIR_Name 0
#define DIR_Attr 11
#define DIR_NTres 12
#define DIR_CrtTime 14
#define DIR_CrtDate 16
#define DIR_FstClusHI 20
#define DIR_WrtTime 22
#define DIR_WrtDate 24
#define DIR_FstClusLO 26
#define DIR_FileSize 28
#define LDIR_Ord 0
#define LDIR_Attr 11
#define LDIR_Type 12
#define LDIR_Chksum 13
#define LDIR_FstClusLO 26
/*--------------------------------*/
/* Multi-byte word access macros */

View File

@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.08 (C)ChaN, 2010
/ FatFs - FAT file system module configuration file R0.08a (C)ChaN, 2010
/----------------------------------------------------------------------------/
/
/ CAUTION! Do not forget to make clean the project after any changes to
@ -7,7 +7,7 @@
/
/----------------------------------------------------------------------------*/
#ifndef _FFCONF
#define _FFCONF 8085 /* Revision ID */
#define _FFCONF 8255 /* Revision ID */
/*---------------------------------------------------------------------------/
@ -26,14 +26,14 @@
/ f_truncate and useless f_getfree. */
#define _FS_MINIMIZE 0 /* 0, 1, 2 or 3 */
#define _FS_MINIMIZE 0 /* 0 to 3 */
/* The _FS_MINIMIZE option defines minimization level to remove some 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 level 1.
/ 3: f_lseek is removed in addition to level 2. */
/ 2: f_opendir and f_readdir are removed in addition to 1.
/ 3: f_lseek is removed in addition to 2. */
#define _USE_STRFUNC 0 /* 0:Disable or 1/2:Enable */
@ -94,12 +94,12 @@
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support.
/
/ 0: Disable LFN. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT 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. When enable LFN,
/ 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. */
@ -110,9 +110,13 @@
/ enable LFN feature and set _LFN_UNICODE to 1. */
#define _FS_RPATH 0 /* 0:Disable or 1:Enable */
/* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir,
/ f_chdrive function are available.
#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.
/
/ Note that output of the f_readdir fnction is affected by this option. */
@ -121,7 +125,7 @@
/ Physical Drive Configurations
/----------------------------------------------------------------------------*/
#define _DRIVES 1
#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
@ -133,10 +137,14 @@
/ to the disk_ioctl function. */
#define _MULTI_PARTITION 0 /* 0:Single parition or 1:Multiple partition */
/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
/ drive number and can mount only first primaly partition. When it is set to 1,
/ each volume is tied to the partitions listed in Drives[]. */
#define _MULTI_PARTITION 0 /* 0:Single partition or 1: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 _USE_ERASE 0 /* 0:Disable or 1:Enable */
/* To enable sector erase feature, set _USE_ERASE to 1. */
@ -157,11 +165,12 @@
/ performance and code size. */
/* Include a header file here to define sync object types on the O/S */
/* #include <windows.h>, <ucos_ii.h>, <semphr.h> or ohters. */
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
/* Include a header file here to define O/S system calls */
/* #include <windows.h>, <ucos_ii.h.h>, <semphr.h> or ohters. */
/* The _FS_REENTRANT option switches the reentrancy of the FatFs module.
/
@ -172,10 +181,8 @@
#define _FS_SHARE 0 /* 0:Disable or >=1:Enable */
/* To enable file shareing feature, set _FS_SHARE to >= 1 and also user
provided memory handlers, ff_memalloc and ff_memfree function must be
added to the project. The value defines number of files can be opened
per volume. */
/* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value
defines how many files can be opened simultaneously. */
#endif /* _FFCONFIG */

View File

@ -329,7 +329,7 @@ const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
0x0428, 0x0429, 0x042A, 0x042D, 0x042C, 0x042D, 0x042E, 0x042F,
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,