## 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 (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 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.

#### QuickInfo

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

Return