diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 28dcea0868c20e32412c5df5c2129b0715ba8569..7d0d061b9a770864e31d4678214f51d407882832 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -228,6 +228,9 @@ const char* dfs_subdir(const char* directory, const char* filename) { const char* dir; + if (strlen(directory) == strlen(filename)) /* it's a same path */ + return RT_NULL; + dir = filename + strlen(directory); if ((*dir != '/') && (dir != filename)) { diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 8450fee03c87f19553d717b412554b974961df2f..f09a7c4a1cef88171a4fcc98f413925f6daf9e22 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -61,7 +61,10 @@ int dfs_file_open(struct dfs_fd* fd, const char *path, int flags) fd->size = 0; fd->pos = 0; - fd->path = rt_strdup(dfs_subdir(fs->path, fullpath)); + if (dfs_subdir(fs->path, fullpath) == RT_NULL) + fd->path = rt_strdup("/"); + else + fd->path = rt_strdup(dfs_subdir(fs->path, fullpath)); rt_free(fullpath); dfs_log(DFS_DEBUG_INFO, ("actul file path: %s\n", fd->path)); @@ -224,7 +227,12 @@ int dfs_file_unlink(const char *path) } if (fs->ops->unlink != RT_NULL) - result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath)); + { + if (dfs_subdir(fs->path, fullpath) == RT_NULL) + result = fs->ops->unlink(fs, "/"); + else + result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath)); + } else result = -DFS_STATUS_ENOSYS; __exit: