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:
dongjiuzhu1
2025-07-14 15:21:15 +08:00
committed by Xiang Xiao
parent ae33447220
commit 338132af8f
+10 -1
View File
@@ -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!)