diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c index 5db3752f613..77eae6476a3 100644 --- a/fs/driver/fs_blockproxy.c +++ b/fs/driver/fs_blockproxy.c @@ -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!)