diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index facad6db64510d72350f80e0d64cff59d0297e6a..5888b8ad0b685f4aa5abbac8bd1877ba48252ce2 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -74,7 +74,10 @@ void dfs_lock() rt_err_t result; result = rt_mutex_take(&fslock, RT_WAITING_FOREVER); - RT_ASSERT(result == RT_EOK); + if (result != RT_EOK) + { + RT_ASSERT(0); + } } /** @@ -350,6 +353,11 @@ up_one: } *dst = '\0'; + + /* remove '/' in the end of path if exist */ + dst --; + if ((dst != fullpath) && (*dst == '/')) *dst = '\0'; + return fullpath; } /*@}*/ diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 4deba547bea4d686acf94b0af42af086d35c38c4..e9b33f2ea5638b08c9d5935d0e32638043317007 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -444,14 +444,28 @@ void ls(const char* pathname) { struct stat stat; int length; - char* fullpath; + char *fullpath, *path; + + fullpath = RT_NULL; + if (pathname == RT_NULL) + { +#ifdef DFS_USING_WORKDIR + /* open current working directory */ + path = rt_strdup(working_directory); +#else + path = rt_strdup("/"); +#endif + if (path == RT_NULL) return ; /* out of memory */ + } + else + { + path = (char*)pathname; + } - fullpath = rt_malloc(DFS_PATH_MAX + 1); - if (fullpath == RT_NULL) return; /* out of memory */ /* list directory */ - if ( dfs_file_open(&fd, pathname, DFS_O_DIRECTORY) == 0 ) + if ( dfs_file_open(&fd, path, DFS_O_DIRECTORY) == 0 ) { - rt_kprintf("Directory %s:\n", pathname); + rt_kprintf("Directory %s:\n", path); do { rt_memset(&dirent, 0, sizeof(struct dirent)); @@ -461,25 +475,24 @@ void ls(const char* pathname) rt_memset(&stat, 0, sizeof(struct stat)); /* build full path for each file */ - if (pathname[strlen(pathname) - 1] != '/') - rt_snprintf(fullpath, DFS_PATH_MAX + 1, "%s%c%s", pathname, '/', dirent.d_name); - else - rt_snprintf(fullpath, DFS_PATH_MAX + 1, "%s%s", pathname, dirent.d_name); + fullpath = dfs_normalize_path(path, dirent.d_name); + if (fullpath == RT_NULL) break; if (dfs_file_stat(fullpath, &stat) == 0) { + rt_kprintf("%-20s", dirent.d_name); if ( DFS_S_ISDIR(stat.st_mode)) { - rt_kprintf("%s\t\t