From 7e543083d1cb401ab671a8d87bac082bd642f317 Mon Sep 17 00:00:00 2001 From: Hyihong Chae Date: Thu, 30 Jun 2016 22:00:40 +0900 Subject: [PATCH] modify internal storage path Change-Id: Ie1360521b69392ef926f17b9a2bc140afb177874 Signed-off-by: HyiHong Chae --- include/mtp_config.h | 2 +- include/util/mtp_util.h | 4 ++-- src/entity/mtp_device.c | 9 +++++---- src/entity/mtp_store.c | 20 ++++++++++++------- src/mtp_cmd_handler_util.c | 5 ++++- src/mtp_init.c | 12 +++++++----- src/mtp_inoti_handler.c | 8 ++++++-- src/util/mtp_support.c | 6 ++++-- src/util/mtp_util.c | 49 +++++++++++++++++++++++++++++++++++++++------- 9 files changed, 84 insertions(+), 31 deletions(-) diff --git a/include/mtp_config.h b/include/mtp_config.h index 561e5d9..b4249e1 100755 --- a/include/mtp_config.h +++ b/include/mtp_config.h @@ -77,7 +77,7 @@ * Transport related configuration */ /* Internal Storage */ -#define MTP_STORE_PATH_CHAR "/home/owner/content" +#define MTP_STORE_PATH_CHAR "/opt/home/owner/content" /* External Storage */ #define MTP_EXTERNAL_PATH_CHAR "/opt/media/SDCardA1" diff --git a/include/util/mtp_util.h b/include/util/mtp_util.h index 4e825a3..45064be 100755 --- a/include/util/mtp_util.h +++ b/include/util/mtp_util.h @@ -141,6 +141,6 @@ void _util_set_local_mmc_status(const phone_status_t val); void _util_get_usbmode_status(phone_status_t *val); phone_status_t _util_get_local_usbmode_status(void); void _util_set_local_usbmode_status(const phone_status_t val); -void _util_get_external_path(char *ext_path); - +void _util_get_external_path(char *external_path); +void _util_get_internal_path(char *internal_path); #endif /* _MTP_UTIL_H_ */ diff --git a/src/entity/mtp_device.c b/src/entity/mtp_device.c index c2e6f6b..0539974 100755 --- a/src/entity/mtp_device.c +++ b/src/entity/mtp_device.c @@ -603,16 +603,17 @@ static mtp_bool __add_store_to_device(store_type_t store_type) mtp_char *storage_path = NULL; mtp_uint32 store_id = 0; file_attr_t attrs = { 0, }; - char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char sto_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; switch (store_type) { case MTP_STORAGE_INTERNAL: - storage_path = MTP_STORE_PATH_CHAR; + _util_get_internal_path(sto_path); + storage_path = (mtp_char *)sto_path; store_id = MTP_INTERNAL_STORE_ID; break; case MTP_STORAGE_EXTERNAL: - _util_get_external_path(ext_path); - storage_path = (mtp_char *)ext_path; + _util_get_external_path(sto_path); + storage_path = (mtp_char *)sto_path; store_id = MTP_EXTERNAL_STORE_ID; break; default: diff --git a/src/entity/mtp_store.c b/src/entity/mtp_store.c index 814d062..7b9cba8 100755 --- a/src/entity/mtp_store.c +++ b/src/entity/mtp_store.c @@ -90,16 +90,17 @@ void _entity_update_store_info_run_time(store_info_t *info, mtp_bool _entity_get_store_path_by_id(mtp_uint32 store_id, mtp_char *path) { - char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char sto_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; switch(store_id) { case MTP_INTERNAL_STORE_ID : - g_strlcpy(path, MTP_STORE_PATH_CHAR, + _util_get_internal_path(sto_path); + g_strlcpy(path, sto_path, MTP_MAX_PATHNAME_SIZE + 1); break; case MTP_EXTERNAL_STORE_ID : - _util_get_external_path(ext_path); - g_strlcpy(path, ext_path, + _util_get_external_path(sto_path); + g_strlcpy(path, sto_path, MTP_MAX_PATHNAME_SIZE + 1); break; default : @@ -178,13 +179,15 @@ mtp_uint32 _entity_get_store_id_by_path(const mtp_char *path_name) { mtp_uint32 store_id = 0; char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; retv_if(NULL == path_name, FALSE); _util_get_external_path(ext_path); + _util_get_internal_path(inter_path); - if (!strncmp(path_name, MTP_STORE_PATH_CHAR, - strlen(MTP_STORE_PATH_CHAR))) { + if (!strncmp(path_name, inter_path, + strlen(inter_path))) { store_id = MTP_INTERNAL_STORE_ID; } else if (!strncmp(path_name, ext_path, strlen(ext_path))) { @@ -1198,8 +1201,11 @@ void _entity_list_modified_files(mtp_uint32 minutes) mtp_char command[FIND_CMD_LEN] = { 0 }; if (TRUE == _device_is_store_mounted(MTP_STORAGE_INTERNAL)) { + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + _util_get_internal_path(inter_path); + g_snprintf(command, FIND_CMD_LEN, FIND_CMD, - MTP_STORE_PATH_CHAR, minutes, + inter_path, minutes, MTP_FILES_MODIFIED_FILES); DBG("find query is [%s]\n", command); ret = system(command); diff --git a/src/mtp_cmd_handler_util.c b/src/mtp_cmd_handler_util.c index a3661ef..a0c9927 100755 --- a/src/mtp_cmd_handler_util.c +++ b/src/mtp_cmd_handler_util.c @@ -276,6 +276,9 @@ mtp_err_t _hutil_add_object_entry(obj_info_t *obj_info, mtp_char *file_name, mtp_char wmp_hidden_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; if (obj_info->store_id == MTP_INTERNAL_STORE_ID) { + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + _util_get_internal_path(inter_path); + g_snprintf(wmp_hidden_path, MTP_MAX_PATHNAME_SIZE + 1, "%s/%s/%s", MTP_USER_DIRECTORY, @@ -283,7 +286,7 @@ mtp_err_t _hutil_add_object_entry(obj_info_t *obj_info, mtp_char *file_name, MTP_FILE_NAME_WMPINFO_XML); g_snprintf(wmp_info_path, MTP_MAX_PATHNAME_SIZE + 1, - "%s/%s", MTP_STORE_PATH_CHAR, + "%s/%s", inter_path, MTP_FILE_NAME_WMPINFO_XML); } else { char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; diff --git a/src/mtp_init.c b/src/mtp_init.c index bd98a3e..0cfe46f 100755 --- a/src/mtp_init.c +++ b/src/mtp_init.c @@ -95,6 +95,7 @@ void _mtp_init(add_rem_store_t sel) mtp_bool ret = 0; int vconf_ret = 0; mtp_int32 error = 0; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; DBG("Initialization start!"); @@ -146,10 +147,11 @@ void _mtp_init(add_rem_store_t sel) } /* Internal Storage */ - if (access(MTP_STORE_PATH_CHAR, F_OK) < 0) { - if (FALSE == _util_dir_create(MTP_STORE_PATH_CHAR, &error)) { + _util_get_internal_path(inter_path); + if (access(inter_path, F_OK) < 0) { + if (FALSE == _util_dir_create((const mtp_char *)inter_path, &error)) { ERR("Cannot make directory!! [%s]\n", - MTP_STORE_PATH_CHAR); + inter_path); goto MTP_INIT_FAIL; } } @@ -158,7 +160,7 @@ void _mtp_init(add_rem_store_t sel) char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; _util_get_external_path(ext_path); if (access(ext_path, F_OK) < 0) { - if (FALSE == _util_dir_create(ext_path, &error)) { + if (FALSE == _util_dir_create((const mtp_char *)ext_path, &error)) { ERR("Cannot make directory!! [%s]\n", ext_path); goto MTP_INIT_FAIL; @@ -168,7 +170,7 @@ void _mtp_init(add_rem_store_t sel) #ifndef MTP_SUPPORT_HIDE_WMPINFO_XML /* Update WMPInfo.xml for preventing frequent saving */ ret = _util_create_path(wmpinfopath, sizeof(wmpinfopath), - MTP_STORE_PATH_CHAR, MTP_FILE_NAME_WMPINFO_XML); + (const mtp_char *)inter_path, MTP_FILE_NAME_WMPINFO_XML); if (FALSE == ret) { ERR("szWMPInfoPath is too long"); goto MTP_INIT_FAIL; diff --git a/src/mtp_inoti_handler.c b/src/mtp_inoti_handler.c index 56dcdd4..47faeaa 100755 --- a/src/mtp_inoti_handler.c +++ b/src/mtp_inoti_handler.c @@ -486,9 +486,11 @@ static void __remove_recursive_inoti_watch(mtp_char *path) static void __clean_up_inoti(void *data) { char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; _util_get_external_path(ext_path); + _util_get_internal_path(inter_path); - __remove_recursive_inoti_watch(MTP_STORE_PATH_CHAR); + __remove_recursive_inoti_watch((mtp_char *)inter_path); __remove_recursive_inoti_watch((mtp_char *)ext_path); __destroy_inoti_open_files_list(); @@ -561,9 +563,11 @@ static void __process_object_added_event(mtp_char *fullpath, parent_obj = _entity_get_object_from_store_by_path(store, parent_path); if (NULL == parent_obj) { char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; _util_get_external_path(ext_path); + _util_get_internal_path(inter_path); - if (!g_strcmp0(parent_path, MTP_STORE_PATH_CHAR) || + if (!g_strcmp0(parent_path, inter_path) || !g_strcmp0(parent_path, ext_path)) { DBG("parent is the root folder"); diff --git a/src/util/mtp_support.c b/src/util/mtp_support.c index 4f715ba..144c2cd 100755 --- a/src/util/mtp_support.c +++ b/src/util/mtp_support.c @@ -469,14 +469,16 @@ mtp_bool _util_is_path_len_valid(const mtp_char *path) static mtp_uint32 external_store_len = 0; char ext_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; retv_if(path == NULL, FALSE); _util_get_external_path(ext_path); + _util_get_internal_path(inter_path); if (!is_initialized) { is_initialized = TRUE; - internal_store_len = strlen(MTP_STORE_PATH_CHAR); + internal_store_len = strlen(inter_path); external_store_len = strlen(ext_path); max_store_len = internal_store_len > external_store_len ? @@ -485,7 +487,7 @@ mtp_bool _util_is_path_len_valid(const mtp_char *path) DBG("max store len : [%u]\n", max_store_len); } - if (!strncmp(path, MTP_STORE_PATH_CHAR, internal_store_len)) { + if (!strncmp(path, inter_path, internal_store_len)) { root_path_len = internal_store_len; } else if (!strncmp(path, ext_path, external_store_len)) { root_path_len = external_store_len; diff --git a/src/util/mtp_util.c b/src/util/mtp_util.c index ef614c6..83731f1 100755 --- a/src/util/mtp_util.c +++ b/src/util/mtp_util.c @@ -293,26 +293,61 @@ void _util_set_local_usbmode_status(const phone_status_t val) return; } -static bool _util_device_supported_cb(int storage_id, storage_type_e type, +static bool _util_device_external_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data) { - char *ext_path = (char *)user_data; + char *storage_path = (char *)user_data; + + DBG("storage id: %d, path: %s", storage_id, path); if (type == STORAGE_TYPE_EXTERNAL && path != NULL) { - strncpy(ext_path, path, strlen(path)); - DBG("external storage path : %s", ext_path); + strncpy(storage_path, path, strlen(path)); + DBG("external storage path : %s", storage_path); } return TRUE; } -void _util_get_external_path(char *ext_path) +void _util_get_external_path(char *external_path) { int error = STORAGE_ERROR_NONE; - error = storage_foreach_device_supported(_util_device_supported_cb, ext_path); + error = storage_foreach_device_supported(_util_device_external_supported_cb, external_path); if (error != STORAGE_ERROR_NONE) { ERR("get external storage path Fail"); - strncpy(ext_path, MTP_EXTERNAL_PATH_CHAR, strlen(MTP_EXTERNAL_PATH_CHAR)); + strncpy(external_path, MTP_EXTERNAL_PATH_CHAR, strlen(MTP_EXTERNAL_PATH_CHAR)); + } +} + +static bool _util_device_internal_supported_cb(int storage_id, storage_type_e type, + storage_state_e state, const char *path, void *user_data) +{ + char *storage_path = (char *)user_data; + + DBG("storage id: %d, path: %s", storage_id, path); + + if (type == STORAGE_TYPE_INTERNAL && path != NULL) { + strncpy(storage_path, path, strlen(path)); + DBG("internal storage path : %s", storage_path); + + if (storage_get_root_directory(storage_id, &storage_path) != STORAGE_ERROR_NONE) { + ERR("get internal storage path Fail"); + return FALSE; + } else { + DBG("get internal storage path : %s", storage_path); + } + } + + return TRUE; +} + +void _util_get_internal_path(char *internal_path) +{ + int error = STORAGE_ERROR_NONE; + error = storage_foreach_device_supported(_util_device_internal_supported_cb, internal_path); + + if (error != STORAGE_ERROR_NONE) { + ERR("get internal storage path Fail"); + strncpy(internal_path, MTP_STORE_PATH_CHAR, strlen(MTP_STORE_PATH_CHAR)); } } -- 2.7.4