Skip to content

Commit 01c3460

Browse files
committed
[DevFS] fix the device none-open issue
1 parent 3da0f4e commit 01c3460

File tree

1 file changed

+11
-3
lines changed
  • components/dfs/filesystems/devfs

1 file changed

+11
-3
lines changed

components/dfs/filesystems/devfs/devfs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int dfs_device_fs_close(struct dfs_fd *file)
131131

132132
int dfs_device_fs_open(struct dfs_fd *file)
133133
{
134+
rt_err_t result;
134135
rt_device_t device;
135136

136137
if (file->flags & DFS_O_CREAT)
@@ -186,9 +187,16 @@ int dfs_device_fs_open(struct dfs_fd *file)
186187
if (device == RT_NULL)
187188
return -DFS_STATUS_ENODEV;
188189

189-
file->data = device;
190-
191-
return DFS_STATUS_OK;
190+
/* to open device */
191+
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
192+
if (result == RT_EOK || result == -RT_ENOSYS)
193+
{
194+
file->data = device;
195+
return DFS_STATUS_OK;
196+
}
197+
198+
/* open device failed. */
199+
return -DFS_STATUS_EIO;
192200
}
193201

194202
int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)

0 commit comments

Comments
 (0)