From ec8e0489195737d84623cc87d4555d4756a3cbe7 Mon Sep 17 00:00:00 2001 From: "giyeol.ok" Date: Fri, 31 May 2013 14:15:29 +0900 Subject: [PATCH] insert umount checking routine to support stable format Change-Id: Iba5d15c1016193423646a7fa0ef6245dffaba9fd Signed-off-by: giyeol.ok --- src/mmc/mmc-handler.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c index 90f574c..e458cc3 100644 --- a/src/mmc/mmc-handler.c +++ b/src/mmc/mmc-handler.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "core/log.h" #include "core/common.h" @@ -55,6 +56,8 @@ #define MMC_32GB_SIZE 61315072 +#define UNMOUNT_RETRY 5 + #define get_mmc_fs(ptr, type, member) \ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) @@ -360,17 +363,47 @@ static void launch_syspopup(const char *str) bundle_free(b); } +static int mmc_check(char* path) +{ + int ret = false; + struct mntent* mnt; + const char* table = "/etc/mtab"; + FILE* fp; + + fp = setmntent(table, "r"); + if (!fp) + return ret; + while (mnt=getmntent(fp)) { + if (!strcmp(mnt->mnt_dir, path)) { + ret = true; + break; + } + } + endmntent(fp); + return ret; +} + +static int mmc_check_and_unmount(char *path) +{ + int ret = 0; + if (mmc_check(path)) + ret = umount(path); + return ret; +} + static int mmc_umount(int option) { - int r, retry = 5; + int r, retry = UNMOUNT_RETRY; if (!check_mount_state()) return 0; _I("Mounted, will be unmounted"); - r = umount(MMC_MOUNT_POINT); - if (!r || option == UNMOUNT_NORMAL) + r = mmc_check_and_unmount(MMC_MOUNT_POINT); + if (!r || option == UNMOUNT_NORMAL) { + _I("unmount mmc card, ret = %d, option = %d", r, option); return r; + } _I("Execute force unmount!"); @@ -381,11 +414,13 @@ static int mmc_umount(int option) usleep(500000); while (--retry) { - r = umount2(MMC_MOUNT_POINT, MNT_DETACH); + r = mmc_check_and_unmount(MMC_MOUNT_POINT); if (!r) break; usleep(500000); _I("umount retry : %d", retry); + if (retry == UNMOUNT_RETRY -2) + kill_app_accessing_mmc(); } return r; -- 2.7.4