提交 e601c2a6 编写于 作者: B bernard

Add sector size check when mounting a FAT file system.

上级 ae891e20
......@@ -110,20 +110,30 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
FATFS *fat;
FRESULT result;
int index;
struct rt_device_blk_geometry geometry;
/* get an empty position */
index = get_disk(RT_NULL);
if (index == -1)
return -DFS_STATUS_ENOSPC;
return -DFS_STATUS_ENOENT;
/* save device */
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));
if (fat == RT_NULL)
{
disk[index] = RT_NULL;
return -1;
return -DFS_STATUS_ENOMEM;
}
/* mount fatfs, always 0 logic driver */
......
......@@ -34,6 +34,9 @@
#ifndef __RT_DEF_H__
#define __RT_DEF_H__
/* include rtconfig header to import configuration */
#include <rtconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册