diff --git a/LICENSE.txt b/LICENSE.txt index bdce11892273005d8571be2f5b3b14a2ad87b880..25379e46fc4f4aef8782caee5db96e74d75b279e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -21,4 +21,4 @@ FatFs has being developped as a personal project of the author, ChaN. It is free / by use of this software. /----------------------------------------------------------------------------*/ -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. +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, do 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 include GNU GPL. When you redistribute the FatFs source code with 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. diff --git a/README.OpenSource b/README.OpenSource index 8083a1aecc76780ba7a2b188a62861ba012081a1..d9803a9cb0a27544c45df6596d60756c6d523b71 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -3,7 +3,7 @@ "Name" : "FatFs", "License" : "BSD 3-Clause License", "License File" : "LICENSE.txt", - "Version Number" : "R0.14a", + "Version Number" : "R0.15", "Owner" : "yesiyuan2@huawei.com", "Upstream URL" : "http://elm-chan.org/fsw/ff/00index_e.html", "Description" : "FatFs is a generic FAT/exFAT filesystem module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk I/O layer. Therefore it is independent of the platform. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, RX and etc. Also Petit FatFs module for tiny microcontrollers is available here." diff --git a/documents/00index_e.html b/documents/00index_e.html index 3646a380464dcd33c04a08c98a587ee5787c8ed7..b3b8adbaab1dc19bbd9a23b7d7b517289b1edeec 100644 --- a/documents/00index_e.html +++ b/documents/00index_e.html @@ -5,6 +5,8 @@ + + FatFs - Generic FAT Filesystem Module @@ -19,18 +21,18 @@

Features

@@ -67,7 +69,7 @@ @@ -89,8 +91,8 @@ +

Integer Types in FatFs API

+

Integer types used in FatFs are defined in ff.h as described below. It is based on Win32 API (windef.h). This will not be a problem on most platform. When a conflict with existing definitions occured, you must resolve it with care.

+
+
BYTE
8-bit unsigned integer in range of 0 to 28 - 1.
+
WORD
16-bit unsigned integer in range of 0 to 216 - 1.
+
DWORD
32-bit unsigned integer in range of 0 to 232 - 1.
+
QWORD
64-bit unsigned integer in range of 0 to 264 - 1.
+
UINT
Alias of unsigned int used to specify any number.
+
WCHAR
Alias of WORD used to specify a UTF-16 code unit.
+
TCHAR
Alias of char, WCHAR or DWORD used to specify a character encoding unit.
+
FSIZE_t
Alias of DWORD or QWORD used to address file offset and to specify file size.
+
LBA_t
Alias of DWORD or QWORD used to address sectors in LBA and to specify number of sectors.
+
+

System Organizations

The dependency diagram shown below is a typical, but not specific, configuration of the embedded system with FatFs module.

dependency diagram

@@ -53,16 +72,16 @@ Integer types used in FatFs are defined in ff.h. This will not be a pro

functional diagram

Required Functions

-

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.

+

You need to provide only MAI functions required by FatFs module and nothing else. If a working device control module for the target system is available, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another device control module or write it from scratch. Most of MAI functions are not that always required. For instance, the write function is not required in read-only configuration. Following table shows which function is required depends on the configuration options.

- + - - - - - - + + + + + +
FunctionRequired whenNote
FunctionRequired when:Note
disk_status
disk_initialize
disk_read
AlwaysDisk I/O functions.
Samples available in ffsample.zip.
There are many implementations on the web.
disk_write
get_fattime
disk_ioctl (CTRL_SYNC)
FF_FS_READONLY == 0
disk_ioctl (GET_SECTOR_COUNT)
disk_ioctl (GET_BLOCK_SIZE)
FF_USE_MKFS == 1
disk_ioctl (GET_SECTOR_SIZE)FF_MAX_SS != FF_MIN_SS
disk_ioctl (CTRL_TRIM)FF_USE_TRIM == 1
ff_uni2oem
ff_oem2uni
ff_wtoupper
FF_USE_LFN != 0Unicode support functions.
Add optional module ffunicode.c to the project.
ff_cre_syncobj
ff_del_syncobj
ff_req_grant
ff_rel_grant
FF_FS_REENTRANT == 1O/S dependent functions.
Sample code is available in ffsystem.c.
disk_write
get_fattime
disk_ioctl (CTRL_SYNC)
FF_FS_READONLY == 0
disk_ioctl (GET_SECTOR_COUNT)
disk_ioctl (GET_BLOCK_SIZE)
FF_USE_MKFS == 1
disk_ioctl (GET_SECTOR_SIZE)FF_MAX_SS != FF_MIN_SS
disk_ioctl (CTRL_TRIM)FF_USE_TRIM == 1
ff_uni2oem
ff_oem2uni
ff_wtoupper
FF_USE_LFN != 0Unicode support functions.
Add optional module ffunicode.c to the project.
ff_cre_syncobj
ff_del_syncobj
ff_req_grant
ff_rel_grant
FF_FS_REENTRANT == 1O/S dependent functions.
Sample code is available in ffsystem.c.
ff_mem_alloc
ff_mem_free
FF_USE_LFN == 3

FatFs cares about neither what kind of storage device is used nor how it is implemented. Only a requirement is that it is a block device read/written in fixed-size blocks that accessible via the disk I/O functions defined above.

@@ -73,11 +92,12 @@ Integer types used in FatFs are defined in ff.h. This will not be a pro @@ -88,19 +108,19 @@ Integer types used in FatFs are defined in ff.h. This will not be a pro ARM7
32bit
ARM7
Thumb
CM3
Thumb-2
AVRH8/300HPIC24RL78V850ESSH-2ARX600IA-32 CompilerGCCGCCGCCGCCCH38C30CC78K0RCA850SHCRXCMSC -text (Full, R/W)10.4k6.7k6.3k12.4k 9.9k11.2k13.0k8.7k9.0k6.5k8.9k -text (Min, R/W) 7.0k4.7k4.4k 8.4k 6.9k 7.8k 9.4k6.0k6.2k4.6k6.3k -text (Full, R/O) 4.8k3.1k2.8k 5.7k 4.7k 5.3k 6.4k4.2k4.0k3.1k4.2k -text (Min, R/O) 3.6k2.4k2.2k 4.4k 3.6k 4.1k 5.0k3.3k3.1k2.4k3.3k -bssV*4 + 2V*4 + 2V*4 + 2V*2 + 2V*4 + 2V*2 + 2V*2 + 2V*4 + 2V*4 + 2V*4 + 2V*4 + 2 +.text (Def, R/W)10.4k6.7k6.1k12.5k11.0k11.4k13.0k8.9k9.2k6.5k8.9k +.text (Min, R/W) 7.0k4.7k4.2k 8.5k 7.6k 7.9k 9.5k6.3k6.4k4.7k6.4k +.text (Def, R/O) 4.9k3.2k2.7k 6.1k 5.2k 5.4k 6.5k4.3k4.2k3.2k4.3k +.text (Min, R/O) 3.7k2.5k2.1k 4.4k 4.0k 4.2k 5.1k3.4k3.3k2.5k3.5k +.bssV*4 + 2V*4 + 2V*4 + 2V*2 + 2V*4 + 2V*2 + 2V*2 + 2V*4 + 2V*4 + 2V*4 + 2V*4 + 2 Work area
(FF_FS_TINY == 0)V*564
+ F*552V*564
+ F*552V*564
+ F*552V*560
+ F*546V*560
+ F*546V*560
+ F*546V*560
+ F*546V*564
+ F*552V*564
+ F*552V*564
+ F*552V*564
+ F*552 Work area
(FF_FS_TINY == 1)V*564
+ F*40V*564
+ F*40V*564
+ F*40V*560
+ F*34V*560
+ F*34V*560
+ F*34V*560
+ F*34V*564
+ F*40V*564
+ F*40V*564
+ F*40V*564
+ F*40

These are the memory usage of FatFs module without lower layer on some target systems in following condition. V denotes number of mounted volumes and F denotes number of open files. Every samples here are optimezed in code size.

-FatFs R0.13a options:
-FF_FS_READONLY   0 (Read/Write) or 1 (Read only)
-FF_FS_MINIMIZE   0 (Full, with all basic functions) or 3 (Min, with fully minimized)
+FatFs R0.15 options:
+FF_FS_READONLY   0 (R/W, read/write) or 1 (R/O, read only)
+FF_FS_MINIMIZE   0 (Def, with all basic functions) or 3 (Min, with fully minimized)
 FF_FS_TINY       0 (Default) or 1 (Tiny file object)
 And any other options are left unchanged from original setting.
 
@@ -108,9 +128,9 @@ And any other options are left unchanged from original setting.

Reducing Module Size

-

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.

+

Follwing table shows which API function is removed by configuration options to reduce the module size. To use an API function, the row of the function must be clear.

- + @@ -151,161 +171,169 @@ And any other options are left unchanged from original setting.

Long File Name

-

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 FF_USE_LFN to 1, 2 or 3, and add ffunicode.c to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by FF_MAX_LFN according to the available memory. The length of an LFN can be up to 255 characters, so that the FF_MAX_LFN 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 FR_INVALID_NAME. When use any re-entry to the API with LFN feature, FF_USE_LFN 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 (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.

-
FunctionFF_FS_
MINIMIZE
FF_FS_
READONLY
FF_USE_
STRFUNC
FF_FS_
RPATH
FF_USE_
FIND
FF_USE_
CHMOD
FF_USE_
EXPAND
FF_USE_
LABEL
FF_USE_
MKFS
FF_USE_
FORWARD
FF_MULTI_
PARTITION
FunctionFF_FS_
MINIMIZE
FF_FS_
READONLY
FF_USE_
STRFUNC
FF_FS_
RPATH
FF_USE_
FIND
FF_USE_
CHMOD
FF_USE_
EXPAND
FF_USE_
LABEL
FF_USE_
MKFS
FF_USE_
FORWARD
FF_MULTI_
PARTITION
0123010101201010101010101
f_mount
- - - - - - - - -
With LFN at CM3 + gcc
FF_CODE_PAGECode size
437-869 (SBCS)+3.3k
932 (Japanese)+62k
936 (Simplified Chinese)+177k
949 (Korean)+140k
950 (Traditional Chinese)+111k
0 (All code pages)+486k
-

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 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.

-

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.

-

There ware some restrictions on using LFN for open source project because the LFN extension on the FAT volume was a patent of Microsoft Corporation. The related patents have expired and using the LFN feature has got free for any projects.

-
- -
-

Unicode API

-

By default, FatFs uses ANSI/OEM code set on the API even at LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option FF_LFN_UNICODE. This means that FatFs is compliant with the full featured LFN specification. The data type TCHAR specifies path name strings on the API is an alias of either char(ANSI/OEM or UTF-8), WCHAR(UTF-16) or DWORD(UTF-32) depends on that option. For more information, refer to the description in the file name.

-

Note that setting of code page, FF_CODE_PAGE, has actually no meaning when FatFs is configured for the Unicode API. It should be set 437 anyway. However it still affects code conversion of string I/O functions at FF_STRF_ENCODE == 0 and backward compatibility with legacy systems, so that code page may need to be configured properly if it is considered a problem.

-
- -
-

exFAT Filesystem

-

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.

-

Note that the exFAT is a patent of Microsoft Corporation. The exFAT feature of FatFs is an implementation based on US. Pat. App. Pub. No. 2009/0164440 A1. FatFs module can switch the exFAT on or off by configuration option, FF_FS_EXFAT. When enable the exFAT on the commercial products, a license by Microsoft will be needed depends on the final destination of the products.

-

Remarks: Enabling exFAT discards C89 compatibility and wants C99 because of need for 64-bit integer type.

-
- -
-

Re-entrancy

-

The file operations of two tasks to the different volumes each other is always re-entrant regardless of the configurations except when LFN is enabled with static working buffer (FF_USE_LFN = 1). It can work concurrently without any mutual exclusion.

-

The file operations of two tasks to the same volume is not re-entrant in default. FatFs can also be configured to make it thread-safe by option FF_FS_REENTRANT. In this case, also the OS dependent synchronization control functions, ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant, need to be added to the project. There are some examples in the ffsystem.c. 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 FF_TIMEOUT, the file function will abort with FR_TIMEOUT. The timeout feature might not be supported on the some RTOSs.

-

There is an exception on the re-entrancy for f_mount/f_mkfs 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.

-
- - - - - - - - -
FunctionCase 1Case 2Case 3
disk_statusYesYesYes(*)
disk_initializeNoYesYes(*)
disk_readNoYesYes(*)
disk_writeNoYesYes(*)
disk_ioctlNoYesYes(*)
get_fattimeNoYesYes
- -

Case 1: Same volume.
-Case 2: Different volume on the same drive.
-Case 3: Different volume on the different drive.
-(*) In only different drive number. -

-
-
-

Remarks: This section describes on the re-entrancy of the FatFs module itself. The FF_FS_REENTRANT option enables only exclusive use of each filesystem objects and FatFs does not that prevent to re-enter the low level disk functions. Thus the low level disk I/O layer must be always thread-safe when FatFs API is re-entered for different volumes. Right table shows which low level function can be re-entered when any FatFs API is re-entered.

-
- -
-

Duplicated File Open

-

FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed or deleted. A violation of these rules can cause data collaption.

-

The file lock control can be enabled by FF_FS_LOCK option. The value of option defines the number of open objects to manage simultaneously. In this case, if any opening, renaming or removing against the file shareing rule that described above is attempted, the file function will be rejected with FR_LOCKED. If number of open objects, files and sub-directories, is equal to FF_FS_LOCK, an extra f_open/f_opendir function will fail with FR_TOO_MANY_OPEN_FILES.

-
- -
-

Performance Effective File Access

-

For good read/write throughput on the small embedded systems with limited size of memory, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by f_read function.

-

Figure 1. Sector unaligned read (short)
- -

-

Figure 2. Sector unaligned read (long)
- -

-

Figure 3. Fully sector aligned read
- -

-

The file I/O buffer is a sector buffer to read/write a part of data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the filesystem object. The buffer configuration option FF_FS_TINY determins which sector buffer is used for the file data transfer. When tiny buffer configuration (1) is selected, data memory consumption is reduced FF_MAX_SS bytes each file object. In this case, FatFs module uses only a sector buffer in the filesystem object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.

-

Figure 1 shows that a partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with disk_read function at a time but the multiple sector transfer is divided at cluster boundary even if it is contiguous.

-

Therefore taking effort to sector aligned read/write accesss eliminates buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.

-
- -
-

Considerations on Flash Memory Media

-

To maximize the write performance of flash memory media, such as SDC, CFC and U Disk, it must be controlled in consideration of its characteristitcs.

-

Using Mutiple-Sector Write

-
-Figure 6. Comparison between Multiple/Single Sector Write
-fig.6 -
-

The write throughput of the flash memory media becomes the worst at single sector write transaction. The write throughput increases as the number of sectors per a write transaction as shown in Figure 6. This effect more appers at faster interface speed and the performance ratio often becomes grater than ten. This result is clearly explaining how fast is multiple block write (W:16K, 32 sectors) than single block write (W:100, 1 sector), and also larger card tends to be slow at single block write. Number of write transactions also affects life time of the flash memory media. When compared at same amount of write data, the single sector write in Figure 6 above wears flash memory media 16 times more than multiple sector write in Figure 6 below. Single sector write is pretty pain for the flash memory media.

-

Therefore the application program should write the data in large block as possible. The ideal write chunk size and alighment is size of sector, and size of cluster is the best. Of course all layers between the application and the storage device must have consideration on multiple sector write, however most of open-source memory card drivers lack it. Do not split a multiple sector write request into single sector write transactions or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write operation.

-

Forcing Memory Erase

-

When remove a file with f_unlink function, the data clusters occupied by the file are marked 'free' on the FAT. But the data sectors containing the file data are not that applied any process, so that the file data left occupies a part of the flash memory array as 'live block'. If the file data can be erased on removing the file, those data blocks will be turned into the free block pool. This may skip internal block erase operation to the data block on next write operation. As the result the write performance might be improved. FatFs can manage this function by setting FF_USE_TRIM to 1. Note that this is an expectation of internal process of the storage device and not that always effective. Most applications will not need this function. Also f_unlink function can take a time when remove a large file.

-
- -
-

Critical Section

-

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.

-
-Figure 4. Long critical section
-fig.4 -
-
-Figure 5. Minimized critical section
-fig.5 -
-
-

An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.

- -

Each case does not affect any file not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using f_sync function as shown in Figure 5.

-
- -
-

Extended Use of FatFs API

-

These are examples of extended use of FatFs APIs. New item will be added whenever a useful code is found.

-
    -
  1. Open or create a file for append (for R0.12 and earlier)
  2. -
  3. Delete a non-empty sub-directory (for R0.12 and later)
  4. -
  5. Allocate contiguous area to the file (for R0.11a and earlier)
  6. -
  7. Test if the file is contiguous or not
  8. -
  9. Compatibility checker for low level disk I/O module
  10. -
  11. Performance checker for low level disk I/O module
  12. -
  13. FAT volume image creator
  14. -
-
- -
-

About FatFs License

-

FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that included in the source files.

-
-/*----------------------------------------------------------------------------/
-/  FatFs - Generic FAT Filesystem Module  Rx.xx                               /
-/-----------------------------------------------------------------------------/
-/
-/ Copyright (C) 20xx, 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
-/ that the following condition is met:
-/
-/ 1. Redistributions of source code must retain the above copyright notice,
-/    this condition and the following disclaimer.
-/
-/ This software is provided by the copyright holder and contributors "AS IS"
-/ and any warranties related to this software are DISCLAIMED.
-/ The copyright owner or contributors be NOT LIABLE for any damages caused
-/ by use of this software.
-/----------------------------------------------------------------------------*/
-
-

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.

-
- -

Return Home

- - +

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 FF_USE_LFN to 1, 2 or 3, and add ffunicode.c to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by FF_MAX_LFN according to the available memory. The length of LFN can be up to 255 characters, so that the FF_MAX_LFN should be set to 255 for any existing file names. If the size of working buffer is insufficient for the input file name, the file function fails with FR_INVALID_NAME. When use any re-entry to the API with LFN feature in RTOS environment, FF_USE_LFN 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 (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.

+

Impact upon Module Size

+ + + + + + + + + +
With LFN at CM3 + gcc
FF_CODE_PAGECode size
437-869 (SBCS)+3.3k
932 (Japanese)+62k
936 (Simplified Chinese)+177k
949 (Korean)+140k
950 (Traditional Chinese)+111k
0 (All code pages)+486k
+

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.

+

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 API with any SBCS code page.

+

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. However the related patents all have expired and using the LFN feature is free for any projects.

+ + +
+

Unicode API

+

By default, FatFs uses ANSI/OEM code set on the API even in LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option FF_LFN_UNICODE. This means that FatFs is compliant with the full featured LFN specification. The data type TCHAR specifies path name strings on the API is an alias of either char(ANSI/OEM or UTF-8), WCHAR(UTF-16) or DWORD(UTF-32) depends on that option. For more information, refer to the description in the file name.

+

Note that setting of code page, FF_CODE_PAGE, has actually no meaning when FatFs is configured for the Unicode API. It should be set 437 to reduce the module size. However it still affects code conversion of string I/O functions when FF_STRF_ENCODE == 0, and also backward compatibility with legacy systems. In this case, the code page may need to be configured properly if it is considered a problem.

+
+ +
+

exFAT Filesystem

+

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.

+

Note that the exFAT filesystem is a patent of Microsoft Corporation. The exFAT feature of FatFs is an implementation based on US. Pat. App. Pub. No. 2009/0164440 A1. FatFs module can switch the exFAT on or off by a configuration option, FF_FS_EXFAT. When enable the exFAT for the commercial products, a license by Microsoft will be needed depends on the final destination of the products.

+

Remarks: Enabling exFAT discards C89 compatibility and it wants C99 because of need for 64-bit integer type.

+
+ +
+

64-bit LBA

+

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 sector, 1 as the second sector and so on. 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 in the most LBA scheme. It can address up to 232 sectors, 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 sectors of the storage device.

+

By default, FatFs works in 32-bit LBA for media access. FatFs can also switch it to 64-bit LBA by a configuration option FF_LBA64. It also enables GPT (GUID Partition Table) for partiotion management on the storage device. For further information about GPT, refer to f_mkfs and f_fdisk function.

+
+ +
+

Re-entrancy

+

The file operations of two tasks to the different volumes each other is always re-entrant and it can work concurrently without any mutual exclusion regardless of the configurations except when LFN is enabled with static working buffer (FF_USE_LFN = 1).

+

The file operations of two tasks to the same volume is not thread-safe by default. FatFs can also be configured to make it thread-safe by an option FF_FS_REENTRANT. 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 FF_TIMEOUT, the file function will abort with FR_TIMEOUT. The timeout feature might not be supported on the some OSs. To enable this feature, OS dependent synchronization control functions, ff_mutex_create/ff_mutex_delete/ff_mutex_take/ff_mutex_give, need to be added to the project. There is an example code in the ffsystem.c for some OSs.

+

Note that there is an exception on the re-entrancy for f_mount and f_mkfs function. You will know why it is. These volume management functions are always not thread-safe to the volume being processed. When use these functions, other tasks need to avoid to access the corresponding volume.

+
+ + + + + + + + +
FunctionCase 1Case 2Case 3
disk_statusYesYesYes(*)
disk_initializeNoYesYes(*)
disk_readNoYesYes(*)
disk_writeNoYesYes(*)
disk_ioctlNoYesYes(*)
get_fattimeNoYesYes
+ +Case 1: Same volume.
+Case 2: Different volume on the same drive.
+Case 3: Different volume on the different drive.
+(*) In only different drive number. +
+
+

Remarks: This section describes on the re-entrancy of the FatFs module itself. The FF_FS_REENTRANT 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.

+
+ +
+

Duplicated File Open

+

FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed or deleted. A violation of these rules can cause data collaption.

+

The file lock control can be enabled by FF_FS_LOCK option. The value of option defines the number of open objects to manage simultaneously. In this case, if any opening, renaming or removing against the file shareing rule that described above is attempted, the file function will be rejected with FR_LOCKED. If number of open objects, files and sub-directories, is equal to FF_FS_LOCK, an extra f_open/f_opendir function will fail with FR_TOO_MANY_OPEN_FILES.

+
+ +
+

Performance Effective File Access

+

For good read/write throughput on the small embedded systems with limited size of memory, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by f_read function.

+

Figure 1. Sector unaligned read (short)
+ +

+

Figure 2. Sector unaligned read (long)
+ +

+

Figure 3. Fully sector aligned read
+ +

+

The file I/O buffer is a sector buffer to read/write a part of data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the filesystem object. The buffer configuration option FF_FS_TINY determins which sector buffer is used for the file data transfer. When tiny buffer configuration (1) is selected, data memory consumption is reduced FF_MAX_SS bytes each file object. In this case, FatFs module uses only a sector buffer in the filesystem object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.

+

Figure 1 shows that a partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with disk_read function at a time but the multiple sector transfer is divided at cluster boundary even if it is contiguous.

+

Therefore taking effort to sector aligned read/write accesss eliminates buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.

+
+ +
+

Considerations on Flash Memory Media

+

To maximize the write performance of flash memory media, such as SDC, CFC and U Disk, it must be controlled in consideration of its characteristitcs.

+

Using Mutiple-Sector Write

+
+Figure 6. Comparison between Multiple/Single Sector Write
+fig.6 +
+

The write throughput of the flash memory media becomes the worst at single sector write transaction. The write throughput increases as the number of sectors per a write transaction as shown in Figure 6. This effect more appers at faster interface speed and the performance ratio often becomes grater than ten. This result is clearly explaining how fast is multiple block write (W:16K, 32 sectors) than single block write (W:100, 1 sector), and also larger card tends to be slow at single block write. Number of write transactions also affects life time of the flash memory media. When compared at same amount of write data, the single sector write in Figure 6 above wears flash memory media 16 times more than multiple sector write in Figure 6 below. Single sector write is pretty pain for the flash memory media.

+

Therefore the application program should write the data in large block as possible. The ideal write chunk size and alighment is size of sector, and size of cluster is the best. Of course all layers between the application and the storage device must have consideration on multiple sector write, however most of open-source memory card drivers lack it. Do not split a multiple sector write request into single sector write transactions or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write operation.

+

Forcing Memory Erase

+

When remove a file with f_unlink function, the data clusters occupied by the file are marked 'free' on the FAT. But the data sectors containing the file data are not that applied any process, so that the file data left occupies a part of the flash memory array as 'live block'. If the file data can be erased on removing the file, those data blocks will be turned into the free block pool. This may skip internal block erase operation to the data block on next write operation. As the result the write performance might be improved. FatFs can manage this function by setting FF_USE_TRIM to 1. Note that because this effect is from an expectation of internal process of the storage device, it is not that always effective. Most applications will not need this function. Also f_unlink function can take a time when remove a large file.

+
+ +
+

Critical Section

+

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.

+
+Figure 4. Long critical section
+fig.4 +
+
+Figure 5. Minimized critical section
+fig.5 +
+
+

An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.

+ +

Each case does not affect any file not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using f_sync function as shown in Figure 5.

+
+ +
+

Various Usable Functions for FatFs Projects

+

These are examples of extended use of FatFs APIs. New item will be added when useful code example is found.

+
    +
  1. Open or Create File for Append (superseded by FA_OPEN_APPEND flag added at R0.12)
  2. +
  3. Delete Non-empty Sub-directory (for R0.12 and later)
  4. +
  5. Create Contiguous File (superseded by f_expand function added at R0.12)
  6. +
  7. Test if the File is Contiguous or Not
  8. +
  9. Compatibility Checker for Storage Device Control Module
  10. +
  11. Performance Checker for Storage Device Control Module
  12. +
  13. FAT Volume Image Creator (Pre-creating built-in FAT volume)
  14. +
  15. Virtual Drive Feature (refer to lpc176x/ in ffsample.zip)
  16. +
  17. Embedded Unicode String Utilities (OEMxxx→Unicode, Unicode→OEMxxx, Unicode→Unicode)
  18. +
+
+ +
+

About FatFs License

+

FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that included in the source files.

+
+/*----------------------------------------------------------------------------/
+/  FatFs - Generic FAT Filesystem Module  Rx.xx                               /
+/-----------------------------------------------------------------------------/
+/
+/ Copyright (C) 20xx, 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
+/ that the following condition is met:
+/
+/ 1. Redistributions of source code must retain the above copyright notice,
+/    this condition and the following disclaimer.
+/
+/ This software is provided by the copyright holder and contributors "AS IS"
+/ and any warranties related to this software are DISCLAIMED.
+/ The copyright owner or contributors be NOT LIABLE for any damages caused
+/ by use of this software.
+/----------------------------------------------------------------------------*/
+
+

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 includes 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.

+
+ +

Return Home

+ + diff --git a/documents/doc/chdir.html b/documents/doc/chdir.html index 072b9e958a2b5385f0e8d2b52de6cc4abb54096a..93e116c394676511919f26d5f54cb5ac4c7b1358 100644 --- a/documents/doc/chdir.html +++ b/documents/doc/chdir.html @@ -25,7 +25,7 @@ FRESULT f_chdir (

Parameters

path
-
Pointer to the null-terminated string that specifies the directory to go.
+
Pointer to the null-terminated string that specifies the directory to be set as current directory.
@@ -50,7 +50,7 @@ FRESULT f_chdir (

Description

-

The f_chdir function changes the current directory of the logical drive. Also the current drive is changed at Unix style volume ID, FF_STR_VOLUME_ID == 2. The current directory of each logical drive is initialized to the root directory on mount.

+

The f_chdir function changes the current directory of the logical drive. Also the current drive will be changed when in Unix style drive prefix, FF_STR_VOLUME_ID == 2. The current directory of each logical drive is initialized to the root directory on mount.

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.

diff --git a/documents/doc/chdrive.html b/documents/doc/chdrive.html index fb1c32fa9bdb7b8fc435000fef830bbfdff8134c..4dfc7d86d7c76a845a00bf5afe4f037ef5e30f1f 100644 --- a/documents/doc/chdrive.html +++ b/documents/doc/chdrive.html @@ -41,7 +41,7 @@ FRESULT f_chdrive (

Description

-

The f_chdrive function changes only the current drive. The initial value of the current drive number is 0. Note that the current drive is retained in a static variable, so that it also affects other tasks that using the file functions.

+

The f_chdrive function changes only the current drive. The initial value of the current drive number is 0. In Unix style drive prefix configuration, this function will not be needed because f_chdir function changes also the current drive. Note that the current drive is retained in a static variable, so that it also affects other tasks that using the file functions.

@@ -56,8 +56,6 @@ FRESULT f_chdrive ( f_chdrive("2:"); /* Set drive 2 as current drive */ f_chdrive(""); /* No effect (set current drive as current drive) */ - - f_chdrive("/flash"); /* Set drive "flash" as current drive (at Unix style volume ID) */
diff --git a/documents/doc/config.html b/documents/doc/config.html index aaabf4865d422d99d8db7280ac69531e8334632f..788e07563cf233015199dd279d73f40d43701113 100644 --- a/documents/doc/config.html +++ b/documents/doc/config.html @@ -11,13 +11,12 @@

Configuration Options

-

There are many options to configure the functions of FatFs for requirement of each project. The configuration options are defined in the ffconf.h.

+

There are many options to configure the features of FatFs for various requirements of each project. The configuration options are defined in ffconf.h.

@@ -45,8 +47,9 @@
  • FF_VOLUME_STRS
  • FF_MULTI_PARTITION
  • FF_MIN_SS, FF_MAX_SS
  • +
  • FF_LBA64
  • +
  • FF_GPT_MIN
  • FF_USE_TRIM
  • -
  • FF_FS_NOFSINFO
  • System Configurations @@ -55,6 +58,7 @@
  • FF_FS_EXFAT
  • FF_FS_NORTC
  • FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR
  • +
  • FF_FS_NOFSINFO
  • FF_FS_LOCK
  • FF_FS_REENTRANT
  • FF_FS_TIMEOUT
  • @@ -79,15 +83,6 @@ 3f_lseek function is removed in addition to 2. -

    FF_USE_STRFUNC

    -

    This option switches string functions, f_gets, f_putc, f_puts and f_printf.

    - - - - - -
    ValueDescription
    0Disable string functions.
    1Enable string functions without LF-CRLF conversion.
    2Enable string functions with LF-CRLF conversion.
    -

    FF_USE_FIND

    Disable (0) or Enable (1) filtered directory read functions, f_findfirst and f_findnext. Also FF_FS_MINIMIZE needs to be 0 or 1.

    @@ -109,6 +104,38 @@

    FF_USE_FORWARD

    Disable (0) or Enable (1) f_forward function.

    +

    FF_USE_STRFUNC

    +

    This option switches string functions, f_gets, f_putc, f_puts and f_printf. These functions are equivalents of regular string stream I/O functions in POSIX. If sprintf is available and code conversion is not needed, f_write with sprintf will be efficient in code size and performance rather than f_printf. When enable this feature, stdarg.h is included in ff.c.

    + + + + + +
    ValueDescription
    0Disable string functions.
    1Enable string functions without LF-CRLF conversion.
    2Enable string functions with LF-CRLF conversion.
    + + +

    This option switches support for long long integer argument in f_printf.

    +

    Disable (0) or Enable (1). When enable this feature, C standard needs to be C99 or later.

    + + +

    This option switches support for floating point argument in f_printf. When enable this feature, C standard needs to be C99 or later and math.h is included in ff.c.

    + + + + + +
    ValueDescription
    0Disable floating point argument.
    1Enable floating point argument in type 'f', 'e' and 'E'.
    2Enable it with decimal separator ',' instead of '.'.
    + +

    FF_STRF_ENCODE

    +

    When character encoding on the API is Unicode (FF_LFN_UNICODE >= 1), string I/O functions enabled by FF_USE_STRFUNC convert the character encoding in it. This option defines the assumption of character encoding on the file to be read/written via those functions. When LFN is not enabled or FF_LFN_UNICODE == 0, the string functions work without any code conversion and this option has no effect.

    + + + + + + +
    ValueCharacter encoding on the file
    0ANSI/OEM in current code page
    1Unicode in UTF-16LE
    2Unicode in UTF-16BE
    3Unicode in UTF-8
    + @@ -116,7 +143,7 @@

    Namespace and Locale Configurations

    FF_CODE_PAGE

    -

    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.

    +

    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 the path name or FF_LFN_UNICODE != 0, there is no difference between any code page settings. Set it 437 anyway.

    @@ -154,10 +181,10 @@
    ValueCode page
    0Includes all code pages below and set by f_setcp()

    FF_MAX_LFN

    -

    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 (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 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.

    +

    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 characters (actually in UTF-16 code units) of the LFN. The buffer occupies (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 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.

    FF_LFN_UNICODE

    -

    This option switches character encoding for the file name on the API. When Unicode is selected, FF_CODE_PAGE 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.

    +

    This option switches character encoding for the file name on the API. FatFs supports the code point up to U+10FFFF. This option also affects behavior of string I/O functions (see FF_STRF_ENCODE).

    @@ -165,35 +192,26 @@
    ValueCharacter EncodingTCHAR
    0ANSI/OEM in current CPchar
    2Unicode in UTF-8char
    3Unicode in UTF-32DWORD
    -

    This option also affects behavior of string I/O functions (see FF_STRF_ENCODE). When LFN is not enabled, this option has no effect and FatFs works at ANSI/OEM code on the API. For more information, read here.

    +

    When Unicode is selected, FF_CODE_PAGE has actually no meaning except for compatibility with legacy systems, such as MS-DOS and any system without support for LFN.

    +

    When LFN is not enabled, this option has no effect and FatFs works in ANSI/OEM code on the API. For more information, read here.

    FF_LFN_BUF, FF_SFN_BUF

    -

    This set of options defines size of file name members, fname[] and altname[], in the FILINFO structure which is used to read out the directory items. These values should be suffcient for the file names to read. The maximum possible length of read file name depends on the character encoding on the API as follows:

    +

    This set of options defines size of file name members, fname[] and altname[], in the FILINFO structure which is used to read out the directory items. These values should be suffcient for the file names to read. The maximum possible length of read file name depends on the character encoding scheme on the API as follows:

    - - + +
    EncodingLFN lengthSFN length
    ANSI/OEM at SBCS255 items12 items
    ANSI/OEM at DBCS510 items12 items
    ANSI/OEM in SBCS255 items12 items
    ANSI/OEM in DBCS510 items12 items
    Unicode in UTF-16/32255 items12 items
    Unicode in UTF-8765 items34 items

    If the size of name member is insufficient for the LFN, the item is treated as without LFN. When LFN is not enabled, these options have no effect.

    -

    FF_STRF_ENCODE

    -

    When character encoding on the API is Unicode (FF_LFN_UNICODE >= 1), string I/O functions, f_gets, f_putc, f_puts and f_printf, convert the character encoding in it. This option defines the assumption of character encoding on the file to be read/written via those functions. When LFN is not enabled or FF_LFN_UNICODE == 0, the string functions work without any encoding conversion and this option has no effect.

    - - - - - - -
    ValueCharacter encoding on the file
    0ANSI/OEM in current code page
    1Unicode in UTF-16LE
    2Unicode in UTF-16BE
    3Unicode in UTF-8
    -

    FF_FS_RPATH

    This option configures relative path function. For more information, read here.

    - - + +
    ValueDescription
    0Disable relative path function and remove related functions.
    1Enable relative path function. f_chdir and f_chdrive function is available.
    0Disable relative path and remove related functions.
    1Enable relative path. f_chdir and f_chdrive function is available.
    2f_getcwd function is available in addition to 1
    @@ -204,13 +222,13 @@

    Volume/Drive Configurations

    FF_VOLUMES

    -

    This option configures number of volumes (logical drives upto 10) to be used.

    +

    This option configures number of volumes (logical drives up to 10) to be used.

    FF_STR_VOLUME_ID

    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 FF_VOLUME_STRS 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.

    - +
    ValueDescriptionExample
    0Only DOS/Windows style drive prefix in numeric ID can be used.0:/filename
    0Only DOS/Windows style drive prefix in numeric ID can be used.1:/filename
    1Also DOS/Windows style drive prefix in string ID can be used.flash:/filename
    2Also Unix style drive prefix in string ID can be used./flash/filename
    @@ -218,29 +236,25 @@

    FF_VOLUME_STRS

    This option defines the volume ID strings for each logical drives. Number of items must not be less than FF_VOLUMES. Valid characters for the volume ID string are A-Z, a-z and 0-9, however, they are compared in case-insensitive. If FF_STR_VOLUME_ID == 0, this option has no effect. If FF_STR_VOLUME_ID >= 1 and this option is not defined, a user defined volume string table needs to be defined as shown below. The table should not be modified on the fly.

    -/* User defined volume ID strings for 0:    1:      2:    3:   ... */
    -const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"};
    +/* User defined volume ID strings for 0: to 3: */
    +const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb"};
     

    FF_MULTI_PARTITION

    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 VolToPart[]. Also f_fdisk funciton will be available. For more information, read here.

    FF_MIN_SS, FF_MAX_SS

    -

    This set of options defines the extent of sector size used on the low level disk I/O interface, disk_read and disk_write function. Valid values are 512, 1024, 2048 and 4096. FF_MIN_SS defines minimum sector size and FF_MAX_SS 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 FF_MAX_SS > FF_MIN_SS, support of variable sector size is enabled and GET_SECTOR_SIZE command needs to be implemented to the disk_ioctl function.

    +

    This set of options defines the extent of sector size used for the low level disk I/O interface, disk_read and disk_write function. Valid values are 512, 1024, 2048 and 4096. FF_MIN_SS defines minimum sector size and FF_MAX_SS 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 FF_MAX_SS > FF_MIN_SS, support of variable sector size is enabled and GET_SECTOR_SIZE command needs to be implemented to the disk_ioctl function.

    + +

    FF_LBA64

    +

    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.

    + +

    FF_MIN_GPT

    +

    This option specifies the threshold of determination of partitioning format when create patitions on the drive in f_mkfs and f_fdisk function. When number of available sectors is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when FF_LBA64 == 0.

    FF_USE_TRIM

    Disable (0) or Enable (1). This option switches ATA-TRIM function. To enable Trim function, also CTRL_TRIM command should be implemented to the disk_ioctl function.

    -

    FF_FS_NOFSINFO

    -

    0 to 3. 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.

    - - - - - - -
    ValueDescription
    bit0=0Use free cluster count in the FSINFO if available.
    bit0=1Do not trust free cluster count in the FSINFO.
    bit1=0Use last allocated cluster number in the FSINFO to find a free cluster if available.
    bit1=1Do not trust last allocated cluster number in the FSINFO.
    - @@ -248,33 +262,40 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"};

    System Configurations

    FF_FS_TINY

    -

    Normal (0) or Tiny (1). At the tiny configuration, size of the file object FIL is reduced FF_MAX_SS bytes. Instead of private data buffer eliminated from the file object, common sector buffer in the filesystem object FATFS is used for the file data transfer.

    +

    Normal (0) or Tiny (1). The tiny configuration reduces size of the FIL structure, file object, FF_MAX_SS bytes each. Instead of private sector buffer eliminated from the file object, common sector buffer in the FATFS structure, filesystem object, is used for the file data transfer.

    FF_FS_EXFAT

    -

    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 FF_LFN_UNICODE >= 1 and FF_MAX_LFN == 255 is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.

    +

    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 FF_LFN_UNICODE >= 1 and FF_MAX_LFN == 255 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.

    FF_FS_NORTC

    -

    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 FF_FS_NORTC to 1 to disable the timestamp function. Every objects modified by FatFs will have a fixed timestamp defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR. To use the timestamp function, set FF_FS_NORTC == 0 and add get_fattime function to the project to get current time form the RTC. This option has no effect at read-only configuration.

    +

    Use RTC (0) or Do not use RTC (1). This option controls timestamp featuer. If the system does not have an RTC or valid timestamp is not needed, set FF_FS_NORTC to 1 to disable the timestamp function. Every objects modified by FatFs will have a constant timestamp defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR. To use the timestamp featuer, set FF_FS_NORTC == 0 and add get_fattime function to the project to get current time form the RTC. This option has no effect in read-only configuration.

    FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR

    -

    This set of options defines the time to be used at no RTC systems. This option has no effect at read-only configuration or FF_FS_NORTC == 0.

    +

    This set of options defines the time to be used in no RTC systems. This option has no effect in read-only configuration or FF_FS_NORTC == 0.

    + +

    FF_FS_NOFSINFO

    +

    0 to 3. 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 the volume mounted will force a full FAT scan. Bit 1 controls the use of last allocated cluster number for new allocation.

    + + + + + + +
    ValueDescription
    bit0=0Use free cluster count in the FSINFO if available.
    bit0=1Do not trust free cluster count in the FSINFO.
    bit1=0Use last allocated cluster number in the FSINFO to find a free cluster if available.
    bit1=1Do not trust last allocated cluster number in the FSINFO.

    FF_FS_LOCK

    -

    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.

    +

    This option switches file lock feature to control duplicated file open and illegal operations to the open objects. Note that this feature is independent of re-entrancy. This option must be 0 in read-only configuration.

    - - + +
    ValueDescription
    0Disable file lock function. To avoid collapsing file by wrong file operation, application program needs to avoid illegal open, remove and rename to the open objects.
    >0Enable file lock function. The value defines how many files/sub-directories can be opened simultaneously under the file lock control. Illigal operations to the open object will be rejected with FR_LOCKED.
    0Disable file lock feature. To avoid to collapse files due to wrong file operations, application program needs to avoid illegal open, remove and rename to the open objects.
    >0Enable file lock feature. The value defines how many files/sub-directories can be opened simultaneously under the file lock feature. Illigal operations to the open object will be rejected with FR_LOCKED.

    FF_FS_REENTRANT

    -

    Disable (0) or Enable (1). This option switches the re-entrancy (thread safe) of the FatFs module itself. Note that file/directory access to the different volume is always re-entrant and it can work simultaneously regardless of this option, however, volume management functions, f_mount, f_mkfs and f_fdisk, are always not re-entrant. Only file/directory access to the same volume, in other words, exclusive use of each filesystem object, is under control of this function. To enable this feature, also user provided synchronization handlers, ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj, need to be added to the project. Sample code is available in ffsystem.c.

    +

    Disable (0) or Enable (1). This option switches the re-entrancy (thread safe) of the FatFs module itself. Note that file/directory access to the different volume is always re-entrant and it can work simultaneously regardless of this option, however, volume management functions, f_mount, f_mkfs and f_fdisk, are always not re-entrant. Only file/directory access to the same volume, in other words, exclusive use of each filesystem object, is under control in this feature. To enable this feature, also user provided synchronization handlers, ff_mutex_take, ff_mutex_give, ff_mutex_create and ff_mutex_delete, need to be added to the project. Sample code is available in ffsystem.c.

    FF_FS_TIMEOUT

    -

    Number of time ticks to abort the file function with FR_TIMEOUT when wait time is too long. This option has no effect when FF_FS_REENTRANT == 0.

    - -

    FF_SYNC_t

    -

    This option defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, SemaphoreHandle_t and etc. A header file for O/S definitions needs to be included somewhere in the scope of ff.c. This option has no effect when FF_FS_REENTRANT == 0.

    +

    Number of O/S time ticks to abort the file function with FR_TIMEOUT when the wait time exceeds this period. This option has no effect when FF_FS_REENTRANT == 0.

    diff --git a/documents/doc/dinit.html b/documents/doc/dinit.html index a7718bcde5ec4a7eae7ca4389a5d329cc450d26a..c668c66b29dba5e03b3939c4f3dbfdc8d9c8619f 100644 --- a/documents/doc/dinit.html +++ b/documents/doc/dinit.html @@ -38,7 +38,7 @@ DSTATUS disk_initialize (

    Description

    This function initializes the storage device and put it ready to generic read/write. When the function succeeded, STA_NOINIT flag in the return value is cleared.

    -

    Remarks: This function needs to be under control of FatFs module. Application program MUST NOT call this function, or FAT structure on the volume can be broken. To re-initialize the filesystem, use f_mount function instead.

    +

    Remarks: This function needs to be under control of FatFs module. Application program MUST NOT call this function while FatFs is in use, or FAT structure on the volume can be broken. To re-initialize the filesystem, use f_mount function instead.

    Return

    diff --git a/documents/doc/dioctl.html b/documents/doc/dioctl.html index fc8543c75f83942afe6f78cbb06174f9177432da..fc5f24cc46cee5ca07563f72e71ba070227ea7d6 100644 --- a/documents/doc/dioctl.html +++ b/documents/doc/dioctl.html @@ -57,35 +57,35 @@ DRESULT disk_ioctl ( - - - - - + + + + +
    Standard ioctl command used by FatFs
    CommandDescription
    CTRL_SYNCMake sure that the device has finished pending write process. If the disk I/O module or storage device has a write-back cache, the cached data marked dirty 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 disk_write function.
    GET_SECTOR_COUNTReturns number of available sectors on the drive into the DWORD variable pointed by buff. This command is used by f_mkfs and f_fdisk function to determine the volume/partition size to be created. Required at FF_USE_MKFS == 1.
    GET_SECTOR_SIZEReturns sector size of the device into the WORD variable pointed by buff. Valid return values for this command are 512, 1024, 2048 and 4096. This command is required only if FF_MAX_SS > FF_MIN_SS. When FF_MAX_SS == FF_MIN_SS, this command is never used and the device must work at that sector size.
    GET_BLOCK_SIZEReturns erase block size of the flash memory media in unit of sector into the DWORD variable pointed by buff. 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 f_mkfs function and it attempts to align data area on the erase block boundary. Required at FF_USE_MKFS == 1.
    CTRL_TRIMInforms 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 DWORD array {<start sector>, <end sector>} pointed by buff. 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 f_mkfs function. Required at FF_USE_TRIM == 1.
    CTRL_SYNCMakes 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 the medium immediately. Nothing to do for this command if each write operation to the medium is completed in the disk_write function.
    GET_SECTOR_COUNTRetrieves number of available sectors, the largest allowable LBA + 1, on the drive into the LBA_t variable that pointed by buff. This command is used by f_mkfs and f_fdisk function to determine the size of volume/partition to be created. It is required when FF_USE_MKFS == 1.
    GET_SECTOR_SIZERetrieves sector size, minimum data unit for generic read/write, into the WORD variable that pointed by buff. Valid sector sizes are 512, 1024, 2048 and 4096. This command is required only if FF_MAX_SS > FF_MIN_SS. When FF_MAX_SS == FF_MIN_SS, this command will be never used and the read/write function must work in FF_MAX_SS bytes/sector.
    GET_BLOCK_SIZERetrieves erase block size in unit of sector of the flash memory media into the DWORD variable that pointed by buff. The allowable value is 1 to 32768 in power of 2. Return 1 if the value is unknown or non flash memory media. This command is used by only f_mkfs function and it attempts to align data area on the suggested block boundary. It is required when FF_USE_MKFS == 1. Note that FatFs does not have FTL (flash translation layer). Either disk I/O layter or storage device must have an FTL in it.
    CTRL_TRIMInforms the disk I/O layter or the storage device that the data on the block of sectors is no longer needed and it can be erased. The sector block is specified in an LBA_t array {<Start LBA>, <End LBA>} that pointed by buff. 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 f_mkfs function. It is required when FF_USE_TRIM == 1.
    -

    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.

    +

    FatFs will never use any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.

    - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
    Example of optional ioctl command
    CommandDescription
    CTRL_FORMATCreate a physical format on the media. If buff is not null, it is pointer to the call-back function for progress notification.
    CTRL_POWER_IDLEPut the device idle state. STA_NOINIT in the current status flags may not be set if the device goes active state by generic read/write function.
    CTRL_POWER_OFFPut the device off state. Shut-down the power to the device and deinitialize the device interface if needed. STA_NOINIT in the current status flags must be set. The device goes active state by disk_initialize function.
    CTRL_LOCKLock media eject mechanism.
    CTRL_UNLOCKUnlock media eject mechanism.
    CTRL_EJECTEject media cartridge. STA_NOINIT and STA_NODISK in status flag are set after the function succeeded.
    CTRL_GET_SMARTRead SMART information.
    MMC_GET_TYPEGet card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by buff. (MMC/SDC specific command)
    MMC_GET_CSDRead CSD register into a 16-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_CIDRead CID register into a 16-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_OCRRead OCR register into a 4-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_SDSTATRead SDSTATUS register into a 64-byte buffer pointed by buff. (SDC specific command)
    ATA_GET_REVGet the revision string into a 16-byte buffer pointed by buff. (ATA/CFC specific command)
    ATA_GET_MODELGet the model string into a 40-byte buffer pointed by buff. (ATA/CFC specific command)
    ATA_GET_SNGet the serial number string into a 20-byte buffer pointed by buff. (ATA/CFC specific command)
    ISDIO_READRead a block of iSDIO registers specified by command structure pointed by buff. (FlashAir specific command)
    ISDIO_WRITEWrite a block of data to iSDIO registers specified by command structure pointed by buff. (FlashAir specific command)
    ISDIO_MRITEChange bits in an iSDIO register specified by command structure pointed by buff. (FlashAir specific command)
    CTRL_FORMATCreates a physical format on the media. If buff is not null, it is pointer to the call-back function for progress notification.
    CTRL_POWER_IDLEPuts the device idle state. STA_NOINIT in the current status flags may not be set if the device goes active state by generic read/write function.
    CTRL_POWER_OFFPuts the device off state. Shut-down the power to the device and deinitialize the device interface if needed. STA_NOINIT in the current status flags must be set. The device goes active state by disk_initialize function.
    CTRL_LOCKLocks media eject mechanism.
    CTRL_UNLOCKUnlocks media eject mechanism.
    CTRL_EJECTEjects media cartridge. STA_NOINIT and STA_NODISK in status flag are set after the function succeeds.
    CTRL_GET_SMARTReads SMART information.
    MMC_GET_TYPEGets card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by buff. (MMC/SDC specific command)
    MMC_GET_CSDReads CSD register and sets it into a 16-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_CIDReads CID register and sets it into a 16-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_OCRReads OCR register and sets it into a 4-byte buffer pointed by buff. (MMC/SDC specific command)
    MMC_GET_SDSTATReads SDSTATUS register and sets it into a 64-byte buffer pointed by buff. (SDC specific command)
    ATA_GET_REVReads the revision string and sets it into a 16-byte buffer pointed by buff. (ATA/CFC specific command)
    ATA_GET_MODELReads the model string and sets it into a 40-byte buffer pointed by buff. (ATA/CFC specific command)
    ATA_GET_SNReads the serial number string and sets it into a 20-byte buffer pointed by buff. (ATA/CFC specific command)
    ISDIO_READReads a block of iSDIO registers specified by command structure pointed by buff. (FlashAir specific command)
    ISDIO_WRITEWrites a block of data to iSDIO registers specified by command structure pointed by buff. (FlashAir specific command)
    ISDIO_MRITEChanges bits in an iSDIO register specified by command structure pointed by buff. (FlashAir specific command)
    diff --git a/documents/doc/dread.html b/documents/doc/dread.html index f2d37a4b8af25d99a49d3f76b88772ea26b7c7a3..1be191b28561d0370d6872a42ca365dcd63295b9 100644 --- a/documents/doc/dread.html +++ b/documents/doc/dread.html @@ -13,12 +13,12 @@

    disk_read

    -

    The disk_read function is called to read data from the sector(s) of storage device.

    +

    The disk_read function is called to read data from the storage device.

     DRESULT disk_read (
       BYTE pdrv,     /* [IN] Physical drive number */
       BYTE* buff,    /* [OUT] Pointer to the read data buffer */
    -  DWORD sector,  /* [IN] Start sector number */
    +  LBA_t sector,  /* [IN] Start sector number */
       UINT count     /* [IN] Number of sectros to read */
     );
     
    @@ -32,7 +32,7 @@ DRESULT disk_read (
    buff
    Pointer to the first item of the byte array to store read data. Size of read data will be the sector size * count bytes.
    sector
    -
    Start sector number in 32-bit LBA.
    +
    Start sector number in LBA. The data type LBA_t is an alias of DWORD or QWORD depends on the configuration option.
    count
    Number of sectors to read.
    @@ -56,13 +56,14 @@ DRESULT disk_read (

    Description

    -

    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 sector. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (FF_MIN_SS == FF_MAX_SS, this is the most case), the read/write function must work at that sector size. When FatFs is configured for variable sector size (FF_MIN_SS < FF_MAX_SS), the sector size of medium is inquired with disk_ioctl function immediately following disk_initialize function succeeded.

    -

    The memory address specified by buff is not that always aligned to word boundary because the argument is defined as BYTE*. The unaligned read/write request can occure at direct transfer. 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.

    +

    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 sector. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (FF_MIN_SS == FF_MAX_SS, this is the most case), the generic read/write function must work at this sector size only. When FatFs is configured for variable sector size (FF_MIN_SS < FF_MAX_SS), the sector size of medium is inquired with disk_ioctl function after disk_initialize function succeeds.

    +

    There are some considerations about the memory addres passed via buff. It is not that always aligned with the word boundary, because the argument is defined as BYTE*. The unaligned transfer request can occure at direct transfer. 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.

    +

    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.

    Generally, a multiple sector read request must not be split into single sector transactions to the storage device, or read throughput gets worse.

    diff --git a/documents/doc/dstat.html b/documents/doc/dstat.html index e9926bb8ef8c74d7b061761c3719d9b2b1a1f662..a891489d020104bc6577084664e829c2a8ed759c 100644 --- a/documents/doc/dstat.html +++ b/documents/doc/dstat.html @@ -25,7 +25,7 @@ DSTATUS disk_status (

    Parameter

    pdrv
    -
    Physical drive number to identify the target device. Always zero at single drive system.
    +
    Physical drive number to identify the target device. Always zero in single drive system.
    @@ -37,9 +37,9 @@ DSTATUS disk_status (
    STA_NOINIT
    Indicates that the device has not been initialized and not ready to work. This flag is set on system reset, media removal or failure of disk_initialize function. It is cleared on disk_initialize function succeeded. Any media change that occurs asynchronously must be captured and reflect it to the status flags, or auto-mount function will not work correctly. If the system does not support media change detection, application program needs to explicitly re-mount the volume with f_mount function after each media change.
    STA_NODISK
    -
    Indicates that no medium in the drive. This is always cleared at fixed disk drive. Note that FatFs does not refer this flag.
    +
    Indicates that no medium in the drive. This is always cleared when the drive is non-removable class. Note that FatFs does not refer this flag.
    STA_PROTECT
    -
    Indicates that the medium is write protected. This is always cleared at the drives without write protect function. Not valid if STA_NODISK is set.
    +
    Indicates that the medium is write protected. This is always cleared when the drive has no write protect function. Not valid if STA_NODISK is set.
    diff --git a/documents/doc/dwrite.html b/documents/doc/dwrite.html index 51174f9c01ba72fc230ffcf0194227a743ea4c67..fef510699552581e1db0d31c459049807c36bd2f 100644 --- a/documents/doc/dwrite.html +++ b/documents/doc/dwrite.html @@ -13,12 +13,12 @@

    disk_write

    -

    The disk_write function is called to write data to the sector(s) of storage device.

    +

    The disk_write function is called to write data to the storage device.

     DRESULT disk_write (
       BYTE pdrv,        /* [IN] Physical drive number */
       const BYTE* buff, /* [IN] Pointer to the data to be written */
    -  DWORD sector,     /* [IN] Sector number to write from */
    +  LBA_t sector,     /* [IN] Sector number to write from */
       UINT count        /* [IN] Number of sectors to write */
     );
     
    @@ -32,7 +32,7 @@ DRESULT disk_write (
    buff
    Pointer to the first item of the byte array to be written. The size of data to be written is sector size * count bytes.
    sector
    -
    Start sector number in 32-bit LBA.
    +
    Start sector number in LBA. The data type LBA_t is an alias of DWORD or QWORD depends on the configuration option.
    count
    Number of sectors to write.
    @@ -60,7 +60,7 @@ DRESULT disk_write (

    Description

    The specified memory address is not that always aligned to word boundary because the argument is defined as BYTE*. For more information, refer to the description of disk_read function.

    Generally, a multiple sector write request (count > 1) must not be split into single sector transactions to the storage device, or the file write throughput will be drastically decreased.

    -

    FatFs expects delayed write function of the disk control layer. The write operation to the media does not need to be completed at return from this function by what write operation is in progress or data is only stored into the write-back cache. But write data on the buff is invalid after return from this function. The write completion request is done by CTRL_SYNC command of disk_ioctl function. Therefore, if a delayed write function is implemented, the write throughput of the filesystem will be improved.

    +

    FatFs expects delayed write function of the disk control layer. The write operation to the media does not need to be completed when return from this function by what write operation is in progress or data is only stored into the write-back cache. But write data on the buff is invalid after return from this function. The write completion request is done by CTRL_SYNC command of disk_ioctl function. Therefore, if a delayed write function is implemented, the write throughput of the filesystem will be improved.

    Remarks: Application program MUST NOT call this function, or FAT structure on the volume can be collapsed.

    diff --git a/documents/doc/expand.html b/documents/doc/expand.html index 96fb3ed0babfa26f45f364e61dea12c29fb43dc0..7620ba9a5459e0b4b4a9658f273423cd943405c4 100644 --- a/documents/doc/expand.html +++ b/documents/doc/expand.html @@ -19,7 +19,7 @@ FRESULT f_expand ( FIL* fp, /* [IN] File object */ FSIZE_t fsz, /* [IN] File size expanded to */ - BYTE opt /* [IN] Operation mode */ + BYTE opt /* [IN] Allocation mode */ ); @@ -32,7 +32,7 @@ FRESULT f_expand (
    fsz
    Number of bytes in size to prepare or allocate for the file. The data type FSIZE_t is an alias of either DWORD(32-bit) or QWORD(64-bit) depends on the configuration option FF_FS_EXFAT.
    opt
    -
    Operation mode. Prepare only (0) or Allocate now (1).
    +
    Allocation mode. Prepare to allocate (0) or Allocate now (1).
    @@ -52,16 +52,16 @@ FRESULT f_expand (

    Description

    -

    The f_expand function prepares or allocates a contiguous data area to the file. When opt is 1, the function allocates a contiguous data area to the file. Unlike expansion of file by f_lseek 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 undefined because no data is written to the file in this process. The function can fail with FR_DENIED due to some reasons below.

    +

    The f_expand function prepares or allocates a contiguous data area to the file. When opt is 1, the data area is allocated to the file in this function. Unlike expansion of file size by f_lseek 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 undefined, because no data is written to the file in this process. The function can fail with FR_DENIED due to some reasons below.

    -

    When opt 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.

    -

    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.

    -

    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 this function to examine if the file is contiguous or not.

    +

    When opt 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 this size unless any other changes to the volume is performed.

    +

    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.

    +

    Also the contiguous file can be easily accessed directly via low-level disk functions. However, this is not recommended in consideration of portability and future compatibility. If the file has not been confirmed be contiguous, use this function to examine if the file is contiguous or not.

    diff --git a/documents/doc/fattime.html b/documents/doc/fattime.html index dfc4937fc637f35c6b5a1d323874fe06af648712..002733a7465ede695b587dd8ce46c08b5cd2063c 100644 --- a/documents/doc/fattime.html +++ b/documents/doc/fattime.html @@ -48,7 +48,30 @@ DWORD get_fattime (void);

    QuickInfo

    -

    This function is not needed when FF_FS_READONLY == 1 or FF_FS_NORTC == 1.

    +

    This function is not needed when FF_FS_READONLY == 1 or FF_FS_NORTC == 1.

    +
    + + +
    +

    Example

    +
    +DWORD get_fattime (void)
    +{
    +    time_t t;
    +    struct tm *stm;
    +
    +
    +    t = time(0);
    +    stm = localtime(&t);
    +
    +    return (DWORD)(stm->tm_year - 80) << 25 |
    +           (DWORD)(stm->tm_mon + 1) << 21 |
    +           (DWORD)stm->tm_mday << 16 |
    +           (DWORD)stm->tm_hour << 11 |
    +           (DWORD)stm->tm_min << 5 |
    +           (DWORD)stm->tm_sec >> 1;
    +}
    +
    diff --git a/documents/doc/fdisk.html b/documents/doc/fdisk.html index 1c0c1e1bcaa05ff465edd80f4bcc4debe3af1c4c..d8c40bdb6b963a2d1cd1dd67958a627c392c27e1 100644 --- a/documents/doc/fdisk.html +++ b/documents/doc/fdisk.html @@ -16,9 +16,9 @@

    The f_fdisk fucntion divides a physical drive.

     FRESULT f_fdisk (
    -  BYTE  pdrv,        /* [IN] Physical drive number */
    -  const DWORD* szt,  /* [IN] Partition map table */
    -  void* work         /* [IN] Work area */
    +  BYTE  pdrv,         /* [IN] Physical drive number */
    +  const LBA_t ptbl[], /* [IN] Partition map table */
    +  void* work          /* [IN] Work area */
     );
     
    @@ -28,10 +28,10 @@ FRESULT f_fdisk (
    pdrv
    Specifies the physical drive to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.
    -
    szt
    -
    Pointer to the first item of the partition map table.
    +
    ptbl
    +
    List of partition size to create on the drive. The data type LBA_t is an alias of DWORD or QWORD depends on the configuration option FF_LBA64.
    work
    -
    Pointer to the function work area. The size must be at least FF_MAX_SS bytes. When a null pointer is given, the function allocates a memory block for the working buffer (at only FF_USE_LFN == 3).
    +
    Pointer to the function work area. The size must be at least FF_MAX_SS bytes. When a null pointer is given with FF_USE_LFN = 3, a memory block is obtained in this function for the working buffer.
    @@ -49,7 +49,8 @@ FRESULT f_fdisk (

    Description

    -

    The f_fdisk 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.

    +

    The f_fdisk 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 truncated at end of the drive.

    +

    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 (FF_LBA64 = 1) and the drive size is equal to or larger than FF_MIN_GPT sectors. It can create over ten partitions on a drive.

    @@ -60,24 +61,26 @@ FRESULT f_fdisk (

    Example

    -    /* Volume management table defined by user (required when FF_MULTI_PARTITION == 1) */
    +    /* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */
     
    -    PARTITION VolToPart[] = {
    -        {0, 1},    /* "0:" ==> Physical drive 0, 1st partition */
    -        {0, 2},    /* "1:" ==> Physical drive 0, 2nd partition */
    -        {1, 0}     /* "2:" ==> Physical drive 1, auto detection */
    +    PARTITION VolToPart[FF_VOLUMES] = {
    +        {0, 1},    /* "0:" ==> 1st partition in PD#0 */
    +        {0, 2},    /* "1:" ==> 2nd partition in PD#0 */
    +        {1, 0}     /* "2:" ==> PD#1 as removable drive */
         };
     
         /* Initialize a brand-new disk drive mapped to physical drive 0 */
     
    -    DWORD plist[] = {50, 50, 0, 0};  /* Divide drive into two partitions */
    -    BYTE work[FF_MAX_SS];
    +    BYTE work[FF_MAX_SS];         /* Working buffer */
    +    LBA_t plist[] = {50, 50, 0};  /* Divide the drive into two partitions */
    +                 /* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */
    +                 /* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */
     
         f_fdisk(0, plist, work);                    /* Divide physical drive 0 */
     
    -    f_mkfs("0:", FM_ANY, work, sizeof work);    /* Create FAT volume on the logical drive 0 */
    -    f_mkfs("1:", FM_ANY, work, sizeof work);    /* Create FAT volume on the logical drive 1 */
    +    f_mkfs("0:", 0, work, sizeof work); /* Create FAT volume on the logical drive 0 */
    +    f_mkfs("1:", 0, work, sizeof work); /* Create FAT volume on the logical drive 1 */
     
     
    diff --git a/documents/doc/filename.html b/documents/doc/filename.html index 510a57a1a08fcda2e84f5af373b3f0dc74a877ca..8ff028dc0d606b992ba97dd8c6bbe451920badca 100644 --- a/documents/doc/filename.html +++ b/documents/doc/filename.html @@ -10,16 +10,16 @@ -

    Path Names on the FatFs

    +

    Path Names on the FatFs API

    Format of the Path Names

    The format of path name on the FatFs module is similer to the filename specs of DOS/Windos as follows:

    [drive#:][/]directory/file
    -

    The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when FF_USE_LFN >= 1. The sub directories are separated with a \ or / in the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the heading drive prefix to specify logical drive is in a numeral + colon. When drive prefix is omitted, the drive number is assumed as default drive (drive 0 or current drive).

    -

    Control characters (\0 to \x1F) 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.

    -

    In default configuration (FF_FS_RPATH == 0), 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 (".", "..") are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.

    -

    When relative path is enabled (FF_FS_RPATH >= 1), 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 f_chdir function. Dot names are also allowed for the path names. The default drive is the current drive set by f_chdrive function.

    +

    The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when FF_USE_LFN >= 1. The sub-directories are separated with a \ or / as the same way as DOS/Windows API. Duplicated separator and terminating separator, such as "//animal///cat/", are ignored. Only a difference is that the heading drive prefix to specify the logical drive, an FAT volume, is in a digit (0-9) + a colon, while it is in an alphabet (A-Z) + a colon in DOS/Windows. The logical drive number is the identifier to specify the volume to be accessed. When drive prefix is omitted, the logical drive number is assumed as default drive.

    +

    Control characters (\0 to \x1F) are recognized as end of the path name. In LFN configuration, leading or embedded white spaces in the file name are valid as part of the file name, but the treminating white space and dot of the file name are ignored and truncated. In non-LFN configuration, white space is recognized as end of the path name.

    +

    In default configuration (FF_FS_RPATH == 0), 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 followed from the root directory. Dot directory names (".", "..") are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.

    +

    When relative path feature is enabled (FF_FS_RPATH >= 1), 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 default drive. Dot directory name is also allowed for the path name. The current directory is set by f_chdir function and the default drive is the current drive set by f_chdrive function.

    @@ -35,51 +35,57 @@
    Path nameFF_FS_RPATH == 0FF_FS_RPATH >= 1
    file.txtA file in the root directory of the drive 0A file in the current directory of the current drive
    dir1/..Invalid nameThe current directory
    /..Invalid nameThe root directory (sticks the top level)
    -

    Also the drive prefix can be in pre-defined arbitrary string. When the option FF_STR_VOLUME_ID == 1, also arbitrary string volume ID can be used as drive prefix. e.g. "flash:file1.txt", "ram:temp.dat" or "sd:". When FF_STR_VOLUME_ID == 2, Unix style drive prefix can be used. e.g. "/flash/file1.txt", "/ram/temp.dat" or "/usb". However, it cannot traverse the drives such as "/flash/../ram/temp.dat". The Unix style drive prefix may lead a confusion in identification between volume ID and file name. For instance, which does "/flash" mean, a file "flash" on the root directory without drive prefix or a drive prefix of "flash"? If the string following a heading slash matches with any volume ID, it is treated as a drive prefix.

    - +

    Also the drive prefix can be in pre-defined arbitrary string. When the option FF_STR_VOLUME_ID == 1, also arbitrary string volume ID can be used as drive prefix. e.g. "flash:file1.txt", "ram:temp.dat" or "sd:". If the srting does not match any volume ID, the function fails with FR_INVALID_DRIVE.

    +

    When FF_STR_VOLUME_ID == 2, Unix style drive prefix can be used. e.g. "/flash/file1.txt", "/ram/temp.dat" or "/sd". If a heading separator is exist, it is treated as start of drive prefix and in absolute path. Any form as "root directory in current drive" and "current directory in specified drive" cannot be used. Double dot name cannot traverse the drives such as "/flash/../ram/foo.dat".

    Remark: In this revision, double dot name ".." cannot follow the parent directory on the exFAT volume. It will work as "." and stay there.

    Legal Characters and Case Sensitivity

    -

    On the FAT filesystem, legal characters for object name (file/directory name) are, 0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~ and any extended character. The valid character codes of extended characters are depends on the configured code page. Under LFN supported system, also + , ; = [ ] 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.

    -

    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, file.txt, File.Txt and FILE.TXT, 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.

    -

    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).

    +

    In the generic FAT filesystems, the legal characters for object name (file/directory name) are, 0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~ in ASCII and extended characters \x80 to \xFF. In the FAT filesystems with LFN extention, also + , ; = [ ], white space and extended characters U+000080 to U+10FFFF are legal for the object name. White spaces and dots can be placed anywhere in the path name except end of the name. Trailing white spaces and dots are ignored.

    +

    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, file.txt, File.Txt and FILE.TXT, are identical on the FAT filesystem. 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 extension is exist.

    +

    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 the 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). However, FatFs works with case-insensitive to the extended character (WindowsNT specs) in LFN configuration.

    Unicode API

    -

    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 TCHAR. It is an alias of char by default and the code set used for the path name string is ANSI/OEM specifid by FF_CODE_PAGE. When FF_LFN_UNICODE is set to 1 or larger, the type of the TCHAR 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, _T(s) and _TEXT(s) macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.

    +

    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 TCHAR. It is an alias of char by default and the code set used for the path name string is ANSI/OEM specifid by FF_CODE_PAGE. When FF_LFN_UNICODE is set to 1 or larger, the type of the TCHAR 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 ✝☪✡☸☭ and any character not in BMP, 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, _T(s) and _TEXT(s) macro are available to specify the string in proper type. The code shown below is an example to define the literal strings.

    - f_open(fp, "filename.txt", FA_READ);      /* ANSI/OEM string (char) */
    - f_open(fp, L"filename.txt", FA_READ);     /* UTF-16 string (WCHAR) */
    - f_open(fp, u8"filename.txt", FA_READ);    /* UTF-8 string (char) */
    - f_open(fp, U"filename.txt", FA_READ);     /* UTF-32 string (DWORD) */
    - f_open(fp, _T("filename.txt"), FA_READ);  /* Changed by configuration (TCHAR) */
    + f_open(fp, "filename.txt", FA_READ);      /* ANSI/OEM string (char) */
    + f_open(fp, L"filename.txt", FA_READ);     /* UTF-16 string (WCHAR) */
    + f_open(fp, u8"filename.txt", FA_READ);    /* UTF-8 string (char) */
    + f_open(fp, U"filename.txt", FA_READ);     /* UTF-32 string (DWORD) */
    + f_open(fp, _T("filename.txt"), FA_READ);  /* Changed by configuration (TCHAR) */
     

    Volume Management

    -

    FatFs module requires dynamic work area, filesystem object, for each volume (logical drive). It is registered/unregistered to the FatFs module by f_mount 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.

    -

    When FF_MULTI_PARTITION = 1 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.

    +

    By default, each logical drive is associated with the physical drive in same drive number. An FAT volume on the physical drive is serched in the volume mount process. It reads boot sectors and checks it if it is an FAT VBR in order of LBA 0 as SFD format, 1st partition, 2nd partition, 3rd partition, ..., as MBR or GPT format.

    +

    When multiple partition feature is enabled, FF_MULTI_PARTITION = 1, each individual logical drive is associated with arbitrary partition or physical drive specified by volume management table, VolToPart[]. The table needs to be defined by user to resolve mappings of the logical drive numbers and the associated partitions or drives. Following code is an example of the volume management table.

    -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 (a non-removable drive)
    +         "3:" is associated with physical drive 1 (a removable drive)
     
     PARTITION VolToPart[FF_VOLUMES] = {
    -    {0, 1},     /* "0:" ==> Physical drive 0, 1st partition */
    -    {0, 2},     /* "1:" ==> Physical drive 0, 2nd partition */
    -    {0, 3},     /* "2:" ==> Physical drive 0, 3rd partition */
    -    {1, 0}      /* "3:" ==> Physical drive 1, auto detection */
    +    {0, 1},     /* "0:" ==> 1st partition on the pd#0 */
    +    {0, 2},     /* "1:" ==> 2nd partition on the pd#0 */
    +    {0, 3},     /* "2:" ==> 3rd partition on the pd#0 */
    +    {1, 0}      /* "3:" ==> pd#1 as removable drive (auto-search) */
     };
    +
    +
    +relationship between logical drive and physical drive
     
    -
    relationship between logical drive and physical drive
    -

    There are some considerations on using multi-partition configuration.

    +

    There are some considerations when enable the multi-partition configuration.

    diff --git a/documents/doc/findfirst.html b/documents/doc/findfirst.html index daa6de644c0c22a9d010a544f88adeb1721912a6..5f1e34439cb8c52a5086b59ae1b517d093831926 100644 --- a/documents/doc/findfirst.html +++ b/documents/doc/findfirst.html @@ -61,12 +61,19 @@ FRESULT f_findfirst (

    Description

    -

    After the directory specified by path could be opened, it starts to search the directory for items with the name specified by pattern. If the first item is found, the information about the object is stored into the file information structure fno.

    -

    The matching pattern can contain wildcard characters (? and *). A ? matches an any character and an * matches an any string in length of zero or longer. When support of long file name is enabled, only fname[] is tested at FF_USE_FIND == 1 and also altname[] is tested at FF_USE_FIND == 2. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.

    +

    After the directory specified by path could be opened, it starts to search the directory for items with the matching pattern specified by pattern. If the first item is found, the information about the item is stored into the file information structure fno. If not found, fno->fname[] has a null string.

    +

    The matching pattern string can contain wildcards. For example:

    +

    Since the matching algorithm uses recursion, number of wildcards in the matching pattern is limited to four to limit the stack usage. Any pattern with too many wildcards does not match any name. In LFN configuration, only fname[] is tested when FF_USE_FIND == 1 and also altname[] is tested when FF_USE_FIND == 2. There are some differences listed below between FatFs and standard systems in matching condition.

    +
    @@ -85,13 +92,13 @@ FRESULT f_findfirst ( void find_image_file (void) { FRESULT fr; /* Return value */ - DIR dj; /* Directory search object */ + DIR dj; /* Directory object */ FILINFO fno; /* File information */ - fr = f_findfirst(&dj, &fno, "", "dsc*.jpg"); /* Start to search for photo files */ + fr = f_findfirst(&dj, &fno, "", "????????.JPG"); /* Start to search for photo files */ while (fr == FR_OK && fno.fname[0]) { /* Repeat while an item is found */ - printf("%s\n", fno.fname); /* Display the object name */ + printf("%s\n", fno.fname); /* Print the object name */ fr = f_findnext(&dj, &fno); /* Search for next item */ } diff --git a/documents/doc/forward.html b/documents/doc/forward.html index ada0a0539bcface3dff1bc51ab0c75918d7ee6dc..fdb5f49dbb725d8210e4b68be8d917c38065c260 100644 --- a/documents/doc/forward.html +++ b/documents/doc/forward.html @@ -54,7 +54,7 @@ FRESULT f_forward (

    Description

    -

    The f_forward function reads the data from the file and forward it to the outgoing stream without data buffer. This is suitable for small memory system because it does not require any data buffer at application module. The file pointer of the file object increases in number of bytes forwarded. In case of *bf is less than btf without error, it means the requested bytes could not be transferred due to end of file or stream goes busy during data transfer.

    +

    The f_forward function reads the data from the file and forward it to the outgoing stream. This function is suitable for small memory system, because it does not require any data buffer in the application module. The file pointer of the file object advances in number of bytes forwarded. In case of *bf is less than btf without error, it means the requested size of data could not be transferred due to end of file or stream goes busy during data transfer.

    @@ -65,7 +65,7 @@ FRESULT f_forward (
    -

    Example (Audio playback)

    +

    Example

     /*------------------------------------------------------------------------*/
     /* Sample code of data transfer function to be called back from f_forward */
    diff --git a/documents/doc/getfree.html b/documents/doc/getfree.html
    index cdc730b71499c3faaba37f3db9804d2588fa9500..5e4f4193a56c2720a995311f7020ed2ac53f64c8 100644
    --- a/documents/doc/getfree.html
    +++ b/documents/doc/getfree.html
    @@ -53,7 +53,7 @@ FRESULT f_getfree (
     
     

    Descriptions

    -

    The f_getfree function gets number of free clusters on the volume. The member csize 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 FF_FS_NOFSINFO option.

    +

    The f_getfree function gets number of free clusters on the volume. The member csize 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 FF_FS_NOFSINFO option.

    diff --git a/documents/doc/getlabel.html b/documents/doc/getlabel.html index dfe067dfc2f82fd1d62e8d2e46e2be739d09eded..0ec6d0d4e955f4b96453f8fbadbbdc1ec3c09e6e 100644 --- a/documents/doc/getlabel.html +++ b/documents/doc/getlabel.html @@ -34,7 +34,7 @@ FRESULT f_getlabel ( ConfigurationFF_FS_EXFAT == 0FF_FS_EXFAT == 1 FF_USE_LFN == 012 items- FF_LFN_UNICODE == 012 items23 items -FF_LFN_UNICODE == 1/312 items12 items +FF_LFN_UNICODE == 1,312 items12 items FF_LFN_UNICODE == 234 items34 items diff --git a/documents/doc/gets.html b/documents/doc/gets.html index 8ab46f474bc8a1f57a69ea35a8bbde5af8562658..89d95607cd0b4c7143deb9e4e38a413f476bb7c6 100644 --- a/documents/doc/gets.html +++ b/documents/doc/gets.html @@ -45,7 +45,7 @@ TCHAR* f_gets (

    Description

    The read operation continues until a '\n' is stored, reached end of the file or the buffer is filled with len - 1 characters. The read string is terminated with a '\0'. When no character to read or any error occured during read operation, it returns a null pointer. The status of EOF and error can be examined with f_eof and f_error function.

    -

    When FatFs is configured to Unicode API (FF_LFN_UNICODE >= 1), data types on the srting fuctions, f_putc, f_puts, f_printf and f_gets, is also switched to Unicode. The character encoding on the file to be read via this function is assumed as FF_STRF_ENCODE. If the character encoding on the file differs from that on the API, it is converted in this function. In this case, input characters with wrong encoding will be lost.

    +

    When FatFs is configured to Unicode API (FF_LFN_UNICODE >= 1), data types on the srting fuctions, f_putc, f_puts, f_printf and f_gets, is also switched to Unicode. The character encoding on the file to be read via this function is assumed as FF_STRF_ENCODE. If the character encoding on the file differs from that on the API, it is converted in this function. In this case, input characters with wrong encoding will be lost.

    diff --git a/documents/doc/lseek.html b/documents/doc/lseek.html index 7173b0e7cd98e26214eecfc7313d96eeca8dbf4d..ffd1f6221d4097700808bbe422080a23a86f7d28 100644 --- a/documents/doc/lseek.html +++ b/documents/doc/lseek.html @@ -18,7 +18,12 @@
     FRESULT f_lseek (
       FIL*    fp,  /* [IN] File object */
    -  FSIZE_t ofs  /* [IN] File read/write pointer */
    +  FSIZE_t ofs  /* [IN] Offset of file read/write pointer to be set */
    +);
    +
    +
    +FRESULT f_rewind (
    +  FIL*    fp   /* [IN] File object */
     );
     
    @@ -48,14 +53,17 @@ FRESULT f_lseek (

    Description

    -

    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 f_lseek function moves the file read/write pointer without any read/write operation to the file.

    -

    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 undefined 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 f_expand function instead. After the f_lseek 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.

    +

    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 f_lseek function moves the file read/write pointer without any read/write operation to the file. The f_rewind function is impremented as a macro.

    +
    +#define f_rewind(fp) f_lseek((fp), 0)
    +
    +

    If 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 undefined, 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 f_expand function instead. After the f_lseek 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 pointing expected offset, either of followings has been occured.

    -

    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 f_read and f_write function as well, however, the file size cannot be expanded by f_write, f_lseek function while the file is at fast seek mode.

    -

    The fast seek mode is enabled when the member cltbl in the file object is not NULL. The CLMT must be created into the DWORD array prior to use the fast seek function. To create the CLMT, set address of the DWORD array to the member cltbl in the open file object, set the size of array in unit of items to the first item and call the f_lseek function with ofs = CREATE_LINKMAP. After the function succeeded and CLMT is created, no FAT access is occured in subsequent f_read, f_write, f_lseek 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 FR_NOT_ENOUGH_CORE, the given array size is insufficient for the file.

    +

    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 f_read and f_write function as well, however, the file size cannot be expanded by f_write, f_lseek function while the file is at fast seek mode.

    +

    The fast seek mode is available when FF_USE_FASTSEEK = 1. The CLMT must be created into the DWORD array prior to use the fast seek mode. To create the CLMT, set address of the DWORD array to the member cltbl in the open file object, set the size of array in unit of items to the cltbl[0] and then call f_lseek function with ofs = CREATE_LINKMAP. After the function succeeded, no FAT access is occured in subsequent f_read, f_write, f_lseek function to the file. The number of items used or required is returned into the cltbl[0]. The number of items needed 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 FR_NOT_ENOUGH_CORE, the size of given array is insufficient for the file.

    @@ -73,16 +81,16 @@ FRESULT f_lseek ( res = f_open(fp, "file.dat", FA_READ|FA_WRITE); if (res) ... - /* Move to offset of 5000 from top of the file */ + /* Set read/write pointer to 5000 */ res = f_lseek(fp, 5000); - /* Move to end of the file to append data */ + /* Set read/write pointer to end of the file to append data */ res = f_lseek(fp, f_size(fp)); - /* Forward 3000 bytes */ + /* Advance read/write pointer 3000 bytes */ res = f_lseek(fp, f_tell(fp) + 3000); - /* Rewind 2000 bytes (take care on wraparound) */ + /* Rewind read/write pointer 2000 bytes (take care on wraparound) */ res = f_lseek(fp, f_tell(fp) - 2000);
    @@ -93,17 +101,17 @@ FRESULT f_lseek (
         res = f_lseek(fp, PRE_SIZE);             /* Expand file size (cluster pre-allocation) */
         if (res || f_tell(fp) != PRE_SIZE) ...   /* Check if the file has been expanded successfly */
     
    -    res = f_lseek(fp, DATA_START);           /* Record data stream WITHOUT cluster allocation delay */
    +    res = f_lseek(fp, OFS_DATA);             /* Record data stream with free from cluster allocation delay */
         ...                                      /* Write operation should be aligned to sector boundary to optimize the write throughput */
     
         res = f_truncate(fp);                    /* Truncate unused area */
    -    res = f_lseek(fp, 0);                    /* Set file header */
    +    res = f_lseek(fp, OFS_HEADER);           /* Set file header */
         ...
     
         res = f_close(fp);
     
    -/* Using fast seek function */
    +/* Using fast seek mode */
     
         DWORD clmt[SZ_TBL];                    /* Cluster link map table buffer */
     
    @@ -111,7 +119,7 @@ FRESULT f_lseek (
     
         res = f_lseek(fp, ofs1);               /* This is normal seek (cltbl is nulled on file open) */
     
    -    fp->cltbl = clmt;                      /* Enable fast seek function (cltbl != NULL) */
    +    fp->cltbl = clmt;                      /* Enable fast seek mode (cltbl != NULL) */
         clmt[0] = SZ_TBL;                      /* Set table size */
         res = f_lseek(fp, CREATE_LINKMAP);     /* Create CLMT */
         ...
    diff --git a/documents/doc/mkfs.html b/documents/doc/mkfs.html
    index 8e2bd1c773b073d0bb2db9ee5df102b96eeab1f5..f40ebb09fd845aa4589a76c61cbfd8c5477ccede 100644
    --- a/documents/doc/mkfs.html
    +++ b/documents/doc/mkfs.html
    @@ -13,14 +13,13 @@
     
     

    f_mkfs

    -

    The f_mkfs fucntion creates an FAT/exFAT volume on the logical drive.

    +

    The f_mkfs function creates an FAT/exFAT volume on the logical drive.

     FRESULT f_mkfs (
    -  const TCHAR* path,  /* [IN] Logical drive number */
    -  BYTE  opt,          /* [IN] Format options */
    -  DWORD au,           /* [IN] Size of the allocation unit */
    -  void* work,         /* [-]  Working buffer */
    -  UINT len            /* [IN] Size of working buffer */
    +  const TCHAR* path,   /* [IN] Logical drive number */
    +  const MKFS_PARM* opt,/* [IN] Format options */
    +  void* work,          /* [-]  Working buffer */
    +  UINT len             /* [IN] Size of working buffer */
     );
     
    @@ -29,15 +28,25 @@ FRESULT f_mkfs (

    Parameters

    path
    -
    Pointer to the null-terminated string specifies the logical drive 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.
    +
    Pointer to the null-terminated string specifies the logical drive 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.
    opt
    -
    Specifies the format option in combination of FM_FAT, FM_FAT32, FM_EXFAT and bitwise-or of these three, FM_ANY. FM_EXFAT 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 au. The flag FM_SFD specifies to create the volume on the drive in SFD format.
    -
    au
    -
    Specifies size of the allocation unit (cluter) in unit of byte. The valid value is n times the sector size. The n 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.
    +
    Specifies the format option structure MKFS_PARM holding format options. If a null pointer is given, it gives the function every option in default value. The structure has five members in order of described below:
    +
    +
    BYTE fmt
    +
    Specifies a combination of FAT type flags, FM_FAT, FM_FAT32, FM_EXFAT and bitwise-or of these three, FM_ANY. FM_EXFAT is ignored when exFAT is not enabled. These flags specify which type of FAT volume to be created. If two or more types are specified, one out of them will be selected depends on the volume size and au_size. The flag FM_SFD specifies to create the volume on the drive in SFD format. The default value is FM_ANY.
    +
    BYTE n_fat
    +
    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.
    +
    UINT n_align
    +
    Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash memory 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 disk_ioctl function.
    +
    DWORD au_size
    +
    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, or up to 16 MB for exFAT volume. If a zero (default value) or any invalid value is given, the function uses default allocation unit size depends on the volume size.
    +
    UINT n_root
    +
    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.
    +
    work
    -
    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 len has no effect (at only FF_USE_LFN == 3).
    +
    Pointer to the working buffer used for the format process. If a null pointer is given with FF_USE_LFN == 3, the function uses a len bytes of heap memory in this function.
    len
    -
    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.
    +
    Size of the working buffer in unit of byte. It needs to be FF_MAX_SS at least. Plenty of working buffer reduces number of write transactions to the drive, thus the format process will finish quickly.
    @@ -57,11 +66,12 @@ FRESULT f_mkfs (

    Description

    -

    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 FR_MKFS_ABORTED. The minimum drive size is 128 sectors with FM_SFD option.

    -

    The allocation unit, also called cluster, 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.

    -

    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.

    -

    When the logical drive to be formatted is bound to a physical drive and FM_SFD 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 FM_SFD is specified, the FAT volume occupies from the first sector of the physical drive is created in SFD format.

    -

    When the logical drive to be formatted is bound to a specific partition (1-4) by support of multiple partition (FF_MULTI_PARTITION == 1), the FAT volume is created on the partition and FM_SFD flag is ignored. The physical drive needs to be partitioned with f_fdisk function or any other partitioning tools prior to create the FAT volume with this function.

    +

    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 is not valid for the volume size, the function will fail with FR_MKFS_ABORTED.

    +

    The allocation unit, also known as cluster, 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 volumes in GB order, 32768 bytes or larger, automatically selected by default, is recommended for most case unless extremely many small files are created in the volume.

    +

    When the logical drive to be formatted is associated with a physical drive (FF_MULTI_PARTITION == 0 or VolToPart[].pt == 0) and FM_SFD flag is not specified, a partition occupies entire drive space is created and then the FAT volume is created in the partition. When FM_SFD flag is specified, the FAT volume is created without any disk partitioning.

    +

    When the logical drive to be formatted is associated with a specific partition by multiple partition feature (FF_MULTI_PARTITION == 1 and VolToPart[].pt > 0), the FAT volume is created in the partition of the physical drive specified by volume mapping table and FM_SFD flag is ignored. The hosting physical drive needs to be partitioned with f_fdisk function or any partitioning tool prior to create the FAT volume with this function. If the partition is not exist, the function aborts with FR_MKFS_ABORTED.

    +

    There are three standard disk partitioning formats, MBR, GPT and SFD. The MBR format, also known as 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. The SFD, Super-Floppy Disk, is non-partitioned disk format. The FAT volume is located at LBA 0 and 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.

    +

    Some systems manage the partitions in the on-board storage in non-standard format. The partitions are mapped as physical drives identified by pdrv in disk_* functions. For such systems, SFD format is suitable to create the FAT volume in the partition.

    @@ -82,11 +92,11 @@ int main (void) BYTE work[FF_MAX_SS]; /* Work area (larger is better for processing time) */ - /* Create FAT volume */ - res = f_mkfs("", FM_ANY, 0, work, sizeof work); + /* Format the default drive with default parameters */ + res = f_mkfs("", 0, work, sizeof work); if (res) ... - /* Register work area */ + /* Give a work area to the default drive */ f_mount(&fs, "", 0); /* Create a file as new */ @@ -109,7 +119,7 @@ int main (void)

    See Also

    -

    Example of volume size and format parameters, Volume management, f_fdisk

    +

    Example of volume size and format parameters, Volume management, f_fdisk

    Return

    diff --git a/documents/doc/mount.html b/documents/doc/mount.html index f54a9b811f2a5214af449fa8ce17cea78bfe6f21..57f40bedd0a52ce4c7c4ab43c4a016ced9d00518 100644 --- a/documents/doc/mount.html +++ b/documents/doc/mount.html @@ -13,7 +13,7 @@

    f_mount

    -

    The f_mount fucntion registers/unregisters filesystem object to the FatFs module.

    +

    The f_mount fucntion gives work area to the FatFs module.

     FRESULT f_mount (
       FATFS*       fs,    /* [IN] Filesystem object */
    @@ -21,6 +21,11 @@ FRESULT f_mount (
       BYTE         opt    /* [IN] Initialization option */
     );
     
    +
    +FRESULT f_unmount (
    +  const TCHAR* path   /* [IN] Logical drive number */
    +);
    +
    @@ -50,7 +55,7 @@ FRESULT f_mount (

    Description

    -

    FatFs requires work area (filesystem object) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with f_mount 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. Some management functions, f_mkfs, f_fdisk and f_setcp, do not want a filesystem object.

    +

    FatFs requires work area (filesystem object) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with f_mount function for the logical drive. The file/directory API functions get ready to work after this procedure. Some volume management functions, f_mkfs, f_fdisk and f_setcp, do not want a filesystem object.

    The f_mount function registers/unregisters a filesystem object to the FatFs module as follows:

    1. Determines the logical drive which specified by path.
    2. @@ -58,6 +63,7 @@ FRESULT f_mount (
    3. Clears and registers the new work area to the volume if fs is not NULL.
    4. Performs volume mount process to the volume if forced mounting is specified.
    +

    If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.

    If forced mounting is not specified (opt = 0), 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.

    • Filesystem object has not been initialized. It is de-initialized by f_mount function.
    • @@ -65,7 +71,10 @@ FRESULT f_mount (

    If the function with forced mounting (opt = 1) failed with FR_NOT_READY, it means that the filesystem object has been registered successfully but the volume is currently not ready to work. The volume mount process will be attempted on subsequent file/directroy function.

    If implementation of the disk I/O layer lacks asynchronous media change detection, application program needs to perform f_mount function after each media change to force cleared the filesystem object.

    -

    To unregister the work area, specify a NULL to the fs, and then the work area can be discarded.

    +

    To unregister the work area, specify a NULL to the fs, and then the work area can be discarded. f_unmount function is implemented as a macro.

    +
    +#define f_unmount(path) f_mount(0, path, 0)
    +
    diff --git a/documents/doc/open.html b/documents/doc/open.html index f511a9923d39c43817294afa63ea18e0555b077d..cc8b87ad98fed9fb8575d3f3df53000d02e9a4c3 100644 --- a/documents/doc/open.html +++ b/documents/doc/open.html @@ -34,15 +34,15 @@ FRESULT f_open (
    Mode flags that specifies the type of access and open method for the file. It is specified by a combination of following flags.
    - - - + + +
    FlagsMeaning
    FA_READSpecifies read access to the object. Data can be read from the file.
    FA_WRITESpecifies write access to the object. Data can be written to the file. Combine with FA_READ for read-write access.
    FA_OPEN_EXISTINGOpens the file. The function fails if the file is not existing. (Default)
    FA_READSpecifies read access to the file. Data can be read from the file.
    FA_WRITESpecifies write access to the file. Data can be written to the file. Combine with FA_READ for read-write access.
    FA_OPEN_EXISTINGOpens a file. The function fails if the file is not existing. (Default)
    FA_CREATE_NEWCreates a new file. The function fails with FR_EXIST if the file is existing.
    FA_CREATE_ALWAYSCreates a new file. If the file is existing, it will be truncated and overwritten.
    FA_OPEN_ALWAYSOpens the file if it is existing. If not, a new file will be created.
    FA_OPEN_APPENDSame as FA_OPEN_ALWAYS except the read/write pointer is set end of the file.
    -Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:
    +Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:
    @@ -86,7 +86,7 @@ Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:

    Description

    -

    The f_open function opens a file and creates a file object. The file object is used for subsequent read/write operations to the file to identify the file. Open file should be closed with f_close function after the session of the file access. If any change to the file is made and not closed prior to power down, media removal or re-mount, or the file can be collapsed.

    +

    The f_open function opens a file and creates a file object. The file object is an identifier for subsequent operations to the file. Open file should be closed with f_close function after the session of the file access. If any change to the file has been made and not closed prior to power off, media removal or re-mount, or the file can be collapsed.

    If duplicated file open is needed, read here carefully. However duplicated open of a file with any write mode flag is always prohibited.

    @@ -111,7 +111,7 @@ int main (void) FRESULT fr; /* FatFs return code */ - /* Register work area to the default drive */ + /* Give a work area to the default drive */ f_mount(&FatFs, "", 0); /* Open a text file */ @@ -141,7 +141,7 @@ int main (void) UINT br, bw; /* File read/write count */ - /* Register work area for each logical drive */ + /* Give work areas to each logical drive */ f_mount(&fs0, "0:", 0); f_mount(&fs1, "1:", 0); @@ -155,10 +155,10 @@ int main (void) /* Copy source to destination */ for (;;) { - fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* Read a chunk of source file */ - if (fr || br == 0) break; /* error or eof */ - fr = f_write(&fdst, buffer, br, &bw); /* Write it to the destination file */ - if (fr || bw < br) break; /* error or disk full */ + fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* Read a chunk of data from the source file */ + if (br == 0) break; /* error or eof */ + fr = f_write(&fdst, buffer, br, &bw); /* Write it to the destination file */ + if (bw < br) break; /* error or disk full */ } /* Close open files */ @@ -166,8 +166,8 @@ int main (void) f_close(&fdst); /* Unregister work area prior to discard it */ - f_mount(0, "0:", 0); - f_mount(0, "1:", 0); + f_unmount("0:"); + f_unmount("1:"); return (int)fr; } diff --git a/documents/doc/printf.html b/documents/doc/printf.html index 82be70c17c7db9cdc5e18b40e64620138a786d73..eb64e8dab2af7fb8bb5e05177f0ada57d1b79aa7 100644 --- a/documents/doc/printf.html +++ b/documents/doc/printf.html @@ -39,7 +39,7 @@ int f_printf (

    Return Values

    -

    When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an EOF (-1) will be returned.

    +

    When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or an error, a negative value will be returned.

    @@ -47,14 +47,30 @@ int f_printf (

    Description

    The format control directive is a sub-set of standard library shown as follows:

    -    %[flag][width][type]
    +    %[flag][width][precision][size]type
     
    -
    flag
    Padding options. A - specifies left justified. A 0 specifies zero padded.
    -
    width
    Minimum width of the field, 1-99 or *. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An * specifies the value comes from an argument in int type.
    -
    type
    c s d u o x b and prefix l 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 sizeof (long) is greater than sizeof (int) (this is typical of 8/16-bit systems), a prefix l needs to be explicitly specified for long integer argument. These characters except for x are case insensitive.
    +
    flag
    Padding option. A - specifies left-aligned. A 0 specifies zero padded. The default setting is in right-aligned and space padded.
    +
    width
    Minimum width of the field, 1-99 or *. If the width of generated string is less than the minimum width, rest field is padded with spaces or zeros. An * specifies the value comes from an argument in int type. The default setting is zero.
    +
    precision
    Specifies number of fractional digits or maximum width of string, .0-.99 or .*. If the number is omitted, it is same as .0. Default setting is 6 for number and no limit for string.
    +
    size
    Specifies size of integer argument, l(long) and ll(long long). If sizeof (long) == sizeof (int) is true (this is typical of 32-bit systems), prefix l can be omitted for long integer argument. The default size is int for integer argument and floating point argument is always assumed double as the default argument promotion.
    +
    type
    Specifies type of the output format and the argument as shown below. The length of generated string is in assumtion of int is 32-bit. +
    POSIXFatFs
    "r"FA_READ
    + + + + + + + + + + +
    TypeFormatArgumentLength
    cCharacterint,
    long,
    long long
    1 character.
    dSigned decimal1 to 11 (20 for ll) characters.
    uUnsigned decimal1 to 10 (20 for ll) characters.
    oUnsigned octal1 to 11 (22 for ll) characters.
    x XUnsigned hexdecimal1 to 8 (16 for ll) characters.
    bUnsigned binary1 to 32 characters. Limited to lower 32 digits when ll is specified.
    sStringTCHAR*As input string. Null pointer generates a null string.
    fFloating point
    (decimal)
    double1 to 31 characters. If the number of characters exceeds 31, it writes "±OV". Not a number and infinite write "NaN" and "±INF".
    e EFloating point
    (e notation)
    4 to 31 characters. If the number of characters exceeds 31 or exponent exceeds +99, it writes "±OV".
    +

    When FatFs is configured for Unicode API (FF_LFN_UNICODE >= 1), character encoding on the string fuctions, f_putc, f_puts, f_printf and f_gets 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 on the file to be written via this function is selected by FF_STRF_ENCODE. The characters with wrong encoding or invalid for the output encoding will be lost.

    +

    If sprintf is used in the project and code conversion is not needed, f_write with sprintf will be efficient in code size and performance rather than f_printf.

    @@ -67,23 +83,24 @@ int f_printf (

    Example

    -    f_printf(&fil, "%d", 1234);            /* "1234" */
    -    f_printf(&fil, "%6d,%3d%%", -200, 5);  /* "  -200,  5%" */
    -    f_printf(&fil, "%ld", 12345L);         /* "12345" */
    -    f_printf(&fil, "%06d", 25);            /* "000025" */
    -    f_printf(&fil, "%06d", -25);           /* "000-25" */
    -    f_printf(&fil, "%*d", 5, 100);         /* "  100" */
    -    f_printf(&fil, "%-6d", 25);            /* "25    " */
    -    f_printf(&fil, "%u", -1);              /* "65535" or "4294967295" */
    -    f_printf(&fil, "%04x", 0xAB3);         /* "0ab3" */
    -    f_printf(&fil, "%08lX", 0x123ABCL);    /* "00123ABC" */
    -    f_printf(&fil, "%04o", 255);           /* "0377" */
    -    f_printf(&fil, "%016b", 0x550F);       /* "0101010100001111" */
    -    f_printf(&fil, "%s", "String");        /* "String" */
    -    f_printf(&fil, "%8s", "abc");          /* "     abc" */
    -    f_printf(&fil, "%-8s", "abc");         /* "abc     " */
    -    f_printf(&fil, "%c", 'a');             /* "a" */
    -    f_printf(&fil, "%f", 10.0);            /* f_printf lacks floating point support */
    +    f_printf(fp, "%d", 1234);             /* "1234" */
    +    f_printf(fp, "%6d,%3d%%", -200, 5);   /* "  -200,  5%" */
    +    f_printf(fp, "%-6u", 100);            /* "100   " */
    +    f_printf(fp, "%ld", 12345678);        /* "12345678" */
    +    f_printf(fp, "%llu", 0x100000000);    /* "4294967296"   (FF_PRINT_LLI) */
    +    f_printf(fp, "%lld", -1LL);           /* "-1"           (FF_PRINT_LLI) */
    +    f_printf(fp, "%04x", 0xA3);           /* "00a3" */
    +    f_printf(fp, "%08lX", 0x123ABC);      /* "00123ABC" */
    +    f_printf(fp, "%016b", 0x550F);        /* "0101010100001111" */
    +    f_printf(fp, "%*d", 6, 100);          /* "   100" */
    +    f_printf(fp, "%s", "abcdefg");        /* "abcdefg" */
    +    f_printf(fp, "%5s", "abc");           /* "  abc" */
    +    f_printf(fp, "%-5s", "abc");          /* "abc  " */
    +    f_printf(fp, "%.5s", "abcdefg");      /* "abcde" */
    +    f_printf(fp, "%-5.2s", "abcdefg");    /* "ab   " */
    +    f_printf(fp, "%c", 'a');              /* "a" */
    +    f_printf(fp, "%12f", 10.0);           /* "   10.000000" (FF_PRINT_FLOAT) */
    +    f_printf(fp, "%.4E", 123.45678);      /* "1.2346E+02"   (FF_PRINT_FLOAT) */
     
    diff --git a/documents/doc/putc.html b/documents/doc/putc.html index 4d93bf508502f793e4133043e5359275c32aaa0f..747b5fdd8c28812ed6955f107b5f17cc27c8d922 100644 --- a/documents/doc/putc.html +++ b/documents/doc/putc.html @@ -35,7 +35,7 @@ int f_putc (

    Return Values

    -

    When the character was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an EOF (-1) will be returned.

    +

    When the character was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, a negative value will be returned.

    diff --git a/documents/doc/puts.html b/documents/doc/puts.html index 92c7e74242c7046f0927042feac0960d1c270ff4..369594253062d3ef6d3e5f581161c6f4c48699b3 100644 --- a/documents/doc/puts.html +++ b/documents/doc/puts.html @@ -35,7 +35,7 @@ int f_puts (

    Return Value

    -

    When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an EOF (-1) will be returned.

    +

    When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, a negative value will be returned.

    diff --git a/documents/doc/rc.html b/documents/doc/rc.html index 3b4f6499a7fcec6cf0fb2b6e540978a2b4945594..8f7fffa1e6c74f70dcba4c6a48713771a4625756 100644 --- a/documents/doc/rc.html +++ b/documents/doc/rc.html @@ -11,7 +11,7 @@

    Return Code of API Functions

    -

    Most of API functions return common result code as enum type FRESULT. When an API function succeeded, it returns zero (FR_OK), otherwise it returns non-zero value indicates type of error.

    +

    Most of API functions return common result code in enum type FRESULT. When an API function succeeded, it returns zero (FR_OK), otherwise it returns non-zero value indicates type of error.

    @@ -22,14 +22,14 @@
    The lower layer, disk_read, disk_write or disk_ioctl function, reported that an unrecoverable hard error occured.
    Note that if once this error occured at any operation to an open file, the file object is aborted and any operations to the file except for close will be rejected.
    FR_INT_ERR
    -
    Assertion failed. An insanity is detected in the internal process. One of the following possibilities is suspected. +
    Assertion failed and an insanity is detected in the internal process. One of the following possibilities is suspected.
      -
    • Work area (file system object, file object or etc...) has been broken by stack overflow or any other tasks. This is the reason in most case.
    • +
    • Work area (file system object, file object or etc...) has been broken by stack overflow or something. This is the reason in most case.
    • There is an error of the FAT structure on the volume.
    • There is a bug in the FatFs module itself.
    • Wrong lower layer implementation.
    -Note that if once this error occured at any operation to an open file, the file object is aborted and any operation to the file except for close will be rejected. +Note that if once this error occured in the operation to an open file, the file object is aborted and any operation to the file except for close will be rejected.
    FR_NOT_READY
    @@ -46,33 +46,33 @@ Note that if once this error occured at any operation to an open file, the file
    Could not find the file in the directory.
    FR_NO_PATH
    -
    Could not find the path, some directory in the path name could not be found.
    +
    Could not find the path. A directory in the path name could not be found.
    FR_INVALID_NAME
    -
    The given string is invalid as the path name. One of the following possibilities is suspected. +
    The given string is invalid as a path name. One of the following possibilities is suspected.
      -
    • There is any character not allowed for the file name.
    • -
    • The string is out of 8.3 format. (at non-LFN cfg.)
    • +
    • There is a character not allowed for the file name.
    • +
    • The file name is out of 8.3 format. (at non-LFN cfg.)
    • FF_MAX_LFN is insufficient for the file name. (at LFN cfg.)
    • -
    • There is any character encoding error in the string.
    • +
    • There is a character encoding error in the string.
    FR_DENIED
    The required access was denied due to one of the following reasons:
      -
    • Write mode open against the read-only file.
    • -
    • Deleting the read-only file or directory.
    • -
    • Deleting the non-empty directory or current directory.
    • -
    • Reading the file opened without FA_READ flag.
    • -
    • Any modification to the file opened without FA_WRITE flag.
    • -
    • Could not create the object due to root directory full or disk full.
    • -
    • Could not allocate a contiguous area to the file.
    • +
    • Write mode open against the read-only file. (f_open)
    • +
    • Deleting the read-only file or directory. (f_unlink)
    • +
    • Deleting the non-empty directory or current directory. (f_unlink)
    • +
    • Reading the file opened without FA_READ flag. (f_read)
    • +
    • Any modification to the file opened without FA_WRITE flag. (f_write, f_truncate, f_expand)
    • +
    • Could not create the object due to root directory full or disk full. (f_open, f_mkdir)
    • +
    • Could not find a contiguous area for the file. (f_expand)
    FR_EXIST
    -
    Name collision, an object with the same name is already existing.
    +
    Name collision. An object with the same name is already existing in the directory.
    FR_INVALID_OBJECT
    The file/directory object is invalid or a null pointer is given. There are some reasons as follows: @@ -87,20 +87,25 @@ Note that if once this error occured at any operation to an open file, the file
    A write mode operation against the write-protected media.
    FR_INVALID_DRIVE
    -
    Invalid drive number is specified in the path name. A null pointer is given as the path name. (Related option: FF_VOLUMES)
    +
    Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: FF_VOLUMES)
    FR_NOT_ENABLED
    Work area for the logical drive has not been registered by f_mount function.
    FR_NO_FILESYSTEM
    -
    There is no valid FAT volume on the drive or wrong lower layer implementation.
    +
    Valid FAT volume could not be found in the drive. One of the following possibilities is suspected. +
      +
    • The FAT volume on the drive is collapsed.
    • +
    • Wrong lower layer implementation.
    • +
    • Wrong VolToPart[] settings. (FF_MULTI_PARTITION = 1)
    • +
    FR_MKFS_ABORTED
    The f_mkfs function aborted before start in format due to a reason as follows:
      -
    • It is impossible to format with the given parameters.
    • -
    • The size of volume is too small. 128 sectors minimum with FM_SFD.
    • -
    • The partition bound to the logical drive coulud not be found. (Related option: FF_MULTI_PARTITION)
    • +
    • It is impossible to create the volume with the given conditions.
    • +
    • The size of the volume is too small. 128 sectors minimum with FM_SFD option.
    • +
    • The partition associated with the logical drive is not exist. (Related option: FF_MULTI_PARTITION)
    diff --git a/documents/doc/read.html b/documents/doc/read.html index 70b51c33024dfa67944cc2b9c16c09b6fe975cac..9dff6237e3fdea64cc02957a5328b9728d58e9ef 100644 --- a/documents/doc/read.html +++ b/documents/doc/read.html @@ -32,9 +32,9 @@ FRESULT f_read (
    buff
    Pointer to the buffer to store the read data.
    btr
    -
    Number of bytes to read in range of UINT type.
    +
    Number of bytes to read in range of UINT type. If the file needs to be read fast, it should be read in large chunk as possible.
    br
    -
    Pointer to the UINT variable that receives number of bytes read. This value is always valid after the function call regardless of the function return code.
    +
    Pointer to the UINT 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 btr, the function return code should be FR_OK.
    @@ -54,7 +54,7 @@ FRESULT f_read (

    Description

    -

    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, *br should be checked to detect end of the file. In case of *br < btr, it means the read/write pointer reached end of the file during read operation.

    +

    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, *br should be checked to detect end of the file. In case of *br < btr, it means the read/write pointer hit end of the file during read operation.

    @@ -64,6 +64,12 @@ FRESULT f_read ( +
    +

    Example

    +

    Refer to the example in f_open.

    +
    + +

    See Also

    f_open, fgets, f_write, f_close, FIL

    diff --git a/documents/doc/readdir.html b/documents/doc/readdir.html index 15fad8d2cc713ec95e834430459fc0d6e26da9ab..52a96b9693a37819850ae2fdfbe4a62a693e30cc 100644 --- a/documents/doc/readdir.html +++ b/documents/doc/readdir.html @@ -20,6 +20,11 @@ FRESULT f_readdir ( FILINFO* fno /* [OUT] File information structure */ ); +
    +FRESULT f_rewinddir (
    +  DIR* dp       /* [IN] Directory object */
    +);
    +
    @@ -48,15 +53,19 @@ FRESULT f_readdir (

    Description

    -

    The f_readdir function reads a directory item, informations about the object. Every item in the directory can be read in sequence by f_readdir function calls. Dot entries ("." and "..") 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 fno->fname[] without any error. When a null pointer is given to the fno, the read index of the directory object is rewinded.

    -

    When support of long file name (LFN) is enabled, a member altname[] 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 fname[] and altname[] has a null string.

    +

    The f_readdir function reads a directory item, informations about the object, from the open directory. Items in the directory can be read in sequence by f_readdir function calls. When all items in the directory have been read and no item to read, a null string is stored into the fno->fname[] without any error. When a null pointer is given to the fno, the read index of the directory object is rewinded. The f_rewinddir function is implemented as a macro.

    +
    +#define f_rewinddir(dp) f_readdir((dp), 0)
    +
    +

    When LFN is enabled, a member altname[] 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 a reason listed below, short file name is stored to the fname[] and the altname[] has a null string.

    -

    There is a problem on reading a directory of exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned into the fname[] to indicate that the object is not accessible. To avoid this problem, configure FatFs FF_LFN_UNICODE >= 1 and FF_MAX_LFN == 255 to support the full feature of LFN specification.

    +

    There is an issue on read directories in exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned as the file name to indicate that the object is not accessible. To avoid this problem, configure FatFs FF_LFN_UNICODE != 0 and FF_MAX_LFN == 255 to support the full feature of LFN specification.

    +

    Dot entries ("." and "..") in the sub-directory of FAT volume are filtered out and they will never appear in the read items because exFAT lacks dot entries in the sub-directory.

    @@ -94,7 +103,7 @@ FRESULT scan_files ( printf("%s/%s\n", path, fno.fname); } } - f_closedir(&dir) + f_closedir(&dir); } return res; diff --git a/documents/doc/sdir.html b/documents/doc/sdir.html index 53a460d0909465d58cd5aa71cddc5c73114dd164..eb18cc323c0862299142a6c1251be85ef165199b 100644 --- a/documents/doc/sdir.html +++ b/documents/doc/sdir.html @@ -19,7 +19,7 @@ FFOBJID obj; /* Object identifier */ DWORD dptr; /* Current read/write offset */ DWORD clust; /* Current cluster */ - DWORD sect; /* Current sector */ + LBA_t sect; /* Current sector */ BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE* fn; /* Pointer to the SFN buffer (in/out) {file[8],ext[3],status[1]} */ #if FF_USE_LFN diff --git a/documents/doc/sfatfs.html b/documents/doc/sfatfs.html index 51564685fe4edb291785c349d2c1a220a00e3f00..6ecd6e5e59f28017015e47a6d0a16a1b2f06b659 100644 --- a/documents/doc/sfatfs.html +++ b/documents/doc/sfatfs.html @@ -47,11 +47,11 @@ #endif DWORD n_fatent; /* Number of FAT entries (Number of clusters + 2) */ DWORD fsize; /* Sectors per FAT */ - DWORD volbase; /* Volume base LBA */ - DWORD fatbase; /* FAT base LBA */ - DWORD dirbase; /* Root directory base (LBA|Cluster) */ - DWORD database; /* Data base LBA */ - DWORD winsect; /* Sector LBA appearing in the win[] */ + LBA_t volbase; /* Volume base LBA */ + LBA_t fatbase; /* FAT base LBA */ + LBA_t dirbase; /* Root directory base (LBA|Cluster) */ + LBA_t database; /* Data base LBA */ + LBA_t winsect; /* Sector LBA appearing in the win[] */ BYTE win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data at tiny cfg) */ } FATFS; diff --git a/documents/doc/sfile.html b/documents/doc/sfile.html index e8a677f7dc622a9ddb347b833bd045b213ab7cdb..9234d32994a0c30f71df0e45c735d2b66d04f18d 100644 --- a/documents/doc/sfile.html +++ b/documents/doc/sfile.html @@ -22,9 +22,9 @@ BYTE err; /* Abort flag (error code) */ FSIZE_t fptr; /* File read/write pointer (Byte offset origin from top of the file) */ DWORD clust; /* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */ - DWORD sect; /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/ + LBA_t sect; /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/ #if !FF_FS_READONLY - DWORD dir_sect; /* Sector number containing the directory entry */ + LBA_t dir_sect; /* Sector number containing the directory entry */ BYTE* dir_ptr; /* Ponter to the directory entry in the window */ #endif #if FF_USE_FASTSEEK diff --git a/documents/doc/sfileinfo.html b/documents/doc/sfileinfo.html index b4c906364d02ffc11373e206d329545c29012246..db0f45e3b10f44bf50d79abec11350e20995b280 100644 --- a/documents/doc/sfileinfo.html +++ b/documents/doc/sfileinfo.html @@ -13,7 +13,7 @@

    FILINFO

    -

    The FILINFO structure holds information about the object returned by f_readdir, f_findfirst, f_findnext and f_stat function. Be careful in the size of structure when LFN is enabled.

    +

    The FILINFO structure holds information about the object retrieved by f_readdir, f_findfirst, f_findnext and f_stat function. Be careful in the size of structure when LFN is enabled.

     typedef struct {
         FSIZE_t fsize;               /* File size */
    @@ -33,9 +33,9 @@
     

    Members

    fsize
    -
    Indicates size of the file in unit of byte. FSIZE_t is an alias of integer type either DWORD(32-bit) or QWORD(64-bit) depends on the configuration option FF_FS_EXFAT. Do not care when the item is a directory.
    +
    Size of the file in unit of byte. FSIZE_t is an alias of integer type either DWORD(32-bit) or QWORD(64-bit) depends on the configuration option FF_FS_EXFAT. Do not care if the item is a sub-directory.
    fdate
    -
    Indicates the date when the file was modified or the directory was created.
    +
    The date when the file was modified or the directory was created.
    bit15:9
    Year origin from 1980 (0..127)
    @@ -46,7 +46,7 @@
    ftime
    -
    Indicates the time when the file was modified or the directory was created.
    +
    The time when the file was modified or the directory was created.
    bit15:11
    Hour (0..23)
    @@ -57,7 +57,7 @@
    fattrib
    -
    Indicates the attribute flags in combination of:
    +
    The attribute flags in combination of:
    @@ -68,9 +68,9 @@
    FlagMeaning
    AM_RDORead-only. Write mode open and deleting is rejected.
    fname[]
    -
    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 fname[] and altname[] each can be configured at LFN configuration.
    +
    Null-terminated object name. A null string is stored when no item to read and it indicates this structure is invalid. The size of fname[] and altname[] each can be configured in LFN configuration.
    altname[]
    -
    Alternative object name is stored if available. This member is not available at non-LFN configuration.
    +
    Alternative object name is stored if available. This member is not available in non-LFN configuration.

    Return

    diff --git a/documents/doc/stat.html b/documents/doc/stat.html index db636675ef41161efe7f922ab052d0b9ee1ab4cf..a4e4fc881906c3c0f84611f061f6b21e8b5b3d36 100644 --- a/documents/doc/stat.html +++ b/documents/doc/stat.html @@ -28,7 +28,7 @@ FRESULT f_stat (
    path
    Pointer to the null-terminated string that specifies the object to get its information. The object must not be the root direcotry.
    fno
    -
    Pointer to the blank FILINFO structure to store the information of the object. Set null pointer if it is not needed.
    +
    Pointer to the blank FILINFO structure to store the information of the object. Set null pointer if this information is not needed.
    @@ -54,7 +54,8 @@ FRESULT f_stat (

    Description

    -

    The f_stat function checks the existence of a file or sub-directory. If not exist, the function returns with FR_NO_FILE. If exist, the function returns with FR_OK 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 FILINFO structure and f_readdir function.

    +

    The f_stat function checks the existence of a file or sub-directory in the directory. If it is not exist, the function returns with FR_NO_FILE. If it is exist, the function returns with FR_OK 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 FILINFO structure and f_readdir function.

    +

    Note that the file information comes from the meta data in the directory. If the file has been opend and modified, the file will need to be synched or closed in order to obtain the latest file information.

    @@ -69,16 +70,17 @@ FRESULT f_stat (
         FRESULT fr;
         FILINFO fno;
    +    const char *fname = "file.txt";
     
     
    -    printf("Test for 'file.txt'...\n");
    +    printf("Test for \"%s\"...\n", fname);
     
    -    fr = f_stat("file.txt", &fno);
    +    fr = f_stat(fname, &fno);
         switch (fr) {
     
         case FR_OK:
             printf("Size: %lu\n", fno.fsize);
    -        printf("Timestamp: %u/%02u/%02u, %02u:%02u\n",
    +        printf("Timestamp: %u-%02u-%02u, %02u:%02u\n",
                    (fno.fdate >> 9) + 1980, fno.fdate >> 5 & 15, fno.fdate & 31,
                    fno.ftime >> 11, fno.ftime >> 5 & 63);
             printf("Attributes: %c%c%c%c%c\n",
    @@ -90,7 +92,7 @@ FRESULT f_stat (
             break;
     
         case FR_NO_FILE:
    -        printf("It is not exist.\n");
    +        printf("\"%s\" is not exist.\n", fname);
             break;
     
         default:
    diff --git a/documents/doc/sync.html b/documents/doc/sync.html
    index 8fcace4b857a6228fe4f6047f0da1193dbc03a9e..9fb42a090737678685ecd646645443ec99339012 100644
    --- a/documents/doc/sync.html
    +++ b/documents/doc/sync.html
    @@ -44,12 +44,12 @@ FRESULT f_sync (
     
     

    Description

    -

    The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync 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 application note.

    +

    The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync 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 application note.

     Case 1. Normal write sequence
     
    -                                Time -->                                     ↓Power off after close
    -OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC
    +                                Time -->                                     ↓Normal shutdown
    +OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC <Power off>
     
     
     Case 2. Without using f_sync()
    diff --git a/documents/doc/write.html b/documents/doc/write.html
    index 3fa61000aa158f4377aba3b8c11347164f6885f1..3d166742f4be6b7f4f2d2910f17436240f8463ed 100644
    --- a/documents/doc/write.html
    +++ b/documents/doc/write.html
    @@ -32,9 +32,9 @@ FRESULT f_write (
     
    buff
    Pointer to the data to be written.
    btw
    -
    Specifies number of bytes to write in range of UINT type.
    +
    Specifies number of bytes to write in range of UINT type. If the data needs to be written fast, it should be written in large chunk as possible.
    bw
    -
    Pointer to the UINT variable that receives the number of bytes written. This value is always valid after the function call regardless of the function return code.
    +
    Pointer to the UINT 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 btw, the function return code should be FR_OK.
    @@ -54,7 +54,7 @@ FRESULT f_write (

    Description

    -

    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, *bw should be checked to detect the disk full. In case of *bw < btw, 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.

    +

    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, *bw should be checked to detect the disk full. In case of *bw < btw, 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.

    @@ -64,6 +64,12 @@ FRESULT f_write (
    +
    +

    Example

    +

    Refer to the example in f_open.

    +
    + +

    See Also

    f_open, f_read, fputc, fputs, fprintf, f_close, FIL

    diff --git a/documents/res/app4.c b/documents/res/app4.c index 4209f39aea29a7f1a1e2008bb61a4302bfa936c5..c46d1a05db97269dd8846b7bf0dabdd6036f116d 100644 --- a/documents/res/app4.c +++ b/documents/res/app4.c @@ -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"); - } 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"); + 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: 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 { diff --git a/documents/res/app5.c b/documents/res/app5.c index cbee7cae8de6c4a57ac366926b705157c7bb4b72..2739019832f92aaf28f21d13dd209d689fbdeb32 100644 --- a/documents/res/app5.c +++ b/documents/res/app5.c @@ -13,7 +13,7 @@ FRESULT test_contiguous_file ( *cont = 0; - fr = f_lseek(fp, 0); /* Validates and prepares the file */ + fr = f_rewind(fp); /* Validates and prepares the file */ if (fr != FR_OK) return fr; #if FF_MAX_SS == FF_MIN_SS @@ -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) { diff --git a/documents/res/app6.c b/documents/res/app6.c new file mode 100644 index 0000000000000000000000000000000000000000..4a3565e8befab38f1cd86e32a6bc96840bb925b4 --- /dev/null +++ b/documents/res/app6.c @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------*/ +/* Raw Read/Write Throughput Checker */ +/*---------------------------------------------------------------------*/ + +#include +#include +#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; +} + diff --git a/documents/res/mkfs.xlsx b/documents/res/mkfs.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/documents/res/uniconv.zip b/documents/res/uniconv.zip new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/documents/updates.html b/documents/updates.html new file mode 100644 index 0000000000000000000000000000000000000000..29d881ffade30572146b6df30516692772ee8fb9 --- /dev/null +++ b/documents/updates.html @@ -0,0 +1,479 @@ + + + + + + + + +FatFs - Known Problems + + +

    Updates and Migration Notes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    RevisionUpdatesMigration Notes
    R0.15
    Nov 6, 2022
    +Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
    +Fixed a potential error in f_mount when FF_FS_REENTRANT.
    +Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
    +Fixed f_mkfs creates broken exFAT volume when the size of volume is >= 2^32 sectors.
    +Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
    +Fixed a compatibility issue in identification of GPT header.
    +
    +User provided synchronization functions, ff_cre_syncobj, ff_del_syncobj, ff_req_grant and ff_rel_grant, needed when FF_FS_REENTRANT are replaced by ff_mutex_create, ff_mutex_delete, ff_mutex_take and ff_mutex_give respectively. For examples, see ffsystem.c.
    +FF_SYNC_t is removed from the configuration options.
    +
    R0.14b
    Apr 17, 2021
    +Made FatFs uses standard library string.h for copy, compare and search instead of built-in string functions.
    +Added support for long long integer and floating point to f_printf. (FF_STRF_LLI and FF_STRF_FP)
    +Made path name parser ignores the terminating separator to allow "dir/".
    +Improved the compatibility in Unix style path name feature.
    +Fixed the file gets dead-locked when f_open failed with certain conditions. (appeared at R0.12a)
    +Fixed f_mkfs can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
    +Fixed code page 855 cannot be set by f_setcp. (appeared at R0.13)
    +Fixed some compiler warnings.
    +
    +From this revision, FatFs depends on string.h.
    +
    R0.14a
    Dec 05, 2020
    +Limited number of recursive calls in f_findnext to prevent stack overflow.
    +Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
    +Fixed some compiler warnings.
    +
    +Number of wildcards in the matching pattern in f_findfirst is limited to 4.
    +
    R0.14
    Oct 14, 2019
    +Added support for 64-bit LBA and GUID partition table (FF_LBA64)
    +Changed some API functions, f_mkfs and f_fdisk.
    +Fixed f_open cannot find the file with file name in length of FF_MAX_LFN characters.
    +Fixed f_readdir cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
    +Fixed f_readdir returns file names with wrong case conversion. (appeared at R0.12)
    +Fixed f_mkfs can fail to create exFAT volume in the second partition. (appeared at R0.12)
    +
    +Usage of f_mkfs and f_fdisk is changed and some features are added to these functions.
    +
    R0.13c
    Oct 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)
    +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)
    +
    +From this revision, FatFs depends on stdint.h in C99 or later.
    +integer.h is removed.
    +
    R0.13b
    Apr 07, 2018
    +Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
    +Added support for Unix style volume prefix. (FF_STR_VOLUME_ID = 2)
    +Fixed accesing objects in the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
    +Fixed f_setlabel does not reject some invalid characters. (appeared at R0.09b)
    +
    +
    R0.13a
    Oct 14, 2017
    +Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
    +Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF)
    +Added dynamic memory allocation option for working buffer of f_mkfs and f_fdisk.
    +Fixed f_fdisk and f_mkfs create the partition table with wrong CHS parameters. (appeared at R0.09)
    +Fixed f_unlink can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
    +Fixed f_setlabel rejects some valid characters for exFAT volume. (appeared at R0.12)
    +
    +
    R0.13
    May 21, 2017
    +Prefix of configuration item names are changed from "_" to "FF_".
    +Added f_setcp, run-time code page configuration. (FF_CODE_PAGE = 0)
    +Improved cluster allocation time on stretch a deep buried cluster chain.
    +Improved processing time of f_mkdir with large cluster size by using FF_USE_LFN = 3.
    +Improved exFAT NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
    +Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
    +Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
    +Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
    +
    +ASCII only configuration, FF_CODE_PAGE = 1, is removed. Use FF_CODE_PAGE = 437 instead.
    +
    R0.12c
    Mar 04, 2017
    +Improved write throughput at the fragmented file on the exFAT volume.
    +Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
    +Fixed successive f_getfree can return wrong count on the FAT12/16 volume. (appeared at R0.12)
    +Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
    +
    +
    R0.12b
    Sep 4, 2016
    +Made f_rename be able to rename objects with the same name but case.
    +Fixed an error in the case conversion teble of code page 866. (ff.c)
    +Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
    +Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
    +Fixed f_mkfs creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12a)
    +Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
    +Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
    +Fixed some internal errors in f_expand and f_lseek. (appeared at R0.12)
    +
    +
    R0.12a
    Jul 10, 2016
    +Added support for creating exFAT volume with some changes of f_mkfs.
    +Added a file open method FA_OPEN_APPEND.
    +f_forward is available regardless of _FS_TINY.
    +Fixed f_mkfs creates broken volume. (appeared at R0.12)
    +Fixed wrong memory read in create_name. (appeared at R0.12)
    +Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
    +
    +Usage of f_mkfs is changed.
    +
    R0.12
    Apr 12, 2016
    +Added support for exFAT file system. (_FS_EXFAT)
    +Added f_expand. (_USE_EXPAND)
    +Changed some members in FINFO and behavior of f_readdir.
    +Added a configuration option _USE_CHMOD.
    +Fixed errors in the case conversion teble of Unicode (cc*.c).
    +
    +Usage and members of FINFO sructure used in f_readdir is changed.
    +Many members in FIL and DIR structure are changed.
    +To use f_chmod, _USE_CHMOD needs to be set.
    +_WORD_ACCESS is removed from the configuration options.
    +Dot entries are never appear in f_reeddir.
    +
    R0.11a
    Sep 5, 2015
    +Fixed wrong media change can lead a deadlock at thread-safe configuration.
    +Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
    +Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
    +Fixed errors in the case conversion teble of Unicode (cc*.c).
    +
    +Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
    +
    R0.11
    Feb 9, 2015
    +Added f_findfirst and f_findnext. (_USE_FIND)
    +Fixed f_unlink does not remove cluster chain of the file. (appeared at R0.10c)
    +Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
    +
    +
    R0.10c
    Nov 9, 2014
    +Added a configuration option for the platforms without RTC. (_FS_NORTC)
    +Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel. (appeared at R0.09b)
    +Fixed a potential problem of FAT access that can appear on disk error.
    +Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
    +
    +
    R0.10b
    May 19, 2014
    +Fixed a hard error in the disk I/O layer can collapse the directory entry.
    +Fixed LFN entry is not deleted on delete/rename an object with its lossy converted SFN. (appeared at R0.07)
    +
    +
    R0.10a
    Jan 15, 2014
    +Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
    +Added an option for minimum sector size. (_MIN_SS)
    +2nd argument of f_rename can have a drive number and it will be ignored.
    +Fixed f_mount with forced mount fails when drive number is larger than 0. (appeared at R0.10)
    +Fixed f_close invalidates the file object without volume lock.
    +Fixed volume lock is left acquired after return from f_closedir. (appeared at R0.10)
    +Fixed creation of a directory entry with LFN fails on too many SFN collisions. (appeared at R0.07)
    +
    +
    R0.10
    Oct 2, 2013
    +Added an option for character encoding on the file. (_STRF_ENCODE)
    +Added f_closedir.
    +Added forced full FAT scan option for f_getfree. (_FS_NOFSINFO)
    +Added forced mount option with changes of f_mount.
    +Improved behavior of volume auto detection.
    +Improved write throughput of f_puts and f_printf.
    +Changed argument of f_chdrive, f_mkfs, disk_read and disk_write.
    +Fixed f_write can be truncated when the file size is close to 4 GB.
    +Fixed f_open, f_mkdir and f_setlabel can return incorrect result code on error.
    +
    +
    R0.09b
    Jan 24, 2013
    +Added f_getlabel and f_setlabel. (_USE_LABEL)
    +
    +
    R0.09a
    Aug 27, 2012
    +Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
    +Changed file functions reject null object pointer to avoid crash.
    +Changed option name _FS_SHARE to _FS_LOCK.
    +
    +
    R0.09
    Sep 6, 2011
    +f_mkfs supports multiple partition on a physical drive.
    +Added f_fdisk. (_MULTI_PARTITION = 2)
    +
    +
    R0.08b
    Jan 15, 2011
    +Fast seek function is also applied to f_read and f_write.
    +f_lseek reports required table size on creating CLMP.
    +Extended format syntax of f_printf.
    +Ignores duplicated directory separators in given path names.
    +
    +
    R0.08a
    Aug 16, 2010
    +Added f_getcwd. (_FS_RPATH = 2)
    +Added sector erase function. (_USE_ERASE)
    +Moved file lock semaphore table from fs object to the bss.
    +Fixed f_mkdir creates wrong directory on non-LFN cfg when the given name contains ';'.
    +Fixed f_mkfs creates wrong FAT32 volume.
    +
    +
    R0.08
    May 15, 2010
    +Added an option to _USE_LFN
    +Added support of file lock. (_FS_SHARE)
    +Added fast seek function. (_USE_FASTSEEK)
    +Changed a type name on the API, XCHAR to TCHAR.
    +Changed member, fname, in the FILINFO on Unicode cfg.
    +String functions support UTF-8 encoding files on Unicode cfg.
    +
    +
    R0.07e
    Nov 3, 2009
    +Separated out configuration options from ff.h to ffconf.h.
    +Added a configuration option, _LFN_UNICODE.
    +Fixed f_unlink fails to remove a sub-dir on _FS_RPATH.
    +Fixed name matching error on the 13 char boundary.
    +Changed f_readdir to return the SFN with always upper case on non-LFN cfg.
    +
    +
    R0.07c
    Jan 21, 2009
    +Fixed f_unlink may return FR_OK on error.
    +Fixed wrong cache control in f_lseek.
    +Added support of relative path.
    +Added f_chdir.
    +Added f_chdrive.
    +Added proper case conversion to extended characters.
    +
    +
    R0.07a
    Apr 14, 2009
    +Separated out OS dependent code on re-entrant configuration.
    +Added multiple sector size support.
    +
    +
    R0.07
    Apr 1, 2009
    +Merged Tiny-FatFs into FatFs as a buffer configuration option.
    +Added support for long file extension.
    +Added multiple code page support.
    +Added re-entrancy for multitask operation.
    +Added auto cluster size selection to f_mkfs.
    +Added rewind option to f_readdir.
    +Changed result code of critical errors.
    +Renamed string functions to avoid name collision.
    +
    +
    R0.06
    Apr 1, 2008
    +Added f_forward. (Tiny-FatFs)
    +Added string functions: f_gets, f_putc, f_puts and f_printf.
    +Improved performance of f_lseek on moving to the same or following cluster.
    +
    +
    R0.05a
    Feb 3, 2008
    +Added f_truncate.
    +Added f_utime.
    +Fixed off by one error at FAT sub-type determination.
    +Fixed btr in f_read can be mistruncated.
    +Fixed cached sector is left not flushed when create and close without write.
    +
    +
    R0.05
    Aug 26, 2007
    +Changed arguments of f_read, f_write.
    +Changed arguments of f_mkfs. (FatFs)
    +Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
    +Fixed f_mkdir on FAT32 creates broken directory. (FatFs)
    +
    +
    R0.04b
    May 5, 2007
    +Added _USE_NTFLAG option.
    +Added support for FSInfo in FAT32 volume.
    +Fixed some problems corresponds to FAT32. (Tiny-FatFs)
    +Fixed DBCS name can result FR_INVALID_NAME.
    +Fixed short seek (<= csize) collapses the file object.
    +
    +
    R0.04a
    Apr 1, 2007
    +Supported multiple partitions on a plysical drive. (FatFs)
    +Added minimization level 3.
    +Added a capability of extending file size to f_lseek.
    +Fixed an endian sensitive code in f_mkfs. (FatFs)
    +Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)
    +
    +
    R0.04
    Feb 4, 2007
    +Supported multiple drive system. (FatFs)
    +Changed some APIs for multiple drive system.
    +Added f_mkfs. (FatFs)
    +Added _USE_FAT32 option. (Tiny-FatFs)
    +
    +
    R0.03a
    Dec 11, 2006
    +Improved cluster scan algolithm to write files fast.
    +Fixed f_mkdir creates broken directory on FAT32.
    +
    +
    R0.03
    Sep 22, 2006
    +Added f_rename. +Changed option _FS_MINIMUM to _FS_MINIMIZE.
    +
    +
    R0.02a
    Jun 10, 2006
    +Added a configuration option _FS_MINIMUM.
    +
    +
    R0.02
    Jun 01, 2006
    +Added FAT12.
    +Removed unbuffered mode.
    +Fixed a problem on small (<32M) patition.
    +
    +
    R0.01
    Apr 29, 2006
    +First release.
    +
    +
    + + diff --git a/documents/updates.txt b/documents/updates.txt deleted file mode 100644 index 95ed9fd048506791c29b3fe5224d7d69932ffe3a..0000000000000000000000000000000000000000 --- a/documents/updates.txt +++ /dev/null @@ -1,226 +0,0 @@ -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) - 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.13b (April 07, 2018) - Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3) - Added support for Unix style volume prefix. (FF_STR_VOLUME_ID = 2) - Fixed accesing any object on the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c) - Fixed f_setlabel() does not reject some invalid characters. (appeared at R0.09b) - -R0.13a (October 14, 2017) - Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2) - Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF). - Added dynamic memory allocation option for working buffer of f_mkfs() and f_fdisk(). - Fixed f_fdisk() and f_mkfs() create the partition table with wrong CHS parameters. (appeared at R0.09) - Fixed f_unlink() can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c) - Fixed f_setlabel() rejects some valid characters for exFAT volume. (appeared at R0.12) - -R0.13 (May 21, 2017) - Changed heading character of configuration keywords "_" to "FF_". - Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead. - Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0) - Improved cluster allocation time on stretch a deep buried cluster chain. - Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3. - Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous. - Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12) - Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c) - Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c) - -R0.12c (March 04, 2017) - Improved write throughput at the fragmented file on the exFAT volume. - Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN. - Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12) - Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c) - -R0.12b (September 4, 2016) - Made f_rename() be able to rename objects with the same name but case. - Fixed an error in the case conversion teble of code page 866. (ff.c) - Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12) - Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12) - Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12a) - Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12) - Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12) - Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12) - -R0.12a (July 10, 2016) - Added support for creating exFAT volume with some changes of f_mkfs(). - Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed. - f_forward() is available regardless of _FS_TINY. - Fixed f_mkfs() creates wrong volume. (appeared at R0.12) - Fixed wrong memory read in create_name(). (appeared at R0.12) - Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD. - -R0.12 (April 12, 2016) - Added support for exFAT file system. (_FS_EXFAT) - Added f_expand(). (_USE_EXPAND) - Changed some members in FINFO structure and behavior of f_readdir(). - Added an option _USE_CHMOD and removed an option _WORD_ACCESS. - Fixed errors in the case conversion teble of Unicode (cc*.c). - -R0.11a (September 5, 2015) - Fixed wrong media change can lead a deadlock at thread-safe configuration. - Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE) - Removed some code pages actually not exist on the standard systems. (_CODE_PAGE) - Fixed errors in the case conversion teble of code page 437 and 850 (ff.c). - Fixed errors in the case conversion teble of Unicode (cc*.c). - -R0.11 (February 9, 2015) - Added f_findfirst() and f_findnext(). (_USE_FIND) - Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c) - Fixed _FS_NORTC option does not work properly. (appeared at R0.10c) - -R0.10c (November 9, 2014) - Added a configuration option for the platforms without RTC. (_FS_NORTC) - Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b) - Fixed a potential problem of FAT access that can appear on disk error. - Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08) - -R0.10b (May 19, 2014) - Fixed a hard error in the disk I/O layer can collapse the directory entry. - Fixed LFN entry is not deleted on delete/rename an object with its lossy converted SFN. (appeared at R0.07) - -R0.10a (January 15, 2014) - Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID) - Added an option for minimum sector size. (_MIN_SS) - 2nd argument of f_rename() can have a drive number and it will be ignored. - Fixed f_mount() with forced mount fails when drive number is larger than 0. (appeared at R0.10) - Fixed f_close() invalidates the file object without volume lock. - Fixed volume lock is left acquired after return from f_closedir(). (appeared at R0.10) - Fixed creation of a directory entry with LFN fails on too many SFN collisions. (appeared at R0.07) - -R0.10 (October 2, 2013) - Added an option for character encoding on the file. (_STRF_ENCODE) - Added f_closedir(). - Added forced full FAT scan option for f_getfree(). (_FS_NOFSINFO) - Added forced mount option with changes of f_mount(). - Improved behavior of volume auto detection. - Improved write throughput of f_puts() and f_printf(). - Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). - Fixed f_write() can be truncated when the file size is close to 4GB. - Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect result code on error. - -R0.09b (January 24, 2013) - Added f_getlabel() and f_setlabel(). (_USE_LABEL = 1) - -R0.09a (August 27, 2012) - Fixed assertion failure due to OS/2 EA on FAT12/16 volume. - Changed file functions reject null object pointer to avoid crash. - Changed option name _FS_SHARE to _FS_LOCK. - -R0.09 (September 6, 2011) - f_mkfs() supports multiple partition on a physical drive. - Added f_fdisk(). (_MULTI_PARTITION = 2) - -R0.08b (January 15, 2011) - Fast seek function is also applied to f_read() and f_write(). - f_lseek() reports required table size on creating CLMP. - Extended format syntax of f_printf(). - Ignores duplicated directory separators in given path names. - -R0.08a (August 16, 2010) - Added f_getcwd(). (_FS_RPATH = 2) - Added sector erase function. (_USE_ERASE) - Moved file lock semaphore table from fs object to the bss. - Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'. - Fixed f_mkfs() creates wrong FAT32 volume. - -R0.08 (May 15, 2010) - Added a memory configuration option. (_USE_LFN) - Added support of file lock. (_FS_SHARE) - Added fast seek function. (_USE_FASTSEEK) - Changed some types on the API, XCHAR->TCHAR. - Changed fname member in the FILINFO structure on Unicode cfg. - String functions support UTF-8 encoding files on Unicode cfg. - -R0.07e (November 3, 2009) - Separated out configuration options from ff.h to ffconf.h. - Added a configuration option, _LFN_UNICODE. - Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. - Fixed name matching error on the 13 char boundary. - Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. - -R0.07c (Junuary 21, 2009) - Fixed f_unlink() may return FR_OK on error. - Fixed wrong cache control in f_lseek(). - Added support of relative path. - Added f_chdir(). - Added f_chdrive(). - Added proper case conversion to extended characters. - -R0.07a (April 14, 2009) - Separated out OS dependent code on re-entrant configuration. - Added multiple sector size support. - -R0.07 (April 1, 2009) - Merged Tiny-FatFs into FatFs as a buffer configuration option. - Added long file name support. - Added multiple code page support. - Added re-entrancy for multitask operation. - Added auto cluster size selection to f_mkfs(). - Added rewind option to f_readdir(). - Changed result code of critical errors. - Renamed string functions to avoid name collision. - -R0.06 (April 1, 2008) - Added f_forward. (Tiny-FatFs) - Added string functions: fgets, fputc, fputs and fprintf. - Improved performance of f_lseek on moving to the same or following cluster. - -R0.05a (February 3, 2008) - Added f_truncate. - Added f_utime. - Fixed off by one error at FAT sub-type determination. - Fixed btr in f_read can be mistruncated. - Fixed cached sector is left not flushed when create and close without write. - -R0.05 (August 26, 2007) - Changed arguments of f_read, f_write. - Changed arguments of f_mkfs. (FatFs) - Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs) - Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs) - -R0.04b (May 5, 2007) - Added _USE_NTFLAG option. - Added FSInfo support. - Fixed some problems corresponds to FAT32. (Tiny-FatFs) - Fixed DBCS name can result FR_INVALID_NAME. - Fixed short seek (<= csize) collapses the file object. - -R0.04a (April 1, 2007) - Supported multiple partitions on a plysical drive. (FatFs) - Added minimization level 3. - Added a capability of extending file size to f_lseek. - Fixed an endian sensitive code in f_mkfs. (FatFs) - Fixed a problem corresponds to FAT32 support. (Tiny-FatFs) - -R0.04 (February 4, 2007) - Supported multiple drive system. (FatFs) - Changed some APIs for multiple drive system. - Added f_mkfs. (FatFs) - Added _USE_FAT32 option. (Tiny-FatFs) - -R0.03a (December 11, 2006) - Improved cluster scan algolithm to write files fast. - Fixed f_mkdir creates incorrect directory on FAT32. - -R0.03 (September 22, 2006) - Added f_rename. - Changed option _FS_MINIMUM to _FS_MINIMIZE. - -R0.02a (June 10, 2006) - Added a configuration option _FS_MINIMUM. - -R0.02 (Jun 01, 2006) - Added FAT12. - Removed unbuffered mode. - Fixed a problem on small (<32M) patition. - -R0.01 (April 29, 2006) - First release - -R0.00 (February 26, 2006) - Prototype (not released) - diff --git a/source/00history.txt b/source/00history.txt index c0e3e741acaeadc65d26edc36cf9c72ead154aa8..4fa1d7a1b549c210354c1857e11dd231684eaae9 100644 --- a/source/00history.txt +++ b/source/00history.txt @@ -328,3 +328,42 @@ 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) + + +R0.14a (December 5, 2020) + Limited number of recursive calls in f_findnext(). + Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted. + Fixed some compiler warnings. + + + +R0.14b (April 17, 2021) + Made FatFs uses standard library for copy, compare and search instead of built-in string functions. + Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP) + Made path name parser ignore the terminating separator to allow "dir/". + Improved the compatibility in Unix style path name feature. + Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a) + Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12) + Fixed code page 855 cannot be set by f_setcp(). + Fixed some compiler warnings. + + + +R0.15 (November 6, 2022) + Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code. + FF_SYNC_t is removed from the configuration options. + Fixed a potential error in f_mount when FF_FS_REENTRANT. + Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true. + Fixed f_mkfs() creates broken exFAT volume when the size of volume is >= 2^32 sectors. + Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8). + Fixed a compatibility issue in identification of GPT header. + diff --git a/source/00readme.txt b/source/00readme.txt index 809be15407cb8d6da35dbdc2b4da22010f38ac34..39f6c8ce72f95450e2fc97bd1f5ceec87e598ae4 100644 --- a/source/00readme.txt +++ b/source/00readme.txt @@ -1,4 +1,4 @@ -FatFs Module Source Files R0.14a +FatFs Module Source Files R0.15 FILES diff --git a/source/ff.c b/source/ff.c index 4345b4aaafdf0fb0adba727d1458b5cb6da28322..e912765c0c6f767b4b035818bffe4abb7f4cb073 100644 --- a/source/ff.c +++ b/source/ff.c @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem Module R0.14a / +/ FatFs - Generic FAT Filesystem Module R0.15 w/patch2 / /-----------------------------------------------------------------------------/ / -/ Copyright (C) 2020, ChaN, all right reserved. +/ Copyright (C) 2022, 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 @@ -39,7 +39,7 @@ ---------------------------------------------------------------------------*/ -#if FF_DEFINED != 80196 /* Revision ID */ +#if FF_DEFINED != 80286 /* Revision ID */ #error Wrong include file (ff.h). #endif @@ -48,6 +48,8 @@ #define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') #define IsLower(c) ((c) >= 'a' && (c) <= 'z') #define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsSeparator(c) ((c) == '/' || (c) == '\\') +#define IsTerminator(c) ((UINT)(c) < (FF_USE_LFN ? ' ' : '!')) #define IsSurrogate(c) ((c) >= 0xD800 && (c) <= 0xDFFF) #define IsSurrogateH(c) ((c) >= 0xD800 && (c) <= 0xDBFF) #define IsSurrogateL(c) ((c) >= 0xDC00 && (c) <= 0xDFFF) @@ -62,8 +64,7 @@ /* Additional file attribute bits for internal use */ #define AM_VOL 0x08 /* Volume label */ #define AM_LFN 0x0F /* LFN entry */ -#define AM_MASK 0x3F /* Mask of defined bits */ - +#define AM_MASK 0x3F /* Mask of defined bits in FAT */ /* Name status flags in fn[11] */ #define NSFLAG 11 /* Index of the name status byte */ @@ -140,26 +141,27 @@ #define PTE_StLba 8 /* MBR PTE: Start in LBA */ #define PTE_SizLba 12 /* MBR PTE: Size in LBA */ -#define GPTH_Sign 0 /* GPT: Header signature (8-byte) */ -#define GPTH_Rev 8 /* GPT: Revision (DWORD) */ -#define GPTH_Size 12 /* GPT: Header size (DWORD) */ -#define GPTH_Bcc 16 /* GPT: Header BCC (DWORD) */ -#define GPTH_CurLba 24 /* GPT: Main header LBA (QWORD) */ -#define GPTH_BakLba 32 /* GPT: Backup header LBA (QWORD) */ -#define GPTH_FstLba 40 /* GPT: First LBA for partitions (QWORD) */ -#define GPTH_LstLba 48 /* GPT: Last LBA for partitions (QWORD) */ -#define GPTH_DskGuid 56 /* GPT: Disk GUID (16-byte) */ -#define GPTH_PtOfs 72 /* GPT: Partation table LBA (QWORD) */ -#define GPTH_PtNum 80 /* GPT: Number of table entries (DWORD) */ -#define GPTH_PteSize 84 /* GPT: Size of table entry (DWORD) */ -#define GPTH_PtBcc 88 /* GPT: Partation table BCC (DWORD) */ -#define SZ_GPTE 128 /* GPT: Size of partition table entry */ +#define GPTH_Sign 0 /* GPT HDR: Signature (8-byte) */ +#define GPTH_Rev 8 /* GPT HDR: Revision (DWORD) */ +#define GPTH_Size 12 /* GPT HDR: Header size (DWORD) */ +#define GPTH_Bcc 16 /* GPT HDR: Header BCC (DWORD) */ +#define GPTH_CurLba 24 /* GPT HDR: This header LBA (QWORD) */ +#define GPTH_BakLba 32 /* GPT HDR: Another header LBA (QWORD) */ +#define GPTH_FstLba 40 /* GPT HDR: First LBA for partition data (QWORD) */ +#define GPTH_LstLba 48 /* GPT HDR: Last LBA for partition data (QWORD) */ +#define GPTH_DskGuid 56 /* GPT HDR: Disk GUID (16-byte) */ +#define GPTH_PtOfs 72 /* GPT HDR: Partition table LBA (QWORD) */ +#define GPTH_PtNum 80 /* GPT HDR: Number of table entries (DWORD) */ +#define GPTH_PteSize 84 /* GPT HDR: Size of table entry (DWORD) */ +#define GPTH_PtBcc 88 /* GPT HDR: Partition table BCC (DWORD) */ +#define SZ_GPTE 128 /* GPT PTE: Size of partition table entry */ #define GPTE_PtGuid 0 /* GPT PTE: Partition type GUID (16-byte) */ #define GPTE_UpGuid 16 /* GPT PTE: Partition unique GUID (16-byte) */ -#define GPTE_FstLba 32 /* GPT PTE: First LBA (QWORD) */ -#define GPTE_LstLba 40 /* GPT PTE: Last LBA inclusive (QWORD) */ -#define GPTE_Flags 48 /* GPT PTE: Flags (QWORD) */ -#define GPTE_Name 56 /* GPT PTE: Name */ +#define GPTE_FstLba 32 /* GPT PTE: First LBA of partition (QWORD) */ +#define GPTE_LstLba 40 /* GPT PTE: Last LBA of partition (QWORD) */ +#define GPTE_Flags 48 /* GPT PTE: Partition flags (QWORD) */ +#define GPTE_Name 56 /* GPT PTE: Partition name */ + /* Post process on fatal error in the file operations */ #define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); } @@ -168,7 +170,7 @@ /* Re-entrancy related */ #if FF_FS_REENTRANT #if FF_USE_LFN == 1 -#error Static LFN work area cannot be used at thread-safe configuration +#error Static LFN work area cannot be used in thread-safe configuration #endif #ifdef __LITEOS_M__ #define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } @@ -187,15 +189,15 @@ /* File lock controls */ -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK #if FF_FS_READONLY #error FF_FS_LOCK must be 0 at read-only configuration #endif typedef struct { - FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */ + FATFS* fs; /* Object ID 1, volume (NULL:blank entry) */ DWORD clu; /* Object ID 2, containing directory (0:root) */ DWORD ofs; /* Object ID 3, offset in the directory */ - WORD ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */ + UINT ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */ } FILESEM; #endif @@ -340,6 +342,7 @@ typedef struct { /* DBCS code range |----- 1st byte -----| |----------- 2nd byte -----------| */ +/* <------> <------> <------> <------> <------> */ #define TBL_DC932 {0x81, 0x9F, 0xE0, 0xFC, 0x40, 0x7E, 0x80, 0xFC, 0x00, 0x00} #define TBL_DC936 {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0x80, 0xFE, 0x00, 0x00} #define TBL_DC949 {0x81, 0xFE, 0x00, 0x00, 0x41, 0x5A, 0x61, 0x7A, 0x81, 0xFE} @@ -377,7 +380,7 @@ UINT time_status = SYSTEM_TIME_ENABLE; /*system time status */ static BYTE CurrVol; /* Current drive */ #endif -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */ #endif @@ -391,10 +394,11 @@ static const char* const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-define /* Code conversion tables */ /*--------------------------------*/ -#if FF_CODE_PAGE == 0 /* Run-time code page configuration */ +#if FF_CODE_PAGE == 0 /* Run-time code page configuration */ #define CODEPAGE CodePage static WORD CodePage; /* Current code page */ -static const BYTE *ExCvt, *DbcTbl; /* Pointer to current SBCS up-case table and DBCS code range table below */ +static const BYTE* ExCvt; /* Ptr to SBCS up-case table Ct???[] (null:not used) */ +static const BYTE* DbcTbl; /* Ptr to DBCS code range table Dc???[] (null:not used) */ static const BYTE Ct437[] = TBL_CT437; static const BYTE Ct720[] = TBL_CT720; @@ -599,18 +603,14 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on uc = (BYTE)*p++; /* Get an encoding unit */ if (uc & 0x80) { /* Multiple byte code? */ - if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */ + if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */ uc &= 0x1F; nf = 1; - } else { - if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */ - uc &= 0x0F; nf = 2; - } else { - if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */ - uc &= 0x07; nf = 3; - } else { /* Wrong sequence */ - return 0xFFFFFFFF; - } - } + } else if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */ + uc &= 0x0F; nf = 2; + } else if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */ + uc &= 0x07; nf = 3; + } else { /* Wrong sequence */ + return 0xFFFFFFFF; } do { /* Get trailing bytes */ b = (BYTE)*p++; @@ -648,8 +648,8 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on } -/* Output a TCHAR string in defined API encoding */ -static BYTE put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */ +/* Store a Unicode char in defined API encoding */ +static UINT put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */ DWORD chr, /* UTF-16 encoded character (Surrogate pair if >=0x10000) */ TCHAR* buf, /* Output buffer */ UINT szb /* Size of the buffer */ @@ -760,12 +760,12 @@ void unlock_fs ( -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK /*-----------------------------------------------------------------------*/ -/* File lock control functions */ +/* File shareing control functions */ /*-----------------------------------------------------------------------*/ -static FRESULT chk_lock ( /* Check if the file can be accessed */ +static FRESULT chk_share ( /* Check if the file can be accessed */ DIR* dp, /* Directory object pointing the file to be checked */ int acc /* Desired access type (0:Read mode open, 1:Write mode open, 2:Delete or rename) */ ) @@ -792,16 +792,16 @@ static FRESULT chk_lock ( /* Check if the file can be accessed */ } -static int enq_lock (void) /* Check if an entry is available for a new object */ +static int enq_share (void) /* Check if an entry is available for a new object */ { UINT i; - for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; + for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; /* Find a free entry */ return (i == FF_FS_LOCK) ? 0 : 1; } -UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */ +static UINT inc_share ( /* Increment object open counter and returns its index (0:Internal error) */ DIR* dp, /* Directory object pointing the file to register or increment */ int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ ) @@ -815,8 +815,8 @@ UINT inc_lock ( /* Increment object open counter and returns its index (0:Intern && Files[i].ofs == dp->dptr) break; } - if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */ - for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; + if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */ + for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; /* Find a free entry */ if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */ Files[i].fs = dp->obj.fs; Files[i].clu = dp->obj.sclust; @@ -832,30 +832,32 @@ UINT inc_lock ( /* Increment object open counter and returns its index (0:Intern } -static FRESULT dec_lock ( /* Decrement object open counter */ +static FRESULT dec_share ( /* Decrement object open counter */ UINT i /* Semaphore index (1..) */ ) { - WORD n; + UINT n; FRESULT res; if (--i < FF_FS_LOCK) { /* Index number origin from 0 */ n = Files[i].ctr; - if (n == 0x100) n = 0; /* If write mode open, delete the entry */ - if (n > 0) n--; /* Decrement read mode open count */ + if (n == 0x100) n = 0; /* If write mode open, delete the object semaphore */ + if (n > 0) n--; /* Decrement read mode open count */ Files[i].ctr = n; - if (n == 0) Files[i].fs = 0; /* Delete the entry if open count gets zero */ + if (n == 0) { /* Delete the object semaphore if open count becomes zero */ + Files[i].fs = 0; /* Free the entry << 1, there is a potential error in this process >>> */ + } res = FR_OK; } else { - res = FR_INT_ERR; /* Invalid index nunber */ + res = FR_INT_ERR; /* Invalid index number */ } return res; } -static void clear_lock ( /* Clear lock entries of the volume */ - FATFS *fs +static void clear_share ( /* Clear all lock entries of the volume */ + FATFS* fs ) { UINT i; @@ -876,7 +878,7 @@ FRESULT empty_lock(FATFS* fs) /* check lock entries is empty or not. */ return FR_OK; } -#endif /* FF_FS_LOCK != 0 */ +#endif /* FF_FS_LOCK */ FRESULT f_checkopenlock(int index) /* check lock entries is empty or not by index. */ { @@ -1032,7 +1034,7 @@ LBA_t clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */ /*-----------------------------------------------------------------------*/ -/* FAT access - Read value of a FAT entry */ +/* FAT access - Read value of an FAT entry */ /*-----------------------------------------------------------------------*/ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */ @@ -1087,7 +1089,7 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Clust #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* FAT access - Change value of a FAT entry */ +/* FAT access - Change value of an FAT entry */ /*-----------------------------------------------------------------------*/ FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ @@ -1112,7 +1114,7 @@ FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ res = move_window(fs, fs->fatbase + (bc / SS(fs))); if (res != FR_OK) break; p = fs->win + bc++ % SS(fs); - *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */ + *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */ fs->wflag = 1; res = move_window(fs, fs->fatbase + (bc / SS(fs))); if (res != FR_OK) break; @@ -1367,7 +1369,8 @@ static DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ FSIZE_t ofs /* File offset to be converted to cluster# */ ) { - DWORD cl, ncl, *tbl; + DWORD cl, ncl; + DWORD *tbl; FATFS *fs = fp->obj.fs; @@ -1718,7 +1721,7 @@ static void put_lfn ( do { if (wc != 0xFFFF) wc = lfn[i++]; /* Get an effective character */ st_word(dir + LfnOfs[s], wc); /* Put it */ - if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */ + if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */ } while (++s < 13); if (wc == 0xFFFF || !lfn[i]) ord |= LLEF; /* Last LFN part is the start of LFN sequence */ dir[LDIR_Ord] = ord; /* Set the LFN order */ @@ -1736,7 +1739,7 @@ static void put_lfn ( static void gen_numname ( BYTE* dst, /* Pointer to the buffer to store numbered SFN */ - const BYTE* src, /* Pointer to SFN */ + const BYTE* src, /* Pointer to SFN in directory form */ const WCHAR* lfn, /* Pointer to LFN */ UINT seq /* Sequence number */ ) @@ -1762,24 +1765,23 @@ static void gen_numname ( seq = (UINT)sreg; } - /* itoa (hexdecimal) */ + /* Make suffix (~ + hexadecimal) */ i = 7; do { - c = (BYTE)((seq % 16) + '0'); + c = (BYTE)((seq % 16) + '0'); seq /= 16; if (c > '9') c += 7; ns[i--] = c; - seq /= 16; - } while (seq); + } while (i && seq); ns[i] = '~'; - /* Append the number to the SFN body */ - for (j = 0; j < i && dst[j] != ' '; j++) { - if (dbc_1st(dst[j])) { + /* Append the suffix to the SFN body */ + for (j = 0; j < i && dst[j] != ' '; j++) { /* Find the offset to append */ + if (dbc_1st(dst[j])) { /* To avoid DBC break up */ if (j == i - 1) break; j++; } } - do { + do { /* Append the suffix */ dst[j++] = (i < 8) ? ns[i++] : ' '; } while (j < 8); } @@ -2112,7 +2114,7 @@ FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ do { res = move_window(fs, dp->sect); if (res != FR_OK) break; - dp->dir[DIR_Name] = DDEM; /* Mark an entry 'deleted' */ + dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted' */ #ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION fs->wflag = 1; @@ -2159,6 +2161,7 @@ void get_fileinfo ( BYTE lcf; WCHAR wc, hs; FATFS *fs = dp->obj.fs; + UINT nw; #else TCHAR c; #endif @@ -2169,15 +2172,18 @@ void get_fileinfo ( #if FF_USE_LFN /* LFN configuration */ if (dp->blk_ofs != 0xFFFFFFFF) { /* Get LFN if available */ - si = di = hs = 0; + si = di = 0; + hs = 0; while (fs->lfnbuf[si] != 0) { wc = fs->lfnbuf[si++]; /* Get an LFN character (UTF-16) */ if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */ hs = wc; continue; /* Get low surrogate */ } - wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in UTF-16 or UTF-8 encoding */ - if (wc == 0) { di = 0; break; } /* Invalid char or buffer overflow? */ - di += wc; + nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */ + if (nw == 0) { /* Buffer overflow or wrong char? */ + di = 0; break; + } + di += nw; hs = 0; } if (hs != 0) di = 0; /* Broken surrogate pair? */ @@ -2194,10 +2200,14 @@ void get_fileinfo ( wc = wc << 8 | dp->dir[si++]; } wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM -> Unicode */ - if (wc == 0) { di = 0; break; } /* Wrong char in the current code page? */ - wc = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in Unicode */ - if (wc == 0) { di = 0; break; } /* Buffer overflow? */ - di += wc; + if (wc == 0) { /* Wrong char in the current code page? */ + di = 0; break; + } + nw = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in API encoding */ + if (nw == 0) { /* Buffer overflow? */ + di = 0; break; + } + di += nw; #else /* ANSI/OEM output */ fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */ #endif @@ -2205,8 +2215,8 @@ void get_fileinfo ( fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */ if (fno->fname[0] == 0) { /* If LFN is invalid, altname[] needs to be copied to fname[] */ - if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccesible */ - fno->fname[di++] = '?'; + if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccessible */ + fno->fname[di++] = '\?'; } else { for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ wc = (WCHAR)fno->altname[si]; @@ -2228,10 +2238,10 @@ void get_fileinfo ( if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */ fno->fname[di++] = c; } - fno->fname[di] = 0; + fno->fname[di] = 0; /* Terminate the SFN */ #endif - fno->fattrib = dp->dir[DIR_Attr]; /* Attribute */ + fno->fattrib = dp->dir[DIR_Attr] & AM_MASK; /* Attribute */ fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */ fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */ fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */ @@ -2250,7 +2260,7 @@ void get_fileinfo ( #define FIND_RECURS 4 /* Maximum number of wildcard terms in the pattern to limit recursion */ -static DWORD get_achar ( /* Get a character and advances ptr */ +static DWORD get_achar ( /* Get a character and advance ptr */ const TCHAR** ptr /* Pointer to pointer to the ANSI/OEM or Unicode string */ ) { @@ -2288,7 +2298,8 @@ static int pattern_match ( /* 0:mismatched, 1:matched */ UINT recur /* Recursion count */ ) { - const TCHAR *pptr, *nptr; + const TCHAR *pptr; + const TCHAR *nptr; DWORD pchr, nchr; UINT sk; @@ -2302,12 +2313,16 @@ static int pattern_match ( /* 0:mismatched, 1:matched */ do { pptr = pat; nptr = nam; /* Top of pattern and name to match */ for (;;) { - if (*pptr == '?' || *pptr == '*') { /* Wildcard term? */ + if (*pptr == '\?' || *pptr == '*') { /* Wildcard term? */ if (recur == 0) return 0; /* Too many wildcard terms? */ sk = 0; do { /* Analyze the wildcard term */ - if (*pptr++ == '?') sk++; else sk |= 0x100; - } while (*pptr == '?' || *pptr == '*'); + if (*pptr++ == '\?') { + sk++; + } else { + sk |= 0x100; + } + } while (*pptr == '\?' || *pptr == '*'); if (pattern_match(pptr, nptr, sk, recur - 1)) return 1; /* Test new branch (recursive call) */ nchr = *nptr; break; /* Branch mismatched */ } @@ -2330,17 +2345,18 @@ static int pattern_match ( /* 0:mismatched, 1:matched */ /* Pick a top segment and create the object name in directory form */ /*-----------------------------------------------------------------------*/ -FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ - DIR* dp, /* Pointer to the directory object */ - const TCHAR** path /* Pointer to pointer to the segment in the path string */ +FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ + DIR* dp, /* Pointer to the directory object */ + const TCHAR** path /* Pointer to pointer to the segment in the path string */ ) { #if FF_USE_LFN /* LFN configuration */ BYTE b, cf; - WCHAR wc, *lfn; + WCHAR wc; + WCHAR *lfn; + const TCHAR* p; DWORD uc; UINT i, ni, si, di; - const TCHAR *p; /* Create LFN into LFN working buffer */ @@ -2350,16 +2366,17 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * if (uc == 0xFFFFFFFF) return FR_INVALID_NAME; /* Invalid code or UTF decode error */ if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16); /* Store high surrogate if needed */ wc = (WCHAR)uc; - if (wc < ' ' || wc == '/' || wc == '\\') break; /* Break if end of the path or a separator is found */ - if (wc < 0x80 && chk_chr("\"*:<>\?|\x7F", wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */ + if (wc < ' ' || IsSeparator(wc)) break; /* Break if end of the path or a separator is found */ + if (wc < 0x80 && chk_chr("*:<>|\"\?\x7F", (int)wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */ if (di >= FF_MAX_LFN) return FR_INVALID_NAME; /* Reject too long name */ - lfn[di++] = wc; /* Store the Unicode character */ + lfn[di++] = wc; /* Store the Unicode character */ } - if (wc < ' ') { /* End of path? */ - cf = NS_LAST; /* Set last segment flag */ - } else { - cf = 0; /* Next segment follows */ - while (*p == '/' || *p == '\\') p++; /* Skip duplicated separators if exist */ + if (wc < ' ') { /* Stopped at end of the path? */ + cf = NS_LAST; /* Last segment */ + } else { /* Stopped at a separator */ + while (IsSeparator(*p)) p++; /* Skip duplicated separators if exist */ + cf = 0; /* Next segment may follow */ + if (IsTerminator(*p)) cf = NS_LAST; /* Ignore terminating separator */ } *path = p; /* Return pointer to the next segment */ @@ -2367,14 +2384,14 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * if ((di == 1 && lfn[di - 1] == '.') || (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */ lfn[di] = 0; - for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */ + for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */ dp->fn[i] = (i < di) ? '.' : ' '; } - dp->fn[i] = cf | NS_DOT; /* This is a dot entry */ + dp->fn[i] = cf | NS_DOT; /* This is a dot entry */ return FR_OK; } #endif - while (di) { /* Snip off trailing spaces and dots if exist */ + while (di) { /* Snip off trailing spaces and dots if exist */ wc = lfn[di - 1]; if (wc != ' ' && wc != '.') break; di--; @@ -2408,20 +2425,20 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * continue; } - if (wc >= 0x80) { /* Is this a non-ASCII character? */ + if (wc >= 0x80) { /* Is this an extended character? */ cf |= NS_LFN; /* LFN entry needs to be created */ #if FF_CODE_PAGE == 0 - if (ExCvt) { /* At SBCS */ + if (ExCvt) { /* In SBCS cfg */ wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */ if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */ - } else { /* At DBCS */ - wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */ + } else { /* In DBCS cfg */ + wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */ } -#elif FF_CODE_PAGE < 900 /* SBCS cfg */ +#elif FF_CODE_PAGE < 900 /* In SBCS cfg */ wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */ if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */ -#else /* DBCS cfg */ - wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */ +#else /* In DBCS cfg */ + wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */ #endif } @@ -2432,7 +2449,7 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * } dp->fn[i++] = (BYTE)(wc >> 8); /* Put 1st byte */ } else { /* SBC */ - if (wc == 0 || chk_chr("+,;=[]", wc)) { /* Replace illegal characters for SFN if needed */ + if (wc == 0 || chk_chr("+,;=[]", (int)wc)) { /* Replace illegal characters for SFN */ wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ } else { if (IsUpper(wc)) { /* ASCII upper case? */ @@ -2461,7 +2478,8 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * #else /* FF_USE_LFN : Non-LFN configuration */ - BYTE c, d, *sfn; + BYTE c, d; + BYTE *sfn; UINT ni, si, i; const char *p; @@ -2476,8 +2494,8 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * if (c != '.' || si >= 3) break; sfn[i++] = c; } - if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME; - *path = p + si; /* Return pointer to the next segment */ + if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME; + *path = p + si; /* Return pointer to the next segment */ sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */ return FR_OK; } @@ -2485,8 +2503,8 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * for (;;) { c = (BYTE)p[si++]; /* Get a byte */ if (c <= ' ') break; /* Break if end of the path name */ - if (c == '/' || c == '\\') { /* Break if a separator is found */ - while (p[si] == '/' || p[si] == '\\') si++; /* Skip duplicated separator if exist */ + if (IsSeparator(c)) { /* Break if a separator is found */ + while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */ break; } if (c == '.' || i >= ni) { /* End of body or field overflow? */ @@ -2509,16 +2527,16 @@ FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create * sfn[i++] = c; sfn[i++] = d; } else { /* SBC */ - if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */ + if (chk_chr("*+,:;<=>[]|\"\?\x7F", (int)c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */ if (IsLower(c)) c -= 0x20; /* To upper */ sfn[i++] = c; } } - *path = p + si; /* Return pointer to the next segment */ + *path = &p[si]; /* Return pointer to the next segment */ if (i == 0) return FR_INVALID_NAME; /* Reject nul string */ if (sfn[0] == DDEM) sfn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */ - sfn[NSFLAG] = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */ + sfn[NSFLAG] = (c <= ' ' || p[si] <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */ return FR_OK; #endif /* FF_USE_LFN */ @@ -2542,13 +2560,13 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ #if FF_FS_RPATH != 0 - if (*path != '/' && *path != '\\') { /* Without heading separator */ - dp->obj.sclust = fs->cdir; /* Start from current directory */ + if (!IsSeparator(*path) && (FF_STR_VOLUME_ID != 2 || !IsTerminator(*path))) { /* Without heading separator */ + dp->obj.sclust = fs->cdir; /* Start at the current directory */ } else #endif { /* With heading separator */ - while (*path == '/' || *path == '\\') path++; /* Strip heading separator */ - dp->obj.sclust = 0; /* Start from root directory */ + while (IsSeparator(*path)) path++; /* Strip separators */ + dp->obj.sclust = 0; /* Start from the root directory */ } if ((UINT)*path < ' ') { /* Null path name is the origin directory itself */ @@ -2600,9 +2618,11 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb const TCHAR** path /* Pointer to pointer to the path name */ ) { - const TCHAR *tp, *tt; + const TCHAR *tp; + const TCHAR *tt; TCHAR tc; - int i, vol = -1; + int i; + int vol = -1; #if FF_STR_VOLUME_ID /* Find string volume ID */ const char *sp; char c; @@ -2610,7 +2630,9 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb tt = tp = *path; if (!tp) return vol; /* Invalid path name? */ - do tc = *tt++; while ((UINT)tc >= (FF_USE_LFN ? ' ' : '!') && tc != ':'); /* Find a colon in the path */ + do { /* Find a colon in the path */ + tc = *tt++; + } while (!IsTerminator(tc) && tc != ':'); if (tc == ':') { /* DOS/Windows style volume ID? */ i = *tp++ - '0'; @@ -2637,21 +2659,22 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb return vol; } #if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */ - if (*tp == '/') { + if (*tp == '/') { /* Is there a volume ID? */ + while (*(tp + 1) == '/') tp++; /* Skip duplicated separator */ i = 0; do { - sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */ + tt = tp; sp = VolumeStr[i]; /* Path name and this string volume ID */ do { /* Compare the volume ID with path name */ - c = *sp++; tc = *(++tp); + c = *sp++; tc = *(++tt); if (IsLower(c)) c -= 0x20; if (IsLower(tc)) tc -= 0x20; } while (c && (TCHAR)c == tc); - } while ((c || (tc != '/' && (UINT)tc >= (FF_USE_LFN ? ' ' : '!'))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */ + } while ((c || (tc != '/' && !IsTerminator(tc))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */ if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */ vol = i; /* Drive number */ - *path = tp; /* Snip the drive prefix off */ - return vol; + *path = tt; /* Snip the drive prefix off */ } + return vol; } #endif /* No drive prefix is found */ @@ -2687,7 +2710,9 @@ UINT check_fs ( /* 0:FAT VBR, 1:exFAT VBR, 2:Not FAT and valid BS, 3:Not FAT a b = fs->win[BS_JmpBoot]; if (b == 0xEB || b == 0xE9 || b == 0xE8) { /* Valid JumpBoot code? (short jump, near jump or near call) */ - if (sign == 0xAA55 && !mem_cmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) return 0; /* It is an FAT32 VBR */ + if (sign == 0xAA55 && !mem_cmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) { + return 0; /* It is an FAT32 VBR */ + } /* FAT volumes formatted with early MS-DOS lack boot signature and FAT string, so that we need to identify the FAT VBR without them. */ w = ld_word(fs->win + BPB_BytsPerSec); if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS) { /* Properness of sector size */ @@ -2770,6 +2795,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ + /*-----------------------------------------------------------------------*/ /* Determine logical drive number and mount the volume if needed */ /*-----------------------------------------------------------------------*/ @@ -2777,15 +2803,15 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ const TCHAR** path, /* Pointer to pointer to the path name (drive number) */ FATFS** rfs, /* Pointer to pointer to the found filesystem object */ - BYTE mode /* !=0: Check write protection for write access */ + BYTE mode /* Desiered access mode to check write protection */ ) { int vol; + FATFS *fs; DSTATUS stat; LBA_t bsect; DWORD tsect, sysect, fasize, nclst, szbfat; WORD nrsv; - FATFS *fs; UINT fmt; @@ -2798,7 +2824,7 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs = FatFs[vol]; /* Get pointer to the filesystem object */ if (!fs) return FR_NOT_ENABLED; /* Is the filesystem object available? */ #if FF_FS_REENTRANT - if (!lock_fs(fs)) return FR_TIMEOUT; /* Lock the volume */ + if (!lock_fs(fs)) return FR_TIMEOUT; /* Lock the volume, and system if needed */ #endif *rfs = fs; /* Return pointer to the filesystem object */ @@ -2814,11 +2840,11 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ } /* The filesystem object is not valid. */ - /* Following code attempts to mount the volume. (find a FAT volume, analyze the BPB and initialize the filesystem object) */ + /* Following code attempts to mount the volume. (find an FAT volume, analyze the BPB and initialize the filesystem object) */ - fs->fs_type = 0; /* Clear the filesystem object */ + fs->fs_type = 0; /* Invalidate the filesystem object */ fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */ - stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */ + stat = disk_initialize(fs->pdrv); /* Initialize the volume hosting physical drive */ if (stat & STA_NOINIT) { /* Check if the initialization succeeded */ return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ } @@ -2835,11 +2861,11 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (fs->win == NULL) return FR_NOT_ENOUGH_CORE; } - /* Find an FAT volume on the drive */ + /* Find an FAT volume on the hosting drive */ fmt = find_volume(fs, vol); if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */ if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */ - bsect = fs->winsect; /* Volume location */ + bsect = fs->winsect; /* Volume offset in the hosting physical drive */ /* An FAT volume is found (bsect). Following code initializes the filesystem object */ @@ -2921,7 +2947,7 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #endif /* !FF_FS_READONLY */ - fs->fs_type = (BYTE)fmt;/* FAT sub-type */ + fs->fs_type = (BYTE)fmt;/* FAT sub-type (the filesystem object gets valid) */ fs->id = ++Fsid; /* Volume mount ID */ #if FF_USE_LFN == 1 fs->lfnbuf = LfnBuf; /* Static LFN working buffer */ @@ -2929,8 +2955,8 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #if FF_FS_RPATH != 0 fs->cdir = 0; /* Initialize current directory */ #endif -#if FF_FS_LOCK != 0 /* Clear file lock semaphores */ - clear_lock(fs); +#if FF_FS_LOCK /* Clear file lock semaphores */ + clear_share(fs); #endif return FR_OK; } @@ -2943,7 +2969,7 @@ FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ /*-----------------------------------------------------------------------*/ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ - FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR object, to check validity */ + FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR structure, to check validity */ FATFS** rfs /* Pointer to pointer to the owner filesystem object to return */ ) { @@ -2953,25 +2979,25 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ if (obj && obj->fs && obj->fs->fs_type && obj->id == obj->fs->id) { /* Test if the object is valid */ #if FF_FS_REENTRANT #ifdef __LITEOS_M__ - if (lock_fs(obj->fs)) { /* Obtain the filesystem object */ - if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */ + if (lock_fs(obj->fs)) { /* Take a grant to access the volume */ + if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the hosting phsical drive is kept initialized */ res = FR_OK; } else { - unlock_fs(obj->fs, FR_OK); + unlock_fs(obj->fs, FR_OK); /* Invalidated volume, abort to access */ } - } else { + } else { /* Could not take */ res = FR_TIMEOUT; } #else res = FR_OK; #endif #else - if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */ + if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the hosting phsical drive is kept initialized */ res = FR_OK; } #endif } - *rfs = (res == FR_OK) ? obj->fs : 0; /* Corresponding filesystem object */ + *rfs = (res == FR_OK) ? obj->fs : 0; /* Return corresponding filesystem object if it is valid */ return res; } @@ -3030,9 +3056,9 @@ UINT get_clustinfo(FIL* fp, /*-----------------------------------------------------------------------*/ FRESULT f_mount ( - FATFS* fs, /* Pointer to the filesystem object (NULL:unmount)*/ + FATFS* fs, /* Pointer to the filesystem object to be registered (NULL:unmount)*/ const TCHAR* path, /* Logical drive number to be mounted/unmounted */ - BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */ + BYTE opt /* Mount option: 0=Do not mount (delayed mount), 1=Mount immediately */ ) { FATFS *cfs; @@ -3041,22 +3067,22 @@ FRESULT f_mount ( const TCHAR *rp = path; - /* Get logical drive number */ + /* Get volume ID (logical drive number) */ vol = get_ldnumber(&rp); if (vol < 0) return FR_INVALID_DRIVE; - cfs = FatFs[vol]; /* Pointer to fs object */ + cfs = FatFs[vol]; /* Pointer to the filesystem object of the volume */ - if (cfs) { -#if FF_FS_LOCK != 0 - clear_lock(cfs); + if (cfs) { /* Unregister current filesystem object if regsitered */ +#if FF_FS_LOCK + clear_share(cfs); #endif -#if FF_FS_REENTRANT /* Discard sync object of the current volume */ +#if FF_FS_REENTRANT /* Discard mutex of the current volume */ if (!ff_del_syncobj(&cfs->sobj)) return FR_INT_ERR; #endif - cfs->fs_type = 0; /* Clear old fs object */ + cfs->fs_type = 0; /* Invalidate the filesystem object to be unregistered */ } - if (fs) { + if (fs) { /* Register new filesystem object */ fs->fs_type = 0; /* Clear new fs object */ #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION fs->vir_flag = FS_PARENT; @@ -3064,13 +3090,13 @@ FRESULT f_mount ( fs->vir_amount = 0xFFFFFFFF; fs->vir_avail = FS_VIRDISABLE; #endif -#if FF_FS_REENTRANT /* Create sync object for the new volume */ +#if FF_FS_REENTRANT /* Create a volume mutex */ if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR; #endif } FatFs[vol] = fs; /* Register new fs object */ - if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted later */ + if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted in subsequent file functions */ res = mount_volume(&path, &fs, 0); /* Force mounted the volume */ LEAVE_FF(fs, res); @@ -3246,7 +3272,7 @@ FRESULT find_fat_partition(FATFS *fs, los_part *part, BYTE *format, QWORD *start FRESULT f_open ( FIL* fp, /* Pointer to the blank file object */ const TCHAR* path, /* Pointer to the file name */ - BYTE mode /* Access mode and file open mode flags */ + BYTE mode /* Access mode and open mode flags */ ) { FRESULT res; @@ -3256,7 +3282,7 @@ FRESULT f_open ( FATFS *fs_bak; #endif #if !FF_FS_READONLY - DWORD cl, bcs, clst, tm; + DWORD cl, bcs, clst, tm; LBA_t sc; #ifndef __LITEOS_M__ LBA_t dw; @@ -3301,19 +3327,18 @@ FRESULT f_open ( if (dj.fn[NSFLAG] & NS_NONAME) { /* Origin directory itself? */ res = FR_INVALID_NAME; } -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK else { - res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */ + res = chk_share(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */ } #endif } - /* Create or Open a file */ if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { if (res != FR_OK) { /* No file, create new */ if ((res == FR_NO_FILE) && (mode & FA_OPEN_ALWAYS)) { /* There is no file to open, create a new entry */ -#if FF_FS_LOCK != 0 - res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; +#if FF_FS_LOCK + res = enq_share() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; #else res = dir_register(&dj); #endif @@ -3389,8 +3414,8 @@ FRESULT f_open ( fp->dir_sect = fs->winsect; /* Pointer to the directory entry */ #endif fp->dir_ptr = dj.dir; -#if FF_FS_LOCK != 0 - fp->obj.lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */ +#if FF_FS_LOCK + fp->obj.lockid = inc_share(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */ if (fp->obj.lockid == 0) res = FR_INT_ERR; #endif } @@ -3425,7 +3450,7 @@ FRESULT f_open ( if (fp->buf == NULL) { res = FR_NOT_ENOUGH_CORE; #if FF_FS_LOCK != 0 - dec_lock(fp->obj.lockid); + dec_share(fp->obj.lockid); #endif #if FF_FS_REENTRANT LEAVE_FF(fs_bak, res); @@ -3489,11 +3514,10 @@ FRESULT f_open ( } } #endif -#if FF_FS_LOCK != 0 - if (res != FR_OK) { - dec_lock(fp->obj.lockid); /* Ivalid lockid will be ignored */ - } +#if FF_FS_LOCK + if (res != FR_OK) dec_share(fp->obj.lockid); /* Decrement file open counter if seek failed */ #endif + FREE_NAMBUF(); } @@ -3513,10 +3537,10 @@ FRESULT f_open ( /*-----------------------------------------------------------------------*/ FRESULT f_read ( - FIL* fp, /* Pointer to the file object */ - void* buff, /* Pointer to data buffer */ + FIL* fp, /* Open file to be read */ + void* buff, /* Data buffer to store the read data */ UINT btr, /* Number of bytes to read */ - UINT* br /* Pointer to number of bytes read */ + UINT* br /* Number of bytes read */ ) { FRESULT res; @@ -3537,8 +3561,7 @@ FRESULT f_read ( remain = fp->obj.objsize - fp->fptr; if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ - for ( ; btr; /* Repeat until btr bytes read */ - btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { + for ( ; btr > 0; btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { /* Repeat until btr bytes read */ if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */ if (csect == 0) { /* On the cluster boundary? */ @@ -3599,7 +3622,7 @@ FRESULT f_read ( fp->flag &= (BYTE)~FA_DIRTY; } #endif - if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */ + if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */ } #endif fp->sect = sect; @@ -3634,10 +3657,10 @@ FRESULT f_read ( /*-----------------------------------------------------------------------*/ FRESULT f_write ( - FIL* fp, /* Pointer to the file object */ - const void* buff, /* Pointer to the data to be written */ + FIL* fp, /* Open file to be written */ + const void* buff, /* Data to be written */ UINT btw, /* Number of bytes to write */ - UINT* bw /* Pointer to number of bytes written */ + UINT* bw /* Number of bytes written */ ) { FRESULT res; @@ -3660,8 +3683,7 @@ FRESULT f_write ( btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr); } - for ( ; btw; /* Repeat until all data written */ - btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { + for ( ; btw > 0; btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { /* Repeat until all data written */ if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */ if (csect == 0) { /* On the cluster boundary? */ @@ -3775,7 +3797,7 @@ FRESULT f_write ( /*-----------------------------------------------------------------------*/ FRESULT f_sync ( - FIL* fp /* Pointer to the file object */ + FIL* fp /* Open file to be synced */ ) { FRESULT res; @@ -3834,7 +3856,7 @@ FRESULT f_sync ( /*-----------------------------------------------------------------------*/ FRESULT f_close ( - FIL* fp /* Pointer to the file object to be closed */ + FIL* fp /* Open file to be closed */ ) { FRESULT res; @@ -3847,8 +3869,8 @@ FRESULT f_close ( { res = validate(&fp->obj, &fs); /* Lock volume */ if (res == FR_OK) { -#if FF_FS_LOCK != 0 - res = dec_lock(fp->obj.lockid); /* Decrement file open counter */ +#if FF_FS_LOCK + res = dec_share(fp->obj.lockid); /* Decrement file open counter */ if (res == FR_OK) fp->obj.fs = 0; /* Invalidate file object */ #else fp->obj.fs = 0; /* Invalidate file object */ @@ -3918,7 +3940,7 @@ FRESULT f_chdir ( } FREE_NAMBUF(); if (res == FR_NO_FILE) res = FR_NO_PATH; -#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed at Unix style volume ID */ +#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */ if (res == FR_OK) { for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */ CurrVol = (BYTE)i; @@ -4010,7 +4032,9 @@ FRESULT f_getcwd ( #endif /* Add current directory path */ if (res == FR_OK) { - do *tp++ = buff[i++]; while (i < len); /* Copy stacked path string */ + do { /* Copy stacked path string */ + *tp++ = buff[i++]; + } while (i < len); } } FREE_NAMBUF(); @@ -4041,7 +4065,8 @@ FRESULT f_lseek ( LBA_t nsect; FSIZE_t ifptr; #if FF_USE_FASTSEEK - DWORD cl, pcl, ncl, tcl, tlen, ulen, *tbl; + DWORD cl, pcl, ncl, tcl, tlen, ulen; + DWORD *tbl; LBA_t dsc; #endif @@ -4213,10 +4238,10 @@ FRESULT f_opendir ( if (res == FR_OK) { dp->obj.id = fs->id; res = dir_sdi(dp, 0); /* Rewind directory */ -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK if (res == FR_OK) { if (dp->obj.sclust != 0) { - dp->obj.lockid = inc_lock(dp, 0); /* Lock the sub directory */ + dp->obj.lockid = inc_share(dp, 0); /* Lock the sub directory */ if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES; } else { dp->obj.lockid = 0; /* Root directory need not to be locked */ @@ -4228,7 +4253,7 @@ FRESULT f_opendir ( FREE_NAMBUF(); if (res == FR_NO_FILE) res = FR_NO_PATH; } - if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function faild */ + if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function failed */ LEAVE_FF(fs, res); } @@ -4250,14 +4275,14 @@ FRESULT f_closedir ( res = validate(&dp->obj, &fs); /* Check validity of the file object */ if (res == FR_OK) { -#if FF_FS_LOCK != 0 - if (dp->obj.lockid) res = dec_lock(dp->obj.lockid); /* Decrement sub-directory open counter */ +#if FF_FS_LOCK + if (dp->obj.lockid) res = dec_share(dp->obj.lockid); /* Decrement sub-directory open counter */ if (res == FR_OK) dp->obj.fs = 0; /* Invalidate directory object */ #else dp->obj.fs = 0; /* Invalidate directory object */ #endif #if FF_FS_REENTRANT - unlock_fs(fs, FR_OK); /* Unlock volume */ + unlock_fs(fs, FR_OK); /* Unlock volume */ #endif } return res; @@ -4283,7 +4308,7 @@ FRESULT f_readdir ( res = validate(&dp->obj, &fs); /* Check validity of the directory object */ if (res == FR_OK) { if (!fno) { - res = dir_sdi(dp, 0); /* Rewind the directory object */ + res = dir_sdi(dp, 0); /* Rewind the directory object */ } else { INIT_NAMBUF(fs); res = DIR_READ_FILE(dp); /* Read an item */ @@ -4403,8 +4428,12 @@ FRESULT fat_count_free_entries( clst = 2; obj.fs = fs; do { stat = get_fat(&obj, clst); - if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } - if (stat == 1) { res = FR_INT_ERR; break; } + if (stat == 0xFFFFFFFF) { + res = FR_DISK_ERR; break; + } + if (stat == 1) { + res = FR_INT_ERR; break; + } if (stat == 0) nfree++; } while (++clst < fs->n_fatent); } else { @@ -4571,9 +4600,9 @@ FRESULT f_unlink ( ) { FRESULT res; + FATFS *fs; DIR dj, sdj; DWORD dclst = 0; - FATFS *fs; #if FF_FS_REENTRANT FATFS *fs_bak; #endif @@ -4660,8 +4689,8 @@ FRESULT f_unlink ( } #endif -#if FF_FS_LOCK != 0 - if (res == FR_OK) res = chk_lock(&dj, 2); /* Check if it is an open object */ +#if FF_FS_LOCK + if (res == FR_OK) res = chk_share(&dj, 2); /* Check if it is an open object */ #endif if (res == FR_OK) { /* The object is accessible */ if (dj.fn[NSFLAG] & NS_NONAME) { @@ -4692,8 +4721,8 @@ FRESULT f_unlink ( } } if (res == FR_OK) { - res = dir_remove(&dj); /* Remove the directory entry */ - if (res == FR_OK && dclst) { /* Remove the cluster chain if exist */ + res = dir_remove(&dj); /* Remove the directory entry */ + if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ res = remove_chain(&dj.obj, dclst, 0); } if (res == FR_OK) res = sync_fs(fs); @@ -4720,9 +4749,9 @@ FRESULT f_mkdir ( ) { FRESULT res; + FATFS *fs; DIR dj; FFOBJID sobj; - FATFS *fs; #if FF_FS_REENTRANT FATFS *fs_bak; #endif @@ -4856,8 +4885,8 @@ FRESULT f_rename ( ) { FRESULT res; - DIR djo, djn; FATFS *fs; + DIR djo, djn; #if FF_FS_REENTRANT FATFS *fs_bak; #endif @@ -4894,9 +4923,9 @@ FRESULT f_rename ( INIT_NAMBUF(fs); res = follow_path(&djo, path_old); /* Check old object */ if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */ -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK if (res == FR_OK) { - res = chk_lock(&djo, 2); + res = chk_share(&djo, 2); } #endif #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION @@ -5018,8 +5047,8 @@ FRESULT f_chmod ( ) { FRESULT res; - DIR dj; FATFS *fs; + DIR dj; #if FF_FS_REENTRANT FATFS *fs_bak; #endif @@ -5083,8 +5112,8 @@ FRESULT f_utime ( ) { FRESULT res; - DIR dj; FATFS *fs; + DIR dj; DEF_NAMBUF @@ -5123,8 +5152,8 @@ FRESULT f_getlabel ( ) { FRESULT res; - DIR dj; FATFS *fs; + DIR dj; UINT si, di; WCHAR wc; @@ -5143,10 +5172,11 @@ FRESULT f_getlabel ( wc = dj.dir[si++]; #if FF_USE_LFN && FF_LFN_UNICODE >= 1 /* Unicode output */ if (dbc_1st((BYTE)wc) && si < 11) wc = wc << 8 | dj.dir[si++]; /* Is it a DBC? */ - wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */ - if (wc != 0) wc = put_utf(wc, &label[di], 4); /* Put it in Unicode */ - if (wc == 0) { di = 0; break; } - di += wc; + wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */ + if (wc == 0) { /* Invalid char in current code page? */ + di = 0; break; + } + di += put_utf(wc, &label[di], 4); /* Store it in Unicode */ #else /* ANSI/OEM output */ label[di++] = (TCHAR)wc; #endif @@ -5201,7 +5231,7 @@ FRESULT set_volumn_label(FATFS *fs, const TCHAR *label) DWORD dc; #endif /* On the FAT/FAT32 volume */ - mem_set(dirvn, ' ', 11); + memset(dirvn, ' ', 11); di = 0; while ((UINT)*label >= ' ') { /* Create volume label */ #if FF_USE_LFN @@ -5217,7 +5247,7 @@ FRESULT set_volumn_label(FATFS *fs, const TCHAR *label) if (wc >= 0x80) wc = ExCvt[wc - 0x80]; /* To upper extended characters (SBCS cfg) */ #endif #endif - if (wc == 0 || chk_chr(badchr + 0, (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */ + if (wc == 0 || strchr(badchr + 0, (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */ LEAVE_FF(fs, FR_INVALID_NAME); } if (wc >= 0x100) dirvn[di++] = (BYTE)(wc >> 8); @@ -5468,8 +5498,7 @@ FRESULT f_forward ( remain = fp->obj.objsize - fp->fptr; if (btf > remain) btf = (UINT)remain; /* Truncate btf by remaining bytes */ - for ( ; btf && (*func)(0, 0); /* Repeat until all data transferred or stream goes busy */ - fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { + for ( ; btf > 0 && (*func)(0, 0); fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { /* Repeat until all data transferred or stream goes busy */ csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */ if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ if (csect == 0) { /* On the cluster boundary? */ @@ -5499,7 +5528,7 @@ FRESULT f_forward ( dbuf = fp->buf; #endif fp->sect = sect; - rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes left in the sector */ + rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */ if (rcnt > btf) rcnt = btf; /* Clip it by btr if needed */ rcnt = (*func)(dbuf + ((UINT)fp->fptr % SS(fs)), rcnt); /* Forward the file data */ if (rcnt == 0) ABORT(fs, FR_INT_ERR); @@ -5587,7 +5616,9 @@ FRESULT f_mkfs ( static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */ static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */ static const MKFS_PARM defopt = {FM_ANY, 0, 0, 0, 0}; /* Default parameter */ - BYTE fsopt, fsty, sys, *buf, *pte, pdrv, ipart; + BYTE fsopt, fsty, sys, pdrv, ipart; + BYTE *buf; + BYTE *pte; #ifndef __LITEOS_M__ size_t ss; #else @@ -5615,17 +5646,19 @@ FRESULT f_mkfs ( vol = get_ldnumber(&path); /* Get target logical drive */ if (vol < 0) return FR_INVALID_DRIVE; if (FatFs[vol]) FatFs[vol]->fs_type = 0; /* Clear the fs object if mounted */ - pdrv = LD2PD(vol); /* Physical drive */ - ipart = LD2PT(vol); /* Partition (0:create as new, 1..:get from partition table) */ - if (!opt) opt = &defopt; /* Use default parameter if it is not given */ + pdrv = LD2PD(vol); /* Hosting physical drive */ + ipart = LD2PT(vol); /* Hosting partition (0:create as new, 1..:existing partition) */ - /* Get physical drive status (sz_drv, sz_blk, ss) */ + /* Initialize the hosting physical drive */ ds = disk_initialize(pdrv); if (ds & STA_NOINIT) return FR_NOT_READY; if (ds & STA_PROTECT) return FR_WRITE_PROTECTED; + + /* Get physical drive parameters (sz_drv, sz_blk and ss) */ + if (!opt) opt = &defopt; /* Use default parameter if it is not given */ sz_blk = opt->align; - if (sz_blk == 0 && disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK) sz_blk = 1; - if (sz_blk == 0 || sz_blk > 0x8000 || (sz_blk & (sz_blk - 1))) sz_blk = 1; + if (sz_blk == 0) disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk); /* Block size from the paramter or lower layer */ + if (sz_blk == 0 || sz_blk > 0x8000 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Use default if the block size is invalid */ #if FF_MAX_SS != FF_MIN_SS if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR; if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR; @@ -5896,14 +5929,15 @@ FRESULT f_mkfs ( /* Determine system ID in the MBR partition table */ if (fsty == FS_FAT32) { sys = ipart > 4 ? 0x0B : 0x0C; /* FAT32X */ + } else if (sz_vol >= 0x10000) { + sys = 0x06; /* FAT12/16 (large) */ + } else if (fsty == FS_FAT16) { + sys = 0x04; /* FAT16 */ } else { - if (sz_vol >= 0x10000) { - sys = 0x06; /* FAT12/16 (large) */ - } else { - sys = (fsty == FS_FAT16) ? 0x04 : 0x01; /* FAT16 : FAT12 */ - } + sys = 0x01; /* FAT12 */ } + /* Update partition information */ #if FF_MULTI_PARTITION if (ipart != 0) { /* Created in the existing partition */ @@ -6356,8 +6390,9 @@ FRESULT f_fdisk ( DSTATUS stat; LBA_t ptbl[4] = {0}; int i = 0;; + FRESULT res; - + /* Initialize the physical drive */ stat = disk_initialize(pdrv); if (stat & STA_NOINIT) return FR_NOT_READY; if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; @@ -6368,7 +6403,9 @@ FRESULT f_fdisk ( i++; } - LEAVE_MKFS(create_partition(pdrv, ptbl, 0x07, buf)); + res = create_partition(pdrv, ptbl, 0x07, buf); /* Create partitions (system ID is temporary setting and determined by f_mkfs) */ + + LEAVE_MKFS(res); } #endif /* FF_MULTI_PARTITION */ @@ -6414,12 +6451,12 @@ TCHAR* f_gets ( if (rc != 1) break; /* EOF? */ wc = s[0]; if (dbc_1st((BYTE)wc)) { /* DBC 1st byte? */ - f_read(fp, s, 1, &rc); /* Get DBC 2nd byte */ + f_read(fp, s, 1, &rc); /* Get 2nd byte */ if (rc != 1 || !dbc_2nd(s[0])) continue; /* Wrong code? */ wc = wc << 8 | s[0]; } - dc = ff_oem2uni(wc, CODEPAGE); /* OEM --> */ - if (dc == 0) continue; + dc = ff_oem2uni(wc, CODEPAGE); /* Convert ANSI/OEM into Unicode */ + if (dc == 0) continue; /* Conversion error? */ #elif FF_STRF_ENCODE == 1 || FF_STRF_ENCODE == 2 /* Read a character in UTF-16LE/BE */ f_read(fp, s, 2, &rc); /* Get a code unit */ if (rc != 2) break; /* EOF? */ @@ -6438,11 +6475,17 @@ TCHAR* f_gets ( dc = s[0]; if (dc >= 0x80) { /* Multi-byte sequence? */ ct = 0; - if ((dc & 0xE0) == 0xC0) { dc &= 0x1F; ct = 1; } /* 2-byte sequence? */ - if ((dc & 0xF0) == 0xE0) { dc &= 0x0F; ct = 2; } /* 3-byte sequence? */ - if ((dc & 0xF8) == 0xF0) { dc &= 0x07; ct = 3; } /* 4-byte sequence? */ + if ((dc & 0xE0) == 0xC0) { /* 2-byte sequence? */ + dc &= 0x1F; ct = 1; + } + if ((dc & 0xF0) == 0xE0) { /* 3-byte sequence? */ + dc &= 0x0F; ct = 2; + } + if ((dc & 0xF8) == 0xF0) { /* 4-byte sequence? */ + dc &= 0x07; ct = 3; + } if (ct == 0) continue; - f_read(fp, s, ct, &rc); /* Get trailing bytes */ + f_read(fp, s, ct, &rc); /* Get trailing bytes */ if (rc != ct) break; rc = 0; do { /* Merge the byte sequence */ @@ -6467,25 +6510,21 @@ TCHAR* f_gets ( *p++ = (TCHAR)dc; nc++; if (dc == '\n') break; /* End of line? */ - } else { - if (dc < 0x800) { /* 2-byte sequence? */ - *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F)); - *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); - nc += 2; - } else { - if (dc < 0x10000) { /* 3-byte sequence? */ - *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F)); - *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); - *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); - nc += 3; - } else { /* 4-byte sequence? */ - *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07)); - *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F)); - *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); - *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); - nc += 4; - } - } + } else if (dc < 0x800) { /* 2-byte sequence? */ + *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 2; + } else if (dc < 0x10000) { /* 3-byte sequence? */ + *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F)); + *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 3; + } else { /* 4-byte sequence */ + *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07)); + *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F)); + *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F)); + nc += 4; } #endif } @@ -6511,11 +6550,14 @@ TCHAR* f_gets ( #if !FF_FS_READONLY #include +#define SZ_PUTC_BUF 64 +#define SZ_NUM_BUF 32 + /*-----------------------------------------------------------------------*/ -/* Put a Character to the File (sub-functions) */ +/* Put a Character to the File (with sub-functions) */ /*-----------------------------------------------------------------------*/ -/* Putchar output buffer and work area */ +/* Output buffer and work area */ typedef struct { FIL *fp; /* Ptr to the writing file */ @@ -6526,11 +6568,11 @@ typedef struct { BYTE bs[4]; UINT wi, ct; #endif - BYTE buf[64]; /* Write buffer */ + BYTE buf[SZ_PUTC_BUF]; /* Write buffer */ } putbuff; -/* Buffered write with code conversion */ +/* Buffered file write with code conversion */ static void putc_bfd (putbuff* pb, TCHAR c) { @@ -6540,7 +6582,7 @@ static void putc_bfd (putbuff* pb, TCHAR c) WCHAR hs, wc; #if FF_LFN_UNICODE == 2 DWORD dc; - const TCHAR *tp; + const TCHAR* tp; #endif #endif @@ -6549,44 +6591,44 @@ static void putc_bfd (putbuff* pb, TCHAR c) } i = pb->idx; /* Write index of pb->buf[] */ - if (i < 0) return; + if (i < 0) return; /* In write error? */ nc = pb->nchr; /* Write unit counter */ #if FF_USE_LFN && FF_LFN_UNICODE #if FF_LFN_UNICODE == 1 /* UTF-16 input */ - if (IsSurrogateH(c)) { /* High surrogate? */ + if (IsSurrogateH(c)) { /* Is this a high-surrogate? */ pb->hs = c; return; /* Save it for next */ } hs = pb->hs; pb->hs = 0; - if (hs != 0) { /* There is a leading high surrogate */ - if (!IsSurrogateL(c)) hs = 0; /* Discard high surrogate if not a surrogate pair */ + if (hs != 0) { /* Is there a leading high-surrogate? */ + if (!IsSurrogateL(c)) hs = 0; /* Discard high-surrogate if not a surrogate pair */ } else { - if (IsSurrogateL(c)) return; /* Discard stray low surrogate */ + if (IsSurrogateL(c)) return; /* Discard stray low-surrogate */ } wc = c; #elif FF_LFN_UNICODE == 2 /* UTF-8 input */ for (;;) { if (pb->ct == 0) { /* Out of multi-byte sequence? */ pb->bs[pb->wi = 0] = (BYTE)c; /* Save 1st byte */ - if ((BYTE)c < 0x80) break; /* Single byte? */ + if ((BYTE)c < 0x80) break; /* Single byte code? */ if (((BYTE)c & 0xE0) == 0xC0) pb->ct = 1; /* 2-byte sequence? */ if (((BYTE)c & 0xF0) == 0xE0) pb->ct = 2; /* 3-byte sequence? */ - if (((BYTE)c & 0xF1) == 0xF0) pb->ct = 3; /* 4-byte sequence? */ - return; + if (((BYTE)c & 0xF8) == 0xF0) pb->ct = 3; /* 4-byte sequence? */ + return; /* Wrong leading byte (discard it) */ } else { /* In the multi-byte sequence */ if (((BYTE)c & 0xC0) != 0x80) { /* Broken sequence? */ - pb->ct = 0; continue; + pb->ct = 0; continue; /* Discard the sequense */ } pb->bs[++pb->wi] = (BYTE)c; /* Save the trailing byte */ - if (--pb->ct == 0) break; /* End of multi-byte sequence? */ + if (--pb->ct == 0) break; /* End of the sequence? */ return; } } tp = (const TCHAR*)pb->bs; - dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */ + dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */ if (dc == 0xFFFFFFFF) return; /* Wrong code? */ - wc = (WCHAR)dc; hs = (WCHAR)(dc >> 16); + wc = (WCHAR)dc; #elif FF_LFN_UNICODE == 3 /* UTF-32 input */ if (IsSurrogate(c) || c >= 0x110000) return; /* Discard invalid code */ if (c >= 0x10000) { /* Out of BMP? */ @@ -6648,7 +6690,7 @@ static void putc_bfd (putbuff* pb, TCHAR c) pb->buf[i++] = (BYTE)wc; #endif -#else /* ANSI/OEM input (without re-encoding) */ +#else /* ANSI/OEM input (without re-encoding) */ pb->buf[i++] = (BYTE)c; #endif @@ -6793,7 +6835,7 @@ int f_printf ( break; case 'O': /* Unsigned octal */ - r = 8; + r = 8; break; case 'D': /* Signed decimal */ @@ -6914,13 +6956,13 @@ FRESULT f_setcp ( WORD cp /* Value to be set as active code page */ ) { - static const WORD validcp[] = { 437, 720, 737, 771, 775, 850, 852, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0}; - static const BYTE* const tables[] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0}; + static const WORD validcp[22] = { 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0}; + static const BYTE *const tables[22] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct855, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0}; UINT i; for (i = 0; validcp[i] != 0 && validcp[i] != cp; i++) ; /* Find the code page */ - if (validcp[i] != cp) return FR_INVALID_PARAMETER; /* Not found? */ + if (validcp[i] != cp) return FR_INVALID_PARAMETER; /* Not found? */ CodePage = cp; if (cp >= 900) { /* DBCS */ diff --git a/source/ff.h b/source/ff.h index 4a74f247b0d7763415ba50737b22fa3c9a7fb9be..dad9b6444d453e3433174e610553d1b90a35ac44 100644 --- a/source/ff.h +++ b/source/ff.h @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem module R0.14a / +/ FatFs - Generic FAT Filesystem module R0.15 / /-----------------------------------------------------------------------------/ / -/ Copyright (C) 2020, ChaN, all right reserved. +/ Copyright (C) 2022, 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 80196 /* Revision ID */ +#define FF_DEFINED 80286 /* Revision ID */ #ifdef __cplusplus extern "C" { @@ -137,8 +137,7 @@ typedef struct FAT_VIRTUAL_PARTITION { -/* Type of path name strings on FatFs API */ - +/* Type of path name strings on FatFs API (TCHAR) */ #ifndef _INC_TCHAR #define _INC_TCHAR @@ -415,8 +414,12 @@ typedef enum { } FRESULT; + + +/*--------------------------------------------------------------*/ +/* FatFs Module Application Interface */ /*--------------------------------------------------------------*/ -/* FatFs module application interface */ + #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION FATFS* f_getfatfs (int vol); FRESULT f_scanfat (FATFS* fs); @@ -429,6 +432,7 @@ FRESULT f_makevirpart (FATFS* fs, const TCHAR* path, BYTE vol); FRESULT f_getvirfree (const TCHAR* path, DWORD* nclst, DWORD* cclst); FRESULT f_checkname (const TCHAR* path); #endif + FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ FRESULT f_close (FIL* fp); /* Close an open file object */ FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */ @@ -518,19 +522,23 @@ FRESULT set_volumn_label(FATFS *fs, const TCHAR *label); /*--------------------------------------------------------------*/ -/* Additional user defined functions */ +/* Additional Functions */ +/*--------------------------------------------------------------*/ -/* RTC function */ +/* RTC function (provided by user) */ #if !FF_FS_READONLY && !FF_FS_NORTC -DWORD get_fattime (void); +DWORD get_fattime (void); /* Get current time */ #endif -/* LFN support functions */ -#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */ + +/* LFN support functions (defined in ffunicode.c) */ + +#if FF_USE_LFN >= 1 WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */ WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */ DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */ #endif +/* O/S dependent functions (samples available in ffsystem.c) */ void* ff_memalloc (UINT msize); /* Allocate memory block */ void ff_memfree (void* mblock); /* Free memory block */ #ifndef __LITEOS_M__ @@ -549,8 +557,8 @@ int ff_del_syncobj (FF_SYNC_t* sobj); /* Delete a sync object */ /*--------------------------------------------------------------*/ -/* Flags and offset address */ - +/* Flags and Offset Address */ +/*--------------------------------------------------------------*/ /* File access mode and open method flags (3rd argument of f_open) */ #define FA_READ 0x01 diff --git a/source/ffconf.h b/source/ffconf.h index 87cfb6252c510ec68a1e077577a57916729b8167..c5052b48c03e398904c293e61d712f7501c16def 100644 --- a/source/ffconf.h +++ b/source/ffconf.h @@ -2,7 +2,7 @@ #define FFCONF_H /*---------------------------------------------------------------------------/ -/ FatFs Functional Configurations +/ Configurations of FatFs Module /---------------------------------------------------------------------------*/ #ifndef __LITEOS_M__ @@ -19,7 +19,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#define FFCONF_DEF 80196 /* Revision ID */ +#define FFCONF_DEF 80286 /* Revision ID */ /*---------------------------------------------------------------------------/ / Function Configurations @@ -42,14 +42,6 @@ extern "C" { / 3: f_lseek() function is removed in addition to 2. */ -#define FF_USE_STRFUNC 0 -/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). -/ -/ 0: Disable string functions. -/ 1: Enable without LF-CRLF conversion. -/ 2: Enable with LF-CRLF conversion. */ - - #define FF_USE_FIND 0 /* This option switches filtered directory read functions, f_findfirst() and / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ diff --git a/source/ffunicode.c b/source/ffunicode.c index 784a10e564e94510adf9b8aef47cef76992ccb8c..54ad526710595e64716d0bc6d01e8461e1b3821d 100644 --- a/source/ffunicode.c +++ b/source/ffunicode.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------*/ -/* Unicode handling functions for FatFs R0.13+ */ +/* Unicode Handling Functions for FatFs R0.13 and Later */ +/*------------------------------------------------------------------------*/ +/* This module will occupy a huge memory in the .rodata section when the */ +/* FatFs is configured for LFN with DBCS. If the system has a Unicode */ +/* library for the code conversion, this module should be modified to use */ +/* it to avoid silly memory consumption. */ /*------------------------------------------------------------------------*/ -/* 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 / -/ utilitiy for the code conversion, this module should be modified to use / -/ that function to avoid silly memory consumption. / -/-------------------------------------------------------------------------*/ /* -/ Copyright (C) 2014, ChaN, all right reserved. +/ Copyright (C) 2022, 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,7 +25,7 @@ #include "ff.h" -#if FF_USE_LFN /* This module will be blanked if non-LFN configuration */ +#if FF_USE_LFN != 0 /* This module will be blanked if in non-LFN configuration */ #define MERGE2(a, b) a ## b #define CVTBL(tbl, cp) MERGE2(tbl, cp) @@ -15214,8 +15214,8 @@ static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */ /*------------------------------------------------------------------------*/ -/* OEM <==> Unicode conversions for static code page configuration */ -/* SBCS fixed code page */ +/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ +/* SBCS Fixed Code Page */ /*------------------------------------------------------------------------*/ #if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900 @@ -15225,7 +15225,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ ) { WCHAR c = 0; - const WCHAR *p = CVTBL(uc, FF_CODE_PAGE); + const WCHAR* p = CVTBL(uc, FF_CODE_PAGE); if (uni < 0x80) { /* ASCII? */ @@ -15247,7 +15247,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ ) { WCHAR c = 0; - const WCHAR *p = CVTBL(uc, FF_CODE_PAGE); + const WCHAR* p = CVTBL(uc, FF_CODE_PAGE); if (oem < 0x80) { /* ASCII? */ @@ -15267,8 +15267,8 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ /*------------------------------------------------------------------------*/ -/* OEM <==> Unicode conversions for static code page configuration */ -/* DBCS fixed code page */ +/* OEM <==> Unicode Conversions for Static Code Page Configuration with */ +/* DBCS Fixed Code Page */ /*------------------------------------------------------------------------*/ #if FF_CODE_PAGE >= 900 @@ -15277,7 +15277,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ WORD cp /* Code page for the conversion */ ) { - const WCHAR *p; + const WCHAR* p; WCHAR c = 0, uc; UINT i = 0, n, li, hi; @@ -15313,7 +15313,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ WORD cp /* Code page for the conversion */ ) { - const WCHAR *p; + const WCHAR* p; WCHAR c = 0; UINT i = 0, n, li, hi; @@ -15346,7 +15346,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ /*------------------------------------------------------------------------*/ -/* OEM <==> Unicode conversions for dynamic code page configuration */ +/* OEM <==> Unicode Conversions for Dynamic Code Page Configuration */ /*------------------------------------------------------------------------*/ #if FF_CODE_PAGE == 0 @@ -15360,7 +15360,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */ WORD cp /* Code page for the conversion */ ) { - const WCHAR *p; + const WCHAR* p; WCHAR c = 0, uc; UINT i, n, li, hi; @@ -15412,7 +15412,7 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ WORD cp /* Code page for the conversion */ ) { - const WCHAR *p; + const WCHAR* p; WCHAR c = 0; UINT i, n, li, hi; @@ -15458,14 +15458,14 @@ WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */ /*------------------------------------------------------------------------*/ -/* Unicode up-case conversion */ +/* Unicode Up-case Conversion */ /*------------------------------------------------------------------------*/ DWORD ff_wtoupper ( /* Returns up-converted code point */ DWORD uni /* Unicode code point to be up-converted */ ) { - const WORD *p; + const WORD* p; WORD uc, bc, nc, cmd; static const WORD cvt1[] = { /* Compressed up conversion table for U+0000 - U+0FFF */ /* Basic Latin */ @@ -15590,4 +15590,4 @@ DWORD ff_wtoupper ( /* Returns up-converted code point */ } -#endif /* #if FF_USE_LFN */ +#endif /* #if FF_USE_LFN != 0 */