/* Create partition table on the physical drive */\r
/*-----------------------------------------------------------------------*/\r
\r
+#define CLUSTER_SIZE 63\r
+#define SUPPORTED_FLASH_SIZE 0x1000\r
+\r
FRESULT f_fdisk (\r
BYTE pdrv, /* Physical drive number */\r
const DWORD* szt, /* Pointer to the size table for each partitions */\r
BYTE s_hd, e_hd, *p, *buf = (BYTE*)work;\r
DSTATUS stat;\r
DWORD sz_disk, sz_part, s_part;\r
-\r
+ DWORD cluster_size = CLUSTER_SIZE;\r
\r
stat = disk_initialize(pdrv);\r
if (stat & STA_NOINIT) return FR_NOT_READY;\r
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;\r
if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR;\r
-\r
/* Determine the CHS without any care of the drive geometry */\r
- for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ;\r
+ for (n = 16; n < 256 && sz_disk / n / cluster_size > 1024; n *= 2) ;\r
if (n == 256) n--;\r
+ if (sz_disk < SUPPORTED_FLASH_SIZE) {\r
+ cluster_size = 1;\r
+ n = sz_disk;\r
+ }\r
e_hd = n - 1;\r
- sz_cyl = 63 * n;\r
+ sz_cyl = cluster_size * n;\r
tot_cyl = sz_disk / sz_cyl;\r
\r
/* Create partition table */\r
sz_part = (DWORD)sz_cyl * p_cyl;\r
if (i == 0) { /* Exclude first track of cylinder 0 */\r
s_hd = 1;\r
- s_part += 63; sz_part -= 63;\r
+ s_part += cluster_size; sz_part -= cluster_size;\r
} else {\r
s_hd = 0;\r
}\r
p[3] = (BYTE)b_cyl; /* Start cylinder */\r
p[4] = 0x06; /* System type (temporary setting) */\r
p[5] = e_hd; /* End head */\r
- p[6] = (BYTE)((e_cyl >> 2) + 63); /* End sector */\r
+ p[6] = (BYTE)((e_cyl >> 2) + cluster_size); /* End sector */\r
p[7] = (BYTE)e_cyl; /* End cylinder */\r
st_dword(p + 8, s_part); /* Start sector in LBA */\r
st_dword(p + 12, sz_part); /* Partition size */\r