diff --git a/documents/css_e.css b/documents/css_e.css index eb21281..e1723d6 100644 --- a/documents/css_e.css +++ b/documents/css_e.css @@ -31,6 +31,7 @@ hr {border-width: 1px; margin: 1em;} div.abst {font-family: sans-serif;} div.para {clear: both; font-family: serif;} div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; } +ul.plain {margin: 0 0 0 1em;} .equ {text-indent: 0; margin: 1em 2em 1em;} .indent {margin-left: 2em;} .rset {float: right; margin: 0.3em 0 0.5em 0.5em;} diff --git a/documents/doc/appnote.html b/documents/doc/appnote.html index 117645b..6d6095e 100644 --- a/documents/doc/appnote.html +++ b/documents/doc/appnote.html @@ -90,7 +90,7 @@ The FatFs module is a middleware written in ANSI C (C89). There is no platform d
  • Volume/Drive Configurations @@ -56,7 +57,7 @@
  • FF_FS_EXFAT
  • FF_FS_NORTC
  • FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR
  • -
  • FF_FS_CTIME
  • +
  • FF_FS_CRTIME
  • FF_FS_NOFSINFO
  • FF_FS_LOCK
  • FF_FS_REENTRANT
  • @@ -170,7 +171,7 @@

    FF_USE_LFN

    -

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

    +

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

    @@ -180,7 +181,7 @@
    ValueDescription
    0Disable LFN. Path name in only 8.3 format can be used.

    FF_MAX_LFN

    -

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

    +

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

    FF_LFN_UNICODE

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

    @@ -191,7 +192,7 @@ 2Unicode in UTF-8char 3Unicode in UTF-32DWORD -

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

    +

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

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

    FF_LFN_BUF, FF_SFN_BUF

    @@ -203,17 +204,21 @@ Unicode in UTF-16/32255 items12 items Unicode in UTF-8765 items34 items -

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

    +

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

    -

    FF_FS_RPATH

    -

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

    +

    FF_RPATH

    +

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

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

    FF_PATH_DEPTH

    +

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

    +

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

    + @@ -224,12 +229,12 @@

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

    FF_STR_VOLUME_ID

    -

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

    +

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

    - - - + + +
    ValueDescriptionExample
    0DOS/Windows style drive prefix in numeric ID.1:/filename
    10 + DOS/Windows style drive prefix in arbitry string ID.flash:/filename
    20 + Unix style drive prefix in arbitry string ID./flash/filename
    0DOS/Windows style drive prefix in numeric ID.1:/filename
    10 + DOS/Windows style drive prefix in arbitry string ID.flash:/filename
    20 + Unix style drive prefix in arbitry string ID./flash/filename

    FF_VOLUME_STRS

    @@ -272,7 +277,7 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb"};

    FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR

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

    -

    FF_FS_CTIME

    +

    FF_FS_CRTIME

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

    FF_FS_NOFSINFO

    @@ -302,6 +307,6 @@ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb"}; -

    Return

    +

    Return

    diff --git a/documents/doc/dinit.html b/documents/doc/dinit.html index 9470f34..ac3b13e 100644 --- a/documents/doc/dinit.html +++ b/documents/doc/dinit.html @@ -40,6 +40,6 @@ DSTATUS disk_initialize ( -

    Return

    +

    Return

    diff --git a/documents/doc/dioctl.html b/documents/doc/dioctl.html index e071ed7..13f67ef 100644 --- a/documents/doc/dioctl.html +++ b/documents/doc/dioctl.html @@ -94,6 +94,6 @@ DRESULT disk_ioctl ( -

    Return

    +

    Return

    diff --git a/documents/doc/dread.html b/documents/doc/dread.html index 94b1c38..64b9e66 100644 --- a/documents/doc/dread.html +++ b/documents/doc/dread.html @@ -66,6 +66,6 @@ DRESULT disk_read ( -

    Return

    +

    Return

    diff --git a/documents/doc/dstat.html b/documents/doc/dstat.html index 40d7336..2e3c6e5 100644 --- a/documents/doc/dstat.html +++ b/documents/doc/dstat.html @@ -42,6 +42,6 @@ DSTATUS disk_status ( -

    Return

    +

    Return

    diff --git a/documents/doc/dwrite.html b/documents/doc/dwrite.html index 39cdb63..66cd3e7 100644 --- a/documents/doc/dwrite.html +++ b/documents/doc/dwrite.html @@ -69,6 +69,6 @@ DRESULT disk_write ( -

    Return

    +

    Return

    diff --git a/documents/doc/eof.html b/documents/doc/eof.html index dc54245..01adf5e 100644 --- a/documents/doc/eof.html +++ b/documents/doc/eof.html @@ -56,6 +56,6 @@ int f_eof ( -

    Return

    +

    Return

    diff --git a/documents/doc/error.html b/documents/doc/error.html index 11759d7..e45430d 100644 --- a/documents/doc/error.html +++ b/documents/doc/error.html @@ -56,6 +56,6 @@ int f_error ( -

    Return

    +

    Return

    diff --git a/documents/doc/expand.html b/documents/doc/expand.html index 35cfa4b..de78053 100644 --- a/documents/doc/expand.html +++ b/documents/doc/expand.html @@ -111,6 +111,6 @@ FRESULT f_expand ( -

    Return

    +

    Return

    diff --git a/documents/doc/fattime.html b/documents/doc/fattime.html index 5a99b6a..6aa310d 100644 --- a/documents/doc/fattime.html +++ b/documents/doc/fattime.html @@ -73,6 +73,6 @@ DWORD get_fattime (void) -

    Return

    +

    Return

    diff --git a/documents/doc/fdisk.html b/documents/doc/fdisk.html index 2957c86..3f51e6d 100644 --- a/documents/doc/fdisk.html +++ b/documents/doc/fdisk.html @@ -89,6 +89,6 @@ FRESULT f_fdisk ( -

    Return

    +

    Return

    diff --git a/documents/doc/filename.html b/documents/doc/filename.html index e0da008..e56e870 100644 --- a/documents/doc/filename.html +++ b/documents/doc/filename.html @@ -12,12 +12,12 @@

    Format of the Path Names

    -

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

    +

    The format of path name (path to an object (file or sub-directory)) on the FatFs module is similer to the file name specs of DOS/Windos as follows:

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

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

    -

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

    -

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

    -

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

    +

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

    +

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

    +

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

    +

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

    @@ -27,22 +27,20 @@ - - - + +
    Path nameFF_FS_RPATH == 0FF_FS_RPATH >= 1
    file.txtA file in the root directory of the drive 0A file in the current directory of the current drive
    2:The root directory of the drive 2The current directory of the drive 2
    2:/The root directory of the drive 2The root directory of the drive 2
    2:file.txtA file in the root directory of the drive 2A file in the current directory of the drive 2
    ../file.txtInvalid nameA file in the parent directory
    .Invalid nameThis directory
    ..Invalid nameParent directory of the current directory (*)
    dir1/..Invalid nameThe current directory
    ..Invalid nameParent directory
    ../file.txtInvalid nameA file in the parent directory
    /..Invalid nameThe root directory (sticks the top level)
    -

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

    -

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

    -

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

    +

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

    +

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

    Legal Characters and Case Sensitivity

    -

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

    -

    FAT filesystem is case-insensitive to the object names on the volume. Object names on the FAT volume are 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 original name is recorded to the LFN entry if LFN extension is enabled.

    -

    On the MS-DOS and PC DOS for Chinese, Japanese and Korean (DOS/DBCS), extended characters are recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on 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.

    +

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

    +

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

    +

    On the MS-DOS and PC DOS for Chinese, Japanese and Korean (DOS/DBCS), extended characters are recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on compatibility with Windows system when the file 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.

    @@ -71,10 +69,8 @@ PARTITION VolToPart[FF_VOLUMES] = { {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 when enable the multi-partition configuration.

    -

    Return

    +

    Return

    diff --git a/documents/doc/findfirst.html b/documents/doc/findfirst.html index e02ff03..e607304 100644 --- a/documents/doc/findfirst.html +++ b/documents/doc/findfirst.html @@ -111,6 +111,6 @@ void find_image_file (void)

    f_findnext, f_closedir, DIR, FILINFO

    -

    Return

    +

    Return

    diff --git a/documents/doc/findnext.html b/documents/doc/findnext.html index f75a28d..cf2ab4d 100644 --- a/documents/doc/findnext.html +++ b/documents/doc/findnext.html @@ -63,6 +63,6 @@ FRESULT f_findnext ( -

    Return

    +

    Return

    diff --git a/documents/doc/forward.html b/documents/doc/forward.html index 09fa9f3..96b29d9 100644 --- a/documents/doc/forward.html +++ b/documents/doc/forward.html @@ -133,6 +133,6 @@ FRESULT play_file ( -

    Return

    +

    Return

    diff --git a/documents/doc/getcwd.html b/documents/doc/getcwd.html index 3315149..debeba3 100644 --- a/documents/doc/getcwd.html +++ b/documents/doc/getcwd.html @@ -11,11 +11,11 @@

    f_getcwd

    -

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

    +

    The f_getcwd function retrieves the current directory and current drive.

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

    Parameters

    buff
    -
    Pointer to the buffer to receive the current directory string.
    +
    Pointer to the string buffer to receive the current directory path.
    len
    -
    Size of the buffer in unit of TCHAR.
    +
    Size of the buffer in unit of (TCHAR).
    @@ -49,7 +49,6 @@ 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 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.

    @@ -77,6 +76,6 @@ FRESULT f_getcwd ( -

    Return

    +

    Return

    diff --git a/documents/doc/getfree.html b/documents/doc/getfree.html index a16272f..84decdc 100644 --- a/documents/doc/getfree.html +++ b/documents/doc/getfree.html @@ -87,6 +87,6 @@ FRESULT f_getfree (

    FATFS

    -

    Return

    +

    Return

    diff --git a/documents/doc/getlabel.html b/documents/doc/getlabel.html index 09a940f..e950258 100644 --- a/documents/doc/getlabel.html +++ b/documents/doc/getlabel.html @@ -83,6 +83,6 @@ FRESULT f_getlabel ( -

    Return

    +

    Return

    diff --git a/documents/doc/gets.html b/documents/doc/gets.html index bcc6bf2..32bf91f 100644 --- a/documents/doc/gets.html +++ b/documents/doc/gets.html @@ -59,6 +59,6 @@ TCHAR* f_gets ( -

    Return

    +

    Return

    diff --git a/documents/doc/index.html b/documents/doc/index.html new file mode 100644 index 0000000..64ae8af --- /dev/null +++ b/documents/doc/index.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/documents/doc/lseek.html b/documents/doc/lseek.html index 9016018..1b97947 100644 --- a/documents/doc/lseek.html +++ b/documents/doc/lseek.html @@ -134,6 +134,6 @@ FRESULT f_rewind ( -

    Return

    +

    Return

    diff --git a/documents/doc/mkdir.html b/documents/doc/mkdir.html index 6c6550b..063baaa 100644 --- a/documents/doc/mkdir.html +++ b/documents/doc/mkdir.html @@ -74,6 +74,6 @@ FRESULT f_mkdir ( -

    Return

    +

    Return

    diff --git a/documents/doc/mkfs.html b/documents/doc/mkfs.html index 030b91b..d50dfb2 100644 --- a/documents/doc/mkfs.html +++ b/documents/doc/mkfs.html @@ -121,6 +121,6 @@ int main (void) -

    Return

    +

    Return

    diff --git a/documents/doc/mount.html b/documents/doc/mount.html index c33e6db..2599809 100644 --- a/documents/doc/mount.html +++ b/documents/doc/mount.html @@ -30,11 +30,11 @@ FRESULT f_unmount (

    Parameters

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

    Description

    -

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

    +

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

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

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

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

    -

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

    +

    If there are open objects of file or directory on the logical drive, they will be invalidated by this function.

    +

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

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

    -

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

    +

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

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

     #define f_unmount(path) f_mount(0, path, 0)
    @@ -116,6 +116,6 @@ int main (void)
     
    -

    Return

    +

    Return

    diff --git a/documents/doc/open.html b/documents/doc/open.html index 028e337..d1f1e24 100644 --- a/documents/doc/open.html +++ b/documents/doc/open.html @@ -180,6 +180,6 @@ int main (void) -

    Return

    +

    Return

    diff --git a/documents/doc/opendir.html b/documents/doc/opendir.html index d8ea3a9..c5ebe8c 100644 --- a/documents/doc/opendir.html +++ b/documents/doc/opendir.html @@ -69,6 +69,6 @@ FRESULT f_opendir ( -

    Return

    +

    Return

    diff --git a/documents/doc/printf.html b/documents/doc/printf.html index 7e29ed2..dfeca11 100644 --- a/documents/doc/printf.html +++ b/documents/doc/printf.html @@ -109,6 +109,6 @@ int f_printf ( -

    Return

    +

    Return

    diff --git a/documents/doc/putc.html b/documents/doc/putc.html index cd82766..2e2839b 100644 --- a/documents/doc/putc.html +++ b/documents/doc/putc.html @@ -54,6 +54,6 @@ int f_putc ( -

    Return

    +

    Return

    diff --git a/documents/doc/puts.html b/documents/doc/puts.html index 7b7ebe1..5687679 100644 --- a/documents/doc/puts.html +++ b/documents/doc/puts.html @@ -55,6 +55,6 @@ int f_puts ( -

    Return

    +

    Return

    diff --git a/documents/doc/rc.html b/documents/doc/rc.html index 4eb30d6..54f28b8 100644 --- a/documents/doc/rc.html +++ b/documents/doc/rc.html @@ -17,7 +17,7 @@
    The function succeeded.
    FR_DISK_ERR
    -
    The lower layer, disk_read, disk_write or disk_ioctl function, reported that an unrecoverable hard error occured.
    Note that if once this error occured at any operation to an open file, the file object is aborted and any operations to the file except for close will be rejected.
    +
    The lower layer, disk_read, disk_write or disk_ioctl function, reported that an unrecoverable hard error occured.
    Note that if once this error occured in the operation to an open file, the file object is aborted and any operations to the file except f_close will be rejected.
    FR_INT_ERR
    Assertion failed and an insanity is detected in the internal process. One of the following possibilities is suspected. @@ -27,7 +27,7 @@
  • There is a bug in the FatFs module itself.
  • Wrong lower layer implementation.
  • -Note that if once this error occured in the operation to an open file, the file object is aborted and any operation to the file except for close will be rejected. +Note that if once this error occured in the operation to an open file, the file object is aborted and any operation to the file except f_close will be rejected.
    FR_NOT_READY
    @@ -44,14 +44,14 @@ Note that if once this error occured in the operation to an open file, the file
    Could not find the file in the directory.
    FR_NO_PATH
    -
    Could not find the path. A directory in the path name could not be found.
    +
    Could not follow the path. A sub-directory in the path name could not be found.
    FR_INVALID_NAME
    The given string is invalid as a path name. One of the following possibilities is suspected.
    @@ -59,30 +59,30 @@ Note that if once this error occured in the operation to an open file, the file
    FR_DENIED
    The required access was denied due to one of the following reasons:
    FR_EXIST
    -
    Name collision. An object with the same name is already existing in the directory.
    +
    Name collision. A file or sub-directory with the same name is already existing in the directory.
    FR_INVALID_OBJECT
    The file/directory object is invalid or the pointer is null. There are some reasons as follows:
    FR_WRITE_PROTECTED
    -
    A write mode operation against the write-protected media.
    +
    A write mode operation against the write-protected medium.
    FR_INVALID_DRIVE
    Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: FF_VOLUMES)
    @@ -111,13 +111,14 @@ Note that if once this error occured in the operation to an open file, the file
    The function was canceled due to a timeout of thread-safe control. (Related option: FF_TIMEOUT)
    FR_LOCKED
    -
    The operation to the object was rejected by file sharing control. (Related option: FF_FS_LOCK)
    +
    The operation to the file or sub-directory was rejected by file sharing control. (Related option: FF_FS_LOCK)
    FR_NOT_ENOUGH_CORE
    Not enough memory for the operation. There is one of the following reasons:
    @@ -129,6 +130,6 @@ Note that if once this error occured in the operation to an open file, the file -

    Return

    +

    Return

    diff --git a/documents/doc/read.html b/documents/doc/read.html index 7b53279..4432a1c 100644 --- a/documents/doc/read.html +++ b/documents/doc/read.html @@ -74,6 +74,6 @@ FRESULT f_read ( -

    Return

    +

    Return

    diff --git a/documents/doc/readdir.html b/documents/doc/readdir.html index 7feb32d..7d47f47 100644 --- a/documents/doc/readdir.html +++ b/documents/doc/readdir.html @@ -168,6 +168,6 @@ int main (void) -

    Return

    +

    Return

    diff --git a/documents/doc/rename.html b/documents/doc/rename.html index e561a43..e221efb 100644 --- a/documents/doc/rename.html +++ b/documents/doc/rename.html @@ -24,9 +24,9 @@ FRESULT f_rename (

    Parameters

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

    Description

    -

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

    +

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

    +

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

    +

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

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

    Return

    +

    Return

    diff --git a/documents/doc/sdir.html b/documents/doc/sdir.html index 71ed4d2..97c06b4 100644 --- a/documents/doc/sdir.html +++ b/documents/doc/sdir.html @@ -14,7 +14,7 @@

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

     typedef struct {
    -    FFOBJID obj;        /* Object identifier */
    +    FFOBJID obj;        /* Object identifier */
         DWORD   dptr;       /* Current read/write offset */
         DWORD   clust;      /* Current cluster */
         LBA_t   sect;       /* Current sector */
    @@ -25,13 +25,13 @@
         WCHAR*  lfn;        /* Pointer to the LFN working buffer (in/out) */
     #endif
     #if FF_USE_FIND
    -    const TCHAR*  pat;  /* Ponter to the matching pattern */
    +    const TCHAR* pat;   /* Ponter to the matching pattern */
     #endif
     } DIR;
     
    -

    Return

    +

    Return

    diff --git a/documents/doc/setcp.html b/documents/doc/setcp.html index 2ea3318..a4b9348 100644 --- a/documents/doc/setcp.html +++ b/documents/doc/setcp.html @@ -75,6 +75,6 @@ FRESULT f_setcp ( -

    Return

    +

    Return

    diff --git a/documents/doc/setlabel.html b/documents/doc/setlabel.html index 64e7908..d926ebb 100644 --- a/documents/doc/setlabel.html +++ b/documents/doc/setlabel.html @@ -88,6 +88,6 @@ FRESULT f_setlabel ( -

    Return

    +

    Return

    diff --git a/documents/doc/sfatfs.html b/documents/doc/sfatfs.html index 30909bb..82f778f 100644 --- a/documents/doc/sfatfs.html +++ b/documents/doc/sfatfs.html @@ -15,7 +15,8 @@
     typedef struct {
         BYTE    fs_type;      /* FAT type (0, FS_FAT12, FS_FAT16, FS_FAT32 or FS_EXFAT) */
    -    BYTE    pdrv;         /* Hosting physical drive of this volume */
    +    BYTE    pdrv;         /* Physical drive that holds this volume */
    +    BYTE    ldrv;         /* Logical drive number (used only when FF_FS_REENTRANT) */
         BYTE    n_fats;       /* Number of FAT copies (1,2) */
         BYTE    wflag;        /* win[] flag (b0:win[] is dirty) */
         BYTE    fsi_flag;     /* FSINFO flags (b7:Disabled, b0:Dirty) */
    @@ -25,36 +26,36 @@
     #if FF_MAX_SS != FF_MIN_SS
         WORD    ssize;        /* Sector size (512,1024,2048 or 4096) */
     #endif
    -#if FF_FS_EXFAT
    -    BYTE*   dirbuf;       /* Directory entry block scratchpad buffer */
    -#endif
    -#if FF_FS_REENTRANT
    -    FF_SYNC_t sobj;       /* Identifier of sync object */
    +#if FF_USE_LFN
    +    WCHAR*  lfnbuf;       /* Pointer to LFN working buffer */
     #endif
     #if !FF_FS_READONLY
    -    DWORD   last_clust;   /* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */
    -    DWORD   free_clust;   /* FSINFO: Number of free clusters (0xFFFFFFFF if invalid) */
    +    DWORD   last_clust;   /* FSINFO: Last allocated cluster (invalid if >=n_fatent) */
    +    DWORD   free_clust;   /* FSINFO: Number of free clusters (invalid if >=fs->n_fatent-2) */
     #endif
     #if FF_FS_RPATH
         DWORD   cdir;         /* Cluster number of current directory (0:root) */
    -#if FF_FS_EXFAT
    -    DWORD   cdc_scl;      /* Containing directory start cluster (invalid when cdir is 0) */
    -    DWORD   cdc_size;     /* b31-b8:Size of containing directory, b7-b0: Chain status */
    -    DWORD   cdc_ofs;      /* Offset in the containing directory (invalid when cdir is 0) */
    -#endif
     #endif
         DWORD   n_fatent;     /* Number of FAT entries (Number of clusters + 2) */
         DWORD   fsize;        /* Sectors per FAT */
    +    LBA_t   winsect;      /* Sector LBA appearing in the win[] */
         LBA_t   volbase;      /* Volume base LBA */
         LBA_t   fatbase;      /* FAT base LBA */
         LBA_t   dirbase;      /* Root directory base (LBA|Cluster) */
         LBA_t   database;     /* Data base LBA */
    -    LBA_t   winsect;      /* Sector LBA appearing in the win[] */
    +#if FF_FS_EXFAT
    +    LBA_t   bitbase;      /* Allocation bitmap base sector */
    +    BYTE*   dirbuf;       /* Directory entry block scratchpad buffer */
    +#if FF_FS_RPATH
    +    FFXCWDS xcwds;        /* Current working directory structure */
    +    FFXCWDS xcwds2;       /* Working buffer to follow the path */
    +#endif
    +#endif
         BYTE    win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data at tiny cfg) */
     } FATFS;
     
    -

    Return

    +

    Return

    diff --git a/documents/doc/sfile.html b/documents/doc/sfile.html index 40c8e74..fb5ac60 100644 --- a/documents/doc/sfile.html +++ b/documents/doc/sfile.html @@ -15,18 +15,18 @@
     typedef struct {
    -    FFOBJID obj;          /* Object identifier */
    -    BYTE    flag;         /* File object status flags */
    +    FFOBJID obj;          /* Object identifier */
    +    BYTE    flag;         /* File status flags */
         BYTE    err;          /* Abort flag (error code) */
    -    FSIZE_t fptr;         /* File read/write pointer (Byte offset origin from top of the file) */
    -    DWORD   clust;        /* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */
    -    LBA_t   sect;         /* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/
    +    FSIZE_t fptr;         /* File read/write pointer (byte offset origin from top of the file; 0 on open) */
    +    DWORD   clust;        /* Current cluster of fptr (one cluster behind if fptr is on the cluster boundary; invalid if fptr == 0) */
    +    LBA_t   sect;         /* Current data sector (can be invalid if fptr is on the cluster boundary)*/
     #if !FF_FS_READONLY
         LBA_t   dir_sect;     /* Sector number containing the directory entry */
    -    BYTE*   dir_ptr;      /* Ponter to the directory entry in the window */
    +    BYTE*   dir_ptr;      /* Pointer to the directory entry in the window */
     #endif
     #if FF_USE_FASTSEEK
    -    DWORD*  cltbl;        /* Pointer to the cluster link map table (Nulled on file open. Set by application.) */
    +    DWORD*  cltbl;        /* Pointer to the cluster link map table (nulled on file open; set by application) */
     #endif
     #if !FF_FS_TINY
         BYTE    buf[FF_MAX_SS]; /* File private data transfer buffer (Always valid if fptr is not on the sector boundary but can be invalid if fptr is on the sector boundary.) */
    @@ -37,6 +37,6 @@
     
     
     
    -

    Return

    +

    Return

    diff --git a/documents/doc/sfileinfo.html b/documents/doc/sfileinfo.html index e1fe1d2..23e1312 100644 --- a/documents/doc/sfileinfo.html +++ b/documents/doc/sfileinfo.html @@ -14,14 +14,14 @@

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

     typedef struct {
    -    FSIZE_t fsize;               /* File size */
    -    WORD    fdate;               /* Last modified date */
    -    WORD    ftime;               /* Last modified time */
    +    FSIZE_t fsize;               /* File size (invalid for directory) */
    +    WORD    fdate;               /* Date of file modification or directory creation */
    +    WORD    ftime;               /* Time of file modification or directory creation */
     #if FF_FS_CRTIME
    -    WORD    crdate;              /* Created date */
    -    WORD    crtime;              /* Created time */
    +    WORD    crdate;              /* Date of object createion */
    +    WORD    crtime;              /* Time of object createion */
     #endif
    -    BYTE    fattrib;             /* Attribute */
    +    BYTE    fattrib;             /* Object attribute */
     #if FF_USE_LFN
         TCHAR   altname[FF_SFN_BUF + 1]; /* Alternative object name */
         TCHAR   fname[FF_LFN_BUF + 1];   /* Primary object name */
    @@ -82,6 +82,6 @@
     
     
     
    -

    Return

    +

    Return

    diff --git a/documents/doc/size.html b/documents/doc/size.html index 3b0a86e..75a9f4e 100644 --- a/documents/doc/size.html +++ b/documents/doc/size.html @@ -56,6 +56,6 @@ FSIZE_t f_size ( -

    Return

    +

    Return

    diff --git a/documents/doc/sobjid.html b/documents/doc/sobjid.html new file mode 100644 index 0000000..c512cc0 --- /dev/null +++ b/documents/doc/sobjid.html @@ -0,0 +1,42 @@ + + + + + + +FatFs - FFOBJID + + + + +
    +

    FFOBJID

    +

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

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

    Return

    + + diff --git a/documents/doc/stat.html b/documents/doc/stat.html index 66806e0..2734c3e 100644 --- a/documents/doc/stat.html +++ b/documents/doc/stat.html @@ -107,6 +107,6 @@ FRESULT f_stat ( -

    Return

    +

    Return

    diff --git a/documents/doc/sxcwds.html b/documents/doc/sxcwds.html new file mode 100644 index 0000000..9b236d2 --- /dev/null +++ b/documents/doc/sxcwds.html @@ -0,0 +1,31 @@ + + + + + + +FatFs - FFXCWDS + + + + +
    +

    FFXCWDS

    +

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

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

    Return

    + + diff --git a/documents/doc/sync.html b/documents/doc/sync.html index 2da3ef9..d2fb64a 100644 --- a/documents/doc/sync.html +++ b/documents/doc/sync.html @@ -82,6 +82,6 @@ S - f_sync() -

    Return

    +

    Return

    diff --git a/documents/doc/tell.html b/documents/doc/tell.html index d40a0ba..ef47a3d 100644 --- a/documents/doc/tell.html +++ b/documents/doc/tell.html @@ -56,6 +56,6 @@ FSIZE_t f_tell ( -

    Return

    +

    Return

    diff --git a/documents/doc/truncate.html b/documents/doc/truncate.html index 307bdb5..d48680a 100644 --- a/documents/doc/truncate.html +++ b/documents/doc/truncate.html @@ -59,6 +59,6 @@ FRESULT f_truncate ( -

    Return

    +

    Return

    diff --git a/documents/doc/unlink.html b/documents/doc/unlink.html index 6d1bc73..be49764 100644 --- a/documents/doc/unlink.html +++ b/documents/doc/unlink.html @@ -67,6 +67,6 @@ If condition of the object to be removed is applicable to the following terms, t -

    Return

    +

    Return

    diff --git a/documents/doc/utime.html b/documents/doc/utime.html index 9f07321..12d913a 100644 --- a/documents/doc/utime.html +++ b/documents/doc/utime.html @@ -95,6 +95,6 @@ FRESULT set_timestamp ( -

    Return

    +

    Return

    diff --git a/documents/doc/write.html b/documents/doc/write.html index d104f63..8037429 100644 --- a/documents/doc/write.html +++ b/documents/doc/write.html @@ -74,6 +74,6 @@ FRESULT f_write ( -

    Return

    +

    Return

    diff --git a/documents/00index_e.html b/documents/index.html similarity index 91% rename from documents/00index_e.html rename to documents/index.html index ccb4186..754f2de 100644 --- a/documents/00index_e.html +++ b/documents/index.html @@ -4,9 +4,6 @@ - - - FatFs - Generic FAT Filesystem Module @@ -17,7 +14,7 @@
    layer -

    FatFs is a generic FAT/exFAT filesystem module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk control layer. Therefore it is independent of the platforms and storage devices. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, RX and etc. Also Petit FatFs module for tiny microcontrollers is available here🔗.

    +

    FatFs is a generic FAT/exFAT filesystem module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk control layer. Therefore it is independent of the platforms and storage devices. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, RX and etc. Also Petit FatFs module for tiny microcontrollers is available here.

    Features


    -

    Go to FatFs Home Page

    +

    Home Page

    diff --git a/documents/updates.html b/documents/updates.html index facbdc4..40da6a5 100644 --- a/documents/updates.html +++ b/documents/updates.html @@ -13,25 +13,44 @@ RevisionUpdatesMigration Notes + +R0.16
    Jul 22, 2025 + + + + + + + + R0.15b
    Jun 21, 2025 -Added support for timestamp of created time. (FF_FS_CRTIME)
    -Fixed FatFs fails to load the FsInfo in FAT32 volumes and the f_getfree always be forced a full FAT scan which takes a long time. (appeared at R0.15a)
    - + -Small changes to the f_utime function to support for the timestamp of created time.
    - + R0.15a
    Nov 22, 2024 -Fixed a complie error when FF_FS_LOCK != 0. (appeared at R0.15)
    -Fixed a potential issue when work FatFs concurrency with FF_FS_REENTRANT, FF_VOLUMES >= 2 and FF_FS_LOCK > 0.
    -Made f_setlabel accept a volume label with Unix style volume ID when FF_STR_VOLUME_ID == 2.
    -Made FatFs update PercInUse field in exFAT VBR. (A preceding f_getfree is needed for the accuracy)
    - + @@ -39,506 +58,630 @@ Made FatFs update PercInUse field in exFAT VBR. (A preceding f_getf R0.15
    Nov 6, 2022 -Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
    -Fixed a potential error in f_mount when FF_FS_REENTRANT.
    -Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
    -Fixed f_mkfs creates broken exFAT volume when the size of volume is >= 2^32 sectors.
    -Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
    -Fixed a compatibility issue in identification of GPT header.
    - +
      +
    • Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
    • +
    • Fixed a potential error in f_mount when FF_FS_REENTRANT.
    • +
    • Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
    • +
    • Fixed f_mkfs creates broken exFAT volume when the size of volume is >= 2^32 sectors.
    • +
    • Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
    • +
    • Fixed a compatibility issue in identification of GPT header.
    • +
    -User provided synchronization functions, ff_cre_syncobj, ff_del_syncobj, ff_req_grant and ff_rel_grant, needed when FF_FS_REENTRANT are replaced with ff_mutex_create, ff_mutex_delete, ff_mutex_take and ff_mutex_give respectively. For example, see ffsystem.c.
    -FF_SYNC_t is removed from the configuration options.
    - +
      +
    • User provided synchronization functions, ff_cre_syncobj, ff_del_syncobj, ff_req_grant and ff_rel_grant, needed when FF_FS_REENTRANT are replaced with ff_mutex_create, ff_mutex_delete, ff_mutex_take and ff_mutex_give respectively. For example, see ffsystem.c.
    • +
    • FF_SYNC_t is removed from the configuration options.
    • +
    R0.14b
    Apr 17, 2021 -Made FatFs uses standard library string.h for copy, compare and search instead of built-in string functions.
    -Added support for long long integer and floating point to f_printf. (FF_STRF_LLI and FF_STRF_FP)
    -Made path name parser ignores the terminating separator to allow "dir/".
    -Improved the compatibility in Unix style path name feature.
    -Fixed the file gets dead-locked when f_open failed with certain conditions. (appeared at R0.12a)
    -Fixed f_mkfs can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
    -Fixed code page 855 cannot be set by f_setcp. (appeared at R0.13)
    -Fixed some compiler warnings.
    +
      +
    • Made FatFs uses standard library string.h for copy, compare and search instead of built-in string functions.
    • +
    • Added support for long long integer and floating point to f_printf. (FF_STRF_LLI and FF_STRF_FP)
    • +
    • Made path name parser ignores the terminating separator to allow "dir/".
    • +
    • Improved the compatibility in Unix style path name feature.
    • +
    • Fixed the file gets dead-locked when f_open failed with certain conditions. (appeared at R0.12a)
    • +
    • Fixed f_mkfs can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
    • +
    • Fixed code page 855 cannot be set by f_setcp. (appeared at R0.13)
    • +
    • Fixed some compiler warnings.
    • +
    -From this revision, FatFs depends on string.h.
    +
      +
    • From this revision, FatFs depends on string.h.
    • +
    R0.14a
    Dec 05, 2020 -Limited number of recursive calls in f_findnext to prevent stack overflow.
    -Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
    -Fixed some compiler warnings.
    +
      +
    • Limited number of recursive calls in f_findnext to prevent stack overflow.
    • +
    • Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
    • +
    • Fixed some compiler warnings.
    • +
    -Number of wildcards in the matching pattern in f_findfirst is limited to 4.
    +
      +
    • Number of wildcards in the matching pattern in f_findfirst is limited to 4.
    • +
    R0.14
    Oct 14, 2019 -Added support for 64-bit LBA and GUID partition table (FF_LBA64)
    -Changed some API functions, f_mkfs and f_fdisk.
    -Fixed f_open cannot find the file with file name in length of FF_MAX_LFN characters.
    -Fixed f_readdir cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
    -Fixed f_readdir returns file names with wrong case conversion. (appeared at R0.12)
    -Fixed f_mkfs can fail to create exFAT volume in the second partition. (appeared at R0.12)
    +
      +
    • Added support for 64-bit LBA and GUID partition table (FF_LBA64)
    • +
    • Changed some API functions, f_mkfs and f_fdisk.
    • +
    • Fixed f_open cannot find the file with file name in length of FF_MAX_LFN characters.
    • +
    • Fixed f_readdir cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
    • +
    • Fixed f_readdir returns file names with wrong case conversion. (appeared at R0.12)
    • +
    • Fixed f_mkfs can fail to create exFAT volume in the second partition. (appeared at R0.12)
    • +
    -Usage of f_mkfs and f_fdisk is changed and some features are added to these functions.
    +
      +
    • Usage of f_mkfs and f_fdisk is changed and some features are added to these functions.
    • +
    R0.13c
    Oct 14, 2018 -Supported stdint.h for C99 and later. (integer.h was included in ff.h)
    -Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
    -Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
    -Fixed f_getcwd cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
    +
      +
    • Supported stdint.h for C99 and later. (integer.h was included in ff.h)
    • +
    • Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
    • +
    • Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
    • +
    • Fixed f_getcwd cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
    • +
    -From this revision, FatFs depends on stdint.h in C99 or later.
    -integer.h is removed.
    +
      +
    • From this revision, FatFs depends on stdint.h in C99 or later.
    • +
    • integer.h is removed.
    • +
    R0.13b
    Apr 07, 2018 -Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
    -Added support for Unix style volume prefix. (FF_STR_VOLUME_ID = 2)
    -Fixed accesing objects in the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
    -Fixed f_setlabel does not reject some invalid characters. (appeared at R0.09b)
    +
      +
    • Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
    • +
    • Added support for Unix style volume prefix. (FF_STR_VOLUME_ID = 2)
    • +
    • Fixed accesing objects in the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
    • +
    • Fixed f_setlabel does not reject some invalid characters. (appeared at R0.09b)
    • +
    + R0.13a
    Oct 14, 2017 -Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
    -Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF)
    -Added dynamic memory allocation option for working buffer of f_mkfs and f_fdisk.
    -Fixed f_fdisk and f_mkfs create the partition table with wrong CHS parameters. (appeared at R0.09)
    -Fixed f_unlink can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
    -Fixed f_setlabel rejects some valid characters for exFAT volume. (appeared at R0.12)
    +
      +
    • Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
    • +
    • Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF)
    • +
    • Added dynamic memory allocation option for working buffer of f_mkfs and f_fdisk.
    • +
    • Fixed f_fdisk and f_mkfs create the partition table with wrong CHS parameters. (appeared at R0.09)
    • +
    • Fixed f_unlink can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
    • +
    • Fixed f_setlabel rejects some valid characters for exFAT volume. (appeared at R0.12)
    • +
    + R0.13
    May 21, 2017 -Prefix of configuration item names are changed from "_" to "FF_".
    -Added f_setcp, run-time code page configuration. (FF_CODE_PAGE = 0)
    -Improved cluster allocation time on stretch a deep buried cluster chain.
    -Improved processing time of f_mkdir with large cluster size by using FF_USE_LFN = 3.
    -Improved exFAT NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
    -Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
    -Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
    -Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
    +
      +
    • Prefix of configuration item names are changed from "_" to "FF_".
    • +
    • Added f_setcp, run-time code page configuration. (FF_CODE_PAGE = 0)
    • +
    • Improved cluster allocation time on stretch a deep buried cluster chain.
    • +
    • Improved processing time of f_mkdir with large cluster size by using FF_USE_LFN = 3.
    • +
    • Improved exFAT NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
    • +
    • Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
    • +
    • Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
    • +
    • Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
    • +
    -ASCII only configuration, FF_CODE_PAGE = 1, is removed. Use FF_CODE_PAGE = 437 instead.
    +
      +
    • ASCII only configuration, FF_CODE_PAGE = 1, is removed. Use FF_CODE_PAGE = 437 instead.
    • +
    R0.12c
    Mar 04, 2017 -Improved write throughput at the fragmented file on the exFAT volume.
    -Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
    -Fixed successive f_getfree can return wrong count on the FAT12/16 volume. (appeared at R0.12)
    -Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
    +
      +
    • Improved write throughput at the fragmented file on the exFAT volume.
    • +
    • Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
    • +
    • Fixed successive f_getfree can return wrong count on the FAT12/16 volume. (appeared at R0.12)
    • +
    • Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
    • +
    + R0.12b
    Sep 4, 2016 -Made f_rename be able to rename objects with the same name but case.
    -Fixed an error in the case conversion teble of code page 866. (ff.c)
    -Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
    -Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
    -Fixed f_mkfs creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12a)
    -Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
    -Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
    -Fixed some internal errors in f_expand and f_lseek. (appeared at R0.12)
    +
      +
    • Made f_rename be able to rename objects with the same name but case.
    • +
    • Fixed an error in the case conversion teble of code page 866. (ff.c)
    • +
    • Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12) +
    • Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
    • +
    • Fixed f_mkfs creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12a)
    • +
    • Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
    • +
    • Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
    • +
    • Fixed some internal errors in f_expand and f_lseek. (appeared at R0.12)
    • +
    + R0.12a
    Jul 10, 2016 -Added support for creating exFAT volume with some changes of f_mkfs.
    -Added a file open method FA_OPEN_APPEND.
    -f_forward is available regardless of _FS_TINY.
    -Fixed f_mkfs creates broken volume. (appeared at R0.12)
    -Fixed wrong memory read in create_name. (appeared at R0.12)
    -Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
    +
      +
    • Added support for creating exFAT volume with some changes of f_mkfs.
    • +
    • Added a file open method FA_OPEN_APPEND.
    • +
    • f_forward is available regardless of _FS_TINY.
    • +
    • Fixed f_mkfs creates broken volume. (appeared at R0.12)
    • +
    • Fixed wrong memory read in create_name. (appeared at R0.12)
    • +
    • Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
    • +
    -Usage of f_mkfs is changed.
    +
      +
    • Usage of f_mkfs is changed.
    • +
    R0.12
    Apr 12, 2016 -Added support for exFAT file system. (_FS_EXFAT)
    -Added f_expand. (_USE_EXPAND)
    -Changed some members in FINFO and behavior of f_readdir.
    -Added a configuration option _USE_CHMOD.
    -Fixed errors in the case conversion teble of Unicode (cc*.c).
    +
      +
    • Added support for exFAT file system. (_FS_EXFAT)
    • +
    • Added f_expand. (_USE_EXPAND)
    • +
    • Changed some members in FINFO and behavior of f_readdir.
    • +
    • Added a configuration option _USE_CHMOD.
    • +
    • Fixed errors in the case conversion teble of Unicode (cc*.c).
    • +
    -Usage and members of FINFO sructure used in f_readdir is changed.
    -Dot entries in the sub-directory are never appear in f_readdir.
    -".." does not work as path name in exFAT volume.
    -f_getcwd does not work in exFAT volume.
    -Many members in FIL and DIR structure are changed.
    -To use f_chmod, _USE_CHMOD needs to be set.
    -_WORD_ACCESS is removed from the configuration options.
    +
      +
    • Usage and members of FINFO sructure used in f_readdir is changed.
    • +
    • Dot entries in the sub-directory are never appear in f_readdir.
    • +
    • ".." does not work as path name in exFAT volume.
    • +
    • f_getcwd does not work in exFAT volume.
    • +
    • Many members in FIL and DIR structure are changed.
    • +
    • To use f_chmod, _USE_CHMOD needs to be set.
    • +
    • _WORD_ACCESS is removed from the configuration options.
    • +
    R0.11a
    Sep 5, 2015 -Fixed wrong media change can lead a deadlock at thread-safe configuration.
    -Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
    -Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
    -Fixed errors in the case conversion teble of Unicode (cc*.c).
    +
      +
    • Fixed wrong media change can lead a deadlock at thread-safe configuration.
    • +
    • Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
    • +
    • Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
    • +
    • Fixed errors in the case conversion teble of Unicode (cc*.c).
    • +
    -Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
    +
      +
    • Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
    • +
    R0.11
    Feb 9, 2015 -Added f_findfirst and f_findnext. (_USE_FIND)
    -Fixed f_unlink does not remove cluster chain of the file. (appeared at R0.10c)
    -Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
    +
      +
    • Added f_findfirst and f_findnext. (_USE_FIND)
    • +
    • Fixed f_unlink does not remove cluster chain of the file. (appeared at R0.10c)
    • +
    • Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
    • +
    + R0.10c
    Nov 9, 2014 -Added a configuration option for the platforms without RTC. (_FS_NORTC)
    -Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel. (appeared at R0.09b)
    -Fixed a potential problem of FAT access that can appear on disk error.
    -Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
    +
      +
    • Added a configuration option for the platforms without RTC. (_FS_NORTC)
    • +
    • Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel. (appeared at R0.09b)
    • +
    • Fixed a potential problem of FAT access that can appear on disk error.
    • +
    • Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
    • +
    + R0.10b
    May 19, 2014 -Fixed a hard error in the disk I/O layer can collapse the directory entry.
    -Fixed LFN entry is not deleted on delete/rename an object with its lossy converted SFN. (appeared at R0.07)
    +
      +
    • Fixed a hard error in the disk I/O layer can collapse the directory entry.
    • +
    • Fixed LFN entry is not deleted on delete/rename an object with its lossy converted SFN. (appeared at R0.07)
    • +
    + R0.10a
    Jan 15, 2014 -Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
    -Added an option for minimum sector size. (_MIN_SS)
    -2nd argument of f_rename can have a drive number and it will be ignored.
    -Fixed f_mount with forced mount fails when drive number is larger than 0. (appeared at R0.10)
    -Fixed f_close invalidates the file object without volume lock.
    -Fixed volume lock is left acquired after return from f_closedir. (appeared at R0.10)
    -Fixed creation of a directory entry with LFN fails on too many SFN collisions. (appeared at R0.07)
    +
      +
    • Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
    • +
    • Added an option for minimum sector size. (_MIN_SS)
    • +
    • 2nd argument of f_rename can have a drive number and it will be ignored.
    • +
    • Fixed f_mount with forced mount fails when drive number is larger than 0. (appeared at R0.10)
    • +
    • Fixed f_close invalidates the file object without volume lock.
    • +
    • Fixed volume lock is left acquired after return from f_closedir. (appeared at R0.10)
    • +
    • Fixed creation of a directory entry with LFN fails on too many SFN collisions. (appeared at R0.07)
    • +
    + R0.10
    Oct 2, 2013 -Added an option for character encoding on the file. (_STRF_ENCODE)
    -Added f_closedir.
    -Added forced full FAT scan option for f_getfree. (_FS_NOFSINFO)
    -Added forced mount option with changes of f_mount.
    -Improved behavior of volume auto detection.
    -Improved write throughput of f_puts and f_printf.
    -Changed argument of f_chdrive, f_mkfs, disk_read and disk_write.
    -Fixed f_write can be truncated when the file size is close to 4 GB.
    -Fixed f_open, f_mkdir and f_setlabel can return incorrect result code on error.
    +
      +
    • Added an option for character encoding on the file. (_STRF_ENCODE)
    • +
    • Added f_closedir.
    • +
    • Added forced full FAT scan option for f_getfree. (_FS_NOFSINFO)
    • +
    • Added forced mount option with changes of f_mount.
    • +
    • Improved behavior of volume auto detection.
    • +
    • Improved write throughput of f_puts and f_printf.
    • +
    • Changed argument of f_chdrive, f_mkfs, disk_read and disk_write.
    • +
    • Fixed f_write can be truncated when the file size is close to 4 GB.
    • +
    • Fixed f_open, f_mkdir and f_setlabel can return incorrect result code on error.
    • +
    + R0.09b
    Jan 24, 2013 -Added f_getlabel and f_setlabel. (_USE_LABEL)
    +
      +
    • Added f_getlabel and f_setlabel. (_USE_LABEL)
    • +
    + R0.09a
    Aug 27, 2012 -Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
    -Changed file functions reject null object pointer to avoid crash.
    -Changed option name _FS_SHARE to _FS_LOCK.
    +
      +
    • Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
    • +
    • Changed file functions reject null object pointer to avoid crash.
    • +
    • Changed option name _FS_SHARE to _FS_LOCK.
    • +
    + R0.09
    Sep 6, 2011 -f_mkfs supports multiple partition on a physical drive.
    -Added f_fdisk. (_MULTI_PARTITION = 2)
    +
      +
    • f_mkfs supports multiple partition on a physical drive.
    • +
    • Added f_fdisk. (_MULTI_PARTITION = 2)
    • +
    + R0.08b
    Jan 15, 2011 -Fast seek function is also applied to f_read and f_write.
    -f_lseek reports required table size on creating CLMP.
    -Extended format syntax of f_printf.
    -Ignores duplicated directory separators in given path names.
    +
      +
    • Fast seek function is also applied to f_read and f_write.
    • +
    • f_lseek reports required table size on creating CLMP.
    • +
    • Extended format syntax of f_printf.
    • +
    • Ignores duplicated directory separators in given path names.
    • +
    + R0.08a
    Aug 16, 2010 -Added f_getcwd. (_FS_RPATH = 2)
    -Added sector erase function. (_USE_ERASE)
    -Moved file lock semaphore table from fs object to the bss.
    -Fixed f_mkdir creates wrong directory on non-LFN cfg when the given name contains ';'.
    -Fixed f_mkfs creates wrong FAT32 volume.
    +
      +
    • Added f_getcwd. (_FS_RPATH = 2)
    • +
    • Added sector erase function. (_USE_ERASE)
    • +
    • Moved file lock semaphore table from fs object to the bss.
    • +
    • Fixed f_mkdir creates wrong directory on non-LFN cfg when the given name contains ';'.
    • +
    • Fixed f_mkfs creates wrong FAT32 volume.
    • +
    + R0.08
    May 15, 2010 -Added an option to _USE_LFN
    -Added support of file lock. (_FS_SHARE)
    -Added fast seek function. (_USE_FASTSEEK)
    -Changed a type name on the API, XCHAR to TCHAR.
    -Changed member, fname, in the FILINFO on Unicode cfg.
    -String functions support UTF-8 encoding files on Unicode cfg.
    +
      +
    • Added an option to _USE_LFN
    • +
    • Added support of file lock. (_FS_SHARE)
    • +
    • Added fast seek function. (_USE_FASTSEEK)
    • +
    • Changed a type name on the API, XCHAR to TCHAR.
    • +
    • Changed member, fname, in the FILINFO on Unicode cfg.
    • +
    • String functions support UTF-8 encoding files on Unicode cfg.
    • +
    + R0.07e
    Nov 3, 2009 -Separated out configuration options from ff.h to ffconf.h.
    -Added a configuration option, _LFN_UNICODE.
    -Fixed f_unlink fails to remove a sub-dir on _FS_RPATH.
    -Fixed name matching error on the 13 char boundary.
    -Changed f_readdir to return the SFN with always upper case on non-LFN cfg.
    +
      +
    • Separated out configuration options from ff.h to ffconf.h.
    • +
    • Added a configuration option, _LFN_UNICODE.
    • +
    • Fixed f_unlink fails to remove a sub-dir on _FS_RPATH.
    • +
    • Fixed name matching error on the 13 char boundary.
    • +
    • Changed f_readdir to return the SFN with always upper case on non-LFN cfg.
    • +
    + R0.07c
    Jan 21, 2009 -Fixed f_unlink may return FR_OK on error.
    -Fixed wrong cache control in f_lseek.
    -Added support of relative path.
    -Added f_chdir.
    -Added f_chdrive.
    -Added proper case conversion to extended characters.
    +
      +
    • Fixed f_unlink may return FR_OK on error.
    • +
    • Fixed wrong cache control in f_lseek.
    • +
    • Added support of relative path.
    • +
    • Added f_chdir.
    • +
    • Added f_chdrive.
    • +
    • Added proper case conversion to extended characters.
    • +
    + R0.07a
    Apr 14, 2009 -Separated out OS dependent code on re-entrant configuration.
    -Added multiple sector size support.
    +
      +
    • Separated out OS dependent code on re-entrant configuration.
    • +
    • Added multiple sector size support.
    • +
    + R0.07
    Apr 1, 2009 -Merged Tiny-FatFs into FatFs as a buffer configuration option.
    -Added support for long file extension.
    -Added multiple code page support.
    -Added re-entrancy for multitask operation.
    -Added auto cluster size selection to f_mkfs.
    -Added rewind option to f_readdir.
    -Changed result code of critical errors.
    -Renamed string functions to avoid name collision.
    +
      +
    • Merged Tiny-FatFs into FatFs as a buffer configuration option.
    • +
    • Added support for long file extension.
    • +
    • Added multiple code page support.
    • +
    • Added re-entrancy for multitask operation.
    • +
    • Added auto cluster size selection to f_mkfs.
    • +
    • Added rewind option to f_readdir.
    • +
    • Changed result code of critical errors.
    • +
    • Renamed string functions to avoid name collision.
    • +
    + R0.06
    Apr 1, 2008 -Added f_forward. (Tiny-FatFs)
    -Added string functions: f_gets, f_putc, f_puts and f_printf.
    -Improved performance of f_lseek on moving to the same or following cluster.
    +
      +
    • Added f_forward. (Tiny-FatFs)
    • +
    • Added string functions: f_gets, f_putc, f_puts and f_printf.
    • +
    • Improved performance of f_lseek on moving to the same or following cluster.
    • +
    + R0.05a
    Feb 3, 2008 -Added f_truncate.
    -Added f_utime.
    -Fixed off by one error at FAT sub-type determination.
    -Fixed btr in f_read can be mistruncated.
    -Fixed cached sector is left not flushed when create and close without write.
    +
      +
    • Added f_truncate.
    • +
    • Added f_utime.
    • +
    • Fixed off by one error at FAT sub-type determination.
    • +
    • Fixed btr in f_read can be mistruncated.
    • +
    • Fixed cached sector is left not flushed when create and close without write.
    • +
    + R0.05
    Aug 26, 2007 -Changed arguments of f_read, f_write.
    -Changed arguments of f_mkfs. (FatFs)
    -Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
    -Fixed f_mkdir on FAT32 creates broken directory. (FatFs)
    +
      +
    • Changed arguments of f_read, f_write.
    • +
    • Changed arguments of f_mkfs. (FatFs)
    • +
    • Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
    • +
    • Fixed f_mkdir on FAT32 creates broken directory. (FatFs)
    • +
    + R0.04b
    May 5, 2007 -Added _USE_NTFLAG option.
    -Added support for FSInfo in FAT32 volume.
    -Fixed some problems corresponds to FAT32. (Tiny-FatFs)
    -Fixed DBCS name can result FR_INVALID_NAME.
    -Fixed short seek (<= csize) collapses the file object.
    +
      +
    • Added _USE_NTFLAG option.
    • +
    • Added support for FSInfo in FAT32 volume.
    • +
    • Fixed some problems corresponds to FAT32. (Tiny-FatFs)
    • +
    • Fixed DBCS name can result FR_INVALID_NAME.
    • +
    • Fixed short seek (<= csize) collapses the file object.
    • +
    + R0.04a
    Apr 1, 2007 -Supported multiple partitions on a plysical drive. (FatFs)
    -Added minimization level 3.
    -Added a capability of extending file size to f_lseek.
    -Fixed an endian sensitive code in f_mkfs. (FatFs)
    -Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)
    +
      +
    • Supported multiple partitions on a plysical drive. (FatFs)
    • +
    • Added minimization level 3.
    • +
    • Added a capability of extending file size to f_lseek.
    • +
    • Fixed an endian sensitive code in f_mkfs. (FatFs)
    • +
    • Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)
    • +
    + R0.04
    Feb 4, 2007 -Supported multiple drive system. (FatFs)
    -Changed some APIs for multiple drive system.
    -Added f_mkfs. (FatFs)
    -Added _USE_FAT32 option. (Tiny-FatFs)
    +
      +
    • Supported multiple drive system. (FatFs)
    • +
    • Changed some APIs for multiple drive system.
    • +
    • Added f_mkfs. (FatFs)
    • +
    • Added _USE_FAT32 option. (Tiny-FatFs)
    • +
    + R0.03a
    Dec 11, 2006 -Improved cluster scan algolithm to write files fast.
    -Fixed f_mkdir creates broken directory on FAT32.
    +
      +
    • Improved cluster scan algolithm to write files fast.
    • +
    • Fixed f_mkdir creates broken directory on FAT32.
    • +
    + R0.03
    Sep 22, 2006 -Added f_rename. -Changed option _FS_MINIMUM to _FS_MINIMIZE.
    +
      +
    • Added f_rename. +
    • Changed option _FS_MINIMUM to _FS_MINIMIZE.
    • +
    + R0.02a
    Jun 10, 2006 -Added a configuration option _FS_MINIMUM.
    +
      +
    • Added a configuration option _FS_MINIMUM.
    • +
    + R0.02
    Jun 01, 2006 -Added FAT12.
    -Removed unbuffered mode.
    -Fixed a problem on small (<32M) patition.
    +
      +
    • Added FAT12.
    • +
    • Removed unbuffered mode.
    • +
    • Fixed a problem on small (<32M) patition.
    • +
    + R0.01
    Apr 29, 2006 -First release.
    +
      +
    • First release.
    • +
    + -

    Return

    +

    Return

    diff --git a/source/00history.txt b/source/00history.txt index 53487b3..11982e0 100644 --- a/source/00history.txt +++ b/source/00history.txt @@ -381,3 +381,9 @@ R0.15b (June 21, 2025) Added support for timestamp of created time. (FF_FS_CRTIME) Fixed FatFs fails to load the FsInfo in FAT32 volumes and the f_getfree always be forced a full FAT scan which takes a long time. (appeared at R0.15a) + + +R0.16 (July 22, 2025) + Removed a long-pending limitation that f_getcwd and double-dot .. in the path name did not work on the exFAT volume. + Fixed f_readdir cannot detect end of directory and it leads the application process into infinite loop. (appeared at R0.15b) + Fixed dot names with terminating separator or duplicated separator are rejected when LFN is not enabled. diff --git a/source/00readme.txt b/source/00readme.txt index 3de3aea..2dae010 100644 --- a/source/00readme.txt +++ b/source/00readme.txt @@ -1,4 +1,4 @@ -FatFs Module Source Files R0.15 +FatFs Module Source Files R0.16 FILES diff --git a/source/diskio.c b/source/diskio.c index 179e387..e8e1b56 100644 --- a/source/diskio.c +++ b/source/diskio.c @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------*/ -/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */ +/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2025 */ /*-----------------------------------------------------------------------*/ /* If a working storage control module is available, it should be */ /* attached to the FatFs via a glue function rather than modifying it. */ @@ -7,13 +7,17 @@ /* storage control modules to the FatFs module with a defined API. */ /*-----------------------------------------------------------------------*/ -#include "ff.h" /* Obtains integer types */ -#include "diskio.h" /* Declarations of disk functions */ +#include "ff.h" /* Basic definitions of FatFs */ +#include "diskio.h" /* Declarations FatFs MAI */ -/* Definitions of physical drive number for each drive */ -#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */ -#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */ -#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */ +/* Example: Declarations of the platform and disk functions in the project */ +#include "platform.h" +#include "storage.h" + +/* Example: Mapping of physical drive number for each drive */ +#define DEV_FLASH 0 /* Map FTL to physical drive 0 */ +#define DEV_MMC 1 /* Map MMC/SD card to physical drive 1 */ +#define DEV_USB 2 /* Map USB MSD to physical drive 2 */ /*-----------------------------------------------------------------------*/ diff --git a/source/diskio.h b/source/diskio.h index e4ead78..195f432 100644 --- a/source/diskio.h +++ b/source/diskio.h @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------/ -/ Low level disk interface modlue include file (C)ChaN, 2019 / +/ Low level disk interface modlue include file (C)ChaN, 2025 / /-----------------------------------------------------------------------*/ #ifndef _DISKIO_DEFINED @@ -55,7 +55,7 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); #define CTRL_EJECT 7 /* Eject media */ #define CTRL_FORMAT 8 /* Create physical format on the media */ -/* MMC/SDC specific ioctl command */ +/* MMC/SDC specific ioctl command (Not used by FatFs) */ #define MMC_GET_TYPE 10 /* Get card type */ #define MMC_GET_CSD 11 /* Get CSD */ #define MMC_GET_CID 12 /* Get CID */ @@ -65,7 +65,7 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ -/* ATA/CF specific ioctl command */ +/* ATA/CF specific ioctl command (Not used by FatFs) */ #define ATA_GET_REV 20 /* Get F/W revision */ #define ATA_GET_MODEL 21 /* Get model name */ #define ATA_GET_SN 22 /* Get serial number */ diff --git a/source/ff.c b/source/ff.c index aad124a..0598b57 100644 --- a/source/ff.c +++ b/source/ff.c @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem Module R0.15b / +/ FatFs - Generic FAT Filesystem Module R0.16 / /-----------------------------------------------------------------------------/ / / Copyright (C) 2025, ChaN, all right reserved. @@ -20,9 +20,8 @@ #include -#include "ff.h" /* Declarations of FatFs API */ -#include "diskio.h" /* Declarations of device I/O functions */ - +#include "ff.h" /* Basic definitions and declarations of API */ +#include "diskio.h" /* Declarations of MAI */ /*-------------------------------------------------------------------------- @@ -30,7 +29,7 @@ ---------------------------------------------------------------------------*/ -#if FF_DEFINED != 5385 /* Revision ID */ +#if FF_DEFINED != 80386 /* Revision ID */ #error Wrong include file (ff.h). #endif @@ -465,7 +464,7 @@ typedef struct { /* Open object identifier with status */ static FATFS *FatFs[FF_VOLUMES]; /* Pointer to the filesystem objects (logical drives) */ static WORD Fsid; /* Filesystem mount ID */ -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH static BYTE CurrVol; /* Current drive number set by f_chdrive() */ #endif @@ -500,9 +499,9 @@ static const BYTE GUID_MS_Basic[16] = {0xA2,0xA0,0xD0,0xEB,0xE5,0xB9,0x33,0x44,0 #if FF_FS_EXFAT #error LFN must be enabled when enable exFAT #endif -#define DEF_NAMBUF -#define INIT_NAMBUF(fs) -#define FREE_NAMBUF() +#define DEF_NAMEBUFF +#define INIT_NAMEBUFF(fs) +#define FREE_NAMEBUFF() #define LEAVE_MKFS(res) return res #else /* LFN configurations */ @@ -523,32 +522,32 @@ static const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* FAT: Offset static BYTE DirBuf[MAXDIRB(FF_MAX_LFN)]; /* Directory entry block scratchpad buffer */ #endif static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */ -#define DEF_NAMBUF -#define INIT_NAMBUF(fs) -#define FREE_NAMBUF() +#define DEF_NAMEBUFF +#define INIT_NAMEBUFF(fs) +#define FREE_NAMEBUFF() #define LEAVE_MKFS(res) return res #elif FF_USE_LFN == 2 /* LFN enabled with dynamic working buffer on the stack */ #if FF_FS_EXFAT -#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; BYTE dbuf[MAXDIRB(FF_MAX_LFN)]; /* LFN working buffer and directory entry block scratchpad buffer */ -#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; (fs)->dirbuf = dbuf; } -#define FREE_NAMBUF() +#define DEF_NAMEBUFF WCHAR lbuf[FF_MAX_LFN+1]; BYTE dbuf[MAXDIRB(FF_MAX_LFN)]; /* LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMEBUFF(fs) { (fs)->lfnbuf = lbuf; (fs)->dirbuf = dbuf; } +#define FREE_NAMEBUFF() #else -#define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN+1]; /* LFN working buffer */ -#define INIT_NAMBUF(fs) { (fs)->lfnbuf = lbuf; } -#define FREE_NAMBUF() +#define DEF_NAMEBUFF WCHAR lbuf[FF_MAX_LFN+1]; /* LFN working buffer */ +#define INIT_NAMEBUFF(fs) { (fs)->lfnbuf = lbuf; } +#define FREE_NAMEBUFF() #endif #define LEAVE_MKFS(res) return res #elif FF_USE_LFN == 3 /* LFN enabled with dynamic working buffer on the heap */ #if FF_FS_EXFAT -#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer and directory entry block scratchpad buffer */ -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); } -#define FREE_NAMBUF() ff_memfree(lfn) +#define DEF_NAMEBUFF WCHAR *lfn; /* Pointer to LFN working buffer and directory entry block scratchpad buffer */ +#define INIT_NAMEBUFF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); } +#define FREE_NAMEBUFF() ff_memfree(lfn) #else -#define DEF_NAMBUF WCHAR *lfn; /* Pointer to LFN working buffer */ -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } -#define FREE_NAMBUF() ff_memfree(lfn) +#define DEF_NAMEBUFF WCHAR *lfn; /* Pointer to LFN working buffer */ +#define INIT_NAMEBUFF(fs) { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } +#define FREE_NAMEBUFF() ff_memfree(lfn) #endif #define LEAVE_MKFS(res) { if (!work) ff_memfree(buf); return res; } #define MAX_MALLOC 0x8000 /* Must be >=FF_MAX_SS */ @@ -2020,14 +2019,14 @@ static void gen_numname ( { BYTE ns[8], c; UINT i, j; - WCHAR wc; - DWORD crc_sreg; memcpy(dst, src, 11); /* Prepare the SFN to be modified */ if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */ - crc_sreg = seq; + WCHAR wc; + DWORD crc_sreg = seq; + while (*lfn) { /* Create a CRC value as a hash of LFN */ wc = *lfn++; for (i = 0; i < 16; i++) { @@ -2198,19 +2197,27 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */ /*------------------------------------------------------------------*/ static void init_alloc_info ( - FATFS* fs, /* Filesystem object */ - FFOBJID* obj /* Object allocation information to be initialized */ + FFOBJID* dobj, /* Object allocation information to be initialized */ + DIR* sdir /* Additional source about containing direcotry */ ) { - obj->sclust = ld_32(fs->dirbuf + XDIR_FstClus); /* Start cluster */ - obj->objsize = ld_64(fs->dirbuf + XDIR_FileSize); /* Size */ - obj->stat = fs->dirbuf[XDIR_GenFlags] & 2; /* Allocation status */ - obj->n_frag = 0; /* No last fragment info */ + FATFS *fs = dobj->fs; + + + if (sdir) { /* Initialize the containing directory. This block needs to precede the followings. */ + dobj->c_scl = sdir->obj.sclust; + dobj->c_size = ((DWORD)sdir->obj.objsize & 0xFFFFFF00) | sdir->obj.stat; + dobj->c_ofs = sdir->blk_ofs; + } + dobj->sclust = ld_32(fs->dirbuf + XDIR_FstClus); /* Start cluster */ + dobj->objsize = ld_64(fs->dirbuf + XDIR_FileSize); /* Size */ + dobj->stat = fs->dirbuf[XDIR_GenFlags] & 2; /* Allocation status */ + dobj->n_frag = 0; /* No last fragment info */ } -#if !FF_FS_READONLY || FF_FS_RPATH != 0 +#if !FF_FS_READONLY || FF_FS_RPATH /*------------------------------------------------*/ /* exFAT: Load the object's directory entry block */ /*------------------------------------------------*/ @@ -2331,7 +2338,7 @@ static FRESULT dir_read ( { FRESULT res = FR_NO_FILE; FATFS *fs = dp->obj.fs; - BYTE attr, b; + BYTE attr, et; #if FF_USE_LFN BYTE ord = 0xFF, sum = 0xFF; #endif @@ -2339,16 +2346,16 @@ static FRESULT dir_read ( while (dp->sect) { res = move_window(fs, dp->sect); if (res != FR_OK) break; - b = dp->dir[DIR_Name]; /* Test for the entry type */ - if (b == 0) { + et = dp->dir[DIR_Name]; /* Test for the entry type */ + if (et == 0) { res = FR_NO_FILE; break; /* Reached to end of the directory */ } #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ if (FF_USE_LABEL && vol) { - if (b == ET_VLABEL) break; /* Volume label entry? */ + if (et == ET_VLABEL) break; /* Volume label entry? */ } else { - if (b == ET_FILEDIR) { /* Start of the file entry block? */ + if (et == ET_FILEDIR) { /* Start of the file entry block? */ dp->blk_ofs = dp->dptr; /* Get location of the block */ res = load_xdir(dp); /* Load the entry block */ if (res == FR_OK) { @@ -2362,17 +2369,17 @@ static FRESULT dir_read ( { /* On the FAT/FAT32 volume */ dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */ #if FF_USE_LFN /* LFN configuration */ - if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ + if (et == DDEM || et == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ ord = 0xFF; } else { if (attr == AM_LFN) { /* An LFN entry is found */ - if (b & LLEF) { /* Is it start of an LFN sequence? */ + if (et & LLEF) { /* Is it start of an LFN sequence? */ sum = dp->dir[LDIR_Chksum]; - b &= (BYTE)~LLEF; ord = b; + et &= (BYTE)~LLEF; ord = et; dp->blk_ofs = dp->dptr; } /* Check LFN validity and capture it */ - ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + ord = (et == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; } else { /* An SFN entry is found */ if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */ dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */ @@ -2381,7 +2388,7 @@ static FRESULT dir_read ( } } #else /* Non LFN configuration */ - if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */ + if (et != DDEM && et != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */ break; } #endif @@ -2408,9 +2415,9 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ { FRESULT res; FATFS *fs = dp->obj.fs; - BYTE c; + BYTE et; #if FF_USE_LFN - BYTE a, ord, sum; + BYTE attr, ord, sum; #endif res = dir_sdi(dp, 0); /* Rewind directory object */ @@ -2442,23 +2449,23 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ do { res = move_window(fs, dp->sect); if (res != FR_OK) break; - c = dp->dir[DIR_Name]; - if (c == 0) { res = FR_NO_FILE; break; } /* Reached end of directory table */ + et = dp->dir[DIR_Name]; /* Entry type */ + if (et == 0) { res = FR_NO_FILE; break; } /* Reached end of directory table */ #if FF_USE_LFN /* LFN configuration */ - dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK; - if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ + dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; + if (et == DDEM || ((attr & AM_VOL) && attr != AM_LFN)) { /* An entry without valid data */ ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */ } else { - if (a == AM_LFN) { /* Is it an LFN entry? */ + if (attr == AM_LFN) { /* Is it an LFN entry? */ if (!(dp->fn[NSFLAG] & NS_NOLFN)) { - if (c & LLEF) { /* Is it start of an entry set? */ - c &= (BYTE)~LLEF; - ord = c; /* Number of LFN entries */ + if (et & LLEF) { /* Is it start of an entry set? */ + et &= (BYTE)~LLEF; + ord = et; /* Number of LFN entries */ dp->blk_ofs = dp->dptr; /* Start offset of LFN */ sum = dp->dir[LDIR_Chksum]; /* Sum of the SFN */ } /* Check validity of the LFN entry and compare it with given name */ - ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; + ord = (et == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF; } } else { /* SFN entry */ if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */ @@ -2492,7 +2499,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too FATFS *fs = dp->obj.fs; #if FF_USE_LFN /* LFN configuration */ UINT n, len, n_ent; - BYTE sn[12], sum; + BYTE sn[12]; if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */ @@ -2519,9 +2526,15 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */ st_64(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); st_64(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize); - fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */ + fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */ res = store_xdir(&dj); /* Store the object status */ if (res != FR_OK) return res; +#if FF_FS_RPATH /* Refrect changes to the current dir chain if the stretched dir is in it */ + for (n = 1; n <= fs->xcwds.depth && dp->obj.sclust != fs->xcwds.tbl[n].d_scl; n++) ; /* Check if the dir is in the current dir path */ + if (n <= fs->xcwds.depth) { /* If exist, update it */ + fs->xcwds.tbl[n].d_size = (DWORD)dp->obj.objsize | dp->obj.stat; + } +#endif } } @@ -2549,7 +2562,8 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too if (res == FR_OK && --n_ent) { /* Set LFN entry if needed */ res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE); if (res == FR_OK) { - sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ + BYTE sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ + do { /* Store LFN entries in bottom first */ res = move_window(fs, dp->sect); if (res != FR_OK) break; @@ -2572,7 +2586,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too memset(dp->dir, 0, SZDIRE); /* Clean the entry */ memcpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */ #if FF_USE_LFN - dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */ + dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put low-case flags */ #endif fs->wflag = 1; } @@ -2643,7 +2657,6 @@ static void get_fileinfo ( { UINT si, di; #if FF_USE_LFN - BYTE lcf; WCHAR wc, hs; FATFS *fs = dp->obj.fs; UINT nw; @@ -2652,6 +2665,7 @@ static void get_fileinfo ( #endif + fno->fname[0] = 0; if (dp->sect == 0) return; /* Exit if read pointer has reached end of directory */ #if FF_USE_LFN /* LFN configuration */ @@ -2739,14 +2753,16 @@ static void get_fileinfo ( } fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */ - if (fno->fname[0] == 0) { /* If LFN is invalid, altname[] needs to be copied to fname[] */ - if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccessible */ - fno->fname[di++] = '\?'; + if (!fno->fname[0]) { /* If LFN is invalid, altname[] needs to be copied to fname[] */ + if (di == 0) { /* If LFN and SFN both are invalid, */ + fno->fname[di++] = '\?'; /* This object is inaccessible due to wrong buffer or locale settings */ } else { - for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ + BYTE lcflg = NS_BODY; + + for (si = di = 0; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */ wc = (WCHAR)fno->altname[si]; - if (wc == '.') lcf = NS_EXT; - if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20; + if (wc == '.') lcflg = NS_EXT; + if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcflg)) wc += 0x20; fno->fname[di] = (TCHAR)wc; } } @@ -2887,7 +2903,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr UINT i, ni, si, di; - /* Create LFN into LFN working buffer */ + /* Create an LFN into LFN working buffer */ p = *path; lfn = dp->obj.fs->lfnbuf; di = 0; for (;;) { uc = tchar2uni(&p); /* Get a character */ @@ -2908,7 +2924,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr } *path = p; /* Return pointer to the next segment */ -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH if ((di == 1 && lfn[di - 1] == '.') || (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */ lfn[di] = 0; @@ -3015,14 +3031,19 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr p = *path; sfn = dp->fn; memset(sfn, ' ', 11); si = i = 0; ni = 8; -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH if (p[si] == '.') { /* Is this a dot entry? */ - for (;;) { + for (;;) { /* Copy one or two dots */ c = (BYTE)p[si++]; if (c != '.' || si >= 3) break; sfn[i++] = c; } - if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME; + if (IsSeparator(c)) { + while (IsSeparator(p[si])) si++; /* Skip duplicated separators */ + if ((BYTE)p[si] <= ' ') c = 0; /* Terminate if no segment follows */ + } else if (c > ' ') { /* Not in dot name */ + return FR_INVALID_NAME; + } *path = p + si; /* Return pointer to the next segment */ sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */ return FR_OK; @@ -3032,7 +3053,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr c = (BYTE)p[si++]; /* Get a byte */ if (c <= ' ') break; /* Break if end of the path name */ if (IsSeparator(c)) { /* Break if a separator is found */ - while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */ + while (IsSeparator(p[si])) si++; /* Skip duplicated separators */ break; } if (c == '.' || i >= ni) { /* End of body or field overflow? */ @@ -3087,28 +3108,33 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ FATFS *fs = dp->obj.fs; -#if FF_FS_RPATH != 0 + /* Determins the start directory (current directory or forced root directory) */ +#if FF_FS_RPATH if (!IsSeparator(*path) && (FF_STR_VOLUME_ID != 2 || !IsTerminator(*path))) { /* Without heading separator */ dp->obj.sclust = fs->cdir; /* Start at the current directory */ } else #endif { /* With heading separator */ - while (IsSeparator(*path)) path++; /* Strip separators */ - dp->obj.sclust = 0; /* Start from the root directory */ + while (IsSeparator(*path)) path++; /* Strip heading separators */ + dp->obj.sclust = 0; /* Start at the root directory */ } + #if FF_FS_EXFAT dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */ -#if FF_FS_RPATH != 0 - if (fs->fs_type == FS_EXFAT && dp->obj.sclust) { /* exFAT: Retrieve the sub-directory's status */ - DIR dj; - - dp->obj.c_scl = fs->cdc_scl; - dp->obj.c_size = fs->cdc_size; - dp->obj.c_ofs = fs->cdc_ofs; - res = load_obj_xdir(&dj, &dp->obj); - if (res != FR_OK) return res; - dp->obj.objsize = ld_32(fs->dirbuf + XDIR_FileSize); - dp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2; +#if FF_FS_RPATH + if (fs->fs_type == FS_EXFAT) { /* exFAT: Retrieve the start-directory's status */ + if (dp->obj.sclust) { /* Start directory is a sub-directory */ + /* Load the current directory chain into working buffer and initialize directory object as current dir */ + memcpy(&fs->xcwds2, &fs->xcwds, sizeof fs->xcwds2); + dp->obj.stat = (BYTE)fs->xcwds2.tbl[fs->xcwds2.depth].d_size; + dp->obj.objsize = fs->xcwds2.tbl[fs->xcwds2.depth].d_size & 0xFFFFFF00; + dp->obj.c_scl = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_scl; + dp->obj.c_size = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_size & 0xFFFFFF00; + dp->obj.c_ofs = fs->xcwds2.tbl[fs->xcwds2.depth - 1].nxt_ofs; + } else { /* Start directory is the root directory */ + /* Clear the directory path working buffer as root directory */ + memset(&fs->xcwds2, 0, sizeof fs->xcwds2); + } } #endif #endif @@ -3121,11 +3147,31 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ for (;;) { res = create_name(dp, &path); /* Get a segment name of the path */ if (res != FR_OK) break; - res = dir_find(dp); /* Find an object with the segment name */ ns = dp->fn[NSFLAG]; +#if FF_FS_EXFAT && FF_FS_RPATH + if (fs->fs_type == FS_EXFAT && (ns & NS_DOT)) { /* Is it a dot name? */ + /* There is no dot entry in exFAT volume, so it needs to follow the parent directory with recorded path */ + if (fs->lfnbuf[1] == '.' && fs->xcwds2.depth) { /* ".." in the sub-dir? */ + fs->xcwds2.depth--; /* Get into the parent directory and load the directory info */ + dp->obj.sclust = fs->xcwds2.tbl[fs->xcwds2.depth].d_scl; + dp->obj.stat = (BYTE)fs->xcwds2.tbl[fs->xcwds2.depth].d_size; + dp->obj.objsize = fs->xcwds2.tbl[fs->xcwds2.depth].d_size & 0xFFFFFF00; + if (fs->xcwds2.depth) { /* Load containing dir info if needed */ + dp->obj.c_scl = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_scl; + dp->obj.c_size = fs->xcwds2.tbl[fs->xcwds2.depth - 1].d_size; + dp->obj.c_ofs = fs->xcwds2.tbl[fs->xcwds2.depth - 1].nxt_ofs; + } + } + dp->obj.attr |= AM_DIR; /* This is a directory */ + dp->fn[NSFLAG] |= NS_NONAME; /* but dot names in exFAT volume are not directory entry */ + if (ns & NS_LAST) break; /* Last segment? */ + continue; /* Follow next segment */ + } +#endif + res = dir_find(dp); /* Find an object with the segment name */ if (res != FR_OK) { /* Failed to find the object */ if (res == FR_NO_FILE) { /* Object is not found */ - if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there */ + if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there (may be root dir in FAT volume) */ if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */ dp->fn[NSFLAG] = NS_NONAME; res = FR_OK; @@ -3135,17 +3181,24 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ } break; } - if (ns & NS_LAST) break; /* Last segment matched. Function completed. */ +#if FF_FS_EXFAT && FF_FS_RPATH + if (fs->fs_type == FS_EXFAT && (dp->obj.attr & AM_DIR)) { /* Record the path if it is a sub-directory */ + fs->xcwds2.tbl[fs->xcwds2.depth].nxt_ofs = dp->blk_ofs; + if (++fs->xcwds2.depth >= sizeof fs->xcwds2.tbl / sizeof fs->xcwds2.tbl[0]) { /* Is it too deep path? */ + res = FR_NOT_ENOUGH_CORE; break; + } + fs->xcwds2.tbl[fs->xcwds2.depth].d_scl = ld_32(fs->dirbuf + XDIR_FstClus); + fs->xcwds2.tbl[fs->xcwds2.depth].d_size = ld_32(fs->dirbuf + XDIR_FileSize) | (fs->dirbuf[XDIR_GenFlags] & 2); + } +#endif + if (ns & NS_LAST) break; /* If last segment matched, the function completed */ /* Get into the sub-directory */ - if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */ - res = FR_NO_PATH; break; + if (!(dp->obj.attr & AM_DIR)) { + res = FR_NO_PATH; break; /* It is not a sub-directory and cannot follow the path */ } #if FF_FS_EXFAT - if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */ - dp->obj.c_scl = dp->obj.sclust; - dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; - dp->obj.c_ofs = dp->blk_ofs; - init_alloc_info(fs, &dp->obj); /* Open next directory */ + if (fs->fs_type == FS_EXFAT) { + init_alloc_info(&dp->obj, dp); /* Open next directory */ } else #endif { @@ -3223,7 +3276,7 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb } #endif /* No drive prefix */ -#if FF_FS_RPATH != 0 +#if FF_FS_RPATH return (int)CurrVol; /* Default drive is current drive */ #else return 0; /* Default drive is 0 */ @@ -3363,7 +3416,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD format */ if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is an FAT VBR as auto scan, not a BS or disk error */ - /* Sector 0 is not an FAT VBR or forced partition number wants a partition */ + /* Sector 0 is not an FAT VBR or forced partition number wants a partitioned drive */ #if FF_LBA64 if (fs->win[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */ @@ -3378,7 +3431,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ if (move_window(fs, pt_lba + i * SZ_GPTE / SS(fs)) != FR_OK) return 4; /* PT sector */ ofs = i * SZ_GPTE % SS(fs); /* Offset in the sector */ if (!memcmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */ - v_ent++; + v_ent++; /* Order of MS BDP */ fmt = check_fs(fs, ld_64(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */ if (part == 0 && fmt <= 1) return fmt; /* Auto search (valid FAT volume found first) */ if (part != 0 && v_ent == part) return fmt; /* Forced partition order (regardless of it is valid or not) */ @@ -3387,7 +3440,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */ return 3; /* Not found */ } #endif - if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has 4 partitions max */ + if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has four primary partitions max (FatFs does not support logical partition) */ for (i = 0; i < 4; i++) { /* Load partition offset in the MBR */ mbr_pt[i] = ld_32(fs->win + MBR_Table + i * SZ_PTE + PTE_StLba); } @@ -3415,8 +3468,6 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ FATFS *fs; DSTATUS stat; LBA_t bsect; - DWORD tsect, sysect, fasize, nclst, szbfat; - WORD nrsv; UINT fmt; @@ -3471,7 +3522,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ #if FF_FS_EXFAT if (fmt == 1) { QWORD maxlba; - DWORD so, cv, bcl, i; + DWORD so, cv, bcl, ncl, i; for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */ if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM; @@ -3493,15 +3544,15 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */ if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768 sectors) */ - nclst = ld_32(fs->win + BPB_NumClusEx); /* Number of clusters */ - if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */ - fs->n_fatent = nclst + 2; + ncl = ld_32(fs->win + BPB_NumClusEx); /* Number of clusters */ + if (ncl > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */ + fs->n_fatent = ncl + 2; /* Boundaries and Limits */ fs->volbase = bsect; fs->database = bsect + ld_32(fs->win + BPB_DataOfsEx); fs->fatbase = bsect + ld_32(fs->win + BPB_FatOfsEx); - if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */ + if (maxlba < (QWORD)fs->database + ncl * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size required) */ fs->dirbase = ld_32(fs->win + BPB_RootClusEx); /* Get bitmap location and check if it is contiguous (implementation assumption) */ @@ -3524,7 +3575,6 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ if (cv == 0xFFFFFFFF) break; /* Last link? */ if (cv != ++bcl) return FR_NO_FILESYSTEM; /* Fragmented bitmap? */ } - #if !FF_FS_READONLY fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Invalidate cluster allocation information */ fs->fsi_flag = 0; /* Enable to sync PercInUse value in VBR */ @@ -3533,6 +3583,9 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ } else #endif /* FF_FS_EXFAT */ { + DWORD tsect, sysect, fasize, nclst, szbfat; + WORD nrsv; + if (ld_16(fs->win + BPB_BytsPerSec) != SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */ fasize = ld_16(fs->win + BPB_FATSz16); /* Number of sectors per FAT */ @@ -3610,18 +3663,25 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */ fs->fs_type = (BYTE)fmt;/* FAT sub-type (the filesystem object gets valid) */ fs->id = ++Fsid; /* Volume mount ID */ -#if FF_USE_LFN == 1 - fs->lfnbuf = LfnBuf; /* Static LFN working buffer */ + +#if FF_USE_LFN == 1 /* Initilize pointers to the static working buffers */ + fs->lfnbuf = LfnBuf; /* LFN working buffer */ #if FF_FS_EXFAT - fs->dirbuf = DirBuf; /* Static directory block scratchpad buuffer */ + fs->dirbuf = DirBuf; /* Directory block scratchpad buuffer */ #endif #endif -#if FF_FS_RPATH != 0 - fs->cdir = 0; /* Initialize current directory */ + +#if FF_FS_RPATH /* Set the current directory top layer (root) */ + fs->cdir = 0; +#if FF_FS_EXFAT + memset(&fs->xcwds, 0, sizeof fs->xcwds); #endif +#endif + #if FF_FS_LOCK /* Clear file lock semaphores */ clear_share(fs); #endif + return FR_OK; } @@ -3673,7 +3733,7 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */ /*-----------------------------------------------------------------------*/ -/* Mount/Unmount a Logical Drive */ +/* API: Mount/Unmount a Logical Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_mount ( @@ -3691,11 +3751,11 @@ FRESULT f_mount ( /* Get volume ID (logical drive number) */ vol = get_ldnumber(&rp); if (vol < 0) return FR_INVALID_DRIVE; - cfs = FatFs[vol]; /* Pointer to the filesystem object of the volume */ - if (cfs) { /* Unregister current filesystem object if registered */ + cfs = FatFs[vol]; /* Pointer to the filesystem object of the volume */ + if (cfs) { /* Unregister current filesystem object */ FatFs[vol] = 0; -#if FF_FS_LOCK +#if FF_FS_LOCK /* Clear file lock semaphores correspond to this volume */ clear_share(cfs); #endif #if FF_FS_REENTRANT /* Discard mutex of the current volume */ @@ -3720,12 +3780,12 @@ FRESULT f_mount ( #endif #endif fs->fs_type = 0; /* Invalidate the new filesystem object */ - FatFs[vol] = fs; /* Register new fs object */ + FatFs[vol] = fs; /* Register it */ } if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted in subsequent file functions */ - res = mount_volume(&path, &fs, 0); /* Force mounted the volume */ + res = mount_volume(&path, &fs, 0); /* Force mounted the volume in this function */ LEAVE_FF(fs, res); } @@ -3733,7 +3793,7 @@ FRESULT f_mount ( /*-----------------------------------------------------------------------*/ -/* Open or Create a File */ +/* API: Open or Create a File */ /*-----------------------------------------------------------------------*/ FRESULT f_open ( @@ -3745,12 +3805,7 @@ FRESULT f_open ( FRESULT res; DIR dj; FATFS *fs; -#if !FF_FS_READONLY - DWORD cl, bcs, clst; - LBA_t sc; - FSIZE_t ofs; -#endif - DEF_NAMBUF + DEF_NAMEBUFF if (!fp) return FR_INVALID_OBJECT; /* Reject null pointer */ @@ -3760,8 +3815,9 @@ FRESULT f_open ( res = mount_volume(&path, &fs, mode); if (res == FR_OK) { + fp->obj.fs = fs; dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ #if !FF_FS_READONLY /* Read/Write configuration */ if (res == FR_OK) { @@ -3794,16 +3850,17 @@ FRESULT f_open ( } } if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate the file if overwrite mode */ + DWORD tm = GET_FATTIME(); #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* Get current allocation info */ - fp->obj.fs = fs; - init_alloc_info(fs, &fp->obj); + init_alloc_info(&fp->obj, 0); /* Set exFAT directory entry block initial state */ memset(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */ memset(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */ fs->dirbuf[XDIR_Attr] = AM_ARC; - st_32(fs->dirbuf + XDIR_CrtTime, GET_FATTIME()); /* Set created time */ + st_32(fs->dirbuf + XDIR_CrtTime, tm); /* Set created time */ + st_32(fs->dirbuf + XDIR_ModTime, tm); /* Set modified time (tmp setting) */ fs->dirbuf[XDIR_GenFlags] = 1; res = store_xdir(&dj); if (res == FR_OK && fp->obj.sclust != 0) { /* Remove the cluster chain if exist */ @@ -3813,15 +3870,18 @@ FRESULT f_open ( } else #endif { + DWORD cl; /* Set FAT directory entry initial state */ - st_32(dj.dir + DIR_CrtTime, GET_FATTIME()); /* Set created time */ + st_32(dj.dir + DIR_CrtTime, tm); /* Set created time */ + st_32(dj.dir + DIR_ModTime, tm); /* Set modified time (tmp setting) */ cl = ld_clust(fs, dj.dir); /* Get current cluster chain */ dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */ st_clust(fs, dj.dir, 0); /* Reset file allocation info */ st_32(dj.dir + DIR_FileSize, 0); fs->wflag = 1; if (cl != 0) { /* Remove the cluster chain if exist */ - sc = fs->winsect; + LBA_t sc = fs->winsect; + res = remove_chain(&dj.obj, cl, 0); if (res == FR_OK) { res = move_window(fs, sc); @@ -3851,7 +3911,8 @@ FRESULT f_open ( if (fp->obj.lockid == 0) res = FR_INT_ERR; #endif } -#else /* R/O configuration */ + +#else /* R/O configuration */ if (res == FR_OK) { if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it origin directory itself? */ res = FR_INVALID_NAME; @@ -3866,10 +3927,7 @@ FRESULT f_open ( if (res == FR_OK) { #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fp->obj.c_scl = dj.obj.sclust; /* Get containing directory info */ - fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; - fp->obj.c_ofs = dj.blk_ofs; - init_alloc_info(fs, &fp->obj); + init_alloc_info(&fp->obj, &dj); } else #endif { @@ -3879,8 +3937,7 @@ FRESULT f_open ( #if FF_USE_FASTSEEK fp->cltbl = 0; /* Disable fast seek mode */ #endif - fp->obj.fs = fs; /* Validate the file object */ - fp->obj.id = fs->id; + fp->obj.id = fs->id; /* Set current volume mount ID */ fp->flag = mode; /* Set file access mode */ fp->err = 0; /* Clear error flag */ fp->sect = 0; /* Invalidate current data sector */ @@ -3890,6 +3947,9 @@ FRESULT f_open ( memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */ #endif if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */ + DWORD bcs, clst; + FSIZE_t ofs; + fp->fptr = fp->obj.objsize; /* Offset to seek */ bcs = (DWORD)fs->csize * SS(fs); /* Cluster size in byte */ clst = fp->obj.sclust; /* Follow the cluster chain */ @@ -3900,11 +3960,12 @@ FRESULT f_open ( } fp->clust = clst; if (res == FR_OK && ofs % SS(fs)) { /* Fill sector buffer if not on the sector boundary */ - sc = clst2sect(fs, clst); - if (sc == 0) { + LBA_t sec = clst2sect(fs, clst); + + if (sec == 0) { res = FR_INT_ERR; } else { - fp->sect = sc + (DWORD)(ofs / SS(fs)); + fp->sect = sec + (DWORD)(ofs / SS(fs)); #if !FF_FS_TINY if (disk_read(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) res = FR_DISK_ERR; #endif @@ -3917,7 +3978,7 @@ FRESULT f_open ( #endif } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */ @@ -3929,7 +3990,7 @@ FRESULT f_open ( /*-----------------------------------------------------------------------*/ -/* Read File */ +/* API: Read File */ /*-----------------------------------------------------------------------*/ FRESULT f_read ( @@ -3941,7 +4002,6 @@ FRESULT f_read ( { FRESULT res; FATFS *fs; - DWORD clst; LBA_t sect; FSIZE_t remain; UINT rcnt, cc, csect; @@ -3959,6 +4019,8 @@ FRESULT f_read ( if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */ csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */ if (csect == 0) { /* On the cluster boundary? */ + DWORD clst; + if (fp->fptr == 0) { /* On the top of the file? */ clst = fp->obj.sclust; /* Follow cluster chain from the origin */ } else { /* Middle or end of the file */ @@ -4029,7 +4091,7 @@ FRESULT f_read ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Write File */ +/* API: Write File */ /*-----------------------------------------------------------------------*/ FRESULT f_write ( @@ -4150,7 +4212,7 @@ FRESULT f_write ( /*-----------------------------------------------------------------------*/ -/* Synchronize the File */ +/* API: Synchronize the File */ /*-----------------------------------------------------------------------*/ FRESULT f_sync ( @@ -4159,7 +4221,6 @@ FRESULT f_sync ( { FRESULT res; FATFS *fs; - BYTE *dir; res = validate(&fp->obj, &fs); /* Check validity of the file object */ @@ -4180,9 +4241,9 @@ FRESULT f_sync ( } if (res == FR_OK) { DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = load_obj_xdir(&dj, &fp->obj); /* Load directory entry block */ if (res == FR_OK) { fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ @@ -4201,14 +4262,15 @@ FRESULT f_sync ( fp->flag &= (BYTE)~FA_MODIFIED; } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } } else #endif { res = move_window(fs, fp->dir_sect); if (res == FR_OK) { - dir = fp->dir_ptr; + BYTE *dir = fp->dir_ptr; + dir[DIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */ st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */ st_32(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */ @@ -4231,7 +4293,7 @@ FRESULT f_sync ( /*-----------------------------------------------------------------------*/ -/* Close File */ +/* API: Close File */ /*-----------------------------------------------------------------------*/ FRESULT f_close ( @@ -4267,7 +4329,7 @@ FRESULT f_close ( #if FF_FS_RPATH >= 1 /*-----------------------------------------------------------------------*/ -/* Change Current Directory or Current Drive, Get Current Directory */ +/* API: Change Current Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_chdrive ( @@ -4287,56 +4349,56 @@ FRESULT f_chdrive ( + +/*-----------------------------------------------------------------------*/ +/* API: Change Current Directory */ +/*-----------------------------------------------------------------------*/ + FRESULT f_chdir ( const TCHAR* path /* Pointer to the directory path */ ) { -#if FF_STR_VOLUME_ID == 2 - UINT i; -#endif FRESULT res; DIR dj; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF res = mount_volume(&path, &fs, 0); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the path */ if (res == FR_OK) { /* Follow completed */ if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it the start directory itself? */ - fs->cdir = dj.obj.sclust; #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fs->cdc_scl = dj.obj.c_scl; - fs->cdc_size = dj.obj.c_size; - fs->cdc_ofs = dj.obj.c_ofs; + memcpy(&fs->xcwds, &fs->xcwds2, sizeof fs->xcwds); } #endif + fs->cdir = dj.obj.sclust; } else { if (dj.obj.attr & AM_DIR) { /* It is a sub-directory */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - fs->cdir = ld_32(fs->dirbuf + XDIR_FstClus); /* Sub-directory cluster */ - fs->cdc_scl = dj.obj.sclust; /* Save containing directory information */ - fs->cdc_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat; - fs->cdc_ofs = dj.blk_ofs; + memcpy(&fs->xcwds, &fs->xcwds2, sizeof fs->xcwds); + fs->cdir = fs->xcwds.tbl[fs->xcwds.depth].d_scl; /* Sub-directory cluster */ } else #endif { - fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */ + fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */ } } else { res = FR_NO_PATH; /* Reached but a file */ } } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); if (res == FR_NO_FILE) res = FR_NO_PATH; #if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */ if (res == FR_OK) { + UINT i; + for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */ CurrVol = (BYTE)i; } @@ -4347,96 +4409,136 @@ FRESULT f_chdir ( } + + #if FF_FS_RPATH >= 2 +/*-----------------------------------------------------------------------*/ +/* API: Get Curent Directory */ +/*-----------------------------------------------------------------------*/ + FRESULT f_getcwd ( - TCHAR* buff, /* Pointer to the directory path */ + TCHAR* buff, /* Pointer to the buffer to store the current direcotry path */ UINT len /* Size of buff in unit of TCHAR */ ) { FRESULT res; DIR dj; FATFS *fs; - UINT i, n; - DWORD ccl; - TCHAR *tp = buff; #if FF_VOLUMES >= 2 UINT vl; #if FF_STR_VOLUME_ID - const char *vp; + const char *vid; #endif #endif FILINFO fno; - DEF_NAMBUF + DEF_NAMEBUFF - /* Get logical drive */ - buff[0] = 0; /* Set null string to get current volume */ - res = mount_volume((const TCHAR**)&buff, &fs, 0); /* Get current volume */ + buff[0] = 0; /* A null str to get current drive */ + res = mount_volume((const TCHAR**)&buff, &fs, 0); if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); +#if FF_FS_EXFAT + if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */ + UINT wi = 0; + UINT di, ni; - /* Follow parent directories and create the path */ - i = len; /* Bottom of buffer (directory stack base) */ - if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* (Cannot do getcwd on exFAT and returns root path) */ +#if FF_VOLUMES >= 2 /* Add drive prefix if needed */ +#if FF_STR_VOLUME_ID == 0 /* Numeric volume ID */ + if (wi < len) buff[wi++] = '0' + CurrVol; +#else /* String volume ID */ + if (FF_STR_VOLUME_ID == 2 && wi < len) buff[wi++] = '/'; + for (vid = (const char*)VolumeStr[CurrVol]; *vid && wi < len; buff[wi++] = *vid++) ; +#endif + if (FF_STR_VOLUME_ID <= 1 && wi < len) buff[wi++] = ':'; +#endif + if (wi < len) buff[wi++] = '/'; + for (di = 0; wi < len && di < fs->xcwds.depth; di++) { /* Follow current directory path with cwd structure */ + dj.obj.sclust = fs->xcwds.tbl[di].d_scl; /* Open this directory */ + dj.obj.stat = (BYTE)fs->xcwds.tbl[di].d_size; + dj.obj.objsize = fs->xcwds.tbl[di].d_size & 0xFFFFFF00; + res = dir_sdi(&dj, fs->xcwds.tbl[di].nxt_ofs); /* Find next directory */ + if (res != FR_OK) break; + res = DIR_READ_FILE(&dj); /* Get the directory name */ + if (res != FR_OK) break; + get_fileinfo(&dj, &fno); + if (di > 0 && wi < len) buff[wi++] = '/'; /* Add the directory name with a directory separator */ + for (ni = 0; fno.fname[ni] && wi < len; buff[wi++] = fno.fname[ni++]) ; + } + if (wi == len) { /* Buffer overflow? */ + res = FR_NOT_ENOUGH_CORE; + } else { + buff[wi] = 0; /* Terminate the string */ + } + } + else +#endif + { /* On the FAT/FAT32 volume */ + TCHAR *tp = buff; + UINT i, nl; + DWORD ccl; + + /* Follow parent directories toward the root directory and create the cwd path */ + i = len; /* Bottom of buffer (directory stack base) */ dj.obj.sclust = fs->cdir; /* Start to follow upper directory from current directory */ while ((ccl = dj.obj.sclust) != 0) { /* Repeat while current directory is a sub-directory */ - res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */ + res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */ if (res != FR_OK) break; res = move_window(fs, dj.sect); if (res != FR_OK) break; - dj.obj.sclust = ld_clust(fs, dj.dir); /* Goto parent directory */ + dj.obj.sclust = ld_clust(fs, dj.dir); /* Go to parent directory */ res = dir_sdi(&dj, 0); if (res != FR_OK) break; - do { /* Find the entry links to the child directory */ + do { /* Find the entry links to this sub-directory */ res = DIR_READ_FILE(&dj); if (res != FR_OK) break; if (ccl == ld_clust(fs, dj.dir)) break; /* Found the entry */ res = dir_next(&dj, 0); } while (res == FR_OK); - if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ + if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be 'not found'. */ if (res != FR_OK) break; - get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ - for (n = 0; fno.fname[n]; n++) ; /* Name length */ - if (i < n + 1) { /* Insufficient space to store the path name? */ + get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ + for (nl = 0; fno.fname[nl]; nl++) ; /* Name length */ + if (i < nl + 1) { /* Insufficient space to store the path name? */ res = FR_NOT_ENOUGH_CORE; break; } - while (n) buff[--i] = fno.fname[--n]; /* Stack the name */ + while (nl) buff[--i] = fno.fname[--nl]; /* Stack the name */ buff[--i] = '/'; } - } - if (res == FR_OK) { - if (i == len) buff[--i] = '/'; /* Is it the root-directory? */ -#if FF_VOLUMES >= 2 /* Put drive prefix */ - vl = 0; -#if FF_STR_VOLUME_ID >= 1 /* String volume ID */ - for (n = 0, vp = (const char*)VolumeStr[CurrVol]; vp[n]; n++) ; - if (i >= n + 2) { - if (FF_STR_VOLUME_ID == 2) *tp++ = (TCHAR)'/'; - for (vl = 0; vl < n; *tp++ = (TCHAR)vp[vl], vl++) ; - if (FF_STR_VOLUME_ID == 1) *tp++ = (TCHAR)':'; - vl++; - } -#else /* Numeric volume ID */ - if (i >= 3) { - *tp++ = (TCHAR)'0' + CurrVol; - *tp++ = (TCHAR)':'; - vl = 2; - } -#endif - if (vl == 0) res = FR_NOT_ENOUGH_CORE; -#endif - /* Add current directory path */ if (res == FR_OK) { - do { /* Copy stacked path string */ - *tp++ = buff[i++]; - } while (i < len); + if (i == len) buff[--i] = '/'; /* Is it the root-directory? */ +#if FF_VOLUMES >= 2 /* Put drive prefix */ + vl = 0; +#if FF_STR_VOLUME_ID >= 1 /* String volume ID */ + for (nl = 0, vid = (const char*)VolumeStr[CurrVol]; vid[nl]; nl++) ; /* Volume ID length */ + if (i >= nl + 2) { + if (FF_STR_VOLUME_ID == 2) *tp++ = '/'; /* Unix style */ + for (vl = 0; vl < nl; *tp++ = vid[vl], vl++) ; + if (FF_STR_VOLUME_ID == 1) *tp++ = ':'; /* DOS/Windows style */ + vl++; + } +#else /* Numeric volume ID */ + if (i >= 3) { + *tp++ = '0' + CurrVol; + *tp++ = ':'; + vl = 2; + } +#endif + if (vl == 0) res = FR_NOT_ENOUGH_CORE; +#endif + /* Add current directory path */ + if (res == FR_OK) { + do { /* Copy stacked path string */ + *tp++ = buff[i++]; + } while (i < len); + } } + *tp = 0; } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } - *tp = 0; LEAVE_FF(fs, res); } @@ -4447,7 +4549,7 @@ FRESULT f_getcwd ( #if FF_FS_MINIMIZE <= 2 /*-----------------------------------------------------------------------*/ -/* Seek File Read/Write Pointer */ +/* API: Seek File Read/Write Pointer */ /*-----------------------------------------------------------------------*/ FRESULT f_lseek ( @@ -4460,11 +4562,7 @@ FRESULT f_lseek ( DWORD clst, bcs; LBA_t nsect; FSIZE_t ifptr; -#if FF_USE_FASTSEEK - DWORD cl, pcl, ncl, tcl, tlen, ulen; - DWORD *tbl; - LBA_t dsc; -#endif + res = validate(&fp->obj, &fs); /* Check validity of the file object */ if (res == FR_OK) res = (FRESULT)fp->err; @@ -4477,6 +4575,10 @@ FRESULT f_lseek ( #if FF_USE_FASTSEEK if (fp->cltbl) { /* Fast seek */ + DWORD cl, pcl, ncl, tcl, tlen, ulen; + DWORD *tbl; + LBA_t dsc; + if (ofs == CREATE_LINKMAP) { /* Create CLMT */ tbl = fp->cltbl; tlen = *tbl++; ulen = 2; /* Given table size and required table size */ @@ -4611,7 +4713,7 @@ FRESULT f_lseek ( #if FF_FS_MINIMIZE <= 1 /*-----------------------------------------------------------------------*/ -/* Create a Directory Object */ +/* API: Create a Directory Object */ /*-----------------------------------------------------------------------*/ FRESULT f_opendir ( @@ -4621,7 +4723,7 @@ FRESULT f_opendir ( { FRESULT res; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF if (!dp) return FR_INVALID_OBJECT; /* Reject null pointer */ @@ -4629,17 +4731,14 @@ FRESULT f_opendir ( res = mount_volume(&path, &fs, 0); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dp->obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(dp, path); /* Follow the path to the directory */ if (res == FR_OK) { /* Follow completed */ - if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is not the origin directory itself */ + if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is neither the origin directory itself nor dot name in exFAT */ if (dp->obj.attr & AM_DIR) { /* This object is a sub-directory */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { - dp->obj.c_scl = dp->obj.sclust; /* Get containing directory information */ - dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat; - dp->obj.c_ofs = dp->blk_ofs; - init_alloc_info(fs, &dp->obj); /* Get object allocation info */ + init_alloc_info(&dp->obj, dp); /* Get object allocation info */ } else #endif { @@ -4650,21 +4749,21 @@ FRESULT f_opendir ( } } if (res == FR_OK) { - dp->obj.id = fs->id; - res = dir_sdi(dp, 0); /* Rewind directory */ + dp->obj.id = fs->id; /* Set current volume mount ID */ + res = dir_sdi(dp, 0); /* Rewind directory */ #if FF_FS_LOCK if (res == FR_OK) { - if (dp->obj.sclust != 0) { - dp->obj.lockid = inc_share(dp, 0); /* Lock the sub directory */ + if (dp->obj.sclust) { /* Is this a sub-directory? */ + dp->obj.lockid = inc_share(dp, 0); /* Lock the sub-directory */ if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES; } else { - dp->obj.lockid = 0; /* Root directory need not to be locked */ + dp->obj.lockid = 0; /* Root directory does not need to be locked */ } } #endif } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); if (res == FR_NO_FILE) res = FR_NO_PATH; } if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function failed */ @@ -4676,7 +4775,7 @@ FRESULT f_opendir ( /*-----------------------------------------------------------------------*/ -/* Close Directory */ +/* API: Close Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_closedir ( @@ -4706,7 +4805,7 @@ FRESULT f_closedir ( /*-----------------------------------------------------------------------*/ -/* Read Directory Entries in Sequence */ +/* API: Read Directory Entries in Sequence */ /*-----------------------------------------------------------------------*/ FRESULT f_readdir ( @@ -4716,7 +4815,7 @@ FRESULT f_readdir ( { FRESULT res; FATFS *fs; - DEF_NAMBUF + DEF_NAMEBUFF res = validate(&dp->obj, &fs); /* Check validity of the directory object */ @@ -4724,7 +4823,8 @@ FRESULT f_readdir ( if (!fno) { res = dir_sdi(dp, 0); /* Rewind the directory object */ } else { - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); + fno->fname[0] = 0; /* Clear file information */ res = DIR_READ_FILE(dp); /* Read an item */ if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory */ if (res == FR_OK) { /* A valid entry is found */ @@ -4732,11 +4832,11 @@ FRESULT f_readdir ( res = dir_next(dp, 0); /* Increment index for next */ if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory now */ } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } } - if (fno && res != FR_OK) fno->fname[0] = 0; /* Invalidate the file information if any error occured */ + if (fno && res != FR_OK) fno->fname[0] = 0; /* Clear the file information if any error occured */ LEAVE_FF(fs, res); } @@ -4744,7 +4844,7 @@ FRESULT f_readdir ( #if FF_USE_FIND /*-----------------------------------------------------------------------*/ -/* Find Next File */ +/* API: Find Next File */ /*-----------------------------------------------------------------------*/ FRESULT f_findnext ( @@ -4769,7 +4869,7 @@ FRESULT f_findnext ( /*-----------------------------------------------------------------------*/ -/* Find First File */ +/* API: Find First File */ /*-----------------------------------------------------------------------*/ FRESULT f_findfirst ( @@ -4796,7 +4896,7 @@ FRESULT f_findfirst ( #if FF_FS_MINIMIZE == 0 /*-----------------------------------------------------------------------*/ -/* Get File Status */ +/* API: Get File Status */ /*-----------------------------------------------------------------------*/ FRESULT f_stat ( @@ -4806,14 +4906,14 @@ FRESULT f_stat ( { FRESULT res; DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF /* Get logical drive and mount the volume if needed */ res = mount_volume(&path, &dj.obj.fs, 0); if (res == FR_OK) { - INIT_NAMBUF(dj.obj.fs); + INIT_NAMEBUFF(dj.obj.fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK) { /* Follow completed */ if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */ @@ -4822,10 +4922,10 @@ FRESULT f_stat ( if (fno) get_fileinfo(&dj, fno); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } - if (fno && res != FR_OK) fno->fname[0] = 0; /* Invalidate the file information if any error occured */ + if (fno && res != FR_OK) fno->fname[0] = 0; /* Invalidate the file information if an error occured */ LEAVE_FF(dj.obj.fs, res); } @@ -4833,7 +4933,7 @@ FRESULT f_stat ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Get Number of Free Clusters */ +/* API: Get Number of Free Clusters */ /*-----------------------------------------------------------------------*/ FRESULT f_getfree ( @@ -4930,7 +5030,7 @@ FRESULT f_getfree ( /*-----------------------------------------------------------------------*/ -/* Truncate File */ +/* API: Truncate File */ /*-----------------------------------------------------------------------*/ FRESULT f_truncate ( @@ -4981,7 +5081,7 @@ FRESULT f_truncate ( /*-----------------------------------------------------------------------*/ -/* Delete a File/Directory */ +/* API: Delete a File/Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_unlink ( @@ -4995,78 +5095,72 @@ FRESULT f_unlink ( #if FF_FS_EXFAT FFOBJID obj; #endif - DEF_NAMBUF - + DEF_NAMEBUFF /* Get logical drive and mount the volume if needed */ res = mount_volume(&path, &fs, FA_WRITE); - if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); - res = follow_path(&dj, path); /* Follow the file path */ - if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) { - res = FR_INVALID_NAME; /* Cannot remove dot entry */ - } + INIT_NAMEBUFF(fs); + res = follow_path(&dj, path); /* Follow the path to the object */ + if (res == FR_OK) { + if (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME)) { + res = FR_INVALID_NAME; /* It must be a real object */ + } else if (dj.obj.attr & AM_RDO) { + res = FR_DENIED; /* The object must not be read-only */ #if FF_FS_LOCK - if (res == FR_OK) res = chk_share(&dj, 2); /* Check if it is an open object */ -#endif - if (res == FR_OK) { /* The object is accessible */ - if (dj.fn[NSFLAG] & NS_NONAME) { - res = FR_INVALID_NAME; /* Cannot remove the origin directory */ } else { - if (dj.obj.attr & AM_RDO) { - res = FR_DENIED; /* Cannot remove R/O object */ - } + res = chk_share(&dj, 2); /* Check if the object is in use */ +#endif } - if (res == FR_OK) { + } + if (res == FR_OK) { /* The object is accessible */ #if FF_FS_EXFAT - obj.fs = fs; - if (fs->fs_type == FS_EXFAT) { - init_alloc_info(fs, &obj); - dclst = obj.sclust; + obj.fs = fs; + if (fs->fs_type == FS_EXFAT) { + init_alloc_info(&obj, 0); + dclst = obj.sclust; + } else +#endif + { + dclst = ld_clust(fs, dj.dir); + } + if (dj.obj.attr & AM_DIR) { /* Is the object a sub-directory? */ +#if FF_FS_RPATH + if (dclst == fs->cdir) { + res = FR_DENIED; /* Current directory cannot be removed */ } else #endif { - dclst = ld_clust(fs, dj.dir); - } - if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */ -#if FF_FS_RPATH != 0 - if (dclst == fs->cdir) { /* Is it the current directory? */ - res = FR_DENIED; - } else -#endif - { - sdj.obj.fs = fs; /* Open the sub-directory */ - sdj.obj.sclust = dclst; + sdj.obj.fs = fs; /* Open the sub-directory */ + sdj.obj.sclust = dclst; #if FF_FS_EXFAT - if (fs->fs_type == FS_EXFAT) { - sdj.obj.objsize = obj.objsize; - sdj.obj.stat = obj.stat; - } + if (fs->fs_type == FS_EXFAT) { + sdj.obj.objsize = obj.objsize; + sdj.obj.stat = obj.stat; + } #endif - res = dir_sdi(&sdj, 0); - if (res == FR_OK) { - res = DIR_READ_FILE(&sdj); /* Test if the directory is empty */ - if (res == FR_OK) res = FR_DENIED; /* Not empty? */ - if (res == FR_NO_FILE) res = FR_OK; /* Empty? */ - } + res = dir_sdi(&sdj, 0); + if (res == FR_OK) { + res = DIR_READ_FILE(&sdj); /* Check if the sub-directory is empty */ + if (res == FR_OK) res = FR_DENIED; /* Not empty? */ + if (res == FR_NO_FILE) res = FR_OK; /* Empty? */ } } } - if (res == FR_OK) { - res = dir_remove(&dj); /* Remove the directory entry */ - if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ -#if FF_FS_EXFAT - res = remove_chain(&obj, dclst, 0); -#else - res = remove_chain(&dj.obj, dclst, 0); -#endif - } - if (res == FR_OK) res = sync_fs(fs); - } } - FREE_NAMBUF(); + if (res == FR_OK) { /* It is ready to remove the object */ + res = dir_remove(&dj); /* Remove the directory entry */ + if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */ +#if FF_FS_EXFAT + res = remove_chain(&obj, dclst, 0); +#else + res = remove_chain(&dj.obj, dclst, 0); +#endif + } + if (res == FR_OK) res = sync_fs(fs); + } + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5076,7 +5170,7 @@ FRESULT f_unlink ( /*-----------------------------------------------------------------------*/ -/* Create a Directory */ +/* API: Create a Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_mkdir ( @@ -5088,22 +5182,19 @@ FRESULT f_mkdir ( DIR dj; FFOBJID sobj; DWORD dcl, pcl, tm; - DEF_NAMBUF + DEF_NAMEBUFF - /* Get logical drive and mount the volume if needed */ - res = mount_volume(&path, &fs, FA_WRITE); - + res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive and mount the volume if needed */ if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ - if (res == FR_OK) res = FR_EXIST; /* Name collision? */ - if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) { /* Invalid name? */ - res = FR_INVALID_NAME; + if (res == FR_OK) { /* Invalid name or name collision */ + res = (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME)) ? FR_INVALID_NAME : FR_EXIST; } if (res == FR_NO_FILE) { /* It is clear to create a new directory */ - sobj.fs = fs; /* New object id to create a new chain */ + sobj.fs = fs; /* New object ID to create a new chain */ dcl = create_chain(&sobj, 0); /* Allocate a cluster for the new directory */ res = FR_OK; if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster? */ @@ -5111,7 +5202,7 @@ FRESULT f_mkdir ( if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; /* Disk error? */ tm = GET_FATTIME(); if (res == FR_OK) { - res = dir_clear(fs, dcl); /* Clean up the new table */ + res = dir_clear(fs, dcl); /* Clear the allocated cluster as new direcotry table */ if (res == FR_OK) { if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */ memset(fs->win + DIR_Name, ' ', 11); /* Create "." entry */ @@ -5154,7 +5245,7 @@ FRESULT f_mkdir ( remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */ } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5164,7 +5255,7 @@ FRESULT f_mkdir ( /*-----------------------------------------------------------------------*/ -/* Rename a File/Directory */ +/* API: Rename a File/Directory */ /*-----------------------------------------------------------------------*/ FRESULT f_rename ( @@ -5176,44 +5267,54 @@ FRESULT f_rename ( FATFS *fs; DIR djo, djn; BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir; - LBA_t sect; - DEF_NAMBUF + DEF_NAMEBUFF - /* Snip the drive number of new name off */ - get_ldnumber(&path_new); - - /* Get logical drive of the old object */ - res = mount_volume(&path_old, &fs, FA_WRITE); + get_ldnumber(&path_new); /* Snip the drive number of new name off */ + res = mount_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */ if (res == FR_OK) { djo.obj.fs = fs; - INIT_NAMBUF(fs); - res = follow_path(&djo, path_old); /* Check old object */ - if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */ -#if FF_FS_LOCK + INIT_NAMEBUFF(fs); + res = follow_path(&djo, path_old); /* Check old object */ if (res == FR_OK) { - res = chk_share(&djo, 2); - } + if (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME)) { + res = FR_INVALID_NAME; /* Object must not be a dot name or blank name */ +#if FF_FS_LOCK + } else { + res = chk_share(&djo, 2); /* Check if the object is in use */ #endif - if (res == FR_OK) { /* Object to be renamed is found */ + } + } + if (res == FR_OK) { /* It is ready to rename the object */ #if FF_FS_EXFAT if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */ - BYTE nf, nn; - WORD nh; +#if FF_FS_RPATH + UINT i; + DWORD dscl = ld_32(fs->dirbuf + XDIR_FstClus); - memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */ - memcpy(&djn, &djo, sizeof djo); - res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ - if (res == FR_OK) { /* Is new name already in use by any other object? */ + for (i = 1; i <= fs->xcwds.depth && dscl != fs->xcwds.tbl[i].d_scl; i++) ; /* Check if the object is a sub-dir in the current dir path */ + if (i <= fs->xcwds.depth) { + res = FR_DENIED; /* Reject to rename a sub-dir in the current dir path */ + } else +#endif + { + memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */ + memcpy(&djn, &djo, sizeof djn); + res = follow_path(&djn, path_new); /* Check if new object name collides with an existing one */ + } + if (res == FR_OK) { /* Is new name already in use by another object? */ res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; } - if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ - res = dir_register(&djn); /* Register the new entry */ + if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ + res = dir_register(&djn); /* Register the new entry */ if (res == FR_OK) { - nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName]; + BYTE nf, nn; + WORD nh; + + nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName]; /* Save name length and hash */ nh = ld_16(fs->dirbuf + XDIR_NameHash); memcpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */ - fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn; + fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn; /* Restore name length and hash */ st_16(fs->dirbuf + XDIR_NameHash, nh); if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ /* Start of critical section where an interruption can cause a cross-link */ @@ -5224,9 +5325,9 @@ FRESULT f_rename ( #endif { /* At FAT/FAT32 volume */ memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */ - memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */ + memcpy(&djn, &djo, sizeof djn); /* Duplicate the directory object */ res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */ - if (res == FR_OK) { /* Is new name already in use by any other object? */ + if (res == FR_OK) { /* Is new name already in use by another object? */ res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST; } if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ @@ -5237,8 +5338,9 @@ FRESULT f_rename ( dir[DIR_Attr] = buf[DIR_Attr]; if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */ fs->wflag = 1; - if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory if needed */ - sect = clst2sect(fs, ld_clust(fs, dir)); + if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory being moved if needed */ + LBA_t sect = clst2sect(fs, ld_clust(fs, dir)); + if (sect == 0) { res = FR_INT_ERR; } else { @@ -5254,15 +5356,15 @@ FRESULT f_rename ( } } } - if (res == FR_OK) { - res = dir_remove(&djo); /* Remove old entry */ + if (res == FR_OK) { /* New entry has been created */ + res = dir_remove(&djo); /* Remove old entry */ if (res == FR_OK) { res = sync_fs(fs); } } /* End of the critical section */ } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5277,7 +5379,7 @@ FRESULT f_rename ( #if FF_USE_CHMOD && !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Change Attribute */ +/* API: Change Attribute */ /*-----------------------------------------------------------------------*/ FRESULT f_chmod ( @@ -5289,7 +5391,7 @@ FRESULT f_chmod ( FRESULT res; FATFS *fs; DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF /* Get logical drive and mount the volume if needed */ @@ -5297,7 +5399,7 @@ FRESULT f_chmod ( if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ if (res == FR_OK) { @@ -5316,7 +5418,7 @@ FRESULT f_chmod ( res = sync_fs(fs); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5326,7 +5428,7 @@ FRESULT f_chmod ( /*-----------------------------------------------------------------------*/ -/* Change Timestamp */ +/* API: Change Timestamp */ /*-----------------------------------------------------------------------*/ FRESULT f_utime ( @@ -5337,7 +5439,7 @@ FRESULT f_utime ( FRESULT res; FATFS *fs; DIR dj; - DEF_NAMBUF + DEF_NAMEBUFF /* Get logical drive and mount the volume if needed */ @@ -5345,7 +5447,7 @@ FRESULT f_utime ( if (res == FR_OK) { dj.obj.fs = fs; - INIT_NAMBUF(fs); + INIT_NAMEBUFF(fs); res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check object validity */ if (res == FR_OK) { @@ -5382,7 +5484,7 @@ FRESULT f_utime ( res = sync_fs(fs); } } - FREE_NAMBUF(); + FREE_NAMEBUFF(); } LEAVE_FF(fs, res); @@ -5394,7 +5496,7 @@ FRESULT f_utime ( #if FF_USE_LABEL /*-----------------------------------------------------------------------*/ -/* Get Volume Label */ +/* API: Get Volume Label */ /*-----------------------------------------------------------------------*/ FRESULT f_getlabel ( @@ -5495,7 +5597,7 @@ FRESULT f_getlabel ( #if !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Set Volume Label */ +/* API: Set Volume Label */ /*-----------------------------------------------------------------------*/ FRESULT f_setlabel ( @@ -5618,7 +5720,7 @@ FRESULT f_setlabel ( #if FF_USE_EXPAND && !FF_FS_READONLY /*-----------------------------------------------------------------------*/ -/* Allocate a Contiguous Blocks to the File */ +/* API: Allocate a Contiguous Blocks to the File */ /*-----------------------------------------------------------------------*/ FRESULT f_expand ( @@ -5714,7 +5816,7 @@ FRESULT f_expand ( #if FF_USE_FORWARD /*-----------------------------------------------------------------------*/ -/* Forward Data to the Stream Directly */ +/* API: Forward Data to the Stream Directly */ /*-----------------------------------------------------------------------*/ FRESULT f_forward ( @@ -5785,7 +5887,7 @@ FRESULT f_forward ( #if !FF_FS_READONLY && FF_USE_MKFS /*-----------------------------------------------------------------------*/ -/* Create FAT/exFAT volume (with sub-functions) */ +/* API: Create FAT/exFAT volume (with a sub-function) */ /*-----------------------------------------------------------------------*/ #define N_SEC_TRACK 63 /* Sectors per track for determination of drive CHS */ @@ -6440,7 +6542,7 @@ FRESULT f_mkfs ( #if FF_MULTI_PARTITION /*-----------------------------------------------------------------------*/ -/* Create Partition Table on the Physical Drive */ +/* API: Create Partition Table on the Physical Drive */ /*-----------------------------------------------------------------------*/ FRESULT f_fdisk ( @@ -6480,7 +6582,7 @@ FRESULT f_fdisk ( #error Wrong FF_STRF_ENCODE setting #endif /*-----------------------------------------------------------------------*/ -/* Get a String from the File */ +/* API: Get a String from the File */ /*-----------------------------------------------------------------------*/ TCHAR* f_gets ( @@ -6615,7 +6717,7 @@ TCHAR* f_gets ( #define SZ_NUM_BUF 32 /*-----------------------------------------------------------------------*/ -/* Put a Character to the File (with sub-functions) */ +/* API: Put a Character to the File (with sub-functions) */ /*-----------------------------------------------------------------------*/ /* Output buffer and work area */ @@ -6806,7 +6908,7 @@ int f_putc ( /*-----------------------------------------------------------------------*/ -/* Put a String to the File */ +/* API: Put a String to the File */ /*-----------------------------------------------------------------------*/ int f_puts ( @@ -6826,7 +6928,7 @@ int f_puts ( /*-----------------------------------------------------------------------*/ -/* Put a Formatted String to the File (with sub-functions) */ +/* API: Put a Formatted String to the File (with sub-functions) */ /*-----------------------------------------------------------------------*/ #if FF_PRINT_FLOAT && FF_INTDEF == 2 #include @@ -7118,7 +7220,7 @@ int f_printf ( #if FF_CODE_PAGE == 0 /*-----------------------------------------------------------------------*/ -/* Set Active Codepage for the Path Name */ +/* API: Set Active Codepage for the Path Name */ /*-----------------------------------------------------------------------*/ FRESULT f_setcp ( diff --git a/source/ff.h b/source/ff.h index dc52c57..b1bd58d 100644 --- a/source/ff.h +++ b/source/ff.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------/ -/ FatFs - Generic FAT Filesystem module R0.15b / +/ FatFs - Generic FAT Filesystem module R0.16 / /-----------------------------------------------------------------------------/ / / Copyright (C) 2025, ChaN, all right reserved. @@ -20,7 +20,7 @@ #ifndef FF_DEFINED -#define FF_DEFINED 5385 /* Revision ID */ +#define FF_DEFINED 80386 /* Revision ID */ #ifdef __cplusplus extern "C" { @@ -127,47 +127,65 @@ extern const char* VolumeStr[FF_VOLUMES]; /* User defined volume ID table */ #endif +/* Current working directory structure (FFXCWDS) */ + +#if FF_FS_EXFAT && FF_FS_RPATH +#if FF_PATH_DEPTH < 1 +#error FF_PATH_DEPTH must not be zero +#endif +typedef struct { + DWORD d_scl; /* Directory start cluster (0:root dir) */ + DWORD d_size; /* Size of directory (b7-b0: cluster chain status) (invalid if d_scl == 0) */ + DWORD nxt_ofs; /* Offset of entry of next dir in this directory (invalid if last link) */ +} FFXCWDL; +typedef struct { + UINT depth; /* Current directory depth (0:root dir) */ + FFXCWDL tbl[FF_PATH_DEPTH + 1]; /* Directory chain of current working directory path */ +} FFXCWDS; +#endif + /* Filesystem object structure (FATFS) */ typedef struct { - BYTE fs_type; /* Filesystem type (0:not mounted) */ - BYTE pdrv; /* Volume hosting physical drive */ - BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */ - BYTE n_fats; /* Number of FATs (1 or 2) */ - BYTE wflag; /* win[] status (b0:dirty) */ - BYTE fsi_flag; /* Allocation information control (b7:disabled, b0:dirty) */ - WORD id; /* Volume mount ID */ - WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ - WORD csize; /* Cluster size [sectors] */ + BYTE fs_type; /* Filesystem type (0:not mounted) */ + BYTE pdrv; /* Physical drive that holds this volume */ + BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */ + BYTE n_fats; /* Number of FATs (1 or 2) */ + BYTE wflag; /* win[] status (b0:dirty) */ + BYTE fsi_flag; /* Allocation information control (b7:disabled, b0:dirty) */ + WORD id; /* Volume mount ID */ + WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ + WORD csize; /* Cluster size [sectors] */ #if FF_MAX_SS != FF_MIN_SS - WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ + WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ #endif #if FF_USE_LFN - WCHAR *lfnbuf; /* LFN working buffer */ + WCHAR* lfnbuf; /* Pointer to LFN working buffer */ #endif #if !FF_FS_READONLY - DWORD last_clst; /* Last allocated cluster (Unknown if >=n_fatent) */ - DWORD free_clst; /* Number of free clusters (Unknown if >=fs->n_fatent-2) */ + DWORD last_clst; /* Last allocated cluster (invalid if >=n_fatent) */ + DWORD free_clst; /* Number of free clusters (invalid if >=fs->n_fatent-2) */ #endif #if FF_FS_RPATH - DWORD cdir; /* Current directory start cluster (0:root) */ + DWORD cdir; /* Current directory start cluster (0:root) */ #endif - DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ - DWORD fsize; /* Number of sectors per FAT */ - LBA_t winsect; /* Current sector appearing in the win[] */ - LBA_t volbase; /* Volume base sector */ - LBA_t fatbase; /* FAT base sector */ - LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ - LBA_t database; /* Data base sector */ + DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ + DWORD fsize; /* Number of sectors per FAT */ + LBA_t winsect; /* Current sector appearing in the win[] */ + LBA_t volbase; /* Volume base sector */ + LBA_t fatbase; /* FAT base sector */ + LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ + LBA_t database; /* Data base sector */ #if FF_FS_EXFAT - LBA_t bitbase; /* Allocation bitmap base sector */ - BYTE *dirbuf; /* Directory entry block scratchpad buffer for exFAT */ - DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */ - DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */ - DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */ + LBA_t bitbase; /* Allocation bitmap base sector */ + BYTE* dirbuf; /* Pointer to directory entry block buffer */ +#if FF_FS_RPATH + FFXCWDS xcwds; /* Crrent working directory structure */ + FFXCWDS xcwds2; /* Working buffer to follow the path */ #endif - BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ +#endif + BYTE win[FF_MAX_SS]; /* Disk access window for directory, FAT (and file data in tiny cfg) */ } FATFS; @@ -175,21 +193,21 @@ typedef struct { /* Object ID and allocation information (FFOBJID) */ typedef struct { - FATFS* fs; /* Pointer to the hosting volume of this object */ - WORD id; /* Hosting volume's mount ID */ - BYTE attr; /* Object attribute */ - BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ - DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ - FSIZE_t objsize; /* Object size (valid when sclust != 0) */ + FATFS* fs; /* Pointer to the volume holding this object */ + WORD id; /* Volume mount ID when this object was opened */ + BYTE attr; /* Object attribute */ + BYTE stat; /* Object chain status (exFAT: b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ + DWORD sclust; /* Object data cluster (0:no data or root directory) */ + FSIZE_t objsize; /* Object size (valid when sclust != 0) */ #if FF_FS_EXFAT - DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ - DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ - DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */ - DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */ - DWORD c_ofs; /* Offset in the containing directory (valid when in file object and sclust != 0) */ + DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ + DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ + DWORD c_scl; /* Cluster of directory holding this object (valid when sclust != 0) */ + DWORD c_size; /* Size of directory holding this object (b7-b0: allocation status, valid when c_scl != 0) */ + DWORD c_ofs; /* Offset of entry in the holding directory */ #endif #if FF_FS_LOCK - UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ + UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ #endif } FFOBJID; @@ -198,18 +216,18 @@ typedef struct { /* File object structure (FIL) */ typedef struct { - FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ - BYTE flag; /* File status flags */ - BYTE err; /* Abort flag (error code) */ - FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */ - DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */ - LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */ + FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ + BYTE flag; /* File status flags */ + BYTE err; /* Abort flag (error code) */ + FSIZE_t fptr; /* File read/write pointer (0 on open) */ + DWORD clust; /* Current cluster of fptr (invalid when fptr is 0) */ + LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */ #if !FF_FS_READONLY - LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */ - BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ + LBA_t dir_sect; /* Sector number containing the directory entry (not used in exFAT) */ + BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used in exFAT) */ #endif #if FF_USE_FASTSEEK - DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ + DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open; set by application) */ #endif #if !FF_FS_TINY BYTE buf[FF_MAX_SS]; /* File private data read/write window */ @@ -221,44 +239,44 @@ typedef struct { /* Directory object structure (DIR) */ typedef struct { - FFOBJID obj; /* Object identifier */ - DWORD dptr; /* Current read/write offset */ - DWORD clust; /* Current cluster */ - LBA_t sect; /* Current sector (0:Read operation has terminated) */ - BYTE* dir; /* Pointer to the directory item in the win[] */ - BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */ + FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ + DWORD dptr; /* Current read/write offset */ + DWORD clust; /* Current cluster */ + LBA_t sect; /* Current sector (0:no more item to read) */ + BYTE* dir; /* Pointer to the directory item in the win[] in filesystem object */ + BYTE fn[12]; /* SFN (in/out) {body[0-7],ext[8-10],status[11]} */ #if FF_USE_LFN - DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */ + DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:invalid) */ #endif #if FF_USE_FIND - const TCHAR* pat; /* Pointer to the name matching pattern */ + const TCHAR *pat; /* Pointer to the name matching pattern */ #endif } DIR; -/* File information structure (FILINFO) */ +/* File/directory information structure (FILINFO) */ typedef struct { - FSIZE_t fsize; /* File size */ - WORD fdate; /* Modified date */ - WORD ftime; /* Modified time */ + FSIZE_t fsize; /* File size (invalid for directory) */ + WORD fdate; /* Date of file modification or directory creation */ + WORD ftime; /* Time of file modification or directory creation */ #if FF_FS_CRTIME - WORD crdate; /* Created date */ - WORD crtime; /* Created time */ + WORD crdate; /* Date of object createion */ + WORD crtime; /* Time of object createion */ #endif - BYTE fattrib; /* File attribute */ + BYTE fattrib; /* Object attribute */ #if FF_USE_LFN - TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */ - TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ + TCHAR altname[FF_SFN_BUF + 1];/* Alternative object name */ + TCHAR fname[FF_LFN_BUF + 1]; /* Primary object name */ #else - TCHAR fname[12 + 1]; /* File name */ + TCHAR fname[12 + 1]; /* Object name */ #endif } FILINFO; -/* Format parameter structure (MKFS_PARM) */ +/* Format parameter structure (MKFS_PARM) used for f_mkfs() */ typedef struct { BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */ @@ -290,7 +308,7 @@ typedef enum { FR_MKFS_ABORTED, /* (14) The f_mkfs function aborted due to some problem */ FR_TIMEOUT, /* (15) Could not take control of the volume within defined period */ FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ - FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated or given buffer is insufficient in size */ + FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated, given buffer size is insufficient or too deep path */ FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ } FRESULT; diff --git a/source/ffconf.h b/source/ffconf.h index ea54af2..cb7842c 100644 --- a/source/ffconf.h +++ b/source/ffconf.h @@ -2,7 +2,7 @@ / Configurations of FatFs Module /---------------------------------------------------------------------------*/ -#define FFCONF_DEF 5385 /* Revision ID */ +#define FFCONF_DEF 80386 /* Revision ID */ /*---------------------------------------------------------------------------/ / Function Configurations @@ -57,9 +57,9 @@ #define FF_USE_STRFUNC 0 -#define FF_PRINT_LLI 1 -#define FF_PRINT_FLOAT 1 -#define FF_STRF_ENCODE 3 +#define FF_PRINT_LLI 0 +#define FF_PRINT_FLOAT 0 +#define FF_STRF_ENCODE 0 /* FF_USE_STRFUNC switches string API functions, f_gets(), f_putc(), f_puts() and / f_printf(). / @@ -154,14 +154,26 @@ #define FF_FS_RPATH 0 -/* This option configures support for relative path. +/* This option configures support for relative path feature. / / 0: Disable relative path and remove related API functions. -/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 1: Enable relative path and dot names. f_chdir() and f_chdrive() are available. / 2: f_getcwd() is available in addition to 1. */ +#define FF_PATH_DEPTH 10 +/* This option defines maximum depth of directory in the exFAT volume. It is NOT +/ relevant to FAT/FAT32 volume. +/ For example, FF_PATH_DEPTH = 3 will able to follow a path "/dir1/dir2/dir3/file" +/ but a sub-directory in the dir3 will not able to be followed and set current +/ directory. +/ The size of filesystem object (FATFS) increases FF_PATH_DEPTH * 24 bytes. +/ When FF_FS_EXFAT == 0 or FF_FS_RPATH == 0, this option has no effect. +*/ + + + /*---------------------------------------------------------------------------/ / Drive/Volume Configurations /---------------------------------------------------------------------------*/ @@ -226,7 +238,7 @@ #define FF_FS_TINY 0 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) -/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ At the tiny configuration, size of file object (FIL) is reduced FF_MAX_SS bytes. / Instead of private sector buffer eliminated from the file object, common sector / buffer in the filesystem object (FATFS) is used for the file data transfer. */ @@ -238,7 +250,7 @@ #define FF_FS_NORTC 0 -#define FF_NORTC_MON 6 +#define FF_NORTC_MON 1 #define FF_NORTC_MDAY 1 #define FF_NORTC_YEAR 2025 /* The option FF_FS_NORTC switches timestamp feature. If the system does not have