elm chan's FAT is available.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@141 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-10-26 23:10:52 +00:00
parent 5f878bb6a2
commit 0cab7ce3bc
3 changed files with 27 additions and 10 deletions

View File

@ -265,8 +265,6 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t c
rt_uint32_t index; rt_uint32_t index;
struct dfs_dirent* d; struct dfs_dirent* d;
if (file->type != FT_DIRECTORY) return -DFS_STATUS_EBADF;
dir = (DIR*)(file->data); dir = (DIR*)(file->data);
RT_ASSERT(dir != RT_NULL); RT_ASSERT(dir != RT_NULL);
@ -274,6 +272,12 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t c
count = (count / sizeof(struct dfs_dirent)) * sizeof(struct dfs_dirent); count = (count / sizeof(struct dfs_dirent)) * sizeof(struct dfs_dirent);
if ( count == 0 ) return -DFS_STATUS_EINVAL; if ( count == 0 ) return -DFS_STATUS_EINVAL;
#if _USE_LFN
/* allocate long file name */
fno.lfname = rt_malloc(256);
fno.lfsize = 256;
#endif
index = 0; index = 0;
while (1) while (1)
{ {
@ -294,15 +298,19 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t c
if (fno.fattrib & AM_DIR) d->d_type &= DFS_DT_DIR; if (fno.fattrib & AM_DIR) d->d_type &= DFS_DT_DIR;
else d->d_type &= DFS_DT_REG; else d->d_type &= DFS_DT_REG;
d->d_namlen = strlen(fn) - 1; d->d_namlen = rt_strlen(fn) - 1;
d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent); d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent);
strcpy(d->d_name, fn); rt_strncpy(d->d_name, fn, rt_strlen(fn));
index ++; index ++;
if ( index * sizeof(struct dfs_dirent) >= count ) if ( index * sizeof(struct dfs_dirent) >= count )
break; break;
} }
#if _USE_LFN
rt_free(fno.lfname);
#endif
if (index == 0) if (index == 0)
return elm_result_to_dfs(result); return elm_result_to_dfs(result);
@ -330,6 +338,12 @@ int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *s
FILINFO file_info; FILINFO file_info;
FRESULT result; FRESULT result;
#if _USE_LFN
/* allocate long file name */
file_info.lfname = rt_malloc(256);
file_info.lfsize = 256;
#endif
result = f_stat(path, &file_info); result = f_stat(path, &file_info);
if (result == FR_OK) if (result == FR_OK)
{ {
@ -342,13 +356,17 @@ int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *s
st->st_blksize = 512; st->st_blksize = 512;
} }
#if _USE_LFN
rt_free(file_info.lfname);
#endif
return elm_result_to_dfs(result); return elm_result_to_dfs(result);
} }
static struct dfs_filesystem_operation dfs_elm; static struct dfs_filesystem_operation dfs_elm;
int elm_init(void) int elm_init(void)
{ {
rt_strncpy(dfs_elm.name, "elmfat", DFS_FS_NAME_MAX); rt_strncpy(dfs_elm.name, "elm", DFS_FS_NAME_MAX);
dfs_elm.mount = dfs_elm_mount; dfs_elm.mount = dfs_elm_mount;
dfs_elm.unmount = dfs_elm_unmount; dfs_elm.unmount = dfs_elm_unmount;

View File

@ -6,10 +6,7 @@
#include "../ff.h" #include "../ff.h"
#if _USE_LFN && _CODE_PAGE == 936
#if !_USE_LFN || _CODE_PAGE != 936
#error This file is not needed in current configuration.
#endif
static static
const WCHAR uni2oem[] = { const WCHAR uni2oem[] = {
@ -10971,3 +10968,5 @@ WCHAR ff_wtoupper ( /* Upper converted character */
return tbl_lower[i] ? tbl_upper[i] : chr; return tbl_lower[i] ? tbl_upper[i] : chr;
} }
#endif

View File

@ -327,7 +327,7 @@ int dfile_raw_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nby
struct dfs_filesystem* fs; struct dfs_filesystem* fs;
/* parameter check */ /* parameter check */
if (fd == RT_NULL || fd->type != FT_REGULAR) return -DFS_STATUS_EINVAL; if (fd == RT_NULL || fd->type != FT_DIRECTORY) return -DFS_STATUS_EINVAL;
fs = (struct dfs_filesystem*) fd->fs; fs = (struct dfs_filesystem*) fd->fs;
if (fs->ops->getdents != RT_NULL) return fs->ops->getdents(fd, dirp, nbytes); if (fs->ops->getdents != RT_NULL) return fs->ops->getdents(fd, dirp, nbytes);