fix readdir issue.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@147 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-11-03 23:57:29 +00:00
parent 6c27bf33ff
commit fee61e2c2a
2 changed files with 74 additions and 70 deletions

View File

@ -302,9 +302,9 @@ 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 = rt_strlen(fn) - 1; d->d_namlen = rt_strlen(fn);
d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent); d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent);
rt_strncpy(d->d_name, fn, rt_strlen(fn)); rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1);
index ++; index ++;
if ( index * sizeof(struct dfs_dirent) >= count ) if ( index * sizeof(struct dfs_dirent) >= count )

View File

@ -9,7 +9,7 @@
|------------------------------------------------------------------------------ |------------------------------------------------------------------------------
| Chang Logs: | Chang Logs:
| Date Author Notes | Date Author Notes
| 2009-05-27 Yi.qiu The first version. | 2009-05-27 Yi.qiu The first version.
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
#include <string.h> #include <string.h>
@ -20,10 +20,10 @@
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : open | Function : open
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -56,10 +56,10 @@ int open(const char *file, int flags, int mode)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : close | Function : close
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -73,7 +73,7 @@ int close(int d)
result = dfile_raw_close(fd); result = dfile_raw_close(fd);
fd_put(fd); fd_put(fd);
fd_put(fd); fd_put(fd);
if (result < 0) if (result < 0)
{ {
rt_set_errno(result); rt_set_errno(result);
@ -86,10 +86,10 @@ int close(int d)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : read | Function : read
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -97,7 +97,7 @@ int read(int fd, char *buf, int len)
{ {
int result; int result;
struct dfs_fd* d; struct dfs_fd* d;
/* get the fd */ /* get the fd */
d = fd_get(fd); d = fd_get(fd);
@ -106,7 +106,7 @@ int read(int fd, char *buf, int len)
{ {
rt_set_errno(result); rt_set_errno(result);
fd_put(d); fd_put(d);
return -1; return -1;
} }
@ -119,10 +119,10 @@ int read(int fd, char *buf, int len)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : write | Function : write
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -139,7 +139,7 @@ int write(int fd, char *buf, int len)
{ {
rt_set_errno(result); rt_set_errno(result);
fd_put(d); fd_put(d);
return -1; return -1;
} }
@ -152,10 +152,10 @@ int write(int fd, char *buf, int len)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : lseek | Function : lseek
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -197,10 +197,10 @@ int lseek(int fd, int offset, int dir)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : rename | Function : rename
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -221,10 +221,10 @@ int rename(const char* old, const char* new )
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : unlink | Function : unlink
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -245,10 +245,10 @@ int unlink(const char *pathname)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : stat | Function : stat
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -269,10 +269,10 @@ int stat(const char *file, struct dfs_stat *buf)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : mkdir | Function : mkdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -284,7 +284,7 @@ int mkdir (const char *path, rt_uint16_t mode)
fd = fd_new(); fd = fd_new();
d = fd_get(fd); d = fd_get(fd);
result = dfile_raw_open(d, path, DFS_O_DIRECTORY | DFS_O_CREAT); result = dfile_raw_open(d, path, DFS_O_DIRECTORY | DFS_O_CREAT);
fd_put(d); fd_put(d);
fd_put(d); fd_put(d);
@ -302,10 +302,10 @@ int mkdir (const char *path, rt_uint16_t mode)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : rmdir | Function : rmdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -327,10 +327,10 @@ int rmdir(const char *pathname)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : opendir | Function : opendir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -356,7 +356,11 @@ DIR* opendir(const char* name)
dfile_raw_close(d); dfile_raw_close(d);
fd_put(d); fd_put(d);
} }
else t->fd = fd; else
{
rt_memset(t, 0, sizeof(DIR));
t->fd = fd;
}
fd_put(d); fd_put(d);
return t; return t;
} }
@ -373,10 +377,10 @@ DIR* opendir(const char* name)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : readdir | Function : readdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -384,7 +388,7 @@ struct dfs_dirent* readdir(DIR *d)
{ {
int result; int result;
struct dfs_fd* fd; struct dfs_fd* fd;
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (!d->num || (d->cur += ((struct dfs_dirent*)(d->buf + d->cur))->d_reclen) >= d->num) if (!d->num || (d->cur += ((struct dfs_dirent*)(d->buf + d->cur))->d_reclen) >= d->num)
@ -410,10 +414,10 @@ struct dfs_dirent* readdir(DIR *d)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : telldir | Function : telldir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -433,17 +437,17 @@ rt_off_t telldir(DIR *d)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : seekdir | Function : seekdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
void seekdir(DIR *d, rt_off_t offset) void seekdir(DIR *d, rt_off_t offset)
{ {
struct dfs_fd* fd; struct dfs_fd* fd;
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (dfile_raw_lseek(fd, offset) >= 0) d->num = d->cur = 0; if (dfile_raw_lseek(fd, offset) >= 0) d->num = d->cur = 0;
fd_put(fd); fd_put(fd);
@ -453,17 +457,17 @@ void seekdir(DIR *d, rt_off_t offset)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : rewinddir | Function : rewinddir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
void rewinddir(DIR *d) void rewinddir(DIR *d)
{ {
struct dfs_fd* fd; struct dfs_fd* fd;
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (dfile_raw_lseek(fd, 0) >= 0) d->num = d->cur = 0; if (dfile_raw_lseek(fd, 0) >= 0) d->num = d->cur = 0;
fd_put(fd); fd_put(fd);
@ -473,10 +477,10 @@ void rewinddir(DIR *d)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : closedir | Function : closedir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
@ -504,17 +508,17 @@ int closedir(DIR* d)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : chdir | Function : chdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
int chdir(const char *path) int chdir(const char *path)
{ {
char* fullpath, full_path[DFS_PATH_MAX + 1]; char* fullpath, full_path[DFS_PATH_MAX + 1];
if(path == RT_NULL || rt_strlen(path) > DFS_PATH_MAX) if(path == RT_NULL || rt_strlen(path) > DFS_PATH_MAX)
return -1; return -1;
@ -528,7 +532,7 @@ int chdir(const char *path)
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
strcpy(working_directory, fullpath); strcpy(working_directory, fullpath);
dfs_unlock(); dfs_unlock();
#endif #endif
} }
else else
{ {
@ -537,9 +541,9 @@ int chdir(const char *path)
rt_strncpy(working_directory, path, strlen(path) + 1); rt_strncpy(working_directory, path, strlen(path) + 1);
working_directory[strlen(path)] = '\0'; working_directory[strlen(path)] = '\0';
dfs_unlock(); dfs_unlock();
#endif #endif
} }
return 0; return 0;
} }
@ -547,10 +551,10 @@ int chdir(const char *path)
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Function : chdir | Function : chdir
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
| Description : | Description :
| |
| Parameters : | Parameters :
| Returns : | Returns :
| |
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */