The f_mkfs fucntion creates an FAT volume on the logical drive.
FRESULT f_mkfs ( const TCHAR* path, /* [IN] Logical drive number */ BYTE sfd, /* [IN] Partitioning rule */ UINT au /* [IN] Size of the allocation unit */ );
FR_OK, FR_DISK_ERR, FR_NOT_READY, FR_WRITE_PROTECTED, FR_INVALID_DRIVE, FR_NOT_ENABLED, FR_MKFS_ABORTED, FR_INVALID_PARAMETER
The f_mkfs function creates an FAT volume on the specified logical drive. When FDISK format is specified, a primary partition occupies entire space of the physical drive and then an FAT volume is created on the partition. When SFD format is specified, the FAT volume starts from the first sector of the physical drive.
There are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable drive. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is usually used for floppy disk, Microdrive, optical disk and any type of super-floppy media.
If the logical drive to be formatted is bound to the specific partition (1-4) by support of multiple partition, _MULTI_PARTITION, the FAT volume is created into the partition. In this case, the second argument sfd has no effect. The physical drive must have been partitioned with f_fdisk function or any other partitioning tools prior to create the FAT volume with this function.
The FAT sub-type, FAT12/FAT16/FAT32, is determined by only number of clusters on the volume, 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 read/write throughput and space usage efficiency. Larger cluster size increases the read/write throughput and decreases the space usage efficiency of the volume. In case of the number of clusters comes on the FAT sub-type boundaries, the function can fail with FR_MKFS_ABORTED.
Remark: Creating exFAT volume is not supported at current revision, R0.12.
Available when _FS_READOLNY == 0 and _USE_MKFS == 1.
/* Format default drive and create a file */ int main (void) { FATFS fs; /* File system object (volume work area) */ FIL fil; /* File object */ FRESULT res; /* API result code */ UINT bw; /* Bytes written */ /* Register work area (do not care about error) */ f_mount(&fs, "", 0); /* Create FAT volume with default cluster size */ res = f_mkfs("", 0, 0); if (res) ... /* Create a file as new */ res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE); if (res) ... /* Write a message */ f_write(&fil, "Hello, World!\r\n", 15, &bw); if (bw != 15) ... /* Close the file */ f_close(&fil); /* Unregister work area */ f_mount(0, "", 0);