Modified process for MMC storage 94/174594/4
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 3 Apr 2018 06:30:25 +0000 (15:30 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 9 Apr 2018 08:12:14 +0000 (17:12 +0900)
1. Merge MMC/OTG process
2. Use systemd storage uuid instead CID
3. Modify mediadb-update tool

Change-Id: I78ac16912119ba820657b40de3b8ddfaea5d11de
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
14 files changed:
lib/include/media-util-user.h
lib/include/private.h
lib/media-util-user.c
src/common/include/media-common-db-svc.h
src/common/include/media-common-external-storage.h
src/common/include/media-common-system.h
src/common/media-common-db-svc.c
src/common/media-common-external-storage.c
src/common/media-common-system.c
src/mediadb-update.c
src/scanner-v2/media-scanner-device-block-v2.c
src/server/include/media-server-device-block.h
src/server/media-server-device-block.c
src/server/media-server-main.c

index fd6ffb3..b3950cd 100755 (executable)
@@ -35,7 +35,7 @@ typedef enum {
 int ms_user_get_internal_root_path(uid_t uid, char **path);
 int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_e *storage_type);
 int ms_user_get_root_thumb_store_path(uid_t uid, char **path);
-int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type, char **path);
+int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type, const char *storage_id, char **path);
 int ms_user_get_media_db_path(uid_t uid, char **path);
 
 #ifndef _USE_TVPD_MODE
index 8411ef1..50e8ed3 100755 (executable)
@@ -64,7 +64,6 @@ static inline tizen_profile_t _get_tizen_profile()
        return profile;
 }
 
-#define _USE_SDCARD    (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
 #define _USE_TV_PATH   (_get_tizen_profile() == TIZEN_PROFILE_TV)
 
 #endif /* _MEDIA_SERVER_PRIVATE_H_ */
index 57e3a1b..f238454 100755 (executable)
@@ -23,6 +23,7 @@
 #include <glib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #ifdef _USE_SENIOR_MODE
 #include <system_info.h>
@@ -55,7 +56,7 @@ bool _ms_is_support_senior_mode()
 }
 #endif
 
-static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
+static int __ms_user_get_path(ms_user_path_type_e type, const char *storage_id, uid_t uid, char **path)
 {
        int ret = MS_MEDIA_ERR_NONE;
        const char *result = NULL;
@@ -95,7 +96,7 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
                result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb/phone");
                break;
        case THUMB_EXTERNAL:
-               result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb/mmc");
+               result = tzplatform_context_mkpath3(context[idx], TZ_USER_SHARE, "media/.thumb/mmc", storage_id);
                break;
 #ifndef _USE_TVPD_MODE
        case MEDIA_SHARED:
@@ -125,7 +126,7 @@ int ms_user_get_internal_root_path(uid_t uid, char **path)
        if (uid == getuid())
                *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
        else
-               ret = __ms_user_get_path(INTERNAL_ROOT, uid, path);
+               ret = __ms_user_get_path(INTERNAL_ROOT, NULL, uid, path);
 
        //MSAPI_DBG_SLOG("internal root path [%s]", *path);
 
@@ -182,14 +183,14 @@ int ms_user_get_root_thumb_store_path(uid_t uid, char **path)
        if (uid == getuid())
                *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb"));
        else
-               ret = __ms_user_get_path(THUMB_ROOT, uid, path);
+               ret = __ms_user_get_path(THUMB_ROOT, NULL, uid, path);
 
        //MSAPI_DBG_SLOG("thumb path [%s]", *path);
 
        return ret;
 }
 
-int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type, char **path)
+int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type, const char *storage_id, char **path)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
@@ -197,15 +198,25 @@ int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type,
                if (storage_type == MS_USER_STORAGE_INTERNAL)
                        *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/phone"));
                else
-                       *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc"));
+                       *path = g_strdup(tzplatform_mkpath3(TZ_USER_SHARE, "media/.thumb/mmc", storage_id));
        } else {
                if (storage_type == MS_USER_STORAGE_INTERNAL)
-                       ret = __ms_user_get_path(THUMB_INTERNAL, uid, path);
+                       ret = __ms_user_get_path(THUMB_INTERNAL, NULL, uid, path);
                else
-                       ret = __ms_user_get_path(THUMB_EXTERNAL, uid, path);
+                       ret = __ms_user_get_path(THUMB_EXTERNAL, storage_id, uid, path);
        }
 
        //MSAPI_DBG_SLOG("thumb path [%s]", *path);
+       /* Create if not exist */
+       if (storage_type == MS_USER_STORAGE_EXTERNAL) {
+               if (!g_file_test(*path, G_FILE_TEST_EXISTS)) {
+                       ret = g_mkdir_with_parents(*path, S_IRWXU | S_IRWXG | S_IRWXO);
+                       if (ret != 0) {
+                               MSAPI_DBG_ERR("Failed to create thumb directory for external");
+                               ret = MS_MEDIA_ERR_INTERNAL;
+                       }
+               }
+       }
 
        return ret;
 }
@@ -217,7 +228,7 @@ int ms_user_get_media_db_path(uid_t uid, char **path)
        if (uid == getuid())
                *path = g_strdup(tzplatform_mkpath(TZ_USER_DB, ".media.db"));
        else
-               ret = __ms_user_get_path(MEDIA_DB, uid, path);
+               ret = __ms_user_get_path(MEDIA_DB, NULL, uid, path);
 
        //MSAPI_DBG_SLOG("DB path [%s]", *path);
 
@@ -232,7 +243,7 @@ int ms_user_get_mediashared_path(uid_t uid, char **path)
        if (uid == getuid())
                *path = g_strdup(tzplatform_getenv(TZ_USER_MEDIASHARED));
        else
-               ret = __ms_user_get_path(MEDIA_SHARED, uid, path);
+               ret = __ms_user_get_path(MEDIA_SHARED, NULL, uid, path);
 
        //MSAPI_DBG_SLOG("DB path [%s]", *path);
 
index d2f315b..c33e2b3 100755 (executable)
@@ -27,7 +27,6 @@
 #include "media-common-types.h"
 
 #define INTERNAL_STORAGE_ID    "media"
-#define MMC_STORAGE_ID         "media"
 #define USB_STORAGE_REMOVED "usb_removed"
 #define DATADISC_STORAGE_ID    "data_disc"
 
@@ -90,7 +89,6 @@ typedef int (*CHANGE_VALIDITY_ITEM_BATCH)(void *, const char *, const char *, in
 
 typedef int (*CHECK_DB)(void*, uid_t, char **);
 typedef int (*GET_UUID)(void *, char **, char **);
-typedef int (*GET_MMC_INFO)(void *, char **, char **, int *, bool *, char **);
 typedef int (*CHECK_STORAGE)(void *, const char *, char **, int *, uid_t, char **);
 typedef int (*INSERT_STORAGE)(void *, const char *, int, const char *, const char *, uid_t, char **);
 typedef int (*UPDATE_STORAGE)(void *, const char *, const char *, uid_t, char **);
@@ -141,7 +139,6 @@ int ms_change_validity_item_batch(void **handle, const char *storage_id, const c
 
 int ms_check_db_upgrade(void **handle, uid_t uid);
 int ms_genarate_uuid(void **handle, char **uuid);
-int ms_get_mmc_info(void **handle, char **storage_name, char **storage_path, int *validity, bool *info_exist);
 int ms_check_storage(void **handle, const char *storage_id, char **storage_path, int *validity, uid_t uid);
 int ms_insert_storage(void **handle, const char *storage_id, const char *storage_name, const char *storage_path, uid_t uid);
 int ms_update_storage(void **handle, const char *storage_id, const char *storage_path, uid_t uid);
index f4e7a75..eada7f9 100755 (executable)
@@ -23,7 +23,6 @@
 
 #include "media-common-types.h"
 
-int ms_get_mmc_id(char **cid);
 int ms_get_stg_changed_event(void);
 
 int ms_read_device_info(const char *root_path, char **device_uuid);
index 6d8a531..f99db06 100755 (executable)
@@ -46,7 +46,6 @@ typedef struct ms_block_info_s {
        char *mount_path;
        int state;
        int block_type;
-       int flags;
        char *mount_uuid;
 } ms_block_info_s;
 
index cbbea37..f4c9151 100755 (executable)
@@ -76,7 +76,6 @@ enum func_list {
        eCHANGE_VALIDITY_ITEM_BATCH,
        eCHECK_DB,
        eGET_UUID,
-       eGET_MMC_INFO,
        eCHECK_STORAGE,
        eINSERT_STORAGE,
        eUPDATE_STORAGE,
@@ -187,7 +186,6 @@ int ms_load_functions(void)
                "change_validity_item_batch",
                "check_db",
                "get_uuid",
-               "get_mmc_info",
                "check_storage",
                "insert_storage",
                "update_storage",
@@ -938,29 +936,6 @@ int ms_genarate_uuid(void **handle, char **uuid)
        return MS_MEDIA_ERR_NONE;
 }
 
-int ms_get_mmc_info(void **handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
-{
-       int lib_index = 0;
-       int res = MS_MEDIA_ERR_NONE;
-       int ret = 0;
-       char *err_msg = NULL;
-
-       MS_DBG("ms_get_mmc_info Start");
-
-       for (lib_index = 0; lib_index < lib_num; lib_index++) {
-               ret = ((GET_MMC_INFO)func_array[lib_index][eGET_MMC_INFO])(handle[lib_index], storage_name, storage_path, validity, info_exist, &err_msg);
-               if (ret != 0) {
-                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
-                       MS_SAFE_FREE(err_msg);
-                       res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
-               }
-       }
-
-       MS_DBG("ms_get_mmc_info End");
-
-       return res;
-}
-
 int ms_check_storage(void **handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
 {
        int lib_index = 0;
index 2badea5..322900a 100755 (executable)
 
 #include <tzplatform_config.h>
 
-#define MMC_INFO_SIZE 256
-
-static int __get_contents(const char *filename, char *buf)
-{
-       FILE *fp;
-
-       fp = fopen(filename, "rt");
-       if (fp == NULL) {
-               MS_DBG_ERR("fp is NULL. file name : %s", filename);
-               return MS_MEDIA_ERR_FILE_OPEN_FAIL;
-       }
-       if (fgets(buf, 255, fp) == NULL)
-               MS_DBG_ERR("fgets failed");
-
-       fclose(fp);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-/*need optimize*/
-int ms_get_mmc_id(char **cid)
-{
-       const char *path = "/sys/block/mmcblk1/device/cid";
-       char mmc_cid[MMC_INFO_SIZE] = {0, };
-       memset(mmc_cid, 0x00, sizeof(mmc_cid));
-
-       if (__get_contents(path, mmc_cid) != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("_get_contents failed");
-               *cid = NULL;
-       } else {
-               *cid = strndup(mmc_cid, strlen(mmc_cid) - 1);           //last is carriage return
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 #define DEVICE_INFO_FILE ".device_info_"
 
 int ms_read_device_info(const char *root_path, char **device_uuid)
index faae2b0..6458ee0 100755 (executable)
@@ -110,10 +110,6 @@ static void __ms_block_changed(GDBusConnection* connection,
        block_info->state = g_variant_get_int32(tmp);
        MS_DBG_INFO("state : %d", block_info->state);
 
-       tmp = g_variant_get_child_value(parameters, 11);
-       block_info->flags = g_variant_get_int32(tmp);
-       MS_DBG_INFO("flags : %d", block_info->flags);
-
        ((block_changed_cb)usr_cb)(block_info, usr_data);
        MS_SAFE_FREE(block_info->mount_path);
        MS_SAFE_FREE(block_info->mount_uuid);
@@ -322,8 +318,6 @@ static int __ms_gdbus_method_sync(const char *dest, const char *path, const char
                                data->mount_path = strdup(val_str[6]);
                                data->state = val_int[2];
                                data->mount_uuid = strdup(val_str[5]);
-                               data->flags = val_int[3];
-
                                if (*dev_list == NULL) {
                                        MS_DBG_ERR("DEV LIST IS NULL");
                                        *dev_list = g_array_new(FALSE, FALSE, sizeof(ms_block_info_s*));
index bf7170b..42fe3b9 100755 (executable)
@@ -30,7 +30,6 @@
 
 #include "media-util.h"
 
-#define MMC_INFO_SIZE 256
 #define BUS_NAME       "org.tizen.system.storage"
 #define OBJECT_PATH    "/Org/Tizen/System/Storage"
 #define INTERFACE_NAME BUS_NAME
@@ -42,8 +41,6 @@
 #define PATH_PLUGIN_LIB                                PATH_LIBDIR"/libmedia-content-plugin.so"
 
 #define DEVICE_METHOD "GetDeviceList"
-#define DEVICE_USB "scsi"
-#define DEVICE_MMC "mmc"
 #define DEVICE_ALL "all"
 
 #define MU_SAFE_FREE(src)              { if (src) {free(src); src = NULL; } }
@@ -55,7 +52,6 @@ typedef struct block_info_s {
        char *mount_path;
        int state;
        int block_type;
-       int flags;
        char *mount_uuid;
 } block_info_s;
 
@@ -63,10 +59,10 @@ int (*svc_connect)                          (void ** handle, uid_t uid, char ** err_msg);
 int (*svc_disconnect)                  (void * handle, char ** err_msg);
 int (*svc_check_db)                    (void * handle, uid_t uid, char ** err_msg);
 int (*svc_get_storage_id)              (void * handle, const char *path, char *storage_id, uid_t uid, char ** err_msg);
-int (*svc_get_mmc_info)                (void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg);
 int (*svc_insert_storage)              (void *handle, const char *storage_id, int storage_type, const char *storage_name, const char *storage_path, uid_t uid, char **err_msg);
-int (*svc_delete_storage)              (void * handle, const char *storage_id, uid_t uid, char **err_msg);
+int (*svc_update_storage)              (void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg);
 int (*svc_set_storage_validity)        (void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg);
+int (*svc_check_storage)               (void * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid, char **err_msg);
 
 void callback(media_request_result_s * result, void *user_data)
 {
@@ -93,36 +89,6 @@ void print_help()
        printf("=======================================================================================\n");
 }
 
-static int __get_contents(const char *filename, char *buf)
-{
-       FILE *fp;
-
-       fp = fopen(filename, "rt");
-       if (fp == NULL)
-               return -1;
-       if (fgets(buf, 255, fp) == NULL)
-               printf("fgets failed\n");
-
-       fclose(fp);
-
-       return 0;
-}
-
-/*need optimize*/
-void __get_mmc_id(char **cid)
-{
-       const char *path = "/sys/block/mmcblk1/device/cid";
-       char mmc_cid[MMC_INFO_SIZE] = {0, };
-       memset(mmc_cid, 0x00, sizeof(mmc_cid));
-
-       if (__get_contents(path, mmc_cid) != 0) {
-               printf("_get_contents failed");
-               *cid = NULL;
-       } else {
-               *cid = strndup(mmc_cid, strlen(mmc_cid) - 1);
-       }
-}
-
 int __get_device_list(GArray **dev_list)
 {
        GDBusConnection *g_bus = NULL;
@@ -148,7 +114,7 @@ int __get_device_list(GArray **dev_list)
                return -1;
        }
 
-       g_dbus_message_set_body(message, g_variant_new("(s)", (gchar*)DEVICE_MMC));
+       g_dbus_message_set_body(message, g_variant_new("(s)", (gchar*)DEVICE_ALL));
 
        reply = g_dbus_connection_send_message_with_reply_sync(g_bus, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
        g_object_unref(message);
@@ -192,7 +158,6 @@ int __get_device_list(GArray **dev_list)
                                data->mount_path = strdup(val_str[6]);
                                data->state = val_int[2];
                                data->mount_uuid = strdup(val_str[5]);
-                               data->flags = val_int[3];
 
                                if (*dev_list == NULL)
                                        *dev_list = g_array_new(FALSE, FALSE, sizeof(block_info_s*));
@@ -232,49 +197,41 @@ void __release_device_list(GArray **dev_list)
        }
 }
 
-static int __check_mmc(void)
+static bool __check_mmc(void)
 {
        int ret = 0;
-       int flag = 0;
        GArray *dev_list = NULL;
        void *funcHandle = NULL;
        void *db_handle = NULL;
-       char *storage_name = NULL;
        char *storage_path = NULL;
        int validity = 0;
-       bool info_exist = FALSE;
-       char *insert_stg_id = NULL;
+       bool need_scan = false;
        char *err_msg = NULL;
 
        funcHandle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
        if (funcHandle == NULL) {
                printf("Error when open plug-in\n");
-               return -1;
+               return false;
        }
 
        svc_connect                     = dlsym(funcHandle, "connect_db");
        svc_disconnect          = dlsym(funcHandle, "disconnect_db");
-       svc_get_mmc_info        = dlsym(funcHandle, "get_mmc_info");
        svc_insert_storage      = dlsym(funcHandle, "insert_storage");
-       svc_delete_storage      = dlsym(funcHandle, "delete_storage");
+       svc_update_storage      = dlsym(funcHandle, "update_storage");
        svc_set_storage_validity        = dlsym(funcHandle, "set_storage_validity");
-
-       ret = svc_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), &err_msg);
-       if (ret < 0) {
-               printf("Error svc_connect\n");
-               dlclose(funcHandle);
-               return -1;
-       }
-
-       ret = svc_get_mmc_info(db_handle, &storage_name, &storage_path, &validity, &info_exist, &err_msg);
-       if (ret < 0 && strcmp(err_msg, "not found in DB") != 0) {
-               printf("Error svc_get_mmc_info\n");
-               dlclose(funcHandle);
-               return -1;
-       }
+       svc_check_storage       = dlsym(funcHandle, "check_storage");
 
        ret = __get_device_list(&dev_list);
        if (ret == 0) {
+               /* Set validity to 0 */
+               ret = svc_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+               if (ret < 0) {
+                       printf("Error svc_connect\n");
+                       __release_device_list(&dev_list);
+                       dlclose(funcHandle);
+                       return false;
+               }
+
                if (dev_list != NULL) {
                        int i = 0 ;
                        int dev_num = dev_list->len;
@@ -282,56 +239,61 @@ static int __check_mmc(void)
 
                        for (i = 0; i < dev_num; i++) {
                                block_info = (block_info_s *)g_array_index(dev_list, int *, i);
-                               if (info_exist) {
-                                       __get_mmc_id(&insert_stg_id);
-
-                                       if (strncmp(storage_name, insert_stg_id, strlen(insert_stg_id)) == 0 && strncmp(storage_path, block_info->mount_path, strlen(block_info->mount_path)) == 0) {
-                                               if (validity == 0) {
-                                                       ret = svc_set_storage_validity(db_handle, "media", 1, tzplatform_getuid(TZ_USER_NAME), &err_msg);
-                                                       if (ret < 0)
-                                                               printf("Error svc_set_storage_validity\n");
-                                               }
-                                       } else {
-                                               ret = svc_delete_storage(db_handle, "media", tzplatform_getuid(TZ_USER_NAME), &err_msg);
-                                               ret = svc_insert_storage(db_handle, "media", 1, insert_stg_id, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+                               /* Check exists */
+                               ret = svc_check_storage(db_handle, block_info->mount_uuid, &storage_path, &validity, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+                               if (ret < 0)
+                                       printf("Error svc_check_storage\n");
+
+                               if (storage_path != NULL) {
+                                       /* check storage_path and update validity and path */
+                                       /* Mount point can be changed */
+                                       if (strcmp(block_info->mount_path, storage_path) != 0) {
+                                               ret = svc_update_storage(db_handle, block_info->mount_uuid, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+                                               if (ret < 0)
+                                                       printf("Error svc_update_storage\n");
+                                       }
+
+                                       if (validity == 0) {
+                                               ret = svc_set_storage_validity(db_handle, block_info->mount_uuid, 1, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+                                               if (ret < 0)
+                                                       printf("Error svc_set_storage_validity\n");
+
+                                               /* Need to scan */
+                                               ret = media_directory_scanning_async(block_info->mount_path, block_info->mount_uuid, true, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
+                                               if (ret < 0)
+                                                       printf("Error media_directory_scanning_async\n");
+                                               else
+                                                       need_scan = true;
                                        }
-                                       MU_SAFE_FREE(insert_stg_id);
                                } else {
-                                       __get_mmc_id(&insert_stg_id);
-                                       ret = svc_insert_storage(db_handle, "media", 1, insert_stg_id, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME), &err_msg);
-                                       MU_SAFE_FREE(insert_stg_id);
+                                       /* insert new storage */
+                                       ret = svc_insert_storage(db_handle, block_info->mount_uuid, 1, NULL, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME), &err_msg);
+                                       if (ret < 0)
+                                               printf("Error svc_insert_storage\n");
+
+                                       /* Need to scan */
+                                       ret = media_directory_scanning_async(block_info->mount_path, block_info->mount_uuid, true, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
+                                       if (ret < 0)
+                                               printf("Error media_directory_scanning_async\n");
+                                       else
+                                               need_scan = true;
                                }
-
-                               ret = media_directory_scanning_async(block_info->mount_path, "media", TRUE, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
-                               if (ret < 0)
-                                       printf("Error media_directory_scanning_async\n");
-                               else
-                                       flag = 1;               /* flag == 1 : Need to mainloop for scanning result callback */
                        }
                        __release_device_list(&dev_list);
-               } else {
-                       if (validity == 1) {
-                               ret = svc_set_storage_validity(db_handle, "media", 0, tzplatform_getuid(TZ_USER_NAME), &err_msg);
-                               if (ret < 0)
-                                       printf("Error svc_set_storage_validity\n");
-                       }
                }
+
+               ret = svc_disconnect(db_handle, &err_msg);
+               if (ret < 0)
+                       printf("Error svc_disconnect\n");
        } else {
                printf("__get_device_list failed\n");
        }
 
-       ret = svc_disconnect(db_handle, &err_msg);
-       if (ret < 0)
-               printf("Error svc_disconnect\n");
-
-       printf("Check mmc done\n");
+       printf("Check external storage done\n");
 
        dlclose(funcHandle);
 
-       if (flag == 1)
-               ret = 1;
-
-       return ret;
+       return need_scan;
 }
 
 static void __check_media_db(void)
@@ -462,9 +424,10 @@ int main(int argc, char **argv)
                }
 
                if (strcmp(argv1 , "check_mmc") == 0) {
-                       ret = __check_mmc();
-                       if (ret == 1)
+                       /* If true, waiting for directory scanning */
+                       if (__check_mmc()) {
                                g_main_loop_run(mainloop);
+                       }
 
                        exit(0);
                }
index 52dc70a..28942fd 100755 (executable)
@@ -80,26 +80,6 @@ static void __msc_usb_remove_event(const char *mount_path)
 }
 #endif
 
-int msc_mmc_remove_handler(const char *mount_path)
-{
-       return MS_MEDIA_ERR_NONE;
-}
-
-void _msc_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status)
-{
-       /* If scanner is not working, media server executes media scanner and sends request. */
-       /* If scanner is working, it detects changing status of SD card. */
-       if (mount_status == MS_STG_INSERTED) {
-               MS_DBG_WARN("GET THE MMC INSERT EVENT");
-               /*DO NOT THING*/
-       } else if (mount_status == MS_STG_REMOVED) {
-               MS_DBG_WARN("GET THE MMC REMOVE EVENT");
-               msc_mmc_remove_handler(mount_path);
-       }
-
-       return;
-}
-
 #ifdef _USE_DEVICED_DBUS
 void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
 {
@@ -110,9 +90,6 @@ void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
                        MS_DBG_WARN("GET THE USB REMOVE EVENT");
                        __msc_usb_remove_event(block_info->mount_path);
                }
-       } else {
-               MS_DBG_WARN("GET THE MMC EVENT");
-               _msc_mmc_changed_event(block_info->mount_path, block_info->state);
        }
 }
 #else
index 1f90fec..fbba264 100755 (executable)
@@ -23,8 +23,6 @@
 
 #include "media-common-system.h"
 
-int ms_mmc_insert_handler(const char *mount_path);
-int ms_mmc_remove_handler(const char *mount_path);
 int ms_usb_insert_handler(const char *mount_path, const char *mount_uuid);
 int ms_usb_remove_handler(const char *mount_path, const char *mount_uuid);
 #ifdef _USE_DEVICED_DBUS
index 4a3a179..44a0f90 100755 (executable)
@@ -175,194 +175,6 @@ int ms_usb_remove_handler(const char *mount_path, const char *mount_uuid)
        return ret;
 }
 
-static ms_dir_scan_type_t __ms_get_mmc_scan_type(const char *cid, const char *storage_name, const char *storage_path)
-{
-       ms_dir_scan_type_t scan_type = MS_SCAN_ALL;
-
-       MS_DBG("Last MMC id = [%s] MMC path = [%s]", storage_name, storage_path);
-       MS_DBG("Current MMC info = [%s]", cid);
-
-       if (storage_name != NULL) {
-               if (strcmp(storage_name, cid) == 0)
-                       scan_type = MS_SCAN_PART;
-       }
-
-       if (scan_type == MS_SCAN_PART)
-               MS_DBG("MMC Scan type [MS_SCAN_PART]");
-       else
-               MS_DBG("MMC Scan type [MS_SCAN_ALL]");
-
-       return scan_type;
-}
-
-static int __ms_get_mmc_info(void **handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-
-       ret = ms_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
-       if (ret != MS_MEDIA_ERR_NONE)
-               MS_DBG_ERR("[No-Error] ms_get_mmc_info failed. Maybe storage info not in media db [%d]", ret);
-
-       return ret;
-}
-
-static int __ms_insert_mmc_info(void **handle, const char *storage_name, const char *storage_path)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       uid_t uid = MEDIA_DEFAULT_UID;
-
-       ms_sys_get_uid(&uid);
-
-       ret = ms_insert_storage(handle, MMC_STORAGE_ID, storage_name, storage_path, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_insert_storage failed [%d]", ret);
-               ret = MS_MEDIA_ERR_INTERNAL;
-       }
-
-       return ret;
-}
-
-static int __ms_update_mmc_info(void **handle, const char *new_storage_name, const char *new_storage_path)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       uid_t uid = MEDIA_DEFAULT_UID;
-
-       ms_sys_get_uid(&uid);
-
-       ret = ms_delete_storage(handle, MMC_STORAGE_ID, uid);
-       if (ret != MS_MEDIA_ERR_NONE)
-               MS_DBG_ERR("ms_delete_storage failed [%d]", ret);
-
-       ret = ms_insert_storage(handle, MMC_STORAGE_ID, new_storage_name, new_storage_path, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_insert_storage failed [%d]", ret);
-               ret = MS_MEDIA_ERR_INTERNAL;
-       }
-
-       return ret;
-}
-
-int ms_mmc_insert_handler(const char *mount_path)
-{
-       /*FIX ME*/
-       int ret = MS_MEDIA_ERR_NONE;
-       ms_dir_scan_type_t scan_type = MS_SCAN_ALL;
-       char *storage_name = NULL;
-       char *storage_path = NULL;
-       int validity = 0;
-       bool info_exist = FALSE;
-       char *cid = NULL;
-       uid_t uid = MEDIA_DEFAULT_UID;
-
-       void **db_handle = NULL;
-
-       ret = ms_load_functions();
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_load_functions failed [%d]", ret);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       ms_sys_get_uid(&uid);
-
-       ret = ms_connect_db(&db_handle, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_connect_db failed [%d]", ret);
-               ms_unload_functions();
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       ms_get_mmc_id(&cid);
-       /* CHECK DB HERE!! */
-       ret = ms_check_db_upgrade(db_handle, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_check_db_upgrade failed [%d]", ret);
-               ms_disconnect_db(&db_handle);
-               ms_unload_functions();
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       __ms_get_mmc_info(db_handle, &storage_name, &storage_path, &validity, &info_exist);
-
-       if (info_exist == TRUE) {
-               scan_type = __ms_get_mmc_scan_type(cid, storage_name, storage_path);
-               if (scan_type == MS_SCAN_ALL) /*FIX ME. path should be compared*/
-                       __ms_update_mmc_info(db_handle, cid, mount_path);
-       } else {
-               __ms_insert_mmc_info(db_handle, cid, mount_path);
-       }
-
-       ms_set_storage_validity(db_handle, MMC_STORAGE_ID, 1, uid);
-
-       ms_disconnect_db(&db_handle);
-       ms_unload_functions();
-
-       MS_SAFE_FREE(cid);
-       MS_SAFE_FREE(storage_name);
-       MS_SAFE_FREE(storage_path);
-
-       ms_send_storage_scan_request(mount_path, MMC_STORAGE_ID, scan_type, uid);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int ms_mmc_remove_handler(const char *mount_path)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       char *storage_path = NULL;
-       void **handle = NULL;
-       int validity = 0;
-       uid_t uid = MEDIA_DEFAULT_UID;
-
-       ret = ms_load_functions();
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_load_functions failed [%d]", ret);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       ms_sys_get_uid(&uid);
-
-       ret = ms_connect_db(&handle, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("ms_connect_db failed [%d]", ret);
-               ms_unload_functions();
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       if (mount_path == NULL)
-               ret = ms_check_storage(handle, MMC_STORAGE_ID, &storage_path, &validity, uid);
-       else
-               storage_path = strdup(mount_path);
-
-       if (storage_path != NULL) {
-               MS_DBG_WARN("mmc_path[%s]", storage_path);
-
-               ms_set_storage_validity(handle, MMC_STORAGE_ID, 0, uid);
-
-               ms_send_storage_scan_request(storage_path, MMC_STORAGE_ID, MS_SCAN_INVALID, uid);
-
-               MS_SAFE_FREE(storage_path);
-       }
-
-       ms_disconnect_db(&handle);
-       ms_unload_functions();
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-void _ms_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status, int flags)
-{
-       /* If scanner is not working, media server executes media scanner and sends request. */
-       /* If scanner is working, it detects changing status of SD card. */
-       if (mount_status == MS_STG_INSERTED) {
-               ms_mmc_insert_handler(mount_path);
-       } else if (mount_status == MS_STG_REMOVED) {
-               /*remove added watch descriptors */
-               ms_mmc_remove_handler(mount_path);
-       }
-
-       return;
-}
-
 void _ms_usb_changed_event(const char *mount_path, const char *mount_uuid, ms_stg_status_e mount_status)
 {
        if (mount_status == MS_STG_INSERTED) {
@@ -389,13 +201,9 @@ void _ms_usb_changed_event(const char *mount_path, const char *mount_uuid, ms_st
 #ifdef _USE_DEVICED_DBUS
 void ms_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
 {
-       if (block_info->block_type == 0) {
-               MS_DBG_WARN("GET THE USB EVENT");
-               _ms_usb_changed_event(block_info->mount_path, block_info->mount_uuid, block_info->state);
-       } else {
-               MS_DBG_WARN("GET THE MMC EVENT");
-               _ms_mmc_changed_event(block_info->mount_path, block_info->state, block_info->flags);
-       }
+       MS_DBG_WARN("GET EXTERNAL EVENT");
+       _ms_usb_changed_event(block_info->mount_path, block_info->mount_uuid, block_info->state);
+
 }
 #else
 static void __ms_usb_add_event(const char *mount_path)
@@ -638,7 +446,7 @@ int ms_check_mounted_storage(uid_t uid)
        ms_connect_db(&handle, uid);
 
 #ifdef _USE_DEVICED_DBUS
-       ret = ms_sys_get_device_list(MS_STG_TYPE_USB, &added_list);
+       ret = ms_sys_get_device_list(MS_STG_TYPE_ALL, &added_list);
 #else
        ret = __ms_check_mounted_storage_list(&added_list);
 #endif
index c4f30b3..e93e23b 100755 (executable)
@@ -53,7 +53,6 @@ bool smarthub_reset_start;
 bool smarthub_reset;
 
 static void __ms_check_mediadb(void);
-static int __ms_check_mmc_status(void);
 static int __ms_check_usb_status(void);
 static void __ms_add_signal_handler(void);
 static void __ms_add_event_receiver(GIOChannel *channel);
@@ -602,47 +601,16 @@ static void __ms_add_signal_handler(void)
 }
 
 ////////////////////////////////////////////////////////////////////
-static int __ms_check_mmc_status(void)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       ms_stg_type_e stg_type = MS_STG_TYPE_MMC;
-       GArray *dev_list = NULL;
-
-       ret = ms_sys_get_device_list(stg_type, &dev_list);
-       if (ret == MS_MEDIA_ERR_NONE) {
-               if (dev_list != NULL) {
-                       MS_DBG_WARN("MMC FOUND[%d]", dev_list->len);
-                       int i = 0 ;
-                       int dev_num = dev_list->len;
-                       ms_block_info_s *block_info = NULL;
-
-                       for (i = 0; i < dev_num; i++) {
-                               block_info = (ms_block_info_s *)g_array_index(dev_list , ms_stg_type_e*, i);
-                               ms_mmc_insert_handler(block_info->mount_path);
-                       }
-
-                       ms_sys_release_device_list(&dev_list);
-               } else {
-                       MS_DBG_ERR("MMC NOT FOUND");
-                       ms_mmc_remove_handler(NULL);
-               }
-       } else {
-               MS_DBG_ERR("ms_sys_get_device_list failed");
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 static int __ms_check_usb_status(void)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       ms_stg_type_e stg_type = MS_STG_TYPE_USB;
+       ms_stg_type_e stg_type = MS_STG_TYPE_ALL;
        GArray *dev_list = NULL;
 
        ret = ms_sys_get_device_list(stg_type, &dev_list);
        if (ret == MS_MEDIA_ERR_NONE) {
                if (dev_list != NULL) {
-                       MS_DBG_WARN("USB FOUND[%d]", dev_list->len);
+                       MS_DBG_WARN("External storage found[%d]", dev_list->len);
                        int i = 0 ;
                        int dev_num = dev_list->len;
                        ms_block_info_s *block_info = NULL;
@@ -654,7 +622,7 @@ static int __ms_check_usb_status(void)
 
                        ms_sys_release_device_list(&dev_list);
                } else {
-                       MS_DBG_ERR("USB NOT FOUND");
+                       MS_DBG_ERR("External storage not found");
                        ms_usb_remove_handler(USB_STORAGE_REMOVED, NULL);
                }
        } else {
@@ -812,8 +780,6 @@ static void __ms_check_mediadb(void)
 #endif
 
        /* update external storage */
-       if (_USE_SDCARD)
-               __ms_check_mmc_status();
        __ms_check_usb_status();
 
 #ifdef _USE_SENIOR_MODE