diff options
author | Munkyu Im <munkyu.im@samsung.com> | 2014-10-22 18:45:38 +0900 |
---|---|---|
committer | Munkyu Im <munkyu.im@samsung.com> | 2014-10-24 14:11:17 +0900 |
commit | 9a99b3f67e5b15814c0df4a4ae83d055641bd1d3 (patch) | |
tree | bcc0190ef2130333f8d594c69ca3ba413ba56124 /tizen/src/ecs | |
parent | 41b0638799779d5e0e07a992b8cd749abae70612 (diff) | |
download | qemu-9a99b3f67e5b15814c0df4a4ae83d055641bd1d3.tar.gz qemu-9a99b3f67e5b15814c0df4a4ae83d055641bd1d3.tar.bz2 qemu-9a99b3f67e5b15814c0df4a4ae83d055641bd1d3.zip |
sdcard: Allow only one attach for the same sdcard image
Implemented file locking when attach/detach sdcard.
During one user attach a image, other user cannot attach it.
Change-Id: I6f0a971c8114048412583acc3daec0f7ac6dc965
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
Diffstat (limited to 'tizen/src/ecs')
-rw-r--r-- | tizen/src/ecs/ecs_msg_injector.c | 138 |
1 files changed, 97 insertions, 41 deletions
diff --git a/tizen/src/ecs/ecs_msg_injector.c b/tizen/src/ecs/ecs_msg_injector.c index 6f7f6e78b8..1d20de1ccc 100644 --- a/tizen/src/ecs/ecs_msg_injector.c +++ b/tizen/src/ecs/ecs_msg_injector.c @@ -38,6 +38,7 @@ #include "emul_state.h" #include "ecs.h" #include "debug_ch.h" +#include "util/osutil.h" MULTI_DEBUG_CHANNEL(qemu, ecs); @@ -46,6 +47,44 @@ static int guest_connection = 0; extern QemuMutex mutex_location_data; static char location_data[MAX_INJECTOR_REQ_DATA]; +static void send_gen_injector_ntf(const char* cmd, int cmdlen, int grp, int act, char* on) +{ + int msglen = 0, datalen = 0; + type_length length = 0; + type_group group = grp; + type_action action = act; + + if (cmd == NULL || cmdlen > 10) + return; + + if (on == NULL) { + msglen = 14; + } else { + datalen = strlen(on); + length = (unsigned short)datalen; + + msglen = datalen + 15; + } + + char* status_msg = (char*) malloc(msglen); + if(!status_msg) + return; + + memset(status_msg, 0, msglen); + + memcpy(status_msg, cmd, cmdlen); + memcpy(status_msg + 10, &length, sizeof(unsigned short)); + memcpy(status_msg + 12, &group, sizeof(unsigned char)); + memcpy(status_msg + 13, &action, sizeof(unsigned char)); + + if (on != NULL) { + memcpy(status_msg + 14, on, datalen); + } + + send_injector_ntf(status_msg, msglen); + + free(status_msg); +} static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed) { @@ -291,9 +330,36 @@ char *get_tizen_sdk_data_path(void) return get_old_tizen_sdk_data_path(); } -static void handle_sdcard(char* dataBuf, size_t dataLen) -{ +static char* get_sdcard_img_path(char* sdcard_img_name, size_t dataLen) { + char* sdcard_img_path = NULL; + char* sdcard_path = NULL; + if (sdcard_img_name == NULL || dataLen < 3) { + return NULL; + } + dataLen = dataLen - 3; + if (sdcard_img_name[dataLen] == '\n') { + sdcard_img_name[dataLen] = '\0'; + TRACE("sdcard_img_name: %s\n", sdcard_img_name); + } else { + ERR("wrong sdcard message!\n"); + return NULL; + } + sdcard_path = get_emulator_sdcard_path(); + if (sdcard_path != NULL) { + sdcard_img_path = g_malloc(DEFAULTBUFLEN); + g_strlcpy(sdcard_img_path, sdcard_path, DEFAULTBUFLEN); + g_strlcat(sdcard_img_path, sdcard_img_name, DEFAULTBUFLEN); + TRACE("sdcard img path: [%s] length: %d\n", sdcard_img_path, strlen(sdcard_img_path)); + g_free(sdcard_path); + return sdcard_img_path; + } + return NULL; +} + +static int handle_sdcard(char* dataBuf, size_t dataLen) +{ + int err_no = 0; char ret = 0; if (dataBuf != NULL){ @@ -301,57 +367,48 @@ static void handle_sdcard(char* dataBuf, size_t dataLen) if (ret == '0' ) { /* umount sdcard */ - do_hotplug(DETACH_SDCARD, NULL, 0); + 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()) { + do_hotplug(DETACH_SDCARD, NULL, 0); + } else { + ERR("failed to umount: %s\n", sdcard_img_path); + send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, err_no, NULL); + return err_no; + } + g_free(sdcard_img_path); } else if (ret == '1') { /* mount sdcard */ - char sdcard_img_path[256]; - char* sdcard_path = NULL; - - sdcard_path = get_emulator_sdcard_path(); - if (sdcard_path) { - g_strlcpy(sdcard_img_path, sdcard_path, - sizeof(sdcard_img_path)); - - /* emulator_sdcard_img_path + sdcard img name */ - char* sdcard_img_name = dataBuf+2; - if(dataLen > 3 && sdcard_img_name != NULL){ - char* pLinechange = strchr(sdcard_img_name, '\n'); - if(pLinechange != NULL){ - sdcard_img_name = g_strndup(sdcard_img_name, pLinechange - sdcard_img_name); - } - - g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path)); - TRACE("sdcard path: [%s]\n", sdcard_img_path); - - do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1); - - /*if using strndup than free string*/ - if(pLinechange != NULL && sdcard_img_name!= NULL){ - free(sdcard_img_name); - } - - } - - g_free(sdcard_path); + char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen); + if ( !is_sdcard_attached() && make_sdcard_lock_os(sdcard_img_path)) { + do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1); + send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, 0, NULL); } else { - ERR("failed to get sdcard path!!\n"); + send_gen_injector_ntf(MSG_TYPE_SDCARD, 6, 11, 5, NULL); + return ERR_LCK; } - } else if(ret == '2'){ - TRACE("sdcard status 2 bypass" ); - }else { + g_free(sdcard_img_path); + + } else if (ret == '2') { + TRACE("sdcard status 2 bypass\n" ); + } else { ERR("!!! unknown command : %c\n", ret); + return ret; } - - }else{ + } else { ERR("!!! unknown data : %c\n", ret); + return ret; } + return ERR_SUCCESS; } static bool injector_req_sdcard(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) { if (msg->has_data) { TRACE("msg(%zu) : %s\n", msg->data.len, msg->data.data); - handle_sdcard((char*) msg->data.data, msg->data.len); + if (handle_sdcard((char*) msg->data.data, msg->data.len) > 0) { + return false; + } } else { ERR("has no msg\n"); } @@ -397,8 +454,7 @@ static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* send_injector_ntf(status_msg, msglen); - if (status_msg) - free(status_msg); + free(status_msg); } static bool injector_req_sensor(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) |