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)
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;
{
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;
-
}