summaryrefslogtreecommitdiff
path: root/components/drivers/sdio
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2016-04-05 11:11:10 +0800
committerBernard Xiong <[email protected]>2016-04-05 11:11:10 +0800
commit048ffb481aff7a3d5a7cbb9bcaa49ec3f4bc131c (patch)
tree3da4977321162b4df43aa95bfc44fb4f9095950e /components/drivers/sdio
parent80431860208d0795c81decb03e6989de2115d97e (diff)
[DeviceDrivers] Add umount operations in SDCard block device.
Diffstat (limited to 'components/drivers/sdio')
-rw-r--r--components/drivers/sdio/block_dev.c40
1 files 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 <drivers/mmcsd_core.h>
-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 */
}