diff options
| author | bernard <[email protected]> | 2014-01-26 20:30:37 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2014-01-26 20:30:37 +0800 |
| commit | e601c2a6ed1968517acf080b7d6cdc57b5a14070 (patch) | |
| tree | 4496a8d99b713cdd47652c264af30e834062b973 /components | |
| parent | ae891e201124c7937dad301739f83cbb296ead9a (diff) | |
Add sector size check when mounting a FAT file system.
Diffstat (limited to 'components')
| -rw-r--r-- | components/dfs/filesystems/elmfat/dfs_elm.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 0d7f9b781c..4495bd9b3e 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -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 */ |
