4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-19 02:53:32 +08:00

Add sector size check when mounting a FAT file system.

This commit is contained in:
bernard 2014-01-26 20:30:37 +08:00
parent ae891e2011
commit e601c2a6ed
2 changed files with 16 additions and 3 deletions

View File

@ -110,20 +110,30 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
FATFS *fat; FATFS *fat;
FRESULT result; FRESULT result;
int index; int index;
struct rt_device_blk_geometry geometry;
/* get an empty position */ /* get an empty position */
index = get_disk(RT_NULL); index = get_disk(RT_NULL);
if (index == -1) if (index == -1)
return -DFS_STATUS_ENOSPC; return -DFS_STATUS_ENOENT;
/* save device */ /* save device */
disk[index] = fs->dev_id; disk[index] = fs->dev_id;
/* check sector size */
if (rt_device_control(fs->dev_id, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry) == RT_EOK)
{
if (geometry.block_size > _MAX_SS)
{
rt_kprintf("Block size of device is great than sector size of FAT.\n");
return -DFS_STATUS_EINVAL;
}
}
fat = (FATFS *)rt_malloc(sizeof(FATFS)); fat = (FATFS *)rt_malloc(sizeof(FATFS));
if (fat == RT_NULL) if (fat == RT_NULL)
{ {
disk[index] = RT_NULL; disk[index] = RT_NULL;
return -1; return -DFS_STATUS_ENOMEM;
} }
/* mount fatfs, always 0 logic driver */ /* mount fatfs, always 0 logic driver */

View File

@ -34,6 +34,9 @@
#ifndef __RT_DEF_H__ #ifndef __RT_DEF_H__
#define __RT_DEF_H__ #define __RT_DEF_H__
/* include rtconfig header to import configuration */
#include <rtconfig.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif