|
|
@@ -41,23 +41,19 @@ int open(const char *file, int flags, ...)
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
|
|
|
result = dfs_file_open(d, file, flags);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
/* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
- fd_put(d);
|
|
|
+ dfs_fd_release(d);
|
|
|
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- /* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return fd;
|
|
|
}
|
|
|
RTM_EXPORT(open);
|
|
|
@@ -120,7 +116,7 @@ int read(int fd, void *buf, size_t len)
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
/* get the fd */
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -131,15 +127,11 @@ int read(int fd, void *buf, size_t len)
|
|
|
result = dfs_file_read(d, buf, len);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- /* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
RTM_EXPORT(read);
|
|
|
@@ -164,7 +156,7 @@ int write(int fd, const void *buf, size_t len)
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
/* get the fd */
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -175,15 +167,11 @@ int write(int fd, const void *buf, size_t len)
|
|
|
result = dfs_file_write(d, buf, len);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- /* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
RTM_EXPORT(write);
|
|
|
@@ -203,7 +191,7 @@ off_t lseek(int fd, off_t offset, int whence)
|
|
|
int result;
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -225,7 +213,6 @@ off_t lseek(int fd, off_t offset, int whence)
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(-EINVAL);
|
|
|
|
|
|
return -1;
|
|
|
@@ -233,7 +220,6 @@ off_t lseek(int fd, off_t offset, int whence)
|
|
|
|
|
|
if (offset < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(-EINVAL);
|
|
|
|
|
|
return -1;
|
|
|
@@ -241,15 +227,11 @@ off_t lseek(int fd, off_t offset, int whence)
|
|
|
result = dfs_file_lseek(d, offset);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- /* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return offset;
|
|
|
}
|
|
|
RTM_EXPORT(lseek);
|
|
|
@@ -343,7 +325,7 @@ int fstat(int fildes, struct stat *buf)
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
/* get the fd */
|
|
|
- d = fd_get(fildes);
|
|
|
+ d = dfs_fd_get(fildes);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -365,8 +347,6 @@ int fstat(int fildes, struct stat *buf)
|
|
|
buf->st_size = d->size;
|
|
|
buf->st_mtime = 0;
|
|
|
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
RTM_EXPORT(fstat);
|
|
|
@@ -388,7 +368,7 @@ int fsync(int fildes)
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
/* get the fd */
|
|
|
- d = fd_get(fildes);
|
|
|
+ d = dfs_fd_get(fildes);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -397,7 +377,6 @@ int fsync(int fildes)
|
|
|
|
|
|
ret = dfs_file_flush(d);
|
|
|
|
|
|
- fd_put(d);
|
|
|
return ret;
|
|
|
}
|
|
|
RTM_EXPORT(fsync);
|
|
|
@@ -420,7 +399,7 @@ int fcntl(int fildes, int cmd, ...)
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
/* get the fd */
|
|
|
- d = fd_get(fildes);
|
|
|
+ d = dfs_fd_get(fildes);
|
|
|
if (d)
|
|
|
{
|
|
|
void *arg;
|
|
|
@@ -431,7 +410,6 @@ int fcntl(int fildes, int cmd, ...)
|
|
|
va_end(ap);
|
|
|
|
|
|
ret = dfs_file_ioctl(d, cmd, arg);
|
|
|
- fd_put(d);
|
|
|
}
|
|
|
else ret = -EBADF;
|
|
|
|
|
|
@@ -486,7 +464,7 @@ int ftruncate(int fd, off_t length)
|
|
|
int result;
|
|
|
struct dfs_fd *d;
|
|
|
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
if (d == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -496,7 +474,6 @@ int ftruncate(int fd, off_t length)
|
|
|
|
|
|
if (length < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(-EINVAL);
|
|
|
|
|
|
return -1;
|
|
|
@@ -504,15 +481,11 @@ int ftruncate(int fd, off_t length)
|
|
|
result = dfs_file_ftruncate(d, length);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- /* release the ref-count of fd */
|
|
|
- fd_put(d);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
RTM_EXPORT(ftruncate);
|
|
|
@@ -564,22 +537,20 @@ int mkdir(const char *path, mode_t mode)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
|
|
|
result = dfs_file_open(d, path, O_DIRECTORY | O_CREAT);
|
|
|
|
|
|
if (result < 0)
|
|
|
{
|
|
|
- fd_put(d);
|
|
|
- fd_put(d);
|
|
|
+ dfs_fd_release(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
dfs_file_close(d);
|
|
|
- fd_put(d);
|
|
|
- fd_put(d);
|
|
|
+ dfs_fd_release(d);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -636,7 +607,7 @@ DIR *opendir(const char *name)
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
- d = fd_get(fd);
|
|
|
+ d = dfs_fd_get(fd);
|
|
|
|
|
|
result = dfs_file_open(d, name, O_RDONLY | O_DIRECTORY);
|
|
|
if (result >= 0)
|
|
|
@@ -646,7 +617,7 @@ DIR *opendir(const char *name)
|
|
|
if (t == NULL)
|
|
|
{
|
|
|
dfs_file_close(d);
|
|
|
- fd_put(d);
|
|
|
+ dfs_fd_release(d);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -654,14 +625,12 @@ DIR *opendir(const char *name)
|
|
|
|
|
|
t->fd = fd;
|
|
|
}
|
|
|
- fd_put(d);
|
|
|
|
|
|
return t;
|
|
|
}
|
|
|
|
|
|
/* open failed */
|
|
|
- fd_put(d);
|
|
|
- fd_put(d);
|
|
|
+ dfs_fd_release(d);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return NULL;
|
|
|
@@ -682,7 +651,7 @@ struct dirent *readdir(DIR *d)
|
|
|
int result;
|
|
|
struct dfs_fd *fd;
|
|
|
|
|
|
- fd = fd_get(d->fd);
|
|
|
+ fd = dfs_fd_get(d->fd);
|
|
|
if (fd == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -704,7 +673,6 @@ struct dirent *readdir(DIR *d)
|
|
|
sizeof(d->buf) - 1);
|
|
|
if (result <= 0)
|
|
|
{
|
|
|
- fd_put(fd);
|
|
|
rt_set_errno(result);
|
|
|
|
|
|
return NULL;
|
|
|
@@ -714,8 +682,6 @@ struct dirent *readdir(DIR *d)
|
|
|
d->cur = 0; /* current entry index */
|
|
|
}
|
|
|
|
|
|
- fd_put(fd);
|
|
|
-
|
|
|
return (struct dirent *)(d->buf + d->cur);
|
|
|
}
|
|
|
RTM_EXPORT(readdir);
|
|
|
@@ -733,7 +699,7 @@ long telldir(DIR *d)
|
|
|
struct dfs_fd *fd;
|
|
|
long result;
|
|
|
|
|
|
- fd = fd_get(d->fd);
|
|
|
+ fd = dfs_fd_get(d->fd);
|
|
|
if (fd == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -742,7 +708,6 @@ long telldir(DIR *d)
|
|
|
}
|
|
|
|
|
|
result = fd->pos - d->num + d->cur;
|
|
|
- fd_put(fd);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -759,7 +724,7 @@ void seekdir(DIR *d, off_t offset)
|
|
|
{
|
|
|
struct dfs_fd *fd;
|
|
|
|
|
|
- fd = fd_get(d->fd);
|
|
|
+ fd = dfs_fd_get(d->fd);
|
|
|
if (fd == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -770,7 +735,6 @@ void seekdir(DIR *d, off_t offset)
|
|
|
/* seek to the offset position of directory */
|
|
|
if (dfs_file_lseek(fd, offset) >= 0)
|
|
|
d->num = d->cur = 0;
|
|
|
- fd_put(fd);
|
|
|
}
|
|
|
RTM_EXPORT(seekdir);
|
|
|
|
|
|
@@ -784,7 +748,7 @@ void rewinddir(DIR *d)
|
|
|
{
|
|
|
struct dfs_fd *fd;
|
|
|
|
|
|
- fd = fd_get(d->fd);
|
|
|
+ fd = dfs_fd_get(d->fd);
|
|
|
if (fd == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -795,7 +759,6 @@ void rewinddir(DIR *d)
|
|
|
/* seek to the beginning of directory */
|
|
|
if (dfs_file_lseek(fd, 0) >= 0)
|
|
|
d->num = d->cur = 0;
|
|
|
- fd_put(fd);
|
|
|
}
|
|
|
RTM_EXPORT(rewinddir);
|
|
|
|
|
|
@@ -812,7 +775,7 @@ int closedir(DIR *d)
|
|
|
int result;
|
|
|
struct dfs_fd *fd;
|
|
|
|
|
|
- fd = fd_get(d->fd);
|
|
|
+ fd = dfs_fd_get(d->fd);
|
|
|
if (fd == NULL)
|
|
|
{
|
|
|
rt_set_errno(-EBADF);
|
|
|
@@ -821,9 +784,8 @@ int closedir(DIR *d)
|
|
|
}
|
|
|
|
|
|
result = dfs_file_close(fd);
|
|
|
- fd_put(fd);
|
|
|
+ dfs_fd_release(fd);
|
|
|
|
|
|
- fd_put(fd);
|
|
|
rt_free(d);
|
|
|
|
|
|
if (result < 0)
|