From e52cab479c318b25065dc5785322ee6da32011fc Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Tue, 23 Dec 2014 21:16:02 +0900 Subject: [PATCH] sdcard: Fix failing re-attaching on Windows failed when try to attach > detach > attach on Windows. becuase of failing unlock when detach sdcard image. Change-Id: If400812633a4a22c937911cc3086125923e9a6fd Signed-off-by: Munkyu Im --- tizen/src/ecs/ecs_msg_injector.c | 2 +- tizen/src/util/osutil-win32.c | 56 +++++++++++----------------------------- tizen/src/util/osutil.h | 2 -- 3 files changed, 16 insertions(+), 44 deletions(-) diff --git a/tizen/src/ecs/ecs_msg_injector.c b/tizen/src/ecs/ecs_msg_injector.c index 84423fb..77ade75 100644 --- a/tizen/src/ecs/ecs_msg_injector.c +++ b/tizen/src/ecs/ecs_msg_injector.c @@ -369,7 +369,7 @@ static int handle_sdcard(char* dataBuf, size_t dataLen) INFO("datalen: %d\n", dataLen); char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen); err_no = remove_sdcard_lock_os(sdcard_img_path); - if (errno == 0 && is_sdcard_attached()) { + if (err_no == 0 && is_sdcard_attached()) { do_hotplug(DETACH_SDCARD, NULL, 0); } else { ERR("failed to umount: %s\n", sdcard_img_path); diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index 9dc28b1..40cf9b3 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -57,7 +57,7 @@ static char *g_pBuf; extern char tizen_target_img_path[]; static char g_sdcard[256] = {0,}; - +static sdcard_info info; static const char *pactempfile = ".autoproxy"; static void check_vm_lock_os(void) @@ -399,16 +399,16 @@ bool make_sdcard_lock_os(char *sdcard) char *lock_file = g_strdup_printf("%s.lck", sdcard); HANDLE hFile = CreateFile(lock_file, GENERIC_READ, - 0, + FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL); if (hFile == INVALID_HANDLE_VALUE) { ERR("file open error : (%d)\n", GetLastError()); - if(GetLastError() == 32) { - if(strcmp(g_sdcard, sdcard) == 0) { + if (GetLastError() == ERROR_SHARING_VIOLATION) { + if (strcmp(g_sdcard, sdcard) == 0) { INFO("try to mount same sdcard!\n"); } return false; @@ -426,56 +426,30 @@ int remove_sdcard_lock_os(char *sdcard) { char *lock_file = g_strdup_printf("%s.lck", sdcard); HANDLE hFile2; - BOOL fSuccess; hFile2 = CreateFile(lock_file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - + /* to check if previous lock exists */ if (hFile2 == INVALID_HANDLE_VALUE) { - ERR("CreateFile() error : (%d)\n", GetLastError()); - if (GetLastError() == 32) { + INFO("CreateFile() return : (%d)\n", GetLastError()); + if (GetLastError() == ERROR_SHARING_VIOLATION) { if (strncmp(g_sdcard, sdcard, strlen(sdcard)) != 0) { INFO("not same sdcard!!!\n"); return ERR_UNLCK; } - INFO("return ERR_SUCCESS\n"); + INFO("unlock success: %s\n", lock_file); g_sdcard[0] = '\0'; - fSuccess = DeleteFile(lock_file); - if (!fSuccess) { - // Handle the error. - ERR("DeleteFile failed (%d)\n", GetLastError()); - return ERR_UNLCK; - } - return ERR_SUCCESS; + CloseHandle(info.handle); + } else { + return ERR_UNLCK; } - return ERR_NOENT; - } - - hFile2 = CreateFile(lock_file, GENERIC_READ, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile2 == INVALID_HANDLE_VALUE) { - ERR("CreateFile() error : (%d)\n", GetLastError()); - return ERR_UNLCK; - } - CloseHandle(hFile2); - fSuccess = DeleteFile(lock_file); - if (!fSuccess) { - // Handle the error. - ERR("DeleteFile failed (%d)\n", GetLastError()); - return ERR_UNLCK; + } else { + ERR("lockfile exists but, it is not locked.\n"); + CloseHandle(hFile2); } - INFO("unlock success: %s\n", lock_file); - CloseHandle(info.handle); - return ERR_SUCCESS; - } diff --git a/tizen/src/util/osutil.h b/tizen/src/util/osutil.h index e75dc94..ed51849 100644 --- a/tizen/src/util/osutil.h +++ b/tizen/src/util/osutil.h @@ -80,8 +80,6 @@ typedef struct sdcard_info #endif char* lock_file; /* reserved for future use */ } sdcard_info; -extern sdcard_info info; - #ifndef CONFIG_WIN32 bool make_sdcard_lock_posix(char *sdcard); int remove_sdcard_lock_posix(char *sdcard); -- 2.7.4