@@ -383,17 +383,20 @@ static int fatfs_statvfs(struct fs_mount_t *mountp,
383383 int res = - ENOTSUP ;
384384#if !defined(CONFIG_FS_FATFS_READ_ONLY )
385385 FATFS * fs ;
386+ DWORD f_bfree = 0 ;
386387
387- res = f_getfree (& mountp -> mnt_point [1 ], & stat -> f_bfree , & fs );
388+ res = f_getfree (& mountp -> mnt_point [1 ], & f_bfree , & fs );
388389 if (res != FR_OK ) {
389390 return - EIO ;
390391 }
391392
393+ stat -> f_bfree = f_bfree ;
394+
392395 /*
393- * _MIN_SS holds the sector size. It is one of the configuration
396+ * FF_MIN_SS holds the sector size. It is one of the configuration
394397 * constants used by the FS module
395398 */
396- stat -> f_bsize = _MIN_SS ;
399+ stat -> f_bsize = FF_MIN_SS ;
397400 stat -> f_frsize = fs -> csize * stat -> f_bsize ;
398401 stat -> f_blocks = (fs -> n_fatent - 2 );
399402
@@ -416,10 +419,16 @@ static int fatfs_mount(struct fs_mount_t *mountp)
416419 /* If no file system found then create one */
417420 if (res == FR_NO_FILESYSTEM &&
418421 (mountp -> flags & FS_MOUNT_FLAG_NO_FORMAT ) == 0 ) {
419- uint8_t work [_MAX_SS ];
420-
421- res = f_mkfs (& mountp -> mnt_point [1 ],
422- (FM_FAT | FM_SFD ), 0 , work , sizeof (work ));
422+ uint8_t work [FF_MAX_SS ];
423+ MKFS_PARM mkfs_opt = {
424+ .fmt = FM_FAT | FM_SFD , /* Any suitable FAT */
425+ .n_fat = 1 , /* One FAT fs table */
426+ .align = 0 , /* Get sector size via diskio query */
427+ .n_root = 512 , /* Max 512 root directory entries */
428+ .au_size = 0 /* Auto calculate cluster size */
429+ };
430+
431+ res = f_mkfs (& mountp -> mnt_point [1 ], & mkfs_opt , work , sizeof (work ));
423432 if (res == FR_OK ) {
424433 res = f_mount ((FATFS * )mountp -> fs_data ,
425434 & mountp -> mnt_point [1 ], 1 );
@@ -435,7 +444,7 @@ static int fatfs_unmount(struct fs_mount_t *mountp)
435444{
436445 FRESULT res ;
437446
438- res = f_mount (NULL , & mountp -> mnt_point [1 ], 1 );
447+ res = f_mount (NULL , & mountp -> mnt_point [1 ], 0 );
439448
440449 return translate_error (res );
441450}
0 commit comments