## 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 */
      WORD  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 first sector on the drive and then the file system is created on the partition. This is called FDISK format and used for harddisk and memory card. When 1 is given, the file system starts from the first sector without partition table. This is often called super floppy disk (SFD) format and used for floppy disk and removable disk.
AllocSize
  Specifies allocation unit size in number of bytes per cluster. The value must be 0 or power of 2 in range of from 512 to 32768. When 0 is specified, the cluster size is determined depends on the volume size. FAT64 (64KB/cluster on FAT16) cannot be created by this function.

#### Return Values

FR_OK (0)
  The function succeeded.
FR_INVALID_DRIVE
  The drive number is invalid.
FR_NOT_READY
  The drive cannot work due to any reason.
FR_WRITE_PROTECTED
  The drive is write protected.
FR_NOT_ENABLED
  The logical drive has no work area.
FR_DISK_ERR
  The function failed due to an error in the disk function.
FR_MKFS_ABORTED
  The function aborted before start in format due to a reason as follows.
  - The disk size is too small.
  - Invalid parameter was given to any parameter.
  - Not allowable cluster size for this drive. This can occure when number of clusters becomes around 0xFF7 and 0xFFF7.

#### Description

The f_mkfs function creates a FAT file system on the drive. There are two partitioning rules, FDISK and SFD, for removable media. It can be selected with an argument. 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 drive 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.

#### QuickInfo

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

Return