Browse Source

update dfs to support NFTL

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2478 bbd45198-f89e-11dd-88c7-29a3b14d5316
goprife@gmail.com 12 years ago
parent
commit
56ab153b1c

+ 8 - 2
components/dfs/filesystems/elmfat/dfs_elm.c

@@ -172,7 +172,7 @@ int dfs_elm_mkfs(const char *device_name)
 	for (drv = 0; drv < _VOLUMES; drv ++)
 	for (drv = 0; drv < _VOLUMES; drv ++)
 	{
 	{
 		dev = disk[drv];
 		dev = disk[drv];
-		if (rt_strncmp(dev->parent.name, device_name, RT_NAME_MAX) == 0)
+		if (dev != RT_NULL && rt_strncmp(dev->parent.name, device_name, RT_NAME_MAX) == 0)
 		{
 		{
 			/* 1: no partition table */
 			/* 1: no partition table */
 			/* 0: auto selection of cluster size */
 			/* 0: auto selection of cluster size */
@@ -782,8 +782,14 @@ DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void *buff)
 		*(DWORD *)buff = geometry.block_size/geometry.bytes_per_sector;
 		*(DWORD *)buff = geometry.block_size/geometry.bytes_per_sector;
 	}
 	}
 	else if (ctrl == CTRL_SYNC)
 	else if (ctrl == CTRL_SYNC)
+	{
 		rt_device_control(device, RT_DEVICE_CTRL_BLK_SYNC, RT_NULL);
 		rt_device_control(device, RT_DEVICE_CTRL_BLK_SYNC, RT_NULL);
-
+	}
+	else if (ctrl == CTRL_ERASE_SECTOR)
+	{
+		rt_device_control(device, RT_DEVICE_CTRL_BLK_ERASE, buff);
+	}
+	
 	return RES_OK;
 	return RES_OK;
 }
 }
 
 

+ 4 - 1
components/dfs/filesystems/elmfat/ffconf.h

@@ -163,8 +163,11 @@
 / it can mount only first primaly partition. When it is set to 1, each volume
 / it can mount only first primaly partition. When it is set to 1, each volume
 / is tied to the partitions listed in VolToPart[]. */
 / is tied to the partitions listed in VolToPart[]. */
 
 
-
+#ifdef RT_DFS_ELM_USE_ERASE
+#define _USE_ERASE	1
+#else
 #define	_USE_ERASE	0	/* 0:Disable or 1:Enable */
 #define	_USE_ERASE	0	/* 0:Disable or 1:Enable */
+#endif
 /* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
 /* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
 /  should be added to the disk_ioctl functio. */
 /  should be added to the disk_ioctl functio. */
 
 

+ 5 - 0
components/dfs/include/dfs_def.h

@@ -198,6 +198,11 @@
 #define DFS_SEEK_SET		SEEK_SET
 #define DFS_SEEK_SET		SEEK_SET
 #define DFS_SEEK_CUR		SEEK_CUR
 #define DFS_SEEK_CUR		SEEK_CUR
 #define DFS_SEEK_END		SEEK_END
 #define DFS_SEEK_END		SEEK_END
+#elif defined(_MSC_VER)
+#include <stdio.h>
+#define DFS_SEEK_SET		SEEK_SET
+#define DFS_SEEK_CUR		SEEK_CUR
+#define DFS_SEEK_END		SEEK_END
 #else
 #else
 #define DFS_SEEK_SET         0
 #define DFS_SEEK_SET         0
 #define DFS_SEEK_CUR         1
 #define DFS_SEEK_CUR         1

+ 2 - 0
components/dfs/include/dfs_posix.h

@@ -69,6 +69,8 @@
 
 
 #if defined(__CC_ARM)
 #if defined(__CC_ARM)
 #include <stdio.h>
 #include <stdio.h>
+#elif defined(_MSC_VER)
+#include <stdio.h>
 #else
 #else
 #define SEEK_SET	DFS_SEEK_SET
 #define SEEK_SET	DFS_SEEK_SET
 #define SEEK_CUR	DFS_SEEK_CUR
 #define SEEK_CUR	DFS_SEEK_CUR

+ 9 - 2
components/dfs/src/dfs_fs.c

@@ -400,7 +400,7 @@ int dfs_mkfs(const char *fs_name, const char *device_name)
 {
 {
 	int index;
 	int index;
 
 
-	/* lock filesystem */
+	/* lock file system */
 	dfs_lock();
 	dfs_lock();
 	/* find the file system operations */
 	/* find the file system operations */
 	for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
 	for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
@@ -420,6 +420,7 @@ int dfs_mkfs(const char *fs_name, const char *device_name)
 	}
 	}
 	dfs_unlock();
 	dfs_unlock();
 
 
+	rt_kprintf("Can not find the file system which named as %s.\n", fs_name);
 	return -1;
 	return -1;
 }
 }
 
 
@@ -455,9 +456,15 @@ FINSH_FUNCTION_EXPORT(mkfs, make a file system);
 
 
 void df(const char *path)
 void df(const char *path)
 {
 {
+	int result;
 	struct statfs buffer;
 	struct statfs buffer;
 
 
-	if (dfs_statfs(path, &buffer) == 0)
+	if (path == RT_NULL)
+		result = dfs_statfs("/", &buffer);
+	else
+		result = dfs_statfs(path, &buffer);
+
+	if (result == 0)
 	{
 	{
 		rt_kprintf("disk free: %d block[%d bytes per block]\n", buffer.f_bfree, buffer.f_bsize);
 		rt_kprintf("disk free: %d block[%d bytes per block]\n", buffer.f_bfree, buffer.f_bsize);
 	}
 	}