diff options
| author | Cliff Chen <[email protected]> | 2020-03-16 10:22:37 +0800 |
|---|---|---|
| committer | Cliff Chen <[email protected]> | 2020-03-16 10:50:34 +0800 |
| commit | 1c68bd9d3cef3e6a935e520de57cb0acfc2c0a5e (patch) | |
| tree | 54aa10cc60ea0baaa45edfdfde1ba0e49b42de41 /components/dfs/src | |
| parent | a7bcf90d78970f9a5e221133653331df158e9548 (diff) | |
Support msc mode automatic switching
Signed-off-by: Cliff Chen <[email protected]>
Diffstat (limited to 'components/dfs/src')
| -rw-r--r-- | components/dfs/src/dfs_fs.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 164beed719..476e47fc06 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -555,6 +555,54 @@ int dfs_mount_device(rt_device_t dev) rt_kprintf("can't find device:%s to be mounted.\n", dev->parent.name); return -RT_ERROR; } + +int dfs_unmount_device(rt_device_t dev) +{ + struct dfs_filesystem *iter; + struct dfs_filesystem *fs = NULL; + + /* lock filesystem */ + dfs_lock(); + + for (iter = &filesystem_table[0]; + iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) + { + /* check if the PATH is mounted */ + if ((iter->dev_id->parent.name != NULL) + && (strcmp(iter->dev_id->parent.name, dev->parent.name) == 0)) + { + fs = iter; + break; + } + } + + if (fs == NULL || + fs->ops->unmount == NULL || + fs->ops->unmount(fs) < 0) + { + goto err1; + } + + /* close device, but do not check the status of device */ + if (fs->dev_id != NULL) + rt_device_close(fs->dev_id); + + if (fs->path != NULL) + rt_free(fs->path); + + /* clear this filesystem table entry */ + memset(fs, 0, sizeof(struct dfs_filesystem)); + + dfs_unlock(); + + return 0; + +err1: + dfs_unlock(); + + return -1; +} + #endif #ifdef RT_USING_FINSH |
