提交 94d413a7 编写于 作者: B bernard.xiong@gmail.com

merge 1.0.2 modification.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2194 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 4455768b
...@@ -142,10 +142,10 @@ struct dfs_fd *fd_get(int fd) ...@@ -142,10 +142,10 @@ struct dfs_fd *fd_get(int fd)
struct dfs_fd *d; struct dfs_fd *d;
#ifdef DFS_USING_STDIO #ifdef DFS_USING_STDIO
if (fd < 3 || fd > DFS_FD_MAX + 3) if (fd < 3 || fd >= DFS_FD_MAX + 3)
return RT_NULL; return RT_NULL;
#else #else
if (fd < 0 || fd > DFS_FD_MAX) if (fd < 0 || fd >= DFS_FD_MAX)
return RT_NULL; return RT_NULL;
#endif #endif
...@@ -166,6 +166,8 @@ struct dfs_fd *fd_get(int fd) ...@@ -166,6 +166,8 @@ struct dfs_fd *fd_get(int fd)
*/ */
void fd_put(struct dfs_fd *fd) void fd_put(struct dfs_fd *fd)
{ {
RT_ASSERT(fd != RT_NULL);
dfs_lock(); dfs_lock();
fd->ref_count --; fd->ref_count --;
......
...@@ -60,7 +60,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags) ...@@ -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)); dfs_log(DFS_DEBUG_INFO, ("open in filesystem:%s", fs->ops->name));
fd->fs = fs; fd->fs = fs;
/* initilize the fd item */ /* initialize the fd item */
fd->type = FT_REGULAR; fd->type = FT_REGULAR;
fd->flags = flags; fd->flags = flags;
fd->size = 0; fd->size = 0;
......
...@@ -38,7 +38,10 @@ int open(const char *file, int flags, int mode) ...@@ -38,7 +38,10 @@ int open(const char *file, int flags, int mode)
/* allocate a fd */ /* allocate a fd */
fd = fd_new(); fd = fd_new();
if (fd < 0) if (fd < 0)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1; return -1;
}
d = fd_get(fd); d = fd_get(fd);
result = dfs_file_open(d, file, flags); result = dfs_file_open(d, file, flags);
...@@ -74,7 +77,7 @@ int close(int fd) ...@@ -74,7 +77,7 @@ int close(int fd)
d = fd_get(fd); d = fd_get(fd);
if (d == RT_NULL) if (d == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -110,7 +113,7 @@ int read(int fd, void *buf, size_t len) ...@@ -110,7 +113,7 @@ int read(int fd, void *buf, size_t len)
d = fd_get(fd); d = fd_get(fd);
if (d == RT_NULL) if (d == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -147,7 +150,7 @@ int write(int fd, const void *buf, size_t len) ...@@ -147,7 +150,7 @@ int write(int fd, const void *buf, size_t len)
d = fd_get(fd); d = fd_get(fd);
if (d == RT_NULL) if (d == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -183,7 +186,7 @@ off_t lseek(int fd, off_t offset, int whence) ...@@ -183,7 +186,7 @@ off_t lseek(int fd, off_t offset, int whence)
d = fd_get(fd); d = fd_get(fd);
if (d == RT_NULL) if (d == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -304,7 +307,7 @@ int fstat(int fildes, struct stat *buf) ...@@ -304,7 +307,7 @@ int fstat(int fildes, struct stat *buf)
d = fd_get(fildes); d = fd_get(fildes);
if (d == RT_NULL) if (d == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -368,7 +371,7 @@ int mkdir(const char *path, mode_t mode) ...@@ -368,7 +371,7 @@ int mkdir(const char *path, mode_t mode)
fd = fd_new(); fd = fd_new();
if (fd == -1) if (fd == -1)
{ {
rt_kprintf("no fd\n"); rt_set_errno(-DFS_STATUS_ENOMEM);
return -1; return -1;
} }
...@@ -432,7 +435,7 @@ DIR *opendir(const char *name) ...@@ -432,7 +435,7 @@ DIR *opendir(const char *name)
fd = fd_new(); fd = fd_new();
if (fd == -1) if (fd == -1)
{ {
rt_kprintf("no fd\n"); rt_set_errno(-DFS_STATUS_ENOMEM);
return RT_NULL; return RT_NULL;
} }
d = fd_get(fd); d = fd_get(fd);
...@@ -481,7 +484,7 @@ struct dirent *readdir(DIR *d) ...@@ -481,7 +484,7 @@ struct dirent *readdir(DIR *d)
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (fd == RT_NULL) if (fd == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return RT_NULL; return RT_NULL;
} }
...@@ -521,7 +524,7 @@ long telldir(DIR *d) ...@@ -521,7 +524,7 @@ long telldir(DIR *d)
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (fd == RT_NULL) if (fd == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return 0; return 0;
} }
...@@ -545,7 +548,7 @@ void seekdir(DIR *d, off_t offset) ...@@ -545,7 +548,7 @@ void seekdir(DIR *d, off_t offset)
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (fd == RT_NULL) if (fd == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return ; return ;
} }
...@@ -567,7 +570,7 @@ void rewinddir(DIR *d) ...@@ -567,7 +570,7 @@ void rewinddir(DIR *d)
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (fd == RT_NULL) if (fd == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return ; return ;
} }
...@@ -593,7 +596,7 @@ int closedir(DIR *d) ...@@ -593,7 +596,7 @@ int closedir(DIR *d)
fd = fd_get(d->fd); fd = fd_get(d->fd);
if (fd == RT_NULL) if (fd == RT_NULL)
{ {
rt_set_errno(-RT_ERROR); rt_set_errno(-DFS_STATUS_EBADF);
return -1; return -1;
} }
...@@ -633,11 +636,17 @@ int chdir(const char *path) ...@@ -633,11 +636,17 @@ int chdir(const char *path)
} }
if (rt_strlen(path) > DFS_PATH_MAX) if (rt_strlen(path) > DFS_PATH_MAX)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; return -1;
}
fullpath = dfs_normalize_path(NULL, path); fullpath = dfs_normalize_path(NULL, path);
if (fullpath == RT_NULL) if (fullpath == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; /* build path failed */ return -1; /* build path failed */
}
dfs_lock(); dfs_lock();
d = opendir(fullpath); d = opendir(fullpath);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册