f_mkfs

The f_mkfs fucntion creates a file system on the drive.

FRESULT f_mkfs (
  BYTE  Drive,            /* Logical drive number */
  BYTE  PartitioningRule, /* Partitioning rule */
  UINT  AllocSize         /* Size of the allocation unit */
);

Parameters

Drive
Logical drive number (0-9) to be formatted.
PartitioningRule
When 0 is given, a partition table is created into the master boot record and a primary DOS partition is created and then an FAT volume is created on the partition. This is called FDISK format and used for harddisk and memory cards. When 1 is given, the FAT volume starts from the first sector on the drive without partition table. This is called SFD format and used for floppy disk and most optical disk.
AllocSize
Force the allocation unit (cluter) size in unit of byte. The value must be power of 2 and between the sector size and 128 times sector size. When invalid value is specified, the cluster size is determined depends on the volume size.

Return Values

FR_OK, FR_DISK_ERR, FR_NOT_READY, FR_WRITE_PROTECTED, FR_INVALID_DRIVE, FR_NOT_ENABLED, FR_MKFS_ABORTED

Description

The f_mkfs function creates an FAT volume on the drive. There are two partitioning rules, FDISK and SFD, for removable media. The FDISK format is recommended for the most case. This function currently does not support multiple partition, so that existing partitions on the physical dirve will be deleted and re-created a new partition occupies entire disk space.

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.

QuickInfo

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

Return