The f_fdisk fucntion divides a physical drive.
FRESULT f_fdisk ( BYTE pdrv, /* [IN] Physical drive number */ const LBA_t ptbl[], /* [IN] Partition map table */ void* work /* [IN] Work area */ );
FR_OK, FR_DISK_ERR, FR_NOT_READY, FR_WRITE_PROTECTED, FR_INVALID_PARAMETER, FR_NOT_ENOUGH_CORE
The f_fdisk function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is truncated at end of the drive.
By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (FF_LBA64 = 1) and the drive size is equal to or larger than FF_MIN_GPT sectors. It can create over ten partitions on a drive.
Available when FF_FS_READOLNY == 0, FF_USE_MKFS == 1 and FF_MULTI_PARTITION == 1.
/* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */ PARTITION VolToPart[FF_VOLUMES] = { {0, 1}, /* "0:" ==> 1st partition in PD#0 */ {0, 2}, /* "1:" ==> 2nd partition in PD#0 */ {1, 0} /* "2:" ==> PD#1 as removable drive */ };
/* Initialize a brand-new disk drive mapped to physical drive 0 */ BYTE work[FF_MAX_SS]; /* Working buffer */ LBA_t plist[] = {50, 50, 0}; /* Divide the drive into two partitions */ /* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */ /* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */ f_fdisk(0, plist, work); /* Divide physical drive 0 */ f_mkfs("0:", 0, work, sizeof work); /* Create FAT volume on the logical drive 0 */ f_mkfs("1:", 0, work, sizeof work); /* Create FAT volume on the logical drive 1 */