fix the bug about directory in uffs

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2412 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
goprife@gmail.com 2012-11-14 15:53:54 +00:00
parent e578007856
commit 583bb26fb2
1 changed files with 34 additions and 7 deletions

View File

@ -427,19 +427,44 @@ static int dfs_uffs_flush(struct dfs_fd* file)
return 0;
}
int uffs_seekdir(uffs_DIR *dir, long offset)
{
int i = 0;
while(i < offset)
{
if (uffs_readdir(dir) == RT_NULL)
return -1;
i++;
}
return 0;
}
static int dfs_uffs_seek(struct dfs_fd* file,
rt_off_t offset)
{
int fd;
int result;
fd = (int)(file->data);
/* set offset as current offset */
result = uffs_seek(fd, offset, USEEK_SET);
if (result < 0)
if (file->type == FT_DIRECTORY)
{
uffs_rewinddir((uffs_DIR *)(file->data));
result = uffs_seekdir((uffs_DIR *)(file->data), offset/sizeof(struct dirent));
if (result >= 0)
{
file->pos = offset;
return offset;
}
}
else if (file->type == FT_REGULAR)
{
result = uffs_seek((int)(file->data), offset, USEEK_SET);
if (result >= 0)
return offset;
}
return uffs_result_to_dfs(uffs_get_error());
return result;
}
/* return the size of struct dirent*/
@ -519,6 +544,8 @@ static int dfs_uffs_getdents(
if (index == 0)
return uffs_result_to_dfs(uffs_get_error());
file->pos += index * sizeof(struct dirent);
return index * sizeof(struct dirent);
}