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:
parent
4d4bb458da
commit
604eea453b
|
@ -168,7 +168,7 @@ void files_releaselist(FAR struct filelist *list)
|
|||
****************************************************************************/
|
||||
|
||||
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;
|
||||
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_priv = priv;
|
||||
nxmutex_unlock(&list->fl_lock);
|
||||
|
||||
if (addref)
|
||||
{
|
||||
inode_addref(inode);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
ret = files_extend(list, i + 1);
|
||||
if (ret >= 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
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;
|
||||
ret = i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
||||
nxmutex_unlock(&list->fl_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
return ret;
|
||||
|
||||
if (addref)
|
||||
{
|
||||
inode_addref(inode);
|
||||
}
|
||||
|
||||
return i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -349,11 +349,11 @@ static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
|
|||
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)
|
||||
{
|
||||
file_mq_close(&mq);
|
||||
|
||||
if (created)
|
||||
{
|
||||
file_mq_unlink(mq_name);
|
||||
|
|
|
@ -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;
|
||||
|
||||
sockfd = file_allocate(&g_sock_inode, oflags, 0, psock, 0);
|
||||
if (sockfd >= 0)
|
||||
{
|
||||
inode_addref(&g_sock_inode);
|
||||
}
|
||||
|
||||
return sockfd;
|
||||
return file_allocate(&g_sock_inode, oflags, 0, psock, 0, true);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -67,7 +67,7 @@ int file_dup(FAR struct file *filep, int minfd)
|
|||
/* Then allocate a new file descriptor for the inode */
|
||||
|
||||
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)
|
||||
{
|
||||
file_close(&filep2);
|
||||
|
|
|
@ -198,7 +198,7 @@ static int epoll_do_create(int size, int flags)
|
|||
|
||||
/* 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)
|
||||
{
|
||||
nxsem_destroy(&eph->sem);
|
||||
|
@ -207,7 +207,6 @@ static int epoll_do_create(int size, int flags)
|
|||
return -1;
|
||||
}
|
||||
|
||||
inode_addref(&g_epoll_inode);
|
||||
nxsem_post(&eph->sem);
|
||||
return fd;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
||||
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)
|
||||
{
|
||||
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,
|
||||
FAR void *priv, int minfd);
|
||||
FAR void *priv, int minfd, bool addref);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_dup
|
||||
|
|
Loading…
Reference in New Issue