## 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         /* Allocation unit size */
    );

#### Parameters

Drive
  Logical drive number (0-9) to be formatted.
PartitioningRule
  When 0 is given, a partition table is created into first sector on the drive and then the file system is created on the partition. This is called FDISK format. When 1 is given, the file system starts from the first sector without partition table. This is often called super floppy (SFD) format.
AllocSize
  Specifies allocation unit size (number of bytes per cluster). The value must be power of 2 in range of from 512 to 32768.

#### 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_RW_ERROR
  The function failed due to a disk error or an internal error.
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 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 partition occupies entire disk space.

The FAT sub-type, FAT12/FAT16/FAT32, is determined by only how many 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 drive size and specified cluster size. The cluster size affects performance of file system and large cluster increases the performance, so that 32768 bytes per cluster is recommended for most case except for small drive.

This function is supported on only FatFs with _USE_MKFS option.

Return