High-level formatting: Difference between revisions

From SEGGER Knowledge Base
Jump to navigation Jump to search
(Created page with "== General information == The high-level formatting is a file system operation that can be used to initialize the structure of the file system on a storage device. Typically, this operation has to be performed only once on a lifetime of a storage device before writing any data to the storage device. The high-level format operation can also be performed on a storage device that is already formatted and that contains files and directories. However, all the files and direc...")
 
No edit summary
Line 1: Line 1:
High-level formatting
== General information ==
== General information ==


Line 7: Line 9:
== Theory of operation ==
== Theory of operation ==


An application can perform a high-level format operation by calling the [https://doc.segger.com/UM02001_emFile.html#FS_Format FS_Format()] API function. This API function can be used to perform a high-level format for any of the file system types supported by emFile. The type of file system used by the high-level format operation is determined the file system support enabled in emFile at compile time via [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_FAT FS_SUPPORT_FAT], [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_EFS FS_SUPPORT_EFS] or [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_EXFAT FS_SUPPORT_EXFAT] configuration defines. If emFile is configured to support more than one file system type then the type of file system used by high-level format operation has to be specified by calling the [https://doc.segger.com/UM02001_emFile.html#FS_SetFSType FS_SetFSType()] API function.
An application can perform a high-level format operation via the [https://doc.segger.com/UM02001_emFile.html#FS_Format FS_Format()] API function. This API function can be used to perform a high-level format for any of the file system types supported by emFile. The type of file system used by the high-level format operation is determined the file system support enabled in emFile at compile time via [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_FAT FS_SUPPORT_FAT], [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_EFS FS_SUPPORT_EFS] or [https://doc.segger.com/UM02001_emFile.html#FS_SUPPORT_EXFAT FS_SUPPORT_EXFAT] configuration defines. If emFile is configured to support more than one file system types, then the type of file system used by high-level format operation has to be specified by calling the [https://doc.segger.com/UM02001_emFile.html#FS_SetFSType FS_SetFSType()] API function.


In addition, emFile comes with specialized API functions for formatting a storage device as FAT and exFAT. These API functions format a storage device according to the specification [https://www.sdcard.org/ SD Association]. The [https://doc.segger.com/UM02001_emFile.html#FS_FAT_FormatSD FS_FAT_FormatSD] API function can be used to format a storage device as FA12, FAT16 or FAT32 while the [https://doc.segger.com/UM02001_emFile.html#FS_EXFAT_FormatSD FS_EXFAT_FormatSD] can be used to format a storage device as exFAT.
In addition, emFile comes with specialized API functions for formatting a storage device as FAT and exFAT. These API functions format a storage device according to the specification [https://www.sdcard.org/ SD Association]. The [https://doc.segger.com/UM02001_emFile.html#FS_FAT_FormatSD FS_FAT_FormatSD] API function can be used to format a storage device as FA12, FAT16 or FAT32 while the [https://doc.segger.com/UM02001_emFile.html#FS_EXFAT_FormatSD FS_EXFAT_FormatSD] can be used to format a storage device as exFAT.
Line 17: Line 19:


The format API functions may initialize other regions of the file system depending on the file system type.
The format API functions may initialize other regions of the file system depending on the file system type.
The boot sector stores basic information about the structure of the file system such as the file system type, the size of an allocation unit called cluster, the total number of clusters and so on. The allocation table stores information about what clusters are allocated and what clusters are belonging to the same file or directory. The root directory is the main entry point for the access to the files and directories stored on the file system. The high-level format information marks all the clusters in the allocation table as not being in use and creates an empty root directory.
== Cluster size ==
A cluster is the minimum storage space that the file system is able to allocate at once for a file or directory and it consists of one or more consecutive logical sectors. The size of a cluster has an influence on the file system performance and on the storage space utilization. Larger clusters provide a better performance because of the reduced number of accesses to the allocation table the file system has to perform for the same amount of accessed data. On the other hand smaller clusters make better use of the storage space if the application works with files of a relatively small size. The high-level formatting API functions of the file system are implemented to use a default cluster size that provides a balance between these.
By default, the size of the cluster is calculated based on the logical sector size and on the total number of logical sectors available on a storage device. As an option, the [https://doc.segger.com/UM02001_emFile.html#FS_Format FS_Format()] API function is able to format a storage device using a specified cluster size.
== Performance ==
The time it takes the high-level format operation to complete depends mainly on the capacity of the storage device and secondly on the cluster size. The following table lists the performance measurement results when formatting a 4 GB SD card and an 128 MB NAND flash device as FAT. The test was performed on a SEGGER [https://www.segger.com/products/production/flasher/models/flasher-pro-xl/ Flasher PRO XL] hardware.
{| class="seggertable"
|+ SD card 4 GB
|-
! Function !! FS type !! Num. clusters !! Cluster size [bytes] !! Time [ms]
|-
| FS_FAT_FormatSD() || FAT32      || 121216      || 32768      || 827
|-
| FS_Format()      || FAT32      || 7652704      || 512        || 26510
|-
| FS_Format()      || FAT32      || 3856720      || 1024        || 13649
|-
| FS_Format()      || FAT32      || 1935952      || 2048        || 8264
|-
| '''FS_Format()''' || '''FAT32''' || '''969874''' ||  '''4096''' || '''5710'''
|-
| FS_Format()      || FAT32      || 485411      || 8192        || 2844
|-                                   
| FS_Format()      || FAT32      || 242824      || 16384      || 1083
|-                                   
| FS_Format()      || FAT32      || 121441      || 32768      || 584
|-                                   
| FS_Format()      || FAT16      || 60732        || 65536      || 582
|}
{| class="seggertable"
|+ NAND flash 128 MB
|-
! Function !! FS type !! Num. clusters !! Cluster size [bytes] !! Time [ms]
|-
| FS_FAT_FormatSD() || FAT12      || 1947        || 65536      || 174
|-                                               
| FS_Format()      || FAT16      || 62239      || 2048        || 583
|-                                               
| FS_Format()      || FAT16      || 31149      || 4096        || 758
|-
| '''FS_Format()''' || '''FAT16''' || '''15582''' ||  '''8192''' || '''450'''
|-
| FS_Format()      || FAT16      || 7793        || 16384      || 189
|-                                               
| FS_Format()      || FAT12      || 3897        || 32768      || 413
|-                                               
| FS_Format()      || FAT12      || 1948        || 65536      || 162
|}

Revision as of 14:04, 19 December 2024

High-level formatting

General information

The high-level formatting is a file system operation that can be used to initialize the structure of the file system on a storage device. Typically, this operation has to be performed only once on a lifetime of a storage device before writing any data to the storage device. The high-level format operation can also be performed on a storage device that is already formatted and that contains files and directories. However, all the files and directories will be lost after the high-level format operation.

The reason why this operation is called high-level is to differentiate it from the other type of format operation that is performed by the NAND and NOR drivers and is called low-level formatting. High-level indicates that the operation is performed in the file system layer that is located above the driver layer in the emFile software stack where the low-level formatting operation is implemented.

Theory of operation

An application can perform a high-level format operation via the FS_Format() API function. This API function can be used to perform a high-level format for any of the file system types supported by emFile. The type of file system used by the high-level format operation is determined the file system support enabled in emFile at compile time via FS_SUPPORT_FAT, FS_SUPPORT_EFS or FS_SUPPORT_EXFAT configuration defines. If emFile is configured to support more than one file system types, then the type of file system used by high-level format operation has to be specified by calling the FS_SetFSType() API function.

In addition, emFile comes with specialized API functions for formatting a storage device as FAT and exFAT. These API functions format a storage device according to the specification SD Association. The FS_FAT_FormatSD API function can be used to format a storage device as FA12, FAT16 or FAT32 while the FS_EXFAT_FormatSD can be used to format a storage device as exFAT.

The high-level formatting operation is initializing at least the following regions of a file system:

  • Boot sector
  • Allocation table
  • Root directory

The format API functions may initialize other regions of the file system depending on the file system type.

The boot sector stores basic information about the structure of the file system such as the file system type, the size of an allocation unit called cluster, the total number of clusters and so on. The allocation table stores information about what clusters are allocated and what clusters are belonging to the same file or directory. The root directory is the main entry point for the access to the files and directories stored on the file system. The high-level format information marks all the clusters in the allocation table as not being in use and creates an empty root directory.

Cluster size

A cluster is the minimum storage space that the file system is able to allocate at once for a file or directory and it consists of one or more consecutive logical sectors. The size of a cluster has an influence on the file system performance and on the storage space utilization. Larger clusters provide a better performance because of the reduced number of accesses to the allocation table the file system has to perform for the same amount of accessed data. On the other hand smaller clusters make better use of the storage space if the application works with files of a relatively small size. The high-level formatting API functions of the file system are implemented to use a default cluster size that provides a balance between these.

By default, the size of the cluster is calculated based on the logical sector size and on the total number of logical sectors available on a storage device. As an option, the FS_Format() API function is able to format a storage device using a specified cluster size.

Performance

The time it takes the high-level format operation to complete depends mainly on the capacity of the storage device and secondly on the cluster size. The following table lists the performance measurement results when formatting a 4 GB SD card and an 128 MB NAND flash device as FAT. The test was performed on a SEGGER Flasher PRO XL hardware.

SD card 4 GB
Function FS type Num. clusters Cluster size [bytes] Time [ms]
FS_FAT_FormatSD() FAT32 121216 32768 827
FS_Format() FAT32 7652704 512 26510
FS_Format() FAT32 3856720 1024 13649
FS_Format() FAT32 1935952 2048 8264
FS_Format() FAT32 969874 4096 5710
FS_Format() FAT32 485411 8192 2844
FS_Format() FAT32 242824 16384 1083
FS_Format() FAT32 121441 32768 584
FS_Format() FAT16 60732 65536 582
NAND flash 128 MB
Function FS type Num. clusters Cluster size [bytes] Time [ms]
FS_FAT_FormatSD() FAT12 1947 65536 174
FS_Format() FAT16 62239 2048 583
FS_Format() FAT16 31149 4096 758
FS_Format() FAT16 15582 8192 450
FS_Format() FAT16 7793 16384 189
FS_Format() FAT12 3897 32768 413
FS_Format() FAT12 1948 65536 162