@@ -5392,7 +5392,9 @@ FRESULT f_mkfs (
5392
5392
const UINT n_fats = 1 ; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
5393
5393
const UINT n_rootdir = 512 ; /* Number of root directory entries for FAT volume */
5394
5394
static const WORD cst [] = {1 , 4 , 16 , 64 , 256 , 512 , 0 }; /* Cluster size boundary for FAT volume (4Ks unit) */
5395
+ #if FF_MKFS_FAT32
5395
5396
static const WORD cst32 [] = {1 , 2 , 4 , 8 , 16 , 32 , 0 }; /* Cluster size boundary for FAT32 volume (128Ks unit) */
5397
+ #endif
5396
5398
BYTE fmt , sys , * buf , * pte , part ; void * pdrv ;
5397
5399
WORD ss ; /* Sector size */
5398
5400
DWORD szb_buf , sz_buf , sz_blk , n_clst , pau , sect , nsect , n ;
@@ -5464,7 +5466,7 @@ FRESULT f_mkfs (
5464
5466
}
5465
5467
}
5466
5468
if (au > 128 ) LEAVE_MKFS (FR_INVALID_PARAMETER ); /* Too large au for FAT/FAT32 */
5467
- if (opt & FM_FAT32 ) { /* FAT32 possible? */
5469
+ if (FF_MKFS_FAT32 && ( opt & FM_FAT32 ) ) { /* FAT32 possible? */
5468
5470
if ((opt & FM_ANY ) == FM_FAT32 || !(opt & FM_FAT )) { /* FAT32 only or no-FAT? */
5469
5471
fmt = FS_FAT32 ; break ;
5470
5472
}
@@ -5641,6 +5643,7 @@ FRESULT f_mkfs (
5641
5643
do {
5642
5644
pau = au ;
5643
5645
/* Pre-determine number of clusters and FAT sub-type */
5646
+ #if FF_MKFS_FAT32
5644
5647
if (fmt == FS_FAT32 ) { /* FAT32 volume */
5645
5648
if (pau == 0 ) { /* au auto-selection */
5646
5649
n = sz_vol / 0x20000 ; /* Volume size in unit of 128KS */
@@ -5651,7 +5654,9 @@ FRESULT f_mkfs (
5651
5654
sz_rsv = 32 ; /* Number of reserved sectors */
5652
5655
sz_dir = 0 ; /* No static directory */
5653
5656
if (n_clst <= MAX_FAT16 || n_clst > MAX_FAT32 ) LEAVE_MKFS (FR_MKFS_ABORTED );
5654
- } else { /* FAT volume */
5657
+ } else
5658
+ #endif
5659
+ { /* FAT volume */
5655
5660
if (pau == 0 ) { /* au auto-selection */
5656
5661
n = sz_vol / 0x1000 ; /* Volume size in unit of 4KS */
5657
5662
for (i = 0 , pau = 1 ; cst [i ] && cst [i ] <= n ; i ++ , pau <<= 1 ) ; /* Get from table */
@@ -5681,12 +5686,14 @@ FRESULT f_mkfs (
5681
5686
/* Determine number of clusters and final check of validity of the FAT sub-type */
5682
5687
if (sz_vol < b_data + pau * 16 - b_vol ) LEAVE_MKFS (FR_MKFS_ABORTED ); /* Too small volume */
5683
5688
n_clst = (sz_vol - sz_rsv - sz_fat * n_fats - sz_dir ) / pau ;
5689
+ #if FF_MKFS_FAT32
5684
5690
if (fmt == FS_FAT32 ) {
5685
5691
if (n_clst <= MAX_FAT16 ) { /* Too few clusters for FAT32 */
5686
5692
if (au == 0 && (au = pau / 2 ) != 0 ) continue ; /* Adjust cluster size and retry */
5687
5693
LEAVE_MKFS (FR_MKFS_ABORTED );
5688
5694
}
5689
5695
}
5696
+ #endif
5690
5697
if (fmt == FS_FAT16 ) {
5691
5698
if (n_clst > MAX_FAT16 ) { /* Too many clusters for FAT16 */
5692
5699
if (au == 0 && (pau * 2 ) <= 64 ) {
@@ -5720,7 +5727,11 @@ FRESULT f_mkfs (
5720
5727
buf [BPB_SecPerClus ] = (BYTE )pau ; /* Cluster size [sector] */
5721
5728
st_word (buf + BPB_RsvdSecCnt , (WORD )sz_rsv ); /* Size of reserved area */
5722
5729
buf [BPB_NumFATs ] = (BYTE )n_fats ; /* Number of FATs */
5730
+ #if FF_MKFS_FAT32
5723
5731
st_word (buf + BPB_RootEntCnt , (WORD )((fmt == FS_FAT32 ) ? 0 : n_rootdir )); /* Number of root directory entries */
5732
+ #else
5733
+ st_word (buf + BPB_RootEntCnt , (WORD ) n_rootdir ); /* Number of root directory entries */
5734
+ #endif
5724
5735
if (sz_vol < 0x10000 ) {
5725
5736
st_word (buf + BPB_TotSec16 , (WORD )sz_vol ); /* Volume size in 16-bit LBA */
5726
5737
} else {
@@ -5730,6 +5741,7 @@ FRESULT f_mkfs (
5730
5741
st_word (buf + BPB_SecPerTrk , 63 ); /* Number of sectors per track (for int13) */
5731
5742
st_word (buf + BPB_NumHeads , 255 ); /* Number of heads (for int13) */
5732
5743
st_dword (buf + BPB_HiddSec , b_vol ); /* Volume offset in the physical drive [sector] */
5744
+ #if FF_MKFS_FAT32
5733
5745
if (fmt == FS_FAT32 ) {
5734
5746
st_dword (buf + BS_VolID32 , GET_FATTIME ()); /* VSN */
5735
5747
st_dword (buf + BPB_FATSz32 , sz_fat ); /* FAT size [sector] */
@@ -5739,7 +5751,9 @@ FRESULT f_mkfs (
5739
5751
buf [BS_DrvNum32 ] = 0x80 ; /* Drive number (for int13) */
5740
5752
buf [BS_BootSig32 ] = 0x29 ; /* Extended boot signature */
5741
5753
mem_cpy (buf + BS_VolLab32 , "NO NAME " "FAT32 " , 19 ); /* Volume label, FAT signature */
5742
- } else {
5754
+ } else
5755
+ #endif
5756
+ {
5743
5757
st_dword (buf + BS_VolID , GET_FATTIME ()); /* VSN */
5744
5758
st_word (buf + BPB_FATSz16 , (WORD )sz_fat ); /* FAT size [sector] */
5745
5759
buf [BS_DrvNum ] = 0x80 ; /* Drive number (for int13) */
@@ -5750,6 +5764,7 @@ FRESULT f_mkfs (
5750
5764
if (disk_write (pdrv , buf , b_vol , 1 ) != RES_OK ) LEAVE_MKFS (FR_DISK_ERR ); /* Write it to the VBR sector */
5751
5765
5752
5766
/* Create FSINFO record if needed */
5767
+ #if FF_MKFS_FAT32
5753
5768
if (fmt == FS_FAT32 ) {
5754
5769
disk_write (pdrv , buf , b_vol + 6 , 1 ); /* Write backup VBR (VBR + 6) */
5755
5770
mem_set (buf , 0 , ss );
@@ -5761,16 +5776,20 @@ FRESULT f_mkfs (
5761
5776
disk_write (pdrv , buf , b_vol + 7 , 1 ); /* Write backup FSINFO (VBR + 7) */
5762
5777
disk_write (pdrv , buf , b_vol + 1 , 1 ); /* Write original FSINFO (VBR + 1) */
5763
5778
}
5779
+ #endif
5764
5780
5765
5781
/* Initialize FAT area */
5766
5782
mem_set (buf , 0 , (UINT )szb_buf );
5767
5783
sect = b_fat ; /* FAT start sector */
5768
5784
for (i = 0 ; i < n_fats ; i ++ ) { /* Initialize FATs each */
5785
+ #if FF_MKFS_FAT32
5769
5786
if (fmt == FS_FAT32 ) {
5770
5787
st_dword (buf + 0 , 0xFFFFFFF8 ); /* Entry 0 */
5771
5788
st_dword (buf + 4 , 0xFFFFFFFF ); /* Entry 1 */
5772
5789
st_dword (buf + 8 , 0x0FFFFFFF ); /* Entry 2 (root directory) */
5773
- } else {
5790
+ } else
5791
+ #endif
5792
+ {
5774
5793
st_dword (buf + 0 , (fmt == FS_FAT12 ) ? 0xFFFFF8 : 0xFFFFFFF8 ); /* Entry 0 and 1 */
5775
5794
}
5776
5795
nsect = sz_fat ; /* Number of FAT sectors */
@@ -5783,7 +5802,11 @@ FRESULT f_mkfs (
5783
5802
}
5784
5803
5785
5804
/* Initialize root directory (fill with zero) */
5805
+ #if FF_MKFS_FAT32
5786
5806
nsect = (fmt == FS_FAT32 ) ? pau : sz_dir ; /* Number of root directory sectors */
5807
+ #else
5808
+ nsect = sz_dir ; /* Number of root directory sectors */
5809
+ #endif
5787
5810
do {
5788
5811
n = (nsect > sz_buf ) ? sz_buf : nsect ;
5789
5812
if (disk_write (pdrv , buf , sect , (UINT )n ) != RES_OK ) LEAVE_MKFS (FR_DISK_ERR );
@@ -5795,7 +5818,7 @@ FRESULT f_mkfs (
5795
5818
if (FF_FS_EXFAT && fmt == FS_EXFAT ) {
5796
5819
sys = 0x07 ; /* HPFS/NTFS/exFAT */
5797
5820
} else {
5798
- if (fmt == FS_FAT32 ) {
5821
+ if (FF_MKFS_FAT32 && fmt == FS_FAT32 ) {
5799
5822
sys = 0x0C ; /* FAT32X */
5800
5823
} else {
5801
5824
if (sz_vol >= 0x10000 ) {
0 commit comments