mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
fs/file: unify prefix about file_xxx api, like file_open, file_ioctl
old: fs_getfilep, fs_putfilep, fs_reffilep new: file_get, file_put, file_ref Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+5
-5
@@ -67,18 +67,18 @@ int file_dup(FAR struct file *filep, int minfd, int flags)
|
||||
return fd2;
|
||||
}
|
||||
|
||||
ret = fs_getfilep(fd2, &filep2);
|
||||
ret = file_get(fd2, &filep2);
|
||||
DEBUGASSERT(ret >= 0);
|
||||
|
||||
ret = file_dup3(filep, filep2, flags);
|
||||
|
||||
fs_putfilep(filep2);
|
||||
file_put(filep2);
|
||||
if (ret >= 0)
|
||||
{
|
||||
return fd2;
|
||||
}
|
||||
|
||||
fs_putfilep(filep2);
|
||||
file_put(filep2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ int dup(int fd)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
@@ -106,7 +106,7 @@ int dup(int fd)
|
||||
/* Let file_dup() do the real work */
|
||||
|
||||
ret = file_dup(filep, 0, 0);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
|
||||
+14
-14
@@ -144,7 +144,7 @@ static FAR epoll_head_t *epoll_head_from_fd(int fd, FAR struct file **filep)
|
||||
|
||||
/* Get file pointer by file descriptor */
|
||||
|
||||
ret = fs_getfilep(fd, filep);
|
||||
ret = file_get(fd, filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
@@ -155,7 +155,7 @@ static FAR epoll_head_t *epoll_head_from_fd(int fd, FAR struct file **filep)
|
||||
|
||||
if ((*filep)->f_inode->u.i_ops != &g_epoll_ops)
|
||||
{
|
||||
fs_putfilep(*filep);
|
||||
file_put(*filep);
|
||||
set_errno(EBADF);
|
||||
return NULL;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ static int epoll_do_close(FAR struct file *filep)
|
||||
list_for_every_entry(&eph->setup, epn, epoll_node_t, node)
|
||||
{
|
||||
file_poll(epn->filep, &epn->pfd, false);
|
||||
fs_putfilep(epn->filep);
|
||||
file_put(epn->filep);
|
||||
}
|
||||
|
||||
list_for_every_entry_safe(&eph->extend, epn, tmp, epoll_node_t, node)
|
||||
@@ -568,7 +568,7 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
epn->pfd.cb = epoll_default_cb;
|
||||
epn->pfd.revents = 0;
|
||||
|
||||
ret = fs_getfilep(fd, &epn->filep);
|
||||
ret = file_get(fd, &epn->filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
list_add_tail(&eph->free, &epn->node);
|
||||
@@ -578,7 +578,7 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
ret = file_poll(epn->filep, &epn->pfd, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
fs_putfilep(epn->filep);
|
||||
file_put(epn->filep);
|
||||
list_add_tail(&eph->free, &epn->node);
|
||||
goto err;
|
||||
}
|
||||
@@ -593,7 +593,7 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
if (epn->pfd.fd == fd)
|
||||
{
|
||||
file_poll(epn->filep, &epn->pfd, false);
|
||||
fs_putfilep(epn->filep);
|
||||
file_put(epn->filep);
|
||||
list_delete(&epn->node);
|
||||
list_add_tail(&eph->free, &epn->node);
|
||||
goto out;
|
||||
@@ -604,7 +604,7 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
{
|
||||
if (epn->pfd.fd == fd)
|
||||
{
|
||||
fs_putfilep(epn->filep);
|
||||
file_put(epn->filep);
|
||||
list_delete(&epn->node);
|
||||
list_add_tail(&eph->free, &epn->node);
|
||||
goto out;
|
||||
@@ -615,7 +615,7 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
{
|
||||
if (epn->pfd.fd == fd)
|
||||
{
|
||||
fs_putfilep(epn->filep);
|
||||
file_put(epn->filep);
|
||||
list_delete(&epn->node);
|
||||
list_add_tail(&eph->free, &epn->node);
|
||||
goto out;
|
||||
@@ -705,12 +705,12 @@ int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
|
||||
|
||||
out:
|
||||
nxmutex_unlock(&eph->lock);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return OK;
|
||||
err:
|
||||
nxmutex_unlock(&eph->lock);
|
||||
err_without_lock:
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
@@ -773,11 +773,11 @@ retry:
|
||||
ret = num;
|
||||
}
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return ret;
|
||||
|
||||
err:
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
set_errno(-ret);
|
||||
out:
|
||||
ferr("epoll wait failed:%d, timeout:%d\n", errno, timeout);
|
||||
@@ -845,11 +845,11 @@ retry:
|
||||
ret = num;
|
||||
}
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return ret;
|
||||
|
||||
err:
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
set_errno(-ret);
|
||||
out:
|
||||
ferr("epoll wait failed:%d, timeout:%d\n", errno, timeout);
|
||||
|
||||
+3
-3
@@ -50,10 +50,10 @@ static int fchstat(int fd, FAR struct stat *buf, int flags)
|
||||
int ret;
|
||||
|
||||
/* First, get the file structure. Note that on failure,
|
||||
* fs_getfilep() will return the errno.
|
||||
* file_get() will return the errno.
|
||||
*/
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -62,7 +62,7 @@ static int fchstat(int fd, FAR struct stat *buf, int flags)
|
||||
/* Perform the fchstat operation */
|
||||
|
||||
ret = file_fchstat(filep, buf, flags);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Successfully fchstat'ed the file */
|
||||
|
||||
+2
-2
@@ -349,7 +349,7 @@ int fcntl(int fd, int cmd, ...)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Let file_vfcntl() do the real work. The errno is not set on
|
||||
@@ -357,7 +357,7 @@ int fcntl(int fd, int cmd, ...)
|
||||
*/
|
||||
|
||||
ret = file_vfcntl(filep, cmd, ap);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
|
||||
+3
-3
@@ -231,16 +231,16 @@ int nx_fstat(int fd, FAR struct stat *buf)
|
||||
int ret;
|
||||
|
||||
/* First, get the file structure. Note that on failure,
|
||||
* fs_getfilep() will return the errno.
|
||||
* file_get() will return the errno.
|
||||
*/
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Perform the fstat operation */
|
||||
|
||||
ret = file_fstat(filep, buf);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
+3
-3
@@ -67,10 +67,10 @@ int fstatfs(int fd, FAR struct statfs *buf)
|
||||
DEBUGASSERT(buf != NULL);
|
||||
|
||||
/* First, get the file structure. Note that on failure,
|
||||
* fs_getfilep() will return the errno.
|
||||
* file_get() will return the errno.
|
||||
*/
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -113,7 +113,7 @@ int fstatfs(int fd, FAR struct statfs *buf)
|
||||
|
||||
/* Check if the fstat operation was successful */
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Successfully statfs'ed the file */
|
||||
|
||||
+2
-2
@@ -106,7 +106,7 @@ int fsync(int fd)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -115,7 +115,7 @@ int fsync(int fd)
|
||||
/* Perform the fsync operation */
|
||||
|
||||
ret = file_fsync(filep);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
|
||||
+2
-2
@@ -266,7 +266,7 @@ int ioctl(int fd, int req, ...)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
@@ -278,7 +278,7 @@ int ioctl(int fd, int req, ...)
|
||||
ret = file_vioctl(filep, req, ap);
|
||||
va_end(ap);
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
|
||||
+2
-2
@@ -127,7 +127,7 @@ off_t nx_seek(int fd, off_t offset, int whence)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@@ -136,7 +136,7 @@ off_t nx_seek(int fd, off_t offset, int whence)
|
||||
/* Then let file_seek do the real work */
|
||||
|
||||
ret = file_seek(filep, offset, whence);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -82,7 +82,7 @@ static inline void poll_teardown(FAR struct pollfd *fds, nfds_t nfds,
|
||||
FAR struct file *filep;
|
||||
int ret;
|
||||
|
||||
ret = fs_getfilep(fds[i].fd, &filep);
|
||||
ret = file_get(fds[i].fd, &filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = file_poll(filep, &fds[i], false);
|
||||
@@ -92,8 +92,8 @@ static inline void poll_teardown(FAR struct pollfd *fds, nfds_t nfds,
|
||||
* before the poll.
|
||||
*/
|
||||
|
||||
fs_putfilep(filep);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
@@ -163,7 +163,7 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds,
|
||||
FAR struct file *filep;
|
||||
int num = i;
|
||||
|
||||
ret = fs_getfilep(fds[i].fd, &filep);
|
||||
ret = file_get(fds[i].fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
num -= 1;
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = (ssize_t)fs_getfilep(fd, &filep);
|
||||
ret = (ssize_t)file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -143,7 +143,7 @@ ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset)
|
||||
/* Let file_pread do the real work */
|
||||
|
||||
ret = file_pread(filep, buf, nbytes, offset);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
|
||||
+2
-2
@@ -137,7 +137,7 @@ ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = (ssize_t)fs_getfilep(fd, &filep);
|
||||
ret = (ssize_t)file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -146,7 +146,7 @@ ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
|
||||
/* Let file_pwrite do the real work */
|
||||
|
||||
ret = file_pwrite(filep, buf, nbytes, offset);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
|
||||
+3
-3
@@ -293,17 +293,17 @@ ssize_t nx_readv(int fd, FAR const struct iovec *iov, int iovcnt)
|
||||
ssize_t ret;
|
||||
|
||||
/* First, get the file structure. Note that on failure,
|
||||
* fs_getfilep() will return the errno.
|
||||
* file_get() will return the errno.
|
||||
*/
|
||||
|
||||
ret = (ssize_t)fs_getfilep(fd, &filep);
|
||||
ret = (ssize_t)file_get(fd, &filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Then let file_readv do all of the work. */
|
||||
|
||||
ret = file_readv(filep, iov, iovcnt);
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -337,22 +337,22 @@ ssize_t sendfile(int outfd, int infd, FAR off_t *offset, size_t count)
|
||||
FAR struct file *infile;
|
||||
int ret;
|
||||
|
||||
ret = fs_getfilep(outfd, &outfile);
|
||||
ret = file_get(outfd, &outfile);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = fs_getfilep(infd, &infile);
|
||||
ret = file_get(infd, &infile);
|
||||
if (ret < 0)
|
||||
{
|
||||
fs_putfilep(outfile);
|
||||
file_put(outfile);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = file_sendfile(outfile, infile, offset, count);
|
||||
fs_putfilep(outfile);
|
||||
fs_putfilep(infile);
|
||||
file_put(outfile);
|
||||
file_put(infile);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
|
||||
@@ -364,7 +364,7 @@ int signalfd(int fd, FAR const sigset_t *mask, int flags)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fs_getfilep(fd, &filep) < 0)
|
||||
if (file_get(fd, &filep) < 0)
|
||||
{
|
||||
ret = EBADF;
|
||||
goto errout;
|
||||
@@ -372,7 +372,7 @@ int signalfd(int fd, FAR const sigset_t *mask, int flags)
|
||||
|
||||
if (filep->f_inode->u.i_ops != &g_signalfd_fileops)
|
||||
{
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ int signalfd(int fd, FAR const sigset_t *mask, int flags)
|
||||
|
||||
if (filep != NULL)
|
||||
{
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
return fd;
|
||||
|
||||
+2
-2
@@ -84,11 +84,11 @@ int syncfs(int fd)
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret == OK)
|
||||
{
|
||||
ret = file_syncfs(filep);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
leave_cancellation_point();
|
||||
|
||||
+7
-7
@@ -509,7 +509,7 @@ int timerfd_settime(int fd, int flags,
|
||||
|
||||
/* Get file pointer by file descriptor */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -557,7 +557,7 @@ int timerfd_settime(int fd, int flags,
|
||||
if (new_value->it_value.tv_sec <= 0 && new_value->it_value.tv_nsec <= 0)
|
||||
{
|
||||
leave_critical_section(intflags);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -607,11 +607,11 @@ int timerfd_settime(int fd, int flags,
|
||||
}
|
||||
|
||||
leave_critical_section(intflags);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return OK;
|
||||
|
||||
errout_with_filep:
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
errout:
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
@@ -634,7 +634,7 @@ int timerfd_gettime(int fd, FAR struct itimerspec *curr_value)
|
||||
|
||||
/* Get file pointer by file descriptor */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
@@ -642,7 +642,7 @@ int timerfd_gettime(int fd, FAR struct itimerspec *curr_value)
|
||||
|
||||
if (filep->f_inode->u.i_ops != &g_timerfd_fops)
|
||||
{
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ int timerfd_gettime(int fd, FAR struct itimerspec *curr_value)
|
||||
|
||||
clock_ticks2time(&curr_value->it_value, ticks);
|
||||
clock_ticks2time(&curr_value->it_interval, dev->delay);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
return OK;
|
||||
|
||||
errout:
|
||||
|
||||
@@ -170,7 +170,7 @@ int ftruncate(int fd, off_t length)
|
||||
|
||||
/* Get the file structure corresponding to the file descriptor. */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
ret = file_get(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Could no get file structure: %d\n", ret);
|
||||
@@ -180,7 +180,7 @@ int ftruncate(int fd, off_t length)
|
||||
/* Perform the truncate operation */
|
||||
|
||||
ret = file_truncate(filep, length);
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
|
||||
+3
-3
@@ -276,10 +276,10 @@ ssize_t nx_writev(int fd, FAR const struct iovec *iov, int iovcnt)
|
||||
ssize_t ret;
|
||||
|
||||
/* First, get the file structure.
|
||||
* Note that fs_getfilep() will return the errno on failure.
|
||||
* Note that file_get() will return the errno on failure.
|
||||
*/
|
||||
|
||||
ret = (ssize_t)fs_getfilep(fd, &filep);
|
||||
ret = (ssize_t)file_get(fd, &filep);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Perform the write operation using the file descriptor as an
|
||||
@@ -288,7 +288,7 @@ ssize_t nx_writev(int fd, FAR const struct iovec *iov, int iovcnt)
|
||||
|
||||
ret = file_writev(filep, iov, iovcnt);
|
||||
|
||||
fs_putfilep(filep);
|
||||
file_put(filep);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user