[DeviceDrivers] Add umount operations in SDCard block device.
This commit is contained in:
parent
8043186020
commit
048ffb481a
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <drivers/mmcsd_core.h>
|
#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
|
struct mmcsd_blk_device
|
||||||
{
|
{
|
||||||
|
@ -336,6 +336,8 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_kprintf("probe mmcsd block device!\n");
|
||||||
|
|
||||||
/* get the first sector to read partition table */
|
/* get the first sector to read partition table */
|
||||||
sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
|
sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
|
||||||
if (sector == RT_NULL)
|
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++)
|
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)
|
if (!blk_dev)
|
||||||
{
|
{
|
||||||
rt_kprintf("mmcsd:malloc mem failde\n");
|
rt_kprintf("mmcsd:malloc memory failed!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rt_memset((void *)blk_dev, 0, sizeof(struct mmcsd_blk_device));
|
|
||||||
/* get the first partition */
|
/* get the first partition */
|
||||||
status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
|
status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
|
||||||
if (status == RT_EOK)
|
if (status == RT_EOK)
|
||||||
|
@ -424,6 +426,15 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
|
||||||
break;
|
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
|
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)
|
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;
|
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);
|
blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
|
||||||
if (blk_dev->card == card)
|
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_device_unregister(&blk_dev->dev);
|
||||||
rt_list_remove(&blk_dev->list);
|
rt_list_remove(&blk_dev->list);
|
||||||
rt_free(blk_dev);
|
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)
|
void rt_mmcsd_blk_init(void)
|
||||||
{
|
{
|
||||||
rt_list_init(&blk_devices);
|
/* nothing */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue