mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 14:49:22 +08:00
fs/block_proxy: fix the issue of the refs count for filep being zeroed out by utilizing dup2
file_open will clear filep, include f_refs Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -147,6 +147,7 @@ static FAR char *unique_chardev(void)
|
||||
|
||||
int block_proxy(FAR struct file *filep, FAR const char *blkdev, int oflags)
|
||||
{
|
||||
struct file temp;
|
||||
FAR char *chardev;
|
||||
bool readonly;
|
||||
int ret;
|
||||
@@ -180,13 +181,21 @@ int block_proxy(FAR struct file *filep, FAR const char *blkdev, int oflags)
|
||||
/* Open the newly created character driver */
|
||||
|
||||
oflags &= ~(O_CREAT | O_EXCL | O_APPEND | O_TRUNC);
|
||||
ret = file_open(filep, chardev, oflags);
|
||||
ret = file_open(&temp, chardev, oflags);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to open %s: %d\n", chardev, ret);
|
||||
goto errout_with_bchdev;
|
||||
}
|
||||
|
||||
ret = file_dup2(&temp, filep);
|
||||
file_close(&temp);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to dup2%s: %d\n", chardev, ret);
|
||||
goto errout_with_bchdev;
|
||||
}
|
||||
|
||||
/* Unlink the character device name. The driver instance will persist,
|
||||
* provided that CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y (otherwise, we have
|
||||
* a problem here!)
|
||||
|
||||
Reference in New Issue
Block a user