From 048ffb481aff7a3d5a7cbb9bcaa49ec3f4bc131c Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 5 Apr 2016 11:11:10 +0800 Subject: [PATCH] [DeviceDrivers] Add umount operations in SDCard block device. --- components/drivers/sdio/block_dev.c | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 6e78c9cd06..e1c7f1dcdd 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -27,7 +27,7 @@ #include -static rt_list_t blk_devices; +static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices); struct mmcsd_blk_device { @@ -336,6 +336,8 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) return err; } + rt_kprintf("probe mmcsd block device!\n"); + /* get the first sector to read partition table */ sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE); if (sector == RT_NULL) @@ -350,13 +352,13 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) { for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++) { - blk_dev = rt_malloc(sizeof(struct mmcsd_blk_device)); + blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device)); if (!blk_dev) { - rt_kprintf("mmcsd:malloc mem failde\n"); + rt_kprintf("mmcsd:malloc memory failed!\n"); break; } - rt_memset((void *)blk_dev, 0, sizeof(struct mmcsd_blk_device)); + /* get the first partition */ status = dfs_filesystem_get_partition(&blk_dev->part, sector, i); if (status == RT_EOK) @@ -424,6 +426,15 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) break; } } + +#ifdef RT_USING_DFS_MNTTABLE + if (0) // if (blk_dev) + { + rt_kprintf("try to mount file system!\n"); + /* try to mount file system on this block device */ + dfs_mount_device(&(blk_dev->dev)); + } +#endif } } else @@ -440,14 +451,21 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) { - rt_list_t *l; + rt_list_t *l, *n; struct mmcsd_blk_device *blk_dev; - - for (l = (&blk_devices)->next; l != &blk_devices; l = l->next) + + for (l = (&blk_devices)->next, n = l->next; l != &blk_devices; l = n) { blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list); if (blk_dev->card == card) { + /* unmount file system */ + const char * mounted_path = dfs_filesystem_get_mounted_path(&(blk_dev->dev)); + if (mounted_path) + { + dfs_unmount(mounted_path); + } + rt_device_unregister(&blk_dev->dev); rt_list_remove(&blk_dev->list); rt_free(blk_dev); @@ -455,7 +473,13 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) } } +/* + * This function will initialize block device on the mmc/sd. + * + * @deprecated since 2.1.0, this function does not need to be invoked + * in the system initialization. + */ void rt_mmcsd_blk_init(void) { - rt_list_init(&blk_devices); + /* nothing */ } -- GitLab