merge 1.0.2 modification.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2194 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2012-06-29 06:03:11 +00:00
parent 4455768b92
commit 94d413a7a7
3 changed files with 26 additions and 15 deletions

View File

@ -142,10 +142,10 @@ struct dfs_fd *fd_get(int fd)
struct dfs_fd *d;
#ifdef DFS_USING_STDIO
if (fd < 3 || fd > DFS_FD_MAX + 3)
if (fd < 3 || fd >= DFS_FD_MAX + 3)
return RT_NULL;
#else
if (fd < 0 || fd > DFS_FD_MAX)
if (fd < 0 || fd >= DFS_FD_MAX)
return RT_NULL;
#endif
@ -166,6 +166,8 @@ struct dfs_fd *fd_get(int fd)
*/
void fd_put(struct dfs_fd *fd)
{
RT_ASSERT(fd != RT_NULL);
dfs_lock();
fd->ref_count --;

View File

@ -60,7 +60,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
dfs_log(DFS_DEBUG_INFO, ("open in filesystem:%s", fs->ops->name));
fd->fs = fs;
/* initilize the fd item */
/* initialize the fd item */
fd->type = FT_REGULAR;
fd->flags = flags;
fd->size = 0;

View File

@ -38,7 +38,10 @@ int open(const char *file, int flags, int mode)
/* allocate a fd */
fd = fd_new();
if (fd < 0)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
d = fd_get(fd);
result = dfs_file_open(d, file, flags);
@ -74,7 +77,7 @@ int close(int fd)
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -110,7 +113,7 @@ int read(int fd, void *buf, size_t len)
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -147,7 +150,7 @@ int write(int fd, const void *buf, size_t len)
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -183,7 +186,7 @@ off_t lseek(int fd, off_t offset, int whence)
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -304,7 +307,7 @@ int fstat(int fildes, struct stat *buf)
d = fd_get(fildes);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -368,7 +371,7 @@ int mkdir(const char *path, mode_t mode)
fd = fd_new();
if (fd == -1)
{
rt_kprintf("no fd\n");
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
@ -432,7 +435,7 @@ DIR *opendir(const char *name)
fd = fd_new();
if (fd == -1)
{
rt_kprintf("no fd\n");
rt_set_errno(-DFS_STATUS_ENOMEM);
return RT_NULL;
}
d = fd_get(fd);
@ -481,7 +484,7 @@ struct dirent *readdir(DIR *d)
fd = fd_get(d->fd);
if (fd == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return RT_NULL;
}
@ -521,7 +524,7 @@ long telldir(DIR *d)
fd = fd_get(d->fd);
if (fd == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return 0;
}
@ -545,7 +548,7 @@ void seekdir(DIR *d, off_t offset)
fd = fd_get(d->fd);
if (fd == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return ;
}
@ -567,7 +570,7 @@ void rewinddir(DIR *d)
fd = fd_get(d->fd);
if (fd == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return ;
}
@ -593,7 +596,7 @@ int closedir(DIR *d)
fd = fd_get(d->fd);
if (fd == RT_NULL)
{
rt_set_errno(-RT_ERROR);
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
@ -633,11 +636,17 @@ int chdir(const char *path)
}
if (rt_strlen(path) > DFS_PATH_MAX)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
fullpath = dfs_normalize_path(NULL, path);
if (fullpath == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; /* build path failed */
}
dfs_lock();
d = opendir(fullpath);