diff options
| -rw-r--r-- | components/dfs/src/dfs.c | 6 | ||||
| -rw-r--r-- | components/dfs/src/dfs_file.c | 2 | ||||
| -rw-r--r-- | components/dfs/src/dfs_posix.c | 33 |
3 files changed, 26 insertions, 15 deletions
diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 7ac596a2a0..3db6e51694 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -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 --; diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 3c9897fc77..a9e4241ac2 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -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; diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index f9608e4ac5..ea6ba19810 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -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);
|
