char device_id[MS_UUID_SIZE] = {0,};
uid_t uid = MEDIA_DEFAULT_UID;
- if (mount_path != NULL) {
+ if (!mount_path)
+ return;
- ms_connect_db(&handle, uid);
+ ms_connect_db(&handle, uid);
- while (1) {
- memset(device_id, 0x0, sizeof(device_id));
- ret = ms_get_storage_id(handle, mount_path, device_id, uid);
+ while (1) {
+ memset(device_id, 0x0, sizeof(device_id));
+ ret = ms_get_storage_id(handle, mount_path, device_id, uid);
- MS_DBG_SWARN("removed path [%s %s]", mount_path, device_id);
+ MS_DBG_SWARN("removed path [%s %s]", mount_path, device_id);
- if (ret == MS_MEDIA_ERR_NONE) {
- ms_set_storage_validity(handle, device_id, 0, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("Device ID is INVALID");
+ break;
+ }
- /* update storage_id table set validity=0 first */
- if (ms_validity_change_all_items(handle, device_id, false, uid) != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("ms_validity_change_all_items failed");
- /* folder validity set 0 under the start_path in folder table*/
- if (ms_set_folder_validity(handle, device_id, mount_path, MS_INVALID, true, uid) != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("set_folder_validity failed");
+ ms_set_storage_validity(handle, device_id, 0, uid);
- if (ms_get_scanner_status()) {
- /*If the media scanner is running, the removed USB can be queueing in the job list.*/
- /*So try to remove it.*/
- ms_send_storage_otg_scan_request(mount_path, device_id, MS_SCAN_INVALID, uid);
- }
- } else {
- MS_DBG_ERR("Device ID is INVALID");
- break;
- }
+ /* update storage_id table set validity=0 first */
+ if (ms_validity_change_all_items(handle, device_id, false, uid) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("ms_validity_change_all_items failed");
+ /* folder validity set 0 under the start_path in folder table*/
+ if (ms_set_folder_validity(handle, device_id, mount_path, MS_INVALID, true, uid) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("set_folder_validity failed");
+
+ if (ms_get_scanner_status()) {
+ /*If the media scanner is running, the removed USB can be queueing in the job list.*/
+ /*So try to remove it.*/
+ ms_send_storage_otg_scan_request(mount_path, device_id, MS_SCAN_INVALID, uid);
}
-
- ms_disconnect_db(handle);
}
+
+ ms_disconnect_db(handle);
}
void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data)
MS_DBG_WARN("usb_event_callback END[%s]", action);
}
-static int __ms_check_mounted_storage_list(GArray **added_list)
+static void __msc_get_storage_path(usb_device_h usb_device, void *user_data)
{
- int ret = MS_MEDIA_ERR_NONE;
- int count = 0;
- int err = 0;
- usb_device_list_h list;
- usb_device_h device;
+ GPtrArray **res_list = (GPtrArray **)user_data;
char *mount_path = NULL;
- char *storage_path = NULL;
-
- err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
- if (err == 0) {
- if (*added_list == NULL)
- *added_list = g_array_new(FALSE, FALSE, sizeof(char*));
-
- count = usb_device_list_get_count(list);
- if (count > 0) {
- int i = 0;
- for (i = 0; i < count; i++) {
- if (i == 0) {
- if (0 == usb_device_list_get_first(list, &device) && device != NULL) {
- mount_path = usb_device_get_mountpath(device);
- if (mount_path != NULL) {
- MS_DBG_SWARN("mount_path [%s]", mount_path);
- storage_path = g_strdup(mount_path);
- g_array_append_val(*added_list, storage_path);
- }
- } else {
- MS_DBG_ERR(" FAILED TO usb_device_list_get_first");
- }
- } else {
- if (0 == usb_device_list_get_next(list, &device) && device != NULL) {
- mount_path = usb_device_get_mountpath(device);
- if (mount_path != NULL) {
- MS_DBG_SWARN("mount_path [%s]", mount_path);
- storage_path = g_strdup(mount_path);
- g_array_append_val(*added_list, storage_path);
- }
- } else {
- MS_DBG_ERR(" FAILED TO usb_device_list_get_next");
- }
- }
- }
- }
- usb_device_free_device_list(list);
- } else {
- MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
- ret = MS_MEDIA_ERR_INTERNAL;
+ mount_path = usb_device_get_mountpath(usb_device);
+ if (mount_path) {
+ MS_DBG_SWARN("mount_path [%s]", mount_path);
+ g_ptr_array_add(*res_list, g_strdup(mount_path));
}
-
- return ret;
}
int ms_check_mounted_storage(uid_t uid)
int ret = MS_MEDIA_ERR_NONE;
int count = 0;
int i = 0;
- GArray *added_list = NULL;
+ GPtrArray *added_list = NULL;
char *mounted_path = NULL;
char *storage_id = NULL;
ms_dir_scan_type_t scan_type = MS_SCAN_ALL;
ms_connect_db(&handle, uid);
- ret = __ms_check_mounted_storage_list(&added_list);
- if (ret != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("__ms_check_mounted_storage_list failed");
-
- if (added_list != NULL) {
- count = added_list->len;
-
- for (i = 0; i < count; i++) {
- mounted_path = g_array_index(added_list, char *, i);
- /* read deive information */
- ret = ms_read_device_info(mounted_path, &storage_id);
-
- if (storage_id == NULL) {
- /* in this case, all new storage */
- char *device_uuid = NULL;
- ret = ms_genarate_uuid(&device_uuid);
- ret = ms_write_device_info(mounted_path, device_uuid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_write_device_info failed");
- MS_SAFE_FREE(device_uuid);
- continue;
- }
- ret = ms_insert_storage(handle, device_uuid, mounted_path, uid);
+ added_list = g_ptr_array_new_with_free_func(g_free);
- scan_type = MS_SCAN_ALL;
- storage_id = g_strdup(device_uuid);
+ usb_mass_storage_foreach(__msc_get_storage_path, &added_list);
+
+ count = added_list->len;
+ for (i = 0; i < count; i++) {
+ mounted_path = g_ptr_array_index(added_list, i);
+ /* read deive information */
+ ret = ms_read_device_info(mounted_path, &storage_id);
+
+ if (!storage_id) {
+ /* in this case, all new storage */
+ char *device_uuid = NULL;
+ ret = ms_genarate_uuid(&device_uuid);
+ ret = ms_write_device_info(mounted_path, device_uuid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_write_device_info failed");
MS_SAFE_FREE(device_uuid);
- } else {
- /* update storage information into media DB */
- int validity = 0;
- char *db_storage_path = NULL;
-
- ret = ms_check_storage(handle, storage_id, &db_storage_path, &validity, uid);
- if (ret == 0) {
- if (validity == 1) {
- MS_DBG_ERR("This storage is already updated.");
- g_free(db_storage_path);
- continue;
- }
+ continue;
+ }
+ ret = ms_insert_storage(handle, device_uuid, mounted_path, uid);
+
+ scan_type = MS_SCAN_ALL;
+ storage_id = g_strdup(device_uuid);
+
+ MS_SAFE_FREE(device_uuid);
+ } else {
+ /* update storage information into media DB */
+ int validity = 0;
+ char *db_storage_path = NULL;
+
+ ret = ms_check_storage(handle, storage_id, &db_storage_path, &validity, uid);
+ if (ret == 0) {
+ if (validity == 1) {
+ MS_DBG_ERR("This storage is already updated.");
+ g_free(db_storage_path);
+ g_free(storage_id);
+ storage_id = NULL;
+ continue;
+ }
- if (db_storage_path != NULL) {
- MS_DBG_SWARN("%s %s", mounted_path, db_storage_path);
- if (strcmp(mounted_path, db_storage_path)) {
- /* update storage path */
- MS_DBG_SWARN("update storage from %s to %s", db_storage_path, mounted_path);
- ret = ms_update_storage(handle, storage_id, mounted_path, uid);
- }
-
- ms_set_storage_validity(handle, storage_id, 1, uid);
- /* update storage_id table set validity=0 first */
- ms_validity_change_all_items(handle, storage_id, false, uid);
- ms_set_folder_validity(handle, storage_id, mounted_path, MS_INVALID, true, uid);
- /* update folder table set scan_status=0 first */
- ms_set_folder_scan_status(handle, storage_id, NULL, MS_DIR_SCAN_NONE, uid);
-
- scan_type = MS_SCAN_PART;
- g_free(db_storage_path);
- } else {
- /* there is no information of this storage in Media DB */
- MS_DBG_SWARN("insert storage %s", mounted_path);
- ret = ms_insert_storage(handle, storage_id, mounted_path, uid);
- scan_type = MS_SCAN_ALL;
+ if (db_storage_path) {
+ MS_DBG_SWARN("%s %s", mounted_path, db_storage_path);
+ if (strcmp(mounted_path, db_storage_path)) {
+ /* update storage path */
+ MS_DBG_SWARN("update storage from %s to %s", db_storage_path, mounted_path);
+ ret = ms_update_storage(handle, storage_id, mounted_path, uid);
}
+
+ ms_set_storage_validity(handle, storage_id, 1, uid);
+ /* update storage_id table set validity=0 first */
+ ms_validity_change_all_items(handle, storage_id, false, uid);
+ ms_set_folder_validity(handle, storage_id, mounted_path, MS_INVALID, true, uid);
+ /* update folder table set scan_status=0 first */
+ ms_set_folder_scan_status(handle, storage_id, NULL, MS_DIR_SCAN_NONE, uid);
+
+ scan_type = MS_SCAN_PART;
+ g_free(db_storage_path);
} else {
/* there is no information of this storage in Media DB */
MS_DBG_SWARN("insert storage %s", mounted_path);
ret = ms_insert_storage(handle, storage_id, mounted_path, uid);
scan_type = MS_SCAN_ALL;
}
+ } else {
+ /* there is no information of this storage in Media DB */
+ MS_DBG_SWARN("insert storage %s", mounted_path);
+ ret = ms_insert_storage(handle, storage_id, mounted_path, uid);
+ scan_type = MS_SCAN_ALL;
}
-
- if (ret != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("error : ms_update_storage or ms_insert_storage failed");
-
- /* request to update media db */
- ret = ms_insert_folder(handle, storage_id, mounted_path, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("error : ms_insert_folder failed");
-
- ms_send_storage_otg_scan_request(mounted_path, storage_id, scan_type, uid);
- g_free(storage_id);
}
- for (i = 0; i < count; i++) {
- mounted_path = g_array_index(added_list, char*, 0);
- g_free(mounted_path);
- g_array_remove_index(added_list, 0);
- }
+ if (ret != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("error : ms_update_storage or ms_insert_storage failed");
- g_array_free(added_list, FALSE);
- added_list = NULL;
+ /* request to update media db */
+ ret = ms_insert_folder(handle, storage_id, mounted_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("error : ms_insert_folder failed");
+
+ ms_send_storage_otg_scan_request(mounted_path, storage_id, scan_type, uid);
+ g_free(storage_id);
+ storage_id = NULL;
}
+ g_ptr_array_free(added_list, TRUE);
+ added_list = NULL;
+
/*disconnect form media db*/
ms_disconnect_db(handle);