## f_fdisk

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 */
    );

#### Parameters

pdrv
  Specifies the physical drive to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.
ptbl
  List of partition size to create on the drive. The data type `LBA_t` is an alias of `DWORD` or `QWORD` depends on the configuration option `FF_LBA64`.
work
  Pointer to the function work area. The size must be at least `FF_MAX_SS` bytes. When a null pointer is given with `FF_USE_LFN = 3`, a memory block is obtained in this function for the working buffer.

#### Return Values

FR_OK, FR_DISK_ERR, FR_NOT_READY, FR_WRITE_PROTECTED, FR_INVALID_PARAMETER, FR_NOT_ENOUGH_CORE

#### Description

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.

#### QuickInfo

Available when `FF_FS_READOLNY == 0`, `FF_USE_MKFS == 1` and `FF_MULTI_PARTITION == 1`.

#### Example

        /* 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 */

#### See Also

Volume management, `f_mkfs`

Return