Prechádzať zdrojové kódy

fix <BAD file> issue on mount point directory

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1237 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 14 rokov pred
rodič
commit
afbce6d5f9

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

@@ -102,8 +102,11 @@
 /  two Unicode handling functions ff_convert() and ff_wtoupper() must be added
 /  to the project. */
 
-
+#ifdef RT_DFS_ELM_LFN_UNICODE
+#define _LFN_UNICODE	1	/* 0 or 1 */
+#else
 #define	_LFN_UNICODE	0	/* 0 or 1 */
+#endif
 /* To switch the character code set on FatFs API to Unicode,
 /  enable LFN feature and set _LFN_UNICODE to 1.
 */

+ 23 - 24
components/dfs/src/dfs_file.c

@@ -74,7 +74,7 @@ int dfs_file_open(struct dfs_fd* fd, const char *path, int flags)
 	if (fs->ops->open == RT_NULL)
 	{
 		/* clear fd */
-		rt_free(fd->path);		
+		rt_free(fd->path);
 		rt_memset(fd, 0, sizeof(*fd));
 
 		return -DFS_STATUS_ENOSYS;
@@ -104,7 +104,7 @@ int dfs_file_open(struct dfs_fd* fd, const char *path, int flags)
 
 /**
  * this function will close a file descriptor.
- * 
+ *
  * @param fd the file descriptor to be closed.
  *
  * @return 0 on successful, -1 on failed.
@@ -116,7 +116,7 @@ int dfs_file_close(struct dfs_fd* fd)
 	if (fd != RT_NULL && fd->fs->ops->close != RT_NULL) result = fd->fs->ops->close(fd);
 
 	/* close fd error, return */
-	if ( result < 0 ) return result; 
+	if ( result < 0 ) return result;
 
 	rt_free(fd->path);
 	rt_memset(fd, 0, sizeof(struct dfs_fd));
@@ -126,7 +126,7 @@ int dfs_file_close(struct dfs_fd* fd)
 
 /**
  * this function will perform a io control on a file descriptor.
- * 
+ *
  * @param fd the file descriptor.
  * @param cmd the command to send to file descriptor.
  * @param args the argument to send to file descriptor.
@@ -160,7 +160,7 @@ int dfs_file_read(struct dfs_fd* fd, void *buf, rt_size_t len)
 	int result = 0;
 
 	if (fd == RT_NULL) return -DFS_STATUS_EINVAL;
-	
+
 	fs = (struct dfs_filesystem*) fd->fs;
 	if (fs->ops->read == RT_NULL) return -DFS_STATUS_ENOSYS;
 
@@ -227,7 +227,7 @@ int dfs_file_unlink(const char *path)
 		goto __exit;
 	}
 
-	if (fs->ops->unlink != RT_NULL) 
+	if (fs->ops->unlink != RT_NULL)
 	{
 		if (dfs_subdir(fs->path, fullpath) == RT_NULL)
 			result = fs->ops->unlink(fs, "/");
@@ -243,7 +243,7 @@ __exit:
 
 /**
  * this function will write some specified length data to file system.
- * 
+ *
  * @param fd the file descriptor.
  * @param buf the data buffer to be written.
  * @param len the data buffer length
@@ -333,7 +333,8 @@ int dfs_file_stat(const char *path, struct stat *buf)
 		return -DFS_STATUS_ENOENT;
 	}
 
-	if (fullpath[0] == '/' && fullpath[1] == '\0')
+	if ((fullpath[0] == '/' && fullpath[1] == '\0') ||
+		(dfs_subdir(fs->path, fullpath) == RT_NULL))
 	{
 		/* it's the root directory */
 		buf->st_dev   = 0;
@@ -351,20 +352,18 @@ int dfs_file_stat(const char *path, struct stat *buf)
 
 		return DFS_STATUS_OK;
 	}
-	
-	/* get the real file path */
-	
-	if (fs->ops->stat == RT_NULL)
+	else
 	{
-		rt_free(fullpath);
-		dfs_log(DFS_DEBUG_ERROR, ("the filesystem didn't implement this function"));
-		return -DFS_STATUS_ENOSYS;
-	}
+		if (fs->ops->stat == RT_NULL)
+		{
+			rt_free(fullpath);
+			dfs_log(DFS_DEBUG_ERROR, ("the filesystem didn't implement this function"));
+			return -DFS_STATUS_ENOSYS;
+		}
 
-	if (dfs_subdir(fs->path, fullpath) == RT_NULL)
-		result = fs->ops->stat(fs, "/", buf);
-	else
+		/* get the real file path and get file stat */
 		result = fs->ops->stat(fs, dfs_subdir(fs->path, fullpath), buf);
+	}
 
 	rt_free(fullpath);
 
@@ -470,7 +469,7 @@ void ls(const char* pathname)
 		{
 			rt_memset(&dirent, 0, sizeof(struct dirent));
 			length = dfs_file_getdents(&fd, &dirent, sizeof(struct dirent));
-			if ( length > 0 ) 
+			if ( length > 0 )
 			{
 				rt_memset(&stat, 0, sizeof(struct stat));
 
@@ -519,13 +518,13 @@ void cat(const char* filename)
 {
 	rt_uint32_t length;
 	char buffer[81];
-	
+
 	if (dfs_file_open(&fd, filename, DFS_O_RDONLY) < 0)
 	{
 		rt_kprintf("Open %s failed\n", filename);
 		return;
 	}
-	
+
 	do
 	{
 		rt_memset(buffer, 0, sizeof(buffer));
@@ -535,7 +534,7 @@ void cat(const char* filename)
 			rt_kprintf("%s", buffer);
 		}
 	}while (length > 0);
-	
+
 	dfs_file_close(&fd);
 }
 FINSH_FUNCTION_EXPORT(cat, print file)
@@ -553,7 +552,7 @@ void copy(const char* src, const char* dst)
 		rt_kprintf("out of memory\n");
 		return;
 	}
-	
+
 	if (dfs_file_open(&src_fd, src, DFS_O_RDONLY) < 0)
 	{
 		rt_free(block_ptr);

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

@@ -71,7 +71,7 @@ err:
  *
  * @param path the specified path string.
  *
- * @return the found file system or NULL if no file system mounted on 
+ * @return the found file system or NULL if no file system mounted on
  * specified path
  */
 struct dfs_filesystem* dfs_filesystem_lookup(const char *path)
@@ -96,8 +96,12 @@ struct dfs_filesystem* dfs_filesystem_lookup(const char *path)
 		}
 
         if ((filesystem_table[index].ops != RT_NULL) &&
-                strncmp(filesystem_table[index].path, path, fspath) == 0)
+            (strncmp(filesystem_table[index].path, path, fspath) == 0))
         {
+        	/* check next path separator */
+        	if ( fspath > 1 && (strlen(path) > fspath) &&
+        		(path[fspath] != '/')) continue;
+
             fs = &filesystem_table[index];
             prefixlen = fspath;
         }