fatfs v0.14 October 14, 2019:
- Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1) - Changed some API functions, f_mkfs() and f_fdisk(). - Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters. - Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters. - Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12) - Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
This commit is contained in:
		
							parent
							
								
									7cb0c2d1e6
								
							
						
					
					
						commit
						ead60b6ce1
					
				| @ -5,6 +5,8 @@ | ||||
| <meta http-equiv="Content-Style-Type" content="text/css"> | ||||
| <meta http-equiv="cache-control" content="no-cache"> | ||||
| <meta name="description" content="Open source FAT filesystem for embedded projects"> | ||||
| <link rel="start" title="Site Top" href="../../"> | ||||
| <link rel="up" title="Freewares" href="../../fsw_e.html"> | ||||
| <link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default"> | ||||
| <title>FatFs - Generic FAT Filesystem Module</title> | ||||
| </head> | ||||
| @ -25,7 +27,7 @@ | ||||
|  <li>Various <a href="doc/config.html">configuration options</a> to support for: | ||||
|   <ul> | ||||
|    <li>Long file name in ANSI/OEM or Unicode.</li> | ||||
|    <li>exFAT filesystem.</li> | ||||
|    <li>exFAT filesystem, 64-bit LBA and GPT for huge storeges.</li> | ||||
|    <li>Thread safe for RTOS.</li> | ||||
|    <li>Multiple volumes (physical drives and partitions).</li> | ||||
|    <li>Variable sector size.</li> | ||||
| @ -67,7 +69,7 @@ | ||||
|  <ul> | ||||
|   <li><a href="doc/opendir.html">f_opendir</a> - Open a directory</li> | ||||
|   <li><a href="doc/closedir.html">f_closedir</a> - Close an open directory</li> | ||||
|   <li><a href="doc/readdir.html">f_readdir</a> - Read an directory item</li> | ||||
|   <li><a href="doc/readdir.html">f_readdir</a> - Read a directory item</li> | ||||
|   <li><a href="doc/findfirst.html">f_findfirst</a> - Open a directory and read the first item matched</li> | ||||
|   <li><a href="doc/findnext.html">f_findnext</a> - Read a next item matched</li> | ||||
|  </ul> | ||||
| @ -89,8 +91,8 @@ | ||||
|  <ul> | ||||
|   <li><a href="doc/mount.html">f_mount</a> - Register/Unregister the work area of the volume</li> | ||||
|   <li><a href="doc/mkfs.html">f_mkfs</a> - Create an FAT volume on the logical drive</li> | ||||
|   <li><a href="doc/fdisk.html">f_fdisk</a> - Create logical drives on the physical drive</li> | ||||
|   <li><a href="doc/getfree.html">f_getfree</a> - Get total size and free size on the volume</li> | ||||
|   <li><a href="doc/fdisk.html">f_fdisk</a> - Create partitions on the physical drive</li> | ||||
|   <li><a href="doc/getfree.html">f_getfree</a> - Get free space on the volume</li> | ||||
|   <li><a href="doc/getlabel.html">f_getlabel</a> - Get volume label</li> | ||||
|   <li><a href="doc/setlabel.html">f_setlabel</a> - Set volume label</li> | ||||
|   <li><a href="doc/setcp.html">f_setcp</a> - Set active code page</li> | ||||
| @ -103,14 +105,22 @@ | ||||
| <div class="para"> | ||||
| <h3>Media Access Interface</h3> | ||||
| <img src="res/layers2.png" class="rset" width="245" height="220" alt="layer"> | ||||
| <p>Since the FatFs module is the <em>filesystem layer</em> independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The low level device control module is <em>not a part of FatFs module</em> and it needs to be provided by implementer. FatFs accesses the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for low level disk I/O module is available <a href="res/app4.c">here</a>.</p> | ||||
| <p>Since FatFs module is the <em>filesystem layer</em> independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The low level device control module is <em>not any part of FatFs module</em> and it needs to be provided by implementer. FatFs accesses the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for low level disk I/O module is available <a href="res/app4.c">here</a>.</p> | ||||
| <ul> | ||||
|  <li><a href="doc/dstat.html">disk_status</a> - Get device status</li> | ||||
|  <li><a href="doc/dinit.html">disk_initialize</a> - Initialize device</li> | ||||
|  <li><a href="doc/dread.html">disk_read</a> - Read sector(s)</li> | ||||
|  <li><a href="doc/dwrite.html">disk_write</a> - Write sector(s)</li> | ||||
|  <li><a href="doc/dioctl.html">disk_ioctl</a> - Control device dependent functions</li> | ||||
|  <li><a href="doc/fattime.html">get_fattime</a> - Get current time</li> | ||||
|  <li>Disk Controls | ||||
|  <ul> | ||||
|   <li><a href="doc/dstat.html">disk_status</a> - Get device status</li> | ||||
|   <li><a href="doc/dinit.html">disk_initialize</a> - Initialize device</li> | ||||
|   <li><a href="doc/dread.html">disk_read</a> - Read data</li> | ||||
|   <li><a href="doc/dwrite.html">disk_write</a> - Write data</li> | ||||
|   <li><a href="doc/dioctl.html">disk_ioctl</a> - Control device dependent functions</li> | ||||
|  </ul> | ||||
|  </li> | ||||
|  <li>Real Time Clock | ||||
|  <ul> | ||||
|   <li><a href="doc/fattime.html">get_fattime</a> - Get current time</li> | ||||
|  </ul> | ||||
|  </li> | ||||
| </ul> | ||||
| </div> | ||||
| 
 | ||||
| @ -119,8 +129,8 @@ | ||||
| <h3>Resources</h3> | ||||
| <p>The FatFs module is a free software opened for education, research and development. You can use, modify and/or redistribute it for personal projects or commercial products without any restriction under your responsibility. For further information, refer to the application note.</p> | ||||
| <ul> | ||||
|  <li>Read first: <a href="doc/appnote.html">FatFs module application note</a></li> | ||||
|  <li>Download: <a href="http://elm-chan.org/fsw/ff/archives.html">Archives of FatFs and Petit-FatFs</a></li> | ||||
|  <li><em>Read First: <a href="doc/appnote.html">FatFs module application note</a></em></li> | ||||
|  <li>Download: <a href="http://elm-chan.org/fsw/ff/archives.html">Archives</a></li> | ||||
|  <li>Community: <a href="http://elm-chan.org/fsw/ff/bd/">FatFs User Forum</a></li> | ||||
|  <li><a href="https://msdn.microsoft.com/en-us/windows/hardware/gg463080.aspx">FAT32 Specification by Microsoft</a>↗ (The authorized document on FAT filesystem)</li> | ||||
|  <li><a href="http://elm-chan.org/docs/fat_e.html">The basics of FAT filesystem</a></li> | ||||
| @ -131,11 +141,7 @@ | ||||
|  <li><a href="http://stm32f4-discovery.net/2014/07/library-21-read-sd-card-fatfs-stm32f4xx-devices/">Read SD card with FatFs on STM32F4xx devices by Tilen Majerle</a>↗ (Quick and easy implementation for STM32F4-Discovery)</li> | ||||
|  <li><a href="res/rwtest1.png">Benchmark 1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li> | ||||
|  <li><a href="res/rwtest2.png">Benchmark 2</a> (LPC2368/72MHz with MMC via MCI)</li> | ||||
|  <li><a href="res/fd.mp4">Demo movie of an application</a> (this project is in ffsample.zip/lpc23xx)</li></ul> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <hr> | ||||
| <p class="foot"><a href="http://elm-chan.org/fsw/ff/00index_e.html">FatFs Home Page</a></p> | ||||
| </body> | ||||
| </html> | ||||
|  | ||||
| @ -19,6 +19,7 @@ | ||||
| <li><a href="#lfn">Long File Name</a></li> | ||||
| <li><a href="#unicode">Unicode API</a></li> | ||||
| <li><a href="#exfat">exFAT Filesystem</a></li> | ||||
| <li><a href="#lba64">64-bit LBA</a></li> | ||||
| <li><a href="#reentrant">Re-entrancy</a></li> | ||||
| <li><a href="#dup">Duplicated File Access</a></li> | ||||
| <li><a href="#fs1">Performance Effective File Access</a></li> | ||||
| @ -38,14 +39,27 @@ | ||||
| The FatFs module is a middleware written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with C89 or later. Only exFAT feature requires C99.</li> | ||||
| <li>Size of integer types<br> | ||||
| <ul> | ||||
| <li>When the C standard is in C89, size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> must be 8/16/32-bit respectively.</li> | ||||
| <li>When it is in C99 or later, <tt>stdint.h</tt> is used to obtain the correct sizes.</li> | ||||
| <li>Size of <tt>char</tt> must be 8-bit.</li> | ||||
| <li>Size of <tt>int</tt>, as well as integer promotion, must be 16-bit or 32-bit.</li> | ||||
| <li>When the C standard is in C89, size of <tt>short</tt> and <tt>long</tt> must be 16-bit and 32-bit respectively.</li> | ||||
| <li>When it is in C99 or later, <tt>stdint.h</tt> is used to obtain the integer sizes.</li> | ||||
| </ul> | ||||
| Integer types used in FatFs are defined in <tt>fftypes.h</tt>. This will not be a problem on most platform. When a conflict with existing definitions occured, you must resolve it with care.</li> | ||||
| </ul> | ||||
| 
 | ||||
| <h4>Integer Types in FatFs API</h4> | ||||
| <p>Integer types used in FatFs are defined in <tt>ff.h</tt> as described below. It is based on Win32 API (<tt>windef.h</tt>). This will not be a problem on most platform. When a conflict with existing definitions occured, you must resolve it with care.</p> | ||||
| <dl> | ||||
| <dt><tt>BYTE</tt></dt><dd>8-bit unsigned integer in range of 0 to 2<sup>8</sup> - 1.</dd> | ||||
| <dt><tt>WORD</tt></dt><dd>16-bit unsigned integer in range of 0 to 2<sup>16</sup> - 1.</dd> | ||||
| <dt><tt>DWORD</tt></dt><dd>32-bit unsigned integer in range of 0 to 2<sup>32</sup> - 1.</dd> | ||||
| <dt><tt>QWORD</tt></dt><dd>64-bit unsigned integer in range of 0 to 2<sup>64</sup> - 1.</dd> | ||||
| <dt><tt>UINT</tt></dt><dd>Alias of <tt>unsigned int</tt> used to specify any number.</dd> | ||||
| <dt><tt>WCHAR</tt></dt><dd>Alias of <tt>WORD</tt> used to specify a UTF-16 encoding unit.</dd> | ||||
| <dt><tt>TCHAR</tt></dt><dd>Alias of <tt>char</tt>, <tt>WCHAR</tt> or <tt>DWORD</tt> used to specify a character encoding unit.</dd> | ||||
| <dt><tt>FSIZE_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address file offset and to specify file size.</dd> | ||||
| <dt><tt>LBA_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address sectors in LBA and to specify number of sectors.</dd> | ||||
| </dl> | ||||
| 
 | ||||
| <h4>System Organizations</h4> | ||||
| <p>The dependency diagram shown below is a typical, but not specific, configuration of the embedded system with FatFs module.</p> | ||||
| <p><img src="../res/modules.png" width="580" height="280" alt="dependency diagram"></p> | ||||
| @ -53,7 +67,7 @@ Integer types used in FatFs are defined in <tt>fftypes.h</tt>. This will not be | ||||
| <p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p> | ||||
| 
 | ||||
| <h4>Required Functions</h4> | ||||
| <p>You need to provide only low level disk I/O functions required by FatFs module and nothing else. If a working disk I/O module for the target system is already provided, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk I/O module or write it from scratch. Most of defined functions are not that always required. For instance, any write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</p> | ||||
| <p>You need to provide only storage device control functions required by FatFs module and nothing else. If a working disk I/O module for the target system is already provided, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk I/O module or write it from scratch. Most of defined functions are not that always required. For instance, any write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</p> | ||||
| <table class="lst2"> | ||||
| <tr><th>Function</th><th>Required when</th><th>Note</th></tr> | ||||
| <tr><td>disk_status<br>disk_initialize<br>disk_read</td><td>Always</td><td rowspan="5">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr> | ||||
| @ -73,11 +87,12 @@ Integer types used in FatFs are defined in <tt>fftypes.h</tt>. This will not be | ||||
| <ul> | ||||
| <li>Filesystem type: FAT, FAT32(rev0.0) and exFAT(rev1.0).</li> | ||||
| <li>Number of open files: Unlimited. (depends on available memory)</li> | ||||
| <li>Number of volumes: Upto 10.</li> | ||||
| <li>Volume size: Upto 2 TB at 512 bytes/sector.</li> | ||||
| <li>File size: Upto 4 GB - 1 on FAT volume and virtually unlimited on exFAT volume.</li> | ||||
| <li>Cluster size: Upto 128 sectors on FAT volume and upto 16 MB on exFAT volume.</li> | ||||
| <li>Number of volumes: Up to 10.</li> | ||||
| <li>Sector size: 512, 1024, 2048 and 4096 bytes.</li> | ||||
| <li>Minimum volume size: 128 sectors.</li> | ||||
| <li>Maximum volume size: 2<sup>32</sup> - 1 sectors in 32-bit LBA, virtually unlimited in 64-bit LBA with exFAT.</li> | ||||
| <li>Maximum file size: 2<sup>32</sup> - 1 bytes on FAT volume, virtually unlimited on exFAT volume.</li> | ||||
| <li>Cluster size: Upto 128 sectors on FAT volume and up to 16 MB on exFAT volume.</li> | ||||
| </ul> | ||||
| </div> | ||||
| 
 | ||||
| @ -107,7 +122,7 @@ And any other options are left unchanged from original setting. | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="reduce"> | ||||
| <h3>Reducing Modle Size</h3> | ||||
| <h3>Reducing Module Size</h3> | ||||
| <p>Follwing table shows which API function is removed by configuration options for the module size reduction. To use any API function, the row of the function must be clear.</p> | ||||
| <table class="lst2"> | ||||
| <tr><td rowspan="2">Function</td><td colspan="4">FF_FS_<br>MINIMIZE</td><td colspan="2">FF_FS_<br>READONLY</td><td colspan="2">FF_USE_<br>STRFUNC</td><td colspan="3">FF_FS_<br>RPATH</td><td colspan="2">FF_USE_<br>FIND</td><td colspan="2">FF_USE_<br>CHMOD</td><td colspan="2">FF_USE_<br>EXPAND</td><td colspan="2">FF_USE_<br>LABEL</td><td colspan="2">FF_USE_<br>MKFS</td><td colspan="2">FF_USE_<br>FORWARD</td><td colspan="2">FF_MULTI_<br>PARTITION</td></tr> | ||||
| @ -151,7 +166,8 @@ And any other options are left unchanged from original setting. | ||||
| 
 | ||||
| <div class="para doc" id="lfn"> | ||||
| <h3>Long File Name</h3> | ||||
| <p>FatFs module supports long file name (LFN). The two different file names, short file name (SFN) and LFN, of a file is transparent on the API except for <tt>f_readdir</tt> function. The support for LFN is disabled by default. To enable the LFN, set <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>ffunicode.c</tt> to the project. The LFN requiers a certain working buffer in addition. The buffer size can be configured by <tt><a href="config.html#max_lfn">FF_MAX_LFN</a></tt> according to the available memory. The length of an LFN will be up to 255 characters, so that the <tt>FF_MAX_LFN</tt> should be set to 255 for all file names. If the size of working buffer is insufficient for the input file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When use any re-entry to the API with LFN is enabled, <tt>FF_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The working buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled.</p> | ||||
| <p>FatFs module supports the long file name (LFN) extension of the FAT filesystem. The two different file names, short file name (SFN) and LFN, of a file is transparent on the API. The support for LFN feature is disabled by default. To enable the LFN, set <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>ffunicode.c</tt> to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by <tt><a href="config.html#max_lfn">FF_MAX_LFN</a></tt> according to the available memory. The length of an LFN can be up to 255 characters, so that the <tt>FF_MAX_LFN</tt> should be set to 255 for all existing file names. If the size of working buffer is insufficient for the input file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When use any re-entry to the API with LFN feature, <tt>FF_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The LFN working buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled.</p> | ||||
| <h4>Impact upon Module Size</h4> | ||||
| <table class="lst2 rset"> | ||||
| <caption>With LFN at CM3 + gcc</caption> | ||||
| <tr><th><tt>FF_CODE_PAGE</tt></th><th>Code size</th></tr> | ||||
| @ -162,9 +178,9 @@ And any other options are left unchanged from original setting. | ||||
| <tr><td>950 (Traditional Chinese)</td><td>+111k</td></tr> | ||||
| <tr><td>0 (All code pages)</td><td>+486k</td></tr> | ||||
| </table> | ||||
| <p>When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows increment of code size by LFN function at different code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table.</p> | ||||
| <p>As the result, the FatFs with LFN enebled with DBCS code pages will not able to be ported on the most 8-bit MCU systems. If the target system is in legacy-free, in only Unicode and any ANSI/OEM code is not used at all, the code page setting gets meaningless. You will able to reduce the code size by configureing FatFs for Unicode with any SBCS code page.</p> | ||||
| <p>There ware some restrictions on using LFN for open source project because the support for LFN on the FAT volume was a patent of Microsoft Corporation. The related patents have expired and using the LFN function has got free for any projects.</p> | ||||
| <p>When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows the increment of code size in some code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table.</p> | ||||
| <p>As the result, the FatFs with LFN enabled with DBCS code pages will not able to be ported on the most 8-bit MCU systems. If the target system is in legacy-free, in only Unicode and any ANSI/OEM code is not used at all, the code page setting gets meaningless. You will able to reduce the code size by configureing FatFs for Unicode with any SBCS code page.</p> | ||||
| <p>There ware some restrictions on using LFN for open source project because the LFN extension on the FAT filesystem was a patent of Microsoft Corporation. But the related patents all have expired and using the LFN feature has got free for any projects.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="unicode"> | ||||
| @ -175,17 +191,40 @@ And any other options are left unchanged from original setting. | ||||
| 
 | ||||
| <div class="para doc" id="exfat"> | ||||
| <h3>exFAT Filesystem</h3> | ||||
| <p>The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as the regular filesystem for SDXC card, 64 GB and larger, and they are being shipped with this format. Therefore the exFAT is one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows upto and some filesystem overhead, especially cluster allocation delay, are reduced as well. These features allow to record the large media file without dividing into some files and improve the write throughput to the file.</p> | ||||
| <p>Note that the exFAT is a patent of Microsoft Corporation. The support for exFAT of FatFs is an implementation based on <cite>US. Pat. App. Pub. No. 2009/0164440 A1</cite>. FatFs module can switch the exFAT on or off by configuration option, <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>. When enable the exFAT on the commercial products, a license by Microsoft will be needed depends on the final destination of the products.</p> | ||||
| <p><em>Remark: Enabling exFAT discards C89 compatibility because of need for 64-bit integer type.</em></p> | ||||
| <p>The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as the filesystem for SDXC card, 64 GB and larger, and they are being shipped with this format. Therefore the exFAT is one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows up to and some filesystem overhead, especially cluster allocation delay, are reduced as well. These features allow to record the large data without dividing into some files and improve the write throughput to the file.</p> | ||||
| <p>Note that the exFAT filesystem is a patent of Microsoft Corporation. The exFAT feature of FatFs is an implementation based on <cite>US. Pat. App. Pub. No. 2009/0164440 A1</cite>. FatFs module can switch the exFAT on or off by a configuration option, <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>. When enable the exFAT for the commercial products, a license by Microsoft will be needed depends on the final destination of the products.</p> | ||||
| <p><em>Remarks: Enabling exFAT discards C89 compatibility and it wants C99 because of need for 64-bit integer type.</em></p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="lba64"> | ||||
| <h3>64-bit LBA</h3> | ||||
| <p>LBA (Logical Block Addressing) is an addressing method to specify the location of data block, called sector, on the storage media. It is a simple linear address beginning from 0 as the first block of data. The host system does not need to consider how the data block is located and managed in the storage device. FatFs supports only LBA for the media access. 32-bit LBA is a common size at the interface of the most storage devices. It can address up to 2<sup>32</sup> blocks, 2 TB in 512 bytes/sector. When a storage device larger than 2 TB is used, larger sector size or 64-bit LBA will be needed to address the entire block of the storage device.</p> | ||||
| <p>By default, FatFs works in 32-bit LBA for media access interface. FatFs can also switch it to 64-bit LBA by a configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>. It also enables GPT (GUID Partition Table) for partiotion management on the storage device. For further information about GPT, refer to <tt><a href="mkfs.html">f_mkfs</a></tt> and <tt><a href="fdisk.html">f_fdisk</a></tt> function.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="reentrant"> | ||||
| <h3>Re-entrancy</h3> | ||||
| <p>The file operations to the <em>different volumes</em> each other is always re-entrant regardless of configurations except when LFN is enabled with static working buffer. It can work concurrently without any mutual exclusion.</p> | ||||
| <p>The file operations to the <em>same volume</em> is not re-entrant. It can also be configured for thread-safe by option <tt><a href="config.html#fs_reentrant">FF_FS_REENTRANT</a></tt>. In this case, also the OS dependent synchronization control functions, <tt>ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant</tt>, need to be added to the project. There are some examples in the <tt>ffsystem.c</tt>. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by <tt>FF_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout function might not be supported on the some RTOSs.</p> | ||||
| <p>The file operations of two tasks to the <em>different volumes</em> each other is always re-entrant regardless of the configurations except when LFN is enabled with static working buffer (<tt>FF_USE_LFN = 1</tt>). It can work concurrently without any mutual exclusion.</p> | ||||
| <p>The file operations of two tasks to the <em>same volume</em> is not re-entrant in default. FatFs can also be configured to make it thread-safe by option <tt><a href="config.html#fs_reentrant">FF_FS_REENTRANT</a></tt>. In this case, also the OS dependent synchronization control functions, <tt>ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant</tt>, need to be added to the project. There are some examples in the <tt>ffsystem.c</tt>. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by <tt>FF_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout feature might not be supported on the some RTOSs.</p> | ||||
| <p>There is an exception on the re-entrancy for <tt>f_mount/f_mkfs</tt> function. These volume management functions are not re-entrant to the same volume. When use these functions, other tasks need to avoid to access the volume.</p> | ||||
| <p>Remarks: This section describes on the re-entrancy of the FatFs module itself. The <tt>FF_FS_REENTRANT</tt> option enables only exclusive use of each filesystem objects and FatFs never prevents to re-enter <tt>disk_*()</tt> functions. Thus the low level disk I/O layer must be always thread-safe when FatFs API is re-entered for different volumes.</p> | ||||
| <div class="rset"> | ||||
| <table class="lst2"> | ||||
| <tr><th><tt>Function</tt></th><th>Case 1</th><th>Case 2</th><th>Case 3</th></tr> | ||||
| <tr><td>disk_status</td><td>Yes</td><td>Yes</td><td>Yes(*)</td></tr> | ||||
| <tr><td>disk_initialize</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> | ||||
| <tr><td>disk_read</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> | ||||
| <tr><td>disk_write</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> | ||||
| <tr><td>disk_ioctl</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr> | ||||
| <tr><td>get_fattime</td><td>No</td><td>Yes</td><td>Yes</td></tr> | ||||
| </table> | ||||
| <small> | ||||
| Case 1: Same volume.<br> | ||||
| Case 2: Different volume on the same drive.<br> | ||||
| Case 3: Different volume on the different drive.<br> | ||||
| (*) In only different drive number. | ||||
| </small> | ||||
| </div> | ||||
| <p>Remarks: This section describes on the re-entrancy of the FatFs module itself. The <tt>FF_FS_REENTRANT</tt> option enables only exclusive use of each filesystem objects and FatFs does not that prevent to re-enter the storage device control functions. Thus the device control layer needs to be always thread-safe when FatFs API is re-entered for different volumes. Right table shows which control function can be re-entered when FatFs API is re-entered on some conditions.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="dup"> | ||||
| @ -227,7 +266,7 @@ Figure 6. Comparison between Multiple/Single Sector Write<br> | ||||
| 
 | ||||
| <div class="para doc" id="critical"> | ||||
| <h3>Critical Section</h3> | ||||
| <p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, incorrect media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.</p> | ||||
| <p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, wrong media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.</p> | ||||
| <div class="lset"> | ||||
| Figure 4. Long critical section<br> | ||||
| <img src="../res/f4.png" width="320" height="436" alt="fig.4"> | ||||
| @ -250,14 +289,16 @@ Figure 5. Minimized critical section<br> | ||||
| 
 | ||||
| <div class="para doc" id="fs3"> | ||||
| <h3>Extended Use of FatFs API</h3> | ||||
| <p>These are examples of extended use of FatFs APIs. New item will be added whenever a useful code is found.</p> | ||||
| <p>These are examples of extended use of FatFs APIs. New item will be added when useful code example is found.</p> | ||||
| <ol> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app1.c">Open or create a file for append</a> (for R0.12 and earlier)</li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app2.c">Delete a non-empty sub-directory</a> (for R0.12 and later)</li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app3.c">Allocate contiguous area to the file</a> (for R0.11a and earlier)</li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app4.c">Compatibility checker for low level disk I/O module</a></li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/mkfatimg.zip">FAT volume image creator</a></li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app5.c">Test if the file is contiguous or not</a></li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app4.c">Compatibility checker for storage device control module</a></li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/app6.c">Performance checker for storage device control module</a></li> | ||||
| <li><a href="http://elm-chan.org/fsw/ff/res/mkfatimg.zip">FAT volume image creator</a></li> | ||||
| <li>Virtual drive feature (refer to lpc176x/ in <a href="../ffsample.zip">ffsample.zip</a>)</li> | ||||
| </ol> | ||||
| </div> | ||||
| 
 | ||||
| @ -284,7 +325,7 @@ Figure 5. Minimized critical section<br> | ||||
| / by use of this software. | ||||
| /----------------------------------------------------------------------------*/ | ||||
| </pre> | ||||
| <p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.</p> | ||||
| <p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that compatible with FatFs license.</p> | ||||
| </div> | ||||
| 
 | ||||
| <p class="foot"><a href="../00index_e.html">Return Home</a></p> | ||||
|  | ||||
| @ -25,7 +25,7 @@ FRESULT f_chdir ( | ||||
| <h4>Parameters</h4> | ||||
| <dl class="par"> | ||||
| <dt>path</dt> | ||||
| <dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory</a> to go.</dd> | ||||
| <dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory</a> to be set as current directory.</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -50,7 +50,7 @@ FRESULT f_chdir ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_chdir</tt> function changes the current directory of the logical drive. Also the current drive is changed at Unix style volume ID, <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 2</tt>. The current directory of each logical drive is initialized to the root directory on mount.</p> | ||||
| <p>The <tt>f_chdir</tt> function changes the current directory of the logical drive. Also the current drive will be changed when Unix style volume ID, <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 2</tt>, is selected. The current directory of each logical drive is initialized to the root directory on mount.</p> | ||||
| <p>Note that the current directory is retained in the each file system object and the current drive is retained in a static variable, so that it also affects other tasks that use the file functions.</p> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -45,8 +45,9 @@ | ||||
|    <li><a href="#volume_strs">FF_VOLUME_STRS</a></li> | ||||
|    <li><a href="#multi_partition">FF_MULTI_PARTITION</a></li> | ||||
|    <li><a href="#max_ss">FF_MIN_SS, FF_MAX_SS</a></li> | ||||
|    <li><a href="#fs_lba64">FF_LBA64</a></li> | ||||
|    <li><a href="#fs_gptmin">FF_GPT_MIN</a></li> | ||||
|    <li><a href="#use_trim">FF_USE_TRIM</a></li> | ||||
|    <li><a href="#fs_nofsinfo">FF_FS_NOFSINFO</a></li> | ||||
|  </ul> | ||||
| </li> | ||||
| <li>System Configurations | ||||
| @ -55,6 +56,7 @@ | ||||
|    <li><a href="#fs_exfat">FF_FS_EXFAT</a></li> | ||||
|    <li><a href="#fs_nortc">FF_FS_NORTC</a></li> | ||||
|    <li><a href="#nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</a></li> | ||||
|    <li><a href="#fs_nofsinfo">FF_FS_NOFSINFO</a></li> | ||||
|    <li><a href="#fs_lock">FF_FS_LOCK</a></li> | ||||
|    <li><a href="#fs_reentrant">FF_FS_REENTRANT</a></li> | ||||
|    <li><a href="#fs_timeout">FF_FS_TIMEOUT</a></li> | ||||
| @ -116,7 +118,7 @@ | ||||
| <h3>Namespace and Locale Configurations</h3> | ||||
| 
 | ||||
| <h4 id="code_page">FF_CODE_PAGE</h4> | ||||
| <p>This option specifies the OEM code page to be used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used for the path name, there is no difference between any code page settings. Set it 437 anyway.</p> | ||||
| <p>This option specifies the OEM code page used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used for path name or character encoding is Unicode, there is no difference between any code page settings. Set it 437 anyway.</p> | ||||
| <table class="lst1"> | ||||
| <tr><th>Value</th><th>Code page</th></tr> | ||||
| <tr><td>0</td><td>Includes all code pages below and set by <tt>f_setcp()</tt></td></tr> | ||||
| @ -157,7 +159,7 @@ | ||||
| <p>LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 in UTF-16 encoding unit of the LFN. The buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.</p> | ||||
| 
 | ||||
| <h4 id="lfn_unicode">FF_LFN_UNICODE</h4> | ||||
| <p>This option switches character encoding for the file name on the API. When Unicode is selected, <tt>FF_CODE_PAGE</tt> has actually no meaning except for compatibility with legacy systems, such as MS-DOS and any system without support for LFN. FatFs supports the code point upto U+10FFFF.</p> | ||||
| <p>This option switches character encoding for the file name on the API. When Unicode is selected, <tt>FF_CODE_PAGE</tt> has actually no meaning except for compatibility with legacy systems, such as MS-DOS and any system without support for LFN. FatFs supports the code point up to U+10FFFF.</p> | ||||
| <table class="lst2"> | ||||
| <tr><th>Value</th><th>Character Encoding</th><th><tt>TCHAR</tt></th></tr> | ||||
| <tr><td>0</td><td>ANSI/OEM in current CP</td><td>char</td></tr> | ||||
| @ -204,7 +206,7 @@ | ||||
| <h3>Volume/Drive Configurations</h3> | ||||
| 
 | ||||
| <h4 id="volumes">FF_VOLUMES</h4> | ||||
| <p>This option configures number of volumes (logical drives upto 10) to be used.</p> | ||||
| <p>This option configures number of volumes (logical drives up to 10) to be used.</p> | ||||
| 
 | ||||
| <h4 id="str_volume_id">FF_STR_VOLUME_ID</h4> | ||||
| <p>This option switches the support for string volume ID. When arbitrary string for the volume ID is enabled for the drive prefix, also pre-defined strings by <tt>FF_VOLUME_STRS</tt> or user defined strings can be used as drive prefix in the path name. Numeric drive number is always valid regardless of this option, and also either format of drive prefix can be enabled by this option.</p> | ||||
| @ -226,11 +228,35 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"}; | ||||
| <p>Disable (0) or Enable (1). This option switches multi-partition function. By default (0), each logical drive number is bound to the same physical drive number and only a volume in the physical drive is mounted. When enabled, each logical drive is bound to the partition on the physical drive listed in the user defined partition resolution table <tt>VolToPart[]</tt>. Also <tt>f_fdisk</tt> funciton will be available. For more information, read <a href="filename.html#vol">here</a>.</p> | ||||
| 
 | ||||
| <h4 id="max_ss">FF_MIN_SS, FF_MAX_SS</h4> | ||||
| <p>This set of options defines the extent of sector size used on the low level disk I/O interface, <tt>disk_read</tt> and <tt>disk_write</tt> function. Valid values are 512, 1024, 2048 and 4096. <tt>FF_MIN_SS</tt> defines minimum sector size and <tt>FF_MAX_SS</tt> defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When <tt>FF_MAX_SS > FF_MIN_SS</tt>, support of variable sector size is enabled and <tt>GET_SECTOR_SIZE</tt> command needs to be implemented to the <tt>disk_ioctl</tt> function.</p> | ||||
| <p>This set of options defines the extent of sector size used for the low level disk I/O interface, <tt>disk_read</tt> and <tt>disk_write</tt> function. Valid values are 512, 1024, 2048 and 4096. <tt>FF_MIN_SS</tt> defines minimum sector size and <tt>FF_MAX_SS</tt> defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When <tt>FF_MAX_SS > FF_MIN_SS</tt>, support of variable sector size is enabled and <tt>GET_SECTOR_SIZE</tt> command needs to be implemented to the <tt>disk_ioctl</tt> function.</p> | ||||
| 
 | ||||
| <h4 id="fs_lba64">FF_LBA64</h4> | ||||
| <p>This option switches media access interface to 64-bit LBA and enables GUID Partition Table (GPT) for partition management, Enabled (1) or Disabled (0). exFAT filesystem needs to be enabled to enable this feature.</p> | ||||
| 
 | ||||
| <h4 id="fs_gptmin">FF_MIN_GPT</h4> | ||||
| <p>This option specifies the threshold of determination of partitioning format when create patitions on the drive in <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function. When number of sectors on the drive is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when <tt>FF_LBA64 == 0</tt>.</p> | ||||
| 
 | ||||
| <h4 id="use_trim">FF_USE_TRIM</h4> | ||||
| <p>Disable (0) or Enable (1). This option switches ATA-TRIM function. To enable Trim function, also <tt>CTRL_TRIM</tt> command should be implemented to the <tt>disk_ioctl</tt> function.</p> | ||||
| 
 | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para doc" id="system"> | ||||
| <h3>System Configurations</h3> | ||||
| 
 | ||||
| <h4 id="fs_tiny">FF_FS_TINY</h4> | ||||
| <p>Normal (0) or Tiny (1). The tiny configuration reduces size of the <tt>FIL</tt> structure, file object, <tt>FF_MAX_SS</tt> bytes each. Instead of private sector buffer eliminated from the file object, common sector buffer in the <tt>FATFS</tt> structure, filesystem object, is used for the file data transfer.</p> | ||||
| 
 | ||||
| <h4 id="fs_exfat">FF_FS_EXFAT</h4> | ||||
| <p>This option switches support for exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing <tt>FF_LFN_UNICODE >= 1</tt> and <tt>FF_MAX_LFN == 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility and wants C99 because of need for 64-bit integer type.</p> | ||||
| 
 | ||||
| <h4 id="fs_nortc">FF_FS_NORTC</h4> | ||||
| <p>Use RTC (0) or Do not use RTC (1). This option controls timestamp function. If the system does not have any RTC function or valid timestamp is not needed, set <tt>FF_FS_NORTC</tt> to 1 to disable the timestamp function. Every objects modified by FatFs will have a fixed timestamp defined by <tt>FF_NORTC_MON</tt>, <tt>FF_NORTC_MDAY</tt> and <tt>FF_NORTC_YEAR</tt>. To use the timestamp function, set <tt>FF_FS_NORTC == 0</tt> and add <tt>get_fattime</tt> function to the project to get current time form the RTC. This option has no effect at read-only configuration.</p> | ||||
| 
 | ||||
| <h4 id="nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</h4> | ||||
| <p>This set of options defines the time to be used at no RTC systems. This option has no effect at read-only configuration or <tt>FF_FS_NORTC == 0</tt>.</p> | ||||
| 
 | ||||
| <h4 id="fs_nofsinfo">FF_FS_NOFSINFO</h4> | ||||
| <p>0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and <tt>f_getfree</tt> function at first time after volume mount will force a full FAT scan. Bit 1 controls the use of last allocated cluster number.</p> | ||||
| <table class="lst1"> | ||||
| @ -241,24 +267,6 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"}; | ||||
| <tr><td>bit1=1</td><td>Do not trust last allocated cluster number in the FSINFO.</td></tr> | ||||
| </table> | ||||
| 
 | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para doc" id="system"> | ||||
| <h3>System Configurations</h3> | ||||
| 
 | ||||
| <h4 id="fs_tiny">FF_FS_TINY</h4> | ||||
| <p>Normal (0) or Tiny (1). At the tiny configuration, size of the file object <tt>FIL</tt> is reduced <tt>FF_MAX_SS</tt> bytes. Instead of private data buffer eliminated from the file object, common sector buffer in the filesystem object <tt>FATFS</tt> is used for the file data transfer.</p> | ||||
| 
 | ||||
| <h4 id="fs_exfat">FF_FS_EXFAT</h4> | ||||
| <p>This option switches support for the exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing <tt>FF_LFN_UNICODE >= 1</tt> and <tt>FF_MAX_LFN == 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.</p> | ||||
| 
 | ||||
| <h4 id="fs_nortc">FF_FS_NORTC</h4> | ||||
| <p>Use RTC (0) or Do not use RTC (1). This option controls timestamp function. If the system does not have any RTC function or valid timestamp is not needed, set <tt>FF_FS_NORTC</tt> to 1 to disable the timestamp function. Every objects modified by FatFs will have a fixed timestamp defined by <tt>FF_NORTC_MON</tt>, <tt>FF_NORTC_MDAY</tt> and <tt>FF_NORTC_YEAR</tt>. To use the timestamp function, set <tt>FF_FS_NORTC == 0</tt> and add <tt>get_fattime</tt> function to the project to get current time form the RTC. This option has no effect at read-only configuration.</p> | ||||
| 
 | ||||
| <h4 id="nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</h4> | ||||
| <p>This set of options defines the time to be used at no RTC systems. This option has no effect at read-only configuration or <tt>FF_FS_NORTC == 0</tt>.</p> | ||||
| 
 | ||||
| <h4 id="fs_lock">FF_FS_LOCK</h4> | ||||
| <p>This option switches file lock function to control duplicated file open and illegal operations to open objects. Note that the file lock function is independent of re-entrancy. This option must be 0 at read-only configuration.</p> | ||||
| <table class="lst1"> | ||||
|  | ||||
| @ -57,35 +57,35 @@ DRESULT disk_ioctl ( | ||||
| <table class="lst"> | ||||
| <caption>Standard ioctl command used by FatFs</caption> | ||||
| <tr><th>Command</th><th>Description</th></tr> | ||||
| <tr><td>CTRL_SYNC</td><td>Make sure that the device has finished pending write process. If the disk I/O module has a write back cache, the dirty buffers must be written back to the media immediately. Nothing to do for this command if each write operation to the media is completed within the <tt>disk_write</tt> function.</td></tr> | ||||
| <tr><td>GET_SECTOR_COUNT</td><td>Returns number of available sectors on the drive into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function to determine the volume/partition size to be created. Required at <tt>FF_USE_MKFS == 1</tt>.</td></tr> | ||||
| <tr><td>GET_SECTOR_SIZE</td><td>Returns sector size of the device into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. Valid return values for this command are 512, 1024, 2048 and 4096. This command is required only if <tt>FF_MAX_SS > FF_MIN_SS</tt>. When <tt>FF_MAX_SS == FF_MIN_SS</tt>, this command is never used and the device must work at that sector size.</td></tr> | ||||
| <tr><td>GET_BLOCK_SIZE</td><td>Returns erase block size of the flash memory media in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or non flash memory media. This command is used by only <tt>f_mkfs</tt> function and it attempts to align data area on the erase block boundary. Required at <tt>FF_USE_MKFS == 1</tt>.</td></tr> | ||||
| <tr><td>CTRL_TRIM</td><td>Informs the device the data on the block of sectors is no longer needed and it can be erased. The sector block is specified by a <tt>DWORD</tt> array {<start sector>, <end sector>} pointed by <tt class="arg">buff</tt>. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the <tt>f_mkfs</tt> function. Required at <tt>FF_USE_TRIM == 1</tt>.</td></tr> | ||||
| <tr><td>CTRL_SYNC</td><td>Makes sure that the device has finished pending write process. If the disk I/O layer or storage device has a write-back cache, the dirty cache data must be committed to media immediately. Nothing to do for this command if each write operation to the media is completed within the <tt>disk_write</tt> function.</td></tr> | ||||
| <tr><td>GET_SECTOR_COUNT</td><td>Retrieves number of available sectors, the largest allowable LBA + 1, on the drive into the <tt>LBA_t</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function to determine the size of volume/partition to be created. It is required when <tt>FF_USE_MKFS == 1</tt>.</td></tr> | ||||
| <tr><td>GET_SECTOR_SIZE</td><td>Retrieves sector size used for read/write function into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. Valid sector sizes are 512, 1024, 2048 and 4096. This command is required only if <tt>FF_MAX_SS > FF_MIN_SS</tt>. When <tt>FF_MAX_SS == FF_MIN_SS</tt>, this command will be never used and the read/write function must work in <tt>FF_MAX_SS</tt> bytes/sector only.</td></tr> | ||||
| <tr><td>GET_BLOCK_SIZE</td><td>Retrieves erase block size of the flash memory media in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or non flash memory media. This command is used by only <tt>f_mkfs</tt> function and it attempts to align data area on the erase block boundary. It is required when <tt>FF_USE_MKFS == 1</tt>.</td></tr> | ||||
| <tr><td>CTRL_TRIM</td><td>Informs the device the data on the block of sectors is no longer needed and it can be erased. The sector block is specified in an <tt>LBA_t</tt> array {<Start LBA>, <End LBA>} pointed by <tt class="arg">buff</tt>. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the <tt>f_mkfs</tt> function. It is required when <tt>FF_USE_TRIM == 1</tt>.</td></tr> | ||||
| </table> | ||||
| 
 | ||||
| <p>FatFs never uses any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.</p> | ||||
| <table class="lst"> | ||||
| <caption>Example of optional ioctl command</caption> | ||||
| <tr><th>Command</th><th>Description</th></tr> | ||||
| <tr><td>CTRL_FORMAT</td><td>Create a physical format on the media. If <tt class="arg">buff</tt> is not null, it is pointer to the call-back function for progress notification.</td></tr> | ||||
| <tr><td>CTRL_POWER_IDLE</td><td>Put the device idle state. <tt>STA_NOINIT</tt> in the current status flags may not be set if the device goes active state by generic read/write function.</td></tr> | ||||
| <tr><td>CTRL_POWER_OFF</td><td>Put the device off state. Shut-down the power to the device and deinitialize the device interface if needed. <tt>STA_NOINIT</tt> in the current status flags must be set. The device goes active state by <tt>disk_initialize</tt> function.</td></tr> | ||||
| <tr><td>CTRL_LOCK</td><td>Lock media eject mechanism.</td></tr> | ||||
| <tr><td>CTRL_UNLOCK</td><td>Unlock media eject mechanism.</td></tr> | ||||
| <tr><td>CTRL_EJECT</td><td>Eject media cartridge. <tt>STA_NOINIT</tt> and <tt>STA_NODISK</tt> in status flag are set after the function succeeded.</td></tr> | ||||
| <tr><td>CTRL_GET_SMART</td><td>Read SMART information.</td></tr> | ||||
| <tr><td>MMC_GET_TYPE</td><td>Get card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_CSD</td><td>Read CSD register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_CID</td><td>Read CID register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_OCR</td><td>Read OCR register into a 4-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_SDSTAT</td><td>Read SDSTATUS register into a 64-byte buffer pointed by <tt class="arg">buff</tt>. (SDC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_REV</td><td>Get the revision string into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_MODEL</td><td>Get the model string into a 40-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_SN</td><td>Get the serial number string into a 20-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ISDIO_READ</td><td>Read a block of iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| <tr><td>ISDIO_WRITE</td><td>Write a block of data to iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| <tr><td>ISDIO_MRITE</td><td>Change bits in an iSDIO register specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| <tr><td>CTRL_FORMAT</td><td>Creates a physical format on the media. If <tt class="arg">buff</tt> is not null, it is pointer to the call-back function for progress notification.</td></tr> | ||||
| <tr><td>CTRL_POWER_IDLE</td><td>Puts the device idle state. <tt>STA_NOINIT</tt> in the current status flags may not be set if the device goes active state by generic read/write function.</td></tr> | ||||
| <tr><td>CTRL_POWER_OFF</td><td>Puts the device off state. Shut-down the power to the device and deinitialize the device interface if needed. <tt>STA_NOINIT</tt> in the current status flags must be set. The device goes active state by <tt>disk_initialize</tt> function.</td></tr> | ||||
| <tr><td>CTRL_LOCK</td><td>Locks media eject mechanism.</td></tr> | ||||
| <tr><td>CTRL_UNLOCK</td><td>Unlocks media eject mechanism.</td></tr> | ||||
| <tr><td>CTRL_EJECT</td><td>Ejects media cartridge. <tt>STA_NOINIT</tt> and <tt>STA_NODISK</tt> in status flag are set after the function succeeded.</td></tr> | ||||
| <tr><td>CTRL_GET_SMART</td><td>Reads SMART information.</td></tr> | ||||
| <tr><td>MMC_GET_TYPE</td><td>Gets card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_CSD</td><td>Reads CSD register and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_CID</td><td>Reads CID register and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_OCR</td><td>Reads OCR register and sets it into a 4-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr> | ||||
| <tr><td>MMC_GET_SDSTAT</td><td>Reads SDSTATUS register and sets it into a 64-byte buffer pointed by <tt class="arg">buff</tt>. (SDC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_REV</td><td>Gets the revision string and sets it into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_MODEL</td><td>Gets the model string and sets it into a 40-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ATA_GET_SN</td><td>Gets the serial number string and sets it into a 20-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr> | ||||
| <tr><td>ISDIO_READ</td><td>Reads a block of iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| <tr><td>ISDIO_WRITE</td><td>Writes a block of data to iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| <tr><td>ISDIO_MRITE</td><td>Changes bits in an iSDIO register specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr> | ||||
| </table> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -18,7 +18,7 @@ | ||||
| DRESULT disk_read ( | ||||
|   BYTE <span class="arg">pdrv</span>,     <span class="c">/* [IN] Physical drive number */</span> | ||||
|   BYTE* <span class="arg">buff</span>,    <span class="c">/* [OUT] Pointer to the read data buffer */</span> | ||||
|   DWORD <span class="arg">sector</span>,  <span class="c">/* [IN] Start sector number */</span> | ||||
|   LBA_t <span class="arg">sector</span>,  <span class="c">/* [IN] Start sector number */</span> | ||||
|   UINT <span class="arg">count</span>     <span class="c">/* [IN] Number of sectros to read */</span> | ||||
| ); | ||||
| </pre> | ||||
| @ -32,7 +32,7 @@ DRESULT disk_read ( | ||||
| <dt>buff</dt> | ||||
| <dd>Pointer to the first item of the <em>byte array</em> to store read data. Size of read data will be the sector size * <tt class="arg">count</tt> bytes.</dd> | ||||
| <dt>sector</dt> | ||||
| <dd>Start sector number in 32-bit LBA.</dd> | ||||
| <dd>Start sector number in 32-bit or 64-bit LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd> | ||||
| <dt>count</dt> | ||||
| <dd>Number of sectors to read.</dd> | ||||
| </dl> | ||||
| @ -56,13 +56,14 @@ DRESULT disk_read ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the read/write function must work at that sector size. When FatFs is configured for variable sector size (<tt>FF_MIN_SS < FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function immediately following <tt>disk_initialize</tt> function succeeded.</p> | ||||
| <p>The memory address specified by <tt class="arg">buff</tt> is not that always aligned to word boundary because the argument is defined as <tt>BYTE*</tt>. The unaligned read/write request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.</p> | ||||
| <p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the generic read/write function must work at the sector size only. When FatFs is configured for variable sector size (<tt>FF_MIN_SS < FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function after <tt>disk_initialize</tt> function succeeded.</p> | ||||
| <p>There are some considerations about the memory addres passed via <tt class="arg">buff</tt>. It is not that always aligned with the word boundary because the argument is defined as <tt>BYTE*</tt>. The unaligned transfer request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. If it is the case, there are some workarounds described below to avoid this issue.</p> | ||||
| <ul> | ||||
| <li>Convert word transfer to byte transfer in this function if needed. - Recommended.</li> | ||||
| <li>Convert word transfer to byte transfer with some trick in this function. - Recommended.</li> | ||||
| <li>On the <tt>f_read()</tt> calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.</li> | ||||
| <li>On the <tt>f_read(fp, dat, btw, bw)</tt> calls, make sure that <tt>(((UINT)dat & 3) == (f_tell(fp) & 3))</tt> is true. - Word alignment of <tt class="arg">buff</tt> is guaranteed.</li> | ||||
| </ul> | ||||
| <p>Also the memory area may be out of reach in DMA. This is the case if it is located on the tightly coupled memory which is usually used for stack. Use double buffered transfer, or avoid to define file I/O buffer, FATFS and FIL structure as local variables where on the stack.</p> | ||||
| <p>Generally, a multiple sector read request must not be split into single sector transactions to the storage device, or read throughput gets worse.</p> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -18,7 +18,7 @@ | ||||
| DRESULT disk_write ( | ||||
|   BYTE <span class="arg">pdrv</span>,        <span class="c">/* [IN] Physical drive number */</span> | ||||
|   const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span> | ||||
|   DWORD <span class="arg">sector</span>,     <span class="c">/* [IN] Sector number to write from */</span> | ||||
|   LBA_t <span class="arg">sector</span>,     <span class="c">/* [IN] Sector number to write from */</span> | ||||
|   UINT <span class="arg">count</span>        <span class="c">/* [IN] Number of sectors to write */</span> | ||||
| ); | ||||
| </pre> | ||||
| @ -32,7 +32,7 @@ DRESULT disk_write ( | ||||
| <dt>buff</dt> | ||||
| <dd>Pointer to the first item of the <em>byte array</em> to be written. The size of data to be written is sector size * <tt class="arg">count</tt> bytes.</dd> | ||||
| <dt>sector</dt> | ||||
| <dd>Start sector number in 32-bit LBA.</dd> | ||||
| <dd>Start sector number in 32-bit or 64-bit LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd> | ||||
| <dt>count</dt> | ||||
| <dd>Number of sectors to write.</dd> | ||||
| </dl> | ||||
|  | ||||
| @ -19,7 +19,7 @@ | ||||
| FRESULT f_expand ( | ||||
|   FIL*    <span class="arg">fp</span>,  <span class="c">/* [IN] File object */</span> | ||||
|   FSIZE_t <span class="arg">fsz</span>, <span class="c">/* [IN] File size expanded to */</span> | ||||
|   BYTE    <span class="arg">opt</span>  <span class="c">/* [IN] Operation mode */</span> | ||||
|   BYTE    <span class="arg">opt</span>  <span class="c">/* [IN] Allocation mode */</span> | ||||
| ); | ||||
| </pre> | ||||
| </div> | ||||
| @ -32,7 +32,7 @@ FRESULT f_expand ( | ||||
| <dt>fsz</dt> | ||||
| <dd>Number of bytes in size to prepare or allocate for the file. The data type <tt>FSIZE_t</tt> is an alias of either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>.</dd> | ||||
| <dt>opt</dt> | ||||
| <dd>Operation mode. Prepare only (0) or Allocate now (1).</dd> | ||||
| <dd>Allocation mode. Prepare to allocate (0) or Allocate now (1).</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -52,16 +52,16 @@ FRESULT f_expand ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_expand</tt> function prepares or allocates a contiguous data area to the file. When <tt class="arg">opt</tt> is 1, the function allocates a contiguous data area to the file. Unlike expansion of file by <tt>f_lseek</tt> function, the file must be truncated prior to use this function and read/write pointer of the file stays at top of the file after the function. The file content allocated with this function is <em>undefined</em> because no data is written to the file in this process. The function can fail with <tt>FR_DENIED</tt> due to some reasons below.</p> | ||||
| <p>The <tt>f_expand</tt> function prepares or allocates a contiguous data area to the file. When <tt class="arg">opt</tt> is 1, the function allocates a contiguous data area to the file. Unlike expansion of file size by <tt>f_lseek</tt> function, the file must be truncated prior to use this function and read/write pointer of the file stays at offset 0 after the function call. The file content allocated with this function is <em>undefined</em> because no data is written to the file in this process. The function can fail with <tt>FR_DENIED</tt> due to some reasons below.</p> | ||||
| <ul> | ||||
| <li>No free contiguous space was found.</li> | ||||
| <li>Size of the file was not zero.</li> | ||||
| <li>The file has been opened in read-only mode.</li> | ||||
| <li>Not allowable file size. (>= 4 GB on FAT volume)</li> | ||||
| </ul> | ||||
| <p>When <tt class="arg">opt</tt> is 0, the function finds a contiguous data area and set it as suggested point for next allocation instead of allocating it to the file. The next cluster allocation is started at top of the contiguous area found by this function. Thus the write file is guaranteed be contiguous and no allocation delay until the size reaches that size at least unless any other changes to the volume is performed.</p> | ||||
| <p>The contiguous file would have an advantage at time-critical read/write operations. It eliminates some overheads in the filesystem and the storage media caused by random access due to fragmented file data. Especially FAT access for the contiguous file on the exFAT volume is completely eliminated and storage media will be accessed sequentially.</p> | ||||
| <p>Also the contiguous file can be easily accessed directly via low-level disk functions. But this is not recommended in consideration for future compatibility. Use <a href="../res/app5.c">this function</a> to examine if the file is contiguous or not.</p> | ||||
| <p>When <tt class="arg">opt</tt> is 0, the function finds a contiguous data area and set it as suggested point for next allocation. The subsequent cluster allocation begins at top of the contiguous area found by this function. Thus the file allocation is guaranteed be contiguous and without allocation delay until the file size reaches that size unless any other changes to the volume is performed.</p> | ||||
| <p>The contiguous file has an advantage for time-critical read/write operations. It eliminates some overheads in the filesystem and the storage device caused by random access for fragmented file.</p> | ||||
| <p>Also the contiguous file can be easily accessed directly via low-level disk functions. But this is not recommended in consideration for portability and future compatibility. If the file has not been confirmed be contiguous, use <a href="../res/app5.c">this function</a> to examine if the file is contiguous or not.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para comp"> | ||||
|  | ||||
| @ -16,9 +16,9 @@ | ||||
| <p>The f_fdisk fucntion divides a physical drive.</p> | ||||
| <pre> | ||||
| FRESULT f_fdisk ( | ||||
|   BYTE  <span class="arg">pdrv</span>,        <span class="c">/* [IN] Physical drive number */</span> | ||||
|   const DWORD* <span class="arg">szt</span>,  <span class="c">/* [IN] Partition map table */</span> | ||||
|   void* <span class="arg">work</span>         <span class="c">/* [IN] Work area */</span> | ||||
|   BYTE  <span class="arg">pdrv</span>,         <span class="c">/* [IN] Physical drive number */</span> | ||||
|   const LBA_t <span class="arg">ptbl[]</span>, <span class="c">/* [IN] Partition map table */</span> | ||||
|   void* <span class="arg">work</span>          <span class="c">/* [IN] Work area */</span> | ||||
| ); | ||||
| </pre> | ||||
| </div> | ||||
| @ -28,10 +28,10 @@ FRESULT f_fdisk ( | ||||
| <dl class="par"> | ||||
| <dt>pdrv</dt> | ||||
| <dd>Specifies the <em>physical drive</em> to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.</dd> | ||||
| <dt>szt</dt> | ||||
| <dd>Pointer to the first item of the partition map table.</dd> | ||||
| <dt>ptbl</dt> | ||||
| <dd>List of partition size to create on the drive. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>.</dd> | ||||
| <dt>work</dt> | ||||
| <dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given, the function allocates a memory block for the working buffer (at only <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>).</dd> | ||||
| <dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> = 3</tt>, a memory block is obtained in this function for the working buffer.</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -49,7 +49,8 @@ FRESULT f_fdisk ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format is in generic FDISK format, so that it can create upto four primary partitions. Logical volumes in the extended partition is not supported. The partition map table with four items specifies how to divide the physical drive. The first item specifies the size of first primary partition and fourth item specifies the fourth primary partition. If the value is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. If it is larger than 100, it specifies the partition size in unit of sector. The partitions are located on the drive in order of from first item.</p> | ||||
| <p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is clipped at the size of remaining space.</p> | ||||
| <p>By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (<tt>FF_LBA64 = 1</tt>) and the drive size is equal to or larger than <tt><a href="config.html#fs_gptmin">FF_MIN_GPT</a></tt> sectors. It can create over ten partitions on a drive.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para comp"> | ||||
| @ -60,9 +61,9 @@ FRESULT f_fdisk ( | ||||
| <div class="para use"> | ||||
| <h4>Example</h4> | ||||
| <pre> | ||||
|     <span class="c">/* Volume management table defined by user (required when FF_MULTI_PARTITION == 1) */</span> | ||||
|     <span class="c">/* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */</span> | ||||
| 
 | ||||
|     PARTITION VolToPart[] = { | ||||
|     PARTITION VolToPart[FF_VOLUMES] = { | ||||
|         {0, 1},    <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span> | ||||
|         {0, 2},    <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span> | ||||
|         {1, 0}     <span class="c">/* "2:" ==> Physical drive 1, auto detection */</span> | ||||
| @ -71,13 +72,15 @@ FRESULT f_fdisk ( | ||||
| <pre> | ||||
|     <span class="c">/* Initialize a brand-new disk drive mapped to physical drive 0 */</span> | ||||
| 
 | ||||
|     DWORD plist[] = {50, 50, 0, 0};  <span class="c">/* Divide drive into two partitions */</span> | ||||
|     BYTE work[FF_MAX_SS]; | ||||
|     BYTE work[FF_MAX_SS];         <span class="c">/* Working buffer */</span> | ||||
|     LBA_t plist[] = {50, 50, 0};  <span class="c">/* Divide the drive into two partitions */</span> | ||||
|                  <span class="c">/* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */</span> | ||||
|                  <span class="c">/* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */</span> | ||||
| 
 | ||||
|     <em>f_fdisk</em>(0, plist, work);                    <span class="c">/* Divide physical drive 0 */</span> | ||||
| 
 | ||||
|     f_mkfs("0:", FM_ANY, work, sizeof work);    <span class="c">/* Create FAT volume on the logical drive 0 */</span> | ||||
|     f_mkfs("1:", FM_ANY, work, sizeof work);    <span class="c">/* Create FAT volume on the logical drive 1 */</span> | ||||
|     f_mkfs("0:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span> | ||||
|     f_mkfs("1:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span> | ||||
| 
 | ||||
| </pre> | ||||
| </div> | ||||
|  | ||||
| @ -10,14 +10,14 @@ | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
| <h1>Path Names on the FatFs</h1> | ||||
| <h1>Path Names on the FatFs API</h1> | ||||
| 
 | ||||
| <div class="para doc" id="nam"> | ||||
| <h3>Format of the Path Names</h3> | ||||
| <p>The format of path name on the FatFs module is similer to the filename specs of DOS/Windos as follows:</p> | ||||
| <pre>[<em>drive#</em>:][/]<em>directory</em>/<em>file</em></pre> | ||||
| <p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when <tt><a href="config.html#use_lfn">FF_USE_LFN</a> >= 1</tt>. The sub directories are separated with a <tt>\</tt> or <tt>/</tt> in the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the heading drive prefix to specify logical drive is in a numeral + colon. When drive prefix is omitted, the drive number is assumed as <em>default drive</em> (drive 0 or current drive).</p> | ||||
| <p>Control characters (<tt>\0</tt> to <tt>\x1F</tt>) are recognized as end of the path name. Leading/embedded white spaces in the path name are valid as a part of the name at LFN configuration but the white space is recognized as end of the path name at non-LFN configuration. Trailing white spaces and dots are ignored at both configurations.</p> | ||||
| <p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when <tt><a href="config.html#use_lfn">FF_USE_LFN</a> >= 1</tt>. The sub-directories are separated with a <tt>\</tt> or <tt>/</tt> as the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the heading drive prefix to specify the logical drive number is in a numeral (0-9) + a colon, while it is an alphabet (A-Z) + a colon in DOS/Windows. The logical drive number is identifier to specify the FAT volume to be accessed. When drive prefix is omitted, the logical drive number is assumed as <em>default drive</em>.</p> | ||||
| <p>Control characters (<tt>\0</tt> to <tt>\x1F</tt>) are recognized as end of the path name. Leading/embedded white spaces in the path name are valid as a part of the name in LFN configuration but the white space is recognized as end of the path name in non-LFN configuration. Trailing white spaces and dots are ignored in both configurations.</p> | ||||
| <p>In default configuration (<tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> == 0</tt>), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name that followed from the root directory. Dot directory names (<tt>".", ".."</tt>) are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.</p> | ||||
| <p>When relative path is enabled (<tt>FF_FS_RPATH >= 1</tt>), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the drive set by <a href="chdir.html"><tt>f_chdir</tt></a> function. Dot names are also allowed for the path names. The default drive is the current drive set by <a href="chdrive.html"><tt>f_chdrive</tt></a> function.</p> | ||||
| <table class="lst2"> | ||||
| @ -42,44 +42,47 @@ | ||||
| 
 | ||||
| <div class="para doc" id="case"> | ||||
| <h3>Legal Characters and Case Sensitivity</h3> | ||||
| <p>On the FAT filesystem, legal characters for object name (file/directory name) are, <tt>0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~</tt> and any extended character. The valid character codes of extended characters are depends on the configured code page. Under LFN supported system, also <tt>+ , ; = [ ]</tt> and white space are legal for the object name and the white spaces and dots can be placed anywhere in the path name except for end of the name.</p> | ||||
| <p>On the FAT filesystem, legal characters for object name (file/directory name) are, <tt>0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~</tt> and any extended character. The valid character codes of extended characters are depends on the configured code page. Under LFN supported system, also <tt>+ , ; = [ ]</tt> and white space are legal for the object name and the white spaces and dots can be placed anywhere in the path name except end of the name.</p> | ||||
| <p>FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, <tt>file.txt</tt>, <tt>File.Txt</tt> and <tt>FILE.TXT</tt>, are identical. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN function is enabled.</p> | ||||
| <p>As for the MS-DOS and PC DOS for CJK (DOS/DBCS), extended characters are recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on compatibility with Windows system when any object with extended characters is created on the volume by DOS/DBCS system; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems. FatFs works with case-sensitive to the extended characters at only non-LFN with DBCS configuration (DOS/DBCS specs). But at LFN configuration, FatFs works with case-insensitive to the extended character (WindowsNT specs).</p> | ||||
| <p>As for the MS-DOS and PC DOS for CJK (DOS/DBCS), extended characters ware recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on compatibility with Windows system when any object with extended characters is created on the volume by DOS/DBCS system; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems. FatFs works with case-sensitive to the extended characters in only non-LFN with DBCS configuration (DOS/DBCS specs). But in LFN configuration, FatFs works with case-insensitive to the extended character (WindowsNT specs).</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="uni"> | ||||
| <h3>Unicode API</h3> | ||||
| <p>The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> by default and the code set used for the path name string is ANSI/OEM specifid by <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>. When <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt> is set to 1 or larger, the type of the <tt>TCHAR</tt> is switched to proper type to support the Unicode string. When Unicode API is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.</p> | ||||
| <p>The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> by default and the code set used for the path name string is ANSI/OEM specifid by <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>. When <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt> is set to 1 or larger, the type of the <tt>TCHAR</tt> is switched to proper type to support the Unicode string. When Unicode API is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to specify the string in proper type. The code shown below is an example to define the literal strings.</p> | ||||
| <pre> | ||||
|  f_open(fp, "filename.txt", FA_READ);      <span class="c">/* ANSI/OEM string (char) */</span> | ||||
|  f_open(fp, L"filename.txt", FA_READ);     <span class="c">/* UTF-16 string (WCHAR) */</span> | ||||
|  f_open(fp, u8"filename.txt", FA_READ);    <span class="c">/* UTF-8 string (char) */</span> | ||||
|  f_open(fp, U"filename.txt", FA_READ);     <span class="c">/* UTF-32 string (DWORD) */</span> | ||||
|  f_open(fp, _T("filename.txt"), FA_READ);  <span class="c">/* Changed by configuration (TCHAR) */</span> | ||||
|  f_open(fp, <span class="e">"filename.txt"</span>, FA_READ);      <span class="c">/* ANSI/OEM string (char) */</span> | ||||
|  f_open(fp, <span class="e">L"filename.txt"</span>, FA_READ);     <span class="c">/* UTF-16 string (WCHAR) */</span> | ||||
|  f_open(fp, <span class="e">u8"filename.txt"</span>, FA_READ);    <span class="c">/* UTF-8 string (char) */</span> | ||||
|  f_open(fp, <span class="e">U"filename.txt"</span>, FA_READ);     <span class="c">/* UTF-32 string (DWORD) */</span> | ||||
|  f_open(fp, <span class="e">_T("filename.txt")</span>, FA_READ);  <span class="c">/* Changed by configuration (TCHAR) */</span> | ||||
| </pre> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para doc" id="vol"> | ||||
| <h3>Volume Management</h3> | ||||
| <p>FatFs module requires dynamic work area, <em>filesystem object</em>, for each volume (logical drive). It is registered/unregistered to the FatFs module by <tt>f_mount</tt> function. By default, each logical drive is bound to the physical drive with the same drive number and an FAT volume on the drive is serched by the volume mount process. It reads boot sectors and checks it if it is an FAT boot sector in order of sector 0 as SFD format, 1st partition, 2nd partition, 3rd partition and 4th partition as FDISK format.</p> | ||||
| <p>When <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION = 1</a></tt> is specified by configuration option, each individual logical drive is bound to the partition on the physical drive specified by volume management table. The volume management table needs to be defined by user to resolve the mappings of logical drives and partitions. Following code is an example of a volume management table.</p> | ||||
| <p>By default, each logical drive is associated with the physical drive in same drive number. An FAT volume on the physical drive is serched by the volume mount process. It reads boot sectors and checks it if it is an FAT boot sector in order of LBA 0 as SFD format, 1st partition, 2nd partition, 3rd partition, ..., as MBR or GPT format.</p> | ||||
| <p>When multiple partition feature is enabled, <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION = 1</a></tt>, each individual logical drive is associated with arbitrary partition or drive specified by volume management table, <tt>VolToPart[]</tt>. The table needs to be defined by user to resolve the mappings of logical drives and partitions. Following code is an example of a volume management table.</p> | ||||
| <pre> | ||||
| Example: "0:", "1:" and "2:" are tied to three pri-partitions on the physical drive 0 (fixed drive) | ||||
|          "3:" is tied to an FAT volume on the physical drive 1 (removable drive) | ||||
| Example: "0:", "1:" and "2:" are associated with three partitions on the physical drive 0 (fixed drive) | ||||
|          "3:" is associated with physical drive 1 (removable drive) | ||||
| 
 | ||||
| PARTITION VolToPart[FF_VOLUMES] = { | ||||
|     {0, 1},     <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span> | ||||
|     {0, 2},     <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span> | ||||
|     {0, 3},     <span class="c">/* "2:" ==> Physical drive 0, 3rd partition */</span> | ||||
|     {1, 0}      <span class="c">/* "3:" ==> Physical drive 1, auto detection */</span> | ||||
|     {0, 1},     <span class="c">/* "0:" ==> 1st partition on physical drive 0 */</span> | ||||
|     {0, 2},     <span class="c">/* "1:" ==> 2nd partition on physical drive 0 */</span> | ||||
|     {0, 3},     <span class="c">/* "2:" ==> 3rd partition on physical drive 0 */</span> | ||||
|     {1, 0}      <span class="c">/* "3:" ==> Physical drive 1 */</span> | ||||
| }; | ||||
| </pre> | ||||
| <div><img src="../res/f7.png" width="900" height="288" alt="relationship between logical drive and physical drive"></div> | ||||
| <p>There are some considerations on using multi-partition configuration.</p> | ||||
| <ul> | ||||
| <li>The physical drive that has two or more mounted partitions must be non-removable. Media change while a system operation is prohibited.</li> | ||||
| <li>Only four primary partitions can be specified. Extended partition is not supported.</li> | ||||
| <li>Windows does not support multiple volumes on the removable storage. Only first parition will be recognized.</li> | ||||
| <li>The physical drive that hosts two or more mounted partitions must be non-removable, or all volumes on the drive must be unmounted when remove the medium.</li> | ||||
| <li>When make any change to the <tt>VolToPart[]</tt>, corresponding volume should be unmounted prior to make change the item.</li> | ||||
| <li>On the MBR format drive, up to four primary partitions (1-4) can be specified. The partition 1 specifies the first item in the partition table and the partition 2 specifies the second one, and so on. Logical patitions in the extended partition is not supported.</li> | ||||
| <li>On the GPT format drive, there is no limitation. The partition 1 specifies the first Microsoft basic data partition found in the partition table and the partition 2 specifies the second one found, and so on.</li> | ||||
| <li>Windows does not support multiple volumes on the storage with removable class. Only the first parition found on the drive will be mounted.</li> | ||||
| <li>For further information, refer to <tt><a href="fdisk.html">f_fdisk</a></tt> and <tt><a href="mkfs.html">f_mkfs</a></tt>function.</li> | ||||
| </ul> | ||||
| </div> | ||||
| 
 | ||||
|  | ||||
| @ -61,12 +61,12 @@ FRESULT f_findfirst ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the name specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the object is stored into the file information structure <tt class="arg">fno</tt>.</p> | ||||
| <p>The matching pattern can contain wildcard characters (<tt>?</tt> and <tt>*</tt>). A <tt>?</tt> matches an any character and an <tt>*</tt> matches an any string in length of zero or longer. When support of long file name is enabled, only <tt>fname[]</tt> is tested at <tt>FF_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested at <tt>FF_USE_FIND == 2</tt>. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.</p> | ||||
| <p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the matching pattern specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the item is stored into the file information structure <tt class="arg">fno</tt>.</p> | ||||
| <p>The matching pattern can contain wildcard characters (<tt>?</tt> and <tt>*</tt>). For example, a <tt>?</tt> matches an any character, an <tt>*</tt> matches an any string in length of zero or longer and ???* matches an any string in length of 3 characters or longer. When LFN is enabled, only <tt>fname[]</tt> is tested when <tt>FF_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested when <tt>FF_USE_FIND == 2</tt>. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.</p> | ||||
| <ul> | ||||
| <li><tt>"*.*"</tt> never matches any name without extension while it matches any name with or without extension at the standard systems.</li> | ||||
| <li>Any pattern terminated with a period never matches any name while it matches any name without extensiton at the standard systems.</li> | ||||
| <li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN with ANSI/OEM API.</li> | ||||
| <li><tt>"*.*"</tt> never matches any name without extension while it matches any name with or without extension in standard systems.</li> | ||||
| <li>Any pattern terminated with a period never matches any name while it matches the name without extensiton in standard systems.</li> | ||||
| <li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive when LFN is enabled with ANSI/OEM API.</li> | ||||
| </ul> | ||||
| </div> | ||||
| 
 | ||||
| @ -85,13 +85,13 @@ FRESULT f_findfirst ( | ||||
| void find_image_file (void) | ||||
| { | ||||
|     FRESULT fr;     <span class="c">/* Return value */</span> | ||||
|     DIR dj;         <span class="c">/* Directory search object */</span> | ||||
|     DIR dj;         <span class="c">/* Directory object */</span> | ||||
|     FILINFO fno;    <span class="c">/* File information */</span> | ||||
| 
 | ||||
|     fr = <em>f_findfirst</em>(&dj, &fno, "", "dsc*.jpg");  <span class="c">/* Start to search for photo files */</span> | ||||
| 
 | ||||
|     while (fr == FR_OK && fno.fname[0]) {         <span class="c">/* Repeat while an item is found */</span> | ||||
|         printf("%s\n", fno.fname);                <span class="c">/* Display the object name */</span> | ||||
|         printf("%s\n", fno.fname);                <span class="c">/* Print the object name */</span> | ||||
|         fr = f_findnext(&dj, &fno);               <span class="c">/* Search for next item */</span> | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -53,7 +53,7 @@ FRESULT f_getfree ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Descriptions</h4> | ||||
| <p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. When FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p> | ||||
| <p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. In case of FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -49,13 +49,13 @@ FRESULT f_lseek ( | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file.</p> | ||||
| <p>When an offset beyond the file size is specified at write mode, the file size is expanded to the specified offset. The file data in the expanded area is <em>undefined</em> because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.</p> | ||||
| <p>When an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset. The file data in the expanded part is <em>undefined</em> because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.</p> | ||||
| <ul> | ||||
| <li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file has been opened in read-only mode.</li> | ||||
| <li>Disk full. There is no free space on the volume to expand the file.</li> | ||||
| </ul> | ||||
| <p>The fast seek function enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p> | ||||
| <p>The fast seek mode is enabled when the member <tt>cltbl</tt> in the file object is not NULL. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek function. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the first item and call the <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, when the file is fragmented in 5, 12 items in the array will be used. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file.</p> | ||||
| <p>The fast seek feature enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p> | ||||
| <p>The fast seek mode is enabled when <tt>FF_USE_FASTSEEK = 1</tt>. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek mode. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the first item and call <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, 12 items in the array will be used for the file fragmented in 5 portions. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the size of given array is insufficient for the file.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| @ -103,7 +103,7 @@ FRESULT f_lseek ( | ||||
|     res = f_close(fp); | ||||
| </pre> | ||||
| <pre> | ||||
| <span class="c">/* Using fast seek function */</span> | ||||
| <span class="c">/* Using fast seek mode */</span> | ||||
| 
 | ||||
|     DWORD clmt[SZ_TBL];                    <span class="c">/* Cluster link map table buffer */</span> | ||||
| 
 | ||||
| @ -111,7 +111,7 @@ FRESULT f_lseek ( | ||||
| 
 | ||||
|     res = <em>f_lseek</em>(fp, ofs1);               <span class="c">/* This is normal seek (cltbl is nulled on file open) */</span> | ||||
| 
 | ||||
|     fp->cltbl = clmt;                      <span class="c">/* Enable fast seek function (cltbl != NULL) */</span> | ||||
|     fp->cltbl = clmt;                      <span class="c">/* Enable fast seek mode (cltbl != NULL) */</span> | ||||
|     clmt[0] = SZ_TBL;                      <span class="c">/* Set table size */</span> | ||||
|     res = <em>f_lseek</em>(fp, CREATE_LINKMAP);     <span class="c">/* Create CLMT */</span> | ||||
|     ... | ||||
|  | ||||
| @ -13,14 +13,13 @@ | ||||
| 
 | ||||
| <div class="para func"> | ||||
| <h2>f_mkfs</h2> | ||||
| <p>The f_mkfs fucntion creates an FAT/exFAT volume on the logical drive.</p> | ||||
| <p>The f_mkfs function creates an FAT/exFAT volume on the logical drive.</p> | ||||
| <pre> | ||||
| FRESULT f_mkfs ( | ||||
|   const TCHAR* <span class="arg">path</span>,  <span class="c">/* [IN] Logical drive number */</span> | ||||
|   BYTE  <span class="arg">opt</span>,          <span class="c">/* [IN] Format options */</span> | ||||
|   DWORD <span class="arg">au</span>,           <span class="c">/* [IN] Size of the allocation unit */</span> | ||||
|   void* <span class="arg">work</span>,         <span class="c">/* [-]  Working buffer */</span> | ||||
|   UINT <span class="arg">len</span>            <span class="c">/* [IN] Size of working buffer */</span> | ||||
|   const TCHAR*  <span class="arg">path</span>,  <span class="c">/* [IN] Logical drive number */</span> | ||||
|   const MKFS_PARM* <span class="arg">opt</span>,<span class="c">/* [IN] Format options */</span> | ||||
|   void*  <span class="arg">work</span>,         <span class="c">/* [-]  Working buffer */</span> | ||||
|   UINT  <span class="arg">len</span>            <span class="c">/* [IN] Size of working buffer */</span> | ||||
| ); | ||||
| </pre> | ||||
| </div> | ||||
| @ -29,15 +28,25 @@ FRESULT f_mkfs ( | ||||
| <h4>Parameters</h4> | ||||
| <dl class="par"> | ||||
| <dt>path</dt> | ||||
| <dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it has no drive number in it, it means the default drive. The logical drive may or may not be mounted for the format process.</dd> | ||||
| <dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it does not have a drive number in it, it means to specify the default drive. The logical drive may or may not have been mounted for the format process.</dd> | ||||
| <dt>opt</dt> | ||||
| <dd>Specifies the format option in combination of <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format.</dd> | ||||
| <dt>au</dt> | ||||
| <dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is <em>n</em> times the sector size. The <em>n</em> is power of 2 from 1 to 128 for FAT volume and upto 16MiB for exFAT volume. If zero is given, the default allocation unit size is selected depends on the volume size.</dd> | ||||
| <dd>Specifies the structure that is holding format options. If a null pointer is given, it gives the function all options in default value. The format option structure has five members described below:<br> | ||||
| <dl class="par"> | ||||
| <dt>BYTE fmt</dt> | ||||
| <dd>Specifies combination of FAT type flags, <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au_size</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format. The default value is <tt>FM_ANY</tt>.</dd> | ||||
| <dt>DWORD au_size</dt> | ||||
| <dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is power of 2 between sector size and 128 * sector size inclusive for FAT/FAT32 volume and up to 16 MB for exFAT volume. If a zero (the default value) or any invalid value is given, the default allocation unit size depends on the volume size is used.</dd> | ||||
| <dt>UINT n_align</dt> | ||||
| <dd>Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash media) in unit of sector. The valid value for this member is between 1 and 32768 inclusive in power of 2. If a zero (the default value) or any invalid value is given, the function obtains the block size from lower layer with <tt>disk_ioctl</tt> function.</dd> | ||||
| <dt>BYTE n_fat</dt> | ||||
| <dd>Specifies number of FAT copies on the FAT/FAT32 volume. Valid value for this member is 1 or 2. The default value (0) and any invaid value gives 1. If the FAT type is exFAT, this member has no effect.</dd> | ||||
| <dt>UINT n_root</dt> | ||||
| <dd>Specifies number of root directory entries on the FAT volume. Valid value for this member is up to 32768 and aligned to sector size / 32. The default value (0) and any invaid value gives 512. If the FAT type is FAT32 or exFAT, this member has no effect.</dd> | ||||
| </dl> | ||||
| <dt>work</dt> | ||||
| <dd>Pointer to the working buffer used for the format process. When a null pointer is given, the function allocates a memory block for the working buffer and <tt class="arg">len</tt> has no effect (at only <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>).</dd> | ||||
| <dd>Pointer to the working buffer used for the format process. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>, the function obtains a memory block in this function for the working buffer.</dd> | ||||
| <dt>len</dt> | ||||
| <dd>Size of the working buffer in unit of byte. It needs to be the sector size of the corresponding physical drive at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.</dd> | ||||
| <dd>Size of the working buffer in unit of byte. It needs to be <tt>FF_MAX_SS</tt> at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -57,11 +66,12 @@ FRESULT f_mkfs ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with <tt>FR_MKFS_ABORTED</tt>. The minimum drive size is 128 sectors with <tt>FM_SFD</tt> option.</p> | ||||
| <p>The allocation unit, also called <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases as the size of allocation unit. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.</p> | ||||
| <p>There are three disk partitioning formats, FDISK, SFD and GPT. The FDISK format is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table on the MBR (maser boot record, the first sector of the physical drive). The SFD (super-floppy disk) is non-partitioned disk format. The FAT volume starts at the first sector of the physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some systems support only either one of the two disk formats and the other is not supported. The GPT (GUID Partition Table) is a newly defined format for large storage devices. FatFs does not support the storages with GPT.</p> | ||||
| <p>When the logical drive to be formatted is bound to a physical drive and <tt>FM_SFD</tt> is not specified, a primary partition occupies whole drive space is created in FDISK format, and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> is specified, the FAT volume occupies from the first sector of the physical drive is created in SFD format.</p> | ||||
| <p>When the logical drive to be formatted is bound to a specific partition (1-4) by support of multiple partition (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 1</tt>), the FAT volume is created on the partition and <tt>FM_SFD</tt> flag is ignored. The physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any other partitioning tools prior to create the FAT volume with this function.</p> | ||||
| <p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with <tt>FR_MKFS_ABORTED</tt>.</p> | ||||
| <p>The allocation unit, also knows as <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.</p> | ||||
| <p>When the logical drive to be formatted is associated with a physical drive (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> = 0</tt>) and <tt>FM_SFD</tt> flag is not specified, a partition occupies entire disk space is created and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> flag is specified, the FAT volume is created without any disk partitioning.</p> | ||||
| <p>When the logical drive to be formatted is associated with a specific partition by multiple partition feature (<tt>FF_MULTI_PARTITION = 1</tt>), the FAT volume is created on the partition specified by the <a href="filename.html#vol">volume mapping table</a> and <tt>FM_SFD</tt> flag is ignored. The physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any partitioning tool prior to create the FAT volume with this function.</p> | ||||
| <p>There are three standard disk partitioning formats, MBR, GPT and SFD. The MBR format (aka FDISK format) is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table. The GPT (GUID Partition Table) is a newly defined patitioning format for large storage devices. FatFs suppors the GPT only when 64-bit LBA is enabled. SFD (super-floppy disk) is non-partitioned disk format. The FAT volume occupies the entire physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some combination of systems and media support only either partitioned format or non-partitioned format and the other is not supported.</p> | ||||
| <p>Some systems manage the partitions on the internal storage in non-standard format. The partitions are mapped as physical drives identified in disk_* functions. For such systems, SFD format is suitable to create the FAT volume on the partition.</p> | ||||
| </div> | ||||
| 
 | ||||
| <div class="para comp"> | ||||
| @ -82,11 +92,11 @@ int main (void) | ||||
|     BYTE work[FF_MAX_SS]; <span class="c">/* Work area (larger is better for processing time) */</span> | ||||
| 
 | ||||
| 
 | ||||
|     <span class="c">/* Create FAT volume */</span> | ||||
|     res = <em>f_mkfs</em>("", FM_ANY, 0, work, sizeof work); | ||||
|     <span class="c">/* Format the default drive with default parameters */</span> | ||||
|     res = <em>f_mkfs</em>("", 0, work, sizeof work); | ||||
|     if (res) ... | ||||
| 
 | ||||
|     <span class="c">/* Register work area */</span> | ||||
|     <span class="c">/* Gives a work area to the default drive */</span> | ||||
|     f_mount(&fs, "", 0); | ||||
| 
 | ||||
|     <span class="c">/* Create a file as new */</span> | ||||
| @ -109,7 +119,7 @@ int main (void) | ||||
| 
 | ||||
| <div class="para ref"> | ||||
| <h4>See Also</h4> | ||||
| <p><a href="../res/mkfs.xls">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p> | ||||
| <p><a href="../res/mkfs.xlsx">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p> | ||||
| </div> | ||||
| 
 | ||||
| <p class="foot"><a href="../00index_e.html">Return</a></p> | ||||
|  | ||||
| @ -13,7 +13,7 @@ | ||||
| 
 | ||||
| <div class="para func"> | ||||
| <h2>f_mount</h2> | ||||
| <p>The f_mount fucntion registers/unregisters filesystem object to the FatFs module.</p> | ||||
| <p>The f_mount fucntion gives work area to the FatFs module.</p> | ||||
| <pre> | ||||
| FRESULT f_mount ( | ||||
|   FATFS*       <span class="arg">fs</span>,    <span class="c">/* [IN] Filesystem object */</span> | ||||
| @ -50,7 +50,7 @@ FRESULT f_mount ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>FatFs requires work area (<em>filesystem object</em>) for each logical drives (FAT volumes). Prior to perform file/directory operations, a filesystem object needs to be registered with <tt>f_mount</tt> function to the logical drive. The file/directory API functions get ready to work after this procedure. If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.</p> | ||||
| <p>FatFs requires work area (<em>filesystem object</em>) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with <tt>f_mount</tt> function for the logical drive. The file/directory API functions get ready to work after this procedure. Some volume management functions, <tt>f_mkfs</tt>, <tt>f_fdisk</tt> and <tt>f_setcp</tt>, do not want a filesystem object.</p> | ||||
| <p>The <tt>f_mount</tt> function registers/unregisters a filesystem object to the FatFs module as follows:</p> | ||||
| <ol> | ||||
| <li>Determines the logical drive which specified by <tt class="arg">path</tt>.</li> | ||||
| @ -58,6 +58,7 @@ FRESULT f_mount ( | ||||
| <li>Clears and registers the new work area to the volume if <tt class="arg">fs</tt> is not NULL.</li> | ||||
| <li>Performs volume mount process to the volume if forced mounting is specified.</li> | ||||
| </ol> | ||||
| <p>If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.<p> | ||||
| <p>If forced mounting is not specified (<tt>opt = 0</tt>), this function always succeeds regardless of the physical drive status. It only clears (de-initializes) the given work area and registers its address to the internal table and no activity of the physical drive in this function. The volume mount process will be attempted on subsequent file/directroy function if the filesystem object is not initialized. (delayed mounting) The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and then initialize the work area, is performed in the subsequent file/directory functions when either of following conditions is true.</p> | ||||
| <ul> | ||||
| <li>Filesystem object has not been initialized. It is de-initialized by <tt>f_mount</tt> function.</li> | ||||
|  | ||||
| @ -42,7 +42,7 @@ FRESULT f_open ( | ||||
| <tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file will be created.</td></tr> | ||||
| <tr><td>FA_OPEN_APPEND</td><td>Same as <tt>FA_OPEN_ALWAYS</tt> except the read/write pointer is set end of the file.</td></tr> | ||||
| </table> | ||||
| Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:<br> | ||||
| Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:<br> | ||||
| <table class="lst2"> | ||||
| <tr><th>POSIX</th><th>FatFs</th></tr> | ||||
| <tr><td>"r"</td><td>FA_READ</td></tr> | ||||
| @ -111,7 +111,7 @@ int main (void) | ||||
|     FRESULT fr;     <span class="c">/* FatFs return code */</span> | ||||
| 
 | ||||
| 
 | ||||
|     <span class="c">/* Register work area to the default drive */</span> | ||||
|     <span class="c">/* Gives a work area to the default drive */</span> | ||||
|     f_mount(&FatFs, "", 0); | ||||
| 
 | ||||
|     <span class="c">/* Open a text file */</span> | ||||
| @ -141,7 +141,7 @@ int main (void) | ||||
|     UINT br, bw;         <span class="c">/* File read/write count */</span> | ||||
| 
 | ||||
| 
 | ||||
|     <span class="c">/* Register work area for each logical drive */</span> | ||||
|     <span class="c">/* Gives work area to each logical drive */</span> | ||||
|     f_mount(&fs0, "0:", 0); | ||||
|     f_mount(&fs1, "1:", 0); | ||||
| 
 | ||||
| @ -155,10 +155,10 @@ int main (void) | ||||
| 
 | ||||
|     <span class="c">/* Copy source to destination */</span> | ||||
|     for (;;) { | ||||
|         fr = f_read(&fsrc, buffer, sizeof buffer, &br);  <span class="c">/* Read a chunk of source file */</span> | ||||
|         if (fr || br == 0) break; <span class="c">/* error or eof */</span> | ||||
|         fr = f_write(&fdst, buffer, br, &bw);            <span class="c">/* Write it to the destination file */</span> | ||||
|         if (fr || bw < br) break; <span class="c">/* error or disk full */</span> | ||||
|         f_read(&fsrc, buffer, sizeof buffer, &br);  <span class="c">/* Read a chunk of data from the source file */</span> | ||||
|         if (br == 0) break; <span class="c">/* error or eof */</span> | ||||
|         f_write(&fdst, buffer, br, &bw);            <span class="c">/* Write it to the destination file */</span> | ||||
|         if (bw < br) break; <span class="c">/* error or disk full */</span> | ||||
|     } | ||||
| 
 | ||||
|     <span class="c">/* Close open files */</span> | ||||
|  | ||||
| @ -47,12 +47,13 @@ int f_printf ( | ||||
| <h4>Description</h4> | ||||
| <p>The format control directive is a sub-set of standard library shown as follows:</p> | ||||
| <pre> | ||||
|     %[flag][width][type] | ||||
|     %[flag][width][prefix][type] | ||||
| </pre> | ||||
| <dl> | ||||
| <dt>flag</dt><dd>Padding options. A <tt>-</tt> specifies left justified. A <tt>0</tt> specifies zero padded.</dd> | ||||
| <dt>width</dt><dd>Minimum width of the field, <tt>1-99</tt> or <tt>*</tt>. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An <tt>*</tt> specifies the value comes from an argument in int type.</dd> | ||||
| <dt>type</dt><dd><tt>c s d u o x b</tt> and prefix <tt>l</tt> specify type of the argument, character, string, signed integer in decimal, unsigned integer in decimal, unsigned integer in octal, unsigned integer in hexdecimal and unsigned integer in binary respectively. If <tt>sizeof (long)</tt> is greater than <tt>sizeof (int)</tt> (this is typical of 8/16-bit systems), a prefix <tt>l</tt> needs to be explicitly specified for long integer argument. These characters except for <tt>x</tt> are case insensitive.</dd> | ||||
| <dt>flag</dt><dd>Padding options. A <tt>'0'</tt> specifies zero padded. A <tt>'-'</tt> specifies left justified.</dd> | ||||
| <dt>width</dt><dd>Minimum width of the field, <tt>'1'-'99'</tt> or <tt>'*'</tt>. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An <tt>*</tt> specifies the value comes from an argument in int type. The default value is zero.</dd> | ||||
| <dt>prefix</dt><dd>Size prefix <tt>'l'</tt> for long integer argument. If <tt>sizeof (long) == sizeof (int)</tt> (this is typical of 32-bit systems), the size prefix can be omitted.</dd> | ||||
| <dt>type</dt><dd><tt>'c','s','d','u','o','x','b'</tt>, specify type of the argument and output format, character, string, signed integer in decimal, unsigned integer in decimal, unsigned integer in octal, unsigned integer in hexdecimal and unsigned integer in binary respectively. These characters except <tt>'x'</tt> are case insensitive. An <tt>'X'</tt> generates a hexdecimal in up-case.</dd> | ||||
| </dl> | ||||
| <p>When FatFs is configured for Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt>), character encoding on the string fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt> function, is also switched to Unicode. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding <em>on the file</em> to be written via this function is selected by <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a></tt>. The characters with wrong encoding or invalid for the output encoding will be lost.</p> | ||||
| </div> | ||||
|  | ||||
| @ -11,7 +11,7 @@ | ||||
| 
 | ||||
| <body> | ||||
| <h1>Return Code of API Functions</h1> | ||||
| <p>Most of API functions return common result code as enum type <tt>FRESULT</tt>. When an API function succeeded, it returns zero (<tt>FR_OK</tt>), otherwise it returns non-zero value indicates type of error.</p> | ||||
| <p>Most of API functions return common result code in enum type <tt>FRESULT</tt>. When an API function succeeded, it returns zero (<tt>FR_OK</tt>), otherwise it returns non-zero value indicates type of error.</p> | ||||
| 
 | ||||
| <dl class="ret"> | ||||
| 
 | ||||
| @ -46,13 +46,13 @@ Note that if once this error occured at any operation to an open file, the file | ||||
| <dd>Could not find the file in the directory.</dd> | ||||
| 
 | ||||
| <dt id="np">FR_NO_PATH</dt> | ||||
| <dd>Could not find the path, some directory in the path name could not be found.</dd> | ||||
| <dd>Could not find the path. A directory in the path name could not be found.</dd> | ||||
| 
 | ||||
| <dt id="in">FR_INVALID_NAME</dt> | ||||
| <dd>The given string is invalid as the <a href="filename.html">path name</a>. One of the following possibilities is suspected. | ||||
| <ul> | ||||
| <li>There is any character not allowed for the file name.</li> | ||||
| <li>The string is out of 8.3 format. (at non-LFN cfg.)</li> | ||||
| <li>There is a character not allowed for the file name.</li> | ||||
| <li>The file name is out of 8.3 format. (at non-LFN cfg.)</li> | ||||
| <li><tt>FF_MAX_LFN</tt> is insufficient for the file name. (at LFN cfg.)</li> | ||||
| <li>There is any character encoding error in the string.</li> | ||||
| </ul> | ||||
| @ -72,7 +72,7 @@ Note that if once this error occured at any operation to an open file, the file | ||||
| </dd> | ||||
| 
 | ||||
| <dt id="ex">FR_EXIST</dt> | ||||
| <dd>Name collision, an object with the same name is already existing.</dd> | ||||
| <dd>Name collision. An object with the same name is already existing in the directory.</dd> | ||||
| 
 | ||||
| <dt id="io">FR_INVALID_OBJECT</dt> | ||||
| <dd>The file/directory object is invalid or a null pointer is given. There are some reasons as follows: | ||||
| @ -87,7 +87,7 @@ Note that if once this error occured at any operation to an open file, the file | ||||
| <dd>A write mode operation against the write-protected media.</dd> | ||||
| 
 | ||||
| <dt id="id">FR_INVALID_DRIVE</dt> | ||||
| <dd>Invalid drive number is specified in the path name. A null pointer is given as the path name. (Related option: <tt><a href="config.html#volumes">FF_VOLUMES</a></tt>)</dd> | ||||
| <dd>Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: <tt><a href="config.html#volumes">FF_VOLUMES</a></tt>)</dd> | ||||
| 
 | ||||
| <dt id="ne">FR_NOT_ENABLED</dt> | ||||
| <dd>Work area for the logical drive has not been registered by <tt>f_mount</tt> function.</dd> | ||||
| @ -99,7 +99,7 @@ Note that if once this error occured at any operation to an open file, the file | ||||
| <dd>The <tt>f_mkfs</tt> function aborted before start in format due to a reason as follows: | ||||
| <ul> | ||||
| <li>It is impossible to format with the given parameters.</li> | ||||
| <li>The size of volume is too small. 128 sectors minimum with <tt>FM_SFD</tt>.</li> | ||||
| <li>The size of volume is too small. 128 sectors minimum with <tt>FM_SFD</tt> option.</li> | ||||
| <li>The partition bound to the logical drive coulud not be found. (Related option: <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a></tt>)</li> | ||||
| </ul> | ||||
| </dd> | ||||
|  | ||||
| @ -30,11 +30,11 @@ FRESULT f_read ( | ||||
| <dt>fp</dt> | ||||
| <dd>Pointer to the open file object.</dd> | ||||
| <dt>buff</dt> | ||||
| <dd>Pointer to the buffer to store read data.</dd> | ||||
| <dd>Pointer to the buffer to store the read data.</dd> | ||||
| <dt>btr</dt> | ||||
| <dd>Number of bytes to read in range of <tt>UINT</tt> type.</dd> | ||||
| <dt>br</dt> | ||||
| <dd>Pointer to the <tt>UINT</tt> variable to return number of bytes read. This value is always valid after the function call regardless of the function return code.</dd> | ||||
| <dd>Pointer to the <tt>UINT</tt> variable that receives number of bytes read. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btr</tt>, the function return code should be <tt>FR_OK</tt>.</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -54,7 +54,7 @@ FRESULT f_read ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The function starts to read data from the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, <tt class="arg">*br</tt> should be checked to detect end of the file. In case of <tt class="arg">*br</tt> < <tt class="arg">btr</tt>, it means the read/write pointer reached end of the file during read operation.</p> | ||||
| <p>The function starts to read data from the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, <tt class="arg">*br</tt> should be checked to detect end of the file. In case of <tt class="arg">*br</tt> < <tt class="arg">btr</tt>, it means the read/write pointer reached end of the file during read operation.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| @ -64,6 +64,12 @@ FRESULT f_read ( | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para use"> | ||||
| <h4>Example</h4> | ||||
| <p>Refer to the example in <tt>f_open</tt>.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para ref"> | ||||
| <h4>See Also</h4> | ||||
| <p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p> | ||||
|  | ||||
| @ -48,7 +48,7 @@ FRESULT f_readdir ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_readdir</tt> function reads a directory item, informations about the object. Every item in the directory can be read in sequence by <tt>f_readdir</tt> function calls. Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a null string is stored into the <tt>fno->fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded.</p> | ||||
| <p>The <tt>f_readdir</tt> function reads a directory item, informations about the object. Items in the directory can be read in sequence by <tt>f_readdir</tt> function calls. Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a null string is stored into the <tt>fno->fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded.</p> | ||||
| <p>When support of long file name (LFN) is enabled, a member <tt>altname[]</tt> is defined in the file information structure to store the short file name of the object. If the long file name is not accessible due to some reason listed below, short file name is stored to the <tt>fname[]</tt> and <tt>altname[]</tt> has a null string.</p> | ||||
| <ul> | ||||
| <li>The item has no LFN. (Not the case at exFAT volume)</li> | ||||
|  | ||||
| @ -19,7 +19,7 @@ | ||||
|     FFOBJID obj;        <span class="c">/* Object identifier */</span> | ||||
|     DWORD   dptr;       <span class="c">/* Current read/write offset */</span> | ||||
|     DWORD   clust;      <span class="c">/* Current cluster */</span> | ||||
|     DWORD   sect;       <span class="c">/* Current sector */</span> | ||||
|     LBA_t   sect;       <span class="c">/* Current sector */</span> | ||||
|     BYTE*   dir;        <span class="c">/* Pointer to the current SFN entry in the win[] */</span> | ||||
|     BYTE*   fn;         <span class="c">/* Pointer to the SFN buffer (in/out) {file[8],ext[3],status[1]} */</span> | ||||
| <span class="k">#if</span> FF_USE_LFN | ||||
|  | ||||
| @ -31,7 +31,7 @@ | ||||
|     BYTE*   dirbuf;       <span class="c">/* Directory entry block scratchpad buffer */</span> | ||||
| <span class="k">#endif</span> | ||||
| <span class="k">#if</span> FF_FS_REENTRANT | ||||
|     FF_SYNC_t sobj;         <span class="c">/* Identifier of sync object */</span> | ||||
|     FF_SYNC_t sobj;       <span class="c">/* Identifier of sync object */</span> | ||||
| <span class="k">#endif</span> | ||||
| <span class="k">#if</span> !FF_FS_READONLY | ||||
|     DWORD   last_clust;   <span class="c">/* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */</span> | ||||
| @ -47,11 +47,11 @@ | ||||
| <span class="k">#endif</span> | ||||
|     DWORD   n_fatent;     <span class="c">/* Number of FAT entries (Number of clusters + 2) */</span> | ||||
|     DWORD   fsize;        <span class="c">/* Sectors per FAT */</span> | ||||
|     DWORD   volbase;      <span class="c">/* Volume base LBA */</span> | ||||
|     DWORD   fatbase;      <span class="c">/* FAT base LBA */</span> | ||||
|     DWORD   dirbase;      <span class="c">/* Root directory base (LBA|Cluster) */</span> | ||||
|     DWORD   database;     <span class="c">/* Data base LBA */</span> | ||||
|     DWORD   winsect;      <span class="c">/* Sector LBA appearing in the win[] */</span> | ||||
|     LBA_t   volbase;      <span class="c">/* Volume base LBA */</span> | ||||
|     LBA_t   fatbase;      <span class="c">/* FAT base LBA */</span> | ||||
|     LBA_t   dirbase;      <span class="c">/* Root directory base (LBA|Cluster) */</span> | ||||
|     LBA_t   database;     <span class="c">/* Data base LBA */</span> | ||||
|     LBA_t   winsect;      <span class="c">/* Sector LBA appearing in the win[] */</span> | ||||
|     BYTE    win[FF_MAX_SS]; <span class="c">/* Disk access window for directory, FAT (and file data at tiny cfg) */</span> | ||||
| } FATFS; | ||||
| </pre> | ||||
|  | ||||
| @ -22,9 +22,9 @@ | ||||
|     BYTE    err;          <span class="c">/* Abort flag (error code) */</span> | ||||
|     FSIZE_t fptr;         <span class="c">/* File read/write pointer (Byte offset origin from top of the file) */</span> | ||||
|     DWORD   clust;        <span class="c">/* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */</span> | ||||
|     DWORD   sect;         <span class="c">/* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/</span> | ||||
|     LBA_t   sect;         <span class="c">/* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/</span> | ||||
| <span class="k">#if</span> !FF_FS_READONLY | ||||
|     DWORD   dir_sect;     <span class="c">/* Sector number containing the directory entry */</span> | ||||
|     LBA_t   dir_sect;     <span class="c">/* Sector number containing the directory entry */</span> | ||||
|     BYTE*   dir_ptr;      <span class="c">/* Ponter to the directory entry in the window */</span> | ||||
| <span class="k">#endif</span> | ||||
| <span class="k">#if</span> FF_USE_FASTSEEK | ||||
|  | ||||
| @ -13,7 +13,7 @@ | ||||
| 
 | ||||
| <div class="para"> | ||||
| <h2>FILINFO</h2> | ||||
| <p>The <tt>FILINFO</tt> structure holds information about the object returned by <tt>f_readdir</tt>, <tt>f_findfirst</tt>, <tt>f_findnext</tt> and <tt>f_stat</tt> function. Be careful in the size of structure when LFN is enabled.</p> | ||||
| <p>The <tt>FILINFO</tt> structure holds information about the object retrieved by <tt>f_readdir</tt>, <tt>f_findfirst</tt>, <tt>f_findnext</tt> and <tt>f_stat</tt> function. Be careful in the size of structure when LFN is enabled.</p> | ||||
| <pre> | ||||
| <span class="k">typedef struct</span> { | ||||
|     FSIZE_t fsize;               <span class="c">/* File size */</span> | ||||
| @ -33,9 +33,9 @@ | ||||
| <h4>Members</h4> | ||||
| <dl> | ||||
| <dt>fsize</dt> | ||||
| <dd>Indicates size of the file in unit of byte. <tt>FSIZE_t</tt> is an alias of integer type either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>. Do not care when the item is a directory.</dd> | ||||
| <dd>Size of the file in unit of byte. <tt>FSIZE_t</tt> is an alias of integer type either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>. Do not care if the item is a sub-directory.</dd> | ||||
| <dt>fdate</dt> | ||||
| <dd>Indicates the date when the file was modified or the directory was created.<br> | ||||
| <dd>The date when the file was modified or the directory was created.<br> | ||||
| <dl> | ||||
| <dt>bit15:9</dt> | ||||
| <dd>Year origin from 1980 (0..127)</dd> | ||||
| @ -46,7 +46,7 @@ | ||||
| </dl> | ||||
| </dd> | ||||
| <dt>ftime</dt> | ||||
| <dd>Indicates the time when the file was modified or the directory was created.<br> | ||||
| <dd>The time when the file was modified or the directory was created.<br> | ||||
| <dl> | ||||
| <dt>bit15:11</dt> | ||||
| <dd>Hour (0..23)</dd> | ||||
| @ -57,7 +57,7 @@ | ||||
| </dl> | ||||
| </dd> | ||||
| <dt>fattrib</dt> | ||||
| <dd>Indicates the attribute flags in combination of:<br> | ||||
| <dd>The attribute flags in combination of:<br> | ||||
| <table class="lst"> | ||||
| <tr><th>Flag</th><th>Meaning</th></tr> | ||||
| <tr><td>AM_RDO</td><td>Read-only. Write mode open and deleting is rejected.</td></tr> | ||||
| @ -68,9 +68,9 @@ | ||||
| </table> | ||||
| </dd> | ||||
| <dt>fname[]</dt> | ||||
| <dd>The null-terminated object name is stored. A null string is stored when no item to read and it indicates this structure is invalid. The size of <tt>fname[]</tt> and <tt>altname[]</tt> each can be configured at LFN configuration.</dd> | ||||
| <dd>Null-terminated object name. A null string is stored when no item to read and it indicates this structure is invalid. The size of <tt>fname[]</tt> and <tt>altname[]</tt> each can be configured at LFN configuration.</dd> | ||||
| <dt>altname[]</dt> | ||||
| <dd>Alternative object name is stored if available. This member is not available at non-LFN configuration.</dd> | ||||
| <dd>Alternative object name is stored if available. This member is not available in non-LFN configuration.</dd> | ||||
| </dl> | ||||
| 
 | ||||
| <p class="foot"><a href="../00index_e.html">Return</a></p> | ||||
|  | ||||
| @ -54,7 +54,7 @@ FRESULT f_stat ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_stat</tt> function checks the existence of a file or sub-directory. If not exist, the function returns with <tt>FR_NO_FILE</tt>. If exist, the function returns with <tt>FR_OK</tt> and the informations of the object, file size, timestamp and attribute, are stored to the file information structure. For details of the file information, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir</tt></a> function.</p> | ||||
| <p>The <tt>f_stat</tt> function checks the existence of a file or sub-directory. If not exist, the function returns with <tt>FR_NO_FILE</tt>. If exist, the function returns with <tt>FR_OK</tt> and the informations about the object, size, timestamp and attribute, is stored to the file information structure. For details of the file information, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir</tt></a> function.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -44,12 +44,12 @@ FRESULT f_sync ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function in certain interval can minimize the risk of data loss due to a sudden blackout or an unintentional media removal. For more information, refer to <a href="appnote.html#critical">application note</a>.</p> | ||||
| <p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function in certain interval can minimize the risk of data loss due to a sudden blackout, wrong media removal or unrecoverable disk error. For more information, refer to <a href="appnote.html#critical">application note</a>.</p> | ||||
| <pre> | ||||
| Case 1. Normal write sequence | ||||
| 
 | ||||
|                                 Time -->                                     ↓Power off after close | ||||
| OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC | ||||
|                                 Time -->                                     ↓Normal shutdown | ||||
| OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC <Power off> | ||||
| 
 | ||||
| 
 | ||||
| Case 2. Without using f_sync() | ||||
|  | ||||
| @ -34,7 +34,7 @@ FRESULT f_write ( | ||||
| <dt>btw</dt> | ||||
| <dd>Specifies number of bytes to write in range of <tt>UINT</tt> type.</dd> | ||||
| <dt>bw</dt> | ||||
| <dd>Pointer to the <tt>UINT</tt> variable to return the number of bytes written. This value is always valid after the function call regardless of the function return code.</dd> | ||||
| <dd>Pointer to the <tt>UINT</tt> variable that receives the number of bytes written. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btw</tt>, the function return code should be <tt>FR_OK</tt>.</dd> | ||||
| </dl> | ||||
| </div> | ||||
| 
 | ||||
| @ -54,7 +54,7 @@ FRESULT f_write ( | ||||
| 
 | ||||
| <div class="para desc"> | ||||
| <h4>Description</h4> | ||||
| <p>The function starts to write data to the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, <tt class="arg">*bw</tt> should be checked to detect the disk full. In case of <tt class="arg">*bw</tt> < <tt class="arg">btw</tt>, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.</p> | ||||
| <p>The function starts to write data to the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, <tt class="arg">*bw</tt> should be checked to detect the disk full. In case of <tt class="arg">*bw</tt> < <tt class="arg">btw</tt>, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| @ -64,6 +64,12 @@ FRESULT f_write ( | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para use"> | ||||
| <h4>Example</h4> | ||||
| <p>Refer to the example in <tt>f_open</tt>.</p> | ||||
| </div> | ||||
| 
 | ||||
| 
 | ||||
| <div class="para ref"> | ||||
| <h4>See Also</h4> | ||||
| <p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p> | ||||
|  | ||||
| @ -10,9 +10,9 @@ | ||||
| #include "diskio.h"     /* Declarations of disk functions */ | ||||
| 
 | ||||
| 
 | ||||
| static | ||||
| DWORD pn (		/* Pseudo random number generator */ | ||||
|     DWORD pns	/* 0:Initialize, !0:Read */ | ||||
| 
 | ||||
| static DWORD pn (       /* Pseudo random number generator */ | ||||
|     DWORD pns   /* 0:Initialize, !0:Read */ | ||||
| ) | ||||
| { | ||||
|     static DWORD lfsr; | ||||
| @ -50,8 +50,8 @@ int test_diskio ( | ||||
| 
 | ||||
|     printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff); | ||||
| 
 | ||||
|     if (sz_buff < _MAX_SS + 4) { | ||||
|         printf("Insufficient work area to run program.\n"); | ||||
|     if (sz_buff < FF_MAX_SS + 8) { | ||||
|         printf("Insufficient work area to run the program.\n"); | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
| @ -115,7 +115,7 @@ int test_diskio ( | ||||
|         } | ||||
| 
 | ||||
|         /* Single sector write test */ | ||||
|         printf("**** Single sector write test 1 ****\n"); | ||||
|         printf("**** Single sector write test ****\n"); | ||||
|         lba = 0; | ||||
|         for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0); | ||||
|         printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba); | ||||
| @ -145,52 +145,56 @@ int test_diskio ( | ||||
|         } | ||||
|         for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ; | ||||
|         if (n == sz_sect) { | ||||
|             printf(" Data matched.\n"); | ||||
|             printf(" Read data matched.\n"); | ||||
|         } else { | ||||
|             printf("Failed: Read data differs from the data written.\n"); | ||||
|             printf(" Read data differs from the data written.\n"); | ||||
|             return 10; | ||||
|         } | ||||
|         pns++; | ||||
| 
 | ||||
|         printf("**** Multiple sector write test ****\n"); | ||||
|         lba = 1; ns = sz_buff / sz_sect; | ||||
|         lba = 5; ns = sz_buff / sz_sect; | ||||
|         if (ns > 4) ns = 4; | ||||
|         for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0); | ||||
|         printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns); | ||||
|         dr = disk_write(pdrv, pbuff, lba, ns); | ||||
|         if (dr == RES_OK) { | ||||
|             printf(" - ok.\n"); | ||||
|         if (ns > 1) { | ||||
|             for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0); | ||||
|             printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns); | ||||
|             dr = disk_write(pdrv, pbuff, lba, ns); | ||||
|             if (dr == RES_OK) { | ||||
|                 printf(" - ok.\n"); | ||||
|             } else { | ||||
|                 printf(" - failed.\n"); | ||||
|                 return 11; | ||||
|             } | ||||
|             printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv); | ||||
|             dr = disk_ioctl(pdrv, CTRL_SYNC, 0); | ||||
|             if (dr == RES_OK) { | ||||
|                 printf(" - ok.\n"); | ||||
|             } else { | ||||
|                 printf(" - failed.\n"); | ||||
|                 return 12; | ||||
|             } | ||||
|             memset(pbuff, 0, sz_sect * ns); | ||||
|             printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns); | ||||
|             dr = disk_read(pdrv, pbuff, lba, ns); | ||||
|             if (dr == RES_OK) { | ||||
|                 printf(" - ok.\n"); | ||||
|             } else { | ||||
|                 printf(" - failed.\n"); | ||||
|                 return 13; | ||||
|             } | ||||
|             for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ; | ||||
|             if (n == (UINT)(sz_sect * ns)) { | ||||
|                 printf(" Read data matched.\n"); | ||||
|             } else { | ||||
|                 printf(" Read data differs from the data written.\n"); | ||||
|                 return 14; | ||||
|             } | ||||
|         } else { | ||||
|             printf(" - failed.\n"); | ||||
|             return 11; | ||||
|         } | ||||
|         printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv); | ||||
|         dr = disk_ioctl(pdrv, CTRL_SYNC, 0); | ||||
|         if (dr == RES_OK) { | ||||
|             printf(" - ok.\n"); | ||||
|         } else { | ||||
|             printf(" - failed.\n"); | ||||
|             return 12; | ||||
|         } | ||||
|         memset(pbuff, 0, sz_sect * ns); | ||||
|         printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns); | ||||
|         dr = disk_read(pdrv, pbuff, lba, ns); | ||||
|         if (dr == RES_OK) { | ||||
|             printf(" - ok.\n"); | ||||
|         } else { | ||||
|             printf(" - failed.\n"); | ||||
|             return 13; | ||||
|         } | ||||
|         for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ; | ||||
|         if (n == (UINT)(sz_sect * ns)) { | ||||
|             printf(" Data matched.\n"); | ||||
|         } else { | ||||
|             printf("Failed: Read data differs from the data written.\n"); | ||||
|             return 14; | ||||
|             printf(" Test skipped.\n"); | ||||
|         } | ||||
|         pns++; | ||||
| 
 | ||||
|         printf("**** Single sector write test (misaligned address) ****\n"); | ||||
|         printf("**** Single sector write test (unaligned buffer address) ****\n"); | ||||
|         lba = 5; | ||||
|         for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0); | ||||
|         printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba); | ||||
| @ -220,9 +224,9 @@ int test_diskio ( | ||||
|         } | ||||
|         for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ; | ||||
|         if (n == sz_sect) { | ||||
|             printf(" Data matched.\n"); | ||||
|             printf(" Read data matched.\n"); | ||||
|         } else { | ||||
|             printf("Failed: Read data differs from the data written.\n"); | ||||
|             printf(" Read data differs from the data written.\n"); | ||||
|             return 18; | ||||
|         } | ||||
|         pns++; | ||||
| @ -274,9 +278,9 @@ int test_diskio ( | ||||
|             } | ||||
|             for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ; | ||||
|             if (n == (UINT)(sz_sect * 2)) { | ||||
|                 printf(" Data matched.\n"); | ||||
|                 printf(" Read data matched.\n"); | ||||
|             } else { | ||||
|                 printf("Failed: Read data differs from the data written.\n"); | ||||
|                 printf(" Read data differs from the data written.\n"); | ||||
|                 return 24; | ||||
|             } | ||||
|         } else { | ||||
|  | ||||
| @ -21,7 +21,7 @@ FRESULT test_contiguous_file ( | ||||
| #else | ||||
|     clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize; | ||||
| #endif | ||||
|     fsz = fp->obj.objsize; | ||||
|     fsz = f_size(fp); | ||||
|     if (fsz > 0) { | ||||
|         clst = fp->obj.sclust - 1;  /* A cluster leading the first cluster for first test */ | ||||
|         while (fsz) { | ||||
|  | ||||
							
								
								
									
										61
									
								
								documents/res/app6.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								documents/res/app6.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,61 @@ | ||||
| /*---------------------------------------------------------------------*/ | ||||
| /* Raw Read/Write Throughput Checker                                   */ | ||||
| /*---------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <systimer.h> | ||||
| #include "diskio.h" | ||||
| #include "ff.h" | ||||
| 
 | ||||
| 
 | ||||
| int test_raw_speed ( | ||||
|     BYTE pdrv,      /* Physical drive number */ | ||||
|     DWORD lba,      /* Start LBA for read/write test */ | ||||
|     DWORD len,      /* Number of bytes to read/write (must be multiple of sz_buff) */ | ||||
|     void* buff,     /* Read/write buffer */ | ||||
|     UINT sz_buff    /* Size of read/write buffer (must be multiple of FF_MAX_SS) */ | ||||
| ) | ||||
| { | ||||
|     WORD ss; | ||||
|     DWORD ofs, tmr; | ||||
| 
 | ||||
| 
 | ||||
| #if FF_MIN_SS != FF_MAX_SS | ||||
|     if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) { | ||||
|         printf("\ndisk_ioctl() failed.\n"); | ||||
|         return 0; | ||||
|     } | ||||
| #else | ||||
|     ss = FF_MAX_SS; | ||||
| #endif | ||||
| 
 | ||||
|     printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff); | ||||
|     tmr = systimer(); | ||||
|     for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) { | ||||
|         if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) { | ||||
|             printf("\ndisk_write() failed.\n"); | ||||
|             return 0; | ||||
|         } | ||||
|     } | ||||
|     if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) { | ||||
|         printf("\ndisk_ioctl() failed.\n"); | ||||
|         return 0; | ||||
|     } | ||||
|     tmr = systimer() - tmr; | ||||
|     printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr); | ||||
| 
 | ||||
|     printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff); | ||||
|     tmr = systimer(); | ||||
|     for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) { | ||||
|         if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) { | ||||
|             printf("\ndisk_read() failed.\n"); | ||||
|             return 0; | ||||
|         } | ||||
|     } | ||||
|     tmr = systimer() - tmr; | ||||
|     printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr); | ||||
| 
 | ||||
|     printf("Test completed.\n"); | ||||
|     return 1; | ||||
| } | ||||
| 
 | ||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 26 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 4.8 KiB | 
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								documents/res/mkfs.xlsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								documents/res/mkfs.xlsx
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 15 KiB | 
| @ -1,3 +1,11 @@ | ||||
| R0.14 (October 14, 2019) | ||||
|   Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1) | ||||
|   Changed some API functions, f_mkfs() and f_fdisk(). | ||||
|   Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters. | ||||
|   Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters. | ||||
|   Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12) | ||||
|   Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12) | ||||
| 
 | ||||
| R0.13c (October 14, 2018) | ||||
|   Supported stdint.h for C99 and later. (integer.h was included in ff.h) | ||||
|   Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12) | ||||
|  | ||||
| @ -328,3 +328,13 @@ R0.13c (October 14, 2018) | ||||
|   Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12) | ||||
|   Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| R0.14 (October 14, 2019) | ||||
|   Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1) | ||||
|   Changed some API functions, f_mkfs() and f_fdisk(). | ||||
|   Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters. | ||||
|   Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters. | ||||
|   Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12) | ||||
|   Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12) | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| FatFs Module Source Files R0.13c | ||||
| FatFs Module Source Files R0.14 | ||||
| 
 | ||||
| 
 | ||||
| FILES | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2016        */ | ||||
| /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2019        */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* If a working storage control module is available, it should be        */ | ||||
| /* attached to the FatFs via a glue function rather than modifying it.   */ | ||||
| @ -99,7 +99,7 @@ DSTATUS disk_initialize ( | ||||
| DRESULT disk_read ( | ||||
| 	BYTE pdrv,		/* Physical drive nmuber to identify the drive */ | ||||
| 	BYTE *buff,		/* Data buffer to store read data */ | ||||
| 	DWORD sector,	/* Start sector in LBA */ | ||||
| 	LBA_t sector,	/* Start sector in LBA */ | ||||
| 	UINT count		/* Number of sectors to read */ | ||||
| ) | ||||
| { | ||||
| @ -149,7 +149,7 @@ DRESULT disk_read ( | ||||
| DRESULT disk_write ( | ||||
| 	BYTE pdrv,			/* Physical drive nmuber to identify the drive */ | ||||
| 	const BYTE *buff,	/* Data to be written */ | ||||
| 	DWORD sector,		/* Start sector in LBA */ | ||||
| 	LBA_t sector,		/* Start sector in LBA */ | ||||
| 	UINT count			/* Number of sectors to write */ | ||||
| ) | ||||
| { | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /*-----------------------------------------------------------------------/
 | ||||
| /  Low level disk interface modlue include file   (C)ChaN, 2014          / | ||||
| /  Low level disk interface modlue include file   (C)ChaN, 2019          / | ||||
| /-----------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #ifndef _DISKIO_DEFINED | ||||
| @ -28,8 +28,8 @@ typedef enum { | ||||
| 
 | ||||
| DSTATUS disk_initialize (BYTE pdrv); | ||||
| DSTATUS disk_status (BYTE pdrv); | ||||
| DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); | ||||
| DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); | ||||
| DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count); | ||||
| DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count); | ||||
| DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										1122
									
								
								source/ff.c
									
									
									
									
									
								
							
							
						
						
									
										1122
									
								
								source/ff.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										59
									
								
								source/ff.h
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								source/ff.h
									
									
									
									
									
								
							| @ -1,8 +1,8 @@ | ||||
| /*----------------------------------------------------------------------------/
 | ||||
| /  FatFs - Generic FAT Filesystem module  R0.13c                              / | ||||
| /  FatFs - Generic FAT Filesystem module  R0.14                               / | ||||
| /-----------------------------------------------------------------------------/ | ||||
| / | ||||
| / Copyright (C) 2018, ChaN, all right reserved. | ||||
| / Copyright (C) 2019, ChaN, all right reserved. | ||||
| / | ||||
| / FatFs module is an open source software. Redistribution and use of FatFs in | ||||
| / source and binary forms, with or without modification, are permitted provided | ||||
| @ -20,7 +20,7 @@ | ||||
| 
 | ||||
| 
 | ||||
| #ifndef FF_DEFINED | ||||
| #define FF_DEFINED	86604	/* Revision ID */ | ||||
| #define FF_DEFINED	86606	/* Revision ID */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| @ -45,16 +45,16 @@ typedef unsigned __int64 QWORD; | ||||
| typedef unsigned int	UINT;	/* int must be 16-bit or 32-bit */ | ||||
| typedef unsigned char	BYTE;	/* char must be 8-bit */ | ||||
| typedef uint16_t		WORD;	/* 16-bit unsigned integer */ | ||||
| typedef uint16_t		WCHAR;	/* 16-bit unsigned integer */ | ||||
| typedef uint32_t		DWORD;	/* 32-bit unsigned integer */ | ||||
| typedef uint64_t		QWORD;	/* 64-bit unsigned integer */ | ||||
| typedef WORD			WCHAR;	/* UTF-16 character type */ | ||||
| #else  	/* Earlier than C99 */ | ||||
| #define FF_INTDEF 1 | ||||
| typedef unsigned int	UINT;	/* int must be 16-bit or 32-bit */ | ||||
| typedef unsigned char	BYTE;	/* char must be 8-bit */ | ||||
| typedef unsigned short	WORD;	/* 16-bit unsigned integer */ | ||||
| typedef unsigned short	WCHAR;	/* 16-bit unsigned integer */ | ||||
| typedef unsigned long	DWORD;	/* 32-bit unsigned integer */ | ||||
| typedef WORD			WCHAR;	/* UTF-16 character type */ | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| @ -65,7 +65,7 @@ typedef struct { | ||||
| 	BYTE pd;	/* Physical drive number */ | ||||
| 	BYTE pt;	/* Partition: 0:Auto detect, 1-4:Forced partition) */ | ||||
| } PARTITION; | ||||
| extern PARTITION VolToPart[];	/* Volume - Partition resolution table */ | ||||
| extern PARTITION VolToPart[];	/* Volume - Partition mapping table */ | ||||
| #endif | ||||
| 
 | ||||
| #if FF_STR_VOLUME_ID | ||||
| @ -105,15 +105,24 @@ typedef char TCHAR; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* Type of file size variables */ | ||||
| /* Type of file size and LBA variables */ | ||||
| 
 | ||||
| #if FF_FS_EXFAT | ||||
| #if FF_INTDEF != 2 | ||||
| #error exFAT feature wants C99 or later | ||||
| #endif | ||||
| typedef QWORD FSIZE_t; | ||||
| #if FF_LBA64 | ||||
| typedef QWORD LBA_t; | ||||
| #else | ||||
| typedef DWORD LBA_t; | ||||
| #endif | ||||
| #else | ||||
| #if FF_LBA64 | ||||
| #error exFAT needs to be enabled when enable 64-bit LBA | ||||
| #endif | ||||
| typedef DWORD FSIZE_t; | ||||
| typedef DWORD LBA_t; | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| @ -155,14 +164,14 @@ typedef struct { | ||||
| #endif | ||||
| 	DWORD	n_fatent;		/* Number of FAT entries (number of clusters + 2) */ | ||||
| 	DWORD	fsize;			/* Size of an FAT [sectors] */ | ||||
| 	DWORD	volbase;		/* Volume base sector */ | ||||
| 	DWORD	fatbase;		/* FAT base sector */ | ||||
| 	DWORD	dirbase;		/* Root directory base sector/cluster */ | ||||
| 	DWORD	database;		/* Data base sector */ | ||||
| 	LBA_t	volbase;		/* Volume base sector */ | ||||
| 	LBA_t	fatbase;		/* FAT base sector */ | ||||
| 	LBA_t	dirbase;		/* Root directory base sector/cluster */ | ||||
| 	LBA_t	database;		/* Data base sector */ | ||||
| #if FF_FS_EXFAT | ||||
| 	DWORD	bitbase;		/* Allocation bitmap base sector */ | ||||
| 	LBA_t	bitbase;		/* Allocation bitmap base sector */ | ||||
| #endif | ||||
| 	DWORD	winsect;		/* Current sector appearing in the win[] */ | ||||
| 	LBA_t	winsect;		/* Current sector appearing in the win[] */ | ||||
| 	BYTE	win[FF_MAX_SS];	/* Disk access window for Directory, FAT (and file data at tiny cfg) */ | ||||
| } FATFS; | ||||
| 
 | ||||
| @ -199,9 +208,9 @@ typedef struct { | ||||
| 	BYTE	err;			/* Abort flag (error code) */ | ||||
| 	FSIZE_t	fptr;			/* File read/write pointer (Zeroed on file open) */ | ||||
| 	DWORD	clust;			/* Current cluster of fpter (invalid when fptr is 0) */ | ||||
| 	DWORD	sect;			/* Sector number appearing in buf[] (0:invalid) */ | ||||
| 	LBA_t	sect;			/* Sector number appearing in buf[] (0:invalid) */ | ||||
| #if !FF_FS_READONLY | ||||
| 	DWORD	dir_sect;		/* Sector number containing the directory entry (not used at exFAT) */ | ||||
| 	LBA_t	dir_sect;		/* Sector number containing the directory entry (not used at exFAT) */ | ||||
| 	BYTE*	dir_ptr;		/* Pointer to the directory entry in the win[] (not used at exFAT) */ | ||||
| #endif | ||||
| #if FF_USE_FASTSEEK | ||||
| @ -220,7 +229,7 @@ typedef struct { | ||||
| 	FFOBJID	obj;			/* Object identifier */ | ||||
| 	DWORD	dptr;			/* Current read/write offset */ | ||||
| 	DWORD	clust;			/* Current cluster */ | ||||
| 	DWORD	sect;			/* Current sector (0:Read operation has terminated) */ | ||||
| 	LBA_t	sect;			/* Current sector (0:Read operation has terminated) */ | ||||
| 	BYTE*	dir;			/* Pointer to the directory item in the win[] */ | ||||
| 	BYTE	fn[12];			/* SFN (in/out) {body[8],ext[3],status[1]} */ | ||||
| #if FF_USE_LFN | ||||
| @ -250,6 +259,18 @@ typedef struct { | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* Format parameter structure (MKFS_PARM) */ | ||||
| 
 | ||||
| typedef struct { | ||||
| 	BYTE fmt;			/* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */ | ||||
| 	BYTE n_fat;			/* Number of FATs */ | ||||
| 	UINT align;			/* Data area alignment (sector) */ | ||||
| 	UINT n_root;		/* Number of root directory entries */ | ||||
| 	DWORD au_size;		/* Cluster size (byte) */ | ||||
| } MKFS_PARM; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* File function return code (FRESULT) */ | ||||
| 
 | ||||
| typedef enum { | ||||
| @ -305,10 +326,10 @@ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);	/* Get numbe | ||||
| FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);	/* Get volume label */ | ||||
| FRESULT f_setlabel (const TCHAR* label);							/* Set volume label */ | ||||
| FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);	/* Forward data to the stream */ | ||||
| FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt);					/* Allocate a contiguous block to the file */ | ||||
| FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt);					/* Allocate a contiguous block to the file */ | ||||
| FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);			/* Mount/Unmount a logical drive */ | ||||
| FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len);	/* Create a FAT volume */ | ||||
| FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work);			/* Divide a physical drive into some partitions */ | ||||
| FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len);	/* Create a FAT volume */ | ||||
| FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work);		/* Divide a physical drive into some partitions */ | ||||
| FRESULT f_setcp (WORD cp);											/* Set current code page */ | ||||
| int f_putc (TCHAR c, FIL* fp);										/* Put a character to the file */ | ||||
| int f_puts (const TCHAR* str, FIL* cp);								/* Put a string to the file */ | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| /  FatFs Functional Configurations | ||||
| /---------------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #define FFCONF_DEF	86604	/* Revision ID */ | ||||
| #define FFCONF_DEF	86606	/* Revision ID */ | ||||
| 
 | ||||
| /*---------------------------------------------------------------------------/
 | ||||
| / Function Configurations | ||||
| @ -102,7 +102,7 @@ | ||||
| /* The FF_USE_LFN switches the support for LFN (long file name).
 | ||||
| / | ||||
| /   0: Disable LFN. FF_MAX_LFN has no effect. | ||||
| /   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. | ||||
| /   1: Enable LFN with static  working buffer on the BSS. Always NOT thread-safe. | ||||
| /   2: Enable LFN with dynamic working buffer on the STACK. | ||||
| /   3: Enable LFN with dynamic working buffer on the HEAP. | ||||
| / | ||||
| @ -110,11 +110,11 @@ | ||||
| /  requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and | ||||
| /  additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. | ||||
| /  The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can | ||||
| /  be in range of 12 to 255. It is recommended to be set 255 to fully support LFN | ||||
| /  be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN | ||||
| /  specification. | ||||
| /  When use stack for the working buffer, take care on stack overflow. When use heap | ||||
| /  memory for the working buffer, memory management functions, ff_memalloc() and | ||||
| /  ff_memfree() in ffsystem.c, need to be added to the project. */ | ||||
| /  ff_memfree() exemplified in ffsystem.c, need to be added to the project. */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_LFN_UNICODE	0 | ||||
| @ -200,24 +200,22 @@ | ||||
| /  GET_SECTOR_SIZE command. */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_LBA64		0 | ||||
| /* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
 | ||||
| /  To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_MIN_GPT		0x100000000 | ||||
| /* Minimum number of sectors to switch GPT format to create partition in f_mkfs and
 | ||||
| /  f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_USE_TRIM		0 | ||||
| /* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
 | ||||
| /  To enable Trim function, also CTRL_TRIM command should be implemented to the | ||||
| /  disk_ioctl() function. */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_FS_NOFSINFO	0 | ||||
| /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
 | ||||
| /  option, and f_getfree() function at first time after volume mount will force | ||||
| /  a full FAT scan. Bit 1 controls the use of last allocated cluster number. | ||||
| / | ||||
| /  bit0=0: Use free cluster count in the FSINFO if available. | ||||
| /  bit0=1: Do not trust free cluster count in the FSINFO. | ||||
| /  bit1=0: Use last allocated cluster number in the FSINFO if available. | ||||
| /  bit1=1: Do not trust last allocated cluster number in the FSINFO. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*---------------------------------------------------------------------------/
 | ||||
| / System Configurations | ||||
| @ -239,7 +237,7 @@ | ||||
| #define FF_FS_NORTC		0 | ||||
| #define FF_NORTC_MON	1 | ||||
| #define FF_NORTC_MDAY	1 | ||||
| #define FF_NORTC_YEAR	2018 | ||||
| #define FF_NORTC_YEAR	2019 | ||||
| /* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
 | ||||
| /  any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable | ||||
| /  the timestamp function. Every object modified by FatFs will have a fixed timestamp | ||||
| @ -247,7 +245,19 @@ | ||||
| /  To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be | ||||
| /  added to the project to read current time form real-time clock. FF_NORTC_MON, | ||||
| /  FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. | ||||
| /  These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ | ||||
| /  These options have no effect in read-only configuration (FF_FS_READONLY = 1). */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_FS_NOFSINFO	0 | ||||
| /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
 | ||||
| /  option, and f_getfree() function at first time after volume mount will force | ||||
| /  a full FAT scan. Bit 1 controls the use of last allocated cluster number. | ||||
| / | ||||
| /  bit0=0: Use free cluster count in the FSINFO if available. | ||||
| /  bit0=1: Do not trust free cluster count in the FSINFO. | ||||
| /  bit1=0: Use last allocated cluster number in the FSINFO if available. | ||||
| /  bit1=1: Do not trust last allocated cluster number in the FSINFO. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| #define FF_FS_LOCK		0 | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /*------------------------------------------------------------------------*/ | ||||
| /* Unicode handling functions for FatFs R0.13c                            */ | ||||
| /* Unicode handling functions for FatFs R0.13+                            */ | ||||
| /*------------------------------------------------------------------------*/ | ||||
| /* This module will occupy a huge memory in the .const section when the    /
 | ||||
| /  FatFs is configured for LFN with DBCS. If the system has any Unicode    / | ||||
| @ -7,7 +7,7 @@ | ||||
| /  that function to avoid silly memory consumption.                        / | ||||
| /-------------------------------------------------------------------------*/ | ||||
| /*
 | ||||
| / Copyright (C) 2018, ChaN, all right reserved. | ||||
| / Copyright (C) 2014, ChaN, all right reserved. | ||||
| / | ||||
| / FatFs module is an open source software. Redistribution and use of FatFs in | ||||
| / source and binary forms, with or without modification, are permitted provided | ||||
| @ -25,11 +25,7 @@ | ||||
| 
 | ||||
| #include "ff.h" | ||||
| 
 | ||||
| #if FF_USE_LFN	/* This module will be blanked at non-LFN configuration */ | ||||
| 
 | ||||
| #if FF_DEFINED != 86604	/* Revision ID */ | ||||
| #error Wrong include file (ff.h). | ||||
| #endif | ||||
| #if FF_USE_LFN	/* This module will be blanked if non-LFN configuration */ | ||||
| 
 | ||||
| #define MERGE2(a, b) a ## b | ||||
| #define CVTBL(tbl, cp) MERGE2(tbl, cp) | ||||
| @ -15245,7 +15241,7 @@ WCHAR ff_uni2oem (	/* Returns OEM code character, zero on error */ | ||||
| 	return c; | ||||
| } | ||||
| 
 | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character, zero on error */ | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character in UTF-16, zero on error */ | ||||
| 	WCHAR	oem,	/* OEM code to be converted */ | ||||
| 	WORD	cp		/* Code page for the conversion */ | ||||
| ) | ||||
| @ -15312,7 +15308,7 @@ WCHAR ff_uni2oem (	/* Returns OEM code character, zero on error */ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character, zero on error */ | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character in UTF-16, zero on error */ | ||||
| 	WCHAR	oem,	/* OEM code to be converted */ | ||||
| 	WORD	cp		/* Code page for the conversion */ | ||||
| ) | ||||
| @ -15411,7 +15407,7 @@ WCHAR ff_uni2oem (	/* Returns OEM code character, zero on error */ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character, zero on error */ | ||||
| WCHAR ff_oem2uni (	/* Returns Unicode character in UTF-16, zero on error */ | ||||
| 	WCHAR	oem,	/* OEM code to be converted (DBC if >=0x100) */ | ||||
| 	WORD	cp		/* Code page for the conversion */ | ||||
| ) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user