mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
fs/vfs: Let caller control whether add the reference count of inode in file_allocate
to simplify the caller in some special case Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Petro Karashchenko
parent
4d4bb458da
commit
604eea453b
+21
-8
@@ -168,7 +168,7 @@ void files_releaselist(FAR struct filelist *list)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
||||||
FAR void *priv, int minfd)
|
FAR void *priv, int minfd, bool addref)
|
||||||
{
|
{
|
||||||
FAR struct filelist *list;
|
FAR struct filelist *list;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -217,6 +217,12 @@ int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
|||||||
list->fl_files[i][j].f_inode = inode;
|
list->fl_files[i][j].f_inode = inode;
|
||||||
list->fl_files[i][j].f_priv = priv;
|
list->fl_files[i][j].f_priv = priv;
|
||||||
nxmutex_unlock(&list->fl_lock);
|
nxmutex_unlock(&list->fl_lock);
|
||||||
|
|
||||||
|
if (addref)
|
||||||
|
{
|
||||||
|
inode_addref(inode);
|
||||||
|
}
|
||||||
|
|
||||||
return i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j;
|
return i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,17 +235,24 @@ int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
|||||||
/* The space of file array isn't enough, allocate a new filechunk */
|
/* The space of file array isn't enough, allocate a new filechunk */
|
||||||
|
|
||||||
ret = files_extend(list, i + 1);
|
ret = files_extend(list, i + 1);
|
||||||
if (ret >= 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
list->fl_files[i][0].f_oflags = oflags;
|
nxmutex_unlock(&list->fl_lock);
|
||||||
list->fl_files[i][0].f_pos = pos;
|
return ret;
|
||||||
list->fl_files[i][0].f_inode = inode;
|
|
||||||
list->fl_files[i][0].f_priv = priv;
|
|
||||||
ret = i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list->fl_files[i][0].f_oflags = oflags;
|
||||||
|
list->fl_files[i][0].f_pos = pos;
|
||||||
|
list->fl_files[i][0].f_inode = inode;
|
||||||
|
list->fl_files[i][0].f_priv = priv;
|
||||||
nxmutex_unlock(&list->fl_lock);
|
nxmutex_unlock(&list->fl_lock);
|
||||||
return ret;
|
|
||||||
|
if (addref)
|
||||||
|
{
|
||||||
|
inode_addref(inode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+2
-2
@@ -349,11 +349,11 @@ static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = file_allocate(mq.f_inode, mq.f_oflags, mq.f_pos, mq.f_priv, 0);
|
ret = file_allocate(mq.f_inode, mq.f_oflags,
|
||||||
|
mq.f_pos, mq.f_priv, 0, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
file_mq_close(&mq);
|
file_mq_close(&mq);
|
||||||
|
|
||||||
if (created)
|
if (created)
|
||||||
{
|
{
|
||||||
file_mq_unlink(mq_name);
|
file_mq_unlink(mq_name);
|
||||||
|
|||||||
+1
-9
@@ -163,15 +163,7 @@ static int sock_file_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
|
|
||||||
int sockfd_allocate(FAR struct socket *psock, int oflags)
|
int sockfd_allocate(FAR struct socket *psock, int oflags)
|
||||||
{
|
{
|
||||||
int sockfd;
|
return file_allocate(&g_sock_inode, oflags, 0, psock, 0, true);
|
||||||
|
|
||||||
sockfd = file_allocate(&g_sock_inode, oflags, 0, psock, 0);
|
|
||||||
if (sockfd >= 0)
|
|
||||||
{
|
|
||||||
inode_addref(&g_sock_inode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sockfd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ int file_dup(FAR struct file *filep, int minfd)
|
|||||||
/* Then allocate a new file descriptor for the inode */
|
/* Then allocate a new file descriptor for the inode */
|
||||||
|
|
||||||
fd2 = file_allocate(filep2.f_inode, filep2.f_oflags,
|
fd2 = file_allocate(filep2.f_inode, filep2.f_oflags,
|
||||||
filep2.f_pos, filep2.f_priv, minfd);
|
filep2.f_pos, filep2.f_priv, minfd, false);
|
||||||
if (fd2 < 0)
|
if (fd2 < 0)
|
||||||
{
|
{
|
||||||
file_close(&filep2);
|
file_close(&filep2);
|
||||||
|
|||||||
+1
-2
@@ -198,7 +198,7 @@ static int epoll_do_create(int size, int flags)
|
|||||||
|
|
||||||
/* Alloc the file descriptor */
|
/* Alloc the file descriptor */
|
||||||
|
|
||||||
fd = file_allocate(&g_epoll_inode, flags, 0, eph, 0);
|
fd = file_allocate(&g_epoll_inode, flags, 0, eph, 0, true);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
nxsem_destroy(&eph->sem);
|
nxsem_destroy(&eph->sem);
|
||||||
@@ -207,7 +207,6 @@ static int epoll_do_create(int size, int flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode_addref(&g_epoll_inode);
|
|
||||||
nxsem_post(&eph->sem);
|
nxsem_post(&eph->sem);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -246,7 +246,7 @@ static int nx_vopen(FAR const char *path, int oflags, va_list ap)
|
|||||||
/* Allocate a new file descriptor for the inode */
|
/* Allocate a new file descriptor for the inode */
|
||||||
|
|
||||||
fd = file_allocate(filep.f_inode, filep.f_oflags,
|
fd = file_allocate(filep.f_inode, filep.f_oflags,
|
||||||
filep.f_pos, filep.f_priv, 0);
|
filep.f_pos, filep.f_priv, 0, false);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
file_close(&filep);
|
file_close(&filep);
|
||||||
|
|||||||
@@ -783,7 +783,7 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist);
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
|
||||||
FAR void *priv, int minfd);
|
FAR void *priv, int minfd, bool addref);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: file_dup
|
* Name: file_dup
|
||||||
|
|||||||
Reference in New Issue
Block a user