fatfs v0.02 Jun 01, 2006:
- Added FAT12. Removed unbuffered mode. - Fixed a problem on small (<32M) patition.
This commit is contained in:
		
							parent
							
								
									4f7376e6aa
								
							
						
					
					
						commit
						238747ef97
					
				| @ -5,7 +5,7 @@ | ||||
| <meta http-equiv="Content-Style-Type" content="text/css"> | ||||
| <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>FatFs - FAT Files System Module</title> | ||||
| <title>ELM - Generic FAT Files System Module</title> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
| @ -14,35 +14,35 @@ | ||||
| 
 | ||||
| <div class="abst"> | ||||
| <img src="layers.png" class="rset" width="245" height="255"> | ||||
| <p>FatFs module is an experimental project to implement a FAT file system to small embdded system. Because the module is written in compliance with ANSI C, it can be used for most 8/16 bit microcontrollers, such as PIC, AVR, H8, Z80 and etc..., without any modification. To use the FatFs module, low level disk I/O functions for each recording media must be provided by user. I created two modules in different configurations in consideration of various use. For read only applications, wriiting codes can also be eliminated to reduce the code size.</p> | ||||
| <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 implemented to most 8/16 small microcontrollers, such as PIC, AVR, H8, Z80 and etc..., without any changes. I created two modules in different configurations in consideration of various use. For read only applications, writing codes can also be eliminated to reduce the module size. 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>Low memory consumption (ex. avr-gcc) | ||||
|   <ul> | ||||
|    <li>Program Code: 7752 bytes (R/W cfg.), 4154 bytes (R/O cfg.)</li> | ||||
|    <li>Module Size: 8282 bytes (R/W cfg.), 4482 bytes (R/O cfg.)</li> | ||||
|    <li>Static Work Area: 2 bytes</li> | ||||
|    <li>Dynamic Work Area: 544 + 542 * <files> bytes</li> | ||||
|    <li>Dynamic Work Area: 544 + 540 * <files> bytes</li> | ||||
|   </ul> | ||||
|  </li> | ||||
|  <li>Supports FAT16(+FAT64) and FAT32 <small>(FAT64: FAT16 in 64KB/cluster)</small></li> | ||||
|  <li>Supports FAT12, FAT16(+FAT64) and FAT32 <small>(FAT64: FAT16 in 64KB/cluster)</small></li> | ||||
|  <li>Supports 8.3 format file name and NT lower capital flags</li> | ||||
|  <li>Supports two partitioning formats: FDISK (only primariy partition) and SFD (only 512B/sector)</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>Low memory consumption (ex. avr-gcc), suitable for small memory system (1KB) | ||||
|   <ul> | ||||
|    <li>Program Code: 6470 bytes (R/W cfg.), 3556 bytes (R/O cfg.)</li> | ||||
|    <li>Module Size: 6868 bytes (R/W cfg.), 3804 bytes (R/O cfg.)</li> | ||||
|    <li>Static Work Area: 2 bytes</li> | ||||
|    <li>Dynamic Work Area: 538 + 24 * <files> bytes</li> | ||||
|   </ul> | ||||
|  </li> | ||||
|  <li>Supports FAT16(+FAT64)</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 primariy partition) and SFD (only 512B/sector)</li> | ||||
|  <li>Supports two partitioning formats: FDISK (only 1st primariy partition) and SFD (only 512B/sector)</li> | ||||
| </ul> | ||||
| </div> | ||||
| 
 | ||||
| @ -71,7 +71,7 @@ | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h3>Disk I/O Interface</h3> | ||||
| <p>FatFs module and Tiny-FatFs module require following functions to lower layer to read/write to physical disk and to get current time.</p> | ||||
| <p>FatFs module and Tiny-FatFs module require following functions to lower layer to read/write physical disk and to get current time.</p> | ||||
| <ul> | ||||
| <li><a href="en/dinit.html">disk_initialize</a> - Initialize disk drive</li> | ||||
| <li><a href="en/dstat.html">disk_status</a> - Get disk status</li> | ||||
| @ -87,7 +87,7 @@ | ||||
| <p>The FatFs module is opened for education, reserch and development. You can use, modify and republish it for personal, non-profit or profit use without any limitation under your responsibility.</p> | ||||
| <br> | ||||
| <ul> | ||||
| <li><a href="rwtest.png">Bench Mark</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="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="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FAT32 Specification</a> (Microsoft)</li> | ||||
| <li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to Use an MMC</a></li> | ||||
| </ul> | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| <meta http-equiv="Content-Style-Type" content="text/css"> | ||||
| <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>FatFs - FAT Files System Module</title> | ||||
| <title>ELM - 汎用FATファイルシステム・モジュール</title> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
| @ -14,18 +14,18 @@ | ||||
| 
 | ||||
| <div class="abst"> | ||||
| <img src="layers.png" class="rset" width="245" height="255"> | ||||
| <p>小規模な組み込みシステム向けの汎用FATファイルシステム・モジュールです。ANSI C準拠でハードウェア・プラットフォームには依存しないので、必要なワークエリアが確保できれば、PIC, AVR, H8, Z80などほとんどのマイコンでそのまま使用可能です。実際に使用するには、各記録メディア(CFC, MMC, SDC, ATA, USB, SCSI等)に対応したディスクI/Oモジュールを用意する必要があります。いろいろな使用形態を考慮して、高速版(FatFs)と省メモリ版(Tiny-FatFs)の2通りを作成してみました。読み出し専用アプリケーションではさらに書き込み関係のコードを削減した構成もできます。</p> | ||||
| <p>小規模な組み込みシステム向けの汎用FATファイルシステム・モジュールです。ANSI C準拠でハードウェア・アーキテクチャには依存しないので、必要なワークエリアが確保できれば、PIC, AVR, H8, Z80などほとんどのマイコンでそのまま使用可能です。いろいろな使用形態を考慮して、高速版(FatFs)と省メモリ版(Tiny-FatFs)の2通りを作成してみました。読み出し専用アプリケーションではさらに書き込み関係のコードを削減した構成もできます。実際に使用するには、各記録メディア(CFC, MMC, SDC, ATA, USB, SCSI等)に対応したディスクI/Oモジュールを用意する必要があります。</p> | ||||
| <h4>FatFsモジュールの特徴</h4> | ||||
| <ul> | ||||
|  <li>システム用と各ファイル用バッファを分離し、複数ファイルの高速アクセスに適する</li> | ||||
|  <li>メモリの消費が少ない(avrgccでの例) | ||||
|   <ul> | ||||
|    <li>プログラム・エリア: 7736 bytes (R/W構成), 4154 bytes (R/O構成)</li> | ||||
|    <li>プログラム・エリア: 8282 bytes (R/W構成), 4482 bytes (R/O構成)</li> | ||||
|    <li>静的ワーク・エリア: 2 bytes</li> | ||||
|    <li>動的ワーク・エリア: 544 + 542 * <files> bytes</li> | ||||
|    <li>動的ワーク・エリア: 544 + 540 * <files> bytes</li> | ||||
|   </ul> | ||||
|  </li> | ||||
|  <li>FAT16(+FAT64), FAT32に対応 <small>(FAT64: FAT16 in 64KB/cluster)</small></li> | ||||
|  <li>FAT12, FAT16(+FAT64), FAT32に対応 <small>(FAT64: FAT16 in 64KB/cluster)</small></li> | ||||
|  <li>8.3形式ファイル名とNT小文字フラグに対応</li> | ||||
|  <li>FDISKフォーマット(基本区画)およびSFDフォーマット(512B/sectorのみ)に対応</li> | ||||
| </ul> | ||||
| @ -34,12 +34,12 @@ | ||||
|  <li>システム用と各ファイル用バッファを共通化し、RAMの使用量を削減</li> | ||||
|  <li>メモリの消費が少なく(avrgccでの例)、小メモリ・システム(1KB)に対応</li> | ||||
|   <ul> | ||||
|    <li>プログラム・エリア: 6470 bytes (R/W構成), 3556 bytes (R/O構成)</li> | ||||
|    <li>プログラム・エリア: 6868 bytes (R/W構成), 3804 bytes (R/O構成)</li> | ||||
|    <li>静的ワーク・エリア: 2 bytes</li> | ||||
|    <li>動的ワーク・エリア: 538 + 24 * <files> bytes</li> | ||||
|   </ul> | ||||
|  </li> | ||||
|  <li>FAT16(+FAT64)に対応</li> | ||||
|  <li>FAT12, FAT16(+FAT64)に対応</li> | ||||
|  <li>8.3形式ファイル名とNT小文字フラグに対応</li> | ||||
|  <li>FDISKフォーマット(基本区画)およびSFDフォーマット(512B/sectorのみ)に対応</li> | ||||
| </ul> | ||||
| @ -83,7 +83,7 @@ | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h3>資料</h3> | ||||
| <p>FatFsモジュールとTiny-FatFsモジュールは教育・研究・開発用に公開しています。どのような目的(個人・非商用・商用)の利用でも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。</p> | ||||
| <p>FatFsモジュールとTiny-FatFsモジュールは教育・研究・開発用に公開しています。どのような利用目的(個人・非商用・商用)でも使用・改変・配布について一切の制限はありませんが、全て利用者の責任の下での利用とします。</p> | ||||
| <br> | ||||
| <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> | ||||
|  | ||||
| @ -30,6 +30,7 @@ a.imglnk img {border: 1px solid;} | ||||
| .iequ {white-space: nowrap; font-weight: bold;} | ||||
| .clr {clear: both;} | ||||
| .it {font-style: italic;} | ||||
| .mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap} | ||||
| 
 | ||||
| h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;} | ||||
| p.hdd {float: right; text-align: right; margin-top: 0.5em;} | ||||
|  | ||||
| @ -33,6 +33,7 @@ a.imglnk img {border: 1px solid;} | ||||
| .iequ {white-space: nowrap; font-weight: bold;} | ||||
| .clr {clear: both;} | ||||
| .it {font-style: italic;} | ||||
| .mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap} | ||||
| 
 | ||||
| h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;} | ||||
| p.hdd {float: right; text-align: right; margin-top: 0.5em;} | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_chmod</title> | ||||
| </head> | ||||
| @ -60,7 +61,7 @@ FRESULT f_chmod ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_close</title> | ||||
| </head> | ||||
| @ -36,7 +37,7 @@ FRESULT f_close ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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> | ||||
| </dl> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_initialize</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_read</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_status</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_write</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - get_fattime</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_getfree</title> | ||||
| </head> | ||||
| @ -38,7 +39,7 @@ FRESULT f_getfree ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_lseek</title> | ||||
| </head> | ||||
| @ -36,12 +37,10 @@ FRESULT f_lseek ( | ||||
| <dl class="ret"> | ||||
| <dt>FR_OK</dt> | ||||
| <dd>The function succeeded.</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>Out of alignment. In unbuffered mode, specified offset must be aligned on 512 byte boundary.</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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| </dl> | ||||
| @ -59,15 +58,15 @@ FRESULT f_lseek ( | ||||
| <pre> | ||||
|     // Move to offset of 5000 from top of file. | ||||
|     res = f_lseek(&file, 5000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Move to 3000 bytes front of current offset. | ||||
|     // Forward 3000 bytes | ||||
|     res = f_lseek(&file, file.fptr + 3000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Move to 2000 bytes back of current offset. | ||||
|     // Rewind 2000 bytes | ||||
|     res = f_lseek(&file, file.fptr - 2000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Move to end of file | ||||
|     res = f_lseek(&file, 0xFFFFFFFF); | ||||
| </pre> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_mkdir</title> | ||||
| </head> | ||||
| @ -46,7 +47,7 @@ FRESULT f_mkdir ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_mountdrv</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_open</title> | ||||
| </head> | ||||
| @ -25,19 +26,18 @@ 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 function succeeded, the file can be accessed with the file object structure until it is closed. The member <tt>buffer</tt> in the structure must be initialized with the address of a 512 bytes file read/write buffer before or immediataly after the f_open function. The initialization is not needed when <tt>FA_UNBUFFERED</tt> flag has been specified.</dd> | ||||
| <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> | ||||
| <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> | ||||
| <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"> | ||||
| <tr><th>Value</th><th>Description</th></td> | ||||
| <tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.<br>Combine with FA_WRITE for read-write access.</td></td> | ||||
| <tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file.<br>Combine with FA_READ for read-write access.</td></td> | ||||
| <tr><td>FA_UNBUFFERED</td><td>This is for only FatFs module. When not specified, the file can be read/written in<br>stream I/O via the file read/write buffer pointed by member 'buffer' in the file<br>object. When specified, file read/write buffer is not used and number of bytes<br>to read/write must be integer multiple of 512. </td></td> | ||||
| <tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file does not exist.</td></td> | ||||
| <tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file exists, it is truncated and overwritten.</td></td> | ||||
| <tr><td>FA_OPEN_ALWAYS</td><td>Opens the file, if it exists. If the file does not exist, the function creates the file.</td></td> | ||||
| <tr><th>Value</th><th>Description</th></tr> | ||||
| <tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.<br>Combine with FA_WRITE for read-write access.</td></tr> | ||||
| <tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file.<br>Combine with FA_READ for read-write access.</td></tr> | ||||
| <tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file does not exist.</td></tr> | ||||
| <tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file exists, it is truncated and overwritten.</td></tr> | ||||
| <tr><td>FA_OPEN_ALWAYS</td><td>Opens the file, if it exists. If the file does not exist, the function creates the file.</td></tr> | ||||
| </table> | ||||
| </dd> | ||||
| </dl> | ||||
| @ -64,7 +64,7 @@ FRESULT f_open ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
| @ -75,46 +75,41 @@ FRESULT f_open ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>Description</h4> | ||||
| <p>To start to use the FatFs module, prepare a work area (<tt>FATFS</tt> structure), clear the structure and store the address to the global variable 'FatFs' to allocate the work area to the FatFs module. Then the FatFs module can work.</p> | ||||
| <p>Flags <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt> are not supported in read-only configuration. Flag <tt>FA_UNBUFFERED</tt> is not supported in Tiny-FatFs.</p> | ||||
| <p>To start to use the FatFs module, prepare a work area (<tt>FATFS</tt> structure), clear it and set its address to the global pointer 'FatFs' to allocate the work area to the FatFs module. Then the FatFs module can work.</p> | ||||
| <p>Flags <tt>FA_WRITE, FA_CREATE_ALWAYS, FA_OPEN_ALWAYS</tt> are not supported in read-only configuration.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>Sample Code</h4> | ||||
| <h4>Example (File Copy)</h4> | ||||
| <pre> | ||||
| void main () | ||||
| { | ||||
|     FATFS fs;            // FatFs work area | ||||
|     FIL fsrc, fdst;      // file structures | ||||
|     BYTE fbuff[512*2];   // file r/w buffers (not required for Tiny-FatFs) | ||||
|     BYTE buffer[4096];   // file copy buffer | ||||
|     FRESULT res;         // FatFs function common result code | ||||
|     WORD br, bw;         // File R/W count | ||||
| 
 | ||||
| 
 | ||||
|     // Activate FatFs module | ||||
|     // Give a work area for FatFs (activate module) | ||||
|     memset(&fs, 0, sizeof(FATFS)); | ||||
|     FatFs = &fs; | ||||
| 
 | ||||
|     // Open source file | ||||
|     fsrc.buffer = fbuff+0;	// (not required for Tiny-FatFs) | ||||
|     res = f_open(&fsrc, "/srcfile.dat", FA_OPEN_EXISTING | FA_READ); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Create destination file | ||||
|     fdst.buffer = fbuff+512;	// (not required for Tiny-FatFs) | ||||
|     res = f_open(&fdst, "/dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Copy source to destination | ||||
|     for (;;) { | ||||
|         res = f_read(&fsrc, buffer, sizeof(buffer), &br); | ||||
|         if (res) die(res); | ||||
|         if (br == 0) break; | ||||
|         if (res || br == 0) break; | ||||
|         res = f_write(&fdst, buffer, br, &bw); | ||||
|         if (res) die(res); | ||||
|         if (bw < br) break; | ||||
|         if (res || bw < br) break; | ||||
|     } | ||||
| 
 | ||||
|     // Close all files | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_opendir</title> | ||||
| </head> | ||||
| @ -35,7 +36,7 @@ FRESULT f_opendir ( | ||||
| <h4>Return Values</h4> | ||||
| <dl class="ret"> | ||||
| <dt>FR_OK</dt> | ||||
| <dd>The function succeeded. The <tt><em>DirObject</em></tt> structure is used for subsequent calls to read the directory items.</dd> | ||||
| <dd>The function succeeded. The <tt><em>DirObject</em></tt> structure is used for subsequent calls to read the directory entries.</dd> | ||||
| <dt>FR_NOPATH</dt> | ||||
| <dd>Could not find the path.</dd> | ||||
| <dt>FR_INVALID_NAME</dt> | ||||
| @ -45,7 +46,7 @@ FRESULT f_opendir ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_read</title> | ||||
| </head> | ||||
| @ -44,8 +45,6 @@ FRESULT f_read ( | ||||
| <dd>The function succeeded.</dd> | ||||
| <dt>FR_DENIED</dt> | ||||
| <dd>The function denied due to the file has been opened in write only mode.</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>The file has been opened in unbufferred mode but unaligned access was detected.</dd> | ||||
| <dt>FR_RW_ERROR</dt> | ||||
| <dd>Any error occured in low level disk I/O.</dd> | ||||
| <dt>FR_NOT_READY</dt> | ||||
| @ -58,7 +57,7 @@ FRESULT f_read ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>Description</h4> | ||||
| <p>The read/write pointer increases in number of bytes read. The <tt>ByteRead</tt> will be smaller than <tt>ByteToRead</tt> when the read pointer reached to end of the file or alignment error occured during the read operation. In unbufferred mode, last fractional bytes cannot be read due to <tt>FR_ALIGN_ERROR</tt>.</p> | ||||
| <p>The read/write pointer increases in number of bytes read. The <tt>ByteRead</tt> will be smaller than <tt>ByteToRead</tt> when the read pointer reached to end of the file or alignment error occured during the read operation.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_readdir</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - DIR</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FATFS</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FIL</title> | ||||
| </head> | ||||
| @ -11,7 +12,7 @@ | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h2>FIL</h2> | ||||
| <p>The FIL structure holds state of a file and it is allocated by an application program. Only <tt>buffer</tt> member can be initialized by the application program.</p> | ||||
| <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> | ||||
| 
 | ||||
| <h4>FatFs</h4> | ||||
| <pre> | ||||
| @ -23,9 +24,9 @@ typedef struct _FIL { | ||||
|     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*   buffer;         // Pointer to 512 byte file R/W buffer | ||||
|     BYTE    flag;           // File status flags | ||||
|     BYTE    sect_clust;     // Left sectors in current cluster | ||||
|     BYTE    buffer[512];    // File R/W buffer | ||||
| } FIL; | ||||
| </pre> | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FILINFO</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_stat</title> | ||||
| </head> | ||||
| @ -45,7 +46,7 @@ FRESULT f_stat ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_sync</title> | ||||
| </head> | ||||
| @ -36,7 +37,7 @@ FRESULT f_sync ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| </dl> | ||||
| @ -45,7 +46,7 @@ FRESULT f_sync ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>Description</h4> | ||||
| <p>The f_sync writes back the cached information of a file being written into the disk. This is the same function as f_close but the file is left opened and can continue the file access. This is suitable for an application of data logger that opens a file for long time in writing mode. The f_sync of periodic or immediataly after f_wriete can minimize the lost data due to an unintentional black out or disk removal. This function is not supported in read-only configuration.</p> | ||||
| <p>The f_sync() writes back the cached information of the file being written. This performs the same function 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> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_unlink</title> | ||||
| </head> | ||||
| @ -48,7 +49,7 @@ FRESULT f_unlink ( | ||||
| <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 opend, has been occured.</dd> | ||||
| <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 has not been enabled.</dd> | ||||
| <dt>FR_NO_FILESYSTEM</dt> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_write</title> | ||||
| </head> | ||||
| @ -44,8 +45,6 @@ FRESULT f_write ( | ||||
| <dd>The function succeeded.</dd> | ||||
| <dt>FR_DENIED</dt> | ||||
| <dd>The function denied due to the file has been opened in read only mode.</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>The file has been opened in unbufferred mode but unaligned access was detected.</dd> | ||||
| <dt>FR_RW_ERROR</dt> | ||||
| <dd>Any error occured in low level disk I/O.</dd> | ||||
| <dt>FR_NOT_READY</dt> | ||||
| @ -58,7 +57,7 @@ FRESULT f_write ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>Description</h4> | ||||
| <p>The read/write pointer increases in number of bytes written. The <tt>ByteWritten</tt> will be smaller than <tt>ByteToWrite</tt> when disk full or alignment error occured during write function. This function is not supported in read only configuration.</p> | ||||
| <p>The read/write pointer increases in number of bytes written. The <tt>ByteWritten</tt> will be smaller than <tt>ByteToWrite</tt> when disk gets full during write function. This function is not supported in read only configuration.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_chmod</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_close</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_initialize</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_read</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_status</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - disk_write</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - get_fattime</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_getfree</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_lseek</title> | ||||
| </head> | ||||
| @ -36,8 +37,6 @@ FRESULT f_lseek ( | ||||
| <dl class="ret"> | ||||
| <dt>FR_OK</dt> | ||||
| <dd>正常終了。</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>アンバッファモードで開いたファイルで、512の整数倍でないオフセットを指定した。</dd> | ||||
| <dt>FR_RW_ERROR</dt> | ||||
| <dd>ディスクアクセスでエラーが発生した。</dd> | ||||
| <dt>FR_INCORRECT_DISK_CHANGE</dt> | ||||
| @ -57,17 +56,17 @@ FRESULT f_lseek ( | ||||
| <div class="para"> | ||||
| <h4>使用例</h4> | ||||
| <pre> | ||||
|     // Move to offset of 5000 from top of file. | ||||
|     // ファイルオフセット 5000 へ移動 | ||||
|     res = f_lseek(&file, 5000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Move to 3000 bytes front of current offset. | ||||
|     // 3000バイト進める | ||||
|     res = f_lseek(&file, file.fptr + 3000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Move to 2000 bytes back of current offset. | ||||
|     // 2000バイト戻す | ||||
|     res = f_lseek(&file, file.fptr - 2000); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // ファイル末尾 + 1 へ移動 | ||||
|     res = f_lseek(&file, 0xFFFFFFFF); | ||||
| </pre> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_mkdir</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_mountdrv</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_open</title> | ||||
| </head> | ||||
| @ -25,22 +26,18 @@ FRESULT f_open ( | ||||
| <h4>パラメータ</h4> | ||||
| <dl class="par"> | ||||
| <dt>FileObject</dt> | ||||
| <dd>新しく作成するファイルオブジェクト構造体へのポインタを指定します。以降、このファイルを閉じるまでそのファイルオブジェクトを使用してファイル操作をします。構造体メンバの<tt>buffer</tt>は、オープン前または直後にそのファイルで使用するR/Wバッファへのアドレスで初期化しておく必要があります(<tt>FA_UNBUFFERED</tt>を指定した場合はバッファは不要)。</dd> | ||||
| <dd>新しく作成するファイルオブジェクト構造体へのポインタを指定します。以降、そのファイルを閉じるまでこのファイルオブジェクトを使用してファイル操作をします。</dd> | ||||
| <dt>FileName</dt> | ||||
| <dd>作成する (またはオープンする) ファイルのフルパス名が入った<tt>'\0'</tt>で終わる文字列へのポインタを指定します。ディレクトリセパレータには<tt>'/'</tt>を使用します。FatFsモジュールにはカレントディレクトリの概念がないので、パスはルートディレクトリから辿る絶対パスとなります。文字列先頭のスペースはスキップされます。パス先頭の<tt>'/'</tt>はあってもなくてもかまいません。</dd> | ||||
| <dt>ModeFlags</dt> | ||||
| <dd>ファイルのアクセス方法やオープン方法を決めるフラグです。このパラメータには次の組み合わせを指定します。<br> | ||||
| <table class="lst"> | ||||
| <tr><th>値</th><th>意味</th></td> | ||||
| <tr><td>FA_READ</td><td>読み出しモードでオープンします。読み書きする場合は<tt>FA_WRITE</tt>と共に指定します。</td></td> | ||||
| <tr><td>FA_WRITE</td><td>書き込みモードでオープンします。読み書きする場合は<tt>FA_READ</tt>と共に指定します。</td></td> | ||||
| <tr><td>FA_UNBUFFERED</td><td> | ||||
| FatFsでのみ指定可。指定するとファイルR/Wバッファを使用せず、メモリを節約できます。<br> | ||||
| read/write/seekは512の整数倍単位でなければなりません。指定しない場合は、ファイル<br> | ||||
| R/Wバッファ(ファイルオブジェクト構造体メンバの<tt>buffer</tt>で指定)を使用。</td></td> | ||||
| <tr><td>FA_OPEN_EXISTING</td><td>既存のファイルを開きます。ファイルが無いときはエラーになります。</td></td> | ||||
| <tr><td>FA_CREATE_ALWAYS</td><td>ファイルを作成します。既存のファイルがある場合は、サイズを0にしてから開きます。</td></td> | ||||
| <tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。</td></td> | ||||
| <tr><td>FA_READ</td><td>読み出しモードでオープンします。読み書きする場合は<tt>FA_WRITE</tt>と共に指定します。</td></tr> | ||||
| <tr><td>FA_WRITE</td><td>書き込みモードでオープンします。読み書きする場合は<tt>FA_READ</tt>と共に指定します。</td></tr> | ||||
| <tr><td>FA_OPEN_EXISTING</td><td>既存のファイルを開きます。ファイルが無いときはエラーになります。</td></tr> | ||||
| <tr><td>FA_CREATE_ALWAYS</td><td>ファイルを作成します。既存のファイルがある場合は、サイズを0にしてから開きます。</td></tr> | ||||
| <tr><td>FA_OPEN_ALWAYS</td><td>既存のファイルを開きます。ファイルが無いときはファイルを作成します。</td></tr> | ||||
| </table> | ||||
| </dd> | ||||
| </dl> | ||||
| @ -84,47 +81,42 @@ R/W | ||||
| 
 | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>使用例</h4> | ||||
| <h4>使用例(ファイルコピー)</h4> | ||||
| <pre> | ||||
| void main () | ||||
| { | ||||
|     FATFS fs;            // FatFs work area | ||||
|     FIL fsrc, fdst;      // file structures | ||||
|     BYTE fbuff[512*2];   // file r/w buffers (not required for Tiny-FatFs) | ||||
|     FATFS fs;            // FatFsワークエリア | ||||
|     FIL fsrc, fdst;      // ファイルオブジェクト | ||||
|     BYTE buffer[4096];   // file copy buffer | ||||
|     FRESULT res;         // FatFs function common result code | ||||
|     WORD br, bw;         // File R/W count | ||||
| 
 | ||||
| 
 | ||||
|     // Activate FatFs module | ||||
|     // FatFsのワークエリアを確保する | ||||
|     memset(&fs, 0, sizeof(FATFS)); | ||||
|     FatFs = &fs; | ||||
| 
 | ||||
|     // Open source file | ||||
|     fsrc.buffer = fbuff+0;	// (not required for Tiny-FatFs) | ||||
|     // ソース・ファイルを開く | ||||
|     res = f_open(&fsrc, "/srcfile.dat", FA_OPEN_EXISTING | FA_READ); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Create destination file | ||||
|     fdst.buffer = fbuff+512;	// (not required for Tiny-FatFs) | ||||
|     // デスティネーション・ファイルを作成する | ||||
|     res = f_open(&fdst, "/dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE); | ||||
|     if (res) die(res); | ||||
| 
 | ||||
|     // Copy source to destination | ||||
|     // ソースからデスティネーションにコピーする | ||||
|     for (;;) { | ||||
|         res = f_read(&fsrc, buffer, sizeof(buffer), &br); | ||||
|         if (res) die(res); | ||||
|         if (br == 0) break; | ||||
|         if (res || br == 0) break; | ||||
|         res = f_write(&fdst, buffer, br, &bw); | ||||
|         if (res) die(res); | ||||
|         if (bw < br) break; | ||||
|         if (res || bw < br) break; | ||||
|     } | ||||
| 
 | ||||
|     // Close all files | ||||
|     // 全てのファイルを閉じる | ||||
|     f_close(&fsrc); | ||||
|     f_close(&fdst); | ||||
| 
 | ||||
|     // Deactivate FatFs module | ||||
|     // FatFsのワークエリアを開放する | ||||
|     FatFs = NULL; | ||||
| } | ||||
| </pre> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_opendir</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_read</title> | ||||
| </head> | ||||
| @ -44,8 +45,6 @@ FRESULT f_read ( | ||||
| <dd>正常終了。</dd> | ||||
| <dt>FR_DENIED</dt> | ||||
| <dd>書き込み専用モードで開いたファイルから読み込もうとした。</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>アンバッファモードで開かれたファイルで、512の整数倍でないアクセスを検出した。</dd> | ||||
| <dt>FR_RW_ERROR</dt> | ||||
| <dd>ディスクアクセスでエラーが発生した。</dd> | ||||
| <dt>FR_NOT_READY</dt> | ||||
| @ -58,7 +57,7 @@ FRESULT f_read ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>解説</h4> | ||||
| <p>読み込み開始位置は、現在のファイルR/Wポインタからになります。ファイルR/Wポインタは読み込まれたバイト数だけ進みます。読み込み中にファイルの終端に達すると、<tt>*ByteRead</tt>は<tt>ByteToRead</tt>よりも小さくなります。アンバッファモードでは最後の端数バイトを残して<tt>FR_ALIGN_ERROR</tt>になります。</p> | ||||
| <p>読み込み開始位置は、現在のファイルR/Wポインタからになります。ファイルR/Wポインタは読み込まれたバイト数だけ進みます。読み込み中にファイルの終端に達すると、<tt>*ByteRead</tt>は<tt>ByteToRead</tt>よりも小さくなります。</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_readdir</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - DIR</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FATFS</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FIL</title> | ||||
| </head> | ||||
| @ -11,7 +12,7 @@ | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h2>FIL</h2> | ||||
| <p><tt>FIL</tt>構造体は、1個で1ファイルの状態を保持し、アプリケーション側で確保・管理されます。アプリケーションから変更可能なメンバは<tt>buffer</tt>のみです。</p> | ||||
| <p><tt>FIL</tt>構造体は、個々のファイルの状態を保持し、アプリケーション側で確保・管理されます。アプリケーションから変更可能なメンバはありません。</p> | ||||
| <h4>FatFs</h4> | ||||
| <pre> | ||||
| typedef struct _FIL { | ||||
| @ -22,9 +23,9 @@ typedef struct _FIL { | ||||
|     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*   buffer;         // Pointer to 512 byte file R/W buffer | ||||
|     BYTE    flag;           // File status flags | ||||
|     BYTE    sect_clust;     // Left sectors in current cluster | ||||
|     BYTE    buffer[512];    // File R/W buffer | ||||
| } FIL; | ||||
| </pre> | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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 - FILINFO</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_stat</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_sync</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_unlink</title> | ||||
| </head> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <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_write</title> | ||||
| </head> | ||||
| @ -32,7 +33,7 @@ FRESULT f_write ( | ||||
| <dt>ByteToWrite</dt> | ||||
| <dd>書き込むバイト数を指定します。</dd> | ||||
| <dt>ByteWritten</dt> | ||||
| <dd>実際に書き込まれたバイト数を格納する変数を指すポインタを指定します。</dd> | ||||
| <dd>書き込まれたバイト数を格納する変数を指すポインタを指定します。</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -44,8 +45,6 @@ FRESULT f_write ( | ||||
| <dd>正常終了。</dd> | ||||
| <dt>FR_DENIED</dt> | ||||
| <dd>読み込み専用モードで開いたファイルに書き込もうとした。</dd> | ||||
| <dt>FR_ALIGN_ERROR</dt> | ||||
| <dd>アンバッファモードで開かれたファイルで、512の整数倍でないアクセスを検出した。</dd> | ||||
| <dt>FR_RW_ERROR</dt> | ||||
| <dd>ディスクアクセスでエラーが発生した。</dd> | ||||
| <dt>FR_NOT_READY</dt> | ||||
| @ -58,7 +57,7 @@ FRESULT f_write ( | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h4>解説</h4> | ||||
| <p>書き込み開始位置は、ファイルR/Wポインタの現在位置からになります。ファイルR/Wポインタは実際に書き込まれたバイト数だけ進みます。書き込み中にディスクが一杯になった、または<tt>FR_ALIGN_ERROR</tt>が帰ったときは、<tt>*ByteWritten</tt>は<tt>ByteToWrite</tt>よりも小さくなります。リードオンリー構成ではこの関数はサポートされません。</p> | ||||
| <p>書き込み開始位置は、ファイルR/Wポインタの現在位置からになります。ファイルR/Wポインタは実際に書き込まれたバイト数だけ進みます。書き込み中にディスクが一杯になったときは、<tt>*ByteWritten</tt>は<tt>ByteToWrite</tt>よりも小さくなります。リードオンリー構成ではこの関数はサポートされません。</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| FatFs/Tiny-FatFs Module Source Files  R0.01 (C)ChaN, 2006 | ||||
| FatFs/Tiny-FatFs Module Source Files R0.02  (C)ChaN, 2006 | ||||
| 
 | ||||
| 
 | ||||
| Files | ||||
| 
 | ||||
|   ff.h       Common include file for FatFs and application module. | ||||
|   ff.c       FatFs module | ||||
|   ff.c       FatFs module. | ||||
|   tff.h      Common include file for Tiny-FatFs and application module. | ||||
|   tff.c      Tiny-FatFs module | ||||
|   tff.c      Tiny-FatFs module. | ||||
|   diskio.h   Common include file for (Tiny-)FatFs and disk I/O module. | ||||
|   integer.h  Alternative type definitions for unsigned integers. | ||||
| 
 | ||||
| @ -20,7 +20,7 @@ Files | ||||
| Configuration Options | ||||
| 
 | ||||
|   There are several configuration options for various envilonment and requirement. | ||||
|   The configuration options are in include files ff.h and tff.h. | ||||
|   The configuration options are in include files, ff.h and tff.h. | ||||
| 
 | ||||
|   #define _BYTE_ACC | ||||
| 
 | ||||
| @ -34,7 +34,7 @@ Configuration Options | ||||
| 
 | ||||
|   #define _FS_READONLY | ||||
| 
 | ||||
|   When application program does not require any write access, _FS_READONLY can be | ||||
|   When application program does not require any write function, _FS_READONLY can be | ||||
|   defined to eliminate writing code to reduce module size. | ||||
| 
 | ||||
| 
 | ||||
| @ -50,7 +50,7 @@ Agreements | ||||
|   The FatFs/Tiny-FatFs module is a free software and there is no warranty. | ||||
|   The FatFs/Tiny-FatFs module is opened for education, reserch and development. | ||||
|   You can use, modify and republish it for personal, non-profit or profit use | ||||
|   without any limitation under your responsibility.  | ||||
|   without any limitation under your responsibility. | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| @ -58,3 +58,5 @@ 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. | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /*-----------------------------------------------------------------------
 | ||||
| /  Low level disk interface modlue include file  R0.01    (C)ChaN, 2006 | ||||
| /  Low level disk interface modlue include file  R0.02    (C)ChaN, 2006 | ||||
| /-----------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #ifndef _DISKIF | ||||
|  | ||||
							
								
								
									
										152
									
								
								src/ff.c
									
									
									
									
									
								
							
							
						
						
									
										152
									
								
								src/ff.c
									
									
									
									
									
								
							| @ -1,13 +1,15 @@ | ||||
| /*--------------------------------------------------------------------------/
 | ||||
| /  FatFs - FAT file system module  R0.01                     (C)ChaN, 2006 | ||||
| /  FatFs - FAT file system module  R0.02                     (C)ChaN, 2006 | ||||
| /---------------------------------------------------------------------------/ | ||||
| / FatFs module is an experimenal project to implement FAT file system to | ||||
| / cheap microcontrollers. This is opened for education, reserch and | ||||
| / development. You can use, modify and republish it for non-profit or profit | ||||
| / use without any limitation under your responsibility. | ||||
| /---------------------------------------------------------------------------/ | ||||
| /  Feb 26, 2006  R0.00  Prototype | ||||
| /  Apr 29, 2006  R0.01  First stable version | ||||
| /  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. | ||||
| /---------------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #include <string.h> | ||||
| @ -59,34 +61,46 @@ BOOL move_window ( | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*---------------------*/ | ||||
| /* Get Cluster State   */ | ||||
| /*----------------------*/ | ||||
| /* Get a Cluster Status */ | ||||
| 
 | ||||
| static | ||||
| DWORD get_cluster ( | ||||
| 	DWORD clust			/* Cluster# to get the link information */ | ||||
| ) | ||||
| { | ||||
| 	WORD wc, bc; | ||||
| 	DWORD fatsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	if ((clust >= 2) && (clust < fs->max_clust)) {		/* Valid cluster# */ | ||||
| 		fatsect = fs->fatbase; | ||||
| 		switch (fs->fs_type) { | ||||
| 		case FS_FAT12 : | ||||
| 			bc = (WORD)clust * 3 / 2; | ||||
| 			if (!move_window(fatsect + bc / 512)) break; | ||||
| 			wc = fs->win[bc % 512]; bc++; | ||||
| 			if (!move_window(fatsect + bc / 512)) break; | ||||
| 			wc |= (WORD)fs->win[bc % 512] << 8; | ||||
| 			return (clust & 1) ? (wc >> 4) : (wc & 0xFFF); | ||||
| 
 | ||||
| 		case FS_FAT16 : | ||||
| 			if (!move_window(clust / 256 + fs->fatbase)) break; | ||||
| 			return LD_WORD(&(fs->win[((WORD)clust * 2) & 511])); | ||||
| 			if (!move_window(fatsect + clust / 256)) break; | ||||
| 			return LD_WORD(&(fs->win[((WORD)clust * 2) % 512])); | ||||
| 
 | ||||
| 		case FS_FAT32 : | ||||
| 			if (!move_window(clust / 128 + fs->fatbase)) break; | ||||
| 			return LD_DWORD(&(fs->win[((WORD)clust * 4) & 511])); | ||||
| 			if (!move_window(fatsect + clust / 128)) break; | ||||
| 			return LD_DWORD(&(fs->win[((WORD)clust * 4) % 512])); | ||||
| 		} | ||||
| 	} | ||||
| 	return 1;	/* Return with 1 means failed */ | ||||
| 	return 1;	/* Return with 1 means function failed */ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*--------------------------*/ | ||||
| /* Change a Cluster State   */ | ||||
| /* Change a Cluster Status  */ | ||||
| 
 | ||||
| #ifndef _FS_READONLY | ||||
| static | ||||
| @ -95,18 +109,35 @@ BOOL put_cluster ( | ||||
| 	DWORD val			/* New value to mark the cluster */ | ||||
| ) | ||||
| { | ||||
| 	WORD bc; | ||||
| 	BYTE *p; | ||||
| 	DWORD fatsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	fatsect = fs->fatbase; | ||||
| 	switch (fs->fs_type) { | ||||
| 	case FS_FAT12 : | ||||
| 		bc = (WORD)clust * 3 / 2; | ||||
| 		if (!move_window(fatsect + bc / 512)) return FALSE; | ||||
| 		p = &fs->win[bc % 512]; | ||||
| 		*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; | ||||
| 		fs->winflag = 1; bc++; | ||||
| 		if (!move_window(fatsect + bc / 512)) return FALSE; | ||||
| 		p = &fs->win[bc % 512]; | ||||
| 		*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); | ||||
| 		break; | ||||
| 
 | ||||
| 	case FS_FAT16 : | ||||
| 		if (!move_window(clust / 256 + fs->fatbase)) return FALSE; | ||||
| 		ST_WORD(&(fs->win[((WORD)clust * 2) & 511]), (WORD)val); | ||||
| 		if (!move_window(fatsect + clust / 256)) return FALSE; | ||||
| 		ST_WORD(&(fs->win[((WORD)clust * 2) % 512]), (WORD)val); | ||||
| 		break; | ||||
| 
 | ||||
| 	case FS_FAT32 : | ||||
| 		if (!move_window(clust / 128 + fs->fatbase)) return FALSE; | ||||
| 		ST_DWORD(&(fs->win[((WORD)clust * 4) & 511]), val); | ||||
| 		if (!move_window(fatsect + clust / 128)) return FALSE; | ||||
| 		ST_DWORD(&(fs->win[((WORD)clust * 4) % 512]), val); | ||||
| 		break; | ||||
| 
 | ||||
| 	default : | ||||
| 		return FALSE; | ||||
| 	} | ||||
| @ -209,7 +240,7 @@ BYTE check_fs ( | ||||
| 	DWORD sect		/* Sector# to check if it is a FAT boot record or not */ | ||||
| ) | ||||
| { | ||||
| 	static const char fatsign[] = "FAT16FAT32"; | ||||
| 	static const char fatsign[] = "FAT12FAT16FAT32"; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| @ -217,8 +248,10 @@ BYTE check_fs ( | ||||
| 	if (disk_read(fs->win, sect, 1) == RES_OK) {	/* Load boot record */ | ||||
| 		if (LD_WORD(&(fs->win[510])) == 0xAA55) {		/* Is it valid? */ | ||||
| 			if (!memcmp(&(fs->win[0x36]), &fatsign[0], 5)) | ||||
| 				return FS_FAT12; | ||||
| 			if (!memcmp(&(fs->win[0x36]), &fatsign[5], 5)) | ||||
| 				return FS_FAT16; | ||||
| 			if (!memcmp(&(fs->win[0x52]), &fatsign[5], 5) && (fs->win[0x28] == 0)) | ||||
| 			if (!memcmp(&(fs->win[0x52]), &fatsign[10], 5) && (fs->win[0x28] == 0)) | ||||
| 				return FS_FAT32; | ||||
| 		} | ||||
| 	} | ||||
| @ -511,7 +544,7 @@ FRESULT check_mounted () | ||||
| FRESULT f_mountdrv () | ||||
| { | ||||
| 	BYTE fat; | ||||
| 	DWORD sect, fatend; | ||||
| 	DWORD sect, fatend, maxsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| @ -526,7 +559,7 @@ FRESULT f_mountdrv () | ||||
| 	/* Search FAT partition */ | ||||
| 	fat = check_fs(sect = 0);		/* Check sector 0 as an SFD format */ | ||||
| 	if (!fat) {						/* Not a FAT boot record, it will be an FDISK format */ | ||||
| 		/* Check a pri-partition listed in top of the partition table */ | ||||
| 		/* Check a partition listed in top of the partition table */ | ||||
| 		if (fs->win[0x1C2]) {					/* Is the partition existing? */ | ||||
| 			sect = LD_DWORD(&(fs->win[0x1C6]));	/* Partition offset in LBA */ | ||||
| 			fat = check_fs(sect);				/* Check the partition */ | ||||
| @ -545,14 +578,15 @@ FRESULT f_mountdrv () | ||||
| 
 | ||||
| 	fatend = fs->sects_fat * fs->n_fats + fs->fatbase; | ||||
| 	if (fat == FS_FAT32) { | ||||
| 		fs->dirbase = LD_DWORD(&(fs->win[0x2C]));	/* Directory start cluster */ | ||||
| 		fs->database = fatend;	 					/* Data start sector (physical) */ | ||||
| 		fs->dirbase = LD_DWORD(&(fs->win[0x2C]));	/* FAT32: Directory start cluster */ | ||||
| 		fs->database = fatend;	 					/* FAT32: Data start sector (physical) */ | ||||
| 	} else { | ||||
| 		fs->dirbase = fatend;						/* Directory start sector (physical) */ | ||||
| 		fs->database = fs->n_rootdir / 16 + fatend;	/* Data start sector (physical) */ | ||||
| 	} | ||||
| 	fs->max_clust = 								/* Maximum cluster number */ | ||||
| 		(LD_DWORD(&(fs->win[0x20])) - fs->database + sect) / fs->sects_clust + 2; | ||||
| 	maxsect = LD_DWORD(&(fs->win[0x20]));			/* Calculate maximum cluster number */ | ||||
| 	if (!maxsect) maxsect = LD_WORD(&(fs->win[0x13])); | ||||
| 	fs->max_clust = (maxsect - fs->database + sect) / fs->sects_clust + 2; | ||||
| 
 | ||||
| 	return FR_OK; | ||||
| } | ||||
| @ -567,32 +601,39 @@ FRESULT f_getfree ( | ||||
| ) | ||||
| { | ||||
| 	DWORD n, clust, sect; | ||||
| 	BYTE m, *ptr, fat; | ||||
| 	BYTE fat, f, *p; | ||||
| 	FRESULT res; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	if ((res = check_mounted()) != FR_OK) return res; | ||||
| 	fat = fs->fs_type; | ||||
| 
 | ||||
| 	/* Count number of free clusters */ | ||||
| 	n = m = clust = 0; | ||||
| 	ptr = NULL; | ||||
| 	sect = fs->fatbase; | ||||
| 	do { | ||||
| 		if (m == 0) { | ||||
| 			if (!move_window(sect++)) return FR_RW_ERROR; | ||||
| 			ptr = fs->win; | ||||
| 		} | ||||
| 		if (fat == FS_FAT32) { | ||||
| 			if (LD_DWORD(ptr) == 0) n++; | ||||
| 			ptr += 4; m += 2; | ||||
| 		} else { | ||||
| 			if (LD_WORD(ptr) == 0) n++; | ||||
| 			ptr += 2; m++; | ||||
| 		} | ||||
| 		clust++; | ||||
| 	} while (clust < fs->max_clust); | ||||
| 	fat = fs->fs_type; | ||||
| 	n = 0; | ||||
| 	if (fat == FS_FAT12) { | ||||
| 		clust = 2; | ||||
| 		do { | ||||
| 			if ((WORD)get_cluster(clust) == 0) n++; | ||||
| 		} while (++clust < fs->max_clust); | ||||
| 	} else { | ||||
| 		clust = fs->max_clust; | ||||
| 		sect = fs->fatbase; | ||||
| 		f = 0; p = 0; | ||||
| 		do { | ||||
| 			if (!f) { | ||||
| 				if (!move_window(sect++)) return FR_RW_ERROR; | ||||
| 				p = fs->win; | ||||
| 			} | ||||
| 			if (fat == FS_FAT16) { | ||||
| 				if (LD_WORD(p) == 0) n++; | ||||
| 				p += 2; f += 1; | ||||
| 			} else { | ||||
| 				if (LD_DWORD(p) == 0) n++; | ||||
| 				p += 4; f += 2; | ||||
| 			} | ||||
| 		} while (--clust); | ||||
| 	} | ||||
| 
 | ||||
| 	*nclust = n; | ||||
| 	return FR_OK; | ||||
| @ -669,9 +710,9 @@ FRESULT f_open ( | ||||
| #endif | ||||
| 
 | ||||
| #ifdef _FS_READONLY | ||||
| 	fp->flag = mode & (FA_UNBUFFERED|FA_READ); | ||||
| 	fp->flag = mode & FA_READ; | ||||
| #else | ||||
| 	fp->flag = mode & (FA_UNBUFFERED|FA_WRITE|FA_READ); | ||||
| 	fp->flag = mode & (FA_WRITE|FA_READ); | ||||
| 	fp->dir_sect = fs->winsect;				/* Pointer to the directory entry */ | ||||
| 	fp->dir_ptr = dir; | ||||
| #endif | ||||
| @ -711,7 +752,7 @@ FRESULT f_read ( | ||||
| 
 | ||||
| 	for ( ;  btr;									/* Repeat until all data transferred */ | ||||
| 		buff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { | ||||
| 		if ((fp->fptr & 511) == 0) {				/* On the sector boundary */ | ||||
| 		if ((fp->fptr % 512) == 0) {				/* On the sector boundary */ | ||||
| 			if (--(fp->sect_clust)) {				/* Decrement sector counter */ | ||||
| 				sect = fp->curr_sect + 1;			/* Next sector */ | ||||
| 			} else {								/* Next cluster */ | ||||
| @ -736,14 +777,12 @@ FRESULT f_read ( | ||||
| 				fp->curr_sect += cc - 1; | ||||
| 				rcnt = cc * 512; continue; | ||||
| 			} | ||||
| 			if (fp->flag & FA_UNBUFFERED)			/* Reject unaligned access when unbuffered mode */ | ||||
| 				return FR_ALIGN_ERROR; | ||||
| 			if (disk_read(fp->buffer, sect, 1) != RES_OK)	/* Load the sector into file I/O buffer */ | ||||
| 				goto fr_error; | ||||
| 		} | ||||
| 		rcnt = 512 - (fp->fptr & 511);				/* Copy fractional bytes from file I/O buffer */ | ||||
| 		rcnt = 512 - (fp->fptr % 512);				/* Copy fractional bytes from file I/O buffer */ | ||||
| 		if (rcnt > btr) rcnt = btr; | ||||
| 		memcpy(buff, &fp->buffer[fp->fptr & 511], rcnt); | ||||
| 		memcpy(buff, &fp->buffer[fp->fptr % 512], rcnt); | ||||
| 	} | ||||
| 
 | ||||
| 	return FR_OK; | ||||
| @ -781,7 +820,7 @@ FRESULT f_write ( | ||||
| 
 | ||||
| 	for ( ;  btw;									/* Repeat until all data transferred */ | ||||
| 		buff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { | ||||
| 		if ((fp->fptr & 511) == 0) {				/* On the sector boundary */ | ||||
| 		if ((fp->fptr % 512) == 0) {				/* On the sector boundary */ | ||||
| 			if (--(fp->sect_clust)) {				/* Decrement sector counter */ | ||||
| 				sect = fp->curr_sect + 1;			/* Next sector */ | ||||
| 			} else {								/* Next cluster */ | ||||
| @ -810,15 +849,13 @@ FRESULT f_write ( | ||||
| 				fp->curr_sect += cc - 1; | ||||
| 				wcnt = cc * 512; continue; | ||||
| 			} | ||||
| 			if (fp->flag & FA_UNBUFFERED)			/* Reject unalighend access when unbuffered mode */ | ||||
| 				return FR_ALIGN_ERROR; | ||||
| 			if ((fp->fptr < fp->fsize) &&  			/* Fill sector buffer with file data if needed */ | ||||
| 				(disk_read(fp->buffer, sect, 1) != RES_OK)) | ||||
| 					goto fw_error; | ||||
| 		} | ||||
| 		wcnt = 512 - (fp->fptr & 511);				/* Copy fractional bytes to file I/O buffer */ | ||||
| 		wcnt = 512 - (fp->fptr % 512);				/* Copy fractional bytes to file I/O buffer */ | ||||
| 		if (wcnt > btw) wcnt = btw; | ||||
| 		memcpy(&fp->buffer[fp->fptr & 511], buff, wcnt); | ||||
| 		memcpy(&fp->buffer[fp->fptr % 512], buff, wcnt); | ||||
| 		fp->flag |= FA__DIRTY; | ||||
| 	} | ||||
| 
 | ||||
| @ -857,7 +894,6 @@ FRESULT f_lseek ( | ||||
| 	} | ||||
| #endif | ||||
| 	if (ofs > fp->fsize) ofs = fp->fsize;	/* Clip offset by file size */ | ||||
| 	if ((ofs & 511) && (fp->flag & FA_UNBUFFERED)) return FR_ALIGN_ERROR; | ||||
| 	fp->fptr = ofs; fp->sect_clust = 1; 	/* Re-initialize file pointer */ | ||||
| 
 | ||||
| 	/* Seek file pinter if needed */ | ||||
| @ -872,7 +908,7 @@ FRESULT f_lseek ( | ||||
| 		if ((clust < 2) || (clust >= fs->max_clust)) goto fk_error; | ||||
| 		fp->curr_clust = clust; | ||||
| 		fp->curr_sect = clust2sect(clust) + sc - fp->sect_clust;	/* Current sector */ | ||||
| 		if (fp->fptr & 511) {										/* Load currnet sector if needed */ | ||||
| 		if (fp->fptr % 512) {										/* Load currnet sector if needed */ | ||||
| 			if (disk_read(fp->buffer, fp->curr_sect, 1) != RES_OK) | ||||
| 				goto fk_error; | ||||
| 		} | ||||
| @ -993,9 +1029,9 @@ FRESULT f_unlink ( | ||||
| 		} while (next_dir_entry(&dirscan)); | ||||
| 	} | ||||
| 
 | ||||
| 	if (!remove_chain(dclust)) return FR_RW_ERROR;	/* Remove the cluster chain */ | ||||
| 	if (!move_window(dsect)) return FR_RW_ERROR;	/* Mark the directory entry deleted */ | ||||
| 	if (!move_window(dsect)) return FR_RW_ERROR;	/* Mark the directory entry 'deleted' */ | ||||
| 	*dir = 0xE5; fs->winflag = 1; | ||||
| 	if (!remove_chain(dclust)) return FR_RW_ERROR;	/* Remove the cluster chain */ | ||||
| 	if (!move_window(0)) return FR_RW_ERROR; | ||||
| 
 | ||||
| 	return FR_OK; | ||||
|  | ||||
							
								
								
									
										120
									
								
								src/ff.h
									
									
									
									
									
								
							
							
						
						
									
										120
									
								
								src/ff.h
									
									
									
									
									
								
							| @ -5,9 +5,6 @@ | ||||
| / cheap microcontrollers. This is opened for education, reserch and | ||||
| / development. You can use it for non-profit or profit use without any | ||||
| / limitation under your responsibility. | ||||
| /---------------------------------------------------------------------------/ | ||||
| /  Feb 26, 2006  R0.00  Prototype | ||||
| /  Apr 29, 2006  R0.01  First stable version | ||||
| /---------------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #ifndef _FATFS | ||||
| @ -32,56 +29,56 @@ 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	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; | ||||
| 	DWORD	sects_fat;		// Sectors per fat
 | ||||
| 	DWORD	max_clust;		// Maximum cluster# + 1
 | ||||
| 	DWORD	fatbase;		// FAT start sector
 | ||||
| 	DWORD	dirbase;		// Root directory start sector (cluster# for FAT32)
 | ||||
| 	DWORD	database;		// Data start sector
 | ||||
| 	DWORD	winsect;		// Current sector appearing in the win[]
 | ||||
| 	BYTE	win[512];		// Disk access window for Directory/FAT area
 | ||||
| 	DWORD	sects_fat;		/* Sectors per fat */ | ||||
| 	DWORD	max_clust;		/* Maximum cluster# + 1 */ | ||||
| 	DWORD	fatbase;		/* FAT start sector */ | ||||
| 	DWORD	dirbase;		/* Root directory start sector (cluster# for FAT32) */ | ||||
| 	DWORD	database;		/* Data start sector */ | ||||
| 	DWORD	winsect;		/* Current sector appearing in the win[] */ | ||||
| 	BYTE	win[512];		/* Disk access window for Directory/FAT area */ | ||||
| } FATFS; | ||||
| 
 | ||||
| 
 | ||||
| /* Directory object structure */ | ||||
| typedef struct _DIR { | ||||
| 	DWORD	sclust;		// Start cluster
 | ||||
| 	DWORD	clust;		// Current cluster
 | ||||
| 	DWORD	sect;		// Current sector
 | ||||
| 	WORD	index;		// Current index
 | ||||
| 	DWORD	sclust;		/* Start cluster */ | ||||
| 	DWORD	clust;		/* Current cluster */ | ||||
| 	DWORD	sect;		/* Current sector */ | ||||
| 	WORD	index;		/* Current index */ | ||||
| } DIR; | ||||
| 
 | ||||
| 
 | ||||
| /* File object structure */ | ||||
| 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	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 | ||||
| 	DWORD	dir_sect;		// Sector containing the directory entry
 | ||||
| 	BYTE*	dir_ptr;		// Ponter to the directory entry in the window
 | ||||
| 	DWORD	dir_sect;		/* Sector containing the directory entry */ | ||||
| 	BYTE*	dir_ptr;		/* Ponter to the directory entry in the window */ | ||||
| #endif | ||||
| 	BYTE*	buffer;			// Pointer to 512 byte file R/W buffer
 | ||||
| 	BYTE	flag;			// File status flags
 | ||||
| 	BYTE	sect_clust;		// Left sectors in cluster
 | ||||
| 	BYTE	flag;			/* File status flags */ | ||||
| 	BYTE	sect_clust;		/* Left sectors in cluster */ | ||||
| 	BYTE	buffer[512];	/* File R/W buffer */ | ||||
| } FIL; | ||||
| 
 | ||||
| 
 | ||||
| /* File status structure */ | ||||
| typedef struct _FILINFO { | ||||
| 	DWORD fsize;			// Size
 | ||||
| 	WORD fdate;				// Date
 | ||||
| 	WORD ftime;				// Time
 | ||||
| 	BYTE fattrib;			// Attribute
 | ||||
| 	char fname[8+1+3+1];	// Name (8.3 format)
 | ||||
| 	DWORD fsize;			/* Size */ | ||||
| 	WORD fdate;				/* Date */ | ||||
| 	WORD ftime;				/* Time */ | ||||
| 	BYTE fattrib;			/* Attribute */ | ||||
| 	char fname[8+1+3+1];	/* Name (8.3 format) */ | ||||
| } FILINFO; | ||||
| 
 | ||||
| 
 | ||||
| @ -89,31 +86,31 @@ typedef struct _FILINFO { | ||||
| /*-----------------------------------------------------*/ | ||||
| /* FatFs module application interface                  */ | ||||
| 
 | ||||
| extern FATFS *FatFs;	// Pointer to active file system object
 | ||||
| extern FATFS *FatFs;	/* Pointer to active file system object */ | ||||
| 
 | ||||
| FRESULT f_open (FIL*, const char*, BYTE);			// Open or create a file
 | ||||
| FRESULT f_read (FIL*, BYTE*, WORD, WORD*);			// Read file
 | ||||
| FRESULT f_close (FIL*);								// Close file
 | ||||
| FRESULT f_lseek (FIL*, DWORD);						// Seek file pointer
 | ||||
| FRESULT f_opendir (DIR*, const char*);				// Initialize to read a 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 ();								// Force initialized the file system
 | ||||
| FRESULT f_open (FIL*, const char*, BYTE);			/* Open or create a file */ | ||||
| FRESULT f_read (FIL*, BYTE*, WORD, WORD*);			/* Read file */ | ||||
| FRESULT f_close (FIL*);								/* Close file */ | ||||
| FRESULT f_lseek (FIL*, DWORD);						/* Seek file pointer */ | ||||
| FRESULT f_opendir (DIR*, const char*);				/* Initialize to read a 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 ();								/* Force initialized the file system */ | ||||
| #ifndef _FS_READONLY | ||||
| FRESULT f_write (FIL*, const BYTE*, WORD, WORD*);	// Write file
 | ||||
| FRESULT f_sync (FIL*);								// Flush cached information 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_write (FIL*, const BYTE*, WORD, WORD*);	/* Write file */ | ||||
| FRESULT f_sync (FIL*);								/* Flush cached information 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 */ | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| /* User defined function to give a current time to fatfs module */ | ||||
| 
 | ||||
| #ifndef _FS_READONLY | ||||
| DWORD get_fattime();	// 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)
 | ||||
| DWORD get_fattime();	/* 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) */ | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| @ -128,7 +125,6 @@ DWORD get_fattime();	// 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day | ||||
| #define	FR_DENIED					5 | ||||
| #define	FR_DISK_FULL				6 | ||||
| #define	FR_RW_ERROR					7 | ||||
| #define	FR_ALIGN_ERROR				8 | ||||
| #define	FR_INCORRECT_DISK_CHANGE	9 | ||||
| #define	FR_WRITE_PROTECTED			10 | ||||
| #define	FR_NOT_ENABLED				11 | ||||
| @ -138,7 +134,6 @@ DWORD get_fattime();	// 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day | ||||
| /* File access control and file status flags */ | ||||
| 
 | ||||
| #define	FA_READ				0x01 | ||||
| #define	FA_UNBUFFERED		0x04 | ||||
| #define	FA_OPEN_EXISTING	0x00 | ||||
| #ifndef _FS_READONLY | ||||
| #define	FA_WRITE			0x02 | ||||
| @ -152,18 +147,19 @@ DWORD get_fattime();	// 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day | ||||
| 
 | ||||
| /* FAT type signature (fs_type) */ | ||||
| 
 | ||||
| #define FS_FAT16	1 | ||||
| #define FS_FAT32	2 | ||||
| #define FS_FAT12	1 | ||||
| #define FS_FAT16	2 | ||||
| #define FS_FAT32	3 | ||||
| 
 | ||||
| 
 | ||||
| /* File attribute mask for directory entry */ | ||||
| 
 | ||||
| #define	AM_RDO	0x01	// Read Only
 | ||||
| #define	AM_HID	0x02	// Hidden
 | ||||
| #define	AM_SYS	0x04	// System
 | ||||
| #define	AM_VOL	0x08	// Volume Label
 | ||||
| #define AM_DIR	0x10	// Directory
 | ||||
| #define AM_ARC	0x20	// Archive
 | ||||
| #define	AM_RDO	0x01	/* Read Only */ | ||||
| #define	AM_HID	0x02	/* Hidden */ | ||||
| #define	AM_SYS	0x04	/* System */ | ||||
| #define	AM_VOL	0x08	/* Volume Label */ | ||||
| #define AM_DIR	0x10	/* Directory */ | ||||
| #define AM_ARC	0x20	/* Archive */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										120
									
								
								src/tff.c
									
									
									
									
									
								
							
							
						
						
									
										120
									
								
								src/tff.c
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | ||||
| /*--------------------------------------------------------------------------/
 | ||||
| /  Tiny FatFs - FAT file system module R0.01                 (C)ChaN, 2006 | ||||
| /  Tiny FatFs - FAT file system module R0.02                 (C)ChaN, 2006 | ||||
| /---------------------------------------------------------------------------/ | ||||
| / FatFs module is an experimenal project to implement FAT file system to | ||||
| / cheap microcontrollers. This is opened for education, reserch and | ||||
| @ -8,6 +8,8 @@ | ||||
| /---------------------------------------------------------------------------/ | ||||
| /  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. | ||||
| /---------------------------------------------------------------------------*/ | ||||
| 
 | ||||
| 
 | ||||
| @ -60,28 +62,38 @@ BOOL move_window ( | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*---------------------*/ | ||||
| /* Get a Cluster State */ | ||||
| /*----------------------*/ | ||||
| /* Get a Cluster Status */ | ||||
| 
 | ||||
| static | ||||
| DWORD get_cluster (WORD clust)		/* Cluster# to get the link information */ | ||||
| WORD get_cluster (WORD clust)		/* Cluster# to get the link information */ | ||||
| { | ||||
| 	WORD wc, bc; | ||||
| 	DWORD fatsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	if ((clust >= 2) && (clust < fs->max_clust)) {		/* Valid cluster# */ | ||||
| 		if (fs->fs_type == FS_FAT16) { | ||||
| 			if (move_window(clust / 256 + fs->fatbase)) | ||||
| 				return LD_WORD(&(fs->win[(clust * 2) & 511])); | ||||
| 		fatsect = fs->fatbase; | ||||
| 		if (fs->fs_type == FS_FAT12) { | ||||
| 			bc = clust * 3 / 2; | ||||
| 			if (!move_window(fatsect + bc / 512)) return 1; | ||||
| 			wc = fs->win[bc % 512]; bc++; | ||||
| 			if (!move_window(fatsect + bc / 512)) return 1; | ||||
| 			wc |= (WORD)fs->win[bc % 512] << 8; | ||||
| 			return (clust & 1) ? (wc >> 4) : (wc & 0xFFF); | ||||
| 		} else { | ||||
| 			if (!move_window(fatsect + clust / 256)) return 1; | ||||
| 			return LD_WORD(&(fs->win[(clust * 2) % 512])); | ||||
| 		} | ||||
| 	} | ||||
| 	return 1;	/* Return with 1 means failed */ | ||||
| 	return 1;	/* Return with 1 means function failed */ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*------------------------*/ | ||||
| /* Change a Cluster State */ | ||||
| /*-------------------------*/ | ||||
| /* Change a Cluster Status */ | ||||
| 
 | ||||
| #ifndef _FS_READONLY | ||||
| static | ||||
| @ -90,12 +102,26 @@ BOOL put_cluster ( | ||||
| 	WORD val		/* New value to mark the cluster */ | ||||
| ) | ||||
| { | ||||
| 	WORD bc; | ||||
| 	BYTE *p; | ||||
| 	DWORD fatsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	if (fs->fs_type != FS_FAT16) return FALSE; | ||||
| 	if (!move_window(clust / 256 + fs->fatbase)) return FALSE; | ||||
| 	ST_WORD(&(fs->win[((WORD)clust * 2) & 511]), (WORD)val); | ||||
| 	fatsect = fs->fatbase; | ||||
| 	if (fs->fs_type == FS_FAT12) { | ||||
| 		bc = clust * 3 / 2; | ||||
| 		if (!move_window(fatsect + bc / 512)) return FALSE; | ||||
| 		p = &fs->win[bc % 512]; | ||||
| 		*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; | ||||
| 		fs->winflag = 1; bc++; | ||||
| 		if (!move_window(fatsect + bc / 512)) return FALSE; | ||||
| 		p = &fs->win[bc % 512]; | ||||
| 		*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); | ||||
| 	} else { | ||||
| 		if (!move_window(fatsect + clust / 256)) return FALSE; | ||||
| 		ST_WORD(&(fs->win[((WORD)clust * 2) % 512]), (WORD)val); | ||||
| 	} | ||||
| 
 | ||||
| 	fs->winflag = 1; | ||||
| 	return TRUE; | ||||
| @ -196,7 +222,7 @@ BYTE check_fs ( | ||||
| 	DWORD sect			/* Sector# to check if it is a FAT boot record or not */ | ||||
| ) | ||||
| { | ||||
| 	static const char fatsign[] = "FAT16"; | ||||
| 	static const char fatsign[] = "FAT12FAT16"; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| @ -204,6 +230,8 @@ BYTE check_fs ( | ||||
| 	if (disk_read(fs->win, sect, 1) == RES_OK) {	/* Load boot record */ | ||||
| 		if (LD_WORD(&(fs->win[510])) == 0xAA55) {		/* Is it valid? */ | ||||
| 			if (!memcmp(&(fs->win[0x36]), &fatsign[0], 5)) | ||||
| 				return FS_FAT12; | ||||
| 			if (!memcmp(&(fs->win[0x36]), &fatsign[5], 5)) | ||||
| 				return FS_FAT16; | ||||
| 		} | ||||
| 	} | ||||
| @ -492,7 +520,7 @@ FRESULT check_mounted () | ||||
| FRESULT f_mountdrv () | ||||
| { | ||||
| 	BYTE fat; | ||||
| 	DWORD sect, fatend; | ||||
| 	DWORD sect, fatend, maxsect; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| @ -524,10 +552,12 @@ FRESULT f_mountdrv () | ||||
| 	fs->n_rootdir = LD_WORD(&(fs->win[0x11]));		/* Nmuber of root directory entries */ | ||||
| 
 | ||||
| 	fatend = fs->sects_fat * fs->n_fats + fs->fatbase; | ||||
| 	fs->dirbase = fatend;						/* Directory start sector (physical) */ | ||||
| 	fs->database = fs->n_rootdir / 16 + fatend;	/* Data start sector (physical) */ | ||||
| 	fs->max_clust = 								/* Maximum cluster number */ | ||||
| 		(LD_DWORD(&(fs->win[0x20])) - fs->database + sect) / fs->sects_clust + 2; | ||||
| 	fs->dirbase = fatend;							/* Directory start sector (physical) */ | ||||
| 	fs->database = fs->n_rootdir / 16 + fatend;		/* Data start sector (physical) */ | ||||
| 
 | ||||
| 	maxsect = LD_DWORD(&(fs->win[0x20]));			/* Calculate maximum cluster number */ | ||||
| 	if (!maxsect) maxsect = LD_WORD(&(fs->win[0x13])); | ||||
| 	fs->max_clust = (maxsect - fs->database + sect) / fs->sects_clust + 2; | ||||
| 
 | ||||
| 	fs->files = 0; | ||||
| 	return FR_OK; | ||||
| @ -542,29 +572,35 @@ FRESULT f_getfree ( | ||||
| 	DWORD *nclust		/* Pointer to the double word to return number of free clusters */ | ||||
| ) | ||||
| { | ||||
| 	WORD clust; | ||||
| 	DWORD n, sect; | ||||
| 	BYTE m, *ptr, fat; | ||||
| 	WORD clust; | ||||
| 	BYTE f, *p; | ||||
| 	FRESULT res; | ||||
| 	FATFS *fs = FatFs; | ||||
| 
 | ||||
| 
 | ||||
| 	if ((res = check_mounted()) != FR_OK) return res; | ||||
| 	fat = fs->fs_type; | ||||
| 
 | ||||
| 	/* Count number of free clusters */ | ||||
| 	n = clust = m = 0; | ||||
| 	ptr = NULL; | ||||
| 	sect = fs->fatbase; | ||||
| 	do { | ||||
| 		if (m == 0) { | ||||
| 			if (!move_window(sect++)) return FR_RW_ERROR; | ||||
| 			ptr = fs->win; | ||||
| 		} | ||||
| 		if (LD_WORD(ptr) == 0) n++; | ||||
| 		ptr += 2; m++; | ||||
| 		clust++; | ||||
| 	} while (clust < fs->max_clust); | ||||
| 	n = 0; | ||||
| 	if (fs->fs_type == FS_FAT12) { | ||||
| 		clust = 2; | ||||
| 		do { | ||||
| 			if (get_cluster(clust) == 0) n++; | ||||
| 		} while (++clust < fs->max_clust); | ||||
| 	} else { | ||||
| 		clust = fs->max_clust; | ||||
| 		sect = fs->fatbase; | ||||
| 		f = 0; p = 0; | ||||
| 		do { | ||||
| 			if (!f) { | ||||
| 				if (!move_window(sect++)) return FR_RW_ERROR; | ||||
| 				p = fs->win; | ||||
| 			} | ||||
| 			if (LD_WORD(p) == 0) n++; | ||||
| 			p += 2; f += 1; | ||||
| 		} while (--clust); | ||||
| 	} | ||||
| 
 | ||||
| 	*nclust = n; | ||||
| 	return FR_OK; | ||||
| @ -682,7 +718,7 @@ FRESULT f_read ( | ||||
| 
 | ||||
| 	for ( ;  btr;									/* Repeat until all data transferred */ | ||||
| 		buff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { | ||||
| 		if ((fp->fptr & 511) == 0) {				/* On the sector boundary */ | ||||
| 		if ((fp->fptr % 512) == 0) {				/* On the sector boundary */ | ||||
| 			if (--(fp->sect_clust)) {				/* Decrement sector counter */ | ||||
| 				sect = fp->curr_sect + 1;			/* Next sector */ | ||||
| 			} else {								/* Next cluster */ | ||||
| @ -703,9 +739,9 @@ FRESULT f_read ( | ||||
| 			} | ||||
| 		} | ||||
| 		if (!move_window(fp->curr_sect)) goto fr_error;	/* Move sector window */ | ||||
| 		rcnt = 512 - (fp->fptr & 511);					/* Copy fractional bytes from sector window */ | ||||
| 		rcnt = 512 - (fp->fptr % 512);					/* Copy fractional bytes from sector window */ | ||||
| 		if (rcnt > btr) rcnt = btr; | ||||
| 		memcpy(buff, &fs->win[fp->fptr & 511], rcnt); | ||||
| 		memcpy(buff, &fs->win[fp->fptr % 512], rcnt); | ||||
| 	} | ||||
| 
 | ||||
| 	return FR_OK; | ||||
| @ -743,7 +779,7 @@ FRESULT f_write ( | ||||
| 
 | ||||
| 	for ( ;  btw;									/* Repeat until all data transferred */ | ||||
| 		buff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { | ||||
| 		if ((fp->fptr & 511) == 0) {				/* On the sector boundary */ | ||||
| 		if ((fp->fptr % 512) == 0) {				/* On the sector boundary */ | ||||
| 			if (--(fp->sect_clust)) {				/* Decrement sector counter */ | ||||
| 				sect = fp->curr_sect + 1;			/* Next sector */ | ||||
| 			} else {								/* Next cluster */ | ||||
| @ -774,9 +810,9 @@ FRESULT f_write ( | ||||
| 			} | ||||
| 		} | ||||
| 		if (!move_window(fp->curr_sect)) goto fw_error;	/* Move sector window */ | ||||
| 		wcnt = 512 - (fp->fptr & 511);				/* Copy fractional bytes bytes to sector window */ | ||||
| 		wcnt = 512 - (fp->fptr % 512);				/* Copy fractional bytes bytes to sector window */ | ||||
| 		if (wcnt > btw) wcnt = btw; | ||||
| 		memcpy(&fs->win[fp->fptr & 511], buff, wcnt); | ||||
| 		memcpy(&fs->win[fp->fptr % 512], buff, wcnt); | ||||
| 		fs->winflag = 1; | ||||
| 	} | ||||
| 
 | ||||
| @ -934,9 +970,9 @@ FRESULT f_unlink ( | ||||
| 		} while (next_dir_entry(&dirscan)); | ||||
| 	} | ||||
| 
 | ||||
| 	if (!remove_chain(dclust)) return FR_RW_ERROR;	/* Remove the cluster chain */ | ||||
| 	if (!move_window(dsect)) return FR_RW_ERROR;	/* Mark the directory entry deleted */ | ||||
| 	if (!move_window(dsect)) return FR_RW_ERROR;	/* Mark the directory entry 'deleted' */ | ||||
| 	*dir = 0xE5; fs->winflag = 1; | ||||
| 	if (!remove_chain(dclust)) return FR_RW_ERROR;	/* Remove the cluster chain */ | ||||
| 	if (!move_window(0)) return FR_RW_ERROR; | ||||
| 
 | ||||
| 	return FR_OK; | ||||
|  | ||||
							
								
								
									
										115
									
								
								src/tff.h
									
									
									
									
									
								
							
							
						
						
									
										115
									
								
								src/tff.h
									
									
									
									
									
								
							| @ -5,9 +5,6 @@ | ||||
| / cheap microcontrollers. This is opened for education, reserch and | ||||
| / development. You can use it for non-profit or profit use without any | ||||
| / limitation under your responsibility. | ||||
| /---------------------------------------------------------------------------/ | ||||
| /  Feb 26, 2006  R0.00  Prototype | ||||
| /  Apr 29, 2006  R0.01  First stable version | ||||
| /---------------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #ifndef _FATFS | ||||
| @ -32,86 +29,86 @@ typedef unsigned char	FRESULT; | ||||
| 
 | ||||
| /* File system object */ | ||||
| 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	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	sects_fat;		// Sectors per fat
 | ||||
| 	WORD	max_clust;		// Maximum cluster# + 1
 | ||||
| 	DWORD	fatbase;		// FAT start sector
 | ||||
| 	DWORD	dirbase;		// Root directory start sector (cluster# for FAT32)
 | ||||
| 	DWORD	database;		// Data start sector
 | ||||
| 	DWORD	winsect;		// Current sector appearing in the win[]
 | ||||
| 	BYTE	win[512];		// Disk access window
 | ||||
| 	WORD	sects_fat;		/* Sectors per fat */ | ||||
| 	WORD	max_clust;		/* Maximum cluster# + 1 */ | ||||
| 	DWORD	fatbase;		/* FAT start sector */ | ||||
| 	DWORD	dirbase;		/* Root directory start sector (cluster# for FAT32) */ | ||||
| 	DWORD	database;		/* Data start sector */ | ||||
| 	DWORD	winsect;		/* Current sector appearing in the win[] */ | ||||
| 	BYTE	win[512];		/* Disk access window */ | ||||
| } FATFS; | ||||
| 
 | ||||
| 
 | ||||
| /* Directory scan object */ | ||||
| typedef struct _DIR { | ||||
| 	WORD	sclust;		// Start cluster
 | ||||
| 	WORD	clust;		// Current cluster
 | ||||
| 	DWORD	sect;		// Current sector
 | ||||
| 	WORD	index;		// Current index
 | ||||
| 	WORD	sclust;		/* Start cluster */ | ||||
| 	WORD	clust;		/* Current cluster */ | ||||
| 	DWORD	sect;		/* Current sector */ | ||||
| 	WORD	index;		/* Current index */ | ||||
| } DIR; | ||||
| 
 | ||||
| 
 | ||||
| /* File object */ | ||||
| typedef struct _FIL { | ||||
| 	DWORD	fptr;			// File Pointer
 | ||||
| 	DWORD	fsize;			// File Size
 | ||||
| 	WORD	org_clust;		// File start cluster
 | ||||
| 	WORD	curr_clust;		// Current cluster
 | ||||
| 	DWORD	curr_sect;		// Current sector
 | ||||
| 	DWORD	fptr;			/* File Pointer */ | ||||
| 	DWORD	fsize;			/* File Size */ | ||||
| 	WORD	org_clust;		/* File start cluster */ | ||||
| 	WORD	curr_clust;		/* Current cluster */ | ||||
| 	DWORD	curr_sect;		/* Current sector */ | ||||
| #ifndef _FS_READONLY | ||||
| 	DWORD	dir_sect;		// Sector containing the directory entry
 | ||||
| 	BYTE*	dir_ptr;		// Ponter to the directory entry in the window
 | ||||
| 	DWORD	dir_sect;		/* Sector containing the directory entry */ | ||||
| 	BYTE*	dir_ptr;		/* Ponter to the directory entry in the window */ | ||||
| #endif | ||||
| 	BYTE	flag;			// File status flags
 | ||||
| 	BYTE	sect_clust;		// Left sectors in cluster
 | ||||
| 	BYTE	flag;			/* File status flags */ | ||||
| 	BYTE	sect_clust;		/* Left sectors in cluster */ | ||||
| } FIL; | ||||
| 
 | ||||
| 
 | ||||
| /* File status structure */ | ||||
| typedef struct _FILINFO { | ||||
| 	DWORD fsize;			// Size
 | ||||
| 	WORD fdate;				// Date
 | ||||
| 	WORD ftime;				// Time
 | ||||
| 	BYTE fattrib;			// Attribute
 | ||||
| 	char fname[8+1+3+1];	// File/Directory name (8.3 format)
 | ||||
| 	DWORD fsize;			/* Size */ | ||||
| 	WORD fdate;				/* Date */ | ||||
| 	WORD ftime;				/* Time */ | ||||
| 	BYTE fattrib;			/* Attribute */ | ||||
| 	char fname[8+1+3+1];	/* File/Directory name (8.3 format) */ | ||||
| } FILINFO; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* fatfs module application interface */ | ||||
| 
 | ||||
| extern FATFS *FatFs;	// Pointer to active file system object
 | ||||
| extern FATFS *FatFs;	/* Pointer to active file system object */ | ||||
| 
 | ||||
| FRESULT f_open (FIL*, const char*, BYTE);			// Open or create a file
 | ||||
| FRESULT f_read (FIL*, BYTE*, WORD, WORD*);			// Read file
 | ||||
| FRESULT f_close (FIL*);								// Close file
 | ||||
| FRESULT f_lseek (FIL*, DWORD);						// Seek file pointer
 | ||||
| FRESULT f_opendir (DIR*, const char*);				// Initialize to read a 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 ();								// Force initialized the file system
 | ||||
| FRESULT f_open (FIL*, const char*, BYTE);			/* Open or create a file */ | ||||
| FRESULT f_read (FIL*, BYTE*, WORD, WORD*);			/* Read file */ | ||||
| FRESULT f_close (FIL*);								/* Close file */ | ||||
| FRESULT f_lseek (FIL*, DWORD);						/* Seek file pointer */ | ||||
| FRESULT f_opendir (DIR*, const char*);				/* Initialize to read a 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 ();								/* Force initialized the file system */ | ||||
| #ifndef _FS_READONLY | ||||
| FRESULT f_write (FIL*, const BYTE*, WORD, WORD*);	// Write file
 | ||||
| FRESULT f_sync (FIL*);								// Flush cached information 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_write (FIL*, const BYTE*, WORD, WORD*);	/* Write file */ | ||||
| FRESULT f_sync (FIL*);								/* Flush cached information 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 */ | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| /* User defined function to give a current time to fatfs module */ | ||||
| 
 | ||||
| #ifndef _FS_READONLY | ||||
| DWORD get_fattime();	// 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)
 | ||||
| DWORD get_fattime();	/* 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) */ | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| @ -126,7 +123,6 @@ DWORD get_fattime();	// 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day | ||||
| #define	FR_DENIED					5 | ||||
| #define	FR_DISK_FULL				6 | ||||
| #define	FR_RW_ERROR					7 | ||||
| #define	FR_ALIGN_ERROR				8 | ||||
| #define	FR_INCORRECT_DISK_CHANGE	9 | ||||
| #define	FR_WRITE_PROTECTED			10 | ||||
| #define	FR_NOT_ENABLED				11 | ||||
| @ -148,17 +144,18 @@ DWORD get_fattime();	// 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day | ||||
| 
 | ||||
| /* FAT type signature (fs_type) */ | ||||
| 
 | ||||
| #define FS_FAT16	1 | ||||
| #define FS_FAT12	1 | ||||
| #define FS_FAT16	2 | ||||
| 
 | ||||
| 
 | ||||
| /* File attribute mask for directory entry */ | ||||
| 
 | ||||
| #define	AM_RDO	0x01	// Read Only
 | ||||
| #define	AM_HID	0x02	// Hidden
 | ||||
| #define	AM_SYS	0x04	// System
 | ||||
| #define	AM_VOL	0x08	// Volume Label
 | ||||
| #define AM_DIR	0x10	// Directory
 | ||||
| #define AM_ARC	0x20	// Archive
 | ||||
| #define	AM_RDO	0x01	/* Read Only */ | ||||
| #define	AM_HID	0x02	/* Hidden */ | ||||
| #define	AM_SYS	0x04	/* System */ | ||||
| #define	AM_VOL	0x08	/* Volume Label */ | ||||
| #define AM_DIR	0x10	/* Directory */ | ||||
| #define AM_ARC	0x20	/* Archive */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user