hds: not allow duplicated host & guest path
authorJinhyung Choi <jinh0.choi@samsung.com>
Wed, 6 Jan 2016 12:25:32 +0000 (21:25 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 7 Jan 2016 11:08:15 +0000 (20:08 +0900)
Change-Id: Ia282cf951ac9dd87c659ae3ed20f3de5092a93b1
Signed-off-by: Jinhyung Choi <jinh0.choi@samsung.com>
tizen/src/ecs/ecs_hds.c
tizen/src/ecs/ecs_hds.h
tizen/src/util/hds.c
tizen/src/util/hds.h

index 8b0b980..65747b2 100644 (file)
@@ -66,12 +66,21 @@ static void ecs_hds_do_mount(char* cmd, type_group group, char *data)
         LOG_WARNING("ecs_hds_do_mount host token is empty.\n");
         make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_FAIL, NULL);
         return;
+    } else if (hds_is_host_path_used((const char*)host)) {
+        LOG_WARNING("host path '%s' is already taken.\n", host);
+        make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_DUP_HOST_PATH, NULL);
+        return;
     }
+
     guest = strtok(NULL, token);
     if (guest == NULL) {
         LOG_WARNING("ecs_hds_do_mount guest token is empty.\n");
         make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_FAIL, NULL);
         return;
+    } else if (hds_is_guest_path_used((const char*)guest)) {
+        LOG_WARNING("guest path '%s' is already taken.\n", guest);
+        make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_DUP_GUEST_PATH, NULL);
+        return;
     }
 
     level_token = strtok(NULL, token);
index ddc23f1..8cf3e03 100644 (file)
 #define ECS_HDS_ACTION_STATE    99
 
 enum hds_act_result {
+    //FIXME: numbering & ordering
     ECS_HDS_ACT_GET_LIST = 0,
     ECS_HDS_ACT_MOUNT_SUCCESS = 1,
     ECS_HDS_ACT_MOUNT_FAIL = 2,
     ECS_HDS_ACT_MOUNT_NOT_PERMITTED = 11,
     ECS_HDS_ACT_MOUNT_NOT_VALID_PATH = 12,
+    ECS_HDS_ACT_MOUNT_DUP_HOST_PATH = 21,
+    ECS_HDS_ACT_MOUNT_DUP_GUEST_PATH = 22,
     ECS_HDS_ACT_UMOUNT_SUCCESS = 3,
     ECS_HDS_ACT_UMOUNT_FAIL = 4,
     ECS_HDS_ACT_UMOUNT_DETACH_FAIL = 5,
index de7a33e..434d3ee 100644 (file)
@@ -212,6 +212,36 @@ void set_hds_attached(const char* id, bool attached)
     list->attached = attached;
 }
 
+bool hds_is_host_path_used(const char* path)
+{
+    hds_list *list, *next;
+
+    QTAILQ_FOREACH_SAFE(list, &lists, next, next)
+    {
+        if (!strcmp(list->host, path)) {
+            LOG_TRACE("found duplicated host path. id: %s\n", list->id);
+            return true;
+        }
+    }
+
+    return false;
+}
+
+bool hds_is_guest_path_used(const char* path)
+{
+    hds_list *list, *next;
+
+    QTAILQ_FOREACH_SAFE(list, &lists, next, next)
+    {
+        if (!strcmp(list->guest, path)) {
+            LOG_TRACE("found duplicated guest path. id: %s\n", list->id);
+            return true;
+        }
+    }
+
+    return false;
+}
+
 char* get_hds_lists(void)
 {
     hds_list *list, *next;
index f49323b..d0acb7a 100644 (file)
@@ -50,6 +50,9 @@ int get_hds_level_by_id(const char* id);
 bool is_hds_attached(const char* id);
 void set_hds_attached(const char* id, bool attached);
 
+bool hds_is_host_path_used(const char* path);
+bool hds_is_guest_path_used(const char* path);
+
 char* get_hds_lists(void);
 int hds_get_pci_available_slot_num(void);