X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/5366852335044c1e68a5c32548d3051cc943552f..refs/tags/fatfs-0.12b:/fatfs/doc/en/mkfs.html diff --git a/fatfs/doc/en/mkfs.html b/fatfs/doc/en/mkfs.html index 573bdd7..51f8aac 100644 --- a/fatfs/doc/en/mkfs.html +++ b/fatfs/doc/en/mkfs.html @@ -13,12 +13,14 @@

f_mkfs

-

The f_mkfs fucntion creates an FAT file system on the logical drive.

+

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

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

Parameters

path
-
Pinter to the null-terminated string that specifies the logical drive to be formatted. If there is no drive number, it means the default drive.
-
sfd
-
Specifies partitioning rule (FDISK(0) or SFD(1)). This argument will be ignored on some case.
+
Pointer to the null-terminated string specifies the logical drive to be formatted. If there is no drive number in it, it means the default drive. The logical drive may or may not be mounted for the format process.
+
opt
+
Specifies the format option in combination of FM_FAT, FM_FAT32, FM_EXFAT and bitwise-or of these three, FM_ANY. FM_EXFAT is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size. The flag FM_SFD specifies to place the volume on the drive in SFD format.
au
-
Specifies size of the allocation unit (cluter) in unit of byte. The value must be sector size * n (n is 1 to 128 and power of 2). When a zero is given, the cluster size is determined depends on the volume size.
+
Specifies size of the allocation unit (cluter) in unit of byte. The valid value is N times the sector size. N is power of 2 from 1 to 128 for FAT volume and upto 16MiB for exFAT volume. If zero is given, the default allocation unit size is selected depends on the volume size.
+
work
+
Pointer to the working buffer used for the format process.
+
len
+
Size of the working buffer in unit of byte. It needs to be the sector size at least. Plenty of working buffer reduces number of write transaction to the device and the format process will be finished quickly.
@@ -43,7 +49,6 @@ FRESULT f_mkfs ( FR_NOT_READY, FR_WRITE_PROTECTED, FR_INVALID_DRIVE, -FR_NOT_ENABLED, FR_MKFS_ABORTED, FR_INVALID_PARAMETER

@@ -51,11 +56,11 @@ FRESULT f_mkfs (

Description

-

The f_mkfs() function creates an FAT volume on the logical drive. When FDISK format is specified, a primary partition occupies the entire disk space is created and then an FAT volume is created on the partition. When SFD format is specified, the FAT volume starts from the first sector of the physical drive.

-

If the logical drive has been bound to any partition (1-4) by multiple partition feature (_MULTI_PARTITION), the FAT volume is created into the specified partition. In this case, the second argument sfd is ignored. The physical drive must have been partitioned with f_fdisk() function or any other partitioning tool prior to use this function.

-

Note that there are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable media. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is usually used for floppy disk, Microdrive, optical disk and super-floppy media.

-

The FAT sub-type, FAT12/FAT16/FAT32, is determined by number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the volume size and the specified cluster size. The cluster size affects performance of the file system and large cluster increases the performance.

-

When the number of clusters gets near the FAT sub-type boundaries, the function can fail with FR_MKFS_ABORTED.

+

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

+

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

+

There are two disk formats, FDISK and SFD. The FDISK format is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR (maser boot record, the first sector of the physical drive). The SFD (super-floppy disk) is non-partitioned disk format. The FAT volume starts at the first sector of the physical drive without any disk partitioning. It is usually used for floppy disk, Microdrive, optical disk and most type of super-floppy media. Some systems support only either one of two formats and other is not supported.

+

When FM_SFD is not specified, a primary partition occupies whole drive space is created and then the FAT volume is created in it. When FM_SFD is specified, the FAT volume occupies from the first sector of the drive is created.

+

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

@@ -63,9 +68,47 @@ FRESULT f_mkfs (

Available when _FS_READOLNY == 0 and _USE_MKFS == 1.

+
+

Example

+
+/* Format default drive and create a file */
+int main (void)
+{
+    FATFS fs;           /* File system object */
+    FIL fil;            /* File object */
+    FRESULT res;        /* API result code */
+    UINT bw;            /* Bytes written */
+    BYTE work[_MAX_SS]; /* Work area (larger is better for process time) */
+
+
+    /* Create FAT volume */
+    res = f_mkfs("", FM_ANY, 0, work, sizeof work);
+    if (res) ...
+
+    /* Register work area */
+    f_mount(&fs, "", 0);
+
+    /* Create a file as new */
+    res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
+    if (res) ...
+
+    /* Write a message */
+    f_write(&fil, "Hello, World!\r\n", 15, &bw);
+    if (bw != 15) ...
+
+    /* Close the file */
+    f_close(&fil);
+
+    /* Unregister work area */
+    f_mount(0, "", 0);
+
+    ...
+
+
+

See Also

-

Volume management, f_fdisk

+

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

Return