Browse Source

Add sector size check when mounting a FAT file system.

bernard 11 years ago
parent
commit
e601c2a6ed
2 changed files with 16 additions and 3 deletions
  1. 13 3
      components/dfs/filesystems/elmfat/dfs_elm.c
  2. 3 0
      include/rtdef.h

+ 13 - 3
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 */

+ 3 - 0
include/rtdef.h

@@ -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