Skip to content

Commit 92ab9d2

Browse files
authored
Merge pull request #3206 from hichard/master
1.修复sd卡热插拔内存泄露的bug
2 parents 5a40f93 + ec3b434 commit 92ab9d2

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

components/dfs/include/dfs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int dfs_unmount(const char *specialfile);
9090

9191
int dfs_mkfs(const char *fs_name, const char *device_name);
9292
int dfs_statfs(const char *path, struct statfs *buffer);
93+
int dfs_mount_device(rt_device_t dev);
9394

9495
#ifdef __cplusplus
9596
}

components/dfs/src/dfs_fs.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ int dfs_mount_table(void)
508508
mount_table[index].rwflag,
509509
mount_table[index].data) != 0)
510510
{
511-
rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
511+
LOG_E("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
512512
mount_table[index].path);
513513
return -RT_ERROR;
514514
}
@@ -518,6 +518,43 @@ int dfs_mount_table(void)
518518
return 0;
519519
}
520520
INIT_ENV_EXPORT(dfs_mount_table);
521+
522+
int dfs_mount_device(rt_device_t dev)
523+
{
524+
int index = 0;
525+
526+
if(dev == RT_NULL) {
527+
rt_kprintf("the device is NULL to be mounted.\n");
528+
return -RT_ERROR;
529+
}
530+
531+
while (1)
532+
{
533+
if (mount_table[index].path == NULL) break;
534+
535+
if(strcmp(mount_table[index].device_name, dev->parent.name) == 0) {
536+
if (dfs_mount(mount_table[index].device_name,
537+
mount_table[index].path,
538+
mount_table[index].filesystemtype,
539+
mount_table[index].rwflag,
540+
mount_table[index].data) != 0)
541+
{
542+
LOG_E("mount fs[%s] device[%s] to %s failed.\n", mount_table[index].filesystemtype, dev->parent.name,
543+
mount_table[index].path);
544+
return -RT_ERROR;
545+
} else {
546+
LOG_D("mount fs[%s] device[%s] to %s ok.\n", mount_table[index].filesystemtype, dev->parent.name,
547+
mount_table[index].path);
548+
return RT_EOK;
549+
}
550+
}
551+
552+
index ++;
553+
}
554+
555+
rt_kprintf("can't find device:%s to be mounted.\n", dev->parent.name);
556+
return -RT_ERROR;
557+
}
521558
#endif
522559

523560
#ifdef RT_USING_FINSH

components/dfs/src/poll.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <dfs_posix.h>
2020
#include <dfs_poll.h>
2121

22+
#ifdef RT_USING_POSIX
23+
2224
struct rt_poll_node;
2325

2426
struct rt_poll_table
@@ -214,3 +216,4 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
214216
return num;
215217
}
216218

219+
#endif

components/dfs/src/select.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <dfs_poll.h>
1515
#include <dfs_select.h>
1616

17+
#ifdef RT_USING_POSIX
18+
1719
static void fdszero(fd_set *set, int nfds)
1820
{
1921
fd_mask *m;
@@ -178,3 +180,4 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
178180
return ret;
179181
}
180182

183+
#endif

components/drivers/sdio/block_dev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
472472
}
473473

474474
#ifdef RT_USING_DFS_MNTTABLE
475-
if (0) // if (blk_dev)
475+
if (blk_dev)
476476
{
477477
LOG_I("try to mount file system!");
478478
/* try to mount file system on this block device */
@@ -507,9 +507,10 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
507507
const char * mounted_path = dfs_filesystem_get_mounted_path(&(blk_dev->dev));
508508
if (mounted_path)
509509
{
510-
dfs_unmount(mounted_path);
510+
dfs_unmount(mounted_path);
511+
LOG_D("unmount file system %s for device %s.\r\n", mounted_path, blk_dev->dev.parent.name);
511512
}
512-
513+
rt_sem_delete(blk_dev->part.lock);
513514
rt_device_unregister(&blk_dev->dev);
514515
rt_list_remove(&blk_dev->list);
515516
rt_free(blk_dev);

0 commit comments

Comments
 (0)