diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/css_e.css b/src/rust/fatfs-sys/depend/fatfs/documents/css_e.css index 8274af3df4..faa27fd0a5 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/css_e.css +++ b/src/rust/fatfs-sys/depend/fatfs/documents/css_e.css @@ -14,6 +14,7 @@ strong {} pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;} pre span.c {color: green;} pre span.k {color: blue;} +pre span.e {color: red;} pre span.b {font-weight: bold;} pre span.arg {font-style: italic;} tt {margin: 0 0.2em; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; } @@ -30,6 +31,7 @@ hr {border-width: 1px; margin: 1em;} div.abst {font-family: sans-serif;} div.para {clear: both; font-family: serif;} div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; } +ul.plain {margin: 0 0 0 1em;} .equ {text-indent: 0; margin: 1em 2em 1em;} .indent {margin-left: 2em;} .rset {float: right; margin: 0.3em 0 0.5em 0.5em;} @@ -37,6 +39,7 @@ div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; ul.flat li {list-style-type: none; margin: 0;} a.imglnk img {border: 1px solid;} .iequ {white-space: nowrap; font-weight: bold;} +.lnk {opacity: 0.5;} .clr {clear: both;} .it {font-style: italic;} .mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap} @@ -57,13 +60,16 @@ small {font-size: 80%;} .indent {margin-left: 2em;} /* Tables */ -table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; } -th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;} -td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;} +table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid gray; } +table caption {font-family: sans-serif; font-weight: bold;} +table th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: gray; padding: 0 3px; vertical-align: top; white-space: nowrap;} +table td {background-color: white; border: 1px solid gray; padding: 0 3px; vertical-align: top; line-height: 1.3em;} table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;} table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;} table.lst3 td {font-family: "Consolas", "Courier New", monospace; white-space: nowrap;} -table caption {font-family: sans-serif; font-weight: bold;} -tr.lst3 td { border-width: 2px 1px 1px; } +tr.lst3 td {border-width: 2px 1px 1px; } +table.lst4 td {padding: 0.3em;} +table.lst4 td:nth-child(2) {width: 45%;} +table.lst4 td:nth-child(3) {width: 45%;} p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;} diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/appnote.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/appnote.html index 82ebdd4d40..32e900f217 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/appnote.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/appnote.html @@ -3,8 +3,6 @@ - - FatFs Module Application Note @@ -41,8 +39,13 @@

Basic Considerations

+
  • Dependency
    + @@ -67,19 +70,19 @@

    System Organizations

    functional diagram

    Required Functions

    -

    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.

    +

    You need to provide only MAI functions and some additional 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 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_status
    disk_initialize
    disk_read
    AlwaysMAI 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.
    ff_mem_alloc
    ff_mem_free
    FF_USE_LFN == 3
    ff_uni2oem
    ff_oem2uni
    ff_wtoupper
    FF_USE_LFN != 0Unicode support functions.
    Just add ffunicode.c to the project.
    ff_mutex_create
    ff_mutex_delete
    ff_mutex_take
    ff_mutex_give
    FF_FS_REENTRANT == 1O/S related functions.
    Some sample codes are available in ffsystem.c.
    ff_memalloc
    ff_memfree
    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.

    +

    FatFs cares about neither what kind of storage device is used nor how it is implemented. Only a requirement is that the storage is a block device that can be read/written via the MAI functions defined above.

    @@ -87,7 +90,7 @@

    Limits

    @@ -166,169 +169,170 @@

    Reducing Module Size

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

    - - +

    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 are 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 LFN specification allows the length of LFN up to 255 characters, so that the FF_MAX_LFN should be set to 255 for every existing file name. 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 file 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.

    +

    Code Page and 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 is meaningless. The code size will able to be reduced by configureing FatFs for Unicode API with some SBCS code page.

    +

    There ware some restrictions on using the LFN in 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 project.

    + + +
    +

    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. By configuration option FF_LBA64, it can be switched to 64-bit LBA and also GPT (GUID Partition Table) is enabled for partition 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 aborts 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 are some example codes in the ffsystem.c for some platforms.

    +

    Note that there is an exception on the re-entrancy for f_mount and f_mkfs function. You would know why it is. These volume management functions are always not thread-safe to the volume 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 or 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 flushed by file data transfer and it needs to be reloaded at every cluster boundary. However it will be suitable for not a few applications from the viewpoint of decent performance and low memory comsumption.

    +

    Figure 1 shows a short data transfer within the sector size. The partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. Figure 2 shows a long data transfer spans multiple sector. The middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows a case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used at all. 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 clearly shows multiple block write (W:16K, 32 sectors) is much higher than single block write (W:100, 1 sector) in write turoughput, 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 not a few memory card driver implementations 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 allocated to the file are marked 'free' on the FAT. However, 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 marked 'blank' on remove 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. In this configuration, f_unlink function might take a time when remove a large file. Most applications will not need this function.

    +
    + +
    +

    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

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdir.html index 93e116c394..41dc847343 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdir.html @@ -3,8 +3,6 @@ - - FatFs - f_chdir @@ -50,8 +48,8 @@

    Return Values

    Description

    -

    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.

    +

    The f_chdir function changes the current directory of the logical drive. Also the current drive will be changed when FatFs is configured FF_STR_VOLUME_ID == 2 and an full path is specified. The current directory of each logical drive is set root directory on mount.

    +

    Note that the current directory is retained in the each filesystem object and the current drive is retained in a static variable, so that they also affect other tasks that use the file functions.

    @@ -64,16 +62,16 @@

    QuickInfo

    Example

    -    /* Change current direcoty of the current drive ("dir1" under root directory) */
    +    /* Set current direcoty of the current drive ("dir1" in the root directory) */
         f_chdir("/dir1");
     
    -    /* Change current direcoty of current drive (parent directory of drive 2) */
    +    /* Set current direcoty of drive 2 (parent directory of current directory) */
         f_chdir("2:..");
     
    -    /* Change current direcoty of the drive "sdcard" (at DOS/Windows style volume ID) */
    +    /* Set current direcoty of drive "sdcard" (FF_STR_VOLUME_ID == 1) */
         f_chdir("sdcard:/dir1");
     
    -    /* Change current direcoty of the drive "flash" and set it as current drive (at Unix style volume ID) */
    +    /* Set current direcoty of drive "flash" and set this drive current drive (FF_STR_VOLUME_ID == 2) */
         f_chdir("/flash/dir1");
     
    @@ -83,6 +81,7 @@

    See Also

    f_chdrive, f_getcwd

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdrive.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdrive.html index 4dfc7d86d7..2df0d9fa4c 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdrive.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chdrive.html @@ -3,8 +3,6 @@ - - FatFs - f_chdrive @@ -65,6 +63,7 @@

    See Also

    f_chdir, f_getcwd

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chmod.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chmod.html index 91e520fd5e..79e0fcc647 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/chmod.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/chmod.html @@ -3,8 +3,6 @@ - - FatFs - f_chmod @@ -27,7 +25,7 @@

    f_chmod

    Parameters

    path
    -
    Pointer to the null-terminated string that specifies an object to be changed
    +
    Pointer to the null-terminated string that specifies an object to be changed. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    attr
    Attribute flags to be set in one or more combination of the following flags. The specified flags are set and others are cleard.
    @@ -84,6 +82,7 @@

    Example

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/close.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/close.html index f4cd2df457..b817e3755d 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/close.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/close.html @@ -3,8 +3,6 @@ - -FatFs - f_close @@ -60,6 +58,7 @@

    See Also

    f_open, f_read, f_write, f_sync, FIL, FATFS

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/closedir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/closedir.html index 3f5df57701..af3b31e65c 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/closedir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/closedir.html @@ -3,8 +3,6 @@ - -FatFs - f_closedir @@ -59,6 +57,7 @@

    See Also

    f_opendir, f_readdir, DIR

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/config.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/config.html index a4c78147cd..cc704fbb83 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/config.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/config.html @@ -3,15 +3,13 @@ - -FatFs - Configuration Options

    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.

    @@ -105,29 +104,29 @@

    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.

    +

    This option switches string I/O functions, f_gets, f_putc, f_puts and f_printf. These functions are the 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 better 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.
    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). C standard needs to be C99 or later to enable this feature.

    +

    Disable (0) or Enable (1). When enable this feature, C standard needs to be C99 or later. This option has no effect when FF_USE_STRFUNC == 0.

    -

    This option switches support for floating point argument in f_printf. C standard needs to be C99 or later to enable this feature.

    +

    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. This option has no effect when FF_USE_STRFUNC == 0.

    - +
    ValueDescription
    0Disable floating point argument.
    1Enable floating point argument in type 'f', 'e' and 'E'.
    2Enable with decimal separator ',' instead of '.'.
    2Same as 1 but with decimal separator ',' instead of '.' in output string.

    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.

    +

    When the 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 the string I/O functions. When LFN is not enabled or FF_LFN_UNICODE == 0, the string I/O functions work without any code conversion and this option has no effect.

    @@ -171,7 +170,7 @@

    FF_CODE_PAGE

    ValueCharacter encoding on the file
    0ANSI/OEM in current code page

    FF_USE_LFN

    -

    This option switches the support for long file name (LFN). When enable the LFN, Unicode support module ffunicode.c need to be added to the project. When use stack for the working buffer, take care on stack overflow. When use heap memory for the working buffer, memory management functions (ff_memalloc and ff_memfree) need to be added to the project.

    +

    This option switches the long file name (LFN) extension and which memory to be allocated for the working buffer. When enable the LFN, Unicode support module ffunicode.c need to be added to the project. When use stack for the working buffer, take care on stack usage. When use heap memory for the working buffer, memory management functions (ff_memalloc and ff_memfree) need to be added to the project.

    @@ -181,7 +180,7 @@

    FF_USE_LFN

    ValueDescription
    0Disable LFN. Path name in only 8.3 format can be used.

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

    +

    LFN extension requiers a 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 unit) of the LFN. The working 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 satisfy 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. FatFs supports the code point up to U+10FFFF. This option also affects behavior of string I/O functions (see FF_STRF_ENCODE).

    @@ -192,7 +191,7 @@

    FF_LFN_UNICODE

    2Unicode in UTF-8char 3Unicode in UTF-32DWORD -

    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 Unicode is selected, FF_CODE_PAGE has actually no meaning except for compatibility with legacy systems, such as MS-DOS and the systems 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

    @@ -204,17 +203,21 @@

    FF_LFN_BUF, FF_SFN_BUF

    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.

    +

    If the size of fname[] is insufficient for the LFN, the directory item is treated as without LFN. When LFN is not enabled, these options have no effect.

    -

    FF_FS_RPATH

    -

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

    +

    FF_RPATH

    +

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

    - - - + + +
    ValueDescription
    0Disable relative path function and remove related functions.
    1Enable relative path function. f_chdir and f_chdrive function is available.
    2f_getcwd function is available in addition to 1
    0Disable relative path and remove related APIs.
    1Enable relative path. f_chdir and f_chdrive are available.
    2f_getcwd is available in addition.
    +

    FF_PATH_DEPTH

    +

    This option defines maximum depth of directory in the path name on the exFAT volume. For example, FF_PATH_DEPTH = 3 will able to open a file "/dir1/dir2/dir3/file" or set dir3 current directory but the sub-directories in the dir3, where 4-level lower from the root directory, will not able to be followed or set current directory. This is NOT relevant to FAT/FAT32 volume.

    +

    The size of filesystem object (FATFS) increases FF_PATH_DEPTH * 24 bytes to store the current directory path. When FF_FS_EXFAT == 0 or FF_FS_RPATH == 0, this option has no effect.

    + @@ -225,12 +228,12 @@

    FF_VOLUMES

    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.

    +

    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. DOS/Windows style numeric volume ID 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.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
    0DOS/Windows style drive prefix in numeric ID.1:/filename
    10 + DOS/Windows style drive prefix in arbitrary string ID.flash:/filename
    20 + Unix style drive prefix in arbitrary string ID./flash/filename

    FF_VOLUME_STRS

    @@ -241,19 +244,19 @@

    FF_VOLUME_STRS

    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.

    +

    This option switches multi-partition featuer. By default (0), each logical drive number is bound to the same physical drive number and only one volume found in the physical drive is mounted. When it is enabled (1), each logical drive can be bound to the specific partition or physical drive listed in the user defined partition resolution table VolToPart[]. Also f_fdisk funciton is available to create the arbitrary partitions on the physical drive. For more information, read here.

    FF_MIN_SS, FF_MAX_SS

    -

    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.

    +

    This set of options defines the extent of sector size used in MAI, disk_read and disk_write function. Valid values are 512, 1024, 2048 and 4096. The FF_MIN_SS defines minimum sector size and the FF_MAX_SS defines maximum sector size. Always set both 512 for common memory cards and harddisks 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.

    +

    This option switches the addressing mode on the MAI to 64-bit LBA, Enabled (1) or Disabled (0). It also enables GUID Partition Table (GPT) for the partition management. The 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 sectors on the drive is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when FF_LBA64 == 0.

    +

    This option specifies the threshold of determination of partitioning format when create patitions on the physical drive in f_mkfs and f_fdisk function. When number of available sectors on the drive is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when 64-bit LBA is not enabled.

    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.

    +

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

    @@ -268,13 +271,16 @@

    FF_FS_EXFAT

    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 in 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 in no RTC systems. This option has no effect in read-only configuration or FF_FS_NORTC == 0.

    +

    FF_FS_CRTIME

    +

    This option enables (1) or disables (0) to access the file creation time with FILINFO structure.

    +

    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 for new allocation.

    +

    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.

    @@ -284,24 +290,22 @@

    FF_FS_NOFSINFO

    ValueDescription
    bit0=0Use free cluster count in the FSINFO if available.

    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 in 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 value will be refered in ff_mutex_take.

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dinit.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dinit.html index c668c66b29..1a4bd30b77 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dinit.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dinit.html @@ -3,8 +3,6 @@ - - FatFs - disk_initialize @@ -41,6 +39,7 @@

    Description

    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

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dioctl.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dioctl.html index 52087826a9..de563624a9 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dioctl.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dioctl.html @@ -3,8 +3,6 @@ - - FatFs - disk_ioctl @@ -57,11 +55,11 @@

    Description

    - - - - - + + + + +
    Standard ioctl command used by FatFs
    CommandDescription
    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 media immediately. Nothing to do for this command if each write operation to the media is completed within the disk_write function.
    GET_SECTOR_COUNTRetrieves number of available sectors, the largest allowable LBA + 1, on the drive into the LBA_t variable 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 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 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 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 erase block boundary. It is required when FF_USE_MKFS == 1.
    CTRL_TRIMInforms the 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>} 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.
    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.
    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 never be used and the disk_read and disk_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 it is unknown or in non-flash memory media. This command is used by f_mkfs function with block size not specified and it attempts to align the data area on the suggested block boundary. Note that FatFs does not have FTL (flash translation layer), so that 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 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.

    @@ -73,9 +71,9 @@

    Description

    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 succeeded. +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_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) @@ -96,6 +94,6 @@

    QuickInfo

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dread.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dread.html index 46d286076b..a0fa29af77 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dread.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dread.html @@ -3,8 +3,6 @@ - - FatFs - disk_read @@ -13,7 +11,7 @@

    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 */
    @@ -56,18 +54,18 @@ 

    Return Value

    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 generic read/write function must work at the 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 succeeded.

    +

    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.

    • Convert word transfer to byte transfer with some trick in this function. - Recommended.
    • On the f_read() calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.
    • -
    • On the f_read(fp, dat, btw, bw) calls, make sure that (((UINT)dat & 3) == (f_tell(fp) & 3)) is true. - Word alignment of buff is guaranteed.
    • +
    • On the f_read(fp, data, btw, bw) calls, make sure that (((UINT)data & 3) == (f_tell(fp) & 3)) is true. - Word alignment of buff is guaranteed.
    -

    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.

    +

    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.

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dstat.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dstat.html index a891489d02..c2191a02b5 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dstat.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dstat.html @@ -3,8 +3,6 @@ - - FatFs - disk_status @@ -43,6 +41,7 @@

    Return Values

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dwrite.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dwrite.html index 10072847c0..fc48f614f0 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/dwrite.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/dwrite.html @@ -3,8 +3,6 @@ - - FatFs - disk_write @@ -13,7 +11,7 @@

    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 */
    @@ -60,7 +58,7 @@ 

    Return Values

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

    +

    FatFs expects the disk control layer may have a delayed write feature. The write operation to the media does not need to be completed when return from this function by what media write operation is in progress or data is stored into the write-back cache. The 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 feature 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.

    @@ -71,6 +69,6 @@

    QuickInfo

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/eof.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/eof.html index efacfbfaab..d33c5d191a 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/eof.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/eof.html @@ -3,8 +3,6 @@ - - FatFs - f_eof @@ -57,6 +55,7 @@

    See Also

    f_open, f_lseek, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/error.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/error.html index bee9685d0c..99385de59d 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/error.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/error.html @@ -3,8 +3,6 @@ - - FatFs - f_error @@ -57,6 +55,7 @@

    See Also

    f_open, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/expand.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/expand.html index 7620ba9a54..ea39e0fcc8 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/expand.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/expand.html @@ -3,8 +3,6 @@ - - FatFs - f_expand @@ -28,7 +26,7 @@

    f_expand

    Parameters

    fp
    -
    Pointer to the open file object.
    +
    Pointer to the open file object. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    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
    @@ -59,9 +57,9 @@

    Description

  • The file has been opened in read-only mode.
  • Not allowable file size. (>= 4 GB on FAT volume)
  • -

    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.

    +

    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 allocation does not occure while the file write session.

    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.

    +

    The contiguous files can easily be accessed 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.

    @@ -76,16 +74,16 @@

    Example

    /* Creating a contiguous file */ /* Create a new file */ - res = f_open(fp = malloc(sizeof (FIL)), "file.dat", FA_WRITE|FA_CREATE_ALWAYS); + res = f_open(fp = malloc(sizeof (FIL)), "file.dat", FA_WRITE|FA_CREATE_ALWAYS); if (res) { /* Check if the file has been opened */ free(fp); die("Failed to open the file."); } - /* Alloacte a 100 MiB of contiguous area to the file */ + /* Allocate a 100 MiB of contiguous area to the file */ res = f_expand(fp, 104857600, 1); if (res) { /* Check if the file has been expanded */ - f_close(fp); + f_close(fp); free(fp); die("Failed to allocate contiguous area."); } @@ -101,7 +99,7 @@

    Example

    lba = fp->obj.fs->database + fp->obj.fs->csize * (fp->obj.sclust - 2); /* Write 2048 sectors from top of the file at a time */ - res = disk_write(drv, buffer, lba, 2048); + res = disk_write(drv, data, lba, 2048);
    @@ -112,6 +110,7 @@

    See Also

    f_open, f_lseek, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/fattime.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/fattime.html index 002733a746..c338ccd6a9 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/fattime.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/fattime.html @@ -3,8 +3,6 @@ - - FatFs - get_fattime @@ -75,6 +73,6 @@

    Example

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/fdisk.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/fdisk.html index d8c40bdb6b..36dd3a499a 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/fdisk.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/fdisk.html @@ -3,8 +3,6 @@ - - FatFs - f_fdisk @@ -49,7 +47,7 @@

    Return Values

    Description

    -

    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.

    +

    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, 4th partition in MBR format or no remainin space for next allocation. 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.

    @@ -64,23 +62,23 @@

    Example

    /* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */ 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 */ + {0, 1}, /* "0:" ==> 1st partition in physical drive 0 */ + {0, 2}, /* "1:" ==> 2nd partition in physical drive 0 */ + {1, 0} /* "2:" ==> Physical drive 1 as removable drive */ };
         /* Initialize a brand-new disk drive mapped to physical drive 0 */
     
         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 */
    +    LBA_t plist[] = {50, 50, 0};  /* Divide the drive by 2 */
    +                 /* {0x10000000, 100}; 256M sectors for the 1st partition and the remaining for the 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_fdisk(0, plist, work);            /* Divide the physical drive 0 */
     
    -    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 */
    +    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 */
     
     
    @@ -90,6 +88,7 @@

    See Also

    Volume management, f_mkfs

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/filename.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/filename.html index 5e4f48a16c..931d01b61e 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/filename.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/filename.html @@ -3,8 +3,6 @@ - - FatFs - Path Names @@ -14,12 +12,12 @@

    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:

    +

    The format of path name (path to an object (file or sub-directory)) on the FatFs module is similer to the file name 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 / 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.

    +

    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 (FAT volume) is in a digit (0-9) + a colon, while it is in an alphabet (A-Z) + a colon in DOS/Windows API. The logical drive number is the identifier to specify the FAT 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 and dots 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 filesystems. Every object on the volume is always specified in absolute path name that followed from the root directory. Dot directory names ("." and "..") 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. Dot directory names (not the object but to refer this directory or parent directory) are 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.

    @@ -29,39 +27,37 @@

    Format of the Path Names

    - - - + +
    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
    2:The root directory of the drive 2The current directory of the drive 2
    2:/The root directory of the drive 2The root directory of the drive 2
    2:file.txtA file in the root directory of the drive 2A file in the current directory of the drive 2
    ../file.txtInvalid nameA file in the parent directory
    .Invalid nameThis directory
    ..Invalid nameParent directory of the current directory (*)
    dir1/..Invalid nameThe current directory
    ..Invalid nameParent directory
    ../file.txtInvalid nameA file in the parent 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:". 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.

    +

    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 an absolute path with a heading volume ID. Any form as "root directory in current drive" and "current directory in specified drive" cannot be used. ".." cannot traverse the volumes such as "/flash/../ram/foo.dat".

    Legal Characters and Case Sensitivity

    -

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

    +

    In the generic FAT filesystems, the legal characters for the object (file or sub-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 names on the FAT volume are compared in case-insensitive. For instance, these three object names, file.txt, File.Txt and FILE.TXT, are identical on the FAT filesystem. This is applied to the extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the original name is recorded to the LFN entry if LFN extension is enabled.

    +

    On the MS-DOS and PC DOS for Chinese, Japanese and Korean (DOS/DBCS), extended characters are recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on the compatibility with Windows system when the file with extended characters is created on the volume by DOS/DBCS systems; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems. FatFs works with case-insensitive to the extended character (WindowsNT specs) in LFN configuration. On the other hand, FatFs works with case-sensitive to the extended characters in only non-LFN with DBCS configuration (DOS/DBCS specs).

    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 ✝☪✡☸☭ 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.

    +

    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 non-zero value, 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, _T("filename.txt"), FA_READ);  /* Depends on FF_LFN_UNICODE (TCHAR) */
     

    Volume Management

    -

    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 boot sector in order of LBA 0 as SFD format, 1st partition, 2nd partition, 3rd partition, ..., as MBR or GPT format.

    +

    By default, each logical drive (FAT volume) 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 associated with three partitions on the physical drive 0 (a non-removable drive)
    @@ -74,19 +70,20 @@ 

    Volume Management

    {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 when enable the multi-partition configuration.

    • The physical drive that hosts two or more mounted partitions should be non-removable, or all volumes on the drive must be unmounted when remove the medium.
    • When make any change to the VolToPart[], corresponding volume should be unmounted prior to make change the item.
    • -
    • On the MBR format drive, up to four primary partitions (1-4) can be specified. The partition number 1 specifies the first item in the partition table and the partition number 2 specifies the second one, and so on. The logical patitions (5-) in the extended partition is not supported.
    • +
    • On the MBR format drive, up to four primary partitions (1-4) can be specified. The partition number 1 specifies the first item in the partition table and the partition number 2 specifies the second one, and so on. The logical patition (5-, partitions in the extended partition) is not supported.
    • On the GPT format drive, the partition number 1 specifies the first Microsoft BDP found in the partition table and the partition number 2 specifies the second one found, and so on.
    • Windows 10 earlier than 1703 does not support multiple volumes on the physical drive with removable class. Only the first parition found on the drive will be mounted. Windows OS does not support SFD format on the physical drive with non-removable class.
    • -
    • Some systems manage the on-board storage in non-standard partition format and each partition is mapped as physical drive in disk_* functions. For such system, FF_MULTI_PARTITION should be always 0.
    • -
    • For further information about the volume management, refer to the description in f_fdisk and f_mkfs.
    • +
    • Some systems manage the on-board storage in non-standard partition format and each partition is mapped as physical drive in disk_* functions. For such system, FF_MULTI_PARTITION should be always 0 and use FM_SFD flag in f_mkfs.
    • +
    • For further information about the volume management, refer to the description in f_mkfs and f_fdisk.
    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/findfirst.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/findfirst.html index 0cd1704729..810a27938d 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/findfirst.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/findfirst.html @@ -3,8 +3,6 @@ - - FatFs - f_findfirst @@ -28,7 +26,7 @@

    f_findfirst

    Parameters

    dp
    -
    Pointer to the blank directory object.
    +
    Pointer to the blank directory object. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    fno
    Pointer to the file information structure to store the information about the found item.
    path
    @@ -62,18 +60,19 @@

    Return Values

    Description

    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 wildcard terms. For example:

    +

    The matching pattern string can contain wildcards. For example:

      -
    • ? - An any character.
    • -
    • ??? - An any string in length of three characters.
    • -
    • * - An any string in length of zero or longer.
    • -
    • ????* - An any string in length of four characters or longer.
    • +
    • ? - Any character.
    • +
    • ??? - Any string in length of three characters.
    • +
    • * - Any string in length of zero or longer.
    • +
    • ????* - Any string in length of four characters or longer.
    • +
    • "?* ?*.txt" - Text file with two or more words of body.
    -

    Since the matching algorithm uses recursion, number of wildcard terms in the matching pattern is limited to four to limit the stack usage. Any pattern with too many wildcard terms 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.

    +

    Since the matching algorithm uses recursion, number of wildcards in the matching pattern is limited to four to limit the stack usage. The 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.

      -
    • "*.*" never matches any name without extension while it matches any name with or without extension in standard systems.
    • -
    • Any pattern terminated with a dot never matches any name while it matches the name without extensiton in standard systems.
    • -
    • DBCS extended characters are compared in case-sensitive when LFN is enabled with ANSI/OEM code API.
    • +
    • "*.*" does not match any name without extension while it matches any name with or without extension in standard systems.
    • +
    • The pattern terminated with a dot does not match any name while it matches the name without extensiton in standard systems.
    • +
    • DBCS extended characters are compared in case-sensitive when LFN is enabled with !FF_LFN_UNICODE.
    @@ -95,14 +94,14 @@

    Examples

    DIR dj; /* Directory object */ FILINFO fno; /* File information */ - fr = f_findfirst(&dj, &fno, "", "????????.JPG"); /* Start to search for photo files */ + fr = f_findfirst(&dj, &fno, "", "*.jpg"); /* Start to find JPEG image files */ - while (fr == FR_OK && fno.fname[0]) { /* Repeat while an item is found */ - printf("%s\n", fno.fname); /* Print the object name */ - fr = f_findnext(&dj, &fno); /* Search for next item */ + while (fr == FR_OK && fno.fname[0]) { /* Repeat while an item is found */ + printf("%s\n", fno.fname); /* Print the object name */ + fr = f_findnext(&dj, &fno); /* Search for next item */ } - f_closedir(&dj); + f_closedir(&dj); } @@ -113,6 +112,6 @@

    See Also

    f_findnext, f_closedir, DIR, FILINFO

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/findnext.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/findnext.html index f39f0fb74e..6dfe8d71ed 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/findnext.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/findnext.html @@ -3,8 +3,6 @@ - - FatFs - f_findnext @@ -64,6 +62,7 @@

    See Also

    f_findfirst, f_closedir, DIR, FILINFO

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/forward.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/forward.html index 97a793d73b..ce36736660 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/forward.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/forward.html @@ -3,8 +3,6 @@ - - FatFs - f_forward @@ -28,13 +26,13 @@

    f_forward

    Parameters

    fp
    -
    Pointer to the open file object.
    +
    Pointer to the open file object. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    func
    Pointer to the user-defined data streaming function. For details, refer to the sample code.
    btf
    Number of bytes to forward in range of UINT.
    bf
    -
    Pointer to the UINT variable to return number of bytes forwarded.
    +
    Pointer to the variable in UINT type to return number of bytes forwarded.
    @@ -54,7 +52,7 @@

    Return Values

    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.

    @@ -109,11 +107,11 @@

    Example

    UINT dmy; /* Open the audio file in read only mode */ - rc = f_open(&fil, fn, FA_READ); + rc = f_open(&fil, fn, FA_READ); if (rc) return rc; /* Repeat until the file pointer reaches end of the file */ - while (rc == FR_OK && !f_eof(&fil)) { + while (rc == FR_OK && !f_eof(&fil)) { /* some processes... */ @@ -122,7 +120,7 @@

    Example

    } /* Close the file and return */ - f_close(&fil); + f_close(&fil); return rc; } @@ -134,6 +132,7 @@

    See Also

    f_open, fgets, f_write, f_close, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getcwd.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getcwd.html index 6eb9a58d1c..20d0e66f83 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getcwd.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getcwd.html @@ -3,8 +3,6 @@ - - FatFs - f_getcwd @@ -13,11 +11,11 @@

    f_getcwd

    -

    The f_getcwd function retrieves the current directory of the current drive.

    +

    The f_getcwd function retrieves the current directory and current drive.

     FRESULT f_getcwd (
       TCHAR* buff, /* [OUT] Buffer to return path name */
    -  UINT len     /* [IN] The length of the buffer */
    +  UINT len     /* [IN] Buffer length */
     );
     
    @@ -26,9 +24,9 @@

    f_getcwd

    Parameters

    buff
    -
    Pointer to the buffer to receive the current directory string.
    +
    Pointer to the string buffer to receive the current directory path.
    len
    -
    Size of the buffer in unit of TCHAR.
    +
    Size of the buffer in unit of (TCHAR).
    @@ -50,8 +48,7 @@

    Return Values

    Description

    -

    The f_getcwd function retrieves full path name of the current directory of the current drive. When FF_VOLUMES >= 2, a heading drive prefix is added to the path name. The style of drive prefix depends on FF_STR_VOLUME_ID.

    -

    Note: In this revision, this function cannot retrieve the current directory path on the exFAT volume. It always returns the root directory path.

    +

    The f_getcwd function retrieves the full path name to the current directory of the current drive. When FF_VOLUMES >= 2, a heading drive prefix is added to the path name. The style of drive prefix depends on FF_STR_VOLUME_ID.

    @@ -78,6 +75,7 @@

    See Also

    f_chdrive, f_chdir

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getfree.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getfree.html index 5e4f4193a5..60ac9bc740 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getfree.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getfree.html @@ -3,8 +3,6 @@ - - FatFs - f_getfree @@ -89,6 +87,6 @@

    See Also

    FATFS

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getlabel.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getlabel.html index 0ec6d0d4e9..675b0f1523 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/getlabel.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/getlabel.html @@ -3,8 +3,6 @@ - - FatFs - f_getlabel @@ -13,7 +11,7 @@

    f_getlabel

    -

    The f_getlabel function returns volume label and volume serial number of a volume.

    +

    The f_getlabel function retrieves volume label and volume serial number of a volume.

     FRESULT f_getlabel (
       const TCHAR* path,  /* [IN] Drive number */
    @@ -27,7 +25,7 @@ 

    f_getlabel

    Parameters

    path
    -
    Pointer to the null-terminated string that specifies the logical drive. Null-string specifies the default drive.
    +
    Pointer to the null-terminated string that specifies the logical drive. Null-string specifies the default drive. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    label
    Pointer to the buffer to store the volume label. If the volume has no label, a null-string will be returned. Set null pointer if this information is not needed. The buffer size should be shown below at least to avoid buffer overflow.
    @@ -71,10 +69,10 @@

    Example

    char str[12]; /* Get volume label of the default drive */ - f_getlabel("", str, 0); + f_getlabel("", str, NULL); /* Get volume label of the drive 2 */ - f_getlabel("2:", str, 0); + f_getlabel("2:", str, NULL); @@ -85,6 +83,6 @@

    See Also

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/gets.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/gets.html index 89d95607cd..68c65da98f 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/gets.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/gets.html @@ -3,8 +3,6 @@ - -FatFs - f_gets @@ -45,13 +43,13 @@

    Return Values

    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 differs between file data and API, it is converted in this function. Input characters with wrong encoding for output will be lost.

    QuickInfo

    -

    This is a wrapper function of f_read function. Available when FF_USE_STRFUNC >= 1. When it is set to 2, '\r's contained in the file are stripped out.

    +

    This is a wrapper function of f_read function. Available when FF_USE_STRFUNC >= 1. When it is set to 2, '\r's contained in the read data are stripped off.

    @@ -60,6 +58,7 @@

    See Also

    f_open, f_read, f_putc, f_puts, f_printf, f_close, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/index.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/index.html new file mode 100644 index 0000000000..8368bb6bdc --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/index.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/lseek.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/lseek.html index 5fc933e37a..7760ee9e7c 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/lseek.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/lseek.html @@ -3,8 +3,6 @@ - -FatFs - f_lseek @@ -32,7 +30,7 @@

    f_lseek

    Parameters

    fp
    -
    Pointer to the open file object.
    +
    Pointer to the open file object. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    ofs
    Byte offset from top of the file to set read/write pointer. 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.
    @@ -53,17 +51,18 @@

    Return Values

    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. The f_rewind function is impremented as a macro.

    +

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

    +

    When an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset in this function. The file data in the expanded part is undefined, because no data is written to the file in this process. Be careful about these behaviours differ from POSIX fseek function. This is suitable to pre-allocate a data area to the file for subsequent fast write operation. If 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.

    • End of file. The specified ofs was clipped at end of the file in read-only mode.
    • Disk full. There is no free space on the volume to expand 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 enabled 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.

    +

    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 in fast seek mode.

    +

    The fast seek mode is available when FF_USE_FASTSEEK = 1. The CLMT must be created into a 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. 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. After the function succeeded, no FAT access is occured in subsequent f_read, f_write, f_lseek function to the file. To disable the fast seek mode, set null pointer to the cltbl.

    @@ -78,33 +77,33 @@

    Example

         /* Open file */
         fp = malloc(sizeof (FIL));
    -    res = f_open(fp, "file.dat", FA_READ|FA_WRITE);
    +    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);
     
     /* Cluster pre-allocation (to prevent buffer overrun on streaming write) */
     
    -    res = f_open(fp, recfile, FA_CREATE_NEW | FA_WRITE);   /* Create a file */
    +    res = f_open(fp, recfile, FA_CREATE_NEW | FA_WRITE);   /* Create a file */
     
         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 */
    +    if (res || f_tell(fp) != PRE_SIZE) ...   /* Check if the file has been expanded successfly */
     
         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_truncate(fp);                    /* Truncate unused area */
         res = f_lseek(fp, OFS_HEADER);           /* Set file header */
         ...
     
    @@ -115,7 +114,7 @@ 

    Example

    DWORD clmt[SZ_TBL]; /* Cluster link map table buffer */ - res = f_open(fp, fname, FA_READ | FA_WRITE); /* Open a file */ + res = f_open(fp, fname, FA_READ | FA_WRITE); /* Open a file */ res = f_lseek(fp, ofs1); /* This is normal seek (cltbl is nulled on file open) */ @@ -134,6 +133,7 @@

    See Also

    f_open, f_truncate, f_expand, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_alloc.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_alloc.html new file mode 100644 index 0000000000..f927bccf16 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_alloc.html @@ -0,0 +1,45 @@ + + + + + + +FatFs - ff_memalloc + + + + +
    +

    ff_memalloc

    +

    The ff_memalloc function is an equivarent or alias of POSIX malloc function.

    +
    +void* ff_memalloc (
    +  UINT msize           /* [IN] Size of memory block */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    msize
    +
    Size of memory block to allocate in unit of byte.
    +
    +
    + + +
    +

    Return Value

    +

    A void type pointer to the allocated memory block. If the memory block could not be allocated, a null pointer is returned and the file function may fail with FR_NOT_ENOUPH_CORE.

    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_USE_LFN = 3. It is intended to be used by FatFs but also application program may use this function.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_create.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_create.html new file mode 100644 index 0000000000..5453b65cdf --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_create.html @@ -0,0 +1,45 @@ + + + + + + +FatFs - ff_mutex_create + + + + +
    +

    ff_mutex_create

    +

    The ff_mutex_create function is for mutal exclusion control of file system object. It is called on register a file system object and create its mutex.

    +
    +int ff_mutex_create (
    +  int vol           /* [IN] Volume ID */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    vol
    +
    Volume ID number in range from 0 to FF_VOLUMES. The value is used for the index of internal table of mutexes.
    +
    +
    + + +
    +

    Return Values

    +

    A non-zero value is returned if a new mutex was created or alreay created. If not, a zero is returned and f_mount function will fail with FR_INT_ERR.

    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_FS_REENTRANT = 1.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_delete.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_delete.html new file mode 100644 index 0000000000..3cc60266b2 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_delete.html @@ -0,0 +1,39 @@ + + + + + + +FatFs - ff_mutex_delete + + + + +
    +

    ff_mutex_delete

    +

    The ff_mutex_delete function is for mutal exclusion control of file system object. It is called on unregister a file system object and delete its mutex.

    +
    +void ff_mutex_delete (
    +  int vol           /* [IN] Volume ID */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    vol
    +
    Volume ID number in range from 0 to FF_VOLUMES. The value is used for the index of internal table of mutexes.
    +
    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_FS_REENTRANT = 1.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_free.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_free.html new file mode 100644 index 0000000000..9fb9417553 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_free.html @@ -0,0 +1,39 @@ + + + + + + +FatFs - ff_memfree + + + + +
    +

    ff_memfree

    +

    The ff_memfree function is an equivalent or an alias of POSIX free function.

    +
    +void ff_memfree (
    +  void* mblock           /* [IN] Pointer to the memory block */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    mblock
    +
    Pointer to the valid memory block allocated by ff_memalloc function. A null pointer has no effect.
    +
    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_USE_LFN = 3. It is intended to be used by FatFs but also application program may use this function.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_give.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_give.html new file mode 100644 index 0000000000..55d83077f0 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_give.html @@ -0,0 +1,39 @@ + + + + + + +FatFs - ff_mutex_give + + + + +
    +

    ff_mutex_give

    +

    The ff_mutex_give function is for mutal exclusion control of file system object. It is called on the control leaves file API to unlock the volume.

    +
    +int ff_mutex_take (
    +  int vol           /* [IN] Volume ID */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    vol
    +
    Volume ID number in range from 0 to FF_VOLUMES. The value is used for the index of internal table of mutexes.
    +
    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_FS_REENTRANT = 1.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_take.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_take.html new file mode 100644 index 0000000000..51184f54fc --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/m_take.html @@ -0,0 +1,45 @@ + + + + + + +FatFs - ff_mutex_take + + + + +
    +

    ff_mutex_take

    +

    The ff_mutex_take function is for mutal exclusion control of file system object. It is called on the control enters file API to lock the volume.

    +
    +int ff_mutex_take (
    +  int vol           /* [IN] Volume ID */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    vol
    +
    Volume ID in range from 0 to FF_VOLUMES. The value is used for the index of internal table of mutexes.
    +
    +
    + + +
    +

    Return Values

    +

    A non-zero value is returned if the mutex was successfully taken. If not, a zero is returned and the file function will abort with FR_TIMEOUT.

    +
    + + +
    +

    QuickInfo

    +

    This function is required when FF_FS_REENTRANT = 1.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkdir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkdir.html index de32f834a6..6e954aa5d6 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkdir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkdir.html @@ -3,8 +3,6 @@ - - FatFs - f_mkdir @@ -75,6 +73,7 @@

    Example

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkfs.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkfs.html index 3f3bd70471..900c98863b 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkfs.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mkfs.html @@ -3,8 +3,6 @@ - -FatFs - f_mkfs @@ -30,23 +28,23 @@

    Parameters

    path
    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 structure MKFS_PARM holding format options. If a null pointer is given, it gives the function all options in default value. The structure has five members described below:
    +
    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 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 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_size. The flag FM_SFD specifies to create the volume on the drive in SFD format. The default value is FM_ANY.
    -
    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_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.
    +
    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 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 an invalid value is given, the function obtains the block size from lower layer with disk_ioctl function.
    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.
    +
    DWORD au_size
    +
    Specifies size of the cluster (allocation unit) in unit of byte. The valid value for this member is between sector size and 128 * sector size inclusive in power of 2 for FAT/FAT32 volume and up to 16 MB in power of 2 for exFAT volume. If a zero (default value) or an invalid value is given, the function uses a default cluster size depends on the volume size.
    work
    -
    Pointer to the working buffer used for the format process. If a null pointer is given with FF_USE_LFN == 3, the function obtains a memory block for the working buffer in this function.
    +
    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 FF_MAX_SS 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.
    @@ -69,9 +67,9 @@

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

    +

    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 some partitioning tool prior to create the FAT volume with this function. If the partition is not exist, the function fails 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 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 of 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.

    @@ -97,21 +95,21 @@

    Example

    if (res) ... /* Give a work area to the default drive */ - f_mount(&fs, "", 0); + f_mount(&fs, "", 0); /* Create a file as new */ - res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE); + res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE); if (res) ... /* Write a message */ - f_write(&fil, "Hello, World!\r\n", 15, &bw); + f_write(&fil, "Hello, World!\r\n", 15, &bw); if (bw != 15) ... /* Close the file */ - f_close(&fil); + f_close(&fil); /* Unregister work area */ - f_mount(0, "", 0); + f_mount(0, "", 0); ... @@ -122,6 +120,7 @@

    See Also

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

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mount.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mount.html index 57f40bedd0..9b2eedf46f 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/mount.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/mount.html @@ -3,8 +3,6 @@ - -FatFs - f_mount @@ -32,11 +30,11 @@

    f_mount

    Parameters

    fs
    -
    Pointer to the filesystem object to be registered and cleared. Null pointer unregisters the registered filesystem object.
    +
    Pointer to the filesystem object to be registered and cleared. A null pointer unregisters the registered filesystem object.
    path
    Pointer to the null-terminated string that specifies the logical drive. The string without drive number means the default drive.
    opt
    -
    Mounting option. 0: Do not mount now (to be mounted on the first access to the volume), 1: Force mounted the volume to check if it is ready to work.
    +
    Mounting option. 0: Do not mount now (to be mounted on the first access to the volume), 1: Force mounted the volume to check if it is ready to work. If fs is a NULL, this argument has no meaning.
    @@ -55,7 +53,7 @@

    Return Values

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

    +

    FatFs requires work area (filesystem object) for each logical drive (FAT volume). Prior to perform 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. @@ -63,14 +61,14 @@

      Description

    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.

    +

    If there are open objects of file or directory on the logical drive, they 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. There is no action to 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.
    • -
    • Physical drive is not initialized. It is de-initialized by system reset or media removal.
    • +
    • The filesystem object has not been initialized. It is de-initialized by f_mount function.
    • +
    • The physical drive is not initialized. It is de-initialized by system reset or media removal.

    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.

    +

    If implementation of the disk I/O layer lacks asynchronous media change detection, the 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. f_unmount function is implemented as a macro.

     #define f_unmount(path) f_mount(0, path, 0)
    @@ -92,19 +90,19 @@ 

    Example

    FATFS *fs; /* Ponter to the filesystem object */ - fs = malloc(sizeof (FATFS)); /* Get work area for the volume */ - f_mount(fs, "", 0); /* Mount the default drive */ + fs = malloc(sizeof (FATFS)); /* Get work area for the volume */ + f_mount(fs, "", 0); /* Mount the default drive */ - f_open(... /* Here any file API can be used */ + f_open(... /* Here any file API can be used */ ... - f_mount(fs, "", 0); /* Re-mount the default drive to reinitialize the filesystem */ + f_mount(fs, "", 0); /* Re-mount the default drive to reinitialize the filesystem */ ... - f_mount(0, "", 0); /* Unmount the default drive */ - free(fs); /* Here the work area can be discarded */ + f_unmount(""); /* Unmount the default drive */ + free(fs); /* Here the work area can be discarded */ ... } @@ -117,6 +115,7 @@

    See Also

    f_open, FATFS

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/oem2uni.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/oem2uni.html new file mode 100644 index 0000000000..19d1d1ebb6 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/oem2uni.html @@ -0,0 +1,48 @@ + + + + + + +FatFs - ff_oem2uni + + + + +
    +

    ff_oem2uni

    +

    The ff_oem2uni function converts an OEM character into Unicode character.

    +
    +WCHAR ff_oem2uni (
    +  WCHAR oem,           /* [IN] OEM character */
    +  WORD cp              /* [IN] Code page */
    +);
    +
    +
    + +
    +

    Parameters

    +
    +
    oem
    +
    An OEM character to be converted into Unicode.
    +
    cp
    +
    Code page of input character. If FF_CODE_PAGE specifies a code page, only this code page can be specified. If it specifies all code page, any supported code page can be specified.
    +
    +
    + + +
    +

    Return Value

    +

    The function returns a Unicode character in UTF-16 encoding converted from input OEM character. If the input character code in specified code page is invalid, a null character is returned.

    +
    + + +
    +

    QuickInfo

    +

    This function is provided in ffunicode.c and required when FF_USE_LFN != 0. It is intended to be used by FatFs but also application program may use this function.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/open.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/open.html index dd2a6e6613..4f78f4fc37 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/open.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/open.html @@ -3,8 +3,6 @@ - -FatFs - f_open @@ -27,19 +25,19 @@

    f_open

    Parameters

    fp
    -
    Pointer to the blank file object structure.
    +
    Pointer to the blank file object structure. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    path
    -
    Pointer to the null-terminated string that specifies the file name to open or create.
    +
    Pointer to the null-terminated string that specifies the file name to open or create. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    mode
    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 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_EXISTINGOpens the file. The function fails if the file is not existing. (Default)
    FA_CREATE_ALWAYSCreates a new file. If the file is existing, the file is truncated and overwritten.
    FA_CREATE_NEWCreates a new file. The function fails if the file is existing.
    FA_OPEN_ALWAYSOpens the file. If it is not exist, a new file is created.
    FA_OPEN_APPENDSame as FA_OPEN_ALWAYS except the read/write pointer is set end of the file.
    Mode flags in POSIX fopen() function corresponds to FatFs mode flags as follows:
    @@ -86,7 +84,8 @@

    Return Values

    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. It is the identifier for subsequent read/write operations to the file. After the function succeeded, the file object is valid. If the function failed, the file object is set invalid.

    +

    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.

    @@ -112,19 +111,19 @@

    Example

    /* Give a work area to the default drive */ - f_mount(&FatFs, "", 0); + f_mount(&FatFs, "", 0); /* Open a text file */ fr = f_open(&fil, "message.txt", FA_READ); if (fr) return (int)fr; /* Read every line and display it */ - while (f_gets(line, sizeof line, &fil)) { + while (f_gets(line, sizeof line, &fil)) { printf(line); } /* Close the file */ - f_close(&fil); + f_close(&fil); return 0; } @@ -142,8 +141,8 @@

    Example

    /* Give work areas to each logical drive */ - f_mount(&fs0, "0:", 0); - f_mount(&fs1, "1:", 0); + f_mount(&fs0, "0:", 0); + f_mount(&fs1, "1:", 0); /* Open source file on the drive 1 */ fr = f_open(&fsrc, "1:file.bin", FA_READ); @@ -155,19 +154,19 @@

    Example

    /* Copy source to destination */ for (;;) { - fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* Read a chunk of data from the source file */ + 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 */ + fr = f_write(&fdst, buffer, br, &bw); /* Write it to the destination file */ if (bw < br) break; /* error or disk full */ } /* Close open files */ - f_close(&fsrc); - f_close(&fdst); + f_close(&fsrc); + f_close(&fdst); /* Unregister work area prior to discard it */ - f_unmount("0:"); - f_unmount("1:"); + f_unmount("0:"); + f_unmount("1:"); return (int)fr; } @@ -180,6 +179,7 @@

    See Also

    f_read, f_write, f_close, FIL, FATFS

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/opendir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/opendir.html index 215c37a673..bc6d457433 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/opendir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/opendir.html @@ -3,8 +3,6 @@ - - FatFs - f_opendir @@ -26,9 +24,9 @@

    f_opendir

    Parameters

    dp
    -
    Pointer to the blank directory object to create a new one.
    +
    Pointer to the blank directory object to create a new one. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    path
    -
    Pointer to the null-terminated string that specifies the directory name to be opened.
    +
    Pointer to the null-terminated string that specifies the directory name to be opened. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    @@ -70,6 +68,7 @@

    See Also

    f_readdir, f_closedir, DIR

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/printf.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/printf.html index 557fb574de..1db40165af 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/printf.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/printf.html @@ -1,114 +1,114 @@ - - - - - - - - -FatFs - f_printf - - - - -
    -

    f_printf

    -

    The f_printf function writes formatted string to the file.

    -
    -int f_printf (
    -  FIL* fp,          /* [IN] File object */
    -  const TCHAR* fmt, /* [IN] Format stirng */
    -  ...
    -);
    -
    -
    - -
    -

    Parameters

    -
    -
    fp
    -
    Pointer to the open file object structure.
    -
    fmt
    -
    Pointer to the null '\0' terminated format string. The terminator character will not be output.
    -
    ...
    -
    Optional arguments...
    - -
    -
    - - -
    -

    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 an error, a negative value will be returned.

    -
    - - -
    -

    Description

    -

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

    -
    -    %[flag][width][precision][size]type
    -
    -
    -
    flag
    Padding options. 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 specified value, rest field is padded with spaces or zeros. An * specifies the value comes from an argument in int type.
    -
    precision
    Specifies number of fractional digits or maximum width of string, .0-.99 or .*. If number is omitted, it will be 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 arrument and floating point argument is always assumed double.
    -
    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. - - - - - - - - - - - -
    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.

    -
    - - -
    -

    QuickInfo

    -

    This is a wrapper function of f_write function. Available when FF_FS_READONLY == 0 and FF_USE_STRFUNC >= 1. When FF_USE_STRFUNC == 2, '\n's in the generated string are written as '\r'+'\n' each.

    -
    - - -
    -

    Example

    -
    -    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) */
    -
    -
    - - -
    -

    See Also

    -

    f_open, f_putc, f_puts, f_gets, f_close, FIL

    -
    - -

    Return

    - - + + + + + + +FatFs - f_printf + + + + +
    +

    f_printf

    +

    The f_printf function writes formatted string to the file.

    +
    +int f_printf (
    +  FIL* fp,          /* [IN] File object */
    +  const TCHAR* fmt, /* [IN] Format stirng */
    +  ...
    +);
    +
    +
    + +
    +

    Parameters

    +
    +
    fp
    +
    Pointer to the open file object structure.
    +
    fmt
    +
    Pointer to the null '\0' terminated format string. The terminator character will not be output.
    +
    ...
    +
    Optional arguments...
    + +
    +
    + + +
    +

    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 an error, a negative value will be returned.

    +
    + + +
    +

    Description

    +

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

    +
    +    %[flag][width][precision][size]type
    +
    +
    +
    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. + + + + + + + + + + + +
    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. A null pointer generates a zero-length string.
    fFloating point
    (decimal)
    double1 to 31 characters. If the number of characters exceeds 31, it writes "±OV". Not a number and infinite value write "NaN" and "±INF" respectively.
    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. If the character encoding differs between file data and API, it is converted in this function. Input characters with wrong encoding for output will be lost.

    +

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

    +
    + + +
    +

    QuickInfo

    +

    This is a wrapper function of f_write function. Available when FF_FS_READONLY == 0 and FF_USE_STRFUNC >= 1. When FF_USE_STRFUNC == 2, '\n's in the generated string are written as '\r'+'\n' each.

    +
    + + +
    +

    Example

    +
    +    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) */
    +
    +
    + + +
    +

    See Also

    +

    f_open, f_putc, f_puts, f_gets, f_close, FIL

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/putc.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/putc.html index 747b5fdd8c..74552c93b2 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/putc.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/putc.html @@ -3,8 +3,6 @@ - - FatFs - f_putc @@ -55,6 +53,7 @@

    See Also

    f_open, f_puts, f_printf, f_gets, f_close, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/puts.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/puts.html index 3695942530..de5833a1f9 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/puts.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/puts.html @@ -3,8 +3,6 @@ - - FatFs - f_puts @@ -41,7 +39,7 @@

    Return Value

    Description

    -

    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 input 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 functions is selected by FF_STRF_ENCODE. The characters with wrong encoding or invalid for the output encoding will be lost.

    +

    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 input 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 functions is selected by FF_STRF_ENCODE. If the character encoding differs between file data and API, it is converted in this function. Input characters with wrong encoding for output will be lost.

    @@ -56,6 +54,7 @@

    See Also

    f_open, f_putc, f_printf, f_gets, f_close, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/rc.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/rc.html index 52b496c376..8c4dba33ef 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/rc.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/rc.html @@ -3,8 +3,6 @@ - - FatFs - API Return Code @@ -19,7 +17,7 @@

    Return Code of API Functions

    The function succeeded.
    FR_DISK_ERR
    -
    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.
    +
    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 in the operation to an open file, the file object is aborted and any operations to the file except f_close will be rejected.
    FR_INT_ERR
    Assertion failed and an insanity is detected in the internal process. One of the following possibilities is suspected. @@ -29,7 +27,7 @@

    Return Code of API Functions

  • There is a bug in the FatFs module itself.
  • Wrong lower layer implementation.
  • -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. +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 f_close will be rejected.
    FR_NOT_READY
    @@ -46,14 +44,14 @@

    Return Code of API Functions

    Could not find the file in the directory.
    FR_NO_PATH
    -
    Could not find the path. A directory in the path name could not be found.
    +
    Could not follow the path. A sub-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 a character not allowed for the file name.
    • +
    • 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.)
    • +
    • FF_MAX_LFN is insufficient for the length of file name. (at LFN cfg.)
    • There is a character encoding error in the string.
    @@ -61,30 +59,30 @@

    Return Code of API Functions

    FR_DENIED
    The required access was denied due to one of the following reasons:
      -
    • 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_mkfs)
    • -
    • Could not allocate a contiguous area to the file. (f_expand)
    • +
    • 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 data area for the file. (f_expand)
    FR_EXIST
    -
    Name collision. An object with the same name is already existing in the directory.
    +
    Name collision. A file or sub-directory 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: +
    The file/directory object is invalid or the pointer is null. There are some reasons as follows:
      -
    • It has been closed, or the structure has been collapsed.
    • -
    • It has been invalidated. Open objects on the volume are invalidated by voulme mount process.
    • +
    • The file/directory object has been closed.
    • +
    • The file/directory object has been invalidated or the structure has been collapsed. Open objects on the volume will be invalidated by a voulme mount process.
    • Physical drive is not ready to work due to a media removal.
    FR_WRITE_PROTECTED
    -
    A write mode operation against the write-protected media.
    +
    A write mode operation against the write-protected medium.
    FR_INVALID_DRIVE
    Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: FF_VOLUMES)
    @@ -93,8 +91,9 @@

    Return Code of API Functions

    Work area for the logical drive has not been registered by f_mount function.
    FR_NO_FILESYSTEM
    -
    No valid FAT volume could not be found in the drive. One of the following possibilities is suspected. +
    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)
    @@ -112,13 +111,14 @@

    Return Code of API Functions

    The function was canceled due to a timeout of thread-safe control. (Related option: FF_TIMEOUT)
    FR_LOCKED
    -
    The operation to the object was rejected by file sharing control. (Related option: FF_FS_LOCK)
    +
    The operation to the file or sub-directory was rejected by file sharing control. (Related option: FF_FS_LOCK)
    FR_NOT_ENOUGH_CORE
    Not enough memory for the operation. There is one of the following reasons:
    • Could not allocate a memory for LFN working buffer. (Related option: FF_USE_LFN)
    • Size of the given buffer is insufficient for the size required.
    • +
    • FF_PATH_DEPTH is insufficient to follow the deep path. (on exFAT volume)
    @@ -129,6 +129,7 @@

    Return Code of API Functions

    The given parameter is invalid or there is an inconsistent for the volume.
    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/read.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/read.html index 4ab350d387..3922c31236 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/read.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/read.html @@ -3,8 +3,6 @@ - - FatFs - f_read @@ -28,13 +26,13 @@

    f_read

    Parameters

    fp
    -
    Pointer to the open file object.
    +
    Pointer to the open file object structure. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    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. If the return value is equal to btr, the function return code should be FR_OK.
    +
    Pointer to the variable in UINT type 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 +52,7 @@

    Return Values

    Description

    -

    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 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 of the file object. 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.

    @@ -75,6 +73,7 @@

    See Also

    f_open, fgets, f_write, f_close, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/readdir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/readdir.html index 52a96b9693..5eec3bbeb3 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/readdir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/readdir.html @@ -3,8 +3,6 @@ - - FatFs - f_readdir @@ -53,19 +51,19 @@

    Return Values

    Description

    -

    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.

    +

    The f_readdir function reads a directory item, informations about the object, from the open directory. Items in the directory can be read by f_readdir function calls in order of the directory table. When all items in the directory have been read and no item to read any more, a null string in fno->fname[] will be returned without an error. If an error occured, also fno->fname[] will have a null string. When a null pointer is given to the fno, the read index of the directory object is rewound. 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.

    +

    When LFN is enabled, a member altname[] is defined in the file information structure to store the short file name of the object. In case of the long file name is not accessible due to any reason listed below, short file name is stored to the fname[] and the altname[] has a null string.

      -
    • The item has no LFN. (Not the case in exFAT volume)
    • -
    • FF_MAX_LFN is insufficient to handle the LFN. (Not the case in FF_MAX_LFN == 255)
    • -
    • FF_LFN_BUF is insufficient to store the LFN.
    • -
    • The LFN contains some character not defined in current CP. (Not the case in FF_LFN_UNICODE != 0)
    • +
    • The object has no LFN. (Not the case on the exFAT volume)
    • +
    • FF_MAX_LFN is insufficient to handle the LFN. (Not the case when FF_MAX_LFN == 255)
    • +
    • FF_LFN_BUF is insufficient to output the LFN.
    • +
    • The LFN contains some character not defined in current CP. (Not the case when FF_LFN_UNICODE != 0)
    -

    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.

    +

    There is an issue to read the directories on the 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 of the consistency with exFAT which lacks dot entries in the sub-directory. They should be logically set into the list if needed.

    @@ -78,6 +76,41 @@

    QuickInfo

    Sample Code

    +/* List contents of a directory */
    +
    +FRESULT list_dir (const char *path)
    +{
    +    FRESULT res;
    +    DIR dir;
    +    FILINFO fno;
    +    int nfile, ndir;
    +
    +
    +    res = f_opendir(&dir, path);                   /* Open the directory */
    +    if (res == FR_OK) {
    +        nfile = ndir = 0;
    +        for (;;) {
    +            res = f_readdir(&dir, &fno);           /* Read a directory item */
    +            if (fno.fname[0] == 0) break;          /* Error or end of dir */
    +            if (fno.fattrib & AM_DIR) {            /* It is a directory */
    +                printf("   <DIR>   %s\n", fno.fname);
    +                ndir++;
    +            } else {                               /* It is a file */
    +                printf("%10u %s\n", fno.fsize, fno.fname);
    +                nfile++;
    +            }
    +        }
    +        f_closedir(&dir);
    +        printf("%d dirs, %d files.\n", ndir, nfile);
    +    } else {
    +        printf("Failed to open \"%s\". (%u)\n", path, res);
    +    }
    +    return res;
    +}
    +
    +
    +/* Recursive scan of all items in the directory */
    +
     FRESULT scan_files (
         char* path        /* Start node to be scanned (***also used as work area***) */
     )
    @@ -88,22 +121,22 @@ 

    Sample Code

    static FILINFO fno; - res = f_opendir(&dir, path); /* Open the directory */ + res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ - if (fno.fattrib & AM_DIR) { /* It is a directory */ + res = f_readdir(&dir, &fno); /* Read a directory item */ + if (fno.fname[0] == 0) break; /* Break on error or end of dir */ + if (fno.fattrib & AM_DIR) { /* The item is a directory */ i = strlen(path); sprintf(&path[i], "/%s", fno.fname); - res = scan_files(path); /* Enter the directory */ + res = scan_files(path); /* Enter the directory */ if (res != FR_OK) break; path[i] = 0; - } else { /* It is a file. */ + } else { /* The item is a file. */ printf("%s/%s\n", path, fno.fname); } } - f_closedir(&dir); + f_closedir(&dir); } return res; @@ -117,7 +150,7 @@

    Sample Code

    char buff[256]; - res = f_mount(&fs, "", 1); + res = f_mount(&fs, "", 1); if (res == FR_OK) { strcpy(buff, "/"); res = scan_files(buff); @@ -134,6 +167,7 @@

    See Also

    f_opendir, f_closedir, f_stat, FILINFO, DIR

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/rename.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/rename.html index 326af0d48b..e0a6485087 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/rename.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/rename.html @@ -3,8 +3,6 @@ - - FatFs - f_rename @@ -26,9 +24,9 @@

    f_rename

    Parameters

    old_name
    -
    Pointer to a null-terminated string that specifies the existing file or sub-directory to be renamed.
    +
    Pointer to the null-terminated string that specifies the existing file or sub-directory to be renamed.
    new_name
    -
    Pointer to a null-terminated string that specifies the new object name. A drive number may be specified in this string but it is ignored and assumed as the same drive of the old_name. Any object with this path name except old_name must not be exist, or the function fails with FR_EXIST.
    +
    Pointer to the null-terminated string that specifies the new object name. A drive number may be specified in this string but it is ignored and assumed as the same drive of the old_name. Any object with this name except old_name must not be exist, or the function fails with FR_EXIST.
    @@ -57,7 +55,9 @@

    Return Values

    Description

    -

    Renames a file or sub-directory and can also move it to other directory in the same volume. The object to be renamed must not be an open object, or the FAT volume can be collapsed. Such the wrong operation is rejected safely when file lock function is enabled.

    +

    Renames a file or sub-directory and can also move it to another directory in the same volume. The file to be renamed must not be an open file, or the FAT volume can be collapsed. Such the wrong file renaming is rejected safely when file lock function is enabled.

    +

    Any sub-directory in the current directory path should not be renamed. It will be rejected on the exFAT volume but succeeds on the FAT/FAT32 volume.

    +

    Remark: Be careful in moving a sub-directory. The sub-directory must not be moved into itself and any sub-directory in it, or the moved sub-directory will be lost.

    @@ -76,12 +76,12 @@

    Example

    /* Rename an object in the drive 2 */ f_rename("2:oldname.txt", "newname.txt"); - /* Rename an object and move it to another directory in the drive */ + /* Rename an object and move it into another directory in the drive */ f_rename("log.txt", "old/log0001.txt"); -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sdir.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sdir.html index eb18cc323c..0d8e31be12 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sdir.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sdir.html @@ -3,8 +3,6 @@ - - FatFs - DIR @@ -16,7 +14,7 @@

    DIR

    The DIR structure is used for the work area to read a directory by f_oepndir, f_readdir, f_findfirst and f_findnext function. Application program must not modify any member in this structure, or f_readdir function will not work properly.

     typedef struct {
    -    FFOBJID obj;        /* Object identifier */
    +    FFOBJID obj;        /* Object identifier */
         DWORD   dptr;       /* Current read/write offset */
         DWORD   clust;      /* Current cluster */
         LBA_t   sect;       /* Current sector */
    @@ -27,12 +25,13 @@ 

    DIR

    WCHAR* lfn; /* Pointer to the LFN working buffer (in/out) */ #endif #if FF_USE_FIND - const TCHAR* pat; /* Ponter to the matching pattern */ + const TCHAR* pat; /* Ponter to the matching pattern */ #endif } DIR;
    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/setcp.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/setcp.html index a1d124bc8f..570e907b8b 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/setcp.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/setcp.html @@ -3,8 +3,6 @@ - - FatFs - f_setcp @@ -77,6 +75,6 @@

    QuickInfo

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/setlabel.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/setlabel.html index 9eb5e78afc..496c4f6fa1 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/setlabel.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/setlabel.html @@ -3,8 +3,6 @@ - - FatFs - f_setlabel @@ -25,7 +23,7 @@

    f_setlabel

    Parameters

    label
    -
    Pointer to the null-terminated string that specifies the volume label to be set.
    +
    Pointer to the null-terminated string that specifies the volume label to be set. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    @@ -49,15 +47,15 @@

    Return Values

    Description

    -

    When the string has a drive prefix, the volume label will be set to the volume specified by the drive prefix. Unix style volume ID cannot be used to specify the volume. If drive number is not specified, the volume label will be set to the default drive. If length of the given volume label is zero, the volume label on the volume will be removed. The format of the volume label is as shown below:

    +

    When the string has a drive prefix, the volume label will be set to the volume specified by the drive prefix. If drive number is not specified, the volume label will be set to the default drive. If length of the given volume label is zero, the volume label on the volume will be removed. The format of the volume label is as shown below:

    • Up to 11 bytes long as conversion of OEM code page at FAT volume.
    • Up to 11 characters long at exFAT volume.
    • -
    • Allowable characters for FAT volume are: characters allowed for SFN excludes dot. Low-case characters are up converted.
    • -
    • Allowable characters for exFAT volume are: characters allowed for LFN includes dot. Low-case characters are preserved.
    • +
    • Allowable characters for FAT volume are: characters allowed for SFN excluding dot. Low-case characters are up converted.
    • +
    • Allowable characters for exFAT volume are: characters allowed for LFN including dot. Low-case characters are preserved.
    • Spaces can be embedded anywhere in the volume label. Trailing spaces are truncated off at FAT volume.
    -

    Remark: The standard system (Windows) has a problem at the volume label with a heading \xE5 on the FAT volume. To avoid this problem, this function rejects such volume label as invalid name.

    +

    Remark: The standard system (Windows) has a problem in the volume label with a heading \xE5 on the FAT volume. To avoid this problem, this function rejects such volume label as invalid name.

    @@ -77,6 +75,9 @@

    Example

    /* Remove volume label of the drive 2 */ f_setlabel("2:"); + + /* Set volume label in Unix style volume id */ + f_setlabel("/tfcard/LOG DISK");
    @@ -87,6 +88,6 @@

    See Also

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfatfs.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfatfs.html index 6ecd6e5e59..f278980633 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfatfs.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfatfs.html @@ -3,8 +3,6 @@ - - FatFs - FATFS @@ -17,7 +15,8 @@

    FATFS

     typedef struct {
         BYTE    fs_type;      /* FAT type (0, FS_FAT12, FS_FAT16, FS_FAT32 or FS_EXFAT) */
    -    BYTE    pdrv;         /* Hosting physical drive of this volume */
    +    BYTE    pdrv;         /* Physical drive that holds this volume */
    +    BYTE    ldrv;         /* Logical drive number (used only when FF_FS_REENTRANT) */
         BYTE    n_fats;       /* Number of FAT copies (1,2) */
         BYTE    wflag;        /* win[] flag (b0:win[] is dirty) */
         BYTE    fsi_flag;     /* FSINFO flags (b7:Disabled, b0:Dirty) */
    @@ -27,36 +26,36 @@ 

    FATFS

    #if FF_MAX_SS != FF_MIN_SS WORD ssize; /* Sector size (512,1024,2048 or 4096) */ #endif -#if FF_FS_EXFAT - BYTE* dirbuf; /* Directory entry block scratchpad buffer */ -#endif -#if FF_FS_REENTRANT - FF_SYNC_t sobj; /* Identifier of sync object */ +#if FF_USE_LFN + WCHAR* lfnbuf; /* Pointer to LFN working buffer */ #endif #if !FF_FS_READONLY - DWORD last_clust; /* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */ - DWORD free_clust; /* FSINFO: Number of free clusters (0xFFFFFFFF if invalid) */ + DWORD last_clust; /* FSINFO: Last allocated cluster (invalid if >=n_fatent) */ + DWORD free_clust; /* FSINFO: Number of free clusters (invalid if >=fs->n_fatent-2) */ #endif #if FF_FS_RPATH DWORD cdir; /* Cluster number of current directory (0:root) */ -#if FF_FS_EXFAT - DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */ - DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */ - DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */ -#endif #endif DWORD n_fatent; /* Number of FAT entries (Number of clusters + 2) */ DWORD fsize; /* Sectors per FAT */ + LBA_t 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[] */ +#if FF_FS_EXFAT + LBA_t bitbase; /* Allocation bitmap base sector */ + BYTE* dirbuf; /* Directory entry block scratchpad buffer */ +#if FF_FS_RPATH + FFXCWDS xcwds; /* Current working directory structure */ + FFXCWDS xcwds2; /* Working buffer to follow the path */ +#endif +#endif BYTE win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data at tiny cfg) */ } FATFS;
    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfile.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfile.html index 9234d32994..7216deba77 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfile.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfile.html @@ -3,8 +3,6 @@ - - FatFs - FIL @@ -17,18 +15,18 @@

    FIL

     typedef struct {
    -    FFOBJID obj;          /* Object identifier */
    -    BYTE    flag;         /* File object status flags */
    +    FFOBJID obj;          /* Object identifier */
    +    BYTE    flag;         /* File status flags */
         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.) */
    -    LBA_t   sect;         /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/
    +    FSIZE_t fptr;         /* File read/write pointer (byte offset origin from top of the file; 0 on open) */
    +    DWORD   clust;        /* Current cluster of fptr (one cluster behind if fptr is on the cluster boundary; invalid if fptr == 0) */
    +    LBA_t   sect;         /* Current data sector (can be invalid if fptr is on the cluster boundary)*/
     #if !FF_FS_READONLY
         LBA_t   dir_sect;     /* Sector number containing the directory entry */
    -    BYTE*   dir_ptr;      /* Ponter to the directory entry in the window */
    +    BYTE*   dir_ptr;      /* Pointer to the directory entry in the window */
     #endif
     #if FF_USE_FASTSEEK
    -    DWORD*  cltbl;        /* Pointer to the cluster link map table (Nulled on file open. Set by application.) */
    +    DWORD*  cltbl;        /* Pointer to the cluster link map table (nulled on file open; set by application) */
     #endif
     #if !FF_FS_TINY
         BYTE    buf[FF_MAX_SS]; /* File private data transfer buffer (Always valid if fptr is not on the sector boundary but can be invalid if fptr is on the sector boundary.) */
    @@ -38,6 +36,7 @@ 

    FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfileinfo.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfileinfo.html index db0f45e3b1..4b855e7f4c 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfileinfo.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sfileinfo.html @@ -3,8 +3,6 @@ - - FatFs - FILINFO @@ -16,10 +14,14 @@

    FILINFO

    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 */
    -    WORD    fdate;               /* Last modified date */
    -    WORD    ftime;               /* Last modified time */
    -    BYTE    fattrib;             /* Attribute */
    +    FSIZE_t fsize;               /* File size (invalid for directory) */
    +    WORD    fdate;               /* Date of file modification or directory creation */
    +    WORD    ftime;               /* Time of file modification or directory creation */
    +#if FF_FS_CRTIME
    +    WORD    crdate;              /* Date of object createion */
    +    WORD    crtime;              /* Time of object createion */
    +#endif
    +    BYTE    fattrib;             /* Object attribute */
     #if FF_USE_LFN
         TCHAR   altname[FF_SFN_BUF + 1]; /* Alternative object name */
         TCHAR   fname[FF_LFN_BUF + 1];   /* Primary object name */
    @@ -56,6 +58,12 @@ 

    Members

    Second / 2 (0..29)
    +
    crdate
    +
    The date when the file/directory was created. This member is available when FF_FS_CRTIME = 1. +
    +
    crtime
    +
    The time when the file/directory was created. This member is available when FF_FS_CRTIME = 1 +
    fattrib
    The attribute flags in combination of:
    @@ -68,11 +76,12 @@

    Members

    fname[]
    -
    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.
    +
    Null-terminated object name is stored. If no item to read or an error occured in the function, a null string is stored to indicate 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 in non-LFN configuration.
    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/size.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/size.html index 0be1a768f6..4d36a7497a 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/size.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/size.html @@ -3,8 +3,6 @@ - - FatFs - f_size @@ -57,6 +55,7 @@

    See Also

    f_open, f_lseek, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sobjid.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sobjid.html new file mode 100644 index 0000000000..911839202c --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sobjid.html @@ -0,0 +1,42 @@ + + + + + + +FatFs - FFOBJID + + + + +
    +

    FFOBJID

    +

    The FFOBJID structure is an object identifier that holds the common status of open objects. This structure is for only internal use and it does not appear on the API.

    + +
    +typedef struct {
    +    FATFS*  fs;         /* Pointer to the volume holds this object */
    +    WORD    id;         /* Volume mount ID when this object was opened */
    +    BYTE    attr;       /* Object attribute */
    +    BYTE    stat;       /* Object chain status (exFAT: b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
    +    DWORD   sclust;     /* Object data cluster (0:no data or root directory) */
    +    FSIZE_t objsize;    /* Object size (valid when sclust != 0) */
    +#if FF_FS_EXFAT
    +    DWORD   n_cont;     /* Size of first fragment - 1 (valid when stat == 3) */
    +    DWORD   n_frag;     /* Size of last fragment needs to be written to FAT (valid when not zero) */
    +    DWORD   c_scl;      /* Cluster of directory holds this object (valid when sclust != 0) */
    +    DWORD   c_size;     /* Size of directory holds this object (b7-b0: allocation status, valid when c_scl != 0) */
    +    DWORD   c_ofs;      /* Offset of entry of this object in the directory */
    +#endif
    +#if FF_FS_LOCK
    +    UINT    lockid;     /* File lock ID origin from 1 (index of file semaphore table Files[]) */
    +#endif
    +} FFOBJID;
    +
    + +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/stat.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/stat.html index 2c2680a2cb..44a505a969 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/stat.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/stat.html @@ -3,8 +3,6 @@ - - FatFs - f_stat @@ -26,7 +24,7 @@

    f_stat

    Parameters

    path
    -
    Pointer to the null-terminated string that specifies the object to get its information. The object must not be the root direcotry.
    +
    Pointer to the null-terminated string that specifies the object to get its information. Any non-object name (root direcotry and dot) is not allowed. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    fno
    Pointer to the blank FILINFO structure to store the information of the object. Set null pointer if this information is not needed.
    @@ -54,7 +52,8 @@

    Return Values

    Description

    -

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

    +

    The f_stat function checks the existence of a file or sub-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 synced or closed in order to obtain the latest file information. This function cannot be used to retrieve the long file name with the short file name.

    @@ -69,16 +68,17 @@

    Example

         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 +90,8 @@ 

    Example

    break; case FR_NO_FILE: - printf("It is not exist.\n"); + case FR_NO_PATH: + printf("\"%s\" is not exist.\n", fname); break; default: @@ -101,10 +102,11 @@

    Example

    -

    References

    +

    See Also

    f_opendir, f_readdir, FILINFO

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sxcwds.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sxcwds.html new file mode 100644 index 0000000000..33184da8cc --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sxcwds.html @@ -0,0 +1,31 @@ + + + + + + +FatFs - FFXCWDS + + + + +
    +

    FFXCWDS

    +

    The FFXCWDS structure holds a current working directory path. It is defined and used only when FF_FS_EXFAT == 1 && FF_FS_RPATH != 0. This structure is for only internal use and it does not appear on the API.

    +
    +typedef struct {
    +    DWORD   d_scl;        /* Directory start cluster (0:root dir) */
    +    DWORD   d_size;       /* Size of directory (b7-b0: cluster chain status) (invalid if d_scl == 0) */
    +    DWORD   nxt_ofs;      /* Offset of entry of next dir in this directory (invalid if last link) */
    +} FFXCWDL;
    +
    +typedef struct {
    +    UINT    depth;        /* Current directory depth (0:root dir) */
    +    FFXCWDL tbl[FF_PATH_DEPTH + 1]; /* Directory chain of current directory path */
    +} FFXCWDS;
    +
    +
    + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sync.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sync.html index 9fb42a0907..cfba282360 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/sync.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/sync.html @@ -3,8 +3,6 @@ - - FatFs - f_sync @@ -68,7 +66,7 @@

    Description

    w - f_write() S - f_sync()
    -

    However there is no sense in f_sync function immediataly before f_close function because it performs f_sync function in it. In other words, the differnce between those functions is that the file object is invalidated or not.

    +

    However there is no sense in f_sync function jsut before f_close function, because the f_close performs f_sync in it. Actually, the differnce between these functions is that the file object is invalidated or not.

    @@ -83,6 +81,7 @@

    See Also

    f_close, Critical section

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/tell.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/tell.html index 075f033fe3..c82958dfe0 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/tell.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/tell.html @@ -3,8 +3,6 @@ - - FatFs - f_tell @@ -57,6 +55,7 @@

    See Also

    f_open, f_lseek, FIL

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/truncate.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/truncate.html index 0ac012f039..7b8aa294ac 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/truncate.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/truncate.html @@ -3,8 +3,6 @@ - - FatFs - f_truncate @@ -25,7 +23,7 @@

    f_truncate

    Parameter

    fp
    -
    Pointer to the open file object to be truncated.
    +
    Pointer to the open file object to be truncated. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    @@ -61,6 +59,6 @@

    See Also

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/uni2oem.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/uni2oem.html new file mode 100644 index 0000000000..49d5b1c5d1 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/uni2oem.html @@ -0,0 +1,47 @@ + + + + + + +FatFs - ff_uni2oem + + + + +
    +

    ff_uni2oem

    +

    The ff_uni2oem function converts a Unicode character into OEM character.

    +
    +WCHAR ff_uni2oem (
    +  DWORD uni,           /* [IN] Unicode character */
    +  WORD cp              /* [IN] Code page */
    +);
    +
    +
    + +
    +

    Parameters

    +
    +
    uni
    +
    A Unicode character in UTF-16 encoding to be converted into OEM code. For the characters out of BMP, high-word is high-surrogate and low word is low-surrogate.
    +
    cp
    +
    Code page of output character. If FF_CODE_PAGE specifies a code page, only this code page can be specified. If it specifies all code page, any supported code page can be specified.
    +
    +
    + + +
    +

    Return Value

    +

    The function returns an OEM character converted from input Unicode character. If the Unicode character has no mapping to the OEM character in specified code page, a null character is returned.

    +
    + +
    +

    QuickInfo

    +

    This function is provided in ffunicode.c and required when FF_USE_LFN != 0. It is intended to be used by FatFs but also application program may use this function.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/unlink.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/unlink.html index 7809648ccd..e7baf05fff 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/unlink.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/unlink.html @@ -3,8 +3,6 @@ - - FatFs - f_unlink @@ -25,7 +23,7 @@

    f_unlink

    Parameter

    path
    -
    Pointer to a null-terminated string that specifies the file or sub-directory to be removed.
    +
    Pointer to a null-terminated string that specifies the file or sub-directory to be removed. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    @@ -69,6 +67,6 @@

    QuickInfo

    -

    Return

    +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/utime.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/utime.html index 40e39eb8db..1bde1c449b 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/utime.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/utime.html @@ -3,8 +3,6 @@ - - FatFs - f_utime @@ -17,7 +15,7 @@

    f_utime

     FRESULT f_utime (
       const TCHAR* path,  /* [IN] Object name */
    -  const FILINFO* fno  /* [IN] Time and data to be set */
    +  const FILINFO* fno  /* [IN] Time and date to be set */
     );
     
    @@ -26,9 +24,9 @@

    f_utime

    Parameters

    path
    -
    Pointer to the null-terminated string that specifies an object to be changed.
    +
    Pointer to the null-terminated string that specifies an object to be changed. If a null pointer is given, the function fails with FR_INVALID_DRIVE.
    fno
    -
    Pointer to the file information structure that has a timestamp to be set in member fdate and ftime. Do not care any other members.
    +
    Pointer to the file information structure that has new timestamps to be set in the members. fdate and ftime are for the last modified time. When FF_FS_CRTIME = 1, crdate and crtime for the created time are available in addition. Every timestamp is in local time. If fdate or crdate is invalid (0), the modified time or created time is left unchanged respectively. Do not care any other member.
    @@ -63,7 +61,7 @@

    Description

    Example

     FRESULT set_timestamp (
    -    char *obj,     /* Pointer to the file name */
    +    const char *fname,     /* Pointer to the file name */
         int year,
         int month,
         int mday,
    @@ -76,8 +74,10 @@ 

    Example

    fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday); fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U); - - return f_utime(obj, &fno); +#if FF_FS_CRTIME + fno.crdate = 0; /* Do not change created time in this code */ +#endif + return f_utime(fname, &fno); }
    @@ -94,6 +94,7 @@

    See Also

    f_stat, FILINFO

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/write.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/write.html index 25fe2904d4..c3b0dd87c6 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/doc/write.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/write.html @@ -3,8 +3,6 @@ - - FatFs - f_write @@ -28,13 +26,13 @@

    f_write

    Parameters

    fp
    -
    Pointer to the open file object structure.
    +
    Pointer to the open file object structure. If a null pointer is given, the function fails with FR_INVALID_OBJECT.
    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. If the return value is equal to btw, the function return code should be FR_OK.
    +
    Pointer to the variable in UINT type 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 +52,7 @@

    Return Values

    Description

    -

    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.

    +

    The function starts to write data to the file at the file offset pointed by read/write pointer of the file object. 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.

    @@ -75,6 +73,7 @@

    See Also

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

    -

    Return

    + +

    Return

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/doc/wtoupper.html b/src/rust/fatfs-sys/depend/fatfs/documents/doc/wtoupper.html new file mode 100644 index 0000000000..283e10f570 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/doc/wtoupper.html @@ -0,0 +1,52 @@ + + + + + + +FatFs - ff_wtoupper + + + + +
    +

    ff_wtoupper

    +

    The ff_wtoupper function is a Unicode version of toupper function.

    +
    +DWORD ff_wtoupper (
    +  DWORD uni           /* [IN] Unicode character */
    +);
    +
    +
    + +
    +

    Parameter

    +
    +
    uni
    +
    A Unicode character in UTF-16 encoding for up-case conversion. For the characters out of BMP, high-word is high-surrogate and low word is low-surrogate.
    +
    +
    + + +
    +

    Return Value

    +

    Up-case converted Unicode character in UTF-16 encoding.

    +
    + + +
    +

    Description

    +

    Input low-case character or middle-case character is converted into up-case character. If not the case, input character is returned.

    +

    +
    + + +
    +

    QuickInfo

    +

    This function is provided in ffunicode.c and required when FF_USE_LFN != 0. It is intended to be used by FatFs but also application program may use this function.

    +
    + + +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/00index_e.html b/src/rust/fatfs-sys/depend/fatfs/documents/index.html similarity index 66% rename from src/rust/fatfs-sys/depend/fatfs/documents/00index_e.html rename to src/rust/fatfs-sys/depend/fatfs/documents/index.html index 0c20aa7d0f..62271b8dec 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/00index_e.html +++ b/src/rust/fatfs-sys/depend/fatfs/documents/index.html @@ -4,7 +4,6 @@ - FatFs - Generic FAT Filesystem Module @@ -15,22 +14,22 @@

    FatFs - Generic FAT Filesystem Module

    layer -

    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.

    +

    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 control layer. Therefore it is independent of the platforms and storage devices. 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.

    Features

    @@ -103,7 +102,7 @@

    Application Interface

    Media Access Interface

    layer -

    Since FatFs module is the Filesystem Layer independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The storage device control module is not any part of FatFs module and it needs to be provided by implementer. FatFs controls the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for storage device control module is available here.

    +

    Since FatFs module is the Filesystem Layer independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The storage device control module is not a part of FatFs module and it needs to be provided by implementer. FatFs controls the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for storage device control module is available here.

    + +
    +

    Home Page

    diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/res/app5.c b/src/rust/fatfs-sys/depend/fatfs/documents/res/app5.c index 9190dad7e7..2739019832 100644 --- a/src/rust/fatfs-sys/depend/fatfs/documents/res/app5.c +++ b/src/rust/fatfs-sys/depend/fatfs/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 diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/res/uniconv.zip b/src/rust/fatfs-sys/depend/fatfs/documents/res/uniconv.zip new file mode 100644 index 0000000000..be7d84f3f2 Binary files /dev/null and b/src/rust/fatfs-sys/depend/fatfs/documents/res/uniconv.zip differ diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/updates.html b/src/rust/fatfs-sys/depend/fatfs/documents/updates.html new file mode 100644 index 0000000000..e75c87bbd0 --- /dev/null +++ b/src/rust/fatfs-sys/depend/fatfs/documents/updates.html @@ -0,0 +1,687 @@ + + + + + + + +FatFs - Updates and Migration Notes + + +

    Updates and Migration Notes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    RevisionUpdatesMigration Notes
    R0.16
    Jul 22, 2025
    +
      +
    • Removed a long-pending limitation that f_getcwd and double-dot ".." in the path name did not work on the exFAT volume.
    • +
    • Fixed f_readdir cannot detect end of directory and it leads the application process into infinite loop. (appeared at R0.15b)
    • +
    • Fixed dot names with terminating separator or duplicated separator are rejected when LFN is not enabled.
    • +
    +
    +
      +
    • Maximum depth of sub-directory on the exFAT volume is limited to the configured level FF_PATH_DEPTH when relative path is enabled.
    • +
    +
    R0.15b
    Jun 21, 2025
    +
      +
    • Added support for the timestamp of created time. (FF_FS_CRTIME)
    • +
    • Fixed FatFs fails to load the FsInfo in FAT32 volumes and the f_getfree always be forced a full FAT scan which takes a long time. (appeared at R0.15a)
    • +
    +
      +
    • Small changes to the f_utime function to support for the timestamp of created time.
    • +
    R0.15a
    Nov 22, 2024
    +
      +
    • Fixed a complie error when FF_FS_LOCK != 0. (appeared at R0.15)
    • +
    • Fixed a potential issue when work FatFs concurrency with FF_FS_REENTRANT, FF_VOLUMES >= 2 and FF_FS_LOCK > 0.
    • +
    • Made f_setlabel accept a volume label with Unix style volume ID when FF_STR_VOLUME_ID == 2.
    • +
    • Made FatFs update PercInUse field in exFAT VBR. (A preceding f_getfree is needed for the accuracy)
    • +
    +
    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 with ff_mutex_create, ff_mutex_delete, ff_mutex_take and ff_mutex_give respectively. For example, 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.
    • +
    • Dot entries in the sub-directory are never appear in f_readdir.
    • +
    • ".." does not work as path name in exFAT volume.
    • +
    • f_getcwd does not work in exFAT volume.
    • +
    • 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.
    • +
    +
    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.
    • +
    +
    + +
    +

    Return

    + + diff --git a/src/rust/fatfs-sys/depend/fatfs/documents/updates.txt b/src/rust/fatfs-sys/depend/fatfs/documents/updates.txt deleted file mode 100644 index 60b6e1a2b2..0000000000 --- a/src/rust/fatfs-sys/depend/fatfs/documents/updates.txt +++ /dev/null @@ -1,286 +0,0 @@ -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.14a (December 05, 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.14 (October 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() function cannot find the file with file name in length of FF_MAX_LFN characters. - Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters. - Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12) - Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12) - -R0.13c (October 14, 2018) - Supported stdint.h for C99 and later. (integer.h was included in ff.h) - Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12) - 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/src/rust/fatfs-sys/depend/fatfs/source/00history.txt b/src/rust/fatfs-sys/depend/fatfs/source/00history.txt index d3c910c197..8d410b2a64 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/00history.txt +++ b/src/rust/fatfs-sys/depend/fatfs/source/00history.txt @@ -357,3 +357,33 @@ R0.14b (April 17, 2021) 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. + + + +R0.15a (November 22, 2024) + Fixed a complie error when FF_FS_LOCK != 0. + Fixed a potential issue when work FatFs concurrency with FF_FS_REENTRANT, FF_VOLUMES >= 2 and FF_FS_LOCK > 0. + Made f_setlabel() accept a volume label in Unix style volume ID when FF_STR_VOLUME_ID == 2. + Made FatFs update PercInUse field in exFAT VBR. (A preceding f_getfree() is needed for the accuracy) + + + +R0.15b (June 21, 2025) + Added support for timestamp of created time. (FF_FS_CRTIME) + Fixed FatFs fails to load the FsInfo in FAT32 volumes and the f_getfree always be forced a full FAT scan which takes a long time. (appeared at R0.15a) + + + +R0.16 (July 22, 2025) + Removed a long-pending limitation that f_getcwd and double-dot .. in the path name did not work on the exFAT volume. + Fixed f_readdir cannot detect end of directory and it leads the application process into infinite loop. (appeared at R0.15b) + Fixed dot names with terminating separator or duplicated separator are rejected when LFN is not enabled. diff --git a/src/rust/fatfs-sys/depend/fatfs/source/00readme.txt b/src/rust/fatfs-sys/depend/fatfs/source/00readme.txt index 53e035f6fd..66414507e4 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/00readme.txt +++ b/src/rust/fatfs-sys/depend/fatfs/source/00readme.txt @@ -1,4 +1,4 @@ -FatFs Module Source Files R0.14b +FatFs Module Source Files R0.16 FILES diff --git a/src/rust/fatfs-sys/depend/fatfs/source/diskio.c b/src/rust/fatfs-sys/depend/fatfs/source/diskio.c index 81aaf59ad6..130148f036 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/diskio.c +++ b/src/rust/fatfs-sys/depend/fatfs/source/diskio.c @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------*/ -/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */ +/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2025 */ /*-----------------------------------------------------------------------*/ /* If a working storage control module is available, it should be */ /* attached to the FatFs via a glue function rather than modifying it. */ @@ -7,13 +7,17 @@ /* storage control modules to the FatFs module with a defined API. */ /*-----------------------------------------------------------------------*/ -#include "ff.h" /* Obtains integer types */ -#include "diskio.h" /* Declarations of disk functions */ +#include "ff.h" /* Basic definitions of FatFs */ +#include "diskio.h" /* Declarations FatFs MAI */ -/* Definitions of physical drive number for each drive */ -#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */ -#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */ -#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */ +/* Example: Declarations of the platform and disk functions in the project */ +#include "platform.h" +#include "storage.h" + +/* Example: Mapping of physical drive number for each drive */ +#define DEV_FLASH 0 /* Map FTL to physical drive 0 */ +#define DEV_MMC 1 /* Map MMC/SD card to physical drive 1 */ +#define DEV_USB 2 /* Map USB MSD to physical drive 2 */ /*-----------------------------------------------------------------------*/ diff --git a/src/rust/fatfs-sys/depend/fatfs/source/diskio.h b/src/rust/fatfs-sys/depend/fatfs/source/diskio.h index c22afaa5f4..c3cda9661e 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/diskio.h +++ b/src/rust/fatfs-sys/depend/fatfs/source/diskio.h @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------/ -/ Low level disk interface modlue include file (C)ChaN, 2019 / +/ Low level disk interface modlue include file (C)ChaN, 2025 / /-----------------------------------------------------------------------*/ #ifndef _DISKIO_DEFINED @@ -55,7 +55,7 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); #define CTRL_EJECT 7 /* Eject media */ #define CTRL_FORMAT 8 /* Create physical format on the media */ -/* MMC/SDC specific ioctl command */ +/* MMC/SDC specific ioctl command (Not used by FatFs) */ #define MMC_GET_TYPE 10 /* Get card type */ #define MMC_GET_CSD 11 /* Get CSD */ #define MMC_GET_CID 12 /* Get CID */ @@ -65,7 +65,7 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ -/* ATA/CF specific ioctl command */ +/* ATA/CF specific ioctl command (Not used by FatFs) */ #define ATA_GET_REV 20 /* Get F/W revision */ #define ATA_GET_MODEL 21 /* Get model name */ #define ATA_GET_SN 22 /* Get serial number */ diff --git a/src/rust/fatfs-sys/depend/fatfs/source/ff.c b/src/rust/fatfs-sys/depend/fatfs/source/ff.c index 66c4dfb0d8..d7926a80f5 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/ff.c +++ b/src/rust/fatfs-sys/depend/fatfs/source/ff.c @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem Module R0.14b / +/ FatFs - Generic FAT Filesystem Module R0.16 w/patch 1 / /-----------------------------------------------------------------------------/ / -/ Copyright (C) 2021, ChaN, all right reserved. +/ Copyright (C) 2025, 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,9 +20,8 @@ #include -#include "ff.h" /* Declarations of FatFs API */ -#include "diskio.h" /* Declarations of device I/O functions */ - +#include "ff.h" /* Basic definitions and declarations of API */ +#include "diskio.h" /* Declarations of MAI */ /*-------------------------------------------------------------------------- @@ -30,18 +29,20 @@ ---------------------------------------------------------------------------*/ -#if FF_DEFINED != 86631 /* Revision ID */ +#if FF_DEFINED != 80386 /* Revision ID */ #error Wrong include file (ff.h). #endif /* Limits and boundaries */ -#define MAX_DIR 0x200000 /* Max size of FAT directory */ -#define MAX_DIR_EX 0x10000000 /* Max size of exFAT directory */ +#define MAX_DIR 0x200000 /* Max size of FAT directory (byte) */ +#define MAX_DIR_EX 0x10000000 /* Max size of exFAT directory (byte) */ #define MAX_FAT12 0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */ #define MAX_FAT16 0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */ -#define MAX_FAT32 0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */ +#define MAX_FAT32 0x0FFFFFF5 /* Max FAT32 clusters (not defined in specs, practical limit) */ #define MAX_EXFAT 0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */ +#define MIN_FAT12 32 /* Min FAT12 clusters (Not defined in specs, implementation limit) */ +#define MIN_VOLUME 64 /* Min volume sectors (Not defined in specs, implementation limit) */ /* Character code support macros */ @@ -89,7 +90,7 @@ #define ET_FILENAME 0xC1 /* Name extension */ -/* FatFs refers the FAT structure as simple byte array instead of structure member +/* FatFs refers the FAT structures as simple byte array instead of structure member / because the C structure is not binary compatible between different platforms */ #define BS_JmpBoot 0 /* x86 jump instruction (3-byte) */ @@ -113,7 +114,7 @@ #define BS_VolLab 43 /* Volume label string (8-byte) */ #define BS_FilSysType 54 /* Filesystem type string (8-byte) */ #define BS_BootCode 62 /* Boot code (448-byte) */ -#define BS_55AA 510 /* Signature word (WORD) */ +#define BS_55AA 510 /* Boot signature (WORD, for VBR and MBR) */ #define BPB_FATSz32 36 /* FAT32: FAT size [sector] (DWORD) */ #define BPB_ExtFlags32 40 /* FAT32: Extended flags (WORD) */ @@ -139,18 +140,18 @@ #define BPB_RootClusEx 96 /* exFAT: Root directory start cluster (DWORD) */ #define BPB_VolIDEx 100 /* exFAT: Volume serial number (DWORD) */ #define BPB_FSVerEx 104 /* exFAT: Filesystem version (WORD) */ -#define BPB_VolFlagEx 106 /* exFAT: Volume flags (WORD) */ +#define BPB_VolFlagEx 106 /* exFAT: Volume flags (WORD, out of check sum calculation) */ #define BPB_BytsPerSecEx 108 /* exFAT: Log2 of sector size in unit of byte (BYTE) */ #define BPB_SecPerClusEx 109 /* exFAT: Log2 of cluster size in unit of sector (BYTE) */ #define BPB_NumFATsEx 110 /* exFAT: Number of FATs (BYTE) */ #define BPB_DrvNumEx 111 /* exFAT: Physical drive number for int13h (BYTE) */ -#define BPB_PercInUseEx 112 /* exFAT: Percent in use (BYTE) */ +#define BPB_PercInUseEx 112 /* exFAT: Percent in use (BYTE, out of check sum calculation) */ #define BPB_RsvdEx 113 /* exFAT: Reserved (7-byte) */ #define BS_BootCodeEx 120 /* exFAT: Boot code (390-byte) */ #define DIR_Name 0 /* Short file name (11-byte) */ #define DIR_Attr 11 /* Attribute (BYTE) */ -#define DIR_NTres 12 /* Lower case flag (BYTE) */ +#define DIR_NTres 12 /* Low case flags of SFN (BYTE) */ #define DIR_CrtTime10 13 /* Created time sub-second (BYTE) */ #define DIR_CrtTime 14 /* Created time (DWORD) */ #define DIR_LstAccDate 18 /* Last accessed date (WORD) */ @@ -194,40 +195,41 @@ #define FSI_StrucSig 484 /* FAT32 FSI: Structure signature (DWORD) */ #define FSI_Free_Count 488 /* FAT32 FSI: Number of free clusters (DWORD) */ #define FSI_Nxt_Free 492 /* FAT32 FSI: Last allocated cluster (DWORD) */ +#define FSI_TrailSig 508 /* FAT32 FSI: Trailing signature (DWORD) */ #define MBR_Table 446 /* MBR: Offset of partition table in the MBR */ #define SZ_PTE 16 /* MBR: Size of a partition table entry */ #define PTE_Boot 0 /* MBR PTE: Boot indicator */ -#define PTE_StHead 1 /* MBR PTE: Start head */ -#define PTE_StSec 2 /* MBR PTE: Start sector */ -#define PTE_StCyl 3 /* MBR PTE: Start cylinder */ +#define PTE_StHead 1 /* MBR PTE: Start head in CHS */ +#define PTE_StSec 2 /* MBR PTE: Start sector in CHS */ +#define PTE_StCyl 3 /* MBR PTE: Start cylinder in CHS */ #define PTE_System 4 /* MBR PTE: System ID */ -#define PTE_EdHead 5 /* MBR PTE: End head */ -#define PTE_EdSec 6 /* MBR PTE: End sector */ -#define PTE_EdCyl 7 /* MBR PTE: End cylinder */ +#define PTE_EdHead 5 /* MBR PTE: End head in CHS */ +#define PTE_EdSec 6 /* MBR PTE: End sector in CHS */ +#define PTE_EdCyl 7 /* MBR PTE: End cylinder in CHS */ #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 a GPT 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 */ @@ -239,16 +241,16 @@ #if FF_USE_LFN == 1 #error Static LFN work area cannot be used in thread-safe configuration #endif -#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } +#define LEAVE_FF(fs, res) { unlock_volume(fs, res); return res; } #else #define LEAVE_FF(fs, res) return res #endif -/* Definitions of logical drive - physical location conversion */ +/* Definitions of logical drive to physical location conversion */ #if FF_MULTI_PARTITION -#define LD2PD(vol) VolToPart[vol].pd /* Get physical drive number */ -#define LD2PT(vol) VolToPart[vol].pt /* Get partition number (0:auto search, 1..:forced partition number) */ +#define LD2PD(vol) VolToPart[vol].pd /* Get physical drive number from the mapping table */ +#define LD2PT(vol) VolToPart[vol].pt /* Get partition number from the mapping table (0:auto search, 1-:forced partition number) */ #else #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is associated with the same physical drive number */ #define LD2PT(vol) 0 /* Auto partition search */ @@ -278,15 +280,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) */ - 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 */ +typedef struct { /* Open object identifier with status */ + 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 */ + UINT ctr; /* Object open status, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */ } FILESEM; #endif @@ -461,20 +463,24 @@ typedef struct { #if FF_VOLUMES < 1 || FF_VOLUMES > 10 #error Wrong FF_VOLUMES setting #endif -static FATFS* FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */ +static FATFS *FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */ static WORD Fsid; /* Filesystem mount ID */ -#if FF_FS_RPATH != 0 -static BYTE CurrVol; /* Current drive */ +#if FF_FS_RPATH +static BYTE CurrVol; /* Current drive number set by f_chdrive() */ #endif -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */ +#if FF_FS_REENTRANT +static volatile BYTE SysLock; /* System lock flag to protect Files[] (0:no mutex, 1:unlocked, 2:locked) */ +static volatile BYTE SysLockVolume; /* Volume id who is locking Files[] */ +#endif #endif #if FF_STR_VOLUME_ID #ifdef FF_VOLUME_STRS -static const char* const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-defined volume ID */ +static const char *const VolumeStr[FF_VOLUMES] = {FF_VOLUME_STRS}; /* Pre-defined volume ID */ #endif #endif @@ -495,9 +501,9 @@ static const BYTE GUID_MS_Basic[16] = {0xA2,0xA0,0xD0,0xEB,0xE5,0xB9,0x33,0x44,0 #if FF_FS_EXFAT #error LFN must be enabled when enable exFAT #endif -#define DEF_NAMBUF -#define INIT_NAMBUF(fs) -#define FREE_NAMBUF() +#define DEF_NAMEBUFF +#define INIT_NAMEBUFF(fs) +#define FREE_NAMEBUFF() #define LEAVE_MKFS(res) return res #else /* LFN configurations */ @@ -518,32 +524,32 @@ static const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* FAT: Offset static BYTE DirBuf[MAXDIRB(FF_MAX_LFN)]; /* Directory entry block scratchpad buffer */ #endif static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */ -#define DEF_NAMBUF -#define INIT_NAMBUF(fs) -#define FREE_NAMBUF() +#define DEF_NAMEBUFF +#define INIT_NAMEBUFF(fs) +#define FREE_NAMEBUFF() #define LEAVE_MKFS(res) return res #elif FF_USE_LFN == 2 /* LFN enabled with dynamic working buffer on the stack */ #if FF_FS_EXFAT -#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; BYTE dbuf[MAXDIRB(FF_MAX_LFN)]; /* LFN working buffer and directory entry block scratchpad buffer */ -#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; (fs)->dirbuf = dbuf; } -#define FREE_NAMBUF() +#define DEF_NAMEBUFF WCHAR lbuf[FF_MAX_LFN+1]; BYTE dbuf[MAXDIRB(FF_MAX_LFN)]; /* LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMEBUFF(fs) { (fs)->lfnbuf = lbuf; (fs)->dirbuf = dbuf; } +#define FREE_NAMEBUFF() #else -#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; /* LFN working buffer */ -#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; } -#define FREE_NAMBUF() +#define DEF_NAMEBUFF WCHAR lbuf[FF_MAX_LFN+1]; /* LFN working buffer */ +#define INIT_NAMEBUFF(fs) { (fs)->lfnbuf = lbuf; } +#define FREE_NAMEBUFF() #endif #define LEAVE_MKFS(res) return res #elif FF_USE_LFN == 3 /* LFN enabled with dynamic working buffer on the heap */ #if FF_FS_EXFAT -#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer and directory entry block scratchpad buffer */ -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); } -#define FREE_NAMBUF() ff_memfree(lfn) +#define DEF_NAMEBUFF WCHAR *lfn; /* Pointer to LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMEBUFF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); } +#define FREE_NAMEBUFF() ff_memfree(lfn) #else -#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer */ -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } -#define FREE_NAMBUF() ff_memfree(lfn) +#define DEF_NAMEBUFF WCHAR *lfn; /* Pointer to LFN working buffer */ +#define INIT_NAMEBUFF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } +#define FREE_NAMEBUFF() ff_memfree(lfn) #endif #define LEAVE_MKFS(res) { if (!work) ff_memfree(buf); return res; } #define MAX_MALLOC 0x8000 /* Must be >=FF_MAX_SS */ @@ -563,7 +569,8 @@ static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */ #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; /* Pointer to SBCS up-case table Ct???[] (null:disabled) */ +static const BYTE* DbcTbl; /* Pointer to DBCS code range table Dc???[] (null:disabled) */ static const BYTE Ct437[] = TBL_CT437; static const BYTE Ct720[] = TBL_CT720; @@ -611,7 +618,7 @@ static const BYTE DbcTbl[] = MKCVTBL(TBL_DC, FF_CODE_PAGE); /* Load/Store multi-byte word in the FAT structure */ /*-----------------------------------------------------------------------*/ -static WORD ld_word (const BYTE* ptr) /* Load a 2-byte little-endian word */ +static WORD ld_16 (const BYTE* ptr) /* Load a 2-byte little-endian word */ { WORD rv; @@ -620,7 +627,7 @@ static WORD ld_word (const BYTE* ptr) /* Load a 2-byte little-endian word */ return rv; } -static DWORD ld_dword (const BYTE* ptr) /* Load a 4-byte little-endian word */ +static DWORD ld_32 (const BYTE* ptr) /* Load a 4-byte little-endian word */ { DWORD rv; @@ -632,7 +639,7 @@ static DWORD ld_dword (const BYTE* ptr) /* Load a 4-byte little-endian word */ } #if FF_FS_EXFAT -static QWORD ld_qword (const BYTE* ptr) /* Load an 8-byte little-endian word */ +static QWORD ld_64 (const BYTE* ptr) /* Load an 8-byte little-endian word */ { QWORD rv; @@ -649,13 +656,13 @@ static QWORD ld_qword (const BYTE* ptr) /* Load an 8-byte little-endian word */ #endif #if !FF_FS_READONLY -static void st_word (BYTE* ptr, WORD val) /* Store a 2-byte word in little-endian */ +static void st_16 (BYTE* ptr, WORD val) /* Store a 2-byte word in little-endian */ { *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; } -static void st_dword (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-endian */ +static void st_32 (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-endian */ { *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; @@ -664,7 +671,7 @@ static void st_dword (BYTE* ptr, DWORD val) /* Store a 4-byte word in little-end } #if FF_FS_EXFAT -static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-endian */ +static void st_64 (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-endian */ { *ptr++ = (BYTE)val; val >>= 8; *ptr++ = (BYTE)val; val >>= 8; @@ -739,7 +746,7 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on #if FF_LFN_UNICODE == 1 /* UTF-16 input */ WCHAR wc; - uc = *p++; /* Get a unit */ + uc = *p++; /* Get an encoding unit */ if (IsSurrogate(uc)) { /* Surrogate? */ wc = *p++; /* Get low surrogate */ if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF; /* Wrong surrogate? */ @@ -747,7 +754,7 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on } #elif FF_LFN_UNICODE == 2 /* UTF-8 input */ - BYTE b; + BYTE tb; int nf; uc = (BYTE)*p++; /* Get an encoding unit */ @@ -761,10 +768,10 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on } else { /* Wrong sequence */ return 0xFFFFFFFF; } - do { /* Get trailing bytes */ - b = (BYTE)*p++; - if ((b & 0xC0) != 0x80) return 0xFFFFFFFF; /* Wrong sequence? */ - uc = uc << 6 | (b & 0x3F); + do { /* Get and merge trailing bytes */ + tb = (BYTE)*p++; + if ((tb & 0xC0) != 0x80) return 0xFFFFFFFF; /* Wrong sequence? */ + uc = uc << 6 | (tb & 0x3F); } while (--nf != 0); if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF; /* Wrong code? */ if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */ @@ -776,14 +783,14 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */ #else /* ANSI/OEM input */ - BYTE b; + BYTE sb; WCHAR wc; wc = (BYTE)*p++; /* Get a byte */ if (dbc_1st((BYTE)wc)) { /* Is it a DBC 1st byte? */ - b = (BYTE)*p++; /* Get 2nd byte */ - if (!dbc_2nd(b)) return 0xFFFFFFFF; /* Invalid code? */ - wc = (wc << 8) + b; /* Make a DBC */ + sb = (BYTE)*p++; /* Get 2nd byte */ + if (!dbc_2nd(sb)) return 0xFFFFFFFF; /* Invalid code? */ + wc = (wc << 8) + sb; /* Make a DBC */ } if (wc != 0) { wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM ==> Unicode */ @@ -875,7 +882,7 @@ static UINT put_utf ( /* Returns number of encoding units written (0:buffer over *buf++ = (TCHAR)wc; /* Store DBC 2nd byte */ return 2; } - if (wc == 0 || szb < 1) return 0; /* Invalid char or buffer overflow? */ + if (wc == 0 || szb < 1) return 0; /* Invalid character or buffer overflow? */ *buf++ = (TCHAR)wc; /* Store the character */ return 1; #endif @@ -887,21 +894,46 @@ static UINT put_utf ( /* Returns number of encoding units written (0:buffer over /*-----------------------------------------------------------------------*/ /* Request/Release grant to access the volume */ /*-----------------------------------------------------------------------*/ -static int lock_fs ( /* 1:Ok, 0:timeout */ - FATFS* fs /* Filesystem object */ + +static int lock_volume ( /* 1:Ok, 0:timeout */ + FATFS* fs, /* Filesystem object to lock */ + int syslock /* System lock required */ ) { - return ff_req_grant(fs->sobj); + int rv; + + +#if FF_FS_LOCK + rv = ff_mutex_take(fs->ldrv); /* Lock the volume */ + if (rv && syslock) { /* System lock reqiered? */ + rv = ff_mutex_take(FF_VOLUMES); /* Lock the system */ + if (rv) { + SysLockVolume = fs->ldrv; + SysLock = 2; /* System lock succeeded */ + } else { + ff_mutex_give(fs->ldrv); /* Failed system lock */ + } + } +#else + rv = syslock ? ff_mutex_take(fs->ldrv) : ff_mutex_take(fs->ldrv); /* Lock the volume (this is to prevent compiler warning) */ +#endif + return rv; } -static void unlock_fs ( +static void unlock_volume ( FATFS* fs, /* Filesystem object */ FRESULT res /* Result code to be returned */ ) { if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) { - ff_rel_grant(fs->sobj); +#if FF_FS_LOCK + if (SysLock == 2 && SysLockVolume == fs->ldrv) { /* Unlock system if it has been locked by this task */ + SysLock = 1; + ff_mutex_give(FF_VOLUMES); + } +#endif + ff_mutex_give(fs->ldrv); /* Unlock the volume */ } } @@ -909,12 +941,12 @@ static void unlock_fs ( -#if FF_FS_LOCK != 0 +#if FF_FS_LOCK /*-----------------------------------------------------------------------*/ -/* File lock control functions */ +/* File sharing 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) */ ) @@ -941,16 +973,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; } -static 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) */ ) @@ -965,7 +997,7 @@ static UINT inc_lock ( /* Increment object open counter and returns its index (0 } if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */ - 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 */ 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; @@ -981,30 +1013,32 @@ static UINT inc_lock ( /* Increment object open counter and returns its index (0 } -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 == 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; @@ -1014,7 +1048,7 @@ static void clear_lock ( /* Clear lock entries of the volume */ } } -#endif /* FF_FS_LOCK != 0 */ +#endif /* FF_FS_LOCK */ @@ -1084,17 +1118,30 @@ static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */ res = sync_window(fs); if (res == FR_OK) { - if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { /* FAT32: Update FSInfo sector if needed */ - /* Create FSInfo structure */ - memset(fs->win, 0, sizeof fs->win); - st_word(fs->win + BS_55AA, 0xAA55); /* Boot signature */ - st_dword(fs->win + FSI_LeadSig, 0x41615252); /* Leading signature */ - st_dword(fs->win + FSI_StrucSig, 0x61417272); /* Structure signature */ - st_dword(fs->win + FSI_Free_Count, fs->free_clst); /* Number of free clusters */ - st_dword(fs->win + FSI_Nxt_Free, fs->last_clst); /* Last allocated culuster */ - fs->winsect = fs->volbase + 1; /* Write it into the FSInfo sector (Next to VBR) */ - disk_write(fs->pdrv, fs->win, fs->winsect, 1); + if (fs->fsi_flag == 1) { /* Allocation changed? */ fs->fsi_flag = 0; + if (fs->fs_type == FS_FAT32) { /* FAT32: Update FSInfo sector */ + /* Create FSInfo structure */ + memset(fs->win, 0, sizeof fs->win); + st_32(fs->win + FSI_LeadSig, 0x41615252); /* Leading signature */ + st_32(fs->win + FSI_StrucSig, 0x61417272); /* Structure signature */ + st_32(fs->win + FSI_Free_Count, fs->free_clst); /* Number of free clusters */ + st_32(fs->win + FSI_Nxt_Free, fs->last_clst); /* Last allocated culuster */ + st_32(fs->win + FSI_TrailSig, 0xAA550000); /* Trailing signature */ + disk_write(fs->pdrv, fs->win, fs->winsect = fs->volbase + 1, 1); /* Write it into the FSInfo sector (Next to VBR) */ + } +#if FF_FS_EXFAT + else if (fs->fs_type == FS_EXFAT) { /* exFAT: Update PercInUse field in BPB */ + if (disk_read(fs->pdrv, fs->win, fs->winsect = fs->volbase, 1) == RES_OK) { /* Load VBR */ + BYTE perc_inuse = (fs->free_clst <= fs->n_fatent - 2) ? (BYTE)((QWORD)(fs->n_fatent - 2 - fs->free_clst) * 100 / (fs->n_fatent - 2)) : 0xFF; /* Precent in use 0-100 or 0xFF(unknown) */ + + if (fs->win[BPB_PercInUseEx] != perc_inuse) { /* Write it back into VBR if needed */ + fs->win[BPB_PercInUseEx] = perc_inuse; + disk_write(fs->pdrv, fs->win, fs->winsect, 1); + } + } + } +#endif } /* Make sure that no pending write process in the lower layer */ if (disk_ioctl(fs->pdrv, CTRL_SYNC, 0) != RES_OK) res = FR_DISK_ERR; @@ -1156,12 +1203,12 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF case FS_FAT16 : if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break; - val = ld_word(fs->win + clst * 2 % SS(fs)); /* Simple WORD array */ + val = ld_16(fs->win + clst * 2 % SS(fs)); /* Simple WORD array */ break; case FS_FAT32 : if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break; - val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x0FFFFFFF; /* Simple DWORD array but mask out upper 4 bits */ + val = ld_32(fs->win + clst * 4 % SS(fs)) & 0x0FFFFFFF; /* Simple DWORD array but mask out upper 4 bits */ break; #if FF_FS_EXFAT case FS_EXFAT : @@ -1182,7 +1229,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF val = 0x7FFFFFFF; /* Generate EOC */ } else { if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break; - val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x7FFFFFFF; + val = ld_32(fs->win + clst * 4 % SS(fs)) & 0x7FFFFFFF; } break; } @@ -1236,7 +1283,7 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ case FS_FAT16: res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))); if (res != FR_OK) break; - st_word(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */ + st_16(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */ fs->wflag = 1; break; @@ -1247,9 +1294,9 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))); if (res != FR_OK) break; if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { - val = (val & 0x0FFFFFFF) | (ld_dword(fs->win + clst * 4 % SS(fs)) & 0xF0000000); + val = (val & 0x0FFFFFFF) | (ld_32(fs->win + clst * 4 % SS(fs)) & 0xF0000000); } - st_dword(fs->win + clst * 4 % SS(fs), val); + st_32(fs->win + clst * 4 % SS(fs), val); fs->wflag = 1; break; } @@ -1430,7 +1477,7 @@ static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ res = put_fat(fs, clst, 0); /* Mark the cluster 'free' on the FAT */ if (res != FR_OK) return res; } - if (fs->free_clst < fs->n_fatent - 2) { /* Update FSINFO */ + if (fs->free_clst < fs->n_fatent - 2) { /* Update allocation information if it is valid */ fs->free_clst++; fs->fsi_flag |= 1; } @@ -1453,7 +1500,7 @@ static FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ } #endif clst = nxt; /* Next cluster */ - } while (clst < fs->n_fatent); /* Repeat while not the last link */ + } while (clst < fs->n_fatent); /* Repeat until the last link */ #if FF_FS_EXFAT /* Some post processes for chain status */ @@ -1573,10 +1620,12 @@ static DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:D } } - if (res == FR_OK) { /* Update FSINFO if function succeeded. */ + if (res == FR_OK) { /* Update allocation information if the function succeeded */ fs->last_clst = ncl; - if (fs->free_clst <= fs->n_fatent - 2) fs->free_clst--; - fs->fsi_flag |= 1; + if (fs->free_clst > 0 && fs->free_clst <= fs->n_fatent - 2) { + fs->free_clst--; + fs->fsi_flag |= 1; + } } else { ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1; /* Failed. Generate error status */ } @@ -1599,7 +1648,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; @@ -1821,9 +1871,9 @@ static DWORD ld_clust ( /* Returns the top cluster value of the SFN entry */ { DWORD cl; - cl = ld_word(dir + DIR_FstClusLO); + cl = ld_16(dir + DIR_FstClusLO); if (fs->fs_type == FS_FAT32) { - cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16; + cl |= (DWORD)ld_16(dir + DIR_FstClusHI) << 16; } return cl; @@ -1837,9 +1887,9 @@ static void st_clust ( DWORD cl /* Value to be set */ ) { - st_word(dir + DIR_FstClusLO, (WORD)cl); + st_16(dir + DIR_FstClusLO, (WORD)cl); if (fs->fs_type == FS_FAT32) { - st_word(dir + DIR_FstClusHI, (WORD)(cl >> 16)); + st_16(dir + DIR_FstClusHI, (WORD)(cl >> 16)); } } #endif @@ -1852,31 +1902,31 @@ static void st_clust ( /*--------------------------------------------------------*/ static int cmp_lfn ( /* 1:matched, 0:not matched */ - const WCHAR* lfnbuf, /* Pointer to the LFN working buffer to be compared */ - BYTE* dir /* Pointer to the directory entry containing the part of LFN */ + const WCHAR* lfnbuf, /* Pointer to the LFN to be compared */ + BYTE* dir /* Pointer to the LFN entry */ ) { - UINT i, s; - WCHAR wc, uc; + UINT ni, di; + WCHAR pchr, chr; - if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */ + if (ld_16(dir + LDIR_FstClusLO) != 0) return 0; /* Check if LDIR_FstClusLO is 0 */ - i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ + ni = (UINT)((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the name to be compared */ - for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ - uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */ - if (wc != 0) { - if (i >= FF_MAX_LFN + 1 || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) { /* Compare it */ + for (pchr = 1, di = 0; di < 13; di++) { /* Process all characters in the entry */ + chr = ld_16(dir + LfnOfs[di]); /* Pick a character from the entry */ + if (pchr != 0) { + if (ni >= FF_MAX_LFN + 1 || ff_wtoupper(chr) != ff_wtoupper(lfnbuf[ni++])) { /* Compare it with name */ return 0; /* Not matched */ } - wc = uc; + pchr = chr; } else { - if (uc != 0xFFFF) return 0; /* Check filler */ + if (chr != 0xFFFF) return 0; /* Check filler */ } } - if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i]) return 0; /* Last segment matched but different length */ + if ((dir[LDIR_Ord] & LLEF) && pchr && lfnbuf[ni]) return 0; /* Last name segment matched but different length */ return 1; /* The part of LFN matched */ } @@ -1888,31 +1938,31 @@ static int cmp_lfn ( /* 1:matched, 0:not matched */ /*-----------------------------------------------------*/ static int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */ - WCHAR* lfnbuf, /* Pointer to the LFN working buffer */ - BYTE* dir /* Pointer to the LFN entry */ + WCHAR* lfnbuf, /* Pointer to the name buffer to be stored */ + const BYTE* dir /* Pointer to the LFN entry */ ) { - UINT i, s; - WCHAR wc, uc; + UINT ni, di; + WCHAR pchr, chr; - if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO is 0 */ + if (ld_16(dir + LDIR_FstClusLO) != 0) return 0; /* Check if LDIR_FstClusLO is 0 */ - i = ((dir[LDIR_Ord] & ~LLEF) - 1) * 13; /* Offset in the LFN buffer */ + ni = (UINT)((dir[LDIR_Ord] & ~LLEF) - 1) * 13; /* Offset in the name buffer */ - for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ - uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */ - if (wc != 0) { - if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ - lfnbuf[i++] = wc = uc; /* Store it */ + for (pchr = 1, di = 0; di < 13; di++) { /* Process all characters in the entry */ + chr = ld_16(dir + LfnOfs[di]); /* Pick a character from the entry */ + if (pchr != 0) { + if (ni >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ + lfnbuf[ni++] = pchr = chr; /* Store it */ } else { - if (uc != 0xFFFF) return 0; /* Check filler */ + if (chr != 0xFFFF) return 0; /* Check filler */ } } - if (dir[LDIR_Ord] & LLEF && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */ - if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ - lfnbuf[i] = 0; + if (dir[LDIR_Ord] & LLEF && pchr != 0) { /* Put terminator if it is the last LFN part and not terminated */ + if (ni >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */ + lfnbuf[ni] = 0; } return 1; /* The part of LFN is valid */ @@ -1932,24 +1982,24 @@ static void put_lfn ( BYTE sum /* Checksum of the corresponding SFN */ ) { - UINT i, s; - WCHAR wc; + UINT ni, di; + WCHAR chr; dir[LDIR_Chksum] = sum; /* Set checksum */ - dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */ + dir[LDIR_Attr] = AM_LFN; /* Set attribute */ dir[LDIR_Type] = 0; - st_word(dir + LDIR_FstClusLO, 0); - - i = (ord - 1) * 13; /* Get offset in the LFN working buffer */ - s = wc = 0; - 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 */ - } 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 */ + st_16(dir + LDIR_FstClusLO, 0); + + ni = (UINT)(ord - 1) * 13; /* Offset in the name */ + di = chr = 0; + do { /* Fill the directory entry */ + if (chr != 0xFFFF) chr = lfn[ni++]; /* Get an effective character */ + st_16(dir + LfnOfs[di], chr); /* Set it */ + if (chr == 0) chr = 0xFFFF; /* Padding characters after the terminator */ + } while (++di < 13); + if (chr == 0xFFFF || !lfn[ni]) ord |= LLEF; /* Last LFN part is the start of an enrty set */ + dir[LDIR_Ord] = ord; /* Set order in the entry set */ } #endif /* !FF_FS_READONLY */ @@ -1966,31 +2016,31 @@ static void gen_numname ( BYTE* dst, /* Pointer to the buffer to store numbered SFN */ const BYTE* src, /* Pointer to SFN in directory form */ const WCHAR* lfn, /* Pointer to LFN */ - UINT seq /* Sequence number */ + WORD seq /* Sequence number */ ) { BYTE ns[8], c; UINT i, j; - WCHAR wc; - DWORD sreg; memcpy(dst, src, 11); /* Prepare the SFN to be modified */ if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */ - sreg = seq; - while (*lfn) { /* Create a CRC as hash value */ + WCHAR wc; + DWORD crc_sreg = seq; + + while (*lfn) { /* Create a CRC value as a hash of LFN */ wc = *lfn++; for (i = 0; i < 16; i++) { - sreg = (sreg << 1) + (wc & 1); + crc_sreg = (crc_sreg << 1) + (wc & 1); wc >>= 1; - if (sreg & 0x10000) sreg ^= 0x11021; + if (crc_sreg & 0x10000) crc_sreg ^= 0x11021; } } - seq = (UINT)sreg; + seq = (WORD)crc_sreg; } - /* Make suffix (~ + hexdecimal) */ + /* Make suffix (~ + 4-digit hexadecimal) */ i = 7; do { c = (BYTE)((seq % 16) + '0'); seq /= 16; @@ -2049,7 +2099,7 @@ static WORD xdir_sum ( /* Get checksum of the directoly entry block */ WORD sum; - szblk = (dir[XDIR_NumSec] + 1) * SZDIRE; /* Number of bytes of the entry block */ + szblk = ((UINT)dir[XDIR_NumSec] + 1) * SZDIRE; /* Number of bytes of the entry block */ for (i = sum = 0; i < szblk; i++) { if (i == XDIR_SetSum) { /* Skip 2-byte sum field */ i++; @@ -2092,26 +2142,26 @@ static DWORD xsum32 ( /* Returns 32-bit checksum */ -/*-----------------------------------*/ -/* exFAT: Get a directry entry block */ -/*-----------------------------------*/ +/*------------------------------------*/ +/* exFAT: Get a directory entry block */ +/*------------------------------------*/ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ - DIR* dp /* Reading direcotry object pointing top of the entry block to load */ + DIR* dp /* Reading directory object pointing top of the entry block to load */ ) { FRESULT res; UINT i, sz_ent; - BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory direcotry entry block 85+C0+C1s */ + BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory directory entry block 85+C0+C1s */ - /* Load file directory entry */ + /* Load file-directory entry */ res = move_window(dp->obj.fs, dp->sect); if (res != FR_OK) return res; - if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR; /* Invalid order */ + if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR; /* Invalid order? */ memcpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE); - sz_ent = (dirb[XDIR_NumSec] + 1) * SZDIRE; - if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR; + sz_ent = ((UINT)dirb[XDIR_NumSec] + 1) * SZDIRE; /* Size of this entry block */ + if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR; /* Invalid block size? */ /* Load stream extension entry */ res = dir_next(dp, 0); @@ -2119,9 +2169,9 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ if (res != FR_OK) return res; res = move_window(dp->obj.fs, dp->sect); if (res != FR_OK) return res; - if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR; /* Invalid order */ + if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR; /* Invalid order? */ memcpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE); - if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR; + if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR; /* Invalid block size for the name? */ /* Load file name entries */ i = 2 * SZDIRE; /* Name offset to load */ @@ -2131,14 +2181,15 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ if (res != FR_OK) return res; res = move_window(dp->obj.fs, dp->sect); if (res != FR_OK) return res; - if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR; /* Invalid order */ - if (i < MAXDIRB(FF_MAX_LFN)) memcpy(dirb + i, dp->dir, SZDIRE); + if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR; /* Invalid order? */ + if (i < MAXDIRB(FF_MAX_LFN)) memcpy(dirb + i, dp->dir, SZDIRE); /* Load name entries only if the object is accessible */ } while ((i += SZDIRE) < sz_ent); /* Sanity check (do it for only accessible object) */ if (i <= MAXDIRB(FF_MAX_LFN)) { - if (xdir_sum(dirb) != ld_word(dirb + XDIR_SetSum)) return FR_INT_ERR; + if (xdir_sum(dirb) != ld_16(dirb + XDIR_SetSum)) return FR_INT_ERR; } + return FR_OK; } @@ -2148,25 +2199,33 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ /*------------------------------------------------------------------*/ static void init_alloc_info ( - FATFS* fs, /* Filesystem object */ - FFOBJID* obj /* Object allocation information to be initialized */ + FFOBJID* dobj, /* Object allocation information to be initialized */ + DIR* sdir /* Additional source about containing direcotry */ ) { - obj->sclust = ld_dword(fs->dirbuf + XDIR_FstClus); /* Start cluster */ - obj->objsize = ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */ - obj->stat = fs->dirbuf[XDIR_GenFlags] & 2; /* Allocation status */ - obj->n_frag = 0; /* No last fragment info */ + FATFS *fs = dobj->fs; + + + if (sdir) { /* Initialize the containing directory. This block needs to precede the followings. */ + dobj->c_scl = sdir->obj.sclust; + dobj->c_size = ((DWORD)sdir->obj.objsize & 0xFFFFFF00) | sdir->obj.stat; + dobj->c_ofs = sdir->blk_ofs; + } + dobj->sclust = ld_32(fs->dirbuf + XDIR_FstClus); /* Start cluster */ + dobj->objsize = ld_64(fs->dirbuf + XDIR_FileSize); /* Size */ + dobj->stat = fs->dirbuf[XDIR_GenFlags] & 2; /* Allocation status */ + dobj->n_frag = 0; /* No last fragment info */ } -#if !FF_FS_READONLY || FF_FS_RPATH != 0 +#if !FF_FS_READONLY || FF_FS_RPATH /*------------------------------------------------*/ /* exFAT: Load the object's directory entry block */ /*------------------------------------------------*/ static FRESULT load_obj_xdir ( - DIR* dp, /* Blank directory object to be used to access containing direcotry */ + DIR* dp, /* Blank directory object to be used to access containing directory */ const FFOBJID* obj /* Object with its containing directory information */ ) { @@ -2195,27 +2254,29 @@ static FRESULT load_obj_xdir ( /*----------------------------------------*/ static FRESULT store_xdir ( - DIR* dp /* Pointer to the direcotry object */ + DIR* dp /* Pointer to the directory object */ ) { FRESULT res; UINT nent; - BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the direcotry entry block 85+C0+C1s */ + BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the entry set 85+C0+C1s */ + - /* Create set sum */ - st_word(dirb + XDIR_SetSum, xdir_sum(dirb)); - nent = dirb[XDIR_NumSec] + 1; + st_16(dirb + XDIR_SetSum, xdir_sum(dirb)); /* Create check sum */ - /* Store the direcotry entry block to the directory */ - res = dir_sdi(dp, dp->blk_ofs); + /* Store the entry set to the directory */ + nent = dirb[XDIR_NumSec] + 1; /* Number of entries */ + res = dir_sdi(dp, dp->blk_ofs); /* Top of the entry set */ while (res == FR_OK) { + /* Set an entry to the directory */ res = move_window(dp->obj.fs, dp->sect); if (res != FR_OK) break; memcpy(dp->dir, dirb, SZDIRE); dp->obj.fs->wflag = 1; - if (--nent == 0) break; + + if (--nent == 0) break; /* All done? */ dirb += SZDIRE; - res = dir_next(dp, 0); + res = dir_next(dp, 0); /* Next entry */ } return (res == FR_OK || res == FR_DISK_ERR) ? res : FR_INT_ERR; } @@ -2223,40 +2284,40 @@ static FRESULT store_xdir ( /*-------------------------------------------*/ -/* exFAT: Create a new directory enrty block */ +/* exFAT: Create a new directory entry block */ /*-------------------------------------------*/ static void create_xdir ( - BYTE* dirb, /* Pointer to the direcotry entry block buffer */ + BYTE* dirb, /* Pointer to the directory entry block buffer */ const WCHAR* lfn /* Pointer to the object name */ ) { UINT i; - BYTE nc1, nlen; - WCHAR wc; + BYTE n_c1, nlen; + WCHAR chr; - /* Create file-directory and stream-extension entry */ + /* Create file-directory and stream-extension entry (1st and 2nd entry) */ memset(dirb, 0, 2 * SZDIRE); dirb[0 * SZDIRE + XDIR_Type] = ET_FILEDIR; dirb[1 * SZDIRE + XDIR_Type] = ET_STREAM; - /* Create file-name entries */ - i = SZDIRE * 2; /* Top of file_name entries */ - nlen = nc1 = 0; wc = 1; + /* Create file name entries (3rd enrty and follows) */ + i = SZDIRE * 2; /* Top of file name entries */ + nlen = n_c1 = 0; chr = 1; do { dirb[i++] = ET_FILENAME; dirb[i++] = 0; do { /* Fill name field */ - if (wc != 0 && (wc = lfn[nlen]) != 0) nlen++; /* Get a character if exist */ - st_word(dirb + i, wc); /* Store it */ + if (chr != 0 && (chr = lfn[nlen]) != 0) nlen++; /* Get a character if exist */ + st_16(dirb + i, chr); /* Store it */ i += 2; } while (i % SZDIRE != 0); - nc1++; - } while (lfn[nlen]); /* Fill next entry if any char follows */ + n_c1++; + } while (lfn[nlen]); /* Fill next C1 entry if any char follows */ dirb[XDIR_NumName] = nlen; /* Set name length */ - dirb[XDIR_NumSec] = 1 + nc1; /* Set secondary count (C0 + C1s) */ - st_word(dirb + XDIR_NameHash, xname_sum(lfn)); /* Set name hash */ + dirb[XDIR_NumSec] = 1 + n_c1; /* Set secondary count (C0 + C1s) */ + st_16(dirb + XDIR_NameHash, xname_sum(lfn)); /* Set name hash */ } #endif /* !FF_FS_READONLY */ @@ -2279,7 +2340,7 @@ static FRESULT dir_read ( { FRESULT res = FR_NO_FILE; FATFS *fs = dp->obj.fs; - BYTE attr, b; + BYTE attr, et; #if FF_USE_LFN BYTE ord = 0xFF, sum = 0xFF; #endif @@ -2287,16 +2348,16 @@ static FRESULT dir_read ( while (dp->sect) { res = move_window(fs, dp->sect); if (res != FR_OK) break; - b = dp->dir[DIR_Name]; /* Test for the entry type */ - if (b == 0) { + et = dp->dir[DIR_Name]; /* Test for the entry type */ + if (et == 0) { res = FR_NO_FILE; break; /* Reached to end of the directory */ } #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ if (FF_USE_LABEL && vol) { - if (b == ET_VLABEL) break; /* Volume label entry? */ + if (et == ET_VLABEL) break; /* Volume label entry? */ } else { - if (b == ET_FILEDIR) { /* Start of the file entry block? */ + if (et == ET_FILEDIR) { /* Start of the file entry block? */ dp->blk_ofs = dp->dptr; /* Get location of the block */ res = load_xdir(dp); /* Load the entry block */ if (res == FR_OK) { @@ -2310,17 +2371,17 @@ static FRESULT dir_read ( { /* On the FAT/FAT32 volume */ dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */ #if FF_USE_LFN /* LFN configuration */ - if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ + if (et == DDEM || et == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ ord = 0xFF; } else { if (attr == AM_LFN) { /* An LFN entry is found */ - if (b & LLEF) { /* Is it start of an LFN sequence? */ + if (et & LLEF) { /* Is it start of an LFN sequence? */ sum = dp->dir[LDIR_Chksum]; - b &= (BYTE)~LLEF; ord = b; + et &= (BYTE)~LLEF; ord = et; dp->blk_ofs = dp->dptr; } /* Check LFN validity and capture it */ - ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + ord = (et == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; } else { /* An SFN entry is found */ if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */ dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */ @@ -2329,7 +2390,7 @@ static FRESULT dir_read ( } } #else /* Non LFN configuration */ - if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */ + if (et != DDEM && et != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */ break; } #endif @@ -2356,9 +2417,9 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ { FRESULT res; FATFS *fs = dp->obj.fs; - BYTE c; + BYTE et; #if FF_USE_LFN - BYTE a, ord, sum; + BYTE attr, ord, sum; #endif res = dir_sdi(dp, 0); /* Rewind directory object */ @@ -2373,10 +2434,10 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ #if FF_MAX_LFN < 255 if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */ #endif - if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */ + if (ld_16(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */ for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */ if ((di % SZDIRE) == 0) di += 2; - if (ff_wtoupper(ld_word(fs->dirbuf + di)) != ff_wtoupper(fs->lfnbuf[ni])) break; + if (ff_wtoupper(ld_16(fs->dirbuf + di)) != ff_wtoupper(fs->lfnbuf[ni])) break; } if (nc == 0 && !fs->lfnbuf[ni]) break; /* Name matched? */ } @@ -2390,27 +2451,28 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ do { res = move_window(fs, dp->sect); if (res != FR_OK) break; - c = dp->dir[DIR_Name]; - if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ + et = dp->dir[DIR_Name]; /* Entry type */ + if (et == 0) { res = FR_NO_FILE; break; } /* Reached end of directory table */ #if FF_USE_LFN /* LFN configuration */ - dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK; - if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ + dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; + if (et == DDEM || ((attr & AM_VOL) && attr != AM_LFN)) { /* An entry without valid data */ ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ } else { - if (a == AM_LFN) { /* An LFN entry is found */ + if (attr == AM_LFN) { /* Is it an LFN entry? */ if (!(dp->fn[NSFLAG] & NS_NOLFN)) { - if (c & LLEF) { /* Is it start of LFN sequence? */ - sum = dp->dir[LDIR_Chksum]; - c &= (BYTE)~LLEF; ord = c; /* LFN start order */ - dp->blk_ofs = dp->dptr; /* Start offset of LFN */ + if (et & LLEF) { /* Is it start of an entry set? */ + et &= (BYTE)~LLEF; + ord = et; /* Number of LFN entries */ + dp->blk_ofs = dp->dptr; /* Start offset of LFN */ + sum = dp->dir[LDIR_Chksum]; /* Sum of the SFN */ } /* Check validity of the LFN entry and compare it with given name */ - ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + ord = (et == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; } - } else { /* An SFN entry is found */ + } else { /* SFN entry */ if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */ if (!(dp->fn[NSFLAG] & NS_LOSS) && !memcmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */ - ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ + ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Not matched, reset LFN sequence */ } } #else /* Non LFN configuration */ @@ -2439,7 +2501,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too FATFS *fs = dp->obj.fs; #if FF_USE_LFN /* LFN configuration */ UINT n, len, n_ent; - BYTE sn[12], sum; + BYTE sn[12]; if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */ @@ -2464,11 +2526,17 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */ if (res != FR_OK) return res; dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */ - st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); - st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize); - fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */ + st_64(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); + st_64(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize); + fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */ res = store_xdir(&dj); /* Store the object status */ if (res != FR_OK) return res; +#if FF_FS_RPATH /* Refrect changes to the current dir chain if the stretched dir is in it */ + for (n = 1; n <= fs->xcwds.depth && dp->obj.sclust != fs->xcwds.tbl[n].d_scl; n++) ; /* Check if the dir is in the current dir path */ + if (n <= fs->xcwds.depth) { /* If exist, update it */ + fs->xcwds.tbl[n].d_size = (DWORD)dp->obj.objsize | dp->obj.stat; + } +#endif } } @@ -2481,7 +2549,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */ dp->fn[NSFLAG] = NS_NOLFN; /* Find only SFN */ for (n = 1; n < 100; n++) { - gen_numname(dp->fn, sn, fs->lfnbuf, n); /* Generate a numbered name */ + gen_numname(dp->fn, sn, fs->lfnbuf, (WORD)n); /* Generate a numbered name */ res = dir_find(dp); /* Check if the name collides with existing SFN */ if (res != FR_OK) break; } @@ -2496,7 +2564,8 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too if (res == FR_OK && --n_ent) { /* Set LFN entry if needed */ res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE); if (res == FR_OK) { - sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ + BYTE sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ + do { /* Store LFN entries in bottom first */ res = move_window(fs, dp->sect); if (res != FR_OK) break; @@ -2519,7 +2588,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too memset(dp->dir, 0, SZDIRE); /* Clean the entry */ memcpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */ #if FF_USE_LFN - dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */ + dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put low-case flags */ #endif fs->wflag = 1; } @@ -2590,7 +2659,6 @@ static void get_fileinfo ( { UINT si, di; #if FF_USE_LFN - BYTE lcf; WCHAR wc, hs; FATFS *fs = dp->obj.fs; UINT nw; @@ -2599,7 +2667,7 @@ static void get_fileinfo ( #endif - fno->fname[0] = 0; /* Invaidate file info */ + fno->fname[0] = 0; if (dp->sect == 0) return; /* Exit if read pointer has reached end of directory */ #if FF_USE_LFN /* LFN configuration */ @@ -2610,26 +2678,34 @@ static void get_fileinfo ( si = SZDIRE * 2; di = 0; /* 1st C1 entry in the entry block */ hs = 0; while (nc < fs->dirbuf[XDIR_NumName]) { - if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */ - if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */ - wc = ld_word(fs->dirbuf + si); si += 2; nc++; /* Get a character */ - if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */ - hs = wc; continue; /* Get low surrogate */ + if (si >= MAXDIRB(FF_MAX_LFN)) { /* Truncated directory block? */ + di = 0; break; + } + if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */ + wc = ld_16(fs->dirbuf + si); si += 2; nc++; /* Get a character */ + if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */ + hs = wc; continue; /* Get low surrogate */ } nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */ - if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */ + if (nw == 0) { /* Buffer overflow or wrong char? */ + di = 0; break; + } di += nw; hs = 0; } if (hs != 0) di = 0; /* Broken surrogate pair? */ - if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */ + if (di == 0) fno->fname[di++] = '\?'; /* Inaccessible object name? */ fno->fname[di] = 0; /* Terminate the name */ fno->altname[0] = 0; /* exFAT does not support SFN */ - fno->fattrib = fs->dirbuf[XDIR_Attr] & AM_MASKX; /* Attribute */ - fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */ - fno->ftime = ld_word(fs->dirbuf + XDIR_ModTime + 0); /* Time */ - fno->fdate = ld_word(fs->dirbuf + XDIR_ModTime + 2); /* Date */ + fno->fattrib = fs->dirbuf[XDIR_Attr] & AM_MASKX; /* Attribute */ + fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_64(fs->dirbuf + XDIR_FileSize); /* Size */ + fno->ftime = ld_16(fs->dirbuf + XDIR_ModTime + 0); /* Last modified time */ + fno->fdate = ld_16(fs->dirbuf + XDIR_ModTime + 2); /* Last modified date */ +#if FF_FS_CRTIME + fno->crtime = ld_16(fs->dirbuf + XDIR_CrtTime + 0); /* Created time */ + fno->crdate = ld_16(fs->dirbuf + XDIR_CrtTime + 2); /* Created date */ +#endif return; } else #endif @@ -2643,7 +2719,9 @@ static void get_fileinfo ( hs = wc; continue; /* Get low surrogate */ } nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */ - if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */ + if (nw == 0) { /* Buffer overflow or wrong char? */ + di = 0; break; + } di += nw; hs = 0; } @@ -2663,9 +2741,13 @@ static 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? */ + 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) { di = 0; break; } /* Buffer overflow? */ + if (nw == 0) { /* Buffer overflow? */ + di = 0; break; + } di += nw; #else /* ANSI/OEM output */ fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */ @@ -2673,14 +2755,16 @@ static 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 (!fno->fname[0]) { /* If LFN is invalid, altname[] needs to be copied to fname[] */ + if (di == 0) { /* If LFN and SFN both are invalid, */ + fno->fname[di++] = '\?'; /* This object is inaccessible due to wrong buffer or locale settings */ } else { - for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ + BYTE lcflg = NS_BODY; + + for (si = di = 0; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ wc = (WCHAR)fno->altname[si]; - if (wc == '.') lcf = NS_EXT; - if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20; + if (wc == '.') lcflg = NS_EXT; + if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcflg)) wc += 0x20; fno->fname[di] = (TCHAR)wc; } } @@ -2700,10 +2784,14 @@ static void get_fileinfo ( fno->fname[di] = 0; /* Terminate the SFN */ #endif - 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 */ + fno->fattrib = dp->dir[DIR_Attr] & AM_MASK; /* Attribute */ + fno->fsize = ld_32(dp->dir + DIR_FileSize); /* Size */ + fno->ftime = ld_16(dp->dir + DIR_ModTime + 0); /* Last modified time */ + fno->fdate = ld_16(dp->dir + DIR_ModTime + 2); /* Last Modified date */ +#if FF_FS_CRTIME + fno->crtime = ld_16(dp->dir + DIR_CrtTime + 0); /* Created time */ + fno->crdate = ld_16(dp->dir + DIR_CrtTime + 2); /* Created date */ +#endif } #endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */ @@ -2734,9 +2822,9 @@ static DWORD get_achar ( /* Get a character and advance ptr */ chr = (BYTE)*(*ptr)++; /* Get a byte */ if (IsLower(chr)) chr -= 0x20; /* To upper ASCII char */ #if FF_CODE_PAGE == 0 - if (ExCvt && chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ + if (ExCvt && chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper (SBCS extended char) */ #elif FF_CODE_PAGE < 900 - if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ + if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper (SBCS extended char) */ #endif #if FF_CODE_PAGE == 0 || FF_CODE_PAGE >= 900 if (dbc_1st((BYTE)chr)) { /* Get DBC 2nd byte if needed */ @@ -2756,7 +2844,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; @@ -2770,12 +2859,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 */ } @@ -2805,13 +2898,14 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr { #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 */ + /* Create an LFN into LFN working buffer */ p = *path; lfn = dp->obj.fs->lfnbuf; di = 0; for (;;) { uc = tchar2uni(&p); /* Get a character */ @@ -2832,7 +2926,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr } *path = p; /* Return pointer to the next segment */ -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH if ((di == 1 && lfn[di - 1] == '.') || (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */ lfn[di] = 0; @@ -2930,7 +3024,8 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr #else /* FF_USE_LFN : Non-LFN configuration */ - BYTE c, d, *sfn; + BYTE c, d; + BYTE *sfn; UINT ni, si, i; const char *p; @@ -2938,14 +3033,19 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr p = *path; sfn = dp->fn; memset(sfn, ' ', 11); si = i = 0; ni = 8; -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH if (p[si] == '.') { /* Is this a dot entry? */ - for (;;) { + for (;;) { /* Copy one or two dots */ c = (BYTE)p[si++]; if (c != '.' || si >= 3) break; sfn[i++] = c; } - if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME; + if (IsSeparator(c)) { + while (IsSeparator(p[si])) si++; /* Skip duplicated separators */ + if ((BYTE)p[si] <= ' ') c = 0; /* Terminate if no segment follows */ + } else if (c > ' ') { /* Not in dot name */ + 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; @@ -2955,7 +3055,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr c = (BYTE)p[si++]; /* Get a byte */ if (c <= ' ') break; /* Break if end of the path name */ if (IsSeparator(c)) { /* Break if a separator is found */ - while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */ + while (IsSeparator(p[si])) si++; /* Skip duplicated separators */ break; } if (c == '.' || i >= ni) { /* End of body or field overflow? */ @@ -3010,28 +3110,33 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ FATFS *fs = dp->obj.fs; -#if FF_FS_RPATH != 0 + /* Determins the start directory (current directory or forced root directory) */ +#if FF_FS_RPATH 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 (IsSeparator(*path)) path++; /* Strip separators */ - dp->obj.sclust = 0; /* Start from the root directory */ + while (IsSeparator(*path)) path++; /* Strip heading separators */ + dp->obj.sclust = 0; /* Start at the root directory */ } + #if FF_FS_EXFAT dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */ -#if FF_FS_RPATH != 0 - if (fs->fs_type == FS_EXFAT && dp->obj.sclust) { /* exFAT: Retrieve the sub-directory's status */ - DIR dj; - - dp->obj.c_scl = fs->cdc_scl; - dp->obj.c_size = fs->cdc_size; - dp->obj.c_ofs = fs->cdc_ofs; - res = load_obj_xdir(&dj, &dp->obj); - if (res != FR_OK) return res; - dp->obj.objsize = ld_dword(fs->dirbuf + XDIR_FileSize); - dp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2; +#if FF_FS_RPATH + if (fs->fs_type == FS_EXFAT) { /* exFAT: Retrieve the start-directory's status */ + if (dp->obj.sclust) { /* Start directory is a sub-directory */ + /* Load the current directory chain into working buffer and initialize directory object as current dir */ + memcpy(&fs->xcwds2, &fs->xcwds, sizeof fs->xcwds2); + dp->obj.stat = (BYTE)fs->xcwds2.tbl[fs->xcwds2.depth].d_size; + dp->obj.objsize = fs->xcwds2.tbl[fs->xcwds2.depth].d_size & 0xFFFFFF00; + dp->obj.c_scl = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_scl; + dp->obj.c_size = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_size & 0xFFFFFF00; + dp->obj.c_ofs = fs->xcwds2.tbl[fs->xcwds2.depth - 1].nxt_ofs; + } else { /* Start directory is the root directory */ + /* Clear the directory path working buffer as root directory */ + memset(&fs->xcwds2, 0, sizeof fs->xcwds2); + } } #endif #endif @@ -3044,11 +3149,31 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ for (;;) { res = create_name(dp, &path); /* Get a segment name of the path */ if (res != FR_OK) break; - res = dir_find(dp); /* Find an object with the segment name */ ns = dp->fn[NSFLAG]; +#if FF_FS_EXFAT && FF_FS_RPATH + if (fs->fs_type == FS_EXFAT && (ns & NS_DOT)) { /* Is it a dot name? */ + /* There is no dot entry in exFAT volume, so it needs to follow the parent directory with recorded path */ + if (fs->lfnbuf[1] == '.' && fs->xcwds2.depth) { /* ".." in the sub-dir? */ + fs->xcwds2.depth--; /* Get into the parent directory and load the directory info */ + dp->obj.sclust = fs->xcwds2.tbl[fs->xcwds2.depth].d_scl; + dp->obj.stat = (BYTE)fs->xcwds2.tbl[fs->xcwds2.depth].d_size; + dp->obj.objsize = fs->xcwds2.tbl[fs->xcwds2.depth].d_size & 0xFFFFFF00; + if (fs->xcwds2.depth) { /* Load containing dir info if needed */ + dp->obj.c_scl = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_scl; + dp->obj.c_size = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_size; + dp->obj.c_ofs = fs->xcwds2.tbl[fs->xcwds2.depth - 1].nxt_ofs; + } + } + dp->obj.attr |= AM_DIR; /* This is a directory */ + dp->fn[NSFLAG] |= NS_NONAME; /* but dot names in exFAT volume are not directory entry */ + if (ns & NS_LAST) break; /* Last segment? */ + continue; /* Follow next segment */ + } +#endif + res = dir_find(dp); /* Find an object with the segment name */ if (res != FR_OK) { /* Failed to find the object */ if (res == FR_NO_FILE) { /* Object is not found */ - if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there */ + if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there (may be root dir in FAT volume) */ if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */ dp->fn[NSFLAG] = NS_NONAME; res = FR_OK; @@ -3058,17 +3183,24 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ } break; } - if (ns & NS_LAST) break; /* Last segment matched. Function completed. */ +#if FF_FS_EXFAT && FF_FS_RPATH + if (fs->fs_type == FS_EXFAT && (dp->obj.attr & AM_DIR)) { /* Record the path if it is a sub-directory */ + fs->xcwds2.tbl[fs->xcwds2.depth].nxt_ofs = dp->blk_ofs; + if (++fs->xcwds2.depth >= sizeof fs->xcwds2.tbl / sizeof fs->xcwds2.tbl[0]) { /* Is it too deep path? */ + res = FR_NOT_ENOUGH_CORE; break; + } + fs->xcwds2.tbl[fs->xcwds2.depth].d_scl = ld_32(fs->dirbuf + XDIR_FstClus); + fs->xcwds2.tbl[fs->xcwds2.depth].d_size = ld_32(fs->dirbuf + XDIR_FileSize) | (fs->dirbuf[XDIR_GenFlags] & 2); + } +#endif + if (ns & NS_LAST) break; /* If last segment matched, the function completed */ /* Get into the sub-directory */ - if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */ - res = FR_NO_PATH; break; + if (!(dp->obj.attr & AM_DIR)) { + res = FR_NO_PATH; break; /* It is not a sub-directory and cannot follow the path */ } #if FF_FS_EXFAT - if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */ - dp->obj.c_scl = dp->obj.sclust; - dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; - dp->obj.c_ofs = dp->blk_ofs; - init_alloc_info(fs, &dp->obj); /* Open next directory */ + if (fs->fs_type == FS_EXFAT) { + init_alloc_info(&dp->obj, dp); /* Open next directory */ } else #endif { @@ -3091,69 +3223,66 @@ 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; - TCHAR tc; + const TCHAR *tp; + const TCHAR *tt; + TCHAR chr; int i; - int vol = -1; #if FF_STR_VOLUME_ID /* Find string volume ID */ - const char *sp; - char c; + const char *vsp; + char vchr; #endif tt = tp = *path; - if (!tp) return vol; /* Invalid path name? */ - do tc = *tt++; while (!IsTerminator(tc) && tc != ':'); /* Find a colon in the path */ + if (!tp) return -1; /* Invalid path name? */ + do { /* Find a colon in the path */ + chr = *tt++; + } while (!IsTerminator(chr) && chr != ':'); - if (tc == ':') { /* DOS/Windows style volume ID? */ + if (chr == ':') { /* Is there a DOS/Windows style volume ID? */ i = FF_VOLUMES; - if (IsDigit(*tp) && tp + 2 == tt) { /* Is there a numeric volume ID + colon? */ - i = (int)*tp - '0'; /* Get the LD number */ + if (IsDigit(*tp) && tp + 2 == tt) { /* Is it a numeric volume ID + colon? */ + i = (int)*tp - '0'; /* Get the logical drive number */ } -#if FF_STR_VOLUME_ID == 1 /* Arbitrary string is enabled */ +#if FF_STR_VOLUME_ID == 1 /* Arbitrary string volume ID is enabled */ else { - i = 0; + i = 0; /* Find volume ID string in the preconfigured table */ do { - sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */ - do { /* Compare the volume ID with path name */ - c = *sp++; tc = *tp++; - if (IsLower(c)) c -= 0x20; - if (IsLower(tc)) tc -= 0x20; - } while (c && (TCHAR)c == tc); - } while ((c || tp != tt) && ++i < FF_VOLUMES); /* Repeat for each id until pattern match */ + vsp = VolumeStr[i]; tp = *path; /* Preconfigured string and path name to test */ + do { /* Compare the volume ID with path name in case-insensitive */ + vchr = *vsp++; chr = *tp++; + if (IsLower(vchr)) vchr -= 0x20; + if (IsLower(chr)) chr -= 0x20; + } while (vchr && (TCHAR)vchr == chr); + } while ((vchr || tp != tt) && ++i < FF_VOLUMES); /* Repeat for each id until pattern match */ } #endif - if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */ - vol = i; /* Drive number */ - *path = tt; /* Snip the drive prefix off */ - } - return vol; + if (i >= FF_VOLUMES) return -1; /* Not found or invalid volume ID */ + *path = tt; /* Snip the drive prefix off */ + return i; /* Return the found drive number */ } #if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */ if (*tp == '/') { /* Is there a volume ID? */ while (*(tp + 1) == '/') tp++; /* Skip duplicated separator */ i = 0; do { - tt = tp; sp = VolumeStr[i]; /* Path name and this string volume ID */ - do { /* Compare the volume ID with path name */ - c = *sp++; tc = *(++tt); - if (IsLower(c)) c -= 0x20; - if (IsLower(tc)) tc -= 0x20; - } while (c && (TCHAR)c == tc); - } 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 = tt; /* Snip the drive prefix off */ - } - return vol; - } -#endif - /* No drive prefix is found */ -#if FF_FS_RPATH != 0 - vol = CurrVol; /* Default drive is current drive */ + vsp = VolumeStr[i]; tt = tp; /* Preconfigured string and path name to test */ + do { /* Compare the volume ID with path name in case-insensitive */ + vchr = *vsp++; chr = *(++tt); + if (IsLower(vchr)) vchr -= 0x20; + if (IsLower(chr)) chr -= 0x20; + } while (vchr && (TCHAR)vchr == chr); + } while ((vchr || (chr != '/' && !IsTerminator(chr))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */ + if (i >= FF_VOLUMES) return -1; /* Not found (invalid volume ID) */ + *path = tt; /* Snip the node name off */ + return i; /* Return the found drive number */ + } +#endif + /* No drive prefix */ +#if FF_FS_RPATH + return (int)CurrVol; /* Default drive is current drive */ #else - vol = 0; /* Default drive is 0 */ + return 0; /* Default drive is 0 */ #endif - return vol; /* Return the default drive */ } @@ -3190,27 +3319,29 @@ static int test_gpt_header ( /* 0:Invalid, 1:Valid */ ) { UINT i; - DWORD bcc; + DWORD bcc, hlen; - if (memcmp(gpth + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16)) return 0; /* Check sign, version (1.0) and length (92) */ - for (i = 0, bcc = 0xFFFFFFFF; i < 92; i++) { /* Check header BCC */ + if (memcmp(gpth + GPTH_Sign, "EFI PART" "\0\0\1", 12)) return 0; /* Check signature and version (1.0) */ + hlen = ld_32(gpth + GPTH_Size); /* Check header size */ + if (hlen < 92 || hlen > FF_MIN_SS) return 0; + for (i = 0, bcc = 0xFFFFFFFF; i < hlen; i++) { /* Check header BCC */ bcc = crc32(bcc, i - GPTH_Bcc < 4 ? 0 : gpth[i]); } - if (~bcc != ld_dword(gpth + GPTH_Bcc)) return 0; - if (ld_dword(gpth + GPTH_PteSize) != SZ_GPTE) return 0; /* Table entry size (must be SZ_GPTE bytes) */ - if (ld_dword(gpth + GPTH_PtNum) > 128) return 0; /* Table size (must be 128 entries or less) */ + if (~bcc != ld_32(gpth + GPTH_Bcc)) return 0; + if (ld_32(gpth + GPTH_PteSize) != SZ_GPTE) return 0; /* Table entry size (must be SZ_GPTE bytes) */ + if (ld_32(gpth + GPTH_PtNum) > 128) return 0; /* Table size (must be 128 entries or less) */ return 1; } #if !FF_FS_READONLY && FF_USE_MKFS -/* Generate random value */ -static DWORD make_rand ( - DWORD seed, /* Seed value */ - BYTE* buff, /* Output buffer */ - UINT n /* Data length */ +/* Generate a random value */ +static DWORD make_rand ( /* Returns a seed value for next */ + DWORD seed, /* Seed value */ + BYTE *buff, /* Output buffer */ + UINT n /* Data length */ ) { UINT r; @@ -3246,7 +3377,7 @@ static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS, fs->wflag = 0; fs->winsect = (LBA_t)0 - 1; /* Invaidate window */ if (move_window(fs, sect) != FR_OK) return 4; /* Load the boot sector */ - sign = ld_word(fs->win + BS_55AA); + sign = ld_16(fs->win + BS_55AA); #if FF_FS_EXFAT if (sign == 0xAA55 && !memcmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* It is an exFAT VBR */ #endif @@ -3255,20 +3386,20 @@ static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS, if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) { return 0; /* It is an FAT32 VBR */ } - /* FAT volumes formatted with early MS-DOS lack BS_55AA and BS_FilSysType, so FAT VBR needs to be identified without them. */ - w = ld_word(fs->win + BPB_BytsPerSec); + /* FAT volumes created in the early MS-DOS era lack BS_55AA and BS_FilSysType, so FAT VBR needs to be identified without them. */ + w = ld_16(fs->win + BPB_BytsPerSec); b = fs->win[BPB_SecPerClus]; if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS /* Properness of sector size (512-4096 and 2^n) */ && b != 0 && (b & (b - 1)) == 0 /* Properness of cluster size (2^n) */ - && ld_word(fs->win + BPB_RsvdSecCnt) != 0 /* Properness of reserved sectors (MNBZ) */ - && (UINT)fs->win[BPB_NumFATs] - 1 <= 1 /* Properness of FATs (1 or 2) */ - && ld_word(fs->win + BPB_RootEntCnt) != 0 /* Properness of root dir entries (MNBZ) */ - && (ld_word(fs->win + BPB_TotSec16) >= 128 || ld_dword(fs->win + BPB_TotSec32) >= 0x10000) /* Properness of volume sectors (>=128) */ - && ld_word(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size (MNBZ) */ + && ld_16(fs->win + BPB_RsvdSecCnt) != 0 /* Properness of number of reserved sectors (MNBZ) */ + && (UINT)fs->win[BPB_NumFATs] - 1 <= 1 /* Properness of number of FATs (1 or 2) */ + && ld_16(fs->win + BPB_RootEntCnt) != 0 /* Properness of root dir size (MNBZ) */ + && (ld_16(fs->win + BPB_TotSec16) >= MIN_VOLUME || ld_32(fs->win + BPB_TotSec32) >= 0x10000) /* Properness of volume size */ + && ld_16(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size (MNBZ) */ return 0; /* It can be presumed an FAT VBR */ } } - return sign == 0xAA55 ? 2 : 3; /* Not an FAT VBR (valid or invalid BS) */ + return sign == 0xAA55 ? 2 : 3; /* Not an FAT VBR (with valid or invalid BS) */ } @@ -3277,7 +3408,7 @@ static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS, static UINT find_volume ( /* Returns BS status found in the hosting drive */ FATFS* fs, /* Filesystem object */ - UINT part /* Partition to fined = 0:auto, 1..:forced */ + UINT part /* Partition to fined = 0:find as SFD and partitions, >0:forced partition number */ ) { UINT fmt, i; @@ -3287,7 +3418,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD format */ if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is an FAT VBR as auto scan, not a BS or disk error */ - /* Sector 0 is not an FAT VBR or forced partition number wants a partition */ + /* Sector 0 is not an FAT VBR or forced partition number wants a partitioned drive */ #if FF_LBA64 if (fs->win[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */ @@ -3296,14 +3427,14 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ if (move_window(fs, 1) != FR_OK) return 4; /* Load GPT header sector (next to MBR) */ if (!test_gpt_header(fs->win)) return 3; /* Check if GPT header is valid */ - n_ent = ld_dword(fs->win + GPTH_PtNum); /* Number of entries */ - pt_lba = ld_qword(fs->win + GPTH_PtOfs); /* Table location */ + n_ent = ld_32(fs->win + GPTH_PtNum); /* Number of entries */ + pt_lba = ld_64(fs->win + GPTH_PtOfs); /* Table location */ for (v_ent = i = 0; i < n_ent; i++) { /* Find FAT partition */ if (move_window(fs, pt_lba + i * SZ_GPTE / SS(fs)) != FR_OK) return 4; /* PT sector */ ofs = i * SZ_GPTE % SS(fs); /* Offset in the sector */ if (!memcmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */ - v_ent++; - fmt = check_fs(fs, ld_qword(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */ + v_ent++; /* Order of MS BDP */ + fmt = check_fs(fs, ld_64(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */ if (part == 0 && fmt <= 1) return fmt; /* Auto search (valid FAT volume found first) */ if (part != 0 && v_ent == part) return fmt; /* Forced partition order (regardless of it is valid or not) */ } @@ -3311,9 +3442,9 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ return 3; /* Not found */ } #endif - if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has 4 partitions max */ + if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has four primary partitions max (FatFs does not support logical partition) */ for (i = 0; i < 4; i++) { /* Load partition offset in the MBR */ - mbr_pt[i] = ld_dword(fs->win + MBR_Table + i * SZ_PTE + PTE_StLba); + mbr_pt[i] = ld_32(fs->win + MBR_Table + i * SZ_PTE + PTE_StLba); } i = part ? part - 1 : 0; /* Table index to find first */ do { /* Find an FAT volume */ @@ -3332,15 +3463,13 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ static 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; @@ -3353,7 +3482,7 @@ static 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_volume(fs, 1)) return FR_TIMEOUT; /* Lock the volume, and system if needed */ #endif *rfs = fs; /* Return pointer to the filesystem object */ @@ -3371,9 +3500,8 @@ static 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 an FAT volume, analyze the BPB and initialize the filesystem object) */ - fs->fs_type = 0; /* Clear the filesystem object */ - fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */ - stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */ + fs->fs_type = 0; /* Invalidate the filesystem object */ + 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 */ } @@ -3385,32 +3513,32 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS || (SS(fs) & (SS(fs) - 1))) return FR_DISK_ERR; #endif - /* Find an FAT volume on the drive */ + /* Find an FAT volume on the hosting drive */ fmt = find_volume(fs, LD2PT(vol)); - if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */ + if (fmt == 4) return FR_DISK_ERR; /* An error occurred in the disk I/O layer */ if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */ - bsect = fs->winsect; /* Volume offset */ + bsect = fs->winsect; /* Volume offset in the hosting physical drive */ /* An FAT volume is found (bsect). Following code initializes the filesystem object */ #if FF_FS_EXFAT if (fmt == 1) { QWORD maxlba; - DWORD so, cv, bcl, i; + DWORD so, cv, bcl, ncl, i; for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */ if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM; - if (ld_word(fs->win + BPB_FSVerEx) != 0x100) return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */ + if (ld_16(fs->win + BPB_FSVerEx) != 0x100) return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */ if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs)) { /* (BPB_BytsPerSecEx must be equal to the physical sector size) */ return FR_NO_FILESYSTEM; } - maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA of the volume + 1 */ + maxlba = ld_64(fs->win + BPB_TotSecEx) + bsect; /* Last LBA of the volume + 1 */ if (!FF_LBA64 && maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be accessed in 32-bit LBA) */ - fs->fsize = ld_dword(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */ + fs->fsize = ld_32(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */ fs->n_fats = fs->win[BPB_NumFATsEx]; /* Number of FATs */ if (fs->n_fats != 1) return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */ @@ -3418,16 +3546,16 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */ if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768 sectors) */ - nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */ - if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */ - fs->n_fatent = nclst + 2; + ncl = ld_32(fs->win + BPB_NumClusEx); /* Number of clusters */ + if (ncl > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */ + fs->n_fatent = ncl + 2; /* Boundaries and Limits */ fs->volbase = bsect; - fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx); - fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx); - if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size requiered) */ - fs->dirbase = ld_dword(fs->win + BPB_RootClusEx); + fs->database = bsect + ld_32(fs->win + BPB_DataOfsEx); + fs->fatbase = bsect + ld_32(fs->win + BPB_FatOfsEx); + if (maxlba < (QWORD)fs->database + ncl * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */ + fs->dirbase = ld_32(fs->win + BPB_RootClusEx); /* Get bitmap location and check if it is contiguous (implementation assumption) */ so = i = 0; @@ -3437,30 +3565,33 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (move_window(fs, clst2sect(fs, (DWORD)fs->dirbase) + so) != FR_OK) return FR_DISK_ERR; so++; } - if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */ + if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */ i = (i + SZDIRE) % SS(fs); /* Next entry */ } - bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */ + bcl = ld_32(fs->win + i + 20); /* Bitmap cluster */ if (bcl < 2 || bcl >= fs->n_fatent) return FR_NO_FILESYSTEM; /* (Wrong cluster#) */ fs->bitbase = fs->database + fs->csize * (bcl - 2); /* Bitmap sector */ for (;;) { /* Check if bitmap is contiguous */ if (move_window(fs, fs->fatbase + bcl / (SS(fs) / 4)) != FR_OK) return FR_DISK_ERR; - cv = ld_dword(fs->win + bcl % (SS(fs) / 4) * 4); + cv = ld_32(fs->win + bcl % (SS(fs) / 4) * 4); if (cv == 0xFFFFFFFF) break; /* Last link? */ - if (cv != ++bcl) return FR_NO_FILESYSTEM; /* Fragmented? */ + if (cv != ++bcl) return FR_NO_FILESYSTEM; /* Fragmented bitmap? */ } - #if !FF_FS_READONLY - fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */ + fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Invalidate cluster allocation information */ + fs->fsi_flag = 0; /* Enable to sync PercInUse value in VBR */ #endif fmt = FS_EXFAT; /* FAT sub-type */ } else #endif /* FF_FS_EXFAT */ { - if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */ + DWORD tsect, sysect, fasize, nclst, szbfat; + WORD nrsv; + + if (ld_16(fs->win + BPB_BytsPerSec) != SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */ - fasize = ld_word(fs->win + BPB_FATSz16); /* Number of sectors per FAT */ - if (fasize == 0) fasize = ld_dword(fs->win + BPB_FATSz32); + fasize = ld_16(fs->win + BPB_FATSz16); /* Number of sectors per FAT */ + if (fasize == 0) fasize = ld_32(fs->win + BPB_FATSz32); fs->fsize = fasize; fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FATs */ @@ -3470,13 +3601,13 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->csize = fs->win[BPB_SecPerClus]; /* Cluster size */ if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) return FR_NO_FILESYSTEM; /* (Must be power of 2) */ - fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt); /* Number of root directory entries */ + fs->n_rootdir = ld_16(fs->win + BPB_RootEntCnt); /* Number of root directory entries */ if (fs->n_rootdir % (SS(fs) / SZDIRE)) return FR_NO_FILESYSTEM; /* (Must be sector aligned) */ - tsect = ld_word(fs->win + BPB_TotSec16); /* Number of sectors on the volume */ - if (tsect == 0) tsect = ld_dword(fs->win + BPB_TotSec32); + tsect = ld_16(fs->win + BPB_TotSec16); /* Number of sectors on the volume */ + if (tsect == 0) tsect = ld_32(fs->win + BPB_TotSec32); - nrsv = ld_word(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */ + nrsv = ld_16(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */ if (nrsv == 0) return FR_NO_FILESYSTEM; /* (Must not be 0) */ /* Determine the FAT sub type */ @@ -3488,6 +3619,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (nclst <= MAX_FAT32) fmt = FS_FAT32; if (nclst <= MAX_FAT16) fmt = FS_FAT16; if (nclst <= MAX_FAT12) fmt = FS_FAT12; + if (nclst <= MIN_FAT12) fmt = 0; if (fmt == 0) return FR_NO_FILESYSTEM; /* Boundaries and Limits */ @@ -3496,9 +3628,9 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->fatbase = bsect + nrsv; /* FAT start sector */ fs->database = bsect + sysect; /* Data start sector */ if (fmt == FS_FAT32) { - if (ld_word(fs->win + BPB_FSVer32) != 0) return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */ + if (ld_16(fs->win + BPB_FSVer32) != 0) return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */ if (fs->n_rootdir != 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ - fs->dirbase = ld_dword(fs->win + BPB_RootClus32); /* Root directory start cluster */ + fs->dirbase = ld_32(fs->win + BPB_RootClus32); /* Root directory start cluster */ szbfat = fs->n_fatent * 4; /* (Needed FAT size) */ } else { if (fs->n_rootdir == 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ @@ -3510,44 +3642,49 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #if !FF_FS_READONLY /* Get FSInfo if available */ - fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */ - fs->fsi_flag = 0x80; -#if (FF_FS_NOFSINFO & 3) != 3 - if (fmt == FS_FAT32 /* Allow to update FSInfo only if BPB_FSInfo32 == 1 */ - && ld_word(fs->win + BPB_FSInfo32) == 1 + fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Invalidate cluster allocation information */ + fs->fsi_flag = 0x80; /* Disable FSInfo by default */ + if (fmt == FS_FAT32 + && ld_16(fs->win + BPB_FSInfo32) == 1 /* FAT32: Enable FSInfo feature only if FSInfo sector is next to VBR */ && move_window(fs, bsect + 1) == FR_OK) { fs->fsi_flag = 0; - if (ld_word(fs->win + BS_55AA) == 0xAA55 /* Load FSInfo data if available */ - && ld_dword(fs->win + FSI_LeadSig) == 0x41615252 - && ld_dword(fs->win + FSI_StrucSig) == 0x61417272) + if ( ld_32(fs->win + FSI_LeadSig) == 0x41615252 /* Load FSInfo data if available */ + && ld_32(fs->win + FSI_StrucSig) == 0x61417272 + && ld_32(fs->win + FSI_TrailSig) == 0xAA550000) { -#if (FF_FS_NOFSINFO & 1) == 0 - fs->free_clst = ld_dword(fs->win + FSI_Free_Count); +#if (FF_FS_NOFSINFO & 1) == 0 /* Get free cluster count if trust it */ + fs->free_clst = ld_32(fs->win + FSI_Free_Count); #endif -#if (FF_FS_NOFSINFO & 2) == 0 - fs->last_clst = ld_dword(fs->win + FSI_Nxt_Free); +#if (FF_FS_NOFSINFO & 2) == 0 /* Get next free cluster if rtust it */ + fs->last_clst = ld_32(fs->win + FSI_Nxt_Free); #endif } } -#endif /* (FF_FS_NOFSINFO & 3) != 3 */ #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 */ + +#if FF_USE_LFN == 1 /* Initilize pointers to the static working buffers */ + fs->lfnbuf = LfnBuf; /* LFN working buffer */ #if FF_FS_EXFAT - fs->dirbuf = DirBuf; /* Static directory block scratchpad buuffer */ + fs->dirbuf = DirBuf; /* Directory block scratchpad buuffer */ #endif #endif -#if FF_FS_RPATH != 0 - fs->cdir = 0; /* Initialize current directory */ + +#if FF_FS_RPATH /* Set the current directory top layer (root) */ + fs->cdir = 0; +#if FF_FS_EXFAT + memset(&fs->xcwds, 0, sizeof fs->xcwds); #endif -#if FF_FS_LOCK != 0 /* Clear file lock semaphores */ - clear_lock(fs); #endif + +#if FF_FS_LOCK /* Clear file lock semaphores */ + clear_share(fs); +#endif + return FR_OK; } @@ -3559,7 +3696,7 @@ static 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 */ ) { @@ -3568,22 +3705,22 @@ 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 - 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_volume(obj->fs, 0)) { /* Take a grant to access the volume */ + if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the hosting physical drive is kept initialized */ res = FR_OK; } else { - unlock_fs(obj->fs, FR_OK); + unlock_volume(obj->fs, FR_OK); /* Invalidated volume, abort to access */ } - } else { + } else { /* Could not take */ res = FR_TIMEOUT; } #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 physical 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; } @@ -3599,7 +3736,7 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ /*-----------------------------------------------------------------------*/ -/* Mount/Unmount a Logical Drive */ +/* API: Mount/Unmount a Logical Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_mount ( @@ -3614,32 +3751,44 @@ 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 */ - if (cfs) { -#if FF_FS_LOCK != 0 - clear_lock(cfs); + cfs = FatFs[vol]; /* Pointer to the filesystem object of the volume */ + if (cfs) { /* Unregister current filesystem object */ + FatFs[vol] = 0; +#if FF_FS_LOCK /* Clear file lock semaphores correspond to this volume */ + clear_share(cfs); #endif -#if FF_FS_REENTRANT /* Discard sync object of the current volume */ - if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR; +#if FF_FS_REENTRANT /* Discard mutex of the current volume */ + ff_mutex_delete(vol); #endif - cfs->fs_type = 0; /* Clear old fs object */ + cfs->fs_type = 0; /* Invalidate the filesystem object to be unregistered */ } - if (fs) { - fs->fs_type = 0; /* Clear new fs object */ -#if FF_FS_REENTRANT /* Create sync object for the new volume */ - if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR; + if (fs) { /* Register new filesystem object */ + fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */ +#if FF_FS_REENTRANT /* Create a volume mutex */ + fs->ldrv = (BYTE)vol; /* Owner volume ID */ + if (!ff_mutex_create(vol)) return FR_INT_ERR; +#if FF_FS_LOCK + if (SysLock == 0) { /* Create a system mutex if needed */ + if (!ff_mutex_create(FF_VOLUMES)) { + ff_mutex_delete(vol); + return FR_INT_ERR; + } + SysLock = 1; /* System mutex is ready */ + } #endif +#endif + fs->fs_type = 0; /* Invalidate the new filesystem object */ + FatFs[vol] = fs; /* Register it */ } - 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 */ + res = mount_volume(&path, &fs, 0); /* Force mounted the volume in this function */ LEAVE_FF(fs, res); } @@ -3647,7 +3796,7 @@ FRESULT f_mount ( /*-----------------------------------------------------------------------*/ -/* Open or Create a File */ +/* API: Open or Create a File */ /*-----------------------------------------------------------------------*/ FRESULT f_open ( @@ -3659,31 +3808,28 @@ FRESULT f_open ( FRESULT res; DIR dj; FATFS *fs; -#if !FF_FS_READONLY - DWORD cl, bcs, clst, tm; - LBA_t sc; - FSIZE_t ofs; -#endif - DEF_NAMBUF + DEF_NAMEBUFF - if (!fp) return FR_INVALID_OBJECT; + if (!fp) return FR_INVALID_OBJECT; /* Reject null pointer */ - /* Get logical drive number */ + /* Get logical drive number and mount the volume if needed */ mode &= FF_FS_READONLY ? FA_READ : FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_CREATE_NEW | FA_OPEN_ALWAYS | FA_OPEN_APPEND; res = mount_volume(&path, &fs, mode); + if (res == FR_OK) { + fp->obj.fs = fs; dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ #if !FF_FS_READONLY /* Read/Write configuration */ if (res == FR_OK) { 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 } @@ -3691,32 +3837,33 @@ FRESULT f_open ( if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { if (res != FR_OK) { /* No file, create new */ if (res == FR_NO_FILE) { /* 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 } mode |= FA_CREATE_ALWAYS; /* File is created */ } - else { /* Any object with the same name is already existing */ - if (dj.obj.attr & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */ - res = FR_DENIED; + else { /* An object with the same name is already existing */ + if (mode & FA_CREATE_NEW) { + res = FR_EXIST; /* Cannot create as new file */ } else { - if (mode & FA_CREATE_NEW) res = FR_EXIST; /* Cannot create as new file */ + if (dj.obj.attr & (AM_RDO | AM_DIR)) res = FR_DENIED; /* Cannot overwrite it (R/O or DIR) */ } } if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate the file if overwrite mode */ + DWORD tm = GET_FATTIME(); #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* Get current allocation info */ - fp->obj.fs = fs; - init_alloc_info(fs, &fp->obj); - /* Set directory entry block initial state */ + init_alloc_info(&fp->obj, 0); + /* Set exFAT directory entry block initial state */ memset(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */ memset(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */ fs->dirbuf[XDIR_Attr] = AM_ARC; - st_dword(fs->dirbuf + XDIR_CrtTime, GET_FATTIME()); + st_32(fs->dirbuf + XDIR_CrtTime, tm); /* Set created time */ + st_32(fs->dirbuf + XDIR_ModTime, tm); /* Set modified time (tmp setting) */ fs->dirbuf[XDIR_GenFlags] = 1; res = store_xdir(&dj); if (res == FR_OK && fp->obj.sclust != 0) { /* Remove the cluster chain if exist */ @@ -3726,17 +3873,18 @@ FRESULT f_open ( } else #endif { - /* Set directory entry initial state */ - tm = GET_FATTIME(); /* Set created time */ - st_dword(dj.dir + DIR_CrtTime, tm); - st_dword(dj.dir + DIR_ModTime, tm); + DWORD cl; + /* Set FAT directory entry initial state */ + st_32(dj.dir + DIR_CrtTime, tm); /* Set created time */ + st_32(dj.dir + DIR_ModTime, tm); /* Set modified time (tmp setting) */ cl = ld_clust(fs, dj.dir); /* Get current cluster chain */ dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */ st_clust(fs, dj.dir, 0); /* Reset file allocation info */ - st_dword(dj.dir + DIR_FileSize, 0); + st_32(dj.dir + DIR_FileSize, 0); fs->wflag = 1; if (cl != 0) { /* Remove the cluster chain if exist */ - sc = fs->winsect; + LBA_t sc = fs->winsect; + res = remove_chain(&dj.obj, cl, 0); if (res == FR_OK) { res = move_window(fs, sc); @@ -3761,12 +3909,13 @@ FRESULT f_open ( if (mode & FA_CREATE_ALWAYS) mode |= FA_MODIFIED; /* Set file change flag if created or overwritten */ fp->dir_sect = fs->winsect; /* Pointer to the directory entry */ 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 } -#else /* R/O configuration */ + +#else /* R/O configuration */ if (res == FR_OK) { if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it origin directory itself? */ res = FR_INVALID_NAME; @@ -3781,21 +3930,17 @@ FRESULT f_open ( if (res == FR_OK) { #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fp->obj.c_scl = dj.obj.sclust; /* Get containing directory info */ - fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; - fp->obj.c_ofs = dj.blk_ofs; - init_alloc_info(fs, &fp->obj); + init_alloc_info(&fp->obj, &dj); } else #endif { fp->obj.sclust = ld_clust(fs, dj.dir); /* Get object allocation info */ - fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize); + fp->obj.objsize = ld_32(dj.dir + DIR_FileSize); } #if FF_USE_FASTSEEK fp->cltbl = 0; /* Disable fast seek mode */ #endif - fp->obj.fs = fs; /* Validate the file object */ - fp->obj.id = fs->id; + fp->obj.id = fs->id; /* Set current volume mount ID */ fp->flag = mode; /* Set file access mode */ fp->err = 0; /* Clear error flag */ fp->sect = 0; /* Invalidate current data sector */ @@ -3805,6 +3950,9 @@ FRESULT f_open ( memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */ #endif if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */ + DWORD bcs, clst; + FSIZE_t ofs; + fp->fptr = fp->obj.objsize; /* Offset to seek */ bcs = (DWORD)fs->csize * SS(fs); /* Cluster size in byte */ clst = fp->obj.sclust; /* Follow the cluster chain */ @@ -3815,24 +3963,25 @@ FRESULT f_open ( } fp->clust = clst; if (res == FR_OK && ofs % SS(fs)) { /* Fill sector buffer if not on the sector boundary */ - sc = clst2sect(fs, clst); - if (sc == 0) { + LBA_t sec = clst2sect(fs, clst); + + if (sec == 0) { res = FR_INT_ERR; } else { - fp->sect = sc + (DWORD)(ofs / SS(fs)); + fp->sect = sec + (DWORD)(ofs / SS(fs)); #if !FF_FS_TINY if (disk_read(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) res = FR_DISK_ERR; #endif } } -#if FF_FS_LOCK != 0 - if (res != FR_OK) dec_lock(fp->obj.lockid); /* Decrement file open counter if seek failed */ +#if FF_FS_LOCK + if (res != FR_OK) dec_share(fp->obj.lockid); /* Decrement file open counter if seek failed */ #endif } #endif } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */ @@ -3844,7 +3993,7 @@ FRESULT f_open ( /*-----------------------------------------------------------------------*/ -/* Read File */ +/* API: Read File */ /*-----------------------------------------------------------------------*/ FRESULT f_read ( @@ -3856,7 +4005,6 @@ FRESULT f_read ( { FRESULT res; FATFS *fs; - DWORD clst; LBA_t sect; FSIZE_t remain; UINT rcnt, cc, csect; @@ -3874,6 +4022,8 @@ FRESULT f_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? */ + DWORD clst; + if (fp->fptr == 0) { /* On the top of the file? */ clst = fp->obj.sclust; /* Follow cluster chain from the origin */ } else { /* Middle or end of the file */ @@ -3921,7 +4071,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; @@ -3944,7 +4094,7 @@ FRESULT f_read ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Write File */ +/* API: Write File */ /*-----------------------------------------------------------------------*/ FRESULT f_write ( @@ -4065,7 +4215,7 @@ FRESULT f_write ( /*-----------------------------------------------------------------------*/ -/* Synchronize the File */ +/* API: Synchronize the File */ /*-----------------------------------------------------------------------*/ FRESULT f_sync ( @@ -4074,8 +4224,6 @@ FRESULT f_sync ( { FRESULT res; FATFS *fs; - DWORD tm; - BYTE *dir; res = validate(&fp->obj, &fs); /* Check validity of the file object */ @@ -4088,7 +4236,6 @@ FRESULT f_sync ( } #endif /* Update the directory entry */ - tm = GET_FATTIME(); /* Modified time */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { res = fill_first_frag(&fp->obj); /* Fill first fragment on the FAT if needed */ @@ -4097,40 +4244,43 @@ FRESULT f_sync ( } if (res == FR_OK) { DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = load_obj_xdir(&dj, &fp->obj); /* Load directory entry block */ if (res == FR_OK) { - fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ - fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */ - st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); /* Update start cluster */ - st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); /* Update file size */ - st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); /* (FatFs does not support Valid File Size feature) */ - st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Update modified time */ + fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ + fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */ + st_32(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); /* Update start cluster */ + st_64(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); /* Update file size */ + st_64(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); /* (FatFs does not support Valid File Size feature) */ + st_32(fs->dirbuf + XDIR_ModTime, GET_FATTIME()); /* Update modified time */ fs->dirbuf[XDIR_ModTime10] = 0; - st_dword(fs->dirbuf + XDIR_AccTime, 0); - res = store_xdir(&dj); /* Restore it to the directory */ + fs->dirbuf[XDIR_ModTZ] = 0; + st_32(fs->dirbuf + XDIR_AccTime, 0); /* Invalidate last access time */ + fs->dirbuf[XDIR_AccTZ] = 0; + res = store_xdir(&dj); /* Restore it to the directory */ if (res == FR_OK) { res = sync_fs(fs); fp->flag &= (BYTE)~FA_MODIFIED; } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } } else #endif { res = move_window(fs, fp->dir_sect); if (res == FR_OK) { - dir = fp->dir_ptr; - dir[DIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ - st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ - st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ - st_dword(dir + DIR_ModTime, tm); /* Update modified time */ - st_word(dir + DIR_LstAccDate, 0); + BYTE *dir = fp->dir_ptr; + + dir[DIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ + st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ + st_32(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ + st_32(dir + DIR_ModTime, GET_FATTIME()); /* Update modified time */ + st_16(dir + DIR_LstAccDate, 0); /* Invalidate last access date */ fs->wflag = 1; - res = sync_fs(fs); /* Restore it to the directory */ + res = sync_fs(fs); /* Restore it to the directory */ fp->flag &= (BYTE)~FA_MODIFIED; } } @@ -4146,7 +4296,7 @@ FRESULT f_sync ( /*-----------------------------------------------------------------------*/ -/* Close File */ +/* API: Close File */ /*-----------------------------------------------------------------------*/ FRESULT f_close ( @@ -4163,14 +4313,14 @@ 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 */ #endif #if FF_FS_REENTRANT - unlock_fs(fs, FR_OK); /* Unlock volume */ + unlock_volume(fs, FR_OK); /* Unlock volume */ #endif } } @@ -4182,7 +4332,7 @@ FRESULT f_close ( #if FF_FS_RPATH >= 1 /*-----------------------------------------------------------------------*/ -/* Change Current Directory or Current Drive, Get Current Directory */ +/* API: Change Current Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_chdrive ( @@ -4202,57 +4352,56 @@ FRESULT f_chdrive ( + +/*-----------------------------------------------------------------------*/ +/* API: Change Current Directory */ +/*-----------------------------------------------------------------------*/ + FRESULT f_chdir ( const TCHAR* path /* Pointer to the directory path */ ) { -#if FF_STR_VOLUME_ID == 2 - UINT i; -#endif FRESULT res; DIR dj; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF - /* Get logical drive */ - res = mount_volume(&path, &fs, 0); + res = mount_volume(&path, &fs, 0); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the path */ if (res == FR_OK) { /* Follow completed */ if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it the start directory itself? */ - fs->cdir = dj.obj.sclust; #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fs->cdc_scl = dj.obj.c_scl; - fs->cdc_size = dj.obj.c_size; - fs->cdc_ofs = dj.obj.c_ofs; + memcpy(&fs->xcwds, &fs->xcwds2, sizeof fs->xcwds); } #endif + fs->cdir = dj.obj.sclust; } else { if (dj.obj.attr & AM_DIR) { /* It is a sub-directory */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fs->cdir = ld_dword(fs->dirbuf + XDIR_FstClus); /* Sub-directory cluster */ - fs->cdc_scl = dj.obj.sclust; /* Save containing directory information */ - fs->cdc_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; - fs->cdc_ofs = dj.blk_ofs; + memcpy(&fs->xcwds, &fs->xcwds2, sizeof fs->xcwds); + fs->cdir = fs->xcwds.tbl[fs->xcwds.depth].d_scl; /* Sub-directory cluster */ } else #endif { - fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */ + fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */ } } else { res = FR_NO_PATH; /* Reached but a file */ } } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); if (res == FR_NO_FILE) res = FR_NO_PATH; #if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */ if (res == FR_OK) { + UINT i; + for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */ CurrVol = (BYTE)i; } @@ -4263,94 +4412,136 @@ FRESULT f_chdir ( } + + #if FF_FS_RPATH >= 2 +/*-----------------------------------------------------------------------*/ +/* API: Get Curent Directory */ +/*-----------------------------------------------------------------------*/ + FRESULT f_getcwd ( - TCHAR* buff, /* Pointer to the directory path */ + TCHAR* buff, /* Pointer to the buffer to store the current direcotry path */ UINT len /* Size of buff in unit of TCHAR */ ) { FRESULT res; DIR dj; FATFS *fs; - UINT i, n; - DWORD ccl; - TCHAR *tp = buff; #if FF_VOLUMES >= 2 UINT vl; #if FF_STR_VOLUME_ID - const char *vp; + const char *vid; #endif #endif FILINFO fno; - DEF_NAMBUF + DEF_NAMEBUFF - /* Get logical drive */ - buff[0] = 0; /* Set null string to get current volume */ - res = mount_volume((const TCHAR**)&buff, &fs, 0); /* Get current volume */ + buff[0] = 0; /* A null str to get current drive */ + res = mount_volume((const TCHAR**)&buff, &fs, 0); if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + UINT wi = 0; + UINT di, ni; + +#if FF_VOLUMES >= 2 /* Add drive prefix if needed */ +#if FF_STR_VOLUME_ID == 0 /* Numeric volume ID */ + if (wi < len) buff[wi++] = '0' + CurrVol; +#else /* String volume ID */ + if (FF_STR_VOLUME_ID == 2 && wi < len) buff[wi++] = '/'; + for (vid = (const char*)VolumeStr[CurrVol]; *vid && wi < len; buff[wi++] = *vid++) ; +#endif + if (FF_STR_VOLUME_ID <= 1 && wi < len) buff[wi++] = ':'; +#endif + if (wi < len) buff[wi++] = '/'; + for (di = 0; wi < len && di < fs->xcwds.depth; di++) { /* Follow current directory path with cwd structure */ + dj.obj.sclust = fs->xcwds.tbl[di].d_scl; /* Open this directory */ + dj.obj.stat = (BYTE)fs->xcwds.tbl[di].d_size; + dj.obj.objsize = fs->xcwds.tbl[di].d_size & 0xFFFFFF00; + res = dir_sdi(&dj, fs->xcwds.tbl[di].nxt_ofs); /* Find next directory */ + if (res != FR_OK) break; + res = DIR_READ_FILE(&dj); /* Get the directory name */ + if (res != FR_OK) break; + get_fileinfo(&dj, &fno); + if (di > 0 && wi < len) buff[wi++] = '/'; /* Add the directory name with a directory separator */ + for (ni = 0; fno.fname[ni] && wi < len; buff[wi++] = fno.fname[ni++]) ; + } + if (wi == len) { /* Buffer overflow? */ + res = FR_NOT_ENOUGH_CORE; + } else { + buff[wi] = 0; /* Terminate the string */ + } + } + else +#endif + { /* On the FAT/FAT32 volume */ + TCHAR *tp = buff; + UINT i, nl; + DWORD ccl; - /* Follow parent directories and create the path */ - i = len; /* Bottom of buffer (directory stack base) */ - if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* (Cannot do getcwd on exFAT and returns root path) */ + /* Follow parent directories toward the root directory and create the cwd path */ + i = len; /* Bottom of buffer (directory stack base) */ dj.obj.sclust = fs->cdir; /* Start to follow upper directory from current directory */ while ((ccl = dj.obj.sclust) != 0) { /* Repeat while current directory is a sub-directory */ - res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */ + res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */ if (res != FR_OK) break; res = move_window(fs, dj.sect); if (res != FR_OK) break; - dj.obj.sclust = ld_clust(fs, dj.dir); /* Goto parent directory */ + dj.obj.sclust = ld_clust(fs, dj.dir); /* Go to parent directory */ res = dir_sdi(&dj, 0); if (res != FR_OK) break; - do { /* Find the entry links to the child directory */ + do { /* Find the entry links to this sub-directory */ res = DIR_READ_FILE(&dj); if (res != FR_OK) break; if (ccl == ld_clust(fs, dj.dir)) break; /* Found the entry */ res = dir_next(&dj, 0); } while (res == FR_OK); - if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ + if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be 'not found'. */ if (res != FR_OK) break; - get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ - for (n = 0; fno.fname[n]; n++) ; /* Name length */ - if (i < n + 1) { /* Insufficient space to store the path name? */ + get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ + for (nl = 0; fno.fname[nl]; nl++) ; /* Name length */ + if (i < nl + 1) { /* Insufficient space to store the path name? */ res = FR_NOT_ENOUGH_CORE; break; } - while (n) buff[--i] = fno.fname[--n]; /* Stack the name */ + while (nl) buff[--i] = fno.fname[--nl]; /* Stack the name */ buff[--i] = '/'; } - } - if (res == FR_OK) { - if (i == len) buff[--i] = '/'; /* Is it the root-directory? */ + if (res == FR_OK) { + if (i == len) buff[--i] = '/'; /* Is it the root-directory? */ #if FF_VOLUMES >= 2 /* Put drive prefix */ - vl = 0; + vl = 0; #if FF_STR_VOLUME_ID >= 1 /* String volume ID */ - for (n = 0, vp = (const char*)VolumeStr[CurrVol]; vp[n]; n++) ; - if (i >= n + 2) { - if (FF_STR_VOLUME_ID == 2) *tp++ = (TCHAR)'/'; - for (vl = 0; vl < n; *tp++ = (TCHAR)vp[vl], vl++) ; - if (FF_STR_VOLUME_ID == 1) *tp++ = (TCHAR)':'; - vl++; - } + for (nl = 0, vid = (const char*)VolumeStr[CurrVol]; vid[nl]; nl++) ; /* Volume ID length */ + if (i >= nl + 2) { + if (FF_STR_VOLUME_ID == 2) *tp++ = '/'; /* Unix style */ + for (vl = 0; vl < nl; *tp++ = vid[vl], vl++) ; + if (FF_STR_VOLUME_ID == 1) *tp++ = ':'; /* DOS/Windows style */ + vl++; + } #else /* Numeric volume ID */ - if (i >= 3) { - *tp++ = (TCHAR)'0' + CurrVol; - *tp++ = (TCHAR)':'; - vl = 2; - } + if (i >= 3) { + *tp++ = '0' + CurrVol; + *tp++ = ':'; + vl = 2; + } #endif - if (vl == 0) res = FR_NOT_ENOUGH_CORE; + if (vl == 0) res = FR_NOT_ENOUGH_CORE; #endif - /* Add current directory path */ - if (res == FR_OK) { - do *tp++ = buff[i++]; while (i < len); /* Copy stacked path string */ + /* Add current directory path */ + if (res == FR_OK) { + do { /* Copy stacked path string */ + *tp++ = buff[i++]; + } while (i < len); + } } + *tp = 0; } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } - *tp = 0; LEAVE_FF(fs, res); } @@ -4361,7 +4552,7 @@ FRESULT f_getcwd ( #if FF_FS_MINIMIZE <= 2 /*-----------------------------------------------------------------------*/ -/* Seek File Read/Write Pointer */ +/* API: Seek File Read/Write Pointer */ /*-----------------------------------------------------------------------*/ FRESULT f_lseek ( @@ -4374,11 +4565,7 @@ FRESULT f_lseek ( DWORD clst, bcs; LBA_t nsect; FSIZE_t ifptr; -#if FF_USE_FASTSEEK - DWORD cl, pcl, ncl, tcl, tlen, ulen; - DWORD *tbl; - LBA_t dsc; -#endif + res = validate(&fp->obj, &fs); /* Check validity of the file object */ if (res == FR_OK) res = (FRESULT)fp->err; @@ -4391,6 +4578,10 @@ FRESULT f_lseek ( #if FF_USE_FASTSEEK if (fp->cltbl) { /* Fast seek */ + DWORD cl, pcl, ncl, tcl, tlen, ulen; + DWORD *tbl; + LBA_t dsc; + if (ofs == CREATE_LINKMAP) { /* Create CLMT */ tbl = fp->cltbl; tlen = *tbl++; ulen = 2; /* Given table size and required table size */ @@ -4525,7 +4716,7 @@ FRESULT f_lseek ( #if FF_FS_MINIMIZE <= 1 /*-----------------------------------------------------------------------*/ -/* Create a Directory Object */ +/* API: Create a Directory Object */ /*-----------------------------------------------------------------------*/ FRESULT f_opendir ( @@ -4535,26 +4726,22 @@ FRESULT f_opendir ( { FRESULT res; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF - if (!dp) return FR_INVALID_OBJECT; + if (!dp) return FR_INVALID_OBJECT; /* Reject null pointer */ - /* Get logical drive */ - res = mount_volume(&path, &fs, 0); + res = mount_volume(&path, &fs, 0); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dp->obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(dp, path); /* Follow the path to the directory */ if (res == FR_OK) { /* Follow completed */ - if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is not the origin directory itself */ + if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is neither the origin directory itself nor dot name in exFAT */ if (dp->obj.attr & AM_DIR) { /* This object is a sub-directory */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - dp->obj.c_scl = dp->obj.sclust; /* Get containing directory inforamation */ - dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; - dp->obj.c_ofs = dp->blk_ofs; - init_alloc_info(fs, &dp->obj); /* Get object allocation info */ + init_alloc_info(&dp->obj, dp); /* Get object allocation info */ } else #endif { @@ -4565,24 +4752,24 @@ FRESULT f_opendir ( } } if (res == FR_OK) { - dp->obj.id = fs->id; - res = dir_sdi(dp, 0); /* Rewind directory */ -#if FF_FS_LOCK != 0 + dp->obj.id = fs->id; /* Set current volume mount ID */ + res = dir_sdi(dp, 0); /* Rewind directory */ +#if FF_FS_LOCK if (res == FR_OK) { - if (dp->obj.sclust != 0) { - dp->obj.lockid = inc_lock(dp, 0); /* Lock the sub directory */ + if (dp->obj.sclust) { /* Is this a 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 */ + dp->obj.lockid = 0; /* Root directory does not need to be locked */ } } #endif } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); 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); } @@ -4591,7 +4778,7 @@ FRESULT f_opendir ( /*-----------------------------------------------------------------------*/ -/* Close Directory */ +/* API: Close Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_closedir ( @@ -4604,14 +4791,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_volume(fs, FR_OK); /* Unlock volume */ #endif } return res; @@ -4621,7 +4808,7 @@ FRESULT f_closedir ( /*-----------------------------------------------------------------------*/ -/* Read Directory Entries in Sequence */ +/* API: Read Directory Entries in Sequence */ /*-----------------------------------------------------------------------*/ FRESULT f_readdir ( @@ -4631,15 +4818,16 @@ FRESULT f_readdir ( { FRESULT res; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF 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); + INIT_NAMEBUFF(fs); + fno->fname[0] = 0; /* Clear file information */ res = DIR_READ_FILE(dp); /* Read an item */ if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory */ if (res == FR_OK) { /* A valid entry is found */ @@ -4647,9 +4835,11 @@ FRESULT f_readdir ( res = dir_next(dp, 0); /* Increment index for next */ if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory now */ } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } } + + if (fno && res != FR_OK) fno->fname[0] = 0; /* Clear the file information if any error occured */ LEAVE_FF(fs, res); } @@ -4657,7 +4847,7 @@ FRESULT f_readdir ( #if FF_USE_FIND /*-----------------------------------------------------------------------*/ -/* Find Next File */ +/* API: Find Next File */ /*-----------------------------------------------------------------------*/ FRESULT f_findnext ( @@ -4682,7 +4872,7 @@ FRESULT f_findnext ( /*-----------------------------------------------------------------------*/ -/* Find First File */ +/* API: Find First File */ /*-----------------------------------------------------------------------*/ FRESULT f_findfirst ( @@ -4709,7 +4899,7 @@ FRESULT f_findfirst ( #if FF_FS_MINIMIZE == 0 /*-----------------------------------------------------------------------*/ -/* Get File Status */ +/* API: Get File Status */ /*-----------------------------------------------------------------------*/ FRESULT f_stat ( @@ -4719,13 +4909,14 @@ FRESULT f_stat ( { FRESULT res; DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF - /* Get logical drive */ + /* Get logical drive and mount the volume if needed */ res = mount_volume(&path, &dj.obj.fs, 0); + if (res == FR_OK) { - INIT_NAMBUF(dj.obj.fs); + INIT_NAMEBUFF(dj.obj.fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK) { /* Follow completed */ if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */ @@ -4734,9 +4925,10 @@ FRESULT f_stat ( if (fno) get_fileinfo(&dj, fno); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } + if (fno && res != FR_OK) fno->fname[0] = 0; /* Invalidate the file information if an error occured */ LEAVE_FF(dj.obj.fs, res); } @@ -4744,13 +4936,13 @@ FRESULT f_stat ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Get Number of Free Clusters */ +/* API: Get Number of Free Clusters */ /*-----------------------------------------------------------------------*/ FRESULT f_getfree ( const TCHAR* path, /* Logical drive number */ DWORD* nclst, /* Pointer to a variable to return number of free clusters */ - FATFS** fatfs /* Pointer to return pointer to corresponding filesystem object */ + FATFS** fatfs /* Pointer to a pointer to return corresponding filesystem object */ ) { FRESULT res; @@ -4761,22 +4953,27 @@ FRESULT f_getfree ( FFOBJID obj; - /* Get logical drive */ + /* Get logical drive and mount the volume if needed */ res = mount_volume(&path, &fs, 0); + if (res == FR_OK) { *fatfs = fs; /* Return ptr to the fs object */ /* If free_clst is valid, return it without full FAT scan */ if (fs->free_clst <= fs->n_fatent - 2) { *nclst = fs->free_clst; } else { - /* Scan FAT to obtain number of free clusters */ + /* Scan FAT to obtain the correct free cluster count */ nfree = 0; if (fs->fs_type == FS_FAT12) { /* FAT12: Scan bit field FAT 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 { @@ -4788,16 +4985,16 @@ FRESULT f_getfree ( clst = fs->n_fatent - 2; /* Number of clusters */ sect = fs->bitbase; /* Bitmap sector */ i = 0; /* Offset in the sector */ - do { /* Counts numbuer of bits with zero in the bitmap */ - if (i == 0) { + do { /* Counts numbuer of clear bits (free clusters) in the bitmap */ + if (i == 0) { /* New sector? */ res = move_window(fs, sect++); if (res != FR_OK) break; } - for (b = 8, bm = fs->win[i]; b && clst; b--, clst--) { - if (!(bm & 1)) nfree++; + for (b = 8, bm = ~fs->win[i]; b && clst; b--, clst--) { /* Count clear bits in a byte */ + nfree += bm & 1; bm >>= 1; } - i = (i + 1) % SS(fs); + i = (i + 1) % SS(fs); /* Next byte */ } while (clst); } else #endif @@ -4806,16 +5003,16 @@ FRESULT f_getfree ( sect = fs->fatbase; /* Top of the FAT */ i = 0; /* Offset in the sector */ do { /* Counts numbuer of entries with zero in the FAT */ - if (i == 0) { + if (i == 0) { /* New sector? */ res = move_window(fs, sect++); if (res != FR_OK) break; } if (fs->fs_type == FS_FAT16) { - if (ld_word(fs->win + i) == 0) nfree++; - i += 2; + if (ld_16(fs->win + i) == 0) nfree++; /* FAT16: Is this cluster free? */ + i += 2; /* Next entry */ } else { - if ((ld_dword(fs->win + i) & 0x0FFFFFFF) == 0) nfree++; - i += 4; + if ((ld_32(fs->win + i) & 0x0FFFFFFF) == 0) nfree++; /* FAT32: Is this cluster free? */ + i += 4; /* Next entry */ } i %= SS(fs); } while (--clst); @@ -4823,8 +5020,8 @@ FRESULT f_getfree ( } if (res == FR_OK) { /* Update parameters if succeeded */ *nclst = nfree; /* Return the free clusters */ - fs->free_clst = nfree; /* Now free_clst is valid */ - fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */ + fs->free_clst = nfree; /* Now free cluster count is valid */ + fs->fsi_flag |= 1; /* FAT32/exfAT : Allocation information is to be updated */ } } } @@ -4836,7 +5033,7 @@ FRESULT f_getfree ( /*-----------------------------------------------------------------------*/ -/* Truncate File */ +/* API: Truncate File */ /*-----------------------------------------------------------------------*/ FRESULT f_truncate ( @@ -4848,7 +5045,8 @@ FRESULT f_truncate ( DWORD ncl; - res = validate(&fp->obj, &fs); /* Check validity of the file object */ + /* Check validity of the file object */ + res = validate(&fp->obj, &fs); if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */ @@ -4886,7 +5084,7 @@ FRESULT f_truncate ( /*-----------------------------------------------------------------------*/ -/* Delete a File/Directory */ +/* API: Delete a File/Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_unlink ( @@ -4894,83 +5092,78 @@ FRESULT f_unlink ( ) { FRESULT res; + FATFS *fs; DIR dj, sdj; DWORD dclst = 0; - FATFS *fs; #if FF_FS_EXFAT FFOBJID obj; #endif - DEF_NAMBUF + DEF_NAMEBUFF - - /* Get logical drive */ + /* Get logical drive and mount the volume if needed */ res = mount_volume(&path, &fs, FA_WRITE); if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); - res = follow_path(&dj, path); /* Follow the file path */ - if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) { - res = FR_INVALID_NAME; /* Cannot remove dot entry */ - } -#if FF_FS_LOCK != 0 - if (res == FR_OK) res = chk_lock(&dj, 2); /* Check if it is an open object */ -#endif - if (res == FR_OK) { /* The object is accessible */ - if (dj.fn[NSFLAG] & NS_NONAME) { - res = FR_INVALID_NAME; /* Cannot remove the origin directory */ + INIT_NAMEBUFF(fs); + res = follow_path(&dj, path); /* Follow the path to the object */ + if (res == FR_OK) { + if (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME)) { + res = FR_INVALID_NAME; /* It must be a real object */ + } else if (dj.obj.attr & AM_RDO) { + res = FR_DENIED; /* The object must not be read-only */ +#if FF_FS_LOCK } else { - if (dj.obj.attr & AM_RDO) { - res = FR_DENIED; /* Cannot remove R/O object */ - } + res = chk_share(&dj, 2); /* Check if the object is in use */ +#endif } - if (res == FR_OK) { + } + if (res == FR_OK) { /* The object is accessible */ #if FF_FS_EXFAT - obj.fs = fs; - if (fs->fs_type == FS_EXFAT) { - init_alloc_info(fs, &obj); - dclst = obj.sclust; + obj.fs = fs; + if (fs->fs_type == FS_EXFAT) { + init_alloc_info(&obj, 0); + dclst = obj.sclust; + } else +#endif + { + dclst = ld_clust(fs, dj.dir); + } + if (dj.obj.attr & AM_DIR) { /* Is the object a sub-directory? */ +#if FF_FS_RPATH + if (dclst == fs->cdir) { + res = FR_DENIED; /* Current directory cannot be removed */ } else #endif { - dclst = ld_clust(fs, dj.dir); - } - if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */ -#if FF_FS_RPATH != 0 - if (dclst == fs->cdir) { /* Is it the current directory? */ - res = FR_DENIED; - } else -#endif - { - sdj.obj.fs = fs; /* Open the sub-directory */ - sdj.obj.sclust = dclst; + sdj.obj.fs = fs; /* Open the sub-directory */ + sdj.obj.sclust = dclst; #if FF_FS_EXFAT - if (fs->fs_type == FS_EXFAT) { - sdj.obj.objsize = obj.objsize; - sdj.obj.stat = obj.stat; - } + if (fs->fs_type == FS_EXFAT) { + sdj.obj.objsize = obj.objsize; + sdj.obj.stat = obj.stat; + } #endif - res = dir_sdi(&sdj, 0); - if (res == FR_OK) { - res = DIR_READ_FILE(&sdj); /* Test if the directory is empty */ - if (res == FR_OK) res = FR_DENIED; /* Not empty? */ - if (res == FR_NO_FILE) res = FR_OK; /* Empty? */ - } + res = dir_sdi(&sdj, 0); + if (res == FR_OK) { + res = DIR_READ_FILE(&sdj); /* Check if the sub-directory is empty */ + if (res == FR_OK) res = FR_DENIED; /* Not empty? */ + if (res == FR_NO_FILE) res = FR_OK; /* Empty? */ } } } - if (res == FR_OK) { - res = dir_remove(&dj); /* Remove the directory entry */ - if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ + } + if (res == FR_OK) { /* It is ready to remove the object */ + res = dir_remove(&dj); /* Remove the directory entry */ + if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ #if FF_FS_EXFAT - res = remove_chain(&obj, dclst, 0); + res = remove_chain(&obj, dclst, 0); #else - res = remove_chain(&dj.obj, dclst, 0); + res = remove_chain(&dj.obj, dclst, 0); #endif - } - if (res == FR_OK) res = sync_fs(fs); } + if (res == FR_OK) res = sync_fs(fs); } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -4980,7 +5173,7 @@ FRESULT f_unlink ( /*-----------------------------------------------------------------------*/ -/* Create a Directory */ +/* API: Create a Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_mkdir ( @@ -4988,24 +5181,23 @@ FRESULT f_mkdir ( ) { FRESULT res; + FATFS *fs; DIR dj; FFOBJID sobj; - FATFS *fs; DWORD dcl, pcl, tm; - DEF_NAMBUF + DEF_NAMEBUFF - res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */ + res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ - if (res == FR_OK) res = FR_EXIST; /* Name collision? */ - if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) { /* Invalid name? */ - res = FR_INVALID_NAME; + if (res == FR_OK) { /* Invalid name or name collision */ + res = (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME)) ? FR_INVALID_NAME : FR_EXIST; } if (res == FR_NO_FILE) { /* It is clear to create a new directory */ - sobj.fs = fs; /* New object id to create a new chain */ + sobj.fs = fs; /* New object ID to create a new chain */ dcl = create_chain(&sobj, 0); /* Allocate a cluster for the new directory */ res = FR_OK; if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster? */ @@ -5013,36 +5205,38 @@ FRESULT f_mkdir ( if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; /* Disk error? */ tm = GET_FATTIME(); if (res == FR_OK) { - res = dir_clear(fs, dcl); /* Clean up the new table */ + res = dir_clear(fs, dcl); /* Clear the allocated cluster as new direcotry table */ if (res == FR_OK) { if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */ memset(fs->win + DIR_Name, ' ', 11); /* Create "." entry */ fs->win[DIR_Name] = '.'; fs->win[DIR_Attr] = AM_DIR; - st_dword(fs->win + DIR_ModTime, tm); + st_32(fs->win + DIR_ModTime, tm); st_clust(fs, fs->win, dcl); memcpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */ fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust; st_clust(fs, fs->win + SZDIRE, pcl); fs->wflag = 1; } - res = dir_register(&dj); /* Register the object to the parent directoy */ + res = dir_register(&dj); /* Register the object to the parent directory */ } } if (res == FR_OK) { #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* Initialize directory entry block */ - st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Created time */ - st_dword(fs->dirbuf + XDIR_FstClus, dcl); /* Table start cluster */ - st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs)); /* Directory size needs to be valid */ - st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs)); - fs->dirbuf[XDIR_GenFlags] = 3; /* Initialize the object flag */ - fs->dirbuf[XDIR_Attr] = AM_DIR; /* Attribute */ + st_32(fs->dirbuf + XDIR_CrtTime, tm); /* Created time */ + st_32(fs->dirbuf + XDIR_ModTime, tm); + st_32(fs->dirbuf + XDIR_FstClus, dcl); /* Table start cluster */ + st_32(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs)); /* Directory size needs to be valid */ + st_32(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs)); + fs->dirbuf[XDIR_GenFlags] = 3; /* Initialize the object flag */ + fs->dirbuf[XDIR_Attr] = AM_DIR; /* Attribute */ res = store_xdir(&dj); } else #endif { - st_dword(dj.dir + DIR_ModTime, tm); /* Created time */ + st_32(dj.dir + DIR_CrtTime, tm); /* Created time */ + st_32(dj.dir + DIR_ModTime, tm); st_clust(fs, dj.dir, dcl); /* Table start cluster */ dj.dir[DIR_Attr] = AM_DIR; /* Attribute */ fs->wflag = 1; @@ -5054,7 +5248,7 @@ FRESULT f_mkdir ( remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */ } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5064,7 +5258,7 @@ FRESULT f_mkdir ( /*-----------------------------------------------------------------------*/ -/* Rename a File/Directory */ +/* API: Rename a File/Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_rename ( @@ -5073,45 +5267,58 @@ FRESULT f_rename ( ) { FRESULT res; - DIR djo, djn; FATFS *fs; + DIR djo, djn; BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir; - LBA_t sect; - DEF_NAMBUF + DEF_NAMEBUFF - get_ldnumber(&path_new); /* Snip the drive number of new name off */ + get_ldnumber(&path_new); /* Snip the drive number of new name off */ res = mount_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */ if (res == FR_OK) { djo.obj.fs = fs; - 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 + INIT_NAMEBUFF(fs); + res = follow_path(&djo, path_old); /* Check old object */ if (res == FR_OK) { - res = chk_lock(&djo, 2); - } + if (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME)) { + res = FR_INVALID_NAME; /* Object must not be a dot name or blank name */ +#if FF_FS_LOCK + } else { + res = chk_share(&djo, 2); /* Check if the object is in use */ #endif - if (res == FR_OK) { /* Object to be renamed is found */ + } + } + if (res == FR_OK) { /* It is ready to rename the object */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */ - BYTE nf, nn; - WORD nh; +#if FF_FS_RPATH + UINT i; + DWORD dscl = ld_32(fs->dirbuf + XDIR_FstClus); - memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */ - memcpy(&djn, &djo, sizeof djo); - res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ - if (res == FR_OK) { /* Is new name already in use by any other object? */ + for (i = 1; i <= fs->xcwds.depth && dscl != fs->xcwds.tbl[i].d_scl; i++) ; /* Check if the object is a sub-dir in the current dir path */ + if (i <= fs->xcwds.depth) { + res = FR_DENIED; /* Reject to rename a sub-dir in the current dir path */ + } else +#endif + { + memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */ + memcpy(&djn, &djo, sizeof djn); + res = follow_path(&djn, path_new); /* Check if new object name collides with an existing one */ + } + if (res == FR_OK) { /* Is new name already in use by another object? */ res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; } - if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ - res = dir_register(&djn); /* Register the new entry */ + if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ + res = dir_register(&djn); /* Register the new entry */ if (res == FR_OK) { - nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName]; - nh = ld_word(fs->dirbuf + XDIR_NameHash); + BYTE nf, nn; + WORD nh; + + nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName]; /* Save name length and hash */ + nh = ld_16(fs->dirbuf + XDIR_NameHash); memcpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */ - fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn; - st_word(fs->dirbuf + XDIR_NameHash, nh); + fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn; /* Restore name length and hash */ + st_16(fs->dirbuf + XDIR_NameHash, nh); if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ /* Start of critical section where an interruption can cause a cross-link */ res = store_xdir(&djn); @@ -5121,9 +5328,9 @@ FRESULT f_rename ( #endif { /* At FAT/FAT32 volume */ memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */ - memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */ + memcpy(&djn, &djo, sizeof djn); /* Duplicate the directory object */ res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ - if (res == FR_OK) { /* Is new name already in use by any other object? */ + if (res == FR_OK) { /* Is new name already in use by another object? */ res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; } if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ @@ -5134,14 +5341,15 @@ FRESULT f_rename ( dir[DIR_Attr] = buf[DIR_Attr]; if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ fs->wflag = 1; - if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory if needed */ - sect = clst2sect(fs, ld_clust(fs, dir)); + if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory being moved if needed */ + LBA_t sect = clst2sect(fs, ld_clust(fs, dir)); + if (sect == 0) { res = FR_INT_ERR; } else { /* Start of critical section where an interruption can cause a cross-link */ res = move_window(fs, sect); - dir = fs->win + SZDIRE * 1; /* Ptr to .. entry */ + dir = fs->win + SZDIRE * 1; /* Pointer to .. entry */ if (res == FR_OK && dir[1] == '.') { st_clust(fs, dir, djn.obj.sclust); fs->wflag = 1; @@ -5151,15 +5359,15 @@ FRESULT f_rename ( } } } - if (res == FR_OK) { - res = dir_remove(&djo); /* Remove old entry */ + if (res == FR_OK) { /* New entry has been created */ + res = dir_remove(&djo); /* Remove old entry */ if (res == FR_OK) { res = sync_fs(fs); } } /* End of the critical section */ } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5174,25 +5382,27 @@ FRESULT f_rename ( #if FF_USE_CHMOD && !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Change Attribute */ +/* API: Change Attribute */ /*-----------------------------------------------------------------------*/ FRESULT f_chmod ( const TCHAR* path, /* Pointer to the file path */ - BYTE attr, /* Attribute bits */ + BYTE attr, /* Attribute bits to set/clear */ BYTE mask /* Attribute mask to change */ ) { FRESULT res; - DIR dj; FATFS *fs; - DEF_NAMBUF + DIR dj; + DEF_NAMEBUFF + + /* Get logical drive and mount the volume if needed */ + res = mount_volume(&path, &fs, FA_WRITE); - res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */ if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ if (res == FR_OK) { @@ -5211,7 +5421,7 @@ FRESULT f_chmod ( res = sync_fs(fs); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5221,42 +5431,63 @@ FRESULT f_chmod ( /*-----------------------------------------------------------------------*/ -/* Change Timestamp */ +/* API: Change Timestamp */ /*-----------------------------------------------------------------------*/ FRESULT f_utime ( const TCHAR* path, /* Pointer to the file/directory name */ - const FILINFO* fno /* Pointer to the timestamp to be set */ + const FILINFO* fno /* Timestamp to be set */ ) { FRESULT res; - DIR dj; FATFS *fs; - DEF_NAMBUF + DIR dj; + DEF_NAMEBUFF - res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */ + /* Get logical drive and mount the volume if needed */ + res = mount_volume(&path, &fs, FA_WRITE); + if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ if (res == FR_OK) { #if FF_FS_EXFAT - if (fs->fs_type == FS_EXFAT) { - st_dword(fs->dirbuf + XDIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + if (fno->fdate) { /* Change last modified time if needed */ + st_32(fs->dirbuf + XDIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + fs->dirbuf[XDIR_ModTime10] = 0; + fs->dirbuf[XDIR_ModTZ] = 0; + } +#if FF_FS_CRTIME + if (fno->crdate) { /* Change created time if needed */ + st_32(fs->dirbuf + XDIR_CrtTime, (DWORD)fno->crdate << 16 | fno->crtime); + fs->dirbuf[XDIR_CrtTime10] = 0; + fs->dirbuf[XDIR_CrtTZ] = 0; + } +#endif res = store_xdir(&dj); } else #endif - { - st_dword(dj.dir + DIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + { /* On the FAT volume */ + if (fno->fdate) { /* Change last modified time if needed */ + st_32(dj.dir + DIR_ModTime, (DWORD)fno->fdate << 16 | fno->ftime); + } +#if FF_FS_CRTIME + if (fno->crdate) { /* Change created time if needed */ + st_32(dj.dir + DIR_CrtTime, (DWORD)fno->crdate << 16 | fno->crtime); + dj.dir[DIR_CrtTime10] = 0; + } +#endif fs->wflag = 1; } if (res == FR_OK) { res = sync_fs(fs); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5268,7 +5499,7 @@ FRESULT f_utime ( #if FF_USE_LABEL /*-----------------------------------------------------------------------*/ -/* Get Volume Label */ +/* API: Get Volume Label */ /*-----------------------------------------------------------------------*/ FRESULT f_getlabel ( @@ -5278,13 +5509,13 @@ FRESULT f_getlabel ( ) { FRESULT res; - DIR dj; FATFS *fs; + DIR dj; UINT si, di; WCHAR wc; - /* Get logical drive */ - res = mount_volume(&path, &fs, 0); + + res = mount_volume(&path, &fs, 0); /* Get logical drive and mount the volume if needed */ /* Get volume label */ if (res == FR_OK && label) { @@ -5299,12 +5530,14 @@ FRESULT f_getlabel ( UINT nw; for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++) { /* Extract volume label from 83 entry */ - wc = ld_word(dj.dir + XDIR_Label + si * 2); + wc = ld_16(dj.dir + XDIR_Label + si * 2); if (hs == 0 && IsSurrogate(wc)) { /* Is the code a surrogate? */ hs = wc; continue; } nw = put_utf((DWORD)hs << 16 | wc, &label[di], 4); /* Store it in API encoding */ - if (nw == 0) { di = 0; break; } /* Encode error? */ + if (nw == 0) { /* Encode error? */ + di = 0; break; + } di += nw; hs = 0; } @@ -5319,7 +5552,9 @@ FRESULT f_getlabel ( #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) { di = 0; break; } /* Invalid char in current code page? */ + 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; @@ -5340,7 +5575,7 @@ FRESULT f_getlabel ( /* Get volume serial number */ if (res == FR_OK && vsn) { - res = move_window(fs, fs->volbase); + res = move_window(fs, fs->volbase); /* Load VBR */ if (res == FR_OK) { switch (fs->fs_type) { case FS_EXFAT: @@ -5351,10 +5586,10 @@ FRESULT f_getlabel ( di = BS_VolID32; break; - default: - di = BS_VolID; + default: /* FAT12/16 */ + di = fs->win[BS_BootSig] == 0x29 ? BS_VolID : 0; } - *vsn = ld_dword(fs->win + di); + *vsn = di ? ld_32(fs->win + di) : 0; /* Get VSN in the VBR */ } } @@ -5365,7 +5600,7 @@ FRESULT f_getlabel ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Set Volume Label */ +/* API: Set Volume Label */ /*-----------------------------------------------------------------------*/ FRESULT f_setlabel ( @@ -5373,8 +5608,8 @@ FRESULT f_setlabel ( ) { FRESULT res; - DIR dj; FATFS *fs; + DIR dj; BYTE dirvn[22]; UINT di; WCHAR wc; @@ -5383,9 +5618,12 @@ FRESULT f_setlabel ( DWORD dc; #endif - /* Get logical drive */ + /* Get logical drive and mount the volume if needed */ res = mount_volume(&label, &fs, FA_WRITE); if (res != FR_OK) LEAVE_FF(fs, res); +#if FF_STR_VOLUME_ID == 2 + for ( ; *label == '/'; label++) ; /* Snip the separators off */ +#endif #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ @@ -5397,13 +5635,13 @@ FRESULT f_setlabel ( if (dc == 0xFFFFFFFF || di >= 10) { /* Wrong surrogate or buffer overflow */ dc = 0; } else { - st_word(dirvn + di * 2, (WCHAR)(dc >> 16)); di++; + st_16(dirvn + di * 2, (WCHAR)(dc >> 16)); di++; } } if (dc == 0 || strchr(&badchr[7], (int)dc) || di >= 11) { /* Check validity of the volume label */ LEAVE_FF(fs, FR_INVALID_NAME); } - st_word(dirvn + di * 2, (WCHAR)dc); di++; + st_16(dirvn + di * 2, (WCHAR)dc); di++; } } else #endif @@ -5485,7 +5723,7 @@ FRESULT f_setlabel ( #if FF_USE_EXPAND && !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Allocate a Contiguous Blocks to the File */ +/* API: Allocate a Contiguous Blocks to the File */ /*-----------------------------------------------------------------------*/ FRESULT f_expand ( @@ -5530,14 +5768,20 @@ FRESULT f_expand ( for (;;) { /* Find a contiguous cluster block */ n = get_fat(&fp->obj, clst); if (++clst >= fs->n_fatent) clst = 2; - if (n == 1) { res = FR_INT_ERR; break; } - if (n == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } + if (n == 1) { + res = FR_INT_ERR; break; + } + if (n == 0xFFFFFFFF) { + res = FR_DISK_ERR; break; + } if (n == 0) { /* Is it a free cluster? */ if (++ncl == tcl) break; /* Break if a contiguous cluster block is found */ } else { scl = clst; ncl = 0; /* Not a free cluster */ } - if (clst == stcl) { res = FR_DENIED; break; } /* No contiguous cluster? */ + if (clst == stcl) { /* No contiguous cluster? */ + res = FR_DENIED; break; + } } if (res == FR_OK) { /* A contiguous free area is found */ if (opt) { /* Allocate it now */ @@ -5575,7 +5819,7 @@ FRESULT f_expand ( #if FF_USE_FORWARD /*-----------------------------------------------------------------------*/ -/* Forward Data to the Stream Directly */ +/* API: Forward Data to the Stream Directly */ /*-----------------------------------------------------------------------*/ FRESULT f_forward ( @@ -5646,12 +5890,12 @@ FRESULT f_forward ( #if !FF_FS_READONLY && FF_USE_MKFS /*-----------------------------------------------------------------------*/ -/* Create FAT/exFAT volume (with sub-functions) */ +/* API: Create FAT/exFAT volume (with a sub-function) */ /*-----------------------------------------------------------------------*/ #define N_SEC_TRACK 63 /* Sectors per track for determination of drive CHS */ #define GPT_ALIGN 0x100000 /* Alignment of partitions in GPT [byte] (>=128KB) */ -#define GPT_ITEMS 128 /* Number of GPT table size (>=128, sector aligned) */ +#define GPT_ITEMS 128 /* Number of GPT table items (>=128, sector aligned) */ /* Create partitions on the physical drive in format of MBR or GPT */ @@ -5659,8 +5903,8 @@ FRESULT f_forward ( static FRESULT create_partition ( BYTE drv, /* Physical drive number */ const LBA_t plst[], /* Partition list */ - BYTE sys, /* System ID (for only MBR, temp setting) */ - BYTE* buf /* Working buffer for a sector */ + BYTE sys, /* System ID for each partition (for only MBR) */ + BYTE *buf /* Working buffer for a sector */ ) { UINT i, cy; @@ -5689,19 +5933,19 @@ static FRESULT create_partition ( rnd = (DWORD)sz_drv + GET_FATTIME(); /* Random seed */ align = GPT_ALIGN / ss; /* Partition alignment for GPT [sector] */ sz_ptbl = GPT_ITEMS * SZ_GPTE / ss; /* Size of partition table [sector] */ - top_bpt = sz_drv - sz_ptbl - 1; /* Backup partiiton table start sector */ - nxt_alloc = 2 + sz_ptbl; /* First allocatable sector */ - sz_pool = top_bpt - nxt_alloc; /* Size of allocatable area */ + top_bpt = sz_drv - sz_ptbl - 1; /* Backup partition table start LBA */ + nxt_alloc = 2 + sz_ptbl; /* First allocatable LBA */ + sz_pool = top_bpt - nxt_alloc; /* Size of allocatable area [sector] */ bcc = 0xFFFFFFFF; sz_part = 1; - pi = si = 0; /* partition table index, size table index */ + pi = si = 0; /* partition table index, map index */ do { if (pi * SZ_GPTE % ss == 0) memset(buf, 0, ss); /* Clean the buffer if needed */ if (sz_part != 0) { /* Is the size table not termintated? */ - nxt_alloc = (nxt_alloc + align - 1) & ((QWORD)0 - align); /* Align partition start */ + nxt_alloc = (nxt_alloc + align - 1) & ((QWORD)0 - align); /* Align partition start LBA */ sz_part = plst[si++]; /* Get a partition size */ if (sz_part <= 100) { /* Is the size in percentage? */ - sz_part = sz_pool * sz_part / 100; - sz_part = (sz_part + align - 1) & ((QWORD)0 - align); /* Align partition end (only if in percentage) */ + sz_part = sz_pool * sz_part / 100; /* Sectors in percentage */ + sz_part = (sz_part + align - 1) & ((QWORD)0 - align); /* Align partition end LBA (only if in percentage) */ } if (nxt_alloc + sz_part > top_bpt) { /* Clip the size at end of the pool */ sz_part = (nxt_alloc < top_bpt) ? top_bpt - nxt_alloc : 0; @@ -5711,11 +5955,11 @@ static FRESULT create_partition ( ofs = pi * SZ_GPTE % ss; memcpy(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16); /* Set partition GUID (Microsoft Basic Data) */ rnd = make_rand(rnd, buf + ofs + GPTE_UpGuid, 16); /* Set unique partition GUID */ - st_qword(buf + ofs + GPTE_FstLba, nxt_alloc); /* Set partition start sector */ - st_qword(buf + ofs + GPTE_LstLba, nxt_alloc + sz_part - 1); /* Set partition end sector */ - nxt_alloc += sz_part; /* Next allocatable sector */ + st_64(buf + ofs + GPTE_FstLba, nxt_alloc); /* Set partition start LBA */ + st_64(buf + ofs + GPTE_LstLba, nxt_alloc + sz_part - 1); /* Set partition end LBA */ + nxt_alloc += sz_part; /* Next allocatable LBA */ } - if ((pi + 1) * SZ_GPTE % ss == 0) { /* Write the buffer if it is filled up */ + if ((pi + 1) * SZ_GPTE % ss == 0) { /* Write the sector buffer if it is filled up */ for (i = 0; i < ss; bcc = crc32(bcc, buf[i++])) ; /* Calculate table check sum */ if (disk_write(drv, buf, 2 + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to primary table */ if (disk_write(drv, buf, top_bpt + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to secondary table */ @@ -5725,32 +5969,32 @@ static FRESULT create_partition ( /* Create primary GPT header */ memset(buf, 0, ss); memcpy(buf + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16); /* Signature, version (1.0) and size (92) */ - st_dword(buf + GPTH_PtBcc, ~bcc); /* Table check sum */ - st_qword(buf + GPTH_CurLba, 1); /* LBA of this header */ - st_qword(buf + GPTH_BakLba, sz_drv - 1); /* LBA of secondary header */ - st_qword(buf + GPTH_FstLba, 2 + sz_ptbl); /* LBA of first allocatable sector */ - st_qword(buf + GPTH_LstLba, top_bpt - 1); /* LBA of last allocatable sector */ - st_dword(buf + GPTH_PteSize, SZ_GPTE); /* Size of a table entry */ - st_dword(buf + GPTH_PtNum, GPT_ITEMS); /* Number of table entries */ - st_dword(buf + GPTH_PtOfs, 2); /* LBA of this table */ + st_32(buf + GPTH_PtBcc, ~bcc); /* Table check sum */ + st_64(buf + GPTH_CurLba, 1); /* LBA of this header */ + st_64(buf + GPTH_BakLba, sz_drv - 1); /* LBA of secondary header */ + st_64(buf + GPTH_FstLba, 2 + sz_ptbl); /* LBA of first allocatable sector */ + st_64(buf + GPTH_LstLba, top_bpt - 1); /* LBA of last allocatable sector */ + st_32(buf + GPTH_PteSize, SZ_GPTE); /* Size of a table entry */ + st_32(buf + GPTH_PtNum, GPT_ITEMS); /* Number of table entries */ + st_32(buf + GPTH_PtOfs, 2); /* LBA of this table */ rnd = make_rand(rnd, buf + GPTH_DskGuid, 16); /* Disk GUID */ for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */ - st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */ + st_32(buf + GPTH_Bcc, ~bcc); /* Header check sum */ if (disk_write(drv, buf, 1, 1) != RES_OK) return FR_DISK_ERR; /* Create secondary GPT header */ - st_qword(buf + GPTH_CurLba, sz_drv - 1); /* LBA of this header */ - st_qword(buf + GPTH_BakLba, 1); /* LBA of primary header */ - st_qword(buf + GPTH_PtOfs, top_bpt); /* LBA of this table */ - st_dword(buf + GPTH_Bcc, 0); + st_64(buf + GPTH_CurLba, sz_drv - 1); /* LBA of this header */ + st_64(buf + GPTH_BakLba, 1); /* LBA of primary header */ + st_64(buf + GPTH_PtOfs, top_bpt); /* LBA of this table */ + st_32(buf + GPTH_Bcc, 0); for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */ - st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */ + st_32(buf + GPTH_Bcc, ~bcc); /* Header check sum */ if (disk_write(drv, buf, sz_drv - 1, 1) != RES_OK) return FR_DISK_ERR; /* Create protective MBR */ memset(buf, 0, ss); - memcpy(buf + MBR_Table, gpt_mbr, 16); /* Create a GPT partition */ - st_word(buf + BS_55AA, 0xAA55); + memcpy(buf + MBR_Table, gpt_mbr, 16); /* Create a GPT partition */ + st_16(buf + BS_55AA, 0xAA55); if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR; } else @@ -5769,20 +6013,20 @@ static FRESULT create_partition ( if (nxt_alloc32 + sz_part32 > sz_drv32 || nxt_alloc32 + sz_part32 < nxt_alloc32) sz_part32 = sz_drv32 - nxt_alloc32; /* Clip at drive size */ if (sz_part32 == 0) break; /* End of table or no sector to allocate? */ - st_dword(pte + PTE_StLba, nxt_alloc32); /* Start LBA */ - st_dword(pte + PTE_SizLba, sz_part32); /* Number of sectors */ + st_32(pte + PTE_StLba, nxt_alloc32); /* Partition start LBA sector */ + st_32(pte + PTE_SizLba, sz_part32); /* Size of partition [sector] */ pte[PTE_System] = sys; /* System type */ - cy = (UINT)(nxt_alloc32 / n_sc / n_hd); /* Start cylinder */ - hd = (BYTE)(nxt_alloc32 / n_sc % n_hd); /* Start head */ - sc = (BYTE)(nxt_alloc32 % n_sc + 1); /* Start sector */ + cy = (UINT)(nxt_alloc32 / n_sc / n_hd); /* Partitio start CHS cylinder */ + hd = (BYTE)(nxt_alloc32 / n_sc % n_hd); /* Partition start CHS head */ + sc = (BYTE)(nxt_alloc32 % n_sc + 1); /* Partition start CHS sector */ pte[PTE_StHead] = hd; pte[PTE_StSec] = (BYTE)((cy >> 2 & 0xC0) | sc); pte[PTE_StCyl] = (BYTE)cy; - cy = (UINT)((nxt_alloc32 + sz_part32 - 1) / n_sc / n_hd); /* End cylinder */ - hd = (BYTE)((nxt_alloc32 + sz_part32 - 1) / n_sc % n_hd); /* End head */ - sc = (BYTE)((nxt_alloc32 + sz_part32 - 1) % n_sc + 1); /* End sector */ + cy = (UINT)((nxt_alloc32 + sz_part32 - 1) / n_sc / n_hd); /* Partition end CHS cylinder */ + hd = (BYTE)((nxt_alloc32 + sz_part32 - 1) / n_sc % n_hd); /* Partition end CHS head */ + sc = (BYTE)((nxt_alloc32 + sz_part32 - 1) % n_sc + 1); /* Partition end CHS sector */ pte[PTE_EdHead] = hd; pte[PTE_EdSec] = (BYTE)((cy >> 2 & 0xC0) | sc); pte[PTE_EdCyl] = (BYTE)cy; @@ -5790,7 +6034,7 @@ static FRESULT create_partition ( pte += SZ_PTE; /* Next entry */ } - st_word(buf + BS_55AA, 0xAA55); /* MBR signature */ + st_16(buf + BS_55AA, 0xAA55); /* MBR signature */ if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR; /* Write it to the MBR */ } @@ -5802,46 +6046,51 @@ static FRESULT create_partition ( FRESULT f_mkfs ( const TCHAR* path, /* Logical drive number */ const MKFS_PARM* opt, /* Format options */ - void* work, /* Pointer to working buffer (null: use heap memory) */ + void* work, /* Pointer to working buffer (null: use len bytes of heap memory) */ UINT len /* Size of working buffer [byte] */ ) { - 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 WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4K sector unit) */ + static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128K sector 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; WORD ss; /* Sector size */ DWORD sz_buf, sz_blk, n_clst, pau, nsect, n, vsn; - LBA_t sz_vol, b_vol, b_fat, b_data; /* Size of volume, Base LBA of volume, fat, data */ + LBA_t sz_vol, b_vol, b_fat, b_data; /* Volume size, base LBA of volume, base LBA of FAT and base LBA of data */ LBA_t sect, lba[2]; - DWORD sz_rsv, sz_fat, sz_dir, sz_au; /* Size of reserved, fat, dir, data, cluster */ - UINT n_fat, n_root, i; /* Index, Number of FATs and Number of roor dir entries */ + DWORD sz_rsv, sz_fat, sz_dir, sz_au; /* Size of reserved area, FAT area, directry area, data area and cluster */ + UINT n_fat, n_root, i; /* Number of FATs, number of roor directory entries and some index */ int vol; DSTATUS ds; - FRESULT fr; + FRESULT res; /* Check mounted drive and clear work area */ - vol = get_ldnumber(&path); /* Get target logical drive */ + vol = get_ldnumber(&path); /* Get logical drive number to be formatted */ 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 parameter 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; #else ss = FF_MAX_SS; #endif + /* Options for FAT sub-type and FAT parameters */ fsopt = opt->fmt & (FM_ANY | FM_SFD); n_fat = (opt->n_fat >= 1 && opt->n_fat <= 2) ? opt->n_fat : 1; @@ -5863,7 +6112,7 @@ FRESULT f_mkfs ( if (FF_MULTI_PARTITION && ipart != 0) { /* Is the volume associated with any specific partition? */ /* Get partition location from the existing partition table */ if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Load MBR */ - if (ld_word(buf + BS_55AA) != 0xAA55) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if MBR is valid */ + if (ld_16(buf + BS_55AA) != 0xAA55) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if MBR is valid */ #if FF_LBA64 if (buf[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */ DWORD n_ent, ofs; @@ -5872,14 +6121,14 @@ FRESULT f_mkfs ( /* Get the partition location from GPT */ if (disk_read(pdrv, buf, 1, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Load GPT header sector (next to MBR) */ if (!test_gpt_header(buf)) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if GPT header is valid */ - n_ent = ld_dword(buf + GPTH_PtNum); /* Number of entries */ - pt_lba = ld_qword(buf + GPTH_PtOfs); /* Table start sector */ + n_ent = ld_32(buf + GPTH_PtNum); /* Number of entries */ + pt_lba = ld_64(buf + GPTH_PtOfs); /* Table start sector */ ofs = i = 0; while (n_ent) { /* Find MS Basic partition with order of ipart */ if (ofs == 0 && disk_read(pdrv, buf, pt_lba++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Get PT sector */ if (!memcmp(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16) && ++i == ipart) { /* MS basic data partition? */ - b_vol = ld_qword(buf + ofs + GPTE_FstLba); - sz_vol = ld_qword(buf + ofs + GPTE_LstLba) - b_vol + 1; + b_vol = ld_64(buf + ofs + GPTE_FstLba); + sz_vol = ld_64(buf + ofs + GPTE_LstLba) - b_vol + 1; break; } n_ent--; ofs = (ofs + SZ_GPTE) % ss; /* Next entry */ @@ -5891,8 +6140,8 @@ FRESULT f_mkfs ( { /* Get the partition location from MBR partition table */ pte = buf + (MBR_Table + (ipart - 1) * SZ_PTE); if (ipart > 4 || pte[PTE_System] == 0) LEAVE_MKFS(FR_MKFS_ABORTED); /* No partition? */ - b_vol = ld_dword(pte + PTE_StLba); /* Get volume start sector */ - sz_vol = ld_dword(pte + PTE_SizLba); /* Get volume size */ + b_vol = ld_32(pte + PTE_StLba); /* Get volume start sector */ + sz_vol = ld_32(pte + PTE_SizLba); /* Get volume size */ } } else { /* The volume is associated with a physical drive */ if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_vol) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); @@ -5911,13 +6160,13 @@ FRESULT f_mkfs ( } } } - if (sz_vol < 128) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if volume size is >=128s */ + if (sz_vol < MIN_VOLUME) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if volume size is not too small */ /* Now start to create an FAT volume at b_vol and sz_vol */ do { /* Pre-determine the FAT type */ if (FF_FS_EXFAT && (fsopt & FM_EXFAT)) { /* exFAT possible? */ - if ((fsopt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || sz_au > 128) { /* exFAT only, vol >= 64MS or sz_au > 128S ? */ + if ((fsopt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || sz_au > 128) { /* exFAT only, vol >= 64M sectors or sz_au > 128 sectors? */ fsty = FS_EXFAT; break; } } @@ -5934,7 +6183,7 @@ FRESULT f_mkfs ( fsty = FS_FAT16; } while (0); - vsn = (DWORD)sz_vol + GET_FATTIME(); /* VSN generated from current time and partitiion size */ + vsn = (DWORD)sz_vol + GET_FATTIME(); /* VSN generated from current time and partition size */ #if FF_FS_EXFAT if (fsty == FS_EXFAT) { /* Create an exFAT volume */ @@ -5957,7 +6206,7 @@ FRESULT f_mkfs ( sz_fat = (DWORD)((sz_vol / sz_au + 2) * 4 + ss - 1) / ss; /* Number of FAT sectors */ b_data = (b_fat + sz_fat + sz_blk - 1) & ~((LBA_t)sz_blk - 1); /* Align data area to the erase block boundary */ if (b_data - b_vol >= sz_vol / 2) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */ - n_clst = (DWORD)(sz_vol - (b_data - b_vol)) / sz_au; /* Number of clusters */ + n_clst = (DWORD)((sz_vol - (b_data - b_vol)) / sz_au); /* Number of clusters */ if (n_clst <16) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too few clusters? */ if (n_clst > MAX_EXFAT) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters? */ @@ -6000,7 +6249,7 @@ FRESULT f_mkfs ( } } while (si); clen[1] = (szb_case + sz_au * ss - 1) / (sz_au * ss); /* Number of up-case table clusters */ - clen[2] = 1; /* Number of root dir clusters */ + clen[2] = 1; /* Number of root directory clusters */ /* Initialize the allocation bitmap */ sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of bitmap sectors */ @@ -6019,12 +6268,13 @@ FRESULT f_mkfs ( do { memset(buf, 0, sz_buf * ss); i = 0; /* Clear work area and reset write offset */ if (clu == 0) { /* Initialize FAT [0] and FAT[1] */ - st_dword(buf + i, 0xFFFFFFF8); i += 4; clu++; - st_dword(buf + i, 0xFFFFFFFF); i += 4; clu++; + st_32(buf + i, 0xFFFFFFF8); i += 4; clu++; + st_32(buf + i, 0xFFFFFFFF); i += 4; clu++; } - do { /* Create chains of bitmap, up-case and root dir */ + + do { /* Create chains of bitmap, up-case and root directory */ while (nbit != 0 && i < sz_buf * ss) { /* Create a chain */ - st_dword(buf + i, (nbit > 1) ? clu + 1 : 0xFFFFFFFF); + st_32(buf + i, (nbit > 1) ? clu + 1 : 0xFFFFFFFF); i += 4; clu++; nbit--; } if (nbit == 0 && j < 3) nbit = clen[j++]; /* Get next chain length */ @@ -6036,14 +6286,14 @@ FRESULT f_mkfs ( /* Initialize the root directory */ memset(buf, 0, sz_buf * ss); - buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry (no label) */ - buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */ - st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */ - st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */ - buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */ - st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */ - st_dword(buf + SZDIRE * 2 + 20, 2 + clen[0]); /* cluster */ - st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */ + buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry (no label) */ + buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */ + st_32(buf + SZDIRE * 1 + 20, 2); /* cluster */ + st_32(buf + SZDIRE * 1 + 24, szb_bit); /* size */ + buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */ + st_32(buf + SZDIRE * 2 + 4, sum); /* sum */ + st_32(buf + SZDIRE * 2 + 20, 2 + clen[0]); /* cluster */ + st_32(buf + SZDIRE * 2 + 24, szb_case); /* size */ sect = b_data + sz_au * (clen[0] + clen[1]); nsect = sz_au; /* Start of the root directory and number of sectors */ do { /* Fill root directory sectors */ n = (nsect > sz_buf) ? sz_buf : nsect; @@ -6058,28 +6308,28 @@ FRESULT f_mkfs ( /* Main record (+0) */ memset(buf, 0, ss); memcpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */ - st_qword(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */ - st_qword(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */ - st_dword(buf + BPB_FatOfsEx, (DWORD)(b_fat - b_vol)); /* FAT offset [sector] */ - st_dword(buf + BPB_FatSzEx, sz_fat); /* FAT size [sector] */ - st_dword(buf + BPB_DataOfsEx, (DWORD)(b_data - b_vol)); /* Data offset [sector] */ - st_dword(buf + BPB_NumClusEx, n_clst); /* Number of clusters */ - st_dword(buf + BPB_RootClusEx, 2 + clen[0] + clen[1]); /* Root dir cluster # */ - st_dword(buf + BPB_VolIDEx, vsn); /* VSN */ - st_word(buf + BPB_FSVerEx, 0x100); /* Filesystem version (1.00) */ - for (buf[BPB_BytsPerSecEx] = 0, i = ss; i >>= 1; buf[BPB_BytsPerSecEx]++) ; /* Log2 of sector size [byte] */ + st_64(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */ + st_64(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */ + st_32(buf + BPB_FatOfsEx, (DWORD)(b_fat - b_vol)); /* FAT offset [sector] */ + st_32(buf + BPB_FatSzEx, sz_fat); /* FAT size [sector] */ + st_32(buf + BPB_DataOfsEx, (DWORD)(b_data - b_vol)); /* Data offset [sector] */ + st_32(buf + BPB_NumClusEx, n_clst); /* Number of clusters */ + st_32(buf + BPB_RootClusEx, 2 + clen[0] + clen[1]); /* Root directory cluster number */ + st_32(buf + BPB_VolIDEx, vsn); /* VSN */ + st_16(buf + BPB_FSVerEx, 0x100); /* Filesystem version (1.00) */ + for (buf[BPB_BytsPerSecEx] = 0, i = ss; i >>= 1; buf[BPB_BytsPerSecEx]++) ; /* Log2 of sector size [byte] */ for (buf[BPB_SecPerClusEx] = 0, i = sz_au; i >>= 1; buf[BPB_SecPerClusEx]++) ; /* Log2 of cluster size [sector] */ buf[BPB_NumFATsEx] = 1; /* Number of FATs */ buf[BPB_DrvNumEx] = 0x80; /* Drive number (for int13) */ - st_word(buf + BS_BootCodeEx, 0xFEEB); /* Boot code (x86) */ - st_word(buf + BS_55AA, 0xAA55); /* Signature (placed here regardless of sector size) */ + st_16(buf + BS_BootCodeEx, 0xFEEB); /* Boot code (x86) */ + st_16(buf + BS_55AA, 0xAA55); /* Signature (placed here regardless of sector size) */ for (i = sum = 0; i < ss; i++) { /* VBR checksum */ if (i != BPB_VolFlagEx && i != BPB_VolFlagEx + 1 && i != BPB_PercInUseEx) sum = xsum32(buf[i], sum); } if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Extended bootstrap record (+1..+8) */ memset(buf, 0, ss); - st_word(buf + ss - 2, 0xAA55); /* Signature (placed at end of sector) */ + st_16(buf + ss - 2, 0xAA55); /* Signature (placed at end of sector) */ for (j = 1; j < 9; j++) { for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */ if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); @@ -6091,7 +6341,7 @@ FRESULT f_mkfs ( if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); } /* Sum record (+11) */ - for (i = 0; i < ss; i += 4) st_dword(buf + i, sum); /* Fill with checksum value */ + for (i = 0; i < ss; i += 4) st_32(buf + i, sum); /* Fill with checksum value */ if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); } @@ -6125,7 +6375,7 @@ FRESULT f_mkfs ( } sz_fat = (n + ss - 1) / ss; /* FAT size [sector] */ sz_rsv = 1; /* Number of reserved sectors */ - sz_dir = (DWORD)n_root * SZDIRE / ss; /* Root dir size [sector] */ + sz_dir = (DWORD)n_root * SZDIRE / ss; /* Root directory size [sector] */ } b_fat = b_vol + sz_rsv; /* FAT base */ b_data = b_fat + sz_fat * n_fat + sz_dir; /* Data base */ @@ -6142,7 +6392,7 @@ FRESULT f_mkfs ( } /* Determine number of clusters and final check of validity of the FAT sub-type */ - if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume? */ + if (sz_vol < b_data + pau * MIN_FAT12 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume for this configuration? */ n_clst = ((DWORD)sz_vol - sz_rsv - sz_fat * n_fat - sz_dir) / pau; if (fsty == FS_FAT32) { if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32? */ @@ -6179,48 +6429,48 @@ FRESULT f_mkfs ( /* Create FAT VBR */ memset(buf, 0, ss); memcpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11); /* Boot jump code (x86), OEM name */ - st_word(buf + BPB_BytsPerSec, ss); /* Sector size [byte] */ + st_16(buf + BPB_BytsPerSec, ss); /* Sector size [byte] */ buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */ - st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */ + st_16(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */ buf[BPB_NumFATs] = (BYTE)n_fat; /* Number of FATs */ - st_word(buf + BPB_RootEntCnt, (WORD)((fsty == FS_FAT32) ? 0 : n_root)); /* Number of root directory entries */ + st_16(buf + BPB_RootEntCnt, (WORD)((fsty == FS_FAT32) ? 0 : n_root)); /* Number of root directory entries */ if (sz_vol < 0x10000) { - st_word(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */ + st_16(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */ } else { - st_dword(buf + BPB_TotSec32, (DWORD)sz_vol); /* Volume size in 32-bit LBA */ + st_32(buf + BPB_TotSec32, (DWORD)sz_vol); /* Volume size in 32-bit LBA */ } buf[BPB_Media] = 0xF8; /* Media descriptor byte */ - st_word(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */ - st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */ - st_dword(buf + BPB_HiddSec, (DWORD)b_vol); /* Volume offset in the physical drive [sector] */ + st_16(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */ + st_16(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */ + st_32(buf + BPB_HiddSec, (DWORD)b_vol); /* Volume offset in the physical drive [sector] */ if (fsty == FS_FAT32) { - st_dword(buf + BS_VolID32, vsn); /* VSN */ - st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */ - st_dword(buf + BPB_RootClus32, 2); /* Root directory cluster # (2) */ - st_word(buf + BPB_FSInfo32, 1); /* Offset of FSINFO sector (VBR + 1) */ - st_word(buf + BPB_BkBootSec32, 6); /* Offset of backup VBR (VBR + 6) */ + st_32(buf + BS_VolID32, vsn); /* VSN */ + st_32(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */ + st_32(buf + BPB_RootClus32, 2); /* Root directory cluster # (2) */ + st_16(buf + BPB_FSInfo32, 1); /* Offset of FSINFO sector (VBR + 1) */ + st_16(buf + BPB_BkBootSec32, 6); /* Offset of backup VBR (VBR + 6) */ buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */ buf[BS_BootSig32] = 0x29; /* Extended boot signature */ memcpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */ } else { - st_dword(buf + BS_VolID, vsn); /* VSN */ - st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */ + st_32(buf + BS_VolID, vsn); /* VSN */ + st_16(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */ buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */ buf[BS_BootSig] = 0x29; /* Extended boot signature */ memcpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */ } - st_word(buf + BS_55AA, 0xAA55); /* Signature (offset is fixed here regardless of sector size) */ + st_16(buf + BS_55AA, 0xAA55); /* Signature (offset is fixed here regardless of sector size) */ if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */ /* Create FSINFO record if needed */ if (fsty == FS_FAT32) { disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */ memset(buf, 0, ss); - st_dword(buf + FSI_LeadSig, 0x41615252); - st_dword(buf + FSI_StrucSig, 0x61417272); - st_dword(buf + FSI_Free_Count, n_clst - 1); /* Number of free clusters */ - st_dword(buf + FSI_Nxt_Free, 2); /* Last allocated cluster# */ - st_word(buf + BS_55AA, 0xAA55); + st_32(buf + FSI_LeadSig, 0x41615252); + st_32(buf + FSI_StrucSig, 0x61417272); + st_32(buf + FSI_Free_Count, n_clst - 1); /* Number of free clusters */ + st_32(buf + FSI_Nxt_Free, 2); /* Last allocated cluster# */ + st_16(buf + BS_55AA, 0xAA55); disk_write(pdrv, buf, b_vol + 7, 1); /* Write backup FSINFO (VBR + 7) */ disk_write(pdrv, buf, b_vol + 1, 1); /* Write original FSINFO (VBR + 1) */ } @@ -6230,17 +6480,17 @@ FRESULT f_mkfs ( sect = b_fat; /* FAT start sector */ for (i = 0; i < n_fat; i++) { /* Initialize FATs each */ if (fsty == FS_FAT32) { - st_dword(buf + 0, 0xFFFFFFF8); /* FAT[0] */ - st_dword(buf + 4, 0xFFFFFFFF); /* FAT[1] */ - st_dword(buf + 8, 0x0FFFFFFF); /* FAT[2] (root directory) */ + st_32(buf + 0, 0xFFFFFFF8); /* FAT[0] */ + st_32(buf + 4, 0xFFFFFFFF); /* FAT[1] */ + st_32(buf + 8, 0x0FFFFFFF); /* FAT[2] (root directory at cluster# 2) */ } else { - st_dword(buf + 0, (fsty == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* FAT[0] and FAT[1] */ + st_32(buf + 0, (fsty == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* FAT[0] and FAT[1] */ } nsect = sz_fat; /* Number of FAT sectors */ do { /* Fill FAT sectors */ n = (nsect > sz_buf) ? sz_buf : nsect; if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); - memset(buf, 0, ss); /* Rest of FAT all are cleared */ + memset(buf, 0, ss); /* Rest of FAT area is initially zero */ sect += n; nsect -= n; } while (nsect); } @@ -6258,32 +6508,30 @@ FRESULT f_mkfs ( /* Determine system ID in the MBR partition table */ if (FF_FS_EXFAT && fsty == FS_EXFAT) { - sys = 0x07; /* exFAT */ + sys = 0x07; /* exFAT */ + } else if (fsty == FS_FAT32) { + sys = 0x0C; /* FAT32X */ + } else if (sz_vol >= 0x10000) { + sys = 0x06; /* FAT12/16 (large) */ + } else if (fsty == FS_FAT16) { + sys = 0x04; /* FAT16 */ } else { - if (fsty == FS_FAT32) { - sys = 0x0C; /* FAT32X */ - } 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 && ipart != 0) { /* Volume is in the existing partition */ - if (!FF_LBA64 || !(fsopt & 0x80)) { + if (!FF_LBA64 || !(fsopt & 0x80)) { /* Is the partition in MBR? */ /* Update system ID in the partition table */ if (disk_read(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Read the MBR */ buf[MBR_Table + (ipart - 1) * SZ_PTE + PTE_System] = sys; /* Set system ID */ if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it back to the MBR */ } } else { /* Volume as a new single partition */ - if (!(fsopt & FM_SFD)) { /* Create partition table if not in SFD */ + if (!(fsopt & FM_SFD)) { /* Create partition table if not in SFD format */ lba[0] = sz_vol; lba[1] = 0; - fr = create_partition(pdrv, lba, sys, buf); - if (fr != FR_OK) LEAVE_MKFS(fr); + res = create_partition(pdrv, lba, sys, buf); + if (res != FR_OK) LEAVE_MKFS(res); } } @@ -6297,7 +6545,7 @@ FRESULT f_mkfs ( #if FF_MULTI_PARTITION /*-----------------------------------------------------------------------*/ -/* Create Partition Table on the Physical Drive */ +/* API: Create Partition Table on the Physical Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_fdisk ( @@ -6308,17 +6556,22 @@ FRESULT f_fdisk ( { BYTE *buf = (BYTE*)work; DSTATUS stat; + 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; + #if FF_USE_LFN == 3 if (!buf) buf = ff_memalloc(FF_MAX_SS); /* Use heap memory for working buffer */ #endif if (!buf) return FR_NOT_ENOUGH_CORE; - 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 */ @@ -6332,7 +6585,7 @@ FRESULT f_fdisk ( #error Wrong FF_STRF_ENCODE setting #endif /*-----------------------------------------------------------------------*/ -/* Get a String from the File */ +/* API: Get a String from the File */ /*-----------------------------------------------------------------------*/ TCHAR* f_gets ( @@ -6373,12 +6626,12 @@ TCHAR* f_gets ( #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? */ - dc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1]; + dc = (FF_STRF_ENCODE == 1) ? ld_16(s) : s[0] << 8 | s[1]; if (IsSurrogateL(dc)) continue; /* Broken surrogate pair? */ if (IsSurrogateH(dc)) { /* High surrogate? */ f_read(fp, s, 2, &rc); /* Get low surrogate */ if (rc != 2) break; /* EOF? */ - wc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1]; + wc = (FF_STRF_ENCODE == 1) ? ld_16(s) : s[0] << 8 | s[1]; if (!IsSurrogateL(wc)) continue; /* Broken surrogate pair? */ dc = ((dc & 0x3FF) + 0x40) << 10 | (wc & 0x3FF); /* Merge surrogate pair */ } @@ -6388,9 +6641,15 @@ 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 */ if (rc != ct) break; @@ -6402,7 +6661,7 @@ TCHAR* f_gets ( if (rc != ct || dc < 0x80 || IsSurrogate(dc) || dc >= 0x110000) continue; /* Wrong encoding? */ } #endif - /* A code point is avaialble in dc to be output */ + /* A code point is available in dc to be output */ if (FF_USE_STRFUNC == 2 && dc == '\r') continue; /* Strip \r off if needed */ #if FF_LFN_UNICODE == 1 || FF_LFN_UNICODE == 3 /* Output it in UTF-16/32 encoding */ @@ -6417,25 +6676,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 } @@ -6465,14 +6720,14 @@ TCHAR* f_gets ( #define SZ_NUM_BUF 32 /*-----------------------------------------------------------------------*/ -/* Put a Character to the File (with sub-functions) */ +/* API: Put a Character to the File (with sub-functions) */ /*-----------------------------------------------------------------------*/ /* Output buffer and work area */ typedef struct { - FIL *fp; /* Ptr to the writing file */ - int idx, nchr; /* Write index of buf[] (-1:error), number of encoding units written */ + FIL *fp; /* Pointer to the writing file */ + int idx, nchr; /* Write index of buf[] (-1:error), number of written encoding units */ #if FF_USE_LFN && FF_LFN_UNICODE == 1 WCHAR hs; #elif FF_USE_LFN && FF_LFN_UNICODE == 2 @@ -6493,7 +6748,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 @@ -6507,39 +6762,39 @@ static void putc_bfd (putbuff* pb, TCHAR c) #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 a stray high-surrogate */ } 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? */ + if (pb->ct == 0) { /* Not in the 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; /* Invalid 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 sequence */ } 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? */ @@ -6554,11 +6809,11 @@ static void putc_bfd (putbuff* pb, TCHAR c) #if FF_STRF_ENCODE == 1 /* Write a code point in UTF-16LE */ if (hs != 0) { /* Surrogate pair? */ - st_word(&pb->buf[i], hs); + st_16(&pb->buf[i], hs); i += 2; nc++; } - st_word(&pb->buf[i], wc); + st_16(&pb->buf[i], wc); i += 2; #elif FF_STRF_ENCODE == 2 /* Write a code point in UTF-16BE */ if (hs != 0) { /* Surrogate pair? */ @@ -6614,7 +6869,7 @@ static void putc_bfd (putbuff* pb, TCHAR c) } -/* Flush remaining characters in the buffer */ +/* Flush characters left in the buffer and return number of characters written */ static int putc_flush (putbuff* pb) { @@ -6622,7 +6877,9 @@ static int putc_flush (putbuff* pb) if ( pb->idx >= 0 /* Flush buffered characters to the file */ && f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK - && (UINT)pb->idx == nw) return pb->nchr; + && (UINT)pb->idx == nw) { + return pb->nchr; + } return -1; } @@ -6654,7 +6911,7 @@ int f_putc ( /*-----------------------------------------------------------------------*/ -/* Put a String to the File */ +/* API: Put a String to the File */ /*-----------------------------------------------------------------------*/ int f_puts ( @@ -6674,7 +6931,7 @@ int f_puts ( /*-----------------------------------------------------------------------*/ -/* Put a Formatted String to the File (with sub-functions) */ +/* API: Put a Formatted String to the File (with sub-functions) */ /*-----------------------------------------------------------------------*/ #if FF_PRINT_FLOAT && FF_INTDEF == 2 #include @@ -6730,8 +6987,8 @@ static void ftoa ( TCHAR fmt /* Notation */ ) { - int d; - int e = 0, m = 0; + int digit; + int exp = 0, mag = 0; char sign = 0; double w; const char *er = 0; @@ -6742,7 +6999,7 @@ static void ftoa ( er = "NaN"; } else { if (prec < 0) prec = 6; /* Default precision? (6 fractional digits) */ - if (val < 0) { /* Nagative? */ + if (val < 0) { /* Negative? */ val = 0 - val; sign = '-'; } else { sign = '+'; @@ -6752,18 +7009,18 @@ static void ftoa ( } else { if (fmt == 'f') { /* Decimal notation? */ val += i10x(0 - prec) / 2; /* Round (nearest) */ - m = ilog10(val); - if (m < 0) m = 0; - if (m + prec + 3 >= SZ_NUM_BUF) er = "OV"; /* Buffer overflow? */ + mag = ilog10(val); + if (mag < 0) mag = 0; + if (mag + prec + 3 >= SZ_NUM_BUF) er = "OV"; /* Buffer overflow? */ } else { /* E notation */ if (val != 0) { /* Not a true zero? */ val += i10x(ilog10(val) - prec) / 2; /* Round (nearest) */ - e = ilog10(val); - if (e > 99 || prec + 7 >= SZ_NUM_BUF) { /* Buffer overflow or E > +99? */ + exp = ilog10(val); + if (exp > 99 || prec + 7 >= SZ_NUM_BUF) { /* Buffer overflow or E > +99? */ er = "OV"; } else { - if (e < -99) e = -99; - val /= i10x(e); /* Normalize */ + if (exp < -99) exp = -99; + val /= i10x(exp); /* Normalize */ } } } @@ -6771,26 +7028,28 @@ static void ftoa ( if (!er) { /* Not error condition */ if (sign == '-') *buf++ = sign; /* Add a - if negative value */ do { /* Put decimal number */ - if (m == -1) *buf++ = ds; /* Insert a decimal separator when get into fractional part */ - w = i10x(m); /* Snip the highest digit d */ - d = (int)(val / w); val -= d * w; - *buf++ = (char)('0' + d); /* Put the digit */ - } while (--m >= -prec); /* Output all digits specified by prec */ + if (mag == -1) *buf++ = ds; /* Insert a decimal separator when get into fractional part */ + w = i10x(mag); /* Snip the highest digit d */ + digit = (int)(val / w); val -= digit * w; + *buf++ = (char)('0' + digit); /* Put the digit */ + } while (--mag >= -prec); /* Output all digits specified by prec */ if (fmt != 'f') { /* Put exponent if needed */ *buf++ = (char)fmt; - if (e < 0) { - e = 0 - e; *buf++ = '-'; + if (exp < 0) { + exp = 0 - exp; *buf++ = '-'; } else { *buf++ = '+'; } - *buf++ = (char)('0' + e / 10); - *buf++ = (char)('0' + e % 10); + *buf++ = (char)('0' + exp / 10); + *buf++ = (char)('0' + exp % 10); } } } if (er) { /* Error condition */ if (sign) *buf++ = sign; /* Add sign if needed */ - do *buf++ = *er++; while (*er); /* Put error symbol */ + do { /* Put error symbol */ + *buf++ = *er++; + } while (*er); } *buf = 0; /* Term */ } @@ -6806,16 +7065,17 @@ int f_printf ( { va_list arp; putbuff pb; - UINT i, j, w, f, r; + UINT i, j, width, flag, radix; int prec; #if FF_PRINT_LLI && FF_INTDEF == 2 - QWORD v; + QWORD val; #else - DWORD v; + DWORD val; #endif - TCHAR tc, pad, *tp; + TCHAR *tp; + TCHAR chr, pad; TCHAR nul = 0; - char d, str[SZ_NUM_BUF]; + char digit, str[SZ_NUM_BUF]; putc_init(&pb, fp); @@ -6823,122 +7083,132 @@ int f_printf ( va_start(arp, fmt); for (;;) { - tc = *fmt++; - if (tc == 0) break; /* End of format string */ - if (tc != '%') { /* Not an escape character (pass-through) */ - putc_bfd(&pb, tc); + chr = *fmt++; + if (chr == 0) break; /* End of format string */ + if (chr != '%') { /* Not an escape character (pass-through) */ + putc_bfd(&pb, chr); continue; } - f = w = 0; pad = ' '; prec = -1; /* Initialize parms */ - tc = *fmt++; - if (tc == '0') { /* Flag: '0' padded */ - pad = '0'; tc = *fmt++; - } else if (tc == '-') { /* Flag: Left aligned */ - f = 2; tc = *fmt++; + flag = width = 0; pad = ' '; prec = -1; /* Initialize the parameters */ + chr = *fmt++; + if (chr == '0') { /* Flag: '0' padded */ + pad = '0'; chr = *fmt++; + } else if (chr == '-') { /* Flag: Left aligned */ + flag = 2; chr = *fmt++; } - if (tc == '*') { /* Minimum width from an argument */ - w = va_arg(arp, int); - tc = *fmt++; + if (chr == '*') { /* Minimum width from an argument */ + width = (UINT)va_arg(arp, int); + chr = *fmt++; } else { - while (IsDigit(tc)) { /* Minimum width */ - w = w * 10 + tc - '0'; - tc = *fmt++; + while (IsDigit(chr)) { /* Minimum width */ + width = width * 10 + chr - '0'; + chr = *fmt++; } } - if (tc == '.') { /* Precision */ - tc = *fmt++; - if (tc == '*') { /* Precision from an argument */ + if (chr == '.') { /* Precision */ + chr = *fmt++; + if (chr == '*') { /* Precision from an argument */ prec = va_arg(arp, int); - tc = *fmt++; + chr = *fmt++; } else { prec = 0; - while (IsDigit(tc)) { /* Precision */ - prec = prec * 10 + tc - '0'; - tc = *fmt++; + while (IsDigit(chr)) { /* Precision */ + prec = prec * 10 + chr - '0'; + chr = *fmt++; } } } - if (tc == 'l') { /* Size: long int */ - f |= 4; tc = *fmt++; + if (chr == 'l') { /* Size: long int */ + flag |= 4; chr = *fmt++; #if FF_PRINT_LLI && FF_INTDEF == 2 - if (tc == 'l') { /* Size: long long int */ - f |= 8; tc = *fmt++; + if (chr == 'l') { /* Size: long long int */ + flag |= 8; chr = *fmt++; } #endif } - if (tc == 0) break; /* End of format string */ - switch (tc) { /* Atgument type is... */ + if (chr == 0) break; /* End of format string */ + switch (chr) { /* Atgument type is... */ case 'b': /* Unsigned binary */ - r = 2; break; + radix = 2; break; + case 'o': /* Unsigned octal */ - r = 8; break; + radix = 8; break; + case 'd': /* Signed decimal */ - case 'u': /* Unsigned decimal */ - r = 10; break; - case 'x': /* Unsigned hexdecimal (lower case) */ - case 'X': /* Unsigned hexdecimal (upper case) */ - r = 16; break; + case 'u': /* Unsigned decimal */ + radix = 10; break; + + case 'x': /* Unsigned hexadecimal (lower case) */ + case 'X': /* Unsigned hexadecimal (upper case) */ + radix = 16; break; + case 'c': /* Character */ putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue; + case 's': /* String */ tp = va_arg(arp, TCHAR*); /* Get a pointer argument */ - if (!tp) tp = &nul; /* Null ptr generates a null string */ + if (!tp) tp = &nul; /* Null pointer generates a null string */ for (j = 0; tp[j]; j++) ; /* j = tcslen(tp) */ - if (prec >= 0 && j > (UINT)prec) j = prec; /* Limited length of string body */ - for ( ; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */ - while (*tp && prec--) putc_bfd(&pb, *tp++); /* Body */ - while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */ + if (prec >= 0 && j > (UINT)prec) j = (UINT)prec; /* Limited length of string body */ + for ( ; !(flag & 2) && j < width; j++) putc_bfd(&pb, pad); /* Left padding */ + while (*tp && prec--) putc_bfd(&pb, *tp++); /* Body */ + while (j++ < width) putc_bfd(&pb, ' '); /* Right padding */ continue; #if FF_PRINT_FLOAT && FF_INTDEF == 2 case 'f': /* Floating point (decimal) */ case 'e': /* Floating point (e) */ case 'E': /* Floating point (E) */ - ftoa(str, va_arg(arp, double), prec, tc); /* Make a flaoting point string */ - for (j = strlen(str); !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */ + ftoa(str, va_arg(arp, double), prec, chr); /* Make a floating point string */ + for (j = strlen(str); !(flag & 2) && j < width; j++) putc_bfd(&pb, pad); /* Leading pads */ for (i = 0; str[i]; putc_bfd(&pb, str[i++])) ; /* Body */ - while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */ + while (j++ < width) putc_bfd(&pb, ' '); /* Trailing pads */ continue; #endif default: /* Unknown type (pass-through) */ - putc_bfd(&pb, tc); continue; + putc_bfd(&pb, chr); + continue; } /* Get an integer argument and put it in numeral */ #if FF_PRINT_LLI && FF_INTDEF == 2 - if (f & 8) { /* long long argument? */ - v = (QWORD)va_arg(arp, LONGLONG); - } else { - if (f & 4) { /* long argument? */ - v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, long) : (QWORD)va_arg(arp, unsigned long); - } else { /* int/short/char argument */ - v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, int) : (QWORD)va_arg(arp, unsigned int); - } + if (flag & 8) { /* long long argument? */ + val = (QWORD)va_arg(arp, long long); + } else if (flag & 4) { /* long argument? */ + val = (chr == 'd') ? (QWORD)(long long)va_arg(arp, long) : (QWORD)va_arg(arp, unsigned long); + } else { /* int/short/char argument */ + val = (chr == 'd') ? (QWORD)(long long)va_arg(arp, int) : (QWORD)va_arg(arp, unsigned int); } - if (tc == 'd' && (v & 0x8000000000000000)) { /* Negative value? */ - v = 0 - v; f |= 1; + if (chr == 'd' && (val & 0x8000000000000000)) { /* Negative value? */ + val = 0 - val; flag |= 1; } #else - if (f & 4) { /* long argument? */ - v = (DWORD)va_arg(arp, long); + if (flag & 4) { /* long argument? */ + val = (DWORD)va_arg(arp, long); } else { /* int/short/char argument */ - v = (tc == 'd') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int); + val = (chr == 'd') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int); } - if (tc == 'd' && (v & 0x80000000)) { /* Negative value? */ - v = 0 - v; f |= 1; + if (chr == 'd' && (val & 0x80000000)) { /* Negative value? */ + val = 0 - val; flag |= 1; } #endif i = 0; do { /* Make an integer number string */ - d = (char)(v % r); v /= r; - if (d > 9) d += (tc == 'x') ? 0x27 : 0x07; - str[i++] = d + '0'; - } while (v && i < SZ_NUM_BUF); - if (f & 1) str[i++] = '-'; /* Sign */ + digit = (char)(val % radix) + '0'; val /= radix; + if (digit > '9') digit += (chr == 'x') ? 0x27 : 0x07; + str[i++] = digit; + } while (val && i < SZ_NUM_BUF); + if (flag & 1) str[i++] = '-'; /* Sign */ /* Write it */ - for (j = i; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */ - do putc_bfd(&pb, (TCHAR)str[--i]); while (i); /* Body */ - while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */ + for (j = i; !(flag & 2) && j < width; j++) { /* Leading pads */ + putc_bfd(&pb, pad); + } + do { /* Body */ + putc_bfd(&pb, (TCHAR)str[--i]); + } while (i); + while (j++ < width) { /* Trailing pads */ + putc_bfd(&pb, ' '); + } } va_end(arp); @@ -6953,7 +7223,7 @@ int f_printf ( #if FF_CODE_PAGE == 0 /*-----------------------------------------------------------------------*/ -/* Set Active Codepage for the Path Name */ +/* API: Set Active Codepage for the Path Name */ /*-----------------------------------------------------------------------*/ FRESULT f_setcp ( @@ -6961,12 +7231,12 @@ FRESULT f_setcp ( ) { 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}; + 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/src/rust/fatfs-sys/depend/fatfs/source/ff.h b/src/rust/fatfs-sys/depend/fatfs/source/ff.h index 64bf79db15..aae57e53f8 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/ff.h +++ b/src/rust/fatfs-sys/depend/fatfs/source/ff.h @@ -1,8 +1,8 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem module R0.14b / +/ FatFs - Generic FAT Filesystem module R0.16 / /-----------------------------------------------------------------------------/ / -/ Copyright (C) 2021, ChaN, all right reserved. +/ Copyright (C) 2025, 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,14 +20,15 @@ #ifndef FF_DEFINED -#define FF_DEFINED 86631 /* Revision ID */ +#define FF_DEFINED 80386 /* Revision ID */ #ifdef __cplusplus extern "C" { #endif +#if !defined(FFCONF_DEF) #include "ffconf.h" /* FatFs configuration options */ - +#endif #if FF_DEFINED != FFCONF_DEF #error Wrong configuration file (ffconf.h). #endif @@ -48,18 +49,18 @@ typedef unsigned __int64 QWORD; #include typedef unsigned int UINT; /* int must be 16-bit or 32-bit */ typedef unsigned char BYTE; /* char must be 8-bit */ -typedef uint16_t WORD; /* 16-bit unsigned integer */ -typedef uint32_t DWORD; /* 32-bit unsigned integer */ -typedef uint64_t QWORD; /* 64-bit unsigned integer */ -typedef WORD WCHAR; /* UTF-16 character type */ +typedef uint16_t WORD; /* 16-bit unsigned */ +typedef uint32_t DWORD; /* 32-bit unsigned */ +typedef uint64_t QWORD; /* 64-bit unsigned */ +typedef WORD WCHAR; /* UTF-16 code unit */ #else /* Earlier than C99 */ #define FF_INTDEF 1 typedef unsigned int UINT; /* int must be 16-bit or 32-bit */ typedef unsigned char BYTE; /* char must be 8-bit */ -typedef unsigned short WORD; /* 16-bit unsigned integer */ -typedef unsigned long DWORD; /* 32-bit unsigned integer */ -typedef WORD WCHAR; /* UTF-16 character type */ +typedef unsigned short WORD; /* short must be 16-bit */ +typedef unsigned long DWORD; /* long must be 32-bit */ +typedef WORD WCHAR; /* UTF-16 code unit */ #endif @@ -113,66 +114,78 @@ typedef char TCHAR; #if FF_MULTI_PARTITION /* Multiple partition configuration */ typedef struct { - BYTE pd; /* Physical drive number */ - BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ + BYTE pd; /* Associated physical drive */ + BYTE pt; /* Associated partition (0:Auto detect, 1-4:Forced partition) */ } PARTITION; -extern PARTITION VolToPart[]; /* Volume - Partition mapping table */ +extern PARTITION VolToPart[]; /* Volume to partition mapping table */ #endif #if FF_STR_VOLUME_ID #ifndef FF_VOLUME_STRS -extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */ +extern const char* VolumeStr[FF_VOLUMES]; /* User defined volume ID table */ #endif #endif +/* Current working directory structure (FFXCWDS) */ + +#if FF_FS_EXFAT && FF_FS_RPATH +#if FF_PATH_DEPTH < 1 +#error FF_PATH_DEPTH must not be zero +#endif +typedef struct { + DWORD d_scl; /* Directory start cluster (0:root dir) */ + DWORD d_size; /* Size of directory (b7-b0: cluster chain status) (invalid if d_scl == 0) */ + DWORD nxt_ofs; /* Offset of entry of next dir in this directory (invalid if last link) */ +} FFXCWDL; +typedef struct { + UINT depth; /* Current directory depth (0:root dir) */ + FFXCWDL tbl[FF_PATH_DEPTH + 1]; /* Directory chain of current working directory path */ +} FFXCWDS; +#endif + /* Filesystem object structure (FATFS) */ typedef struct { - BYTE fs_type; /* Filesystem type (0:not mounted) */ - BYTE pdrv; /* Associated physical drive */ - BYTE n_fats; /* Number of FATs (1 or 2) */ - BYTE wflag; /* win[] flag (b0:dirty) */ - BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */ - WORD id; /* Volume mount ID */ - WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ - WORD csize; /* Cluster size [sectors] */ + BYTE fs_type; /* Filesystem type (0:not mounted) */ + BYTE pdrv; /* Physical drive that holds this volume */ + BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */ + BYTE n_fats; /* Number of FATs (1 or 2) */ + BYTE wflag; /* win[] status (b0:dirty) */ + BYTE fsi_flag; /* Allocation information control (b7:disabled, b0:dirty) */ + WORD id; /* Volume mount ID */ + WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ + WORD csize; /* Cluster size [sectors] */ #if FF_MAX_SS != FF_MIN_SS - WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ + WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ #endif #if FF_USE_LFN - WCHAR* lfnbuf; /* LFN working buffer */ -#endif -#if FF_FS_EXFAT - BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */ -#endif -#if FF_FS_REENTRANT - FF_SYNC_t sobj; /* Identifier of sync object */ + WCHAR* lfnbuf; /* Pointer to LFN working buffer */ #endif #if !FF_FS_READONLY - DWORD last_clst; /* Last allocated cluster */ - DWORD free_clst; /* Number of free clusters */ + DWORD last_clst; /* Last allocated cluster (invalid if >=n_fatent) */ + DWORD free_clst; /* Number of free clusters (invalid if >=fs->n_fatent-2) */ #endif #if FF_FS_RPATH - DWORD cdir; /* Current directory start cluster (0:root) */ + DWORD cdir; /* Current directory start cluster (0:root) */ +#endif + DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ + DWORD fsize; /* Number of sectors per FAT */ + LBA_t winsect; /* Current sector appearing in the win[] */ + LBA_t volbase; /* Volume base sector */ + LBA_t fatbase; /* FAT base sector */ + LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ + LBA_t database; /* Data base sector */ #if FF_FS_EXFAT - DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */ - DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */ - DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */ -#endif + LBA_t bitbase; /* Allocation bitmap base sector */ + BYTE* dirbuf; /* Pointer to directory entry block buffer */ +#if FF_FS_RPATH + FFXCWDS xcwds; /* Crrent working directory structure */ + FFXCWDS xcwds2; /* Working buffer to follow the path */ #endif - DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ - DWORD fsize; /* Size of an FAT [sectors] */ - LBA_t volbase; /* Volume base sector */ - LBA_t fatbase; /* FAT base sector */ - LBA_t dirbase; /* Root directory base sector/cluster */ - LBA_t database; /* Data base sector */ -#if FF_FS_EXFAT - LBA_t bitbase; /* Allocation bitmap base sector */ #endif - LBA_t winsect; /* Current sector appearing in the win[] */ - BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ + BYTE win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data in tiny cfg) */ } FATFS; @@ -180,21 +193,21 @@ typedef struct { /* Object ID and allocation information (FFOBJID) */ typedef struct { - FATFS* fs; /* Pointer to the hosting volume of this object */ - WORD id; /* Hosting volume mount ID */ - BYTE attr; /* Object attribute */ - BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ - DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ - FSIZE_t objsize; /* Object size (valid when sclust != 0) */ + FATFS* fs; /* Pointer to the volume holding this object */ + WORD id; /* Volume mount ID when this object was opened */ + BYTE attr; /* Object attribute */ + BYTE stat; /* Object chain status (exFAT: b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ + DWORD sclust; /* Object data cluster (0:no data or root directory) */ + FSIZE_t objsize; /* Object size (valid when sclust != 0) */ #if FF_FS_EXFAT - DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ - DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ - DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */ - DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */ - DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */ + DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ + DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ + DWORD c_scl; /* Cluster of directory holding this object (valid when sclust != 0) */ + DWORD c_size; /* Size of directory holding this object (b7-b0: allocation status, valid when c_scl != 0) */ + DWORD c_ofs; /* Offset of entry in the holding directory */ #endif #if FF_FS_LOCK - UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ + UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ #endif } FFOBJID; @@ -203,18 +216,18 @@ typedef struct { /* File object structure (FIL) */ typedef struct { - FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ - BYTE flag; /* File status flags */ - BYTE err; /* Abort flag (error code) */ - FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */ - DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */ - LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */ + FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ + BYTE flag; /* File status flags */ + BYTE err; /* Abort flag (error code) */ + FSIZE_t fptr; /* File read/write pointer (0 on open) */ + DWORD clust; /* Current cluster of fptr (invalid when fptr is 0) */ + LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */ #if !FF_FS_READONLY - LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */ - BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ + LBA_t dir_sect; /* Sector number containing the directory entry (not used in exFAT) */ + BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used in exFAT) */ #endif #if FF_USE_FASTSEEK - DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ + DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open; set by application) */ #endif #if !FF_FS_TINY BYTE buf[FF_MAX_SS]; /* File private data read/write window */ @@ -226,40 +239,44 @@ typedef struct { /* Directory object structure (DIR) */ typedef struct { - FFOBJID obj; /* Object identifier */ - DWORD dptr; /* Current read/write offset */ - DWORD clust; /* Current cluster */ - LBA_t sect; /* Current sector (0:Read operation has terminated) */ - BYTE* dir; /* Pointer to the directory item in the win[] */ - BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */ + FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ + DWORD dptr; /* Current read/write offset */ + DWORD clust; /* Current cluster */ + LBA_t sect; /* Current sector (0:no more item to read) */ + BYTE* dir; /* Pointer to the directory item in the win[] in filesystem object */ + BYTE fn[12]; /* SFN (in/out) {body[0-7],ext[8-10],status[11]} */ #if FF_USE_LFN - DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */ + DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:invalid) */ #endif #if FF_USE_FIND - const TCHAR* pat; /* Pointer to the name matching pattern */ + const TCHAR *pat; /* Pointer to the name matching pattern */ #endif } DIR; -/* File information structure (FILINFO) */ +/* File/directory information structure (FILINFO) */ typedef struct { - FSIZE_t fsize; /* File size */ - WORD fdate; /* Modified date */ - WORD ftime; /* Modified time */ - BYTE fattrib; /* File attribute */ + FSIZE_t fsize; /* File size (invalid for directory) */ + WORD fdate; /* Date of file modification or directory creation */ + WORD ftime; /* Time of file modification or directory creation */ +#if FF_FS_CRTIME + WORD crdate; /* Date of object createion */ + WORD crtime; /* Time of object createion */ +#endif + BYTE fattrib; /* Object attribute */ #if FF_USE_LFN - TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */ - TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ + TCHAR altname[FF_SFN_BUF + 1];/* Alternative object name */ + TCHAR fname[FF_LFN_BUF + 1]; /* Primary object name */ #else - TCHAR fname[12 + 1]; /* File name */ + TCHAR fname[12 + 1]; /* Object name */ #endif } FILINFO; -/* Format parameter structure (MKFS_PARM) */ +/* Format parameter structure (MKFS_PARM) used for f_mkfs() */ typedef struct { BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */ @@ -274,32 +291,34 @@ typedef struct { /* File function return code (FRESULT) */ typedef enum { - FR_OK = 0, /* (0) Succeeded */ + FR_OK = 0, /* (0) Function succeeded */ FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ FR_INT_ERR, /* (2) Assertion failed */ - FR_NOT_READY, /* (3) The physical drive cannot work */ + FR_NOT_READY, /* (3) The physical drive does not work */ FR_NO_FILE, /* (4) Could not find the file */ FR_NO_PATH, /* (5) Could not find the path */ FR_INVALID_NAME, /* (6) The path name format is invalid */ - FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ - FR_EXIST, /* (8) Access denied due to prohibited access */ + FR_DENIED, /* (7) Access denied due to a prohibited access or directory full */ + FR_EXIST, /* (8) Access denied due to a prohibited access */ FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ FR_NOT_ENABLED, /* (12) The volume has no work area */ - FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ - FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */ - FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ + FR_NO_FILESYSTEM, /* (13) Could not find a valid FAT volume */ + FR_MKFS_ABORTED, /* (14) The f_mkfs function aborted due to some problem */ + FR_TIMEOUT, /* (15) Could not take control of the volume within defined period */ FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ - FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ + FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated, given buffer size is insufficient or too deep path */ FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ } FRESULT; + +/*--------------------------------------------------------------*/ +/* FatFs Module Application Interface */ /*--------------------------------------------------------------*/ -/* FatFs module application interface */ 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 */ @@ -336,6 +355,8 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ +/* Some API fucntions are implemented as macro */ + #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) #define f_error(fp) ((fp)->err) #define f_tell(fp) ((fp)->fptr) @@ -349,40 +370,45 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil /*--------------------------------------------------------------*/ -/* 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 -#if FF_USE_LFN == 3 /* Dynamic memory allocation */ -void* ff_memalloc (UINT msize); /* Allocate memory block */ -void ff_memfree (void* mblock); /* Free memory block */ -#endif -/* Sync functions */ -#if FF_FS_REENTRANT -int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */ -int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */ -void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */ -int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */ + +/* O/S dependent functions (samples available in ffsystem.c) */ + +#if FF_USE_LFN == 3 /* Dynamic memory allocation */ +void* ff_memalloc (UINT msize); /* Allocate memory block */ +void ff_memfree (void* mblock); /* Free memory block */ +#endif +#if FF_FS_REENTRANT /* Sync functions */ +int ff_mutex_create (int vol); /* Create a sync object */ +void ff_mutex_delete (int vol); /* Delete a sync object */ +int ff_mutex_take (int vol); /* Lock sync object */ +void ff_mutex_give (int vol); /* Unlock sync object */ #endif /*--------------------------------------------------------------*/ -/* Flags and offset address */ - +/* Flags and Offset Address */ +/*--------------------------------------------------------------*/ -/* File access mode and open method flags (3rd argument of f_open) */ +/* File access mode and open method flags (3rd argument of f_open function) */ #define FA_READ 0x01 #define FA_WRITE 0x02 #define FA_OPEN_EXISTING 0x00 @@ -391,10 +417,10 @@ int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */ #define FA_OPEN_ALWAYS 0x10 #define FA_OPEN_APPEND 0x30 -/* Fast seek controls (2nd argument of f_lseek) */ +/* Fast seek controls (2nd argument of f_lseek function) */ #define CREATE_LINKMAP ((FSIZE_t)0 - 1) -/* Format options (2nd argument of f_mkfs) */ +/* Format options (2nd argument of f_mkfs function) */ #define FM_FAT 0x01 #define FM_FAT32 0x02 #define FM_EXFAT 0x04 diff --git a/src/rust/fatfs-sys/depend/fatfs/source/ffconf.h b/src/rust/fatfs-sys/depend/fatfs/source/ffconf.h index 8d45bd23f7..2165770b78 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/ffconf.h +++ b/src/rust/fatfs-sys/depend/fatfs/source/ffconf.h @@ -1,8 +1,8 @@ /*---------------------------------------------------------------------------/ -/ FatFs Functional Configurations +/ Configurations of FatFs Module /---------------------------------------------------------------------------*/ -#define FFCONF_DEF 86631 /* Revision ID */ +#define FFCONF_DEF 80386 /* Revision ID */ /*---------------------------------------------------------------------------/ / Function Configurations @@ -31,36 +31,36 @@ #define FF_USE_MKFS 1 -/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ +/* This option switches f_mkfs(). (0:Disable or 1:Enable) */ #define FF_USE_FASTSEEK 0 -/* This option switches fast seek function. (0:Disable or 1:Enable) */ +/* This option switches fast seek feature. (0:Disable or 1:Enable) */ #define FF_USE_EXPAND 0 -/* This option switches f_expand function. (0:Disable or 1:Enable) */ +/* This option switches f_expand(). (0:Disable or 1:Enable) */ #define FF_USE_CHMOD 0 -/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/* This option switches attribute control API functions, f_chmod() and f_utime(). / (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ #define FF_USE_LABEL 0 -/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/* This option switches volume label API functions, f_getlabel() and f_setlabel(). / (0:Disable or 1:Enable) */ #define FF_USE_FORWARD 0 -/* This option switches f_forward() function. (0:Disable or 1:Enable) */ +/* This option switches f_forward(). (0:Disable or 1:Enable) */ #define FF_USE_STRFUNC 1 #define FF_PRINT_LLI 0 #define FF_PRINT_FLOAT 0 #define FF_STRF_ENCODE 0 -/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and +/* FF_USE_STRFUNC switches string API functions, f_gets(), f_putc(), f_puts() and / f_printf(). / / 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect. @@ -68,8 +68,8 @@ / 2: Enable with LF-CRLF conversion. / / FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2 - makes f_printf() support floating point argument. These features want C99 or later. -/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character +/ makes f_printf() support floating point argument. These features want C99 or later. +/ When FF_LFN_UNICODE >= 1 with LFN enabled, string API functions convert the character / encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE / to be read/written via those functions. / @@ -118,15 +118,15 @@ /* The FF_USE_LFN switches the support for LFN (long file name). / / 0: Disable LFN. FF_MAX_LFN has no effect. -/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. / 2: Enable LFN with dynamic working buffer on the STACK. / 3: Enable LFN with dynamic working buffer on the HEAP. / -/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function +/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN feature / requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and / additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. / The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can -/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN +/ be in range of 12 to 255. It is recommended to be set 255 to fully support the LFN / specification. / When use stack for the working buffer, take care on stack overflow. When use heap / memory for the working buffer, memory management functions, ff_memalloc() and @@ -154,14 +154,26 @@ #define FF_FS_RPATH 0 -/* This option configures support for relative path. +/* This option configures support for relative path feature. / -/ 0: Disable relative path and remove related functions. -/ 1: Enable relative path. f_chdir() and f_chdrive() are available. -/ 2: f_getcwd() function is available in addition to 1. +/ 0: Disable relative path and remove related API functions. +/ 1: Enable relative path and dot names. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() is available in addition to 1. */ +#define FF_PATH_DEPTH 10 +/* This option defines maximum depth of directory in the exFAT volume. It is NOT +/ relevant to FAT/FAT32 volume. +/ For example, FF_PATH_DEPTH = 3 will able to follow a path "/dir1/dir2/dir3/file" +/ but a sub-directory in the dir3 will not able to be followed and set current +/ directory. +/ The size of filesystem object (FATFS) increases FF_PATH_DEPTH * 24 bytes. +/ When FF_FS_EXFAT == 0 or FF_FS_RPATH == 0, this option has no effect. +*/ + + + /*---------------------------------------------------------------------------/ / Drive/Volume Configurations /---------------------------------------------------------------------------*/ @@ -175,10 +187,10 @@ /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each -/ logical drives. Number of items must not be less than FF_VOLUMES. Valid +/ logical drive. Number of items must not be less than FF_VOLUMES. Valid / characters for the volume ID strings are A-Z, a-z and 0-9, however, they are / compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is -/ not defined, a user defined volume string table needs to be defined as: +/ not defined, a user defined volume string table is needed as: / / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... */ @@ -188,9 +200,9 @@ /* This option switches support for multiple volumes on the physical drive. / By default (0), each logical drive number is bound to the same physical drive / number and only an FAT volume found on the physical drive will be mounted. -/ When this function is enabled (1), each logical drive number can be bound to +/ When this feature is enabled (1), each logical drive number can be bound to / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() -/ funciton will be available. */ +/ will be available. */ #define FF_MIN_SS 512 @@ -198,8 +210,8 @@ /* This set of options configures the range of sector size to be supported. (512, / 1024, 2048 or 4096) Always set both 512 for most systems, generic 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 is larger than FF_MIN_SS, FatFs is configured -/ for variable sector size mode and disk_ioctl() function needs to implement +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is +/ configured for variable sector size mode and disk_ioctl() needs to implement / GET_SECTOR_SIZE command. */ @@ -209,14 +221,14 @@ #define FF_MIN_GPT 0x10000000 -/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and -/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */ +/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs() and +/ f_fdisk(). 2^32 sectors maximum. This option has no effect when FF_LBA64 == 0. */ #define FF_USE_TRIM 0 /* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) -/ To enable Trim function, also CTRL_TRIM command should be implemented to the -/ disk_ioctl() function. */ +/ To enable this feature, also CTRL_TRIM command should be implemented to +/ the disk_ioctl(). */ @@ -226,7 +238,7 @@ #define FF_FS_TINY 1 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) -/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ At the tiny configuration, size of file object (FIL) is reduced FF_MAX_SS bytes. / Instead of private sector buffer eliminated from the file object, common sector / buffer in the filesystem object (FATFS) is used for the file data transfer. */ @@ -241,19 +253,24 @@ #define FF_NORTC_MON 1 #define FF_NORTC_MDAY 1 #define FF_NORTC_YEAR 2019 -/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have -/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable -/ the timestamp function. Every object modified by FatFs will have a fixed timestamp +/* The option FF_FS_NORTC switches timestamp feature. If the system does not have +/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the +/ timestamp feature. Every object modified by FatFs will have a fixed timestamp / defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. -/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be -/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() need to be added +/ to the project to read current time form real-time clock. FF_NORTC_MON, / FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. / These options have no effect in read-only configuration (FF_FS_READONLY = 1). */ +#define FF_FS_CRTIME 0 +/* This option enables(1)/disables(0) the timestamp of the file created. When +/ set 1, the file created time is available in FILINFO structure. */ + + #define FF_FS_NOFSINFO 0 -/* If you need to know correct free space on the FAT32 volume, set bit 0 of this -/ option, and f_getfree() function at first time after volume mount will force +/* If you need to know the correct free space on the FAT32 volume, set bit 0 of +/ this option, and f_getfree() on the first time after volume mount will force / a full FAT scan. Bit 1 controls the use of last allocated cluster number. / / bit0=0: Use free cluster count in the FSINFO if available. @@ -275,26 +292,21 @@ / lock control is independent of re-entrancy. */ -/* #include // O/S definitions */ #define FF_FS_REENTRANT 0 #define FF_FS_TIMEOUT 1000 -#define FF_SYNC_t HANDLE /* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs / module itself. Note that regardless of this option, file access to different / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() -/ and f_fdisk() function, are always not re-entrant. Only file/directory access -/ to the same volume is under control of this function. +/ and f_fdisk(), are always not re-entrant. Only file/directory access to +/ the same volume is under control of this featuer. / -/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect. / 1: Enable re-entrancy. Also user provided synchronization handlers, -/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() -/ function, must be added to the project. Samples are available in -/ option/syscall.c. +/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give(), +/ must be added to the project. Samples are available in ffsystem.c. / -/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. -/ The FF_SYNC_t 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.h. */ +/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick. +*/ diff --git a/src/rust/fatfs-sys/depend/fatfs/source/ffsystem.c b/src/rust/fatfs-sys/depend/fatfs/source/ffsystem.c index ad5d73770f..2657fe2287 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/ffsystem.c +++ b/src/rust/fatfs-sys/depend/fatfs/source/ffsystem.c @@ -1,170 +1,208 @@ /*------------------------------------------------------------------------*/ -/* Sample Code of OS Dependent Functions for FatFs */ -/* (C)ChaN, 2018 */ +/* A Sample Code of User Provided OS Dependent Functions for FatFs */ /*------------------------------------------------------------------------*/ - #include "ff.h" -#if FF_USE_LFN == 3 /* Dynamic memory allocation */ +#if FF_USE_LFN == 3 /* Use dynamic memory allocation */ /*------------------------------------------------------------------------*/ -/* Allocate a memory block */ +/* Allocate/Free a Memory Block */ /*------------------------------------------------------------------------*/ +#include /* with POSIX API */ + + void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ UINT msize /* Number of bytes to allocate */ ) { - return malloc(msize); /* Allocate a new memory block with POSIX API */ + return malloc((size_t)msize); /* Allocate a new memory block */ } -/*------------------------------------------------------------------------*/ -/* Free a memory block */ -/*------------------------------------------------------------------------*/ - void ff_memfree ( - void* mblock /* Pointer to the memory block to free (nothing to do if null) */ + void* mblock /* Pointer to the memory block to free (no effect if null) */ ) { - free(mblock); /* Free the memory block with POSIX API */ + free(mblock); /* Free the memory block */ } #endif -#if FF_FS_REENTRANT /* Mutal exclusion */ +#if FF_FS_REENTRANT /* Mutal exclusion */ /*------------------------------------------------------------------------*/ -/* Create a Synchronization Object */ +/* Definitions of Mutex */ /*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to create a new -/ synchronization object for the volume, such as semaphore and mutex. -/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR. -*/ -//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */ +#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */ + + +#if OS_TYPE == 0 /* Win32 */ +#include +static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */ +#elif OS_TYPE == 1 /* uITRON */ +#include "itron.h" +#include "kernel.h" +static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */ -int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ - BYTE vol, /* Corresponding volume (logical drive number) */ - FF_SYNC_t* sobj /* Pointer to return the created sync object */ +#elif OS_TYPE == 2 /* uc/OS-II */ +#include "includes.h" +static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */ + +#elif OS_TYPE == 3 /* FreeRTOS */ +#include "FreeRTOS.h" +#include "semphr.h" +static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */ + +#elif OS_TYPE == 4 /* CMSIS-RTOS */ +#include "cmsis_os.h" +static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */ + +#endif + + + +/*------------------------------------------------------------------------*/ +/* Create a Mutex */ +/*------------------------------------------------------------------------*/ +/* This function is called in f_mount function to create a new mutex +/ or semaphore for the volume. When a 0 is returned, the f_mount function +/ fails with FR_INT_ERR. +*/ + +int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */ + int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ ) { - /* Win32 */ - *sobj = CreateMutex(NULL, FALSE, NULL); - return (int)(*sobj != INVALID_HANDLE_VALUE); - - /* uITRON */ -// T_CSEM csem = {TA_TPRI,1,1}; -// *sobj = acre_sem(&csem); -// return (int)(*sobj > 0); - - /* uC/OS-II */ -// OS_ERR err; -// *sobj = OSMutexCreate(0, &err); -// return (int)(err == OS_NO_ERR); - - /* FreeRTOS */ -// *sobj = xSemaphoreCreateMutex(); -// return (int)(*sobj != NULL); - - /* CMSIS-RTOS */ -// *sobj = osMutexCreate(&Mutex[vol]); -// return (int)(*sobj != NULL); +#if OS_TYPE == 0 /* Win32 */ + Mutex[vol] = CreateMutex(NULL, FALSE, NULL); + return (int)(Mutex[vol] != INVALID_HANDLE_VALUE); + +#elif OS_TYPE == 1 /* uITRON */ + T_CMTX cmtx = {TA_TPRI,1}; + + Mutex[vol] = acre_mtx(&cmtx); + return (int)(Mutex[vol] > 0); + +#elif OS_TYPE == 2 /* uC/OS-II */ + OS_ERR err; + + Mutex[vol] = OSMutexCreate(0, &err); + return (int)(err == OS_NO_ERR); + +#elif OS_TYPE == 3 /* FreeRTOS */ + Mutex[vol] = xSemaphoreCreateMutex(); + return (int)(Mutex[vol] != NULL); + +#elif OS_TYPE == 4 /* CMSIS-RTOS */ + osMutexDef(cmsis_os_mutex); + + Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex)); + return (int)(Mutex[vol] != NULL); + +#endif } /*------------------------------------------------------------------------*/ -/* Delete a Synchronization Object */ +/* Delete a Mutex */ /*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to delete a synchronization -/ object that created with ff_cre_syncobj() function. When a 0 is returned, -/ the f_mount() function fails with FR_INT_ERR. +/* This function is called in f_mount function to delete a mutex or +/ semaphore of the volume created with ff_mutex_create function. */ -int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */ - FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ +void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */ + int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ ) { - /* Win32 */ - return (int)CloseHandle(sobj); +#if OS_TYPE == 0 /* Win32 */ + CloseHandle(Mutex[vol]); - /* uITRON */ -// return (int)(del_sem(sobj) == E_OK); +#elif OS_TYPE == 1 /* uITRON */ + del_mtx(Mutex[vol]); - /* uC/OS-II */ -// OS_ERR err; -// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); -// return (int)(err == OS_NO_ERR); +#elif OS_TYPE == 2 /* uC/OS-II */ + OS_ERR err; - /* FreeRTOS */ -// vSemaphoreDelete(sobj); -// return 1; + OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err); - /* CMSIS-RTOS */ -// return (int)(osMutexDelete(sobj) == osOK); +#elif OS_TYPE == 3 /* FreeRTOS */ + vSemaphoreDelete(Mutex[vol]); + +#elif OS_TYPE == 4 /* CMSIS-RTOS */ + osMutexDelete(Mutex[vol]); + +#endif } /*------------------------------------------------------------------------*/ -/* Request Grant to Access the Volume */ +/* Request a Grant to Access the Volume */ /*------------------------------------------------------------------------*/ -/* This function is called on entering file functions to lock the volume. +/* This function is called on enter file functions to lock the volume. / When a 0 is returned, the file function fails with FR_TIMEOUT. */ -int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ - FF_SYNC_t sobj /* Sync object to wait */ +int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */ + int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ ) { - /* Win32 */ - return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0); +#if OS_TYPE == 0 /* Win32 */ + return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0); + +#elif OS_TYPE == 1 /* uITRON */ + return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK); + +#elif OS_TYPE == 2 /* uC/OS-II */ + OS_ERR err; - /* uITRON */ -// return (int)(wai_sem(sobj) == E_OK); + OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err)); + return (int)(err == OS_NO_ERR); - /* uC/OS-II */ -// OS_ERR err; -// OSMutexPend(sobj, FF_FS_TIMEOUT, &err)); -// return (int)(err == OS_NO_ERR); +#elif OS_TYPE == 3 /* FreeRTOS */ + return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE); - /* FreeRTOS */ -// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE); +#elif OS_TYPE == 4 /* CMSIS-RTOS */ + return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK); - /* CMSIS-RTOS */ -// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK); +#endif } + /*------------------------------------------------------------------------*/ -/* Release Grant to Access the Volume */ +/* Release a Grant to Access the Volume */ /*------------------------------------------------------------------------*/ -/* This function is called on leaving file functions to unlock the volume. +/* This function is called on leave file functions to unlock the volume. */ -void ff_rel_grant ( - FF_SYNC_t sobj /* Sync object to be signaled */ +void ff_mutex_give ( + int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ ) { - /* Win32 */ - ReleaseMutex(sobj); +#if OS_TYPE == 0 /* Win32 */ + ReleaseMutex(Mutex[vol]); - /* uITRON */ -// sig_sem(sobj); +#elif OS_TYPE == 1 /* uITRON */ + unl_mtx(Mutex[vol]); - /* uC/OS-II */ -// OSMutexPost(sobj); +#elif OS_TYPE == 2 /* uC/OS-II */ + OSMutexPost(Mutex[vol]); - /* FreeRTOS */ -// xSemaphoreGive(sobj); +#elif OS_TYPE == 3 /* FreeRTOS */ + xSemaphoreGive(Mutex[vol]); - /* CMSIS-RTOS */ -// osMutexRelease(sobj); -} +#elif OS_TYPE == 4 /* CMSIS-RTOS */ + osMutexRelease(Mutex[vol]); #endif +} + +#endif /* FF_FS_REENTRANT */ diff --git a/src/rust/fatfs-sys/depend/fatfs/source/ffunicode.c b/src/rust/fatfs-sys/depend/fatfs/source/ffunicode.c index 784a10e564..54ad526710 100644 --- a/src/rust/fatfs-sys/depend/fatfs/source/ffunicode.c +++ b/src/rust/fatfs-sys/depend/fatfs/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 */ diff --git a/src/sd.c b/src/sd.c index 479a8c5763..8316d17fb8 100644 --- a/src/sd.c +++ b/src/sd.c @@ -29,6 +29,20 @@ static const char* ROOTDIR = "0:/bitbox02"; FATFS fs; +static bool _mounted_geometry_valid(const FATFS* fatfs) +{ + if (fatfs->fs_type != FS_FAT12 && fatfs->fs_type != FS_FAT16 && fatfs->fs_type != FS_FAT32) { + return false; + } + if (fatfs->n_fats < 1 || fatfs->n_fats > 2 || fatfs->fsize == 0) { + return false; + } + if (fatfs->volbase > fatfs->fatbase || fatfs->fatbase > fatfs->database) { + return false; + } + return (QWORD)fatfs->fatbase + (QWORD)fatfs->fsize * fatfs->n_fats <= (QWORD)fatfs->database; +} + /** * Gets the full directory for an optionally given sub-directory. * Also creates the sub-directory if it doesn't exist yet. @@ -107,6 +121,13 @@ static bool _mount(void) if (res != FR_OK) { #ifndef TESTING sd_mmc_pause_clock(); +#endif + return false; + } + if (!_mounted_geometry_valid(&fs)) { + f_unmount(""); +#ifndef TESTING + sd_mmc_pause_clock(); #endif return false; } @@ -349,6 +370,10 @@ static bool _delete_file(const char* fn, const char* subdir) if (result != FR_OK) { return false; } + if (f_size(&file_object) > SD_MAX_FILE_SIZE) { + f_close(&file_object); + return false; + } for (DWORD f_ps = 0; f_ps < file_object.obj.objsize; f_ps++) { f_putc('\xAC', &file_object); // overwrite data }