fatfs v0.04 Feb 04, 2007:

- Supported multiple drive system.
- Changed some APIs for multiple drive system.
- Added f_mkfs().
This commit is contained in:
savelij13 2025-09-11 09:03:34 +03:00
parent f76dc3a97f
commit 3d65978d31
75 changed files with 2636 additions and 1380 deletions

View File

@ -3,6 +3,8 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<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 - Generic FAT Files System Module</title>
@ -13,26 +15,22 @@
<hr>
<div class="abst">
<img src="layers.png" class="rset" width="245" height="255">
<p>FatFs module is an experimental project to implement FAT file system to small embdded systems. The FatFs module is written in compliance with ANSI C, therefore it is independent of hardware architecture. It can be incorporated into most small microcontrollers, such as 8051, PIC, AVR, H8, Z80 and etc..., without any change. I created two modules in different configurations in consideration of various use. To use the FatFs module, low level disk I/O functions for each media must be provided by user.</p>
<img src="img/layers.png" class="rset" width="245" height="255" alt="layer">
<p>FatFs module is an experimental project to implement a FAT file system to small embdded systems. The FatFs module is written in compliance with ANSI C, therefore it is independent of hardware architecture. It can be incorporated into most small microcontrollers, such as 8051, PIC, AVR, H8, Z80 and etc..., without any change. I created two modules in different configurations in consideration of various use. To use the FatFs module, low level disk I/O functions for each media must be provided by user.</p>
<h4>Features of FatFs Module</h4>
<ul>
<li>Separated buffer for FAT and each file. Suitable for fast multiple file accsess.</li>
<li>Optimized for 8/16 bit microcontrollers.</li>
<li>Low memory consumption</li>
<li>Separated buffer for FAT/DIR and each file, suitable for fast multiple file accsess.</li>
<li>Supports FAT12, FAT16(+FAT64) and FAT32 <small>(FAT64: FAT16 in 64KB/cluster)</small></li>
<li>Supports multiple drives.</li>
<li>Supports 8.3 format file name and NT lower capital flags</li>
<li>Supports two partitioning formats: FDISK (only 1st primariy partition) and SFD (only 512B/sector)</li>
</ul>
<h4>Features of Tiny-FatFs Module</h4>
<ul>
<li>Only a common buffer for FAT and each file to reduce memory consumption.</li>
<li>Supports two partitioning rules: FDISK (only 1st primariy partition) and SFD</li>
<li>Optimized for 8/16 bit microcontrollers.</li>
<li>Low memory consumption, suitable for small memory system (1KB)</li>
<li>Supports FAT12 and FAT16(+FAT64)</li>
<li>Supports 8.3 format file name and NT lower capital flags</li>
<li>Supports two partitioning formats: FDISK (only 1st primariy partition) and SFD (only 512B/sector)</li>
</ul>
<h4>Features of Tiny-FatFs Module (different to FatFs)</h4>
<ul>
<li>Very low memory consumption, suitable for small memory system (RAM:1KB)</li>
<li>Supports only single drive.</li>
</ul>
</div>
@ -45,19 +43,19 @@
<table class="lst2">
<caption>FatFs</caption>
<tr><th>Section</th><th>Std cfg.</th><th>Min cfg.</th></tr>
<tr><td>Program (R/W cfg.)</td><td>8526</td><td>6042</td></tr>
<tr><td>Program (R/O cfg.)</td><td>4172</td><td>3402</td></tr>
<tr><td>Static Work Area</td><td colspan="2">2</td>
<tr><td>Dynamic Work Area</td><td colspan="2">548 + 540 * &lt;files&gt;</td>
<tr><td>Program (R/W cfg.)</td><td>8574</td><td>6094</td></tr>
<tr><td>Program (R/O cfg.)</td><td>4268</td><td>3494</td></tr>
<tr><td>Static Work Area</td><td colspan="2">2 + 2*&lt;drives&gt;</td>
<tr><td>Dynamic Work Area</td><td colspan="2">550*&lt;drives&gt; + 544*&lt;files&gt;</td>
</table>
</div>
<table class="lst2">
<caption>Tiny-FatFs</caption>
<tr><th>Section</th><th>Std cfg.</th><th>Min cfg.</th></tr>
<tr><td>Program (R/W cfg.)</td><td>7138</td><td>4862</td></tr>
<tr><td>Program (R/O cfg.)</td><td>3542</td><td>2778</td></tr>
<tr><td>Static Work Area</td><td colspan="2">2</td></tr>
<tr><td>Dynamic Work Area</td><td colspan="2">540 + 24 * &lt;files&gt;</td></tr>
<tr><td>Program (R/W cfg.)</td><td>7164</td><td>4890</td></tr>
<tr><td>Program (R/O cfg.)</td><td>3660</td><td>2946</td></tr>
<tr><td>Static Work Area</td><td colspan="2">4</td></tr>
<tr><td>Dynamic Work Area</td><td colspan="2">542 + 28*&lt;files&gt;</td></tr>
</table>
</div>
@ -66,6 +64,7 @@
<h3>Application Interface</h3>
<p>FatFs/Tiny-FatFs module provides following functions.</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>
@ -80,7 +79,7 @@
<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/rename.html">f_rename</a> - Rename/Move a File or Directory</li>
<li><a href="en/mountdrv.html">f_mountdrv</a> - Force Initialized FatFs Module</li>
<li><a href="en/mkfs.html">f_mkfs</a> - Create a File System on the Drive</li>
</ul>
</div>
@ -101,13 +100,16 @@
<div class="para">
<h3>Resources</h3>
<p>The FatFs/Tiny-FatFs module is a free software and is opened for education, research and development. You can use, modify and/or republish it for personal, non-profit or profit use without any restriction under your responsibility.</p>
<br>
<ul>
<li><a href="rwtest.png">Benchmark</a> (Test Board: ATmega64/9.2MHz with <a href="rw_mmc.jpeg">MMC</a>/<a href="rw_ata.jpeg">HDD</a>/<a href="rw_cfc.jpeg">CFC</a>)</li>
<li><a href="en/appnote.html">FatFs module application note</a></li>
<li><a href="img/rwtest.png">Benchmark</a> (Test Board: ATmega64/9.2MHz with <a href="img/rw_mmc.jpeg">MMC</a>/<a href="img/rw_ata.jpeg">HDD</a>/<a href="img/rw_cfc.jpeg">CFC</a>)</li>
<li><a href="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FAT32 Specification</a> (Microsoft)</li>
<li><a href="../../docs/mmc/mmc_e.html">How to Use an MMC</a></li>
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to Use an MMC</a></li>
</ul>
</div>
<hr>
<p class="foot"><a href="../../cc_e.html">Return</a></p>
</body>
</html>

View File

@ -3,6 +3,8 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="start" title="Site Top" href="../../index_j.html">
<link rel="up" title="Freewares" href="../../fsw.html">
<link rel="alternate" hreflang="en" title="English version" href="00index_e.html">
<link rel="stylesheet" href="css_j.css" type="text/css" media="screen" title="ELM Default">
<title>ELM - 汎用FATファイルシステム・モジュール</title>
@ -13,50 +15,46 @@
<hr>
<div class="abst">
<img src="layers.png" class="rset" width="245" height="255">
<p>小規模な組み込みシステム向けの汎用FATファイルシステム・モジュールです。ANSI C準拠でハードウェア・アーキテクチャには依存しないので、必要なワークエリアが確保できれば、PIC, AVR, H8, Z80などほとんどのマイコンでそのまま使用可能です。いろいろな使用形態を考慮して、高速版FatFsと省メモリ版Tiny-FatFsの2通りを作成してみました。実際に使用するには、各記録メディアCFC, MMC, SDC, ATA, USB, SCSI等に対応したディスクI/Oモジュールサンプルありを用意する必要があります。</p>
<h4>FatFsモジュールの特徴</h4>
<img src="img/layers.png" class="rset" width="245" height="255" alt="layer">
<p>小規模な組み込みシステム向けの汎用FATファイルシステム・モジュールです。ANSI C準拠でハードウェア・アーキテクチャには依存しないので、必要なワーク・エリアが確保できれば、8051, AVR, H8, Z80などほとんどのマイコンでそのまま使用可能です。いろいろな使用形態を考慮して、高機能版(<strong>FatFs</strong>)と省メモリ版(<strong>Tiny-FatFs</strong>の2通りを作成してみました。実際に使用するには、各記録メディアCFC, MMC, SDC, ATA, USB, SCSI等に対応したディスクI/Oモジュールサンプルありを用意する必要があります。</p>
<h4>FatFsの特徴</h4>
<ul>
<li>システム用と各ファイル用バッファを分離し、複数ファイルの高速アクセスに適する</li>
<li>8/16ビットマイコン向けにコードを最適化</li>
<li>メモリの消費が少ない</li>
<li>ファイル・システム用とファイルI/O用バッファを分離し、複数ファイルの高速アクセスに適する</li>
<li>FAT12, FAT16(+FAT64), FAT32に対応 <small>(FAT64: FAT16 in 64KB/cluster)</small></li>
<li>複数ドライブをサポート</li>
<li>8.3形式ファイル名とNT小文字フラグに対応</li>
<li>FDISKフォーマット(基本区画)およびSFDフォーマット(512B/sectorのみ)に対応</li>
</ul>
<h4>Tiny-FatFsモジュールの特徴</h4>
<ul>
<li>システム用と各ファイル用バッファを共通化し、RAMの使用量を削減</li>
<li>8/16ビットマイコン向けにコードを最適化</li>
<li>メモリの消費が少なく、小メモリ・システム(1KB)に対応</li>
<li>FAT12, FAT16(+FAT64)に対応</li>
<li>8.3形式ファイル名とNT小文字フラグに対応</li>
<li>FDISKフォーマット(基本区画)およびSFDフォーマット(512B/sectorのみ)に対応</li>
</ul>
<h4>Tiny-FatFsの特徴(FatFsとの相違)</h4>
<ul>
<li>RAMの使用量を削減し、小メモリ・システム(RAM:1KB)にも対応</li>
<li>単一ドライブのみサポート</li>
</ul>
</div>
<div class="para">
<h3>メモリ使用</h3>
<p>いくつかのコンフィギュレーション・オプションにより、不要な関数を削ってモジュールサイズを削減できます。次に実際のメモリ使用量[バイト]を示します(avrgccの例)。</p>
<h3>メモリ使用</h3>
<p>いくつかのコンフィギュレーション・オプションにより、不要な関数を削ってモジュールサイズを削減できます。次に実際のメモリ使用量[バイト]を示します(avrgccの例)。</p>
<div class="lset">
<table class="lst2">
<caption>FatFs</caption>
<tr><th>セクション</th><th>標準</th><th>最小</th></tr>
<tr><td>プログラム(R/W構成)</td><td>8526</td><td>6042</td></tr>
<tr><td>プログラム(R/O構成)</td><td>4172</td><td>3402</td></tr>
<tr><td>静的ワークエリア</td><td colspan="2">2</td>
<tr><td>動的ワークエリア</td><td colspan="2">548 + 540 * &lt;files&gt;</td>
<tr><td>プログラム(R/W構成)</td><td>8574</td><td>6094</td></tr>
<tr><td>プログラム(R/O構成)</td><td>4268</td><td>3494</td></tr>
<tr><td>静的ワークエリア</td><td colspan="2">2 + 2*&lt;drives&gt;</td>
<tr><td>動的ワークエリア</td><td colspan="2">550*&lt;drives&gt; + 544*&lt;files&gt;</td>
</table>
</div>
<table class="lst2">
<caption>Tiny-FatFs</caption>
<tr><th>セクション</th><th>標準</th><th>最小</th></tr>
<tr><td>プログラム(R/W構成)</td><td>7138</td><td>4862</td></tr>
<tr><td>プログラム(R/O構成)</td><td>3542</td><td>2778</td></tr>
<tr><td>静的ワークエリア</td><td colspan="2">2</td></tr>
<tr><td>動的ワークエリア</td><td colspan="2">540 + 24 * &lt;files&gt;</td></tr>
<tr><td>プログラム(R/W構成)</td><td>7164</td><td>4890</td></tr>
<tr><td>プログラム(R/O構成)</td><td>3660</td><td>2946</td></tr>
<tr><td>静的ワークエリア</td><td colspan="2">4</td></tr>
<tr><td>動的ワークエリア</td><td colspan="2">542 + 28*&lt;files&gt;</td></tr>
</table>
</div>
@ -65,6 +63,7 @@
<h3>上位レイヤI/F</h3>
<p>FatFs/Tiny-FatFsモジュールは、次のファイル操作関数を提供しています。</p>
<ul>
<li><a href="ja/mount.html">f_mount</a> - ワークエリアの登録・削除</li>
<li><a href="ja/open.html">f_open</a> - ファイルのオープン・作成</li>
<li><a href="ja/close.html">f_close</a> - ファイルのクローズ</li>
<li><a href="ja/read.html">f_read</a> - ファイルの読み込み</li>
@ -79,7 +78,7 @@
<li><a href="ja/unlink.html">f_unlink</a> - ファイルまたはディレクトリの削除</li>
<li><a href="ja/chmod.html">f_chmod</a> - ファイルまたはディレクトリ属性の変更</li>
<li><a href="ja/rename.html">f_rename</a> - ファイルまたはディレクトリの名前変更・移動</li>
<li><a href="ja/mountdrv.html">f_mountdrv</a> - ファイル・システムの明示的初期化</li>
<li><a href="ja/mkfs.html">f_mkfs</a> - ディスクのフォーマット</li>
</ul>
</div>
@ -99,14 +98,17 @@
<div class="para">
<h3>資料</h3>
<p>FatFs/Tiny-FatFsモジュールはフリーソフトウェアとして教育・研究・開発用に公開しています。どのような利用目的個人・非商用・商用でも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。</p>
<br>
<p>FatFs/Tiny-FatFsモジュールはフリー・ソフトウェアとして教育・研究・開発用に公開しています。どのような利用目的個人・非商用・商用でも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。</p>
<ul>
<li><a href="rwtest.png">パフォーマンス・テスト</a>テストボードATmega64/9.2MHz with <a href="rw_mmc.jpeg">MMC</a>/<a href="rw_ata.jpeg">HDD</a>/<a href="rw_cfc.jpeg">CFC</a></li>
<li><a href="ja/appnote.html">FatFsモジュール・アプリケーション・ート</a></li>
<li><a href="img/rwtest.png">パフォーマンス・テスト</a>テスト・ボードATmega64/9.2MHz with <a href="img/rw_mmc.jpeg">MMC</a>/<a href="img/rw_ata.jpeg">HDD</a>/<a href="img/rw_cfc.jpeg">CFC</a></li>
<li><a href="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FAT32仕様書</a> (Microsoft)</li>
<li><a href="../../docs/mmc/mmc.html">MMCの使いかた</a></li>
<li><a href="http://elm-chan.org/docs/mmc/mmc.html">MMCの使いかた</a></li>
</ul>
</div>
<hr>
<p class="foot"><a href="../../cc.html">戻る</a></p>
</body>
</html>

View File

@ -24,7 +24,7 @@ div.para {clear: both; font-family: serif;}
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0 0 0.5em 0.5em;}
.lset {float: left; margin: 0 0.5em 0.5em 0;}
.lset {float: left; margin: 0 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}

View File

@ -27,7 +27,7 @@ div.para {clear: both; font-family: "
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0 0 0.5em 0.5em;}
.lset {float: left; margin: 0 0.5em 0.5em 0;}
.lset {float: left; margin: 0 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}

108
doc/en/appnote.html Normal file
View File

@ -0,0 +1,108 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs Module Application Note</title>
</head>
<body>
<h1>FatFs Module Application Note (for R0.04)</h1>
<hr>
<div class="para">
<h3>Considerations on porting to various platform</h3>
<p>The FatFs module is assuming following terms on portability.</p>
<ul>
<li>ANSI C<br>
The FatFs module is a middleware that written in ANSI C. There is no platform dependence, so long as the compiler is in compliance with ANSI C. However it handles system portable FAT structures. You must take the <strong>endian</strong> into consideration. This setting is defined in ff.h (tff.h). It must be changed for your platform first or the compiler will abort with an error.</li>
<li>Size of char/short/long is 8/16/32 bit.<br>
This will not be a problem on most C compilers. When any conflict of integer definitions between integer.h and existing definitions is occured, you must resolve the confrict with care.</li>
</ul>
</div>
<div class="para">
<h3>FatFs vs. Tiny-FatFs</h3>
<p>For most applications, such as portable audio and data logger, Tiny-FatFs is the best choice. However because the Tiny-FatFs does not support FAT32 in default, there is a limitation that can handle only tiny storage upto 2GB(4GB in FAT64). The FAT32 support can be added by <tt>_USE_FAT32</tt> option with an additional code size.</p>
<p>FatFs is suitable for accessing multiple files fast, and for multiple drive system.</p>
<div class="rset">
<table class="lst2">
<tr><th>Memory Size</th><th>FAT Type</th></tr>
<tr><td>&lt;= 64MB</td><td>FAT12</td></tr>
<tr><td>128MB - 2GB</td><td>FAT16</td></tr>
<tr><td>&gt;= 4GB</td><td>FAT32</td></tr>
</table>
</div>
<p>Rignt table shows the correspondence between memory size and FAT type for SD memroy card and they are shipped with this format. The data area is justified to the erase block and the memory card works the best performance. For that reason, the memory card should not be reformated with PC. When cluster size or FAT type is changed, the write performance can be worse.</p>
</div>
<div class="para">
<h3>Performance effective file access</h3>
<p>For good performance on reading/writing files on the small embedded system, application program should consider what process is done in the FatFs module. The file data on the disk is transferred by f_read function in following process.</p>
<p>Figure 1. Sector miss-aligned read (short)<br>
<img src="../img/f1.png" width="490" height="73">
</p>
<p>Figure 2. Sector miss-aligned read (long)<br>
<img src="../img/f2.png" width="490" height="140">
</p>
<p>Figure 3. Sector aligned read<br>
<img src="../img/f3.png" width="490" height="119">
</p>
<p>The file I/O buffer means a sector buffer to read/write partial data on the sector. For FatFs, member buffer[] in the file object is used. For Tiny-FatFs, member win[] in the file system object is used.</p>
<p>Tiny-FatFs processes all data transfer and access to the FAT/directory with only one sector buffer, so that FAT sector cached into the buffer is lost and it must reloaded at every cluster boundary. FatFs has a FAT/directory buffer separated from file I/O buffer, the frequency of FAT accesses is only 1/341, 1/256 or 1/128 (when cluster is contiguous) compared to Tiny-FatFs. Thus the Tiny-FatFs is sacrificing its performance in compensation for very small memory footprint.</p>
<p>Figure 1 shows that partial sector data is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that aligned to sector boundary is transferred into memory directly. Figure 3 shows that entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. At the direct transfer, maximum extent of sectors are read with disk_read function at a time but it never across cluster boundary even if it is contiguous.</p>
<p>Therefore taking effort to sector aligned read/write accesss reduces memcpy and read/write performance will be improved. Besides the effect, cached FAT sector on the Tiny-FatFs is not flushed during read/write access, so that it can achieve same performance as FatFs and its small memory footprint simultanesously.</p>
</div>
<div class="para">
<h3>Critical section</h3>
<p>When write operation to the FAT file system is interrupted due to any accidental failure, such as sudden blackout, incorrect disk removal and unrecoverable data error, the FAT structure can be destroyed. Following images shows the critical section on the FatFs module.</p>
<div class="lset">
Figure 4. Long critical section<br>
<img src="../img/f4.png" width="320" height="470" alt="fig.4">
</div>
<div class="lset">
Figure 5. Minimized critical section<br>
<img src="../img/f5.png" width="320" height="470" alt="fig.5">
</div>
<br class="clr">
<p>An interruption in the red section can cause a cross link; as a result, the file/directory is lost. There is one or more possibility listed below when an interruption in the yellow section is occured.</p>
<ul>
<li>File data being rewrited is collapted.</li>
<li>A file being appended returns initial state.</li>
<li>A file created as new is gone.</li>
<li>A file created as new remains with length of zero.</li>
<li>A file created in overwrite remains with length of zero.</li>
<li>A file created in overwrite returns initial state.</li>
<li>Efficiency of disk use gets worse due to lost chain.</li>
</ul>
<p>Every case does not affect the files that not in write operation. 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 and using f_sync function properly.</p>
</div>
<div class="para">
<h3>Problems and Ideas</h3>
<ul>
<li>Abstraction of file object<br>
Currently the file object structure is held by application layer. This is not a problem for Tiny-FatFs, it consumes the task stack only 26 bytes per file. But FatFs requires 550 bytes per file. When manage the file objects in file handle, stack consumption at application module will able to be reduced. In this case, the work area for file objects is managed in FatFs module. This has a disadvantage that direct access to the file object structure cannot be used and additional file functions, such as feof and ftell, will be needed.</li>
<li>Efficient sector buffer management<br>
The FatFs module has only one sector buffer per logical drive. There is an ineffciency on random file access with many files simultanesously. When additional memory for the sector buffer is available, the file access performance will able to be improved with an advanced cache mechanism.</li>
<li>FSInfo sector<br>
On FAT32 file system, the cluster search to create a file as new or get number of free clusters takes time due to a great many clusters. The FSInfo sector that has last allocated cluster number and number of free clusters is provided to prevent the silly cluster search. However the FatFs module does not support this feature.</li>
<li>Long file name<br>
There is an extended feature to handle long file name (LFN) up to 255 characters, in addition to 8.3 format file name, on FAT file system. To support this, 512 byte string buffer for file name and UCS-2 - Shift_JIS mutual conversion table are required. Therefore memory consumption of code and work area will be increased drastically. The FatFs module does not support this feature. The LFN on the FAT file system is a patent of Microsoft. When support it on the commercial products, you have to be licensed.</li>
<li>Porting to RTOS<br>
When use FatFs module from only one task, no consideration is needed. However when use it from two or more tasks simultanesously, any exclusion control will be required. Porting of FatFs module to &mu;ITRON is in progress by <a href="http://www.toppers.jp/">TOPPERS Project</a>.</li>
</ul>
<br>
<p>These are the problems and ideas on current revision of FatFs module. However the main target of FatFs module is 8 bit microcontrollers. These extensions requires much resource and the FatFs will unable to be ported to the 8 bit system. This may be the most serious problem on future plan.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -12,12 +12,12 @@
<div class="para">
<h2>f_chmod</h2>
<p>The f_chmod changes the attribute of a file or directory.</p>
<p>The f_chmod function changes the attribute of a file or directory.</p>
<pre>
FRESULT f_chmod (
const char* <em>FileName</em>, // Pointer to the file or directory
BYTE <em>Attribute</em>, // Attribute flags
BYTE <em>AttributeMask</em> // Attribute masks
const char* <em>FileName</em>, /* Pointer to the file or directory */
BYTE <em>Attribute</em>, /* Attribute flags */
BYTE <em>AttributeMask</em> /* Attribute masks */
);
</pre>
</div>
@ -26,7 +26,7 @@ FRESULT f_chmod (
<h4>Parameter</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies a file or directory to be changed</dd>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be changed</dd>
<dt>Attribute</dt>
<dd>Attribute flags to be set in one or more combination of the following flags. The specified flags are set and others are cleard.<br>
<table class="lst">
@ -54,16 +54,16 @@ FRESULT f_chmod (
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The file name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</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>
<dd>The medium is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -72,14 +72,14 @@ FRESULT f_chmod (
<div class="para">
<h4>Description</h4>
<p>The f_chmod changes the attribute of a file or directory. This function is not supported in read-only configuration and minimization level of &gt;=1.</p>
<p>The f_chmod function changes the attribute of a file or directory. This function is not supported in read-only configuration and minimization level of &gt;=1.</p>
</div>
<div class="para">
<h4>Example</h4>
<pre>
// Set read-only flag, clear archive flag and others are left unchanged.
// Set read-only flag, clear archive flag and others are retained.
f_chmod("file.txt", AR_RDO, AR_RDO | AR_ARC);
</pre>
</div>

View File

@ -12,10 +12,10 @@
<div class="para">
<h2>f_close</h2>
<p>Function f_close closes a file.</p>
<p>The f_close function closes an open file.</p>
<pre>
FRESULT f_close (
FIL* <em>FileObject</em> // Pointer to the file object structure
FIL* <em>FileObject</em> /* Pointer to the file object structure */
);
</pre>
</div>
@ -24,7 +24,7 @@ FRESULT f_close (
<h4>Parameter</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the file object structure to be closed.</dd>
<dd>Pointer to the open file object structure to be closed.</dd>
</dl>
</div>
@ -33,20 +33,20 @@ FRESULT f_close (
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The file has been closed successfuly.</dd>
<dd>The file object has been closed successfuly.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>Any error has occured in low level disk I/O.</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_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>Function f_close closes a file. If any data has been written, the cached information of the file is written back to the disk. When the function succeeded, the file object is no longer valid and structure can be discarded.</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

@ -12,20 +12,31 @@
<div class="para">
<h2>disk_initialize</h2>
<p>The disk_initialize initializes the disk drive.</p>
<p>The disk_initialize function initializes the disk drive.</p>
<pre>
DSTATUS disk_initialize ();
DSTATUS disk_initialize (
BYTE <em>Drive</em> /* Physical drive number */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to initialize.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<p>This function returns a disk status. For details of the disk status, refer to the <tt><a href="dstat.html">disk_status()</a></tt>.</p>
<p>This function returns a disk status as the result. For details of the disk status, refer to the <a href="dstat.html">disk_status</a> function.</p>
</div>
<div class="para">
<h4>Description</h4>
<p>The disk_initialize initializes the disk drive. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value will be cleard.</p>
<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>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>

View File

@ -12,12 +12,13 @@
<div class="para">
<h2>disk_read</h2>
<p>The disk_read reads sector(s) from the disk drive.</p>
<p>The disk_read function reads sector(s) from the disk drive.</p>
<pre>
DRESULT disk_read (
BYTE* <em>Buffer</em>, // Pointer to the read buffer.
DWORD <em>SectorNumber</em>, // Sector number to read from.
BYTE <em>SectorCount</em> // Number of sectros to read.
BYTE <em>Drive</em>, /* Physical drive number */
BYTE* <em>Buffer</em>, /* Pointer to the read buffer */
DWORD <em>SectorNumber</em>, /* Sector number to read from */
BYTE <em>SectorCount</em> /* Number of sectros to read */
);
</pre>
</div>
@ -25,6 +26,8 @@ DRESULT disk_read (
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to read.</dd>
<dt>Buffer</dt>
<dd>Pointer to the read buffer to store the read data. <tt>SectorCount * 512</tt> bytes is required for the size of the read buffer.</dd>
<dt>SectorNumber</dt>

View File

@ -12,22 +12,33 @@
<div class="para">
<h2>disk_status</h2>
<p>The disk_status gets the disk status.</p>
<p>The disk_status function gets the disk status.</p>
<pre>
DSTATUS disk_status ();
DSTATUS disk_status (
BYTE <em>Drive</em> /* Physical drive number */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to be tested.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<p>The disk status is returned in combinatin of following flags.</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>Indicates that the disk drive has not been initialiezed. This flag is set when power-on, occurrence of disk removal or <tt>disk_initialize()</tt> failed and cleared when <tt>disk_initialize()</tt> succeeded.</dd>
<dd>Indicates that the disk drive has not been initialiezed. This flag is set on: power-on, disk removal and disk_initialize function failed, and cleared on: disk_initialize function succeeded.</dd>
<dt>STA_NODISK</dt>
<dd>Indicates that no disk in the drive. It is always cleared on non-removable drive.</dd>
<dd>Indicates that no medium in the drive. It is always cleared on fixed disk drive.</dd>
<dt>STA_PROTECTED</dt>
<dd>Indicates that the disk is write protected. It is always cleared on the disk that has not write protect notch.</dd>
<dd>Indicates that the medium is write protected. It is always cleared on the drive that does not support write protect notch.</dd>
</dl>
</div>

View File

@ -15,9 +15,10 @@
<p>The disk_write writes sector(s) to the disk.</p>
<pre>
DRESULT disk_write (
const BYTE* <em>Buffer</em>, // Pointer to the data to be written.
DWORD <em>SectorNumber</em>, // Sector number to write.
BYTE <em>SectorCount</em> // Number of sectors to write.
BYTE <em>Drive</em>, /* Physical drive number */
const BYTE* <em>Buffer</em>, /* Pointer to the read buffer */
DWORD <em>SectorNumber</em>, /* Sector number to write */
BYTE <em>SectorCount</em> /* Number of sectors to write */
);
</pre>
</div>
@ -25,6 +26,8 @@ DRESULT disk_write (
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Specifies the physical drive number to write.</dd>
<dt>Buffer</dt>
<dd>Pointer to the data to be written.</dd>
<dt>SectorNumber</dd>

View File

@ -12,9 +12,9 @@
<div class="para">
<h2>get_fattime</h2>
<p>The get_fattime gets current time.</p>
<p>The get_fattime function gets current time.</p>
<pre>
DWORD get_fattime ();
DWORD get_fattime (void);
</pre>
</div>
@ -41,7 +41,7 @@ DWORD get_fattime ();
<div class="para">
<h4>Description</h4>
<p>The function must return any valid time even if the system does not support a real time clock. The get_fattime is not required in read only configuration.</p>
<p>The get_fattime function must return any valid time even if the system does not support a real time clock. This fucntion is not required in read only configuration.</p>
</div>

36
doc/en/filename.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - File and Path name on the FatFs module</title>
</head>
<body>
<h2>File and Path name on the FatFs module</h2>
<div class="para">
<p>The format of file and path name on the FatFs module is similer to MS-DOS. However does not have a concept of current directory, all objects on the drive are specified in full path from the roor directory.</p>
<pre>
"<em>Drive#</em>:<em>directory</em>/<em>file</em>"
"file1.txt" a file on drive 0
"/file1.txt" (same as above)
"dir1/dir2/file1.txt" a file on drive 0
"2:dir3/file2.txt" a file on drive 2
"2:/dir5" a directory on drive 2
"" the root directory on drive 0
"/" (same as above)
"2:" the root directory on drive 2
</pre>
<p>The FatFs module supports only 8.3 format file name and long file name is currentry not supported. For directory separator, a '/' is used, not a '\'.</p>
<p>The FatFs module has work areas that called file system object for each logical drive. The logical drive number is specified in a numeral with a colon. When drive number is omitted, it means the default drive (0). The logical drive is bound to the physical drive that has same drive number.</p>
<p>As for the Tiny-FatFs, it has only one logical drive and always works as drive 0. Any drive number cannot be contained in the path name.</p>
</div>
</body>
</html>

View File

@ -12,10 +12,12 @@
<div class="para">
<h2>f_getfree</h2>
<p>The f_getfree gets number of the free clusters.</p>
<p>The f_getfree function gets number of the free clusters.</p>
<pre>
FRESULT f_getfree (
DWORD* <em>Clusters</em> // Pointer to the variable to store number of free clusters.
const char* <em>Path</em>, /* Root directory of the drive */
DWORD* <em>Clusters</em>, /* Pointer to the variable to store number of free clusters */
FATFS** <em>FileSystemObject</em> /* Pointer to pointer to file system object */
);
</pre>
</div>
@ -23,8 +25,12 @@ FRESULT f_getfree (
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Path</dt>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">root directory</a> of the logical drive. Always specify a null-string for Tiny-FatFs.</dd>
<dt>Clusters</dt>
<dd>Pointer to the DWORD variable to store number of free clusters.</dd>
<dt>FileSystemObject</dt>
<dd>Pointer to the pointer that to be stored the pointer to corresponding file system object.</dd>
</dl>
</div>
@ -33,15 +39,15 @@ FRESULT f_getfree (
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded. The <tt><em>*Clusters</em></tt> havs number of free clusters.</dd>
<dd>The function succeeded. The <tt><em>*Clusters</em></tt> havs number of free clusters and <tt><em>*FileSystemObject</em></tt> points the file system object.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</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_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -50,21 +56,26 @@ FRESULT f_getfree (
<div class="para">
<h4>Descriptions</h4>
<p>The f_getfree gets number of free clusters on the drive. The <tt>FatFs.sects_clust</tt> is indicating number of sectors per cluster, so that the free space in unit of byte can be calcurated with this. This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
<p>The f_getfree function gets number of free clusters on the drive. The <tt>sects_clust</tt> member in the file system object refreting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
</div>
<div class="para">
<h4>Samples Code</h4>
<pre>
FATFS *fs;
DWORD clust;
// Get free clusters
res = f_getfree(&clust);
res = f_getfree("", &clust, &fs);
if (res) die(res);
// Get free bytes
printf("%lu bytes available on the disk.\n", clust * FatFs->sects_clust * 512);
// Get free space
printf("%lu KB total disk space.\n"
"%lu KB available on the disk.\n",
(fs->max_clust - 2) * fs->sects_clust / 2,
clust * fs->sects_clust / 2);
</pre>
</div>

View File

@ -12,11 +12,11 @@
<div class="para">
<h2>f_lseek</h2>
<p>The f_lseek moves the file read/write pointer.</p>
<p>The f_lseek functione moves the file read/write pointer of an open file object.</p>
<pre>
FRESULT f_lseek (
FIL* <em>FileObject</em>, // Pointer to the file object structure
DWORD <em>Offset</em> // File offset in unit of byte
FIL* <em>FileObject</em>, /* Pointer to the file object structure *
DWORD <em>Offset</em> /* File offset in unit of byte *
);
</pre>
</div>
@ -25,7 +25,7 @@ FRESULT f_lseek (
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the file object structure.</dd>
<dd>Pointer to the open file object.</dd>
<dt>Offset</dt>
<dd>Number of bytes where from start of file</dd>
</dl>
@ -39,17 +39,17 @@ FRESULT f_lseek (
<dd>The function succeeded.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal, such as a medium change during any file is opend, has been occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</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_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The f_lseek moves the file read/write pointer. The offset can be specified in only origin from top of the file and cannot moved to above end of the file. When an offset above the file size was specified, the read/write pointer moves to end of the file.</p>
<p>The f_lseek function moves the file read/write pointer of an open file object. The offset can be specified in only origin from top of the file and cannot moved to above end of the file. When an offset above the file size was specified, the read/write pointer moves to end of the file.</p>
</div>
@ -66,7 +66,7 @@ FRESULT f_lseek (
res = f_lseek(&file, file.fptr - 2000);
// Move to end of the file
res = f_lseek(&file, 0xFFFFFFFF);
res = f_lseek(&file, file.fsize);
</pre>
</div>

View File

@ -12,10 +12,10 @@
<div class="para">
<h2>f_mkdir</h2>
<p>The f_mkdir creates a directory.</p>
<p>The f_mkdir function creates a new directory.</p>
<pre>
FRESULT f_mkdir (
const char* <em>DirName</em> // Pointer to the directory name
const char* <em>DirName</em> /* Pointer to the directory name */
);
</pre>
</div>
@ -24,7 +24,7 @@ FRESULT f_mkdir (
<h4>Parameter</h4>
<dl class="par">
<dt>DirName</dt>
<dd>Pointer to the null-terminated string that specifies the full-path directory name to create. The directory separator is <tt>'/'</tt>. Because the FatFs module does not have a concept of current directory, a full-path name that followed from the root directory must be used. Leading space charactors are skipped if exist and heading <tt>'/'</tt> can be exist or omitted.</dd>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory name</a> to create. </dd>
</dl>
</div>
@ -38,6 +38,8 @@ FRESULT f_mkdir (
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The path name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</dd>
<dt>FR_DENIED</dt>
<dd>The function was denied due to any of following reasons: any file or directory that has same name is existing, cannot be created due to directory table or disk is full.</dd>
<dt>FR_NOT_READY</dt>
@ -46,10 +48,8 @@ FRESULT f_mkdir (
<dd>The medium is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -58,7 +58,7 @@ FRESULT f_mkdir (
<div class="para">
<h4>Description</h4>
<p>The f_mkdir creates an empty directory. This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
<p>The f_mkdir function creates a new directory. This function is not supported in read-only configuration and minimization level of &gt;= 1.</p>
<p>
</p>
</div>

70
doc/en/mkfs.html Normal file
View File

@ -0,0 +1,70 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mkfs</title>
</head>
<body>
<div class="para">
<h2>f_mkfs</h2>
<p>The f_mkfs fucntion creates a file system on the drive.</p>
<pre>
FRESULT f_mkfs (
BYTE <em>Drive</em>, /* Logical drive number */
BYTE <em>PartitioningRule</em>, /* Partitioning rule */
BYTE <em>AllocSize</em> /* Allocation unit size */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Logical drive number (0-9) to be formatted.</dd>
<dt>PartitioningRule</dt>
<dd>When 0 is given, a partition table is created into first sector on the drive and then the file system is created on the partition. This is called FDISK format. When 1 is given, the file system starts from the first sector without partition table. This is often called super floppy (SFD) format.</dd>
<dt>AllocSize</dt>
<dd>Specifies allocation unit size (number of sectors per cluster). The value must be power of 2 in range of from 1 to 64.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</dd>
<dt>FR_NOT_READY</dt>
<dd>The drive cannot work due to any reason.</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>The drive is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>The function failed due to a write error in the low level disk I/O.</dd>
<dt>FR_MKFS_ABORTED</dt>
<dd>The function aborted before start in format due to a reason as follows.
<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>
</ul>
</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The f_mkfs function creates a FAT file system on the drive. There are two partitioning rules, FDISK and SFD, for removable media. It can be selected with a parameter and FDISK format is recommended for most case. The FAT type, FAT12/FAT16/FAT32, is determined by only how many clusters on the drive and nothing else, according to FAT specification. Thus which FAT type is selected, is depends on the drive size and specified cluster size.</p>
<p>This function is supported on only FatFs with _USE_MKFS option.<p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

59
doc/en/mount.html Normal file
View File

@ -0,0 +1,59 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mount</title>
</head>
<body>
<div class="para">
<h2>f_mount</h2>
<p>The f_mount fucntion registers/unregisters a work area to the FatFs module.</p>
<pre>
FRESULT f_mount (
BYTE <em>Drive</em>, /* Logical drive number */
FATFS* <em>FileSystemObject</em> /* Pointer to the work area */
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>Drive</dt>
<dd>Logical drive number (0-9) to register/unregister the work area. Always 0 for Tiny-FatFs.</dd>
<dt>FileSystemObject</dt>
<dd>Pointer to the work area (file system object) to be registered.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</dd>
</dl>
</div>
<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 logical drive with this function before using any 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 work area and registers its address to the internal table, any access to the disk I/O layer does not occure. Actual mounting process is performed in any other file funcitons when it is needed.<p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -12,12 +12,12 @@
<div class="para">
<h2>f_open</h2>
<p>The f_open function creates or opens the file and initialize a file object structure to be used to access the file.</p>
<p>The f_open function creates a <em>file object</em> to be used to access the file.</p>
<pre>
FRESULT f_open (
FIL* <em>FileObject</em>, // Pointer to the file object structure
const char* <em>FileName</em>, // Pointer to the file neme
BYTE <em>ModeFlags</em> // Mode flags
FIL* <em>FileObject</em>, /* Pointer to the blank file object structure */
const char* <em>FileName</em>, /* Pointer to the file neme */
BYTE <em>ModeFlags</em> /* Mode flags */
);
</pre>
</div>
@ -26,9 +26,9 @@ FRESULT f_open (
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the blank file object structure to be initialized. After the f_open() succeeded, the file can be accessed with the file object structure until it is closed.</dd>
<dd>Pointer to the file object structure to be created. After the f_open funciton succeeded, the file can be accessed with the file object structure until it is closed.</dd>
<dt>FileName</dt>
<dd>Pointer to a null-terminated string specifies the full-path file name to create or open. The directory separator is <tt>'/'</tt>. Because the FatFs module does not have a concept of current directory, a full-path name that followed from the root directory must be used. Leading space charactors are skipped if exist, and heading <tt>'/'</tt> can be exist or omitted.</dd>
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to create or open.</dd>
<dt>ModeFlags</dt>
<dd>Specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
<table class="lst">
@ -48,13 +48,15 @@ FRESULT f_open (
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded. The <tt><em>FileObject</em></tt> structure is used for subsequent calls to refer to the file. When close the file, use function <tt><a href="close.html">f_close()</a></tt>.</dd>
<dd>The function succeeded and the file object is valid.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the file.</dd>
<dt>FR_NO_PATH</dt>
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The file name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</dd>
<dt>FR_DENIED</dt>
<dd>The required access was denied due to any of following reasons: write mode open of a file that has read-only attribute, file creation under existing a same name directory or read-only file, cannot be created due to the directory table or disk full.</dd>
<dt>FR_NOT_READY</dt>
@ -63,10 +65,8 @@ FRESULT f_open (
<dd>Write mode open or creation under the medium is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -75,7 +75,8 @@ FRESULT f_open (
<div class="para">
<h4>Description</h4>
<p>To start FatFs module, prepare a work area (<tt>FATFS</tt> structure), fill it with zero and set its address to the global variable <em>FatFs</em> to give the work area to the FatFs module. All file functions can work after the initialization. <a href="mountdrv.html">f_mountdrv()</a> can also be used instead of the zero filling, however, the physical drive must be ready at that time. To terminate use of the FatFs module, close all files, clear <em>FatFs</em> and then the work area can be discarded.</p>
<p>The created file object is used for subsequent calls to refer to the file. When close an open file object, use <a href="close.html">f_close</a> function.</p>
<p>Before using any file function, work area (file system object) must be given to each logical drive with <a href="mount.html">f_mount</a> function. All file functions can work after this procedure.</p>
<p>Flags <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt> are not supported in read-only configuration.</p>
</div>
@ -85,16 +86,15 @@ FRESULT f_open (
<pre>
void main ()
{
FATFS fs; // FatFs work area
FIL fsrc, fdst; // file structures
FATFS fs; // Work area (file system object) for logical drive
FIL fsrc, fdst; // file objects
BYTE buffer[4096]; // file copy buffer
FRESULT res; // FatFs function common result code
WORD br, bw; // File R/W count
// Give a work area to FatFs module (activate FatFs module)
FatFs = &fs;
memset(&fs, 0, sizeof(FATFS)); // Clear work area. f_mountdrv() can also be used instead.
// Register a work area to logical drive 0
f_mount(0, &fs);
// Open source file
res = f_open(&fsrc, "srcfile.dat", FA_OPEN_EXISTING | FA_READ);
@ -107,7 +107,7 @@ void main ()
// Copy source to destination
for (;;) {
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
if (res || br == 0) break; // error or eof
if (res || br == 0) break; // error or eof
res = f_write(&fdst, buffer, br, &bw);
if (res || bw &lt; br) break; // error or disk full
}
@ -116,8 +116,8 @@ void main ()
f_close(&fsrc);
f_close(&fdst);
// Deactivate FatFs module
FatFs = NULL;
// Unregister a work area before discard it
f_mount(0, NULL);
}
</pre>
</div>

View File

@ -12,11 +12,11 @@
<div class="para">
<h2>f_opendir</h2>
<p>The f_opendir opens a directory.</p>
<p>The f_opendir function opens a directory.</p>
<pre>
FRESULT f_opendir (
DIR* <em>DirObject</em>, // Pointer to blank directory object structure
const char* <em>DirName</em> // Pointer to the directory name
DIR* <em>DirObject</em>, /* Pointer to the blank directory object structure */
const char* <em>DirName</em> /* Pointer to the directory name */
);
</pre>
</div>
@ -25,9 +25,9 @@ FRESULT f_opendir (
<h4>Parameter</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>Pointer to the blank directory object to be initialized</dd>
<dd>Pointer to the blank directory object to be created.</dd>
<dt>DirName</dt>
<dd>Pinter to the null-terminated string that specifies the full-path directory name to be opened. The directory separator is <tt>'/'</tt>. Because the FatFs module does not have a concept of current directory, a full-path name that followed from the root directory must be used. Leading space charactors are skipped if exist and heading <tt>'/'</tt> can be exist or omitted. The target directory name cannot be followed by a <tt>'/'</tt>. When open the root directory, specify <tt>&quot;&quot;</tt> or <tt>&quot;/&quot;</tt>.</dd>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
</dl>
</div>
@ -36,21 +36,21 @@ FRESULT f_opendir (
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded. The <tt><em>DirObject</em></tt> structure is used for subsequent calls to read the directory entries.</dd>
<dd>The function succeeded and the directory object is created. It is used for subsequent calls to read the directory entries.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the directory.</dd>
<dt>FR_NO_PATH</dt>
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The path name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</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_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -59,7 +59,7 @@ FRESULT f_opendir (
<div class="para">
<h4>Description</h4>
<p>The f_opendir opens a directory and initializes the <tt><em>DirObject</em></tt> structure for subsequent calls. The directory object structure can be discarded at any time. This function is not supported in minimization level 2.</p>
<p>The f_opendir function opens an exsisting directory and creates the directory object for subsequent calls. The directory object structure can be discarded at any time without any procedure. This function is not supported in minimization level 2.</p>
</div>

View File

@ -12,13 +12,13 @@
<div class="para">
<h2>f_read</h2>
<p>The f_read reads data from a file.</p>
<p>The f_read function reads data from a file.</p>
<pre>
FRESULT f_read (
FIL* <em>FileObject</em>, // Pointer to the file object structure
void* <em>Buffer</em>, // Pointer to the buffer to store read data
WORD <em>ByteToRead</em>, // Number of bytes to read
WORD* <em>ByteRead</em> // Pointer to the variable to return number of bytes read
FIL* <em>FileObject</em>, /* Pointer to the file object structure */
void* <em>Buffer</em>, /* Pointer to the buffer to store read data */
WORD <em>ByteToRead</em>, /* Number of bytes to read */
WORD* <em>ByteRead</em> /* Pointer to the variable to return number of bytes read */
);
</pre>
</div>
@ -27,7 +27,7 @@ FRESULT f_read (
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the valid file object structure.</dd>
<dd>Pointer to the open file object.</dd>
<dt>Buffer</dt>
<dd>Pointer to the buffer to store read data</dd>
<dt>ByteToRead</dt>
@ -46,18 +46,18 @@ FRESULT f_read (
<dt>FR_DENIED</dt>
<dd>The function denied due to the file has been opened in write only mode.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dd>Any error has occured in low level disk I/O.</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_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The read/write pointer increases in number of bytes read. The <tt>ByteRead</tt> will be less than <tt>ByteToRead</tt> when the read pointer reached to end of the file or any error occured during the read operation.</p>
<p>The file pointer in the file object increases in number of bytes read. The <tt>ByteRead</tt> will become less than <tt>ByteToRead</tt> when the read pointer reached to end of the file or any error occured during the read operation.</p>
</div>

View File

@ -12,11 +12,11 @@
<div class="para">
<h2>f_readdir</h2>
<p>The f_readdir reads directory items.</p>
<p>The f_readdir function reads directory entries.</p>
<pre>
FRESULT f_readdir (
DIR* <em>DirObject</em>, // Pointer to the directory object strcture
FILINFO* <em>FileInfo</em> // Pointer to the blank file information structure
DIR* <em>DirObject</em>, /* Pointer to the directory object strcture */
FILINFO* <em>FileInfo</em> /* Pointer to the blank file information structure */
);
</pre>
</div>
@ -25,7 +25,7 @@ FRESULT f_readdir (
<h4>Parameters</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>Pointer to the valid directory object strcture.</dd>
<dd>Pointer to the open directory strcture.</dd>
<dt>FileInfo</dt>
<dd>Pointer to the file information structure to store the read item.</dd>
</dl>
@ -41,15 +41,15 @@ FRESULT f_readdir (
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>The directory object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The f_readdir reads directory items in sequence. All items in the directory can be read by calling f_readdir repeatedly. When all items have been read and no item to read, the member <tt>f_name[]</tt> in the file information structure gets a null string. For details of the file informations, refer to the <tt>FILINFO</tt>. This function is not supported in minimization level of 2.</p>
<p>The f_readdir function reads directory entries in sequence. All items in the directory can be read by calling f_readdir function repeatedly. When all directory items have been read and no item to read, the function returns a null string into <tt>f_name[]</tt> member without any error. For details of the file informations, refer to the <tt>FILINFO</tt>. This function is not supported in minimization level of 2.</p>
</div>

View File

@ -15,8 +15,8 @@
<p>Rename file or directory.</p>
<pre>
FRESULT f_rename (
const char* <em>OldName</em>, // Pointer to old object name
const char* <em>NewName</em> // Pointer to new object name
const char* <em>OldName</em>, /* Pointer to old file/directory name */
const char* <em>NewName</em> /* Pointer to new file/directory name */
);
</pre>
</div>
@ -25,9 +25,9 @@ FRESULT f_rename (
<h4>Parameter</h4>
<dl class="par">
<dt>OldName</dt>
<dd>Pointer to a null-terminated string specifies the old object name to be renamed.</dd>
<dd>Pointer to a null-terminated string specifies the old <a href="filename.html">file/directory name</a> to be renamed.</dd>
<dt>NewName</dt>
<dd>Pointer to a null-terminated string specifies the new object name. Existing name cannot be used.</dd>
<dd>Pointer to a null-terminated string specifies the new file/directory name without drive number. Existing object nannot be specified.</dd>
</dl>
</div>
@ -38,11 +38,13 @@ FRESULT f_rename (
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the file or directory.</dd>
<dd>Could not find the file nor directory.</dd>
<dt>FR_NO_PATH</dt>
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The file name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</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_DENIED</dt>
@ -51,10 +53,8 @@ FRESULT f_rename (
<dd>The medium is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -63,8 +63,8 @@ FRESULT f_rename (
<div class="para">
<h4>Description</h4>
<p>Rename a file or directory and can move it to other directory. This function is not supported in read-only configuration or minimization level of &gt;= 1.</p>
<p>Note: In this revision, moving any directory to other directory collapses the file system.</p>
<p>Rename a file or directory and can move it to other directory. Logical drive number is determined by old name, new name must not contain logical drive number. This function is not supported in read-only configuration or minimization level of &gt;= 1.</p>
<p>Note: In this revision, moving any directory to other directory collapses the FAT structure on the disk.</p>
</div>

View File

@ -12,23 +12,27 @@
<div class="para">
<h2>DIR</h2>
<p>The <tt>DIR</tt> structure is used for the work area to read a directory.</p>
<p>The <tt>DIR</tt> structure is used for the work area to read a directory by f_oepndir and f_readdir functions.</p>
<h4>FatFs</h4>
<pre>
typedef struct _DIR {
DWORD sclust; // Directory start cluster
DWORD clust; // Current reading cluster
DWORD sect; // Current reading sector
WORD index; // Current index
FATFS* fs; /* Pointer to the owner file system object */
DWORD sclust; /* Start cluster */
DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
</pre>
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _DIR {
WORD sclust; // Directory start cluster
WORD clust; // Current reading cluster
DWORD sect; // Current reading sector
WORD index; // Current index
FATFS* fs; /* Pointer to the owner file system object */
CLUST sclust; /* Start cluster */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
</pre>
</div>

View File

@ -12,17 +12,16 @@
<div class="para">
<h2>FATFS</h2>
<p>The <tt>FATFS</tt> structure holds dynamic work area of the FatFs modlue and it is allocated by an application program. There is no members that can be changed from the application program.</p>
<p>The <tt>FATFS</tt> structure holds dynamic work area of individual logical drives. It is given by application program and registerd/unregisterd to the FatFs module with f_mount function. There is no member that can be changed from the application program.</p>
<h4>FatFs</h4>
<pre>
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE fs_type; /* FAT type (0:Not mouted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
BYTE drive; /* Physical drive number */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD sects_fat; /* Sectors per fat */
DWORD max_clust; /* Maximum cluster# + 1 */
@ -30,6 +29,7 @@ typedef struct _FATFS {
DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */
DWORD database; /* Data start sector */
DWORD last_clust; /* Last allocated cluster */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT */
} FATFS;
</pre>
@ -37,20 +37,19 @@ typedef struct _FATFS {
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE fs_type; /* FAT type (0:Not mouted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
WORD sects_fat; /* Sectors per fat */
WORD max_clust; /* Maximum cluster# + 1 */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector */
DWORD database; /* Data start sector */
WORD last_clust; /* Last allocated cluster */
CLUST sects_fat; /* Sectors per fat */
CLUST max_clust; /* Maximum cluster# + 1 */
CLUST last_clust; /* Last allocated cluster */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
} FATFS;
</pre>

View File

@ -12,36 +12,40 @@
<div class="para">
<h2>FIL</h2>
<p>The FIL structure holds state of a file and it is allocated by an application program. There is no member that can be changed by the application program.</p>
<p>The FIL structure (file object) holds state of a file. It is created by f_open function and discarded by f_close function. There is no member that can be changed by the application program.</p>
<h4>FatFs</h4>
<pre>
typedef struct _FIL {
DWORD fptr; // File R/W pointer
DWORD fsize; // File size
DWORD org_clust; // File start cluster
DWORD curr_clust; // Current cluster
DWORD curr_sect; // Current sector
DWORD dir_sect; // Sector# containing the directory entry
BYTE* dir_ptr; // Ponter to the directory entry in the window
BYTE flag; // File status flags
BYTE sect_clust; // Left sectors in current cluster
BYTE buffer[512]; // File R/W buffer
FATFS* fs; /* Pointer to the owner file system object */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster */
DWORD curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
BYTE buffer[512]; /* File R/W buffer */
} FIL;
</pre>
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _FIL {
DWORD fptr; // File R/W pointer
DWORD fsize; // File size
WORD org_clust; // File start cluster
WORD curr_clust; // Current cluster
DWORD curr_sect; // Current sector
DWORD dir_sect; // Sector# containing the directory entry
BYTE* dir_ptr; // Ponter to the directory entry in the window
BYTE flag; // File status flags
BYTE sect_clust; // Left sectors in current cluster
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
} FIL;
</pre>
</div>

View File

@ -15,8 +15,8 @@
<p>The f_stat gets the file status.</p>
<pre>
FRESULT f_stat (
const char* <em>FileName</em>, // Pointer to the file or directory name
FILINFO* <em>FileInfo</em> // Pointer to the FILINFO structure
const char* <em>FileName</em>, /* Pointer to the file or directory name */
FILINFO* <em>FileInfo</em> /* Pointer to the FILINFO structure */
);
</pre>
</div>
@ -25,9 +25,9 @@ FRESULT f_stat (
<h4>Parameters</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies the file or directory name to get the information. Do not specify root directory.</dd>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">file or directory</a> to get its information. Do not specify root directory.</dd>
<dt>FileInfo</dt>
<dd>Pointer to the <tt>FILINFO</tt> structure to store the information.</dd>
<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information.</dd>
</dl>
</div>
@ -43,14 +43,14 @@ FRESULT f_stat (
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The file name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</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_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>

View File

@ -12,10 +12,10 @@
<div class="para">
<h2>f_sync</h2>
<p>The f_sync flushes the cached information of the wriiting file.</p>
<p>The f_sync function flushes the cached information of a wriiting file.</p>
<pre>
FRESULT f_sync (
FIL* <em>FileObject</em> // Pointer to the file object structure
FIL* <em>FileObject</em> /* Pointer to the file object */
);
</pre>
</div>
@ -24,7 +24,7 @@ FRESULT f_sync (
<h4>Parameters</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the file object to be flushed.</dd>
<dd>Pointer to the open file object to be flushed.</dd>
</dl>
</div>
@ -35,18 +35,18 @@ FRESULT f_sync (
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has been occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>Any error has occured in low level disk I/O.</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_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The function f_sync() performs the same process as f_close() but the file is left opened and can continue file read/write operations to the file. This is suitable for applications that open files for a long time in writing mode, such as data logger. Performing f_sync() of periodic or immediataly after f_write() can minimize risk of data loss due to sudden blackout or unintentional disk removal. This function is not supported in read-only configuration.</p>
<p>The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for applications that open files for a long time in writing mode, such as data logger. Performing f_sync of periodic or immediataly after f_write can minimize risk of data loss due to sudden blackout or unintentional disk removal. This function is not supported in read-only configuration.</p>
</div>

View File

@ -15,7 +15,7 @@
<p>The f_unlink removes file or directory.</p>
<pre>
FRESULT f_unlink (
const char* <em>FileName</em> // Pointer to the file or directory name
const char* <em>FileName</em> /* Pointer to the file or directory name */
);
</pre>
</div>
@ -24,7 +24,7 @@ FRESULT f_unlink (
<h4>Parameters</h4>
<dl class="par">
<dt>FileName</dt>
<dd>Pointer to the null-terminated string that specifies the full path name of a file or directory to be removed. In read-only and minimum configuration, this function is not supported.</dd>
<dd>Pointer to the null-terminated string that specifies a <a href="filename.html">file or directory</a> to be removed.</dd>
</dl>
</div>
@ -40,6 +40,8 @@ FRESULT f_unlink (
<dd>Could not find the path.</dd>
<dt>FR_INVALID_NAME</dt>
<dd>The path name is invalid.</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>The drive number is invalid.</dd>
<dt>FR_DENIED</dt>
<dd>The function was denied due to either of following reasons: the file or directory has read-only attribute, the directory is not empty.</dd>
<dt>FR_NOT_READY</dt>
@ -48,10 +50,8 @@ FRESULT f_unlink (
<dd>The medium is write protected.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>Incorrect disk removal/change has occured.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dd>The logical drive has no work area.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
@ -60,7 +60,7 @@ FRESULT f_unlink (
<div class="para">
<h4>Description</h4>
<p>The f_unlink removes file or directory. This function is not supported in minimization level of &gt;= 1.</p>
<p>The f_unlink function removes a file or directory. In read-only configuration or minimization level is &gt;= 1, this function is not supported.</p>
</div>

View File

@ -15,10 +15,10 @@
<p>The f_write writes data to a file.</p>
<pre>
FRESULT f_write (
FIL* <em>FileObject</em>, // Pointer to the file object structure
const void* <em>Buffer</em>, // Pointer to the data to be written
WORD <em>ByteToWrite</em>, // Number of bytes to write
WORD* <em>ByteWritten</em> // Pointer to the variable to return number of bytes written
FIL* <em>FileObject</em>, /* Pointer to the file object structure */
const void* <em>Buffer</em>, /* Pointer to the data to be written */
WORD <em>ByteToWrite</em>, /* Number of bytes to write */
WORD* <em>ByteWritten</em> /* Pointer to the variable to return number of bytes written */
);
</pre>
</div>
@ -27,7 +27,7 @@ FRESULT f_write (
<h4>Parameter</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>Pointer to the valid file object structure.</dd>
<dd>Pointer to the open file object structure.</dd>
<dt>Buffer</dt>
<dd>Pointer to the data to be written.</dd>
<dt>ByteToWrite</dt>
@ -46,18 +46,18 @@ FRESULT f_write (
<dt>FR_DENIED</dt>
<dd>The function denied due to the file has been opened in read only mode.</dd>
<dt>FR_RW_ERROR</dt>
<dd>Any error occured in low level disk I/O.</dd>
<dd>Any error has occured in low level disk I/O layer.</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_NOT_ENABLED</dt>
<dd>FatFs module is not enabled.</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>The file object is invalid.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The read/write pointer increases in number of bytes written. The <tt>ByteWritten</tt> will be less than <tt>ByteToWrite</tt> when disk gets full during write function. This function is not supported in read-only configuration.</p>
<p>The read/write pointer in the file object is increased in number of bytes written. The <tt>ByteWritten</tt> will become less than <tt>ByteToWrite</tt> when disk gets full during write function. This function is not supported in read-only configuration.</p>
</div>

BIN
doc/img/f1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
doc/img/f2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
doc/img/f3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

BIN
doc/img/f4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
doc/img/f5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
doc/img/layers.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

108
doc/ja/appnote.html Normal file
View File

@ -0,0 +1,108 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFsモジュール アプリケーション・ノート</title>
</head>
<body>
<h1>FatFsモジュール アプリケーション・ノート (for R0.04)</h1>
<hr>
<div class="para">
<h3>移植の際に配慮すべきこと</h3>
<p>FatFsモジュールは移植性に関して次の点を前提としています。</p>
<ul>
<li>処理系はANSI C準拠であること。<br>
FatFsモジュールはANSI C準拠で記述されているので、ANSI C準拠のコンパイラなら特に処理系依存な点はありません。ただし、FATというシステム間でポータブルな構造体を操作するため、プロセッサのエンディアンの違いは意識する必要があります。これは ff.h(tff.h) で定義されているので、最初にこれを適切に設定します(忘れている場合はエラーを出す)。</li>
<li>char/short/long のサイズは、それぞれ 8/16/32ビットであること。<br>
整数の型とサイズに関してはまっとうなコンパイラなら問題ないと思います。integer.h内の typedefと既存の定義が衝突した場合は矛盾がないように注意しなければなりません。</li>
</ul>
</div>
<div class="para">
<h3>FatFs vs. Tiny-FatFs</h3>
<p>ポータブル・オーディオやデータ・ロガーなど、よくある用途ではTiny-FatFsで十分です。しかし、Tiny-FatFsはデフォルトではFAT32に対応していないので、使用できるディスクは2GB(FAT64で4GB)までという制約があります。<tt>_USE_FAT32</tt>オプションでFAT32がサポートされますが、コード・サイズが膨らみます。</p>
<p>フル機能のFatFsは、複数ファイルを高速アクセスする場合や、複数ドライブの対応が必要な場合に有効です。</p>
<div class="rset">
<table class="lst2">
<tr><th>メモリ容量</th><th>FATタイプ</th></tr>
<tr><td>&lt;= 64MB</td><td>FAT12</td></tr>
<tr><td>128MB2GB</td><td>FAT16</td></tr>
<tr><td>&gt;= 4GB</td><td>FAT32</td></tr>
</table>
</div>
<p>右の表にメモリ・カードの容量と規定のFATタイプ(SDメモリの場合)を示します。出荷時はこれらのFATタイプでフォーマットされていて、最大のパフォーマンスが出るようにデータ領域の境界が調整されています。したがって、PCでフォーマットするなどして規定と違うフォーマットになると書き込み性能が大幅に低下する場合があるので注意が必要です。</p>
</div>
<div class="para">
<h3>効率の良いファイル・アクセスの方法</h3>
<p>資源の限られた組み込みシステムで効率よくアクセスするためには、ファイル・アクセスの仕組みをある程度意識した使用が求められます。FatFsモジュールでは、ディスク上のファイル・データは f_read()内で次のような手順で読み出されます。</p>
<div class="lset">図1. セクタ・ミスアライメント・リード<br>
<img src="../img/f1.png" width="490" height="73" alt="fig.1">
</div>
<br class="clr">
<div class="lset">図2. セクタ・ミスアライメント・リード<br>
<img src="../img/f2.png" width="490" height="140" alt="fig.2">
</div>
<br class="clr">
<div class="lset">図3. セクタ・アライメント・リード<br>
<img src="../img/f3.png" width="490" height="119" alt="fig.3">
</div>
<br class="clr">
<p>ここでファイルI/Oバッファとは、データ・セクタの一部を読み書きするための1セクタ長のバッファで、FatFsではそのファイル・オブジェクト内の、Tiny-FatFsではワークエリア内のバッファのことを指しています。</p>
<p>Tiny-FatFsでは、全てのデータ転送とFATやディレクトリへのアクセスをただ一つのセクタ・バッファで行っているため、データ転送によりFATのキャッシュが失われ、クラスタ境界を通過するたびにFATセクタを読み直す必要があります。FatFsの場合は、データ用バッファはFAT用とは別なので、FATセクタを読む頻度はTiny-FatFsの 1/341, 1/256 または 1/128で済みます(クラスタが連続している場合)。つまり、Tiny-FatFsは性能低下の代償を払ってRAM使用量を削減しているわけです。</p>
<p>転送領域のうちセクタ全体を含む部分は(図2)のようにファイルI/Oバッファを介さず、ディスクとの間で直接転送されます。完全なセクタ・アライメント・アクセスの場合(図3)は、ファイルI/Oバッファは全く使用されません。直接転送では、可能ならdisk_read()に複数セクタを指定して最大限のマルチ・セクタ転送が行われます。ただし、クラスタ境界をまたぐときは、たとえセクタが連続していたとしても転送は分割されます。</p>
<p>このように、極力セクタ・アライメント・アクセスになるように配慮すれば、無駄なデータ転送が減って性能が向上します。さらに、Tiny-FatFsではFATのキャッシュが生きるようになり、FatFsと同じ性能と省メモリ特性が同時に得られます。</p>
</div>
<div class="para">
<h3>クリチカル・セクション</h3>
<p>ディスク上のFAT構造を操作している途中で、停電、不正なメディアの取り外し、回復不能なデータエラー等の障害が発生すると、更新が中途半端な状態で中断され、その結果としてFAT構造が破壊される可能性があります。次にFatFsモジュールにおけるクリチカル・セクションと、その間の障害により起きうるエラーの状態を示します。</p>
<div class="lset">
図4. 長いクリチカル・セクション<br>
<img src="../img/f4.png" width="320" height="470" alt="fig.4">
</div>
<div class="lset">
図5. 短くしたクリチカル・セクション<br>
<img src="../img/f5.png" width="320" height="470" alt="fig.5">
</div>
<br class="clr">
<p>赤で示したセクションを実行中に障害が発生した場合、クロスリンクが発生して操作対象のファイル・ディレクトリが失われる可能性があります。黄色で示したセクションを実行中に障害が発生した場合、つぎのうちいずれかまたは複数の結果が生じる可能性が考えられます。</p>
<ul>
<li>書き換え中のファイルのデータ構造が破壊される。</li>
<li>追記中のファイルがオープン前の状態に戻る。</li>
<li>新規に作成されたファイルが消える。</li>
<li>新規に作成されたファイルの長さがゼロになって残る。</li>
<li>上書きで作成されたファイルの長さがゼロになって残る。</li>
<li>上書きで作成されたファイルが作成前の状態に戻る。</li>
<li>ロストチェーンの発生によりディスクの利用効率が悪化する。</li>
</ul>
<p>いずれも書き込み中でないファイルには影響はありません。これらのクリチカル・セクションは、ファイルを書き込みモードで開いている時間を最小限にするか、f_sync()を適宜使用することで図5のように最小化することができます。</p>
</div>
<div class="para">
<h3>現リビジョンの問題点とその改善案</h3>
<ul>
<li>ファイル・オブジェクトの抽象化<br>
現在はファイル・オブジェクトの実体をアプリケーション側で管理しているので、アプリケーション・モジュールでのスタック消費量が多くなります(Tiny-FatFsでは問題にはならない)。これをハンドルで管理するなどより抽象化すればアプリケーション・モジュールでのスタック消費量を減らせます。この場合、FatFs内でファイル・オブジェクトの領域を静的に確保しておくか、malloc()することになります。ただし、このようにするとファイル・オブジェクトを直接参照できなくなり、feofやftellなどムダな関数が新たに必要になります。</li>
<li>セクタ・バッファ管理の改善<br>
現在はセクタ・バッファを固定して使用しているため、無駄なディスクアクセスが多く効率が悪い。メモリの潤沢なシステムでは、複数のセクタ・バッファを使用してディスク・キャッシュを構成すれば性能を向上させることができます。</li>
<li>FSInfoへの対応<br>
FAT32ではその膨大なクラスタ数のため、ファイル新規作成や空きスペース取得時のクラスタ・サーチにかなりの時間を要します。このため、最終割り当てクラスタ番号や残りクラスタ数がFSInfoセクタに記録されていて、延々とクラスタ・サーチするのを避けられるようになっています。現在はFSInfoに未対応なので、空きスペース取得時や、ディスク使用量が多い状態でのファイル作成(作成後の最初の書き込み)処理時間は問題になるレベルです。</li>
<li>長いファイル名への対応<br>
FATの拡張仕様では従来の8.3形式ファイル名に加え、255文字までの長いファイル名を扱えるようになっていますが、現リビジョンでは未対応で8.3形式しか使用できません。これに対応するには、ファイル名だけでも500バイト以上のバッファが必要になったり、UCS-2とShift_JISの相互変換(巨大な変換テーブル)が必要となるなど、メモリの消費が爆発的に増えてしまいます。なお、長いファイル名の機能はMicrosoft社の特許になっているため、これを製品に使うにはライセンス契約が必要です。</li>
<li>RTOSへの対応<br>
FatFsモジュールを使用するタスクを一つに限るなら特に意識する必要はありませんが、複数のタスクから使用するには、何らかの排他制御が必要になってきます。FatFsモジュールのRTOSへの対応作業は、<a href="http://www.toppers.jp/">TOPPERSプロジェクト</a>で行われています。</li>
</ul>
<br>
<p>そして、これらの機能拡張を行うとそれだけ多くのリソースが要求されるようになり、このプロジェクトが対象としている8/16ビット・マイコンのシステムに載せられなくなってしまうという問題もあります(これが一番の問題かも知れません)。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>

View File

@ -15,23 +15,23 @@
<p>ファイルまたはディレクトリの属性を変更します。</p>
<pre>
FRESULT f_chmod (
const char* <em>FileName</em>, // ファイルまたはディレクトリの文字列へのポインタ
BYTE <em>Attribute</em>, // 設定値
BYTE <em>AttributeMask</em> // 変更マスク
const char* <em>FileName</em>, /* ファイルまたはディレクトリ名へのポインタ */
BYTE <em>Attribute</em>, /* 設定値 */
BYTE <em>AttributeMask</em> /* 変更マスク */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileName</dt>
<dd>属性変更対象のファイルまたはディレクトリのフルパス名の入った<tt>'\0'</tt>で終わる文字列を指定します。</dd>
<dd>属性変更対象のファイルまたはディレクトリの<a href="filename.html">フルパス名</a>の入った<tt>'\0'</tt>で終わる文字列を指定します。</dd>
<dt>Attribute</dt>
<dd>設定する属性。指定可能な属性は次の通りで、これらの組み合わせで指定します。指定されなかった属性は解除されます。<br>
<table class="lst">
<tr><th></th><th>意味</th></td>
<tr><td>AM_RDO</td><td>リードオンリー</td></td>
<tr><td>AM_RDO</td><td>リードオンリー</td></td>
<tr><td>AM_ARC</td><td>アーカイブ</td></td>
<tr><td>AM_SYS</td><td>システム</td></td>
<tr><td>AM_HID</td><td>ヒドゥン</td></td>
@ -54,16 +54,16 @@ FRESULT f_chmod (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>その論理ドライブにワーク・エリアが与えられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -72,7 +72,7 @@ FRESULT f_chmod (
<div class="para">
<h4>解説</h4>
<p>ファイルまたはディレクトリの属性を変更します。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>ファイルまたはディレクトリの属性を変更します。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
</div>

View File

@ -15,16 +15,16 @@
<p>ファイルを閉じます。</p>
<pre>
FRESULT f_close (
FIL* <em>FileObject</em> // ファイルオブジェクト構造体へのポインタ
FIL* <em>FileObject</em> /* ファイル・オブジェクトへのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>閉じようとするファイルのファイルオブジェクト構造体へのポインタを指定します。</dd>
<dd>閉じようとするファイルのファイルオブジェクト構造体へのポインタを指定します。</dd>
</dl>
</div>
@ -35,18 +35,18 @@ FRESULT f_close (
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスク・ドライブが動作不能状態</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイル・オブジェクト</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>ファイルを閉じます。書き込みの行われたファイルの場合、キャッシュされた状態R/Wバッファ上のデータ、変更されたFATやディレクトリ項目はディスクに書き戻されます。関数が正常終了すると、そのファイルオブジェクト構造体は無効になり、そのメモリも解放できます。</p>
<p>ファイルを閉じます。書き込みの行われたファイルの場合、キャッシュされた状態R/Wバッファ上のデータ、変更されたFATやディレクトリ項目はディスクに書き戻されます。関数が正常終了すると、そのファイルオブジェクトは無効になり、そのメモリも解放できます。</p>
</div>

View File

@ -12,20 +12,31 @@
<div class="para">
<h2>disk_initialize</h2>
<p>ディスクドライブを初期化します。</p>
<p>ディスクドライブを初期化します。</p>
<pre>
DSTATUS disk_initialize ();
DSTATUS disk_initialize (
BYTE <em>Drive</em> /* 物理ドライブ番号 */
);
</pre>
</div>
<div class="para">
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>初期化する物理ドライブ番号(0-9)を指定します。</dd>
</dl>
</div>
<div class="para">
<h4>戻り値</h4>
<p>この関数は戻り値としてディスクステータスを返します。ディスクステータスの詳細に関しては<tt><a href="dstat.html">disk_status()</a></tt>を参照してください。</p>
<p>この関数は戻り値としてディスクステータスを返します。ディスクステータスの詳細に関しては<tt><a href="dstat.html">disk_status()</a></tt>を参照してください。</p>
</div>
<div class="para">
<h4>解説</h4>
<p>ディスクドライブを初期化します。関数が成功すると、戻り値の<tt>STA_NOINIT</tt>フラグがクリアされます。</p>
<p>ディスクドライブを初期化します。関数が成功すると、戻り値の<tt>STA_NOINIT</tt>フラグがクリアされます。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -15,18 +15,21 @@
<p>ディスクからセクタを読み出します。</p>
<pre>
DRESULT disk_read (
BYTE* <em>Buffer</em>, // 読み出しバッファへのポインタ
DWORD <em>SectorNumber</em>, // 読み出し開始セクタ番号
BYTE <em>SectorCount</em> // 読み出しセクタ数
BYTE <em>Drive</em>, /* 物理ドライブ番号 */
BYTE* <em>Buffer</em>, /* 読み出しバッファへのポインタ */
DWORD <em>SectorNumber</em>, /* 読み出し開始セクタ番号 */
BYTE <em>SectorCount</em> /* 読み出しセクタ数 */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>物理ドライブ番号(0-9)を指定します。</dd>
<dt>Buffer</dt>
<dd>ディスクから読み出したセクタデータを格納するバッファ。<tt>SectorCount * 512</tt>バイトのサイズが必要です。</dd>
<dd>ディスクから読み出したデータを格納するバッファ。<tt>SectorCount * 512</tt>バイトのサイズが必要です。</dd>
<dt>SectorNumber</dt>
<dd>読み出しを開始するセクタ番号。LBAで指定します。</dd>
<dt>SectorCount</dt>

View File

@ -12,22 +12,33 @@
<div class="para">
<h2>disk_status</h2>
<p>ディスクの状態を取得します。</p>
<p>ディスク・ドライブの状態を取得します。</p>
<pre>
DSTATUS disk_status ();
DSTATUS disk_status (
BYTE <em>Drive</em> /* 物理ドライブ番号 */
);
</pre>
</div>
<div class="para">
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>ステータスを取得する物理ドライブ番号を指定します。</dd>
</dl>
</div>
<div class="para">
<h4>戻り値</h4>
<p>ディスクドライブの状態が次のフラグの組み合わせの値で返されます。</p>
<p>物理ドライブの状態が次のフラグの組み合わせの値で返されます。</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>ドライブが初期化されていないことを示すフラグ。電源ONまたはメディアの取り外しでセットされ、<tt>disk_initialize()</tt>の正常終了でクリア、失敗でセットされます。</dd>
<dd>ドライブが初期化されていないことを示すフラグ。電源ONまたはメディアの取り外しでセットされ、disk_initialize() の正常終了でクリア、失敗でセットされます。</dd>
<dt>STA_NODISK</dt>
<dd>メディアがセットされていないことを示すフラグ。メディアが取り外されている間はセットされ、メディアがセットされている間はクリアされます。固定ディスクでは常にクリアされています。</dd>
<dt>STA_PROTECTED</dt>
<dd>メディアがライトプロテクトされていることを示すフラグ。ライトプロテクトノッチをサポートしないメディアでは常にクリアされています。</dd>
<dd>メディアがライトプロテクトされていることを示すフラグ。ライトプロテクトノッチをサポートしないメディアでは常にクリアされています。</dd>
</dl>
</div>

View File

@ -12,21 +12,24 @@
<div class="para">
<h2>disk_write</h2>
<p>ディスクにセクタデータを書き込みます。</p>
<p>ディスクにデータを書き込みます。</p>
<pre>
DRESULT disk_write (
const BYTE* <em>Buffer</em>, // 書き込むデータへのポインタ
DWORD <em>SectorNumber</em>, // 書き込み開始セクタ番号
BYTE <em>SectorCount</em> // 書き込みセクタ数
BYTE <em>Drive</em>, /* 物理ドライブ番号 */
const BYTE* <em>Buffer</em>, /* 書き込むデータへのポインタ */
DWORD <em>SectorNumber</em>, /* 書き込み開始セクタ番号 */
BYTE <em>SectorCount</em> /* 書き込みセクタ数 */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>書き込むドライブ番号を指定します。</dd>
<dt>Buffer</dt>
<dd>ディスクに書き込むセクタデータを指定します。</dd>
<dd>ディスクに書き込むデータを指定します。</dd>
<dt>SectorNumber</dt>
<dd>書き込みを開始するセクタ番号。LBAで指定します。</dd>
<dt>SectorCount</dt>
@ -54,7 +57,7 @@ DRESULT disk_write (
<div class="para">
<h4>解説</h4>
<p>リードオンリー構成ではこの関数は必要とされません。</p>
<p>リードオンリー構成ではこの関数は必要とされません。</p>
</div>

View File

@ -14,14 +14,14 @@
<h2>get_fattime</h2>
<p>現在時刻を取得します。</p>
<pre>
DWORD get_fattime ();
DWORD get_fattime (void);
</pre>
</div>
<div class="para">
<h4>戻り値</h4>
<p>現在のローカルタイムが<tt>DWORD</tt>値にパックされて返されます。ビットフィールドは次に示すようになります。</p>
<p>現在のローカルタイムが<tt>DWORD</tt>値にパックされて返されます。ビットフィールドは次に示すようになります。</p>
<dl>
<dt>bit31:25</dt>
<dd>1980年を起点とした年が 0..127 で入ります。</dd>
@ -41,7 +41,7 @@ DWORD get_fattime ();
<div class="para">
<h4>解説</h4>
<p>RTCをサポートしないシステムでも、何らかの有効な値を返さなければなりません。リードオンリー構成ではこの関数は必要とされません。</p>
<p>RTCをサポートしないシステムでも、何らかの日付として有効な値を返さなければなりません。リードオンリー構成ではこの関数は必要とされません。</p>
</div>

36
doc/ja/filename.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - ファイル・ディレクトリの指定方法</title>
</head>
<body>
<h2>ファイル・ディレクトリの指定方法</h2>
<div class="para">
<p>FatFsモジュールでのファイル、ディレクトリ、ドライブの指定方法はMS-DOSとほぼ同じです。ただし、MS-DOSのようなカレント・ディレクトリの概念は無いので、常にルート・ディレクトリから辿る絶対パスでの指定となります。パス名の指定方法と例は次の通りです。</p>
<pre>
"[<em>論理ドライブ番号</em>:][/]<em>ディレクトリ名</em>/<em>ファイル名</em>"
"file1.txt" ファイル(drive0)
"/file1.txt" ↑と同じ
"dir1/dir2/file1.txt" ファイル(drive0)
"2:dir3/file2.txt" ファイル(drive2)
"2:/dir5" ディレクトリ(drive2)
"" ルート・ディレクトリ(drive2)
"/" ↑と同じ
"2:" ルート・ディレクトリ(drive2)
</pre>
<p>FatFsモジュールは8.3形式ファイル名にのみ対応しています。長いファイル名には対応していないので、ファイル名やディレクトリ名は8.3形式の範囲内で指定します。ディレクトリ・セパレータには'/'を使用します。パス名先頭の'/'は、あってもなくても同じです。</p>
<p>論理ドライブ番号は、'0''9'の一文字の数字とコロンで指定します。省略した場合は"0:"を指定したことになります。FatFsでは論理ドライブ毎にファイル・システム・オブジェクトというワーク・エリアを持っています。現在のところ、論理ドライブは同じ番号の物理ドライブに結びつけられています。</p>
<p>Tiny-FatFsでは一つのファイル・システム・オブジェクトしか持てず、常に論理ドライブ0として動作します。また、パス名中に論理ドライブ番号を使用できません。</p>
</div>
</body>
</html>

View File

@ -12,19 +12,25 @@
<div class="para">
<h2>f_getfree</h2>
<p>ディスクの未使用領域を得ます。</p>
<p>ディスクの未使用クラスタ数を得ます。</p>
<pre>
FRESULT f_getfree (
DWORD* <em>Clusters</em> // 空きクラスタ数を格納する変数へのポインタ
const char* <em>Path</em>, /* 対象ドライブのルート・ディレクトリ */
DWORD* <em>Clusters</em>, /* 空きクラスタ数を格納する変数へのポインタ */
FATFS** <em>FileSystemObject</em> /* ファイル・システム・オブジェクトを指すポインタへのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>Path</dt>
<dd>情報を得る論理ドライブのルートディレクトリの<a href="filename.html">パス名</a>が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
<dt>Clusters</dt>
<dd>空きクラスタ数を格納するDWORD変数へのポインタを指定します。</dd>
<dt>FileSystemObject</dt>
<dd>対象ドライブのファイル・システム・オブジェクトを指すポインタを格納するポインタへのポインタを指定します。</dd>
</dl>
</div>
@ -34,14 +40,14 @@ FRESULT f_getfree (
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。<tt><em>*Clusters</em></tt>に空きクラスタ数が返されます。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>その論理ドライブにワーク・エリアが与えられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -50,21 +56,26 @@ FRESULT f_getfree (
<div class="para">
<h4>解説</h4>
<p>ファイルシステム上の空きクラスタ数を取得します。<tt>FatFs.sects_clust</tt> がクラスタあたりのセクタ数を示しているので、これを元に実際の空きサイズが計算できます。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>論理ドライブ上の空きクラスタ数を取得します。返されたファイル・システム・オブジェクトの<tt>sects_clust</tt>メンバがクラスタあたりのセクタ数を示しているので、これを元に実際の空きサイズが計算できます。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
</div>
<div class="para">
<h4>使用例</h4>
<pre>
FATFS *fs;
DWORD clust;
// Get free clusters
res = f_getfree(&clust);
res = f_getfree("", &clust, &fs);
if (res) die(res);
// Get free bytes
printf("%lu bytes available on the disk.\n", clust * FatFs->sects_clust * 512);
// Get free space
printf("%lu KB total disk space.\n"
"%lu KB available on the disk.\n",
(fs->max_clust - 2) * fs->sects_clust / 2,
clust * fs->sects_clust / 2);
</pre>
</div>

View File

@ -15,17 +15,17 @@
<p>ファイルのR/Wポインタを移動します。</p>
<pre>
FRESULT f_lseek (
FIL* <em>FileObject</em>, // ファイルオブジェクト構造体へのポインタ
DWORD <em>Offset</em> // 移動先オフセット
FIL* <em>FileObject</em>, /* ファイル・オブジェクト構造体へのポインタ */
DWORD <em>Offset</em> /* 移動先オフセット */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>対象となるファイルオブジェクト構造体へのポインタを指定します。</dd>
<dd>対象となるファイルオブジェクト構造体へのポインタを指定します。</dd>
<dt>Offset</dt>
<dd>移動先のオフセットR/Wポインタ値。ファイル先頭からのオフセットをバイト単位で指定します。</dd>
</dl>
@ -38,18 +38,18 @@ FRESULT f_lseek (
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスク・ドライブが動作不能状態</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイルオブジェクト</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>ファイルR/Wポインタを移動します。オフセットの指定はファイル先頭からのみです。ファイル末尾以降への移動はできません。ファイルサイズ以上のオフセットを指定した場合、R/Wポインタはファイルサイズと同じになります。</p>
<p>ファイルR/Wポインタを移動します。オフセットの指定はファイル先頭からのみです。ファイル末尾以降への移動はできません。ファイルサイズ以上のオフセットを指定した場合、R/Wポインタはファイルサイズと同じになります。</p>
</div>
@ -66,7 +66,7 @@ FRESULT f_lseek (
res = f_lseek(&file, file.fptr - 2000);
// ファイル追記の準備
res = f_lseek(&file, 0xFFFFFFFF);
res = f_lseek(&file, file.fsize);
</pre>
</div>

View File

@ -15,16 +15,16 @@
<p>ディレクトリを作成します。</p>
<pre>
FRESULT f_mkdir (
const char* <em>DirName</em> // 作成するディレクトリ名へのポインタ
const char* <em>DirName</em> /* 作成するディレクトリ名へのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>DirName</dt>
<dd>作成するディレクトリのフルパス名が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。ディレクトリセパレータには<tt>'/'</tt>を使用します。FatFsモジュールにはカレントディレクトリの概念がないので、パスはルートディレクトリから辿る絶対パスとなります。文字列先頭のスペースはスキップされます。パス先頭の<tt>'/'</tt>はあってもなくてもかまいません</dd>
<dd>作成するディレクトリの<a href="filename.html">フルパス名</a>が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します</dd>
</dl>
</div>
@ -38,18 +38,18 @@ FRESULT f_mkdir (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_DENIED</dt>
<dd>同名のディレクトリやファイルの存在、ディスクやディレクトリエントリが満杯の場合など。</dd>
<dd>同名のディレクトリやファイルの存在、ディスクやディレクトリエントリが満杯の場合など。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>その論理ドライブにワーク・エリアが与えられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -58,7 +58,7 @@ FRESULT f_mkdir (
<div class="para">
<h4>解説</h4>
<p>空のディレクトリを作成します。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>空のディレクトリを作成します。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>
</p>
</div>

70
doc/ja/mkfs.html Normal file
View File

@ -0,0 +1,70 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mkfs</title>
</head>
<body>
<div class="para">
<h2>f_mkfs</h2>
<p>ドライブ上にFATファイル・システムを作成(フォーマット)します。</p>
<pre>
FRESULT f_mkfs (
BYTE <em>Drive</em>, /* Logical drive number */
BYTE <em>PartitioningRule</em>, /* Partitioning rule */
BYTE <em>AllocSize</em> /* Allocation unit size */
);
</pre>
</div>
<div class="para">
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>フォーマットする論理ドライブ(0-9)。</dd>
<dt>PartitioningRule</dt>
<dd>0を指定すると、区画テーブルを作成したあとその区画にファイル・システムを作成します(FDISKフォーマット)。1を指定すると、先頭セクタから直接ファイル・システムを構築します(super floppy (SFD) フォーマット)。</dd>
<dt>AllocSize</dt>
<dd>アロケーション・ユニット・サイズ(クラスタ・サイズ)をセクタ単位で指定します。2の累乗でかつ1から64までの範囲でなければなりません。</dd>
</dl>
</div>
<div class="para">
<h4>戻り値</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が無効。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_MKFS_ABORTED</dt>
<dd>次の理由で処理が中断された。
<ul>
<li>ディスク・サイズが小さすぎる。</li>
<li>何らかの引数が無効。</li>
<li>そのクラスタ・サイズが使えない。クラスタ数が0xFF7と0xFFF7近辺になると発生する可能性がある。</li>
</ul>
</dd>
</dl>
</div>
<div class="para">
<h4>説明</h4>
<p>f_mkfs関数はFATファイル・システムをドライブ上に作成します。リムーバブル・メディアのパーテーショニング・ルールとしては、FDISK形式とSFD形式がありますが、多くの場合はFDISK形式が推奨されます。FATタイプ(FAT12/FAT16/FAT32)は、ディスク上のクラスタ数によってのみ決定される決まりになっていて、それ以外の要因はありません。したがって、どのFATタイプになるかは、ディスク・サイズとクラスタ・サイズに依存します。</p>
<p>この関数は、FatFsで_USE_MKFSを選択したときにサポートされます。<p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

59
doc/ja/mount.html Normal file
View File

@ -0,0 +1,59 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mount</title>
</head>
<body>
<div class="para">
<h2>f_mount</h2>
<p>論理ドライブのワーク・エリアを登録・抹消します。</p>
<pre>
FRESULT f_mount (
BYTE <em>Drive</em>, /* 論理ドライブ番号 */
FATFS* <em>FileSystemObject</em> /* ワーク・エリアへのポインタ */
);
</pre>
</div>
<div class="para">
<h4>引数</h4>
<dl class="par">
<dt>Drive</dt>
<dd>論理ドライブ番号(0-9)。Tiny-FatFsでは常に0。</dd>
<dt>FileSystemObject</dt>
<dd>登録するワーク・エリア(ファイル・システム・オブジェクト)へのポインタ。</dd>
</dl>
</div>
<div class="para">
<h4>戻り値</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が無効。</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>論理ドライブにそのワーク・エリアを登録したり抹消したりします。何らかのファイル関数を使用する前にこの関数でその論理ドライブのワーク・エリアを与えておかなければなりません。<em>FileSystemObject</em>にNULLポインタを指定するとその論理ドライブのワーク・エリアの登録は抹消され、登録されていたワーク・エリアは破棄できます。</p>
<p>この関数内では物理ドライブへのアクセスは行われず、ワーク・エリアを初期化して内部配列にそのアドレスを登録するだけです。実際のマウント動作は他のファイル関数の中で必要に応じて行われます。</p>
</div>
<div class="para">
<h4>参照</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>

View File

@ -15,20 +15,20 @@
<p>ファイルをオープンまたは作成します。</p>
<pre>
FRESULT f_open (
FIL* <em>FileObject</em>, // 空のファイルオブジェクト構造体へのポインタ
const char* <em>FileName</em>, // ファイルのフルパス名へのポインタ
BYTE <em>ModeFlags</em> // モードフラグ
FIL* <em>FileObject</em>, /* 空のファイル・オブジェクト構造体へのポインタ */
const char* <em>FileName</em>, /* ファイルのフルパス名へのポインタ */
BYTE <em>ModeFlags</em> /* モードフラグ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>新しく作成するファイルオブジェクト構造体へのポインタを指定します。以降、そのファイルを閉じるまでこのファイルオブジェクトを使用してファイル操作をします。</dd>
<dd>新しく作成するファイルオブジェクト構造体へのポインタを指定します。以降、そのファイルを閉じるまでこのファイルオブジェクトを使用してファイル操作をします。</dd>
<dt>FileName</dt>
<dd>作成する (またはオープンする) ファイルのフルパス名が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。ディレクトリセパレータには<tt>'/'</tt>を使用します。FatFsモジュールにはカレントディレクトリの概念がないので、パスはルートディレクトリから辿る絶対パスとなります。文字列先頭のスペースはスキップされます。パス先頭の<tt>'/'</tt>はあってもなくてもかまいません</dd>
<dd>開く(または作成する)ファイルの <a href="filename.html">ファイル名</a>が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します</dd>
<dt>ModeFlags</dt>
<dd>ファイルのアクセス方法やオープン方法を決めるフラグです。このパラメータには次の組み合わせを指定します。<br>
<table class="lst">
@ -48,25 +48,25 @@ FRESULT f_open (
<h4>戻り値</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。以降、<tt><em>FileObject</em></tt>構造体を使ってこのファイルを操作できます。ファイルを閉じるときは、<tt><a href="close.html">f_close()</a></tt>を使用します。</dd>
<dd>正常終了。以降、<tt><em>FileObject</em></tt>構造体を使ってこのファイルを操作できます。</dd>
<dt>FR_NO_FILE</dt>
<dd>ファイルが見つからない。</dd>
<dt>FR_NO_PATH</dt>
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>ファイル名が不正。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_DENIED</dt>
<dd>アクセスが拒否された。リードオンリーファイルの書き込みモードオープン、同名のディレクトリまたはリードオンリファイルがある状態でのファイル作成、ディスクまたはディレクトリテーブルが満杯でファイルを作成できないなど。</dd>
<dd>アクセスが拒否された。リードオンリーファイルの書き込みモードオープン、同名のディレクトリまたはリードオンリー・ファイルがある状態でのファイル作成、ディスクまたはディレクトリテーブルが満杯でファイルを作成できないなど。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態で書き込みオープンまたはファイル作成をした。</dd>
<dd>メディアが書き込み禁止状態で書き込みオープンをした。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>その論理ドライブにワーク・エリアが割り当てられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -75,26 +75,25 @@ FRESULT f_open (
<div class="para">
<h4>解説</h4>
<p>FatFsモジュールの使用を開始するにはまず、FatFsモジュールのグローバル変数<em>FatFs</em>にゼロクリアしたワークエリア(<tt>FATFS</tt>構造体)のアドレスを代入します。このようにしてFatFsモジュールにワークエリアを割り当てるとモジュールは動作可能状態になり、ファイル関数が使えるようになります。ゼロクリアの代わりに<a href="mountdrv.html">f_mountdrv()</a>でもOKですが、少なくともその時点で物理ドライブが動作可能になっていなければなりません。FatFsモジュールの使用を終了するには、全てのファイルを閉じたあと<em>FatFs</em>をクリアします。その後、ワークエリアは破棄できます。</p>
<p>作成されたファイル・オブジェクトは、以降そのファイルに対するアクセスに使用します。ファイルを閉じるときは、<a href="close.html">f_close()</a>を使用します。</p>
<p>ファイル操作関数を使用する前にまず、<a href="mount.html">f_mount()</a>を使ってそれぞれの論理ドライブにワーク・エリア(ファイル・システム・オブジェクト)を与えなければなりません。この初期化の後、その論理ドライブに対して全てのファイル関数が使えるようになります。</p>
<p>リードオンリー構成では、<tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt>の各フラグはサポートされません。</p>
</div>
<div class="para">
<h4>使用例(ファイルコピー)</h4>
<h4>使用例(ファイルコピー)</h4>
<pre>
void main ()
{
FATFS fs; // FatFsワークエリア
FIL fsrc, fdst; // ファイルオブジェクト
FATFS fs; // 論理ドライブのワーク・エリア(ファイル・システム・オブジェクト)
FIL fsrc, fdst; // ファイルオブジェクト
BYTE buffer[4096]; // file copy buffer
FRESULT res; // FatFs function common result code
WORD br, bw; // File R/W count
// FatFsのワークエリアを確保する
FatFs = &fs;
memset(&fs, 0, sizeof(FATFS)); // ワークエリアの初期化。代わりに f_mountdrv() でもよい
// ドライブ0にワーク・エリアを与える
f_mount(0, &fs);
// ソース・ファイルを開く
res = f_open(&fsrc, "srcfile.dat", FA_OPEN_EXISTING | FA_READ);
@ -116,8 +115,8 @@ void main ()
f_close(&fsrc);
f_close(&fdst);
// FatFsのワークエリアを開放する
FatFs = NULL;
// ワークエリアを開放する
f_mount(0, NULL);
}
</pre>
</div>

View File

@ -15,19 +15,19 @@
<p>ディレクトリをオープンします。</p>
<pre>
FRESULT f_opendir (
DIR* <em>DirObject</em>, // ディレクトリブジェクト構造体へのポインタ
const char* <em>DirName</em> // ディレクトリ名へのポインタ
DIR* <em>DirObject</em>, /* ディレクトリ・ブジェクト構造体へのポインタ */
const char* <em>DirName</em> /* ディレクトリ名へのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>初期化するディレクトリオブジェクト構造体へのポインタを指定します。</dd>
<dd>初期化するディレクトリオブジェクト構造体へのポインタを指定します。</dd>
<dt>DirName</dt>
<dd>オープンするディレクトリのフルパス名が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。ディレクトリセパレータには<tt>'/'</tt>を使用します。FatFsモジュールにはカレントディレクトリの概念がないので、パスはルートディレクトリから辿る絶対パスとなります。先頭のスペースはスキップされます。パス先頭の<tt>'/'</tt>はあってもなくてもかまいませんが、最後のディレクトリ名の後ろに<tt>'/'</tt>を付けることはできません。ルートディレクトリを開くときは、<tt>&quot;&quot;</tt>または<tt>&quot;/&quot;</tt>を指定します。</dd>
<dd>オープンするディレクトリの<a href="filename.html">フルパス名</a>が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
</dl>
</div>
@ -43,14 +43,14 @@ FRESULT f_opendir (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>論理ドライブにワーク・エリアが与えられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -59,7 +59,7 @@ FRESULT f_opendir (
<div class="para">
<h4>解説</h4>
<p>ディレクトリをオープンします。正常終了したら、<tt><em>DirObject</em></tt>構造体を使ってこのディレクトリの項目を順次読み出せます。使用後の処理は必要ありません。<tt><em>DirObject</em></tt>構造体は任意の時点で破棄できます。<tt>_FS_MINIMIZE == 2</tt>ではこの関数はサポートされません。</p>
<p>ディレクトリをオープンします。正常終了したら、<tt><em>DirObject</em></tt>構造体を使ってこのディレクトリの項目を順次読み出せます。<tt><em>DirObject</em></tt>構造体は使用後は任意の時点で破棄できます。<tt>_FS_MINIMIZE == 2</tt>ではこの関数はサポートされません。</p>
</div>

View File

@ -15,7 +15,7 @@
<p>ファイルからデータを読み出します。</p>
<pre>
FRESULT f_read (
FIL* <em>FileObject</em>, // ファイルオブジェクト構造体
FIL* <em>FileObject</em>, // ファイルオブジェクト構造体
void* <em>Buffer</em>, // 読み出したデータを格納するバッファ
WORD <em>ByteToRead</em>, // 読み出すバイト数
WORD* <em>ByteRead</em> // 読み出されたバイト数
@ -24,10 +24,10 @@ FRESULT f_read (
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>ファイルオブジェクト構造体へのポインタを指定します。</dd>
<dd>ファイルオブジェクト構造体へのポインタを指定します。</dd>
<dt>Buffer</dt>
<dd>読み出したデータを格納するバッファを指すポインタを指定します。</dd>
<dt>ByteToRead</dt>
@ -46,11 +46,11 @@ FRESULT f_read (
<dt>FR_DENIED</dt>
<dd>書き込み専用モードで開いたファイルから読み込もうとした。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイル・オブジェクト</dd>
</dl>
</div>

View File

@ -15,17 +15,17 @@
<p>ディレクトリ項目を読み出します</p>
<pre>
FRESULT f_readdir (
DIR* <em>DirObject</em>, // ディレクトリブジェクト構造体へのポインタ
FILINFO* <em>FileInfo</em> // ファイル情報構造体へのポインタ
DIR* <em>DirObject</em>, /* ディレクトリ・ブジェクト構造体へのポインタ */
FILINFO* <em>FileInfo</em> /* ファイル情報構造体へのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>DirObject</dt>
<dd>初期化済みのディレクトリオブジェクト構造体へのポインタを指定します。</dd>
<dd>ディレクトリオブジェクト構造体へのポインタを指定します。</dd>
<dt>FileInfo</dt>
<dd>読み出したディレクトリ項目を格納するファイル情報構造体へのポインタを指定します。</dd>
</dl>
@ -38,18 +38,18 @@ FRESULT f_readdir (
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なディレクトリ・オブジェクト</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>ディレクトリ項目を順次読み出します。この関数を繰り返し実行することによりディレクトリの全ての項目を読み出すことができます。全ての項目を読み出し、読み出す項目がもう無いときは、<tt>f_name[]</tt>メンバにヌル文字列が返されます。得られるファイル情報の詳細については <tt>FILINFO</tt>構造体を参照してください。<tt>_FS_MINIMIZE == 2</tt>ではこの関数はサポートされません。</p>
<p>ディレクトリ・エントリーを順次読み出します。この関数を繰り返し実行することによりディレクトリの全ての項目を読み出すことができます。全ての項目を読み出し、読み出す項目がもう無いときは、<tt>f_name[]</tt>メンバにヌル文字列が返されます。得られるファイル情報の詳細については <tt>FILINFO</tt>構造体を参照してください。<tt>_FS_MINIMIZE == 2</tt>ではこの関数はサポートされません。</p>
</div>

View File

@ -15,19 +15,19 @@
<p>ファイルまたはディレクトリの名前の変更または移動。</p>
<pre>
FRESULT f_rename (
const char* <em>OldName</em>, // 古いファイルまたはディレクトリの文字列へのポインタ
const char* <em>NewName</em> // 新しいファイルまたはディレクトリの文字列へのポインタ
const char* <em>OldName</em>, /* 古いファイルまたはディレクトリ名 */
const char* <em>NewName</em> /* 新しいファイルまたはディレクトリ名 */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>OldName</dt>
<dd>変更対象のファイルまたはディレクトリのフルパス名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
<dd>変更対象のファイルまたはディレクトリの<a href="filename.html">フルパス名</a>の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
<dt>NewName</dt>
<dd>新しいファイルまたはディレクトリのフルパス名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。既に存在するものと同じ名前は使えません。<br>
<dd>新しいファイルまたはディレクトリのフルパス名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。既に存在するものと同じ名前は使えません。また、ドライブ番号は指定できず、<em>OldName</em>で指定されたドライブ上として扱われます。<br>
</dl>
</div>
@ -43,18 +43,18 @@ FRESULT f_rename (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_DENIED</dt>
<dd>新しい名前が作れない。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>論理ドライブにワークエリアが割り当てられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -63,8 +63,8 @@ FRESULT f_rename (
<div class="para">
<h4>解説</h4>
<p>ファイルまたはディレクトリの名前を変更します。別のディレクトリへの移動も可能です。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>※現リビジョンでは、ディレクトリを別のディレクトリに移動するとファイルシステムが壊れます。</p>
<p>ファイルまたはディレクトリの名前を変更します。別のディレクトリへの移動(同じドライブ内のみ)も可能です。リードオンリー構成および<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>※現リビジョンでは、ディレクトリを別のディレクトリに移動するとファイルシステムが壊れます。</p>
</div>

View File

@ -12,23 +12,27 @@
<div class="para">
<h2>DIR</h2>
<p><tt>DIR</tt>構造体は、ディレクトリ情報読み出しのワークエリアとして使用されます。</p>
<p><tt>DIR</tt>構造体は、f_opendir(), f_readdir()のワーク・エリアとして使用されます。</p>
<h4>FatFs</h4>
<pre>
typedef struct _DIR {
DWORD sclust; // Directory start cluster
DWORD clust; // Current reading cluster
DWORD sect; // Current reading sector
WORD index; // Current index
FATFS* fs; /* Pointer to the owner file system object */
DWORD sclust; /* Start cluster */
DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
</pre>
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _DIR {
WORD sclust; // Directory start cluster
WORD clust; // Current reading cluster
DWORD sect; // Current reading sector
WORD index; // Current index
FATFS* fs; /* Pointer to the owner file system object */
CLUST sclust; /* Start cluster */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
</pre>
</div>

View File

@ -12,17 +12,16 @@
<div class="para">
<h2>FATFS</h2>
<p><tt>FATFS</tt>構造体は、FatFsモジュールのダイナミックワークエリアを保持し、アプリケーション側で確保・管理されます。アプリケーションから変更可能なメンバはありません。</p>
<p><tt>FATFS</tt>構造体は、個々の論理ドライブのダイナミック・ワーク・エリアを保持し、f_mount()でFatFsモジュールに登録されます。アプリケーションから書き換え可能なメンバはありません。</p>
<h4>FatFs</h4>
<pre>
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE fs_type; /* FAT type (0:Not mouted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
BYTE drive; /* Physical drive number */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD sects_fat; /* Sectors per fat */
DWORD max_clust; /* Maximum cluster# + 1 */
@ -30,6 +29,7 @@ typedef struct _FATFS {
DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */
DWORD database; /* Data start sector */
DWORD last_clust; /* Last allocated cluster */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT */
} FATFS;
</pre>
@ -37,20 +37,19 @@ typedef struct _FATFS {
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE fs_type; /* FAT type (0:Not mouted) */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
WORD sects_fat; /* Sectors per fat */
WORD max_clust; /* Maximum cluster# + 1 */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector */
DWORD database; /* Data start sector */
WORD last_clust; /* Last allocated cluster */
CLUST sects_fat; /* Sectors per fat */
CLUST max_clust; /* Maximum cluster# + 1 */
CLUST last_clust; /* Last allocated cluster */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
} FATFS;
</pre>

View File

@ -12,35 +12,39 @@
<div class="para">
<h2>FIL</h2>
<p><tt>FIL</tt>構造体は、個々のファイルの状態を保持し、アプリケーション側で確保・管理されます。アプリケーションから変更可能なメンバはありません。</p>
<p><tt>FIL</tt>構造体は、f_open()で作成され、そのファイルの状態を保持します。アプリケーションから書き換え可能なメンバはありません。</p>
<h4>FatFs</h4>
<pre>
typedef struct _FIL {
DWORD fptr; // File R/W pointer
DWORD fsize; // File size
DWORD org_clust; // File start cluster
DWORD curr_clust; // Current cluster
DWORD curr_sect; // Current sector
DWORD dir_sect; // Sector# containing the directory entry
BYTE* dir_ptr; // Ponter to the directory entry in the window
BYTE flag; // File status flags
BYTE sect_clust; // Left sectors in current cluster
BYTE buffer[512]; // File R/W buffer
FATFS* fs; /* Pointer to the owner file system object */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster */
DWORD curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
BYTE buffer[512]; /* File R/W buffer */
} FIL;
</pre>
<h4>Tiny-FatFs</h4>
<pre>
typedef struct _FIL {
DWORD fptr; // File R/W pointer
DWORD fsize; // File size
WORD org_clust; // File start cluster
WORD curr_clust; // Current cluster
DWORD curr_sect; // Current sector
DWORD dir_sect; // Sector# containing the directory entry
BYTE* dir_ptr; // Ponter to the directory entry in the window
BYTE flag; // File status flags
BYTE sect_clust; // Left sectors in current cluster
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
} FIL;
</pre>
</div>

View File

@ -15,11 +15,11 @@
<p><tt>FILINFO</tt>構造体は、<tt>f_stat(), f_readdir()</tt>で返されるファイル情報を保持します。</p>
<pre>
typedef struct _FILINFO {
DWORD fsize; // Size
WORD fdate; // Date
WORD ftime; // Time
BYTE fattrib; // Attribute
char fname[8+1+3+1]; // Name
DWORD fsize; /* Size */
WORD fdate; /* Date */
WORD ftime; /* Time */
BYTE fattrib; /* Attribute */
char fname[8+1+3+1]; /* Name */
} FILINFO;
</pre>
</div>

View File

@ -15,19 +15,19 @@
<p></p>
<pre>
FRESULT f_stat (
const char* <em>FileName</em>, // ファイルまたはディレクトリ名へのポインタ
FILINFO* <em>FileInfo</em> // ファイル情報構造体へのポインタ
const char* <em>FileName</em>, /* ファイルまたはディレクトリ名へのポインタ */
FILINFO* <em>FileInfo</em> /* ファイル情報構造体へのポインタ *
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileName</dt>
<dd>情報を得るファイルまたはディレクトリ名の<tt>'\0'</tt>で終わる文字列を指すポインタを指定します。ルートディレクトリの指定は禁止です。</dd>
<dt>FileInfo</dt>
<dd>読み出し結果を格納するファイル情報構造体へのポインタを指定します。</dd>
<dd>読み出したファイル情報を格納するファイル情報構造体へのポインタを指定します。</dd>
</dl>
</div>
@ -43,14 +43,14 @@ FRESULT f_stat (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>論理ドライブにワークエリアが割り当てられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>

View File

@ -15,16 +15,16 @@
<p>書き込み中のファイルのキャッシュされた情報をフラッシュします。</p>
<pre>
FRESULT f_sync (
FIL* <em>FileObject</em> // ファイルオブジェクト構造体へのポインタ
FIL* <em>FileObject</em> /* ファイル・オブジェクト構造体へのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>syncするファイルオブジェクト構造体へのポインタを指定します。</dd>
<dd>syncするファイルのファイル・オブジェクト構造体へのポインタを指定します。</dd>
</dl>
</div>
@ -35,19 +35,19 @@ FRESULT f_sync (
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスク・ドライブが動作不能状態</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>ファイル・オブジェクトが無効</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>この関数は<tt>f_close()</tt>と同じ処理を実行しますが、ファイルは引き続き開かれたままになり、読み書きを続行できます。ロギングなど、書き込みモードで長時間ファイルが開かれているアプリケーションにおいて、定期的または区切りの良いところでsyncすることにより、不意の電源断やメディアの取り外しにより失われるデータを最小にすることができます。</p>
<p>リードオンリー構成ではこの関数はサポートされません。</p>
<p>この関数は<tt>f_close()</tt>と同じ処理を実行しますが、ファイルは引き続き開かれたままになり、読み書きを続行できます。ロギングなど、書き込みモードで長時間ファイルが開かれているアプリケーションにおいて、定期的または区切りの良いところでsyncすることにより、不意の電源断やメディアの取り外しにより失われるデータを最小にすることができます。</p>
<p>リードオンリー構成ではこの関数はサポートされません。</p>
</div>

View File

@ -15,16 +15,16 @@
<p>ファイルまたはディレクトリを削除します。</p>
<pre>
FRESULT f_unlink (
const char* <em>FileName</em> // ファイルまたはディレクトリ名へのポインタ
const char* <em>FileName</em> /* ファイルまたはディレクトリ名へのポインタ */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileName</dt>
<dd>削除対象のファイルまたはディレクトリ名の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。リードオンリー構成および _FS_MINIMIZE &gt;= 1 ではこの関数はサポートされません</dd>
<dd>削除対象の<a href="filename.html">ファイルまたはディレクトリ名</a>の入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。</dd>
</dl>
</div>
@ -40,18 +40,18 @@ FRESULT f_unlink (
<dd>パスが見つからない。</dd>
<dt>FR_INVALID_NAME</dt>
<dd>パス名が不正。</dd>
<dt>FR_INVALID_DRIVE</dt>
<dd>ドライブ番号が不正。</dd>
<dt>FR_DENIED</dt>
<dd>対象ファイル・ディレクトリがリードオンリー状態、対象ディレクトリが空でない場合など。</dd>
<dd>対象ファイル・ディレクトリがリードオンリー状態、対象ディレクトリが空でない場合など。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_WRITE_PROTECTED</dt>
<dd>メディアが書き込み禁止状態。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_INCORRECT_DISK_CHANGE</dt>
<dd>不正なメディアの取り外しがあった。ファイルを開いたままのメディア交換など。</dd>
<dd>ディスク・アクセスでエラーが発生した。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>論理ドライブにワーク・エリアが割り当てられていない。</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>ディスク上に有効なFATパーテーションが見つからない。</dd>
</dl>
@ -60,7 +60,7 @@ FRESULT f_unlink (
<div class="para">
<h4>解説</h4>
<p>ファイルまたはディレクトリを削除します。<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
<p>ファイルまたはディレクトリを削除します。リード・オンリー構成や<tt>_FS_MINIMIZE &gt;= 1</tt>ではこの関数はサポートされません。</p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>

View File

@ -15,19 +15,19 @@
<p>ファイルにデータを書き込みます。</p>
<pre>
FRESULT f_write (
FIL* <em>FileObject</em>, // ファイルオブジェクト構造体
const void* <em>Buffer</em>, // 書き込みデータ
WORD <em>ByteToWrite</em>, // 書き込むバイト数
WORD* <em>ByteWritten</em> // 書き込まれたバイト数
FIL* <em>FileObject</em>, /* ファイル・オブジェクト */
const void* <em>Buffer</em>, /* 書き込みデータ */
WORD <em>ByteToWrite</em>, /* 書き込むバイト数 */
WORD* <em>ByteWritten</em> /* 書き込まれたバイト数 */
);
</pre>
</div>
<div class="para">
<h4>パラメータ</h4>
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>ファイルオブジェクト構造体へのポインタを指定します。</dd>
<dd>ファイルオブジェクト構造体へのポインタを指定します。</dd>
<dt>Buffer</dt>
<dd>書き込むデータを格納したバッファを指すポインタを指定します。</dd>
<dt>ByteToWrite</dt>
@ -46,18 +46,18 @@ FRESULT f_write (
<dt>FR_DENIED</dt>
<dd>読み込み専用モードで開いたファイルに書き込もうとした。</dd>
<dt>FR_RW_ERROR</dt>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dd>ディスクアクセスでエラーが発生した。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>FatFsモジュールが停止状態</dd>
<dd>メディアがセットされていないなど、ディスクドライブが動作不能状態。</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイルオブジェクト</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>書き込み開始位置は、ファイルR/Wポインタの現在位置からになります。ファイルR/Wポインタは実際に書き込まれたバイト数だけ進みます。書き込み中にディスクが一杯になったときは、<tt>*ByteWritten</tt><tt>ByteToWrite</tt>よりも小さくなります。リードオンリー構成ではこの関数はサポートされません。</p>
<p>書き込み開始位置は、ファイルR/Wポインタの現在位置からになります。ファイルR/Wポインタは実際に書き込まれたバイト数だけ進みます。書き込み中にディスクが一杯になったときは、<tt>*ByteWritten</tt><tt>ByteToWrite</tt>よりも小さくなります。リードオンリー構成ではこの関数はサポートされません。</p>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,4 +1,4 @@
FatFs/Tiny-FatFs Module Source Files R0.03a (C)ChaN, 2006
FatFs/Tiny-FatFs Module Source Files R0.04 (C)ChaN, 2007
FILES
@ -23,45 +23,64 @@ CONFIGURATION OPTIONS
requirement. The configuration options are defined in header files, ff.h
and tff.h.
_BYTE_ACC
_MCU_ENDIAN
This is the most impotant option that depends on the processor architecture.
When your microcontroller corresponds to either or both of following terms,
the _BYTE_ACC must be defined to force FatFs to access FAT structure in
byte-by-byte. If not, this can be undefined to improve code size. This is
UNDEFINED in default.
When target device corresponds to either or both of following terms, the
_MCU_ENDIAN must be set to 2 to force FatFs to access FAT structure in
byte-by-byte. If not the case, this can be set to 1 for good code efficiency.
The initial value is 0 (must be set to 1 or 2 properly).
- Muti-byte integers (short, long) are stored in Big-Endian.
- Address miss-aligned memory access causes an address error or any
incorrect behavior.
- Address miss-aligned memory access results in an incorrect behavior.
_FS_READONLY
When application program does not require any write function, _FS_READONLY
can be defined to eliminate writing code to reduce module size. This is
UNDEFINED in default. This setting should be reflected to configurations for
low level disk function if available.
can be set to 1 to eliminate writing code to reduce module size. This
setting should be reflected to configurations of low level disk I/O module
if available. The initial value is 0 (R/W).
_FS_MINIMIZE
When application program requires only file read/write function, _FS_MINIMIZE
can be defined to eliminate some functions to reduce the module size. The
default value is 0 (full function).
can be defined to eliminate some functions to reduce the module size. The
initial value is 0 (full function).
_DRIVES
Number of drives to be used. This option is not supported on Tiny-FatFs.
The initial value is 2.
_FAT32
When _FAT32 is set to 1, the FAT32 support is added with an additional
code size. This is for only Tiny-FatFs and not supported on FatFs. FatFs
always supports all FAT type. The initial value is 0 (disabled).
_USE_SJIS
When _USE_SJIS is defined, Shift-JIS code set can be used as a file name,
otherwire second byte of double-byte characters will be collapted. This is
DEFINED in default.
initially defined.
_USE_MKFS
When _USE_MKFS is defined and _FS_READONLY is set to 0, f_mkfs function
is enabled. This is for only FatFs module and not supported on Tiny-FatFs.
This is initialy undefined (not available).
Following table shows which function is removed by configuratin options.
_FS_MINIMIZE _FS_MINIMIZE _FS_READONLY
(1) (2)
_FS_MINIMIZE _FS_MINIMIZE _FS_READONLY _USE_MKFS
(1) (2) (1) (undef)
f_mount
f_open
f_close
f_read
@ -76,7 +95,7 @@ CONFIGURATION OPTIONS
f_mkdir x x x
f_chmod x x x
f_rename x x x
f_mountdrv
f_mkfs x x
@ -92,11 +111,20 @@ AGREEMENTS
REVISION HISTORY
Feb 26, 2006 R0.00 Prototype
Apr 29, 2006 R0.01 First stable version
Jun 01, 2006 R0.02 Added FAT12. Removed unbuffered mode.
Fixed a problem on small (<32M) patition.
Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM.
Sep 22, 2006 R0.03 Added f_rename().
Changed option _FS_MINIMUM to _FS_MINIMIZE.
Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast.
Fixed f_mkdir() creates incorrect directory on FAT32.
Feb 04, 2007 R0.04 Supported multiple drive system.
Changed some APIs for multiple drive system.
Added f_mkfs().

View File

@ -1,10 +1,10 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.02 (C)ChaN, 2006
/ Low level disk interface modlue include file R0.04 (C)ChaN, 2007
/-----------------------------------------------------------------------*/
#ifndef _DISKIF
#ifndef _DISKIO
//#define _READONLY /* Define this for read-only use */
#define _READONLY 0 /* 1: Read-only mode */
#include "integer.h"
@ -15,15 +15,14 @@ typedef unsigned char DRESULT;
/*---------------------------------------*/
/* Prototypes for disk control functions */
DSTATUS disk_initialize ();
DSTATUS disk_shutdown ();
DSTATUS disk_status ();
DRESULT disk_read (BYTE*, DWORD, BYTE);
#ifndef _READONLY
DRESULT disk_write (const BYTE*, DWORD, BYTE);
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (BYTE, void*);
void disk_timerproc ();
DRESULT disk_ioctl (BYTE, BYTE, void*);
void disk_timerproc (void);
/* Results of Disk Functions (DRESULT) */
@ -45,7 +44,9 @@ void disk_timerproc ();
/* Command code for disk_ioctrl() */
#define GET_SECTORS 1
#define PUT_IDLE_STATE 2
#define CTRL_POWER 2
#define CTRL_LOCK 3
#define CTRL_EJECT 4
#define MMC_GET_CSD 10
#define MMC_GET_CID 11
#define MMC_GET_OCR 12
@ -54,5 +55,5 @@ void disk_timerproc ();
#define ATA_GET_SN 22
#define _DISKIF
#define _DISKIO
#endif

1174
src/ff.c

File diff suppressed because it is too large Load Diff

102
src/ff.h
View File

@ -1,11 +1,11 @@
/*--------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.03a (C)ChaN, 2006
/ FatFs - FAT file system module include file R0.04 (C)ChaN, 2007
/---------------------------------------------------------------------------/
/ FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2006, ChaN, all right reserved.
/ Copyright (C) 2007, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
@ -16,27 +16,36 @@
#ifndef _FATFS
#error Don't forget to change these options.
#define _MCU_ENDIAN 0
/* The _MCU_ENDIAN defines which access method is used to the FAT structure.
/ 1: Enable word access.
/ 2: Disable word access and use byte-by-byte access instead.
/ When the architectural byte order of the MCU is big-endian and/or address
/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2.
/ If it is not the case, it can be set to 1 for good code efficiency. */
//#define _BYTE_ACC
/* The _BYTE_ACC enables byte-by-byte access for multi-byte variables. This
/ MUST be defined when multi-byte variable is stored in big-endian and/or
/ address miss-aligned access is prohibited. */
//#define _FS_READONLY
/* Read only configuration. This removes writing functions, f_write, f_sync,
/ f_unlink, f_mkdir, f_chmod, f_rename and f_getfree. */
#define _FS_READONLY 0
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename
/ and useless f_getfree. */
#define _FS_MINIMIZE 0
/* The _FS_MINIMIZE defines minimization level to remove some functions.
/ 0: Not minimized.
/* 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 and f_rename are removed.
/ 2: f_opendir and f_readdir are removed in addition to level 1. */
#define _DRIVES 2
/* Number of logical drives to be used */
#define _USE_SJIS
/* When _USE_SJIS is defined, Shift-JIS code transparency is enabled, otherwise
/ only US-ASCII(7bit) code can be accepted as file/directory name. */
/* #define _USE_MKFS */
/* When _USE_MKFS is defined and _FS_READONLY is set to 0, f_mkfs function
is enabled. */
#include "integer.h"
@ -48,12 +57,11 @@ typedef unsigned char FRESULT;
/* File system object structure */
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
BYTE drive; /* Physical drive number */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD sects_fat; /* Sectors per fat */
DWORD max_clust; /* Maximum cluster# + 1 */
@ -61,30 +69,35 @@ typedef struct _FATFS {
DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */
DWORD database; /* Data start sector */
DWORD last_clust; /* Last allocated cluster */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT */
} FATFS;
/* Directory object structure */
typedef struct _DIR {
FATFS* fs; /* Pointer to the owner file system object */
DWORD sclust; /* Start cluster */
DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
/* File object structure */
typedef struct _FIL {
FATFS* fs; /* Pointer to the owner file system object */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster */
DWORD curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
#ifndef _FS_READONLY
#if _FS_READONLY == 0
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
BYTE buffer[512]; /* File R/W buffer */
@ -105,28 +118,27 @@ typedef struct _FILINFO {
/*-----------------------------------------------------*/
/* FatFs module application interface */
extern FATFS *FatFs; /* Pointer to active file system object */
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read file */
FRESULT f_close (FIL*); /* Close file */
FRESULT f_lseek (FIL*, DWORD); /* Seek file pointer */
FRESULT f_opendir (DIR*, const char*); /* Open a directory */
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */
FRESULT f_getfree (DWORD*); /* Get number of free clusters */
FRESULT f_mountdrv (void); /* Force initialized the file system */
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write file */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete a file or directory */
FRESULT f_mkdir (const char*); /* Create a directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file attriburte */
FRESULT f_rename (const char*, const char*); /* Rename a file or directory */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
FRESULT f_mkfs (BYTE, BYTE, BYTE); /* Create a file system on the drive */
/* User defined function to give a current time to fatfs module */
DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
@ -138,20 +150,22 @@ DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16:
#define FR_NO_FILE 2
#define FR_NO_PATH 3
#define FR_INVALID_NAME 4
#define FR_DENIED 5
#define FR_DISK_FULL 6
#define FR_RW_ERROR 7
#define FR_INCORRECT_DISK_CHANGE 8
#define FR_INVALID_DRIVE 5
#define FR_DENIED 6
#define FR_DISK_FULL 7
#define FR_RW_ERROR 8
#define FR_WRITE_PROTECTED 9
#define FR_NOT_ENABLED 10
#define FR_NO_FILESYSTEM 11
#define FR_INVALID_OBJECT 12
#define FR_MKFS_ABORTED 13
/* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#ifndef _FS_READONLY
#if _FS_READONLY == 0
#define FA_WRITE 0x02
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
@ -182,16 +196,20 @@ DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16:
/* Multi-byte word access macros */
#ifdef _BYTE_ACC
#if _MCU_ENDIAN == 1 /* Use word access */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else
#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24)
#else
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#error Don't forget to set _MCU_ENDIAN properly!
#endif
#endif

View File

@ -1,14 +1,19 @@
#ifndef _INTEGER
typedef unsigned char BYTE;
typedef unsigned char UCHAR;
typedef int INT;
typedef unsigned int UINT;
typedef char CHAR;
typedef unsigned short WORD;
typedef unsigned short USHORT;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
typedef short SHORT;
typedef unsigned long DWORD;
typedef unsigned long ULONG;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
typedef unsigned char BOOL;
#define FALSE 0

924
src/tff.c

File diff suppressed because it is too large Load Diff

113
src/tff.h
View File

@ -1,11 +1,11 @@
/*--------------------------------------------------------------------------/
/ Tiny-FatFs - FAT file system module include file R0.03a (C)ChaN, 2006
/ Tiny-FatFs - FAT file system module include file R0.04 (C)ChaN, 2007
/---------------------------------------------------------------------------/
/ FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2006, ChaN, all right reserved.
/ Copyright (C) 2007, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
@ -16,23 +16,28 @@
#ifndef _FATFS
#error Don't forget to change these options.
#define _MCU_ENDIAN 0
/* The _MCU_ENDIAN defines which access method is used to the FAT structure.
/ 1: Enable word access.
/ 2: Disable word access and use byte-by-byte access instead.
/ When the architectural byte order of the MCU is big-endian and/or address
/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2.
/ If it is not the case, it can be set to 1 for good code efficiency. */
//#define _BYTE_ACC
/* The _BYTE_ACC enables byte-by-byte access for multi-byte variables. This
/ MUST be defined when multi-byte variable is stored in big-endian and/or
/ address miss-aligned access is prohibited. */
//#define _FS_READONLY
/* Read only configuration. This removes writing functions, f_write, f_sync,
/ f_unlink, f_mkdir, f_chmod, f_rename and g_getfree. */
#define _FS_READONLY 0
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename
/ and useless f_getfree. */
#define _FS_MINIMIZE 0
/* The _FS_MINIMIZE defines minimization level to remove some functions.
/ 0: Not minimized.
/* 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 and f_rename are removed.
/ 2: f_opendir and f_readdir are removed in addition to level 1. */
/* #define _FAT32 0 */
/* When enable FAT32 support, set _FAT32 to 1. */
#define _USE_SJIS
/* When _USE_SJIS is defined, Shift-JIS code transparency is enabled, otherwise
/ only US-ASCII(7bit) code can be accepted as file/directory name. */
@ -43,48 +48,56 @@
/* Result type for fatfs application interface */
typedef unsigned char FRESULT;
#if _FAT32 == 0
typedef WORD CLUST;
#else
typedef DWORD CLUST;
#endif
/* File system object structure */
typedef struct _FATFS {
BYTE fs_type; /* FAT type */
BYTE files; /* Number of files currently opend */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
WORD n_rootdir; /* Number of root directory entry */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
WORD sects_fat; /* Sectors per fat */
WORD max_clust; /* Maximum cluster# + 1 */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector */
DWORD database; /* Data start sector */
WORD last_clust; /* Last allocated cluster */
CLUST sects_fat; /* Sectors per fat */
CLUST max_clust; /* Maximum cluster# + 1 */
CLUST last_clust; /* Last allocated cluster */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
} FATFS;
/* Directory object structure */
typedef struct _DIR {
WORD sclust; /* Start cluster */
WORD clust; /* Current cluster */
FATFS* fs; /* Pointer to the owner file system object */
CLUST sclust; /* Start cluster */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
WORD index; /* Current index */
WORD id; /* Sum of owner file system mount ID */
} DIR;
/* File object structure */
typedef struct _FIL {
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
WORD org_clust; /* File start cluster */
WORD curr_clust; /* Current cluster */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
#ifndef _FS_READONLY
#if _FS_READONLY == 0
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
WORD id; /* Sum of owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
} FIL;
@ -104,28 +117,26 @@ typedef struct _FILINFO {
/*-----------------------------------------------------*/
/* FatFs module application interface */
extern FATFS *FatFs; /* Pointer to active file system object */
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read file */
FRESULT f_close (FIL*); /* Close file */
FRESULT f_lseek (FIL*, DWORD); /* Seek file pointer */
FRESULT f_opendir (DIR*, const char*); /* Open a directory */
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */
FRESULT f_getfree (DWORD*); /* Get number of free clusters */
FRESULT f_mountdrv (void); /* Force initialized the file system */
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write file */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete a file or directory */
FRESULT f_mkdir (const char*); /* Create a directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file attriburte */
FRESULT f_rename (const char*, const char*); /* Rename a file or directory */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
/* User defined function to give a current time to fatfs module */
DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
@ -137,20 +148,21 @@ DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16:
#define FR_NO_FILE 2
#define FR_NO_PATH 3
#define FR_INVALID_NAME 4
#define FR_DENIED 5
#define FR_DISK_FULL 6
#define FR_RW_ERROR 7
#define FR_INCORRECT_DISK_CHANGE 8
#define FR_INVALID_DRIVE 5
#define FR_DENIED 6
#define FR_DISK_FULL 7
#define FR_RW_ERROR 8
#define FR_WRITE_PROTECTED 9
#define FR_NOT_ENABLED 10
#define FR_NO_FILESYSTEM 11
#define FR_INVALID_OBJECT 12
/* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#ifndef _FS_READONLY
#if _FS_READONLY == 0
#define FA_WRITE 0x02
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
@ -163,6 +175,7 @@ DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16:
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
/* File attribute bits for directory entry */
@ -179,16 +192,20 @@ DWORD get_fattime(void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16:
/* Multi-byte word access macros */
#ifdef _BYTE_ACC
#if _MCU_ENDIAN == 1 /* Use word access */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else
#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24)
#else
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#error Don't forget to set _MCU_ENDIAN properly!
#endif
#endif