From 5630b9308323c3f3aaa09be8fe0f3aecaa826473 Mon Sep 17 00:00:00 2001 From: Leo C. Date: Sun, 30 Jun 2024 09:37:28 +0200 Subject: Import fatfs R0.15 --- fatfs/documents/doc/appnote.html | 393 +++++++++++++++++++++---------------- fatfs/documents/doc/chdir.html | 4 +- fatfs/documents/doc/chdrive.html | 4 +- fatfs/documents/doc/config.html | 143 ++++++++------ fatfs/documents/doc/dinit.html | 2 +- fatfs/documents/doc/dioctl.html | 48 ++--- fatfs/documents/doc/dread.html | 15 +- fatfs/documents/doc/dstat.html | 6 +- fatfs/documents/doc/dwrite.html | 8 +- fatfs/documents/doc/expand.html | 12 +- fatfs/documents/doc/fattime.html | 25 ++- fatfs/documents/doc/fdisk.html | 35 ++-- fatfs/documents/doc/filename.html | 64 +++--- fatfs/documents/doc/findfirst.html | 23 ++- fatfs/documents/doc/forward.html | 4 +- fatfs/documents/doc/getcwd.html | 2 +- fatfs/documents/doc/getfree.html | 2 +- fatfs/documents/doc/getlabel.html | 2 +- fatfs/documents/doc/gets.html | 2 +- fatfs/documents/doc/lseek.html | 36 ++-- fatfs/documents/doc/mkfs.html | 52 +++-- fatfs/documents/doc/mount.html | 15 +- fatfs/documents/doc/open.html | 34 ++-- fatfs/documents/doc/printf.html | 61 +++--- fatfs/documents/doc/putc.html | 2 +- fatfs/documents/doc/puts.html | 2 +- fatfs/documents/doc/rc.html | 55 +++--- fatfs/documents/doc/read.html | 14 +- fatfs/documents/doc/readdir.html | 25 ++- fatfs/documents/doc/sdir.html | 2 +- fatfs/documents/doc/setlabel.html | 6 +- fatfs/documents/doc/sfatfs.html | 12 +- fatfs/documents/doc/sfile.html | 4 +- fatfs/documents/doc/sfileinfo.html | 14 +- fatfs/documents/doc/stat.html | 14 +- fatfs/documents/doc/sync.html | 25 ++- fatfs/documents/doc/unlink.html | 2 +- fatfs/documents/doc/write.html | 12 +- 38 files changed, 695 insertions(+), 486 deletions(-) (limited to 'fatfs/documents/doc') diff --git a/fatfs/documents/doc/appnote.html b/fatfs/documents/doc/appnote.html index ee88b42..5a7a2df 100644 --- a/fatfs/documents/doc/appnote.html +++ b/fatfs/documents/doc/appnote.html @@ -19,12 +19,13 @@
  • Long File Name
  • Unicode API
  • exFAT Filesystem
  • +
  • 64-bit LBA
  • Re-entrancy
  • Duplicated File Access
  • Performance Effective File Access
  • Considerations on Flash Memory Media
  • Critical Section
  • -
  • Extended Use of FatFs API
  • +
  • Various Usable Functions for FatFs Projects
  • About FatFs License
  • @@ -32,33 +33,58 @@

    How to Port

    Basic Considerations

    -

    The FatFs module is assuming following conditions on portability.

    +

    The FatFs module assumes following conditions on portability.

    + +

    Integer Types in FatFs API

    +

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

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

    System Organizations

    -

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

    +

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

    dependency diagram

    -

    (a) If a working disk module with FatFs disk interface is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, glue functions are needed to translate the interfaces between FatFs and the drivers.

    +

    (a) If a working disk module for FatFs is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, some glue functions are needed to translate the interfaces between FatFs and the driver.

    functional diagram

    Required Functions

    -

    You need to provide only low level disk I/O functions required by FatFs module and nothing else. If a working disk module for the target system is already provided, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk I/O module or write it from scratch. Most of defined functions are not that always required. For example, any write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.

    +

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

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

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

    @@ -66,11 +92,12 @@ The FatFs module assumes that size of char/short/long
    @@ -81,29 +108,29 @@ The FatFs module assumes that size of char/short/long ARM7
    32bit
    ARM7
    Thumb
    CM3
    Thumb-2
    AVRH8/300HPIC24RL78V850ESSH-2ARX600IA-32 CompilerGCCGCCGCCGCCCH38C30CC78K0RCA850SHCRXCMSC -text (Full, R/W)10.4k6.7k6.3k12.4k 9.9k11.2k13.0k8.7k9.0k6.5k8.9k -text (Min, R/W) 7.0k4.7k4.4k 8.4k 6.9k 7.8k 9.4k6.0k6.2k4.6k6.3k -text (Full, R/O) 4.8k3.1k2.8k 5.7k 4.7k 5.3k 6.4k4.2k4.0k3.1k4.2k -text (Min, R/O) 3.6k2.4k2.2k 4.4k 3.6k 4.1k 5.0k3.3k3.1k2.4k3.3k -bssV*4 + 2V*4 + 2V*4 + 2V*2 + 2V*4 + 2V*2 + 2V*2 + 2V*4 + 2V*4 + 2V*4 + 2V*4 + 2 +.text (Def, R/W)10.4k6.7k6.1k12.5k11.0k11.4k13.0k8.9k9.2k6.5k8.9k +.text (Min, R/W) 7.0k4.7k4.2k 8.5k 7.6k 7.9k 9.5k6.3k6.4k4.7k6.4k +.text (Def, R/O) 4.9k3.2k2.7k 6.1k 5.2k 5.4k 6.5k4.3k4.2k3.2k4.3k +.text (Min, R/O) 3.7k2.5k2.1k 4.4k 4.0k 4.2k 5.1k3.4k3.3k2.5k3.5k +.bssV*4 + 2V*4 + 2V*4 + 2V*2 + 2V*4 + 2V*2 + 2V*2 + 2V*4 + 2V*4 + 2V*4 + 2V*4 + 2 Work area
    (FF_FS_TINY == 0)V*564
    + F*552V*564
    + F*552V*564
    + F*552V*560
    + F*546V*560
    + F*546V*560
    + F*546V*560
    + F*546V*564
    + F*552V*564
    + F*552V*564
    + F*552V*564
    + F*552 Work area
    (FF_FS_TINY == 1)V*564
    + F*40V*564
    + F*40V*564
    + F*40V*560
    + F*34V*560
    + F*34V*560
    + F*34V*560
    + F*34V*564
    + F*40V*564
    + F*40V*564
    + F*40V*564
    + F*40 -

    These are the memory usage on some target systems with following condition. The memory sizes are in unit of byte, V denotes number of mounted volumes and F denotes number of open files. All samples here are optimezed in code size.

    +

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

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

    Reducing Modle Size

    -

    Follwing table shows which API function is removed by configuration options for the module size reduction. To use any API function, the row of the function must be clear.

    +

    Reducing Module Size

    +

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

    - + @@ -144,141 +171,169 @@ And other options are left unchanged from original setting.

    Long File Name

    -

    FatFs module supports long file name (LFN). The two different file names, short file name (SFN) and LFN, of a file is transparent on the API except for f_readdir function. The support for LFN 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 requiers a certain working buffer in addition. The buffer size can be configured by FF_MAX_LFN according to the available memory. The length of an LFN will be up to 255 characters, so that the FF_MAX_LFN should be set to 255 for all file names. If the size of working buffer is insufficient for the input file name, the file function fails with FR_INVALID_NAME. When use any re-entry to the API with LFN is enabled, 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 working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.

    -
    FunctionFF_FS_
    MINIMIZE
    FF_FS_
    READONLY
    FF_USE_
    STRFUNC
    FF_FS_
    RPATH
    FF_USE_
    FIND
    FF_USE_
    CHMOD
    FF_USE_
    EXPAND
    FF_USE_
    LABEL
    FF_USE_
    MKFS
    FF_USE_
    FORWARD
    FF_MULTI_
    PARTITION
    FunctionFF_FS_
    MINIMIZE
    FF_FS_
    READONLY
    FF_USE_
    STRFUNC
    FF_FS_
    RPATH
    FF_USE_
    FIND
    FF_USE_
    CHMOD
    FF_USE_
    EXPAND
    FF_USE_
    LABEL
    FF_USE_
    MKFS
    FF_USE_
    FORWARD
    FF_MULTI_
    PARTITION
    0123010101201010101010101
    f_mount
    - - - - - - - - -
    With LFN at CM3+gcc
    FF_CODE_PAGEIncrement
    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 increment of code size by LFN function at different code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table. As the result, the FatFs with LFN enebled with those code pages will not able to be ported on the most 8-bit MCU systems.

    -

    If you can discard ANSI/OEM code API and backward compatibility with non-ASCII SFN, you will able to configure FatFs for Unicode API with any SBCS.

    -

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

    -
    - -
    -

    Unicode API

    -

    By default, FatFs uses ANSI/OEM code set on the API even at LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option FF_LFN_UNICODE. This means that FatFs supports 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 code page setting, FF_CODE_PAGE, has actually no meaning for the path names at the Unicode API. However it still affects code conversion of string I/O functions at FF_STRF_ENCODE != 0 and backward compatibility with legacy systems, so that code page needs to be configured properly when 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 a recommended filesystem for high capacity SD cards larger than 32 GB and they are being shipped with this format, so that the exFAT became one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows upto and some filesystem overhead, especially cluster allocation delay, are reduced as well. This feature improves the write throughput to the file.

    -

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

    -

    Remark: Enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.

    -
    - -
    -

    Re-entrancy

    -

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

    -

    The file operations to the same volume is not re-entrant. It can also be configured for 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 function 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.

    -

    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 never prevents to re-enter disk_*() functions. Thus the low level disk I/O layer must be always thread-safe when FatFs API is re-entered for different volumes.

    -
    - -
    -

    Duplicated File Open

    -

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

    -

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

    -
    - -
    -

    Performance Effective File Access

    -

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

    -

    Figure 1. Sector unaligned read (short)
    - -

    -

    Figure 2. Sector unaligned read (long)
    - -

    -

    Figure 3. Fully sector aligned read
    - -

    -

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

    -

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

    -

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

    -
    - -
    -

    Considerations on Flash Memory Media

    -

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

    -

    Using Mutiple-Sector Write

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

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

    -

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

    -

    Forcing Memory Erase

    -

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

    -
    - -
    -

    Critical Section

    -

    If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, incorrect media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.

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

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

    - -

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

    -
    - -
    -

    Extended Use of FatFs API

    -

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

    -
      -
    1. Open or create a file for append (for only R0.12 and earlier)
    2. -
    3. Empty a directory
    4. -
    5. Allocate contiguous area to the file (for only R0.11a and earlier)
    6. -
    7. Compatibility checker for low level disk I/O module
    8. -
    9. FAT volume image creator
    10. -
    -
    - -
    -

    About FatFs License

    -

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

    -
    -/*----------------------------------------------------------------------------/
    -/  FatFs - Generic FAT Filesystem Module  Rx.xx                               /
    -/-----------------------------------------------------------------------------/
    -/
    -/ Copyright (C) 20xx, ChaN, all right reserved.
    -/
    -/ FatFs module is an open source software. Redistribution and use of FatFs in
    -/ source and binary forms, with or without modification, are permitted provided
    -/ that the following condition is met:
    -/
    -/ 1. Redistributions of source code must retain the above copyright notice,
    -/    this condition and the following disclaimer.
    -/
    -/ This software is provided by the copyright holder and contributors "AS IS"
    -/ and any warranties related to this software are DISCLAIMED.
    -/ The copyright owner or contributors be NOT LIABLE for any damages caused
    -/ by use of this software.
    -/----------------------------------------------------------------------------*/
    -
    -

    Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.

    -
    - -

    Return Home

    - - +

    FatFs module supports the long file name (LFN) extension of the FAT filesystem. The two different file names, short file name (SFN) and LFN, of a file is transparent on the API. The support for LFN feature is disabled by default. To enable the LFN, set FF_USE_LFN to 1, 2 or 3, and add ffunicode.c to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by FF_MAX_LFN according to the available memory. The length of LFN can be up to 255 characters, so that the FF_MAX_LFN should be set to 255 for any existing file names. If the size of working buffer is insufficient for the input file name, the file function fails with FR_INVALID_NAME. When use any re-entry to the API with LFN feature in RTOS environment, FF_USE_LFN must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The LFN working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.

    +

    Impact upon Module Size

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

    When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows the increment of code size in some code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table.

    +

    As the result, the FatFs with LFN enabled with DBCS code pages will not able to be ported on the most 8-bit MCU systems. If the target system is in legacy-free, in only Unicode and any ANSI/OEM code is not used at all, the code page setting gets meaningless. You will able to reduce the code size by configureing FatFs for Unicode API with any SBCS code page.

    +

    There ware some restrictions on using LFN for open source project, because the LFN extension on the FAT filesystem was a patent of Microsoft Corporation. However the related patents all have expired and using the LFN feature is free for any projects.

    + + +
    +

    Unicode API

    +

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

    +

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

    +
    + +
    +

    exFAT Filesystem

    +

    The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as the filesystem for SDXC card, 64 GB and larger, and they are being shipped with this format. Therefore the exFAT is one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows up to and some filesystem overhead, especially cluster allocation delay, are reduced as well. These features allow to record the large data without dividing into some files and improve the write throughput to the file.

    +

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

    +

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

    +
    + +
    +

    64-bit LBA

    +

    LBA (Logical Block Addressing) is an addressing method to specify the location of data block, called sector, on the storage media. It is a simple linear address beginning from 0 as the first sector, 1 as the second sector and so on. The host system does not need to consider how the data block is located and managed in the storage device. FatFs supports only LBA for the media access. 32-bit LBA is a common size in the most LBA scheme. It can address up to 232 sectors, 2 TB in 512 bytes/sector. When a storage device larger than 2 TB is used, larger sector size or 64-bit LBA will be needed to address the entire sectors of the storage device.

    +

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

    +
    + +
    +

    Re-entrancy

    +

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

    +

    The file operations of two tasks to the same volume is not thread-safe by default. FatFs can also be configured to make it thread-safe by an option FF_FS_REENTRANT. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by FF_TIMEOUT, the file function will abort with FR_TIMEOUT. The timeout feature might not be supported on the some OSs. To enable this feature, OS dependent synchronization control functions, ff_mutex_create/ff_mutex_delete/ff_mutex_take/ff_mutex_give, need to be added to the project. There is an example code in the ffsystem.c for some OSs.

    +

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

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

    Remarks: This section describes on the re-entrancy of the FatFs module itself. The FF_FS_REENTRANT option enables only exclusive use of each filesystem objects and FatFs does not that prevent to re-enter the storage device control functions. Thus the device control layer needs to be always thread-safe when FatFs API is re-entered for different volumes. Right table shows which control function can be re-entered when FatFs API is re-entered on some conditions.

    +
    + +
    +

    Duplicated File Open

    +

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

    +

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

    +
    + +
    +

    Performance Effective File Access

    +

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

    +

    Figure 1. Sector unaligned read (short)
    + +

    +

    Figure 2. Sector unaligned read (long)
    + +

    +

    Figure 3. Fully sector aligned read
    + +

    +

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

    +

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

    +

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

    +
    + +
    +

    Considerations on Flash Memory Media

    +

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

    +

    Using Mutiple-Sector Write

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

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

    +

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

    +

    Forcing Memory Erase

    +

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

    +
    + +
    +

    Critical Section

    +

    If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, wrong media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.

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

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

    + +

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

    +
    + +
    +

    Various Usable Functions for FatFs Projects

    +

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

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

    About FatFs License

    +

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

    +
    +/*----------------------------------------------------------------------------/
    +/  FatFs - Generic FAT Filesystem Module  Rx.xx                               /
    +/-----------------------------------------------------------------------------/
    +/
    +/ Copyright (C) 20xx, ChaN, all right reserved.
    +/
    +/ FatFs module is an open source software. Redistribution and use of FatFs in
    +/ source and binary forms, with or without modification, are permitted provided
    +/ that the following condition is met:
    +/
    +/ 1. Redistributions of source code must retain the above copyright notice,
    +/    this condition and the following disclaimer.
    +/
    +/ This software is provided by the copyright holder and contributors "AS IS"
    +/ and any warranties related to this software are DISCLAIMED.
    +/ The copyright owner or contributors be NOT LIABLE for any damages caused
    +/ by use of this software.
    +/----------------------------------------------------------------------------*/
    +
    +

    Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses includes GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that compatible with FatFs license.

    +
    + +

    Return Home

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

    Parameters

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

    Description

    -

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

    +

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

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

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

    Description

    -

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

    +

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

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

    Configuration Options

    -

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

    +

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

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

    FF_USE_STRFUNC

    -

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

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

    FF_USE_FIND

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

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

    FF_USE_FORWARD

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

    +

    FF_USE_STRFUNC

    +

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

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

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

    +

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

    + + +

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

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

    FF_STRF_ENCODE

    +

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

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

    Namespace and Locale Configurations

    FF_CODE_PAGE

    -

    This option specifies the OEM code page to be used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used at all, there is no difference between any code page settings.

    +

    This option specifies the OEM code page used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used for the path name or FF_LFN_UNICODE != 0, there is no difference between any code page settings. Set it 437 anyway.

    - + @@ -154,10 +181,10 @@
    ValueCode page
    0Include all code pages below and set by f_setcp()
    0Includes all code pages below and set by f_setcp()
    437U.S.
    720Arabic
    737Greek

    FF_MAX_LFN

    -

    LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 in UTF-16 encoding unit of the LFN. The buffer occupies (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.

    +

    LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 characters (actually in UTF-16 code units) of the LFN. The buffer occupies (FF_MAX_LFN + 1) * 2 bytes and additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.

    FF_LFN_UNICODE

    -

    This option switches character encoding for the file name on the API. When Unicode is selected, FF_CODE_PAGE has actually no meaning except for compatibility with legacy systems. FatFs supports the code point upto U+10FFFF.

    +

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

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

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

    +

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

    +

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

    FF_LFN_BUF, FF_SFN_BUF

    -

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

    +

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

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

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

    -

    FF_STRF_ENCODE

    -

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

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

    FF_FS_RPATH

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

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

    Volume/Drive Configurations

    FF_VOLUMES

    -

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

    +

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

    FF_STR_VOLUME_ID

    This option switches the support for string volume ID. When arbitrary string for the volume ID is enabled for the drive prefix, also pre-defined strings by FF_VOLUME_STRS or user defined strings can be used as drive prefix in the path name. Numeric drive number is always valid regardless of this option, and also either format of drive prefix can be enabled by this option.

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

    FF_VOLUME_STRS

    -

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

    +

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

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

    FF_MULTI_PARTITION

    Disable (0) or Enable (1). This option switches multi-partition function. By default (0), each logical drive number is bound to the same physical drive number and only a volume in the physical drive is mounted. When enabled, each logical drive is bound to the partition on the physical drive listed in the user defined partition resolution table VolToPart[]. Also f_fdisk funciton will be available. For more information, read here.

    FF_MIN_SS, FF_MAX_SS

    -

    This set of options defines the extent of sector size used on the low level disk I/O interface, disk_read and disk_write function. Valid values are 512, 1024, 2048 and 4096. FF_MIN_SS defines minimum sector size and FF_MAX_SS defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When FF_MAX_SS > FF_MIN_SS, support of variable sector size is enabled and GET_SECTOR_SIZE command needs to be implemented to the disk_ioctl function.

    +

    This set of options defines the extent of sector size used for the low level disk I/O interface, disk_read and disk_write function. Valid values are 512, 1024, 2048 and 4096. FF_MIN_SS defines minimum sector size and FF_MAX_SS defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When FF_MAX_SS > FF_MIN_SS, support of variable sector size is enabled and GET_SECTOR_SIZE command needs to be implemented to the disk_ioctl function.

    + +

    FF_LBA64

    +

    This option switches media access interface to 64-bit LBA and enables GUID Partition Table (GPT) for partition management, Enabled (1) or Disabled (0). exFAT filesystem needs to be enabled to enable this feature.

    + +

    FF_MIN_GPT

    +

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

    FF_USE_TRIM

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

    -

    FF_FS_NOFSINFO

    -

    0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and f_getfree function at first time after volume mount will force a full FAT scan. Bit 1 controls the use of last allocated cluster number.

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

    System Configurations

    FF_FS_TINY

    -

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

    +

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

    FF_FS_EXFAT

    -

    This option switches support for the exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing FF_LFN_UNICODE >= 1 and FF_MAX_LFN == 255 is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.

    +

    This option switches support for exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing FF_LFN_UNICODE >= 1 and FF_MAX_LFN == 255 is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility and wants C99 because of need for 64-bit integer type.

    FF_FS_NORTC

    -

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

    +

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

    FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR

    -

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

    +

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

    + +

    FF_FS_NOFSINFO

    +

    0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and f_getfree function at first time after the volume mounted will force a full FAT scan. Bit 1 controls the use of last allocated cluster number for new allocation.

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

    FF_FS_LOCK

    -

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

    +

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

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

    FF_FS_REENTRANT

    -

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

    +

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

    FF_FS_TIMEOUT

    -

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

    - -

    FF_SYNC_t

    -

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

    +

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

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

    Description

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

    -

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

    +

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

    Return

    diff --git a/fatfs/documents/doc/dioctl.html b/fatfs/documents/doc/dioctl.html index 15b9c8a..b7ad0aa 100644 --- a/fatfs/documents/doc/dioctl.html +++ b/fatfs/documents/doc/dioctl.html @@ -57,35 +57,35 @@ DRESULT disk_ioctl ( - - - - - + + + + +
    Standard ioctl command used by FatFs
    CommandDescription
    CTRL_SYNCMake sure that the device has finished pending write process. If the disk I/O module has a write back cache, the dirty buffers must be written back to the media immediately. Nothing to do for this command if each write operation to the media is completed within the disk_write function.
    GET_SECTOR_COUNTReturns number of available sectors on the drive into the DWORD variable pointed by buff. This command is used by f_mkfs and f_fdisk function to determine the volume/partition size to be created. Required at FF_USE_MKFS == 1.
    GET_SECTOR_SIZEReturns sector size of the device into the WORD variable pointed by buff. Valid return values for this command are 512, 1024, 2048 and 4096. This command is required only if FF_MAX_SS > FF_MIN_SS. When FF_MAX_SS == FF_MIN_SS, this command is never used and the device must work at that sector size.
    GET_BLOCK_SIZEReturns erase block size of the flash memory media in unit of sector into the DWORD variable pointed by buff. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or non flash memory media. This command is used by only f_mkfs function and it attempts to align data area on the erase block boundary. Required at FF_USE_MKFS == 1.
    CTRL_TRIMInforms the device the data on the block of sectors is no longer needed and it can be erased. The sector block is specified by a DWORD array {<start sector>, <end sector>} pointed by buff. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the f_mkfs function. Required at FF_USE_TRIM == 1.
    CTRL_SYNCMakes sure that the device has finished pending write process. If the disk I/O layer or storage device has a write-back cache, the dirty cache data must be committed to the medium immediately. Nothing to do for this command if each write operation to the medium is completed in the disk_write function.
    GET_SECTOR_COUNTRetrieves number of available sectors, the largest allowable LBA + 1, on the drive into the LBA_t variable that pointed by buff. This command is used by f_mkfs and f_fdisk function to determine the size of volume/partition to be created.
    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 never uses any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.

    +

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

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

    disk_read

    -

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

    +

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

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

    Description

    -

    Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called sector. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (FF_MIN_SS == FF_MAX_SS, this is the most case), the read/write function must work at that sector size. When FatFs is configured for variable sector size (FF_MIN_SS < FF_MAX_SS), the sector size of medium is inquired with disk_ioctl function immediately following disk_initialize function succeeded.

    -

    The memory address specified by buff is not that always aligned to word boundary because the argument is defined as BYTE*. The unaligned read/write request can occure at direct transfer. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.

    +

    Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called sector. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (FF_MIN_SS == FF_MAX_SS, this is the most case), the generic read/write function must work at this sector size only. When FatFs is configured for variable sector size (FF_MIN_SS < FF_MAX_SS), the sector size of medium is inquired with disk_ioctl function after disk_initialize function succeeds.

    +

    There are some considerations about the memory addres passed via buff. It is not that always aligned with the word boundary, because the argument is defined as BYTE*. The unaligned transfer request can occure at direct transfer. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. If it is the case, there are some workarounds described below to avoid this issue.

    +

    Also the memory area may be out of reach in DMA. This is the case if it is located on the tightly coupled memory which is usually used for stack. Use double buffered transfer, or avoid to define file I/O buffer, FATFS and FIL structure as local variables where on the stack.

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

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

    Parameter

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

    disk_write

    -

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

    +

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

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

    Description

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

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

    -

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

    +

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

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

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

    Description

    -

    The f_expand function prepares or allocates a contiguous data area to the file. When opt is 1, the function allocates a contiguous data area to the file. Unlike expansion of file by f_lseek function, the file must be truncated prior to use this function and read/write pointer of the file stays at top of the file after the function. The file content allocated with this function is undefined because no data is written to the file in this process. The function can fail with FR_DENIED due to some reasons below.

    +

    The f_expand function prepares or allocates a contiguous data area to the file. When opt is 1, the data area is allocated to the file in this function. Unlike expansion of file size by f_lseek function, the file must be truncated prior to use this function and read/write pointer of the file stays at offset 0 after the function call. The file content allocated with this function is undefined, because no data is written to the file in this process. The function can fail with FR_DENIED due to some reasons below.

    -

    When opt is 0, the function finds a contiguous data area and set it as suggested point for next allocation instead of allocating it to the file. The next cluster allocation is started at top of the contiguous area found by this function. Thus the write file is guaranteed be contiguous and no allocation delay until the size reaches that size at least unless any other changes to the volume is performed.

    -

    The contiguous file would have an advantage at time-critical read/write operations. It eliminates some overheads in the filesystem and the storage media caused by random access due to fragmented file data. Especially FAT access for the contiguous file on the exFAT volume is completely eliminated and storage media will be accessed sequentially.

    -

    Also the contiguous file can be easily accessed directly via low-level disk functions. But this is not recommended in consideration for future compatibility.

    +

    When opt is 0, the function finds a contiguous data area and set it as suggested point for next allocation. The subsequent cluster allocation begins at top of the contiguous area found by this function. Thus the file allocation is guaranteed be contiguous and without allocation delay until the file size reaches this size unless any other changes to the volume is performed.

    +

    The contiguous file has an advantage for time-critical read/write operations. It eliminates some overheads in the filesystem and the storage device caused by random access for fragmented file.

    +

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

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

    QuickInfo

    -

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

    +

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

    +
    + + +
    +

    Example

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

    The f_fdisk fucntion divides a physical drive.

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

    Description

    -

    The f_fdisk function creates partitions on the physical drive. The partitioning format is in generic FDISK format, so that it can create upto four primary partitions. Logical volumes in the extended partition is not supported. The partition map table with four items specifies how to divide the physical drive. The first item specifies the size of first primary partition and fourth item specifies the fourth primary partition. If the value is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. If it is larger than 100, it specifies the partition size in unit of sector. The partitions are located on the drive in order of from first item.

    +

    The f_fdisk function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is truncated at end of the drive.

    +

    By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (FF_LBA64 = 1) and the drive size is equal to or larger than FF_MIN_GPT sectors. It can create over ten partitions on a drive.

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

    Example

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

    Path Names on the FatFs

    +

    Path Names on the FatFs API

    Format of the Path Names

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

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

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

    -

    Control characters (\0 to \x1F) are recognized as end of the path name. Leading/embedded white spaces in the path name are valid as a part of the name at LFN configuration but the white space is recognized as end of the path name at non-LFN configuration. Trailing white spaces and dots are ignored at both configurations.

    -

    In default configuration (FF_FS_RPATH == 0), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name that followed from the root directory. Dot directory names (".", "..") are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.

    -

    When relative path is enabled (FF_FS_RPATH >= 1), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the drive set by f_chdir function. Dot names are also allowed for the path names. The default drive is the current drive set by f_chdrive function.

    +

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

    +

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

    +

    In default configuration (FF_FS_RPATH == 0), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name followed from the root directory. Dot directory names (".", "..") are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.

    +

    When relative path feature is enabled (FF_FS_RPATH >= 1), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the default drive. Dot directory name is also allowed for the path name. The current directory is set by f_chdir function and the default drive is the current drive set by f_chdrive function.

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

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

    - +

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

    +

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

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

    Legal Characters and Case Sensitivity

    -

    On the FAT filesystem, legal characters for object name (file/directory name) are, 0-9 A-Z ! # $ % & ' ( ) - @ ^ _ ` { } ~ and extended characters (\x80-\xFF). Under LFN supported system, also + , ; = [ ] and white space are legal for the object name and the white spaces and dots can be placed anywhere in the path name except for end of the object name.

    -

    FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, file.txt, File.Txt and FILE.TXT, are identical. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN function is enabled.

    -

    As for the MS-DOS and PC DOS for CJK, it was case-sensitive to the DBCS extended characters. To follow this specification, FatFs works with case-sensitive to the extended characters at only non-LFN with DBCS configuration (DOS/DBCS specs). But at LFN configuration, FatFs works with case-insensitive to the extended character (WindowsNT specs). This can cause a problem on compatibility with Windows system when an object with extended characters is created on the volume at non-LFN and DBCS configuration; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems.

    +

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

    +

    FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, file.txt, File.Txt and FILE.TXT, are identical on the FAT filesystem. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN extension is exist.

    +

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

    Unicode API

    -

    The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as TCHAR. It is an alias of char by default and the code set used for the path name string is ANSI/OEM specifid by FF_CODE_PAGE. When FF_LFN_UNICODE is set to 1, the type of the TCHAR is switched to WCHAR to support UTF-16 encoded Unicode string. When UTF-16 or UTF-8 is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, _T(s) and _TEXT(s) macro are available to select either ANSI/OEM or Unicode automatically. The code shown below is an example to define the literal strings.

    +

    The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as TCHAR. It is an alias of char by default and the code set used for the path name string is ANSI/OEM specifid by FF_CODE_PAGE. When FF_LFN_UNICODE is set to 1 or larger, the type of the TCHAR is switched to proper type to support the Unicode string. When Unicode API is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭ and any character not in BMP, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, _T(s) and _TEXT(s) macro are available to specify the string in proper type. The code shown below is an example to define the literal strings.

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

    Volume Management

    -

    FatFs module requires dynamic work area, filesystem object, for each volume (logical drive). It is registered/unregistered to the FatFs module by f_mount function. By default, each logical drive is bound to the physical drive with the same drive number and an FAT volume on the drive is serched by the volume mount process. It reads boot sectors and checks it if it is an FAT boot sector in order of sector 0 as SFD format, 1st partition, 2nd partition, 3rd partition and 4th partition as FDISK format.

    -

    When FF_MULTI_PARTITION = 1 is specified by configuration option, each individual logical drive is bound to the partition on the physical drive specified by volume management table. The volume management table needs to be defined by user to resolve the mappings of logical drives and partitions. Following code is an example of a volume management table.

    +

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

    +

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

    -Example: "0:", "1:" and "2:" are tied to three pri-partitions on the physical drive 0 (fixed drive)
    -         "3:" is tied to an FAT volume on the physical drive 1 (removable drive)
    +Example: "0:", "1:" and "2:" are associated with three partitions on the physical drive 0 (a non-removable drive)
    +         "3:" is associated with physical drive 1 (a removable drive)
     
     PARTITION VolToPart[FF_VOLUMES] = {
    -    {0, 1},     /* "0:" ==> Physical drive 0, 1st partition */
    -    {0, 2},     /* "1:" ==> Physical drive 0, 2nd partition */
    -    {0, 3},     /* "2:" ==> Physical drive 0, 3rd partition */
    -    {1, 0}      /* "3:" ==> Physical drive 1, auto detection */
    +    {0, 1},     /* "0:" ==> 1st partition on the pd#0 */
    +    {0, 2},     /* "1:" ==> 2nd partition on the pd#0 */
    +    {0, 3},     /* "2:" ==> 3rd partition on the pd#0 */
    +    {1, 0}      /* "3:" ==> pd#1 as removable drive (auto-search) */
     };
    +
    +
    +relationship between logical drive and physical drive
     
    -
    relationship between logical drive and physical drive
    -

    There are some considerations on using multi-partition configuration.

    +

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

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

    Description

    -

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

    -

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

    +

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

    +

    The matching pattern string can contain wildcards. For example:

    +

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

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

    Description

    -

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

    +

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

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

    Example (Audio playback)

    +

    Example

     /*------------------------------------------------------------------------*/
     /* Sample code of data transfer function to be called back from f_forward */
    diff --git a/fatfs/documents/doc/getcwd.html b/fatfs/documents/doc/getcwd.html
    index d5eab61..6eb9a58 100644
    --- a/fatfs/documents/doc/getcwd.html
    +++ b/fatfs/documents/doc/getcwd.html
    @@ -50,7 +50,7 @@ FRESULT f_getcwd (
     
     

    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 is depends on FF_STR_VOLUME_ID.

    +

    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.

    diff --git a/fatfs/documents/doc/getfree.html b/fatfs/documents/doc/getfree.html index cdc730b..5e4f419 100644 --- a/fatfs/documents/doc/getfree.html +++ b/fatfs/documents/doc/getfree.html @@ -53,7 +53,7 @@ FRESULT f_getfree (

    Descriptions

    -

    The f_getfree function gets number of free clusters on the volume. The member csize in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. When FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by FF_FS_NOFSINFO option.

    +

    The f_getfree function gets number of free clusters on the volume. The member csize in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. In case of FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by FF_FS_NOFSINFO option.

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

    Description

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

    -

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

    +

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

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

    Description

    -

    File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The f_lseek function moves the file read/write pointer without any read/write operation to the file.

    -

    When an offset beyond the file size is specified at write mode, the file size is expanded to the specified offset. The file data in the expanded area is undefined because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use f_expand function instead. After the f_lseek function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.

    +

    File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The f_lseek function moves the file read/write pointer without any read/write operation to the file. The f_rewind function is impremented as a macro.

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

    If an offset beyond the file size is specified in write mode, the file size is expanded to the specified offset. The file data in the expanded part is undefined, because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use f_expand function instead. After the f_lseek function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not pointing expected offset, either of followings has been occured.

    -

    The fast seek function enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to f_read and f_write function as well, however, the file size cannot be expanded by f_write, f_lseek function while the file is at fast seek mode.

    -

    The fast seek mode is enabled when the member cltbl in the file object is not NULL. The CLMT must be created into the DWORD array prior to use the fast seek function. To create the CLMT, set address of the DWORD array to the member cltbl in the open file object, set the size of array in unit of items to the first item and call the f_lseek function with ofs = CREATE_LINKMAP. After the function succeeded and CLMT is created, no FAT access is occured in subsequent f_read, f_write, f_lseek function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, when the file is fragmented in 5, 12 items in the array will be used. If the function failed with FR_NOT_ENOUGH_CORE, the given array size is insufficient for the file.

    +

    The fast seek feature enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to f_read and f_write function as well, however, the file size cannot be expanded by f_write, f_lseek function while the file is at fast seek mode.

    +

    The fast seek mode is available when FF_USE_FASTSEEK = 1. The CLMT must be created into the DWORD array prior to use the fast seek mode. To create the CLMT, set address of the DWORD array to the member cltbl in the open file object, set the size of array in unit of items to the cltbl[0] and then call f_lseek function with ofs = CREATE_LINKMAP. After the function succeeded, no FAT access is occured in subsequent f_read, f_write, f_lseek function to the file. The number of items used or required is returned into the cltbl[0]. The number of items needed is (number of the file fragments + 1) * 2. For example, 12 items in the array will be used for the file fragmented in 5 portions. If the function failed with FR_NOT_ENOUGH_CORE, the size of given array is insufficient for the file.

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

    f_mkfs

    -

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

    +

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

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

    Parameters

    path
    -
    Pointer to the null-terminated string specifies the logical drive to be formatted. If it has no drive number in it, it means the default drive. The logical drive may or may not be mounted for the format process.
    +
    Pointer to the null-terminated string specifies the logical drive to be formatted. If it does not have a drive number in it, it means to specify the default drive. The logical drive may or may not have been mounted for the format process.
    opt
    -
    Specifies the format option in combination of FM_FAT, FM_FAT32, FM_EXFAT and bitwise-or of these three, FM_ANY. FM_EXFAT is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and au. The flag FM_SFD specifies to create the volume on the drive in SFD format.
    -
    au
    -
    Specifies size of the allocation unit (cluter) in unit of byte. The valid value is n times the sector size. The n is power of 2 from 1 to 128 for FAT volume and upto 16MiB for exFAT volume. If zero is given, the default allocation unit size is selected depends on the volume size.
    +
    Specifies the format option structure MKFS_PARM holding format options. If a null pointer is given, it gives the function every option in default value. The structure has five members in order of described below:
    +
    +
    BYTE fmt
    +
    Specifies a combination of FAT type flags, FM_FAT, FM_FAT32, FM_EXFAT and bitwise-or of these three, FM_ANY. FM_EXFAT is ignored when exFAT is not enabled. These flags specify which type of FAT volume to be created. If two or more types are specified, one out of them will be selected depends on the volume size and au_size. The flag FM_SFD specifies to create the volume on the drive in SFD format. The default value is FM_ANY.
    +
    BYTE n_fat
    +
    Specifies number of FAT copies on the FAT/FAT32 volume. Valid value for this member is 1 or 2. The default value (0) and any invaid value gives 1. If the FAT type is exFAT, this member has no effect.
    +
    UINT n_align
    +
    Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash memory media) in unit of sector. The valid value for this member is between 1 and 32768 inclusive in power of 2. If a zero (the default value) or any invalid value is given, the function obtains the block size from lower layer with disk_ioctl function.
    +
    DWORD au_size
    +
    Specifies size of the allocation unit (cluter) in unit of byte. The valid value is power of 2 between sector size and 128 * sector size inclusive for FAT/FAT32 volume, or up to 16 MB for exFAT volume. If a zero (default value) or any invalid value is given, the function uses default allocation unit size depends on the volume size.
    +
    UINT n_root
    +
    Specifies number of root directory entries on the FAT volume. Valid value for this member is up to 32768 and aligned to sector size / 32. The default value (0) and any invaid value gives 512. If the FAT type is FAT32 or exFAT, this member has no effect.
    +
    work
    -
    Pointer to the working buffer used for the format process. When a null pointer is given, the function allocates a memory block for the working buffer and len has no effect (at only FF_USE_LFN == 3).
    +
    Pointer to the working buffer used for the format process. If a null pointer is given with FF_USE_LFN == 3, the function uses a len bytes of heap memory in this function.
    len
    -
    Size of the working buffer in unit of byte. It needs to be the sector size of the corresponding physical drive at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.
    +
    Size of the working buffer in unit of byte. It needs to be FF_MAX_SS at least. Plenty of working buffer reduces number of write transactions to the drive, thus the format process will finish quickly.
    @@ -57,11 +66,12 @@ FRESULT f_mkfs (

    Description

    -

    The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with FR_MKFS_ABORTED. The minimum drive size is 128 sectors with FM_SFD option.

    -

    The allocation unit, also called cluster, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases as the size of allocation unit. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.

    -

    There are three disk partitioning formats, FDISK, SFD and GPT. The FDISK format is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table on the MBR (maser boot record, the first sector of the physical drive). The SFD (super-floppy disk) is non-partitioned disk format. The FAT volume starts at the first sector of the physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some systems support only either one of the two disk formats and the other is not supported. The GPT (GUID Partition Table) is a newly defined format for large storage devices. FatFs does not support the storages with GPT.

    -

    When the logical drive to be formatted is bound to a physical drive and FM_SFD is not specified, a primary partition occupies whole drive space is created in FDISK format, and then the FAT volume is created in the partition. When FM_SFD is specified, the FAT volume occupies from the first sector of the physical drive is created in SFD format.

    -

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

    +

    The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument is not valid for the volume size, the function will fail with FR_MKFS_ABORTED.

    +

    The allocation unit, also known as cluster, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large volumes in GB order, 32768 bytes or larger, automatically selected by default, is recommended for most case unless extremely many small files are created in the volume.

    +

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

    +

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

    +

    There are three standard disk partitioning formats, MBR, GPT and SFD. The MBR format, also known as FDISK format, is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table. The GPT, GUID Partition Table, is a newly defined patitioning format for large storage devices. FatFs suppors the GPT only when 64-bit LBA is enabled. The SFD, Super-Floppy Disk, is non-partitioned disk format. The FAT volume is located at LBA 0 and occupies the entire physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some combination of systems and media support only either partitioned format or non-partitioned format and the other is not supported.

    +

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

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

    See Also

    -

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

    +

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

    Return

    diff --git a/fatfs/documents/doc/mount.html b/fatfs/documents/doc/mount.html index 901ffc0..57f40be 100644 --- a/fatfs/documents/doc/mount.html +++ b/fatfs/documents/doc/mount.html @@ -13,7 +13,7 @@

    f_mount

    -

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

    +

    The f_mount fucntion gives work area to the FatFs module.

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

    Description

    -

    FatFs requires work area (filesystem object) for each logical drives (FAT volumes). Prior to perform file/directory operations, a filesystem object needs to be registered with f_mount function to the logical drive. The file/directory API functions get ready to work after this procedure. If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.

    +

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

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

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

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

    If forced mounting is not specified (opt = 0), this function always succeeds regardless of the physical drive status. It only clears (de-initializes) the given work area and registers its address to the internal table and no activity of the physical drive in this function. The volume mount process will be attempted on subsequent file/directroy function if the filesystem object is not initialized. (delayed mounting) The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and then initialize the work area, is performed in the subsequent file/directory functions when either of following conditions is true.

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

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

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

    -

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

    +

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

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

    Description

    -

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

    +

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

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

    @@ -111,14 +111,14 @@ int main (void) FRESULT fr; /* FatFs return code */ - /* Register work area to the default drive */ + /* Give a work area to the default drive */ f_mount(&FatFs, "", 0); /* Open a text file */ fr = f_open(&fil, "message.txt", FA_READ); if (fr) return (int)fr; - /* Read all lines and display it */ + /* Read every line and display it */ while (f_gets(line, sizeof line, &fil)) { printf(line); } @@ -134,16 +134,16 @@ int main (void) int main (void) { - FATFS fs[2]; /* Work area (filesystem object) for logical drives */ + FATFS fs0, fs1; /* Work area (filesystem object) for logical drives */ FIL fsrc, fdst; /* File objects */ BYTE buffer[4096]; /* File copy buffer */ FRESULT fr; /* FatFs function common result code */ UINT br, bw; /* File read/write count */ - /* Register work area for each logical drive */ - f_mount(&fs[0], "0:", 0); - f_mount(&fs[1], "1:", 0); + /* Give work areas to each logical drive */ + 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,10 +155,10 @@ int main (void) /* Copy source to destination */ for (;;) { - fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* Read a chunk of source file */ - if (fr || br == 0) break; /* error or eof */ - fr = f_write(&fdst, buffer, br, &bw); /* Write it to the destination file */ - if (fr || bw < br) break; /* error or disk full */ + fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* Read a chunk of data from the source file */ + if (br == 0) break; /* error or eof */ + fr = f_write(&fdst, buffer, br, &bw); /* Write it to the destination file */ + if (bw < br) break; /* error or disk full */ } /* Close open files */ @@ -166,8 +166,8 @@ int main (void) f_close(&fdst); /* Unregister work area prior to discard it */ - f_mount(NULL, "0:", 0); - f_mount(NULL, "1:", 0); + f_unmount("0:"); + f_unmount("1:"); return (int)fr; } diff --git a/fatfs/documents/doc/printf.html b/fatfs/documents/doc/printf.html index 82be70c..eb64e8d 100644 --- a/fatfs/documents/doc/printf.html +++ b/fatfs/documents/doc/printf.html @@ -39,7 +39,7 @@ int f_printf (

    Return Values

    -

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

    +

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

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

    Description

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

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

    When FatFs is configured for Unicode API (FF_LFN_UNICODE >= 1), character encoding on the string fuctions, f_putc, f_puts, f_printf and f_gets function, is also switched to Unicode. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding on the file to be written via this function is selected by FF_STRF_ENCODE. The characters with wrong encoding or invalid for the output encoding will be lost.

    +

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

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

    Example

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

    Return Values

    -

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

    +

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

    diff --git a/fatfs/documents/doc/puts.html b/fatfs/documents/doc/puts.html index 92c7e74..3695942 100644 --- a/fatfs/documents/doc/puts.html +++ b/fatfs/documents/doc/puts.html @@ -35,7 +35,7 @@ int f_puts (

    Return Value

    -

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

    +

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

    diff --git a/fatfs/documents/doc/rc.html b/fatfs/documents/doc/rc.html index 05bcf9e..8f7fffa 100644 --- a/fatfs/documents/doc/rc.html +++ b/fatfs/documents/doc/rc.html @@ -11,7 +11,7 @@

    Return Code of API Functions

    -

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

    +

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

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

    Description

    -

    The function starts to read data from the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, *br should be checked to detect end of the file. In case of *br < btr, it means the read/write pointer reached end of the file during read operation.

    +

    The function starts to read data from the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, *br should be checked to detect end of the file. In case of *br < btr, it means the read/write pointer hit end of the file during read operation.

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

    Example

    +

    Refer to the example in f_open.

    +
    + +

    See Also

    f_open, fgets, f_write, f_close, FIL

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

    Description

    -

    The f_readdir function reads a directory item, informations about the object. All items in the directory can be read in sequence by f_readdir function calls. Dot entries ("." and "..") in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a nul string is stored into the fno->fname[] without any error. When a null pointer is given to the fno, the read index of the directory object is rewinded.

    -

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

    +

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

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

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

    -

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

    +

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

    +

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

    @@ -94,7 +103,7 @@ FRESULT scan_files ( printf("%s/%s\n", path, fno.fname); } } - f_closedir(&dir) + f_closedir(&dir); } return res; diff --git a/fatfs/documents/doc/sdir.html b/fatfs/documents/doc/sdir.html index 53a460d..eb18cc3 100644 --- a/fatfs/documents/doc/sdir.html +++ b/fatfs/documents/doc/sdir.html @@ -19,7 +19,7 @@ FFOBJID obj; /* Object identifier */ DWORD dptr; /* Current read/write offset */ DWORD clust; /* Current cluster */ - DWORD sect; /* Current sector */ + LBA_t sect; /* Current sector */ BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE* fn; /* Pointer to the SFN buffer (in/out) {file[8],ext[3],status[1]} */ #if FF_USE_LFN diff --git a/fatfs/documents/doc/setlabel.html b/fatfs/documents/doc/setlabel.html index c50db18..9eb5e78 100644 --- a/fatfs/documents/doc/setlabel.html +++ b/fatfs/documents/doc/setlabel.html @@ -53,9 +53,9 @@ FRESULT f_setlabel (

    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.

    diff --git a/fatfs/documents/doc/sfatfs.html b/fatfs/documents/doc/sfatfs.html index e5207cb..6ecd6e5 100644 --- a/fatfs/documents/doc/sfatfs.html +++ b/fatfs/documents/doc/sfatfs.html @@ -31,7 +31,7 @@ BYTE* dirbuf; /* Directory entry block scratchpad buffer */ #endif #if FF_FS_REENTRANT - FF_SYNC_t sobj; /* Identifier of sync object */ + FF_SYNC_t sobj; /* Identifier of sync object */ #endif #if !FF_FS_READONLY DWORD last_clust; /* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */ @@ -47,11 +47,11 @@ #endif DWORD n_fatent; /* Number of FAT entries (Number of clusters + 2) */ DWORD fsize; /* Sectors per FAT */ - DWORD volbase; /* Volume base LBA */ - DWORD fatbase; /* FAT base LBA */ - DWORD dirbase; /* Root directory base (LBA|Cluster) */ - DWORD database; /* Data base LBA */ - DWORD winsect; /* Sector LBA appearing in the win[] */ + LBA_t volbase; /* Volume base LBA */ + LBA_t fatbase; /* FAT base LBA */ + LBA_t dirbase; /* Root directory base (LBA|Cluster) */ + LBA_t database; /* Data base LBA */ + LBA_t winsect; /* Sector LBA appearing in the win[] */ BYTE win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data at tiny cfg) */ } FATFS; diff --git a/fatfs/documents/doc/sfile.html b/fatfs/documents/doc/sfile.html index e8a677f..9234d32 100644 --- a/fatfs/documents/doc/sfile.html +++ b/fatfs/documents/doc/sfile.html @@ -22,9 +22,9 @@ BYTE err; /* Abort flag (error code) */ FSIZE_t fptr; /* File read/write pointer (Byte offset origin from top of the file) */ DWORD clust; /* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */ - DWORD sect; /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/ + LBA_t sect; /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/ #if !FF_FS_READONLY - DWORD dir_sect; /* Sector number containing the directory entry */ + LBA_t dir_sect; /* Sector number containing the directory entry */ BYTE* dir_ptr; /* Ponter to the directory entry in the window */ #endif #if FF_USE_FASTSEEK diff --git a/fatfs/documents/doc/sfileinfo.html b/fatfs/documents/doc/sfileinfo.html index b4c9063..db0f45e 100644 --- a/fatfs/documents/doc/sfileinfo.html +++ b/fatfs/documents/doc/sfileinfo.html @@ -13,7 +13,7 @@

    FILINFO

    -

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

    +

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

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

    Members

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

    Return

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

    Description

    -

    The f_stat function checks the existence of a file or sub-directory. If not exist, the function returns with FR_NO_FILE. If exist, the function returns with FR_OK and the informations of the object, file size, timestamp and attribute, are stored to the file information structure. For details of the file information, refer to the FILINFO structure and f_readdir function.

    +

    The f_stat function checks the existence of a file or sub-directory in the directory. If it is not exist, the function returns with FR_NO_FILE. If it is exist, the function returns with FR_OK and the informations about the object, size, timestamp and attribute, is stored to the file information structure. For details of the file information, refer to the FILINFO structure and f_readdir function.

    +

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

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

    Description

    -

    The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync function of periodic or immediataly after f_write function can minimize the risk of data loss due to a sudden blackout or an unintentional media removal. For more information, refer to application note.

    +

    The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync function in certain interval can minimize the risk of data loss due to a sudden blackout, wrong media removal or unrecoverable disk error. For more information, refer to application note.

    +
    +Case 1. Normal write sequence
    +
    +                                Time -->                                     ↓Normal shutdown
    +OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC <Power off>
    +
    +
    +Case 2. Without using f_sync()
    +
    +                                Time -->                             ↓System crush
    +Owwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
    + |<--------------- All data written will be lost ------------------>|
    +
    +
    +Case 3. Using f_sync()
    +                                Time -->                             ↓System crush
    +OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwww
    +                            Data after last f_sync will be lost |<->| 
    +O - f_open()
    +C - f_close()
    +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.

    diff --git a/fatfs/documents/doc/unlink.html b/fatfs/documents/doc/unlink.html index 26f3cb9..7809648 100644 --- a/fatfs/documents/doc/unlink.html +++ b/fatfs/documents/doc/unlink.html @@ -13,7 +13,7 @@

    f_unlink

    -

    The f_unlink function removes a file or sub-directory.

    +

    The f_unlink function removes a file or sub-directory from the volume.

     FRESULT f_unlink (
       const TCHAR* path  /* [IN] Object name */
    diff --git a/fatfs/documents/doc/write.html b/fatfs/documents/doc/write.html
    index d451255..3d16674 100644
    --- a/fatfs/documents/doc/write.html
    +++ b/fatfs/documents/doc/write.html
    @@ -32,9 +32,9 @@ FRESULT f_write (
     
    buff
    Pointer to the data to be written.
    btw
    -
    Specifies number of bytes to write in range of UINT type.
    +
    Specifies number of bytes to write in range of UINT type. If the data needs to be written fast, it should be written in large chunk as possible.
    bw
    -
    Pointer to the UINT variable to return the number of bytes written. This value is always valid after the function call regardless of the function return code.
    +
    Pointer to the UINT variable that receives the number of bytes written. This value is always valid after the function call regardless of the function return code. If the return value is equal to btw, the function return code should be FR_OK.
    @@ -54,7 +54,7 @@ FRESULT f_write (

    Description

    -

    The function starts to write data to the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, *bw should be checked to detect the disk full. In case of *bw < btw, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.

    +

    The function starts to write data to the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, *bw should be checked to detect the disk full. In case of *bw < btw, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.

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

    Example

    +

    Refer to the example in f_open.

    +
    + +

    See Also

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

    -- cgit v1.2.3