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

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


Logical drive number (0-9) to be formatted.
Specifies partitioning rule, FDISK(0) or SFD(1). This argument is ignored on some case.
Force the allocation unit (cluter) size in unit of byte. The value must be power of 2 and between the sector size and 128 * sector size. When a zero is given, the cluster size is determined depends on the volume size.

Return Values



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

If the logical drive is being 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 is ignored. The physical drive must be 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 format is usually used for harddisk, MMC, SDC and CFC. It can divide a physical drive into one or more partitions with a partition table on the MBR. The SFD format is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is 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.


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

See Also

Volume management, f_fdisk