4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <dirent.h> /* Defines DT_* constants */
28 #include <sys/syscall.h>
34 #include "media-util.h"
35 #include "media-server-ipc.h"
36 #include "media-common-utils.h"
37 #include "media-common-db-svc.h"
38 #include "media-scanner-dbg-v2.h"
39 #include "media-scanner-common-v2.h"
40 #include "media-scanner-db-manage-v2.h"
41 #include "media-scanner-socket-v2.h"
42 #include "media-scanner-extract-v2.h"
44 extern bool power_off2;
45 GAsyncQueue *storage_extract_queue;
46 GAsyncQueue *folder_extract_queue;
47 static GMutex extract_req_mutex;
48 static GMutex extract_blocked_mutex;
49 static char *g_extract_cancel_path;
50 static char *g_extract_blocked_path;
51 bool g_directory_extract_processing;
52 static int stg_extract_status;
54 static GMutex extract_item_mutex;
55 static GMutex decode_mutex;
57 static s_extract_item* cancel_extract_item = NULL;
58 static s_extract_item* cur_extract_item = NULL;
60 static GCond extract_data_cond;
61 static GMutex extract_data_mutex;
62 #define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
64 #define NORMAL_EVENT 0
66 static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid, bool is_end);
67 static void __msc_set_storage_extract_status(ms_storage_scan_status_e status);
68 static void __msc_get_storage_extract_status(ms_storage_scan_status_e *status);
69 static void __msc_resume_extract(void);
70 static void __msc_pause_extract(void);
71 static int __msc_extract_set_db_status(ms_db_status_type_t status);
72 static void __msc_del_cancel_extract_item(void);
73 static void __msc_set_cur_extract_item(const char* cur_path, int pid);
74 static void __msc_del_cur_extract_item(void);
75 static void __msc_del_extract_blocked_path(const char* blocked_path);
83 static int __msc_folder_bulk_extract(sqlite3 *handle, const char* storage_id, int storage_type, const char *path, int scan_type, int pid, uid_t uid, unsigned int *io_err_count, bool is_end);
85 void msc_init_extract_thread(void)
87 if (!storage_extract_queue) storage_extract_queue = g_async_queue_new();
88 if (!folder_extract_queue) folder_extract_queue = g_async_queue_new();
90 g_mutex_init(&extract_req_mutex);
91 g_mutex_init(&extract_blocked_mutex);
92 g_mutex_init(&extract_data_mutex);
94 g_mutex_init(&extract_item_mutex);
95 g_mutex_init(&decode_mutex);
97 g_cond_init(&extract_data_cond);
100 void msc_deinit_extract_thread(void)
102 if (storage_extract_queue) g_async_queue_unref(storage_extract_queue);
103 if (folder_extract_queue) g_async_queue_unref(folder_extract_queue);
105 g_mutex_clear(&extract_req_mutex);
106 g_mutex_clear(&extract_blocked_mutex);
107 g_mutex_clear(&extract_data_mutex);
109 g_mutex_clear(&extract_item_mutex);
110 g_mutex_clear(&decode_mutex);
112 g_cond_clear(&extract_data_cond);
115 int __msc_folder_bulk_extract(sqlite3 *handle, const char* storage_id, int storage_type, const char *path, int scan_type, int pid, uid_t uid, unsigned int *io_err_count, bool is_end)
117 MS_DBG_WARN("begin of __msc_folder_bulk_extract");
118 int ret = MS_MEDIA_ERR_NONE;
119 int tmp_ret = MS_MEDIA_ERR_NONE;
120 GArray *data_array = NULL;
121 ms_item_info_s* db_data = NULL;
122 int extract_count = 0;
125 ret = ms_get_extract_list(handle, storage_id, storage_type, scan_type, path, is_end, uid, (void*)&data_array);
126 if (ret != MS_MEDIA_ERR_NONE) {
127 MS_DBG_ERR("ms_get_extract_list failed!!!");
128 return MS_MEDIA_ERR_NONE;
131 if (data_array == NULL) {
132 MS_DBG_ERR("data_array is NULL!!!");
133 return MS_MEDIA_ERR_NONE;
136 while (data_array->len != 0) {
137 tmp_ret = MS_MEDIA_ERR_NONE;
140 ret = __msc_check_extract_stop_status(scan_type, path, pid, is_end);
141 if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
142 MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
146 db_data = g_array_index(data_array, ms_item_info_s*, 0);
147 g_array_remove_index(data_array, 0);
149 g_mutex_lock(&decode_mutex);
150 tmp_ret = ms_update_one_extract_item(handle, storage_id, storage_type, db_data);
151 g_mutex_unlock(&decode_mutex);
152 if (tmp_ret == MS_MEDIA_ERR_NONE)
154 else if (tmp_ret == MS_MEDIA_ERR_INTERNAL)
158 MS_SAFE_FREE(db_data->path);
159 MS_SAFE_FREE(db_data);
163 if (sleep_count % 5 == 0) {
165 usleep(SCAN_SLEEP_TIME);
169 if (extract_count > 0)
170 ms_query_do_update_list(handle);
172 while (data_array->len != 0) {
174 db_data = g_array_index(data_array, ms_item_info_s*, 0);
175 g_array_remove_index(data_array, 0);
178 MS_SAFE_FREE(db_data->path);
179 MS_SAFE_FREE(db_data);
183 g_array_free(data_array, FALSE);
186 MS_DBG_WARN("end of __msc_folder_bulk_extract");
190 gpointer msc_folder_extract_thread(gpointer data)
192 ms_comm_msg_s *extract_data = NULL;
193 int ret = MS_MEDIA_ERR_NONE;
194 sqlite3 *handle = NULL;
196 ms_user_storage_type_e storage_type;
197 char *storage_id = NULL;
198 char *update_path = NULL;
199 unsigned int io_err_count = 0;
200 uid_t uid = MEDIA_DEFAULT_UID;
202 int end_flag = NORMAL_EVENT;
203 ms_noti_type_e noti_type = MS_ITEM_INSERT;
206 extract_data = g_async_queue_pop(folder_extract_queue);
207 if (extract_data->pid == POWEROFF) {
208 MS_DBG_ERR("power off");
212 MS_DBG_WARN("DIRECTORY EXTRACT START [%.*s %d]", MAX_MSG_SIZE, extract_data->msg, extract_data->msg_type);
216 __msc_set_cur_extract_item(extract_data->msg, extract_data->pid);
217 g_directory_extract_processing = true;
218 uid = extract_data->uid;
220 /*connect to media db, if conneting is failed, db updating is stopped*/
221 ret = ms_connect_db(&handle, uid);
222 if (ret != MS_MEDIA_ERR_NONE) {
223 MS_DBG_ERR("ms_connect_db failed");
227 scan_type = extract_data->msg_type;
228 noti_type = extract_data->noti_type;
230 storage_id = g_strdup(extract_data->storage_id);
231 if (storage_id == NULL) {
232 MS_DBG_ERR("storage_id NULL");
233 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
237 MS_DBG("path : [%.*s], storage_id : [%s]", MAX_MSG_SIZE, extract_data->msg, storage_id);
239 update_path = g_strdup(extract_data->msg);
241 if (strlen(storage_id) == 0) {
242 MS_DBG_ERR("storage_id length is 0. There is no information of your request [%.*s]", MAX_MSG_SIZE, extract_data->msg);
243 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
247 if (scan_type != MS_MSG_DIRECTORY_SCANNING
248 && scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
249 MS_DBG_ERR("Invalid request");
250 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
253 end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
255 ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
256 if (ret != MS_MEDIA_ERR_NONE) {
257 MS_DBG_ERR("ms_user_get_storage_type failed");
261 ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid, end_flag);
263 if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
264 MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
268 /*insert data into media db */
269 ret = msc_check_db_size(uid, extract_data->msg_type);
270 if (ret != MS_MEDIA_ERR_NONE) {
271 MS_DBG_ERR("NOT ENOUGH MEMORY");
272 if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
273 ret = MS_MEDIA_ERR_NONE;
278 ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, extract_data->pid, uid, &io_err_count, end_flag);
281 g_directory_extract_processing = false;
283 MS_DBG_ERR("power off");
290 if (extract_data->result) {
291 MS_DBG_ERR("MS_MSG_SCANNER_COMPLETE");
292 if (noti_type == MS_ITEM_INSERT || noti_type == MS_ITEM_UPDATE) {
293 /*send notification*/
294 char *folder_uuid = NULL;
295 ms_get_folder_id(handle, storage_id, extract_data->msg, &folder_uuid);
296 MS_DBG_WARN("storage_id = [%s], dir Path = [%s], folder_uuid = [%s], noti_type = [%d]", storage_id, update_path, folder_uuid, noti_type);
297 ms_send_dir_update_noti(update_path, folder_uuid, noti_type, extract_data->pid);
299 extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
300 msc_send_result(ret, extract_data);
302 MS_DBG_ERR("MS_MSG_SCANNER_PARTIAL");
303 msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, extract_data->pid, extract_data->msg);
308 g_free(extract_data);
313 __msc_del_cur_extract_item();
314 __msc_del_cancel_extract_item();
315 if (msc_get_disc_dir_scan_status()) {
316 MS_DBG("[DISC ACCESS END]");
317 msc_set_disc_dir_scan_status(false);
319 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
320 if (disc_state == MS_DISC_ACCESS) {
321 MS_DBG_WARN("[CHANGE DISC STATE]");
322 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
326 MS_DBG_WARN("DIRECTORY EXTRACT END [%d]", ret);
328 ms_storage_scan_status_e storage_scan_status = MS_STORAGE_SCAN_NONE;
329 __msc_get_storage_extract_status(&storage_scan_status);
331 /*get storage list and scan status from media db*/
332 if (storage_scan_status != MS_STORAGE_SCAN_COMPLETE) {
333 __msc_resume_extract();
334 MS_DBG_WARN("extract RESUME OK");
337 /*disconnect form media db*/
339 ms_disconnect_db(handle);
340 usleep(SCAN_SLEEP_TIME);
344 __msc_resume_extract();
347 g_free(extract_data);
351 ms_disconnect_db(handle);
356 gpointer msc_storage_extract_thread(gpointer data)
358 ms_comm_msg_s *extract_data = NULL;
359 int ret = MS_MEDIA_ERR_NONE;
360 sqlite3 *handle = NULL;
361 ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
363 char *update_path = NULL;
364 unsigned int io_err_count = 0;
365 uid_t uid = MEDIA_DEFAULT_UID;
367 int end_flag = NORMAL_EVENT;
368 int tem_ret = MS_MEDIA_ERR_NONE;
371 __msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
372 extract_data = g_async_queue_pop(storage_extract_queue);
373 if (extract_data->pid == POWEROFF) {
374 MS_DBG_ERR("power off");
378 __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_PROCESSING);
382 MS_DBG_WARN("STORAGE extract START extract len is %d ", g_async_queue_length(storage_extract_queue));
384 scan_type = extract_data->msg_type;
385 if (scan_type != MS_MSG_STORAGE_ALL
386 && scan_type != MS_MSG_STORAGE_PARTIAL) {
387 MS_DBG_ERR("Invalid request[%d]", scan_type);
388 msc_remove_extract_request(extract_data);
389 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
393 uid = extract_data->uid;
395 /*connect to media db, if conneting is failed, db updating is stopped*/
396 ret = ms_connect_db(&handle, uid);
397 if (ret != MS_MEDIA_ERR_NONE) {
398 MS_DBG_ERR("ms_connect_db falied!");
402 end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
403 update_path = g_strdup(extract_data->msg);
404 if (!MS_STRING_VALID(update_path)) {
405 MS_DBG_ERR("Invalid update_path");
406 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
409 MS_DBG_WARN("extract storage_id is [%s], path [%s]", extract_data->storage_id, update_path);
410 ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
411 if (ret != MS_MEDIA_ERR_NONE) {
412 MS_DBG_ERR("ms_user_get_storage_type failed");
415 if (storage_type == MS_USER_STORAGE_EXTERNAL_USB) {
416 if (!ms_storage_mount_status(update_path)) {
417 MS_DBG_ERR("%s is unmounted", update_path);
418 ret = MS_MEDIA_ERR_USB_UNMOUNTED;
419 msc_remove_extract_request(extract_data);
423 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, uid);
424 __msc_extract_set_db_status(MS_DB_UPDATING);
426 ret = msc_check_db_size(uid, extract_data->msg_type);
427 if (ret != MS_MEDIA_ERR_NONE) {
428 MS_DBG_ERR("NOT ENOUGH MEMORY");
429 __msc_extract_set_db_status(MS_DB_STOPPED);
434 ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, extract_data->pid, uid, &io_err_count, end_flag);
435 MS_DBG_WARN("extract PAUSE");
436 __msc_pause_extract();
437 MS_DBG_WARN("extract RESUME");
439 tem_ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid, end_flag);
440 if (tem_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
441 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, uid);
442 __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
443 MS_DBG_WARN("storage scan force stopped");
444 /* set vconf key db extract status */
445 __msc_extract_set_db_status(MS_DB_STOPPED);
447 msc_remove_extract_request(extract_data);
450 if (extract_data->result) {
451 MS_DBG_WARN("extract_data->result is true, MS_STORAGE_SCAN_COMPLETE");
452 __msc_del_extract_blocked_path(update_path);
453 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
454 __msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
456 /* send notification */
457 ms_send_dir_update_noti(update_path, NULL, MS_ITEM_UPDATE, extract_data->pid);
458 /* set vconf key db extract status */
459 __msc_extract_set_db_status(MS_DB_UPDATED);
466 if (strncmp(update_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) {
467 if (msc_get_disc_stg_scan_status()) {
468 MS_DBG("[DISC ACCESS STOP]");
469 msc_set_disc_stg_scan_status(false);
471 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
472 if (disc_state == MS_DISC_ACCESS) {
473 MS_DBG_WARN("[CHANGE DISC STATE]");
474 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
484 MS_DBG_ERR("power off");
488 /*disconnect form media db*/
489 if (handle) ms_disconnect_db(handle);
494 if (extract_data->result) {
495 extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
496 msc_send_result(ret, extract_data);
499 g_free(extract_data);
502 MS_DBG_WARN("STORAGE EXTRACT END[%d]", ret);
503 usleep(SCAN_SLEEP_TIME);
507 MS_SAFE_FREE(extract_data);
509 ms_disconnect_db(handle);
514 void msc_insert_exactor_request(int message_type, bool ins_status, const char *storage_id, const char *path, int pid, uid_t uid, ms_noti_type_e noti_type)
516 ms_comm_msg_s *extract_data = g_new0(ms_comm_msg_s, 1);
518 extract_data->msg_type = message_type;
519 extract_data->pid = pid;
520 extract_data->uid = uid;
521 extract_data->result = ins_status;
522 extract_data->noti_type = noti_type;
523 SAFE_STRLCPY(extract_data->msg, path, sizeof(extract_data->msg));
524 SAFE_STRLCPY(extract_data->storage_id, storage_id, sizeof(extract_data->storage_id));
526 if (message_type == MS_MSG_STORAGE_ALL || message_type == MS_MSG_STORAGE_PARTIAL || message_type == MS_MSG_STORAGE_INVALID) {
527 g_async_queue_push(storage_extract_queue, extract_data);
528 MS_DBG("insert to storage exactor queue. msg_type [%d]", ins_status);
529 } else if (message_type == MS_MSG_DIRECTORY_SCANNING || message_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
530 g_async_queue_push(folder_extract_queue, extract_data);
531 MS_DBG("insert to dir exactor queue. msg_type [%d]", ins_status);
533 MS_DBG_ERR("try to insert to exactor scan with msg_type [%d]", message_type);
534 g_free(extract_data);
538 int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
543 if (recv_msg == NULL) {
544 MS_DBG_ERR("recv_msg is null");
545 return MS_MEDIA_ERR_INVALID_PARAMETER;
547 const char *storageid = recv_msg->storage_id;
548 int len = g_async_queue_length(storage_extract_queue);
549 ms_comm_msg_s *msg = NULL;
550 GAsyncQueue *temp_queue = NULL;
552 MS_DBG_WARN("exactor_req_mutex is LOCKED");
553 g_mutex_lock(&extract_req_mutex);
556 MS_DBG_ERR("Request is not stacked");
557 goto END_REMOVE_REQUEST;
560 temp_queue = g_async_queue_new();
562 for (i = 0; i < len; i++) {
563 /*create new queue to compare request*/
564 msg = g_async_queue_pop(storage_extract_queue);
565 if ((strcmp(msg->storage_id, storageid) == 0)) {
567 MS_DBG_WARN("force stop storage scan");
568 msg->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
569 msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
573 g_async_queue_push(temp_queue, msg);
576 len = g_async_queue_length(temp_queue);
578 for (j = 0; j < len; j++) {
579 msg = g_async_queue_pop(temp_queue);
581 g_async_queue_push(storage_extract_queue, msg);
583 g_async_queue_unref(temp_queue);
586 g_mutex_unlock(&extract_req_mutex);
587 MS_DBG_WARN("exactor_req_mutex is UNLOCKED");
588 __msc_del_extract_blocked_path(recv_msg->msg);
590 return MS_MEDIA_ERR_NONE;
593 static int __msc_set_extract_item(s_extract_item** item, const char* path, int pid)
595 s_extract_item* extract_item = *item;
599 extract_item = g_new0(s_extract_item, 1);
601 g_free(extract_item->path);
603 extract_item->path = g_strdup(path);
604 extract_item->pid = pid;
606 *item = extract_item;
608 MS_DBG_SWARN("__msc_set_extract_item path[%s],pid[%d]", extract_item->path, extract_item->pid);
610 return MS_MEDIA_ERR_NONE;
613 static void __msc_del_extract_item(s_extract_item** item)
616 g_free((*item)->path);
622 int msc_set_cancel_extract_item(const char* cancel_path, int pid)
625 MS_DBG_WARN("msc_set_cancel_extract_item begin");
626 g_mutex_lock(&extract_item_mutex);
627 if (cancel_path == NULL) {
628 MS_DBG_ERR("cancel_path invalid...");
632 if (cur_extract_item && cur_extract_item->path) {
633 if ((strcmp(cur_extract_item->path, cancel_path) == 0) && (pid == cur_extract_item->pid))
634 ret = __msc_set_extract_item(&cancel_extract_item, cancel_path, pid);
635 else if ((pid == -1) && (strncmp(cur_extract_item->path, cancel_path, strlen(cancel_path)) == 0))
636 ret = __msc_set_extract_item(&cancel_extract_item, cancel_path, pid);
638 g_mutex_unlock(&extract_item_mutex);
640 MS_DBG_WARN("msc_set_cancel_extract_item end");
644 static void __msc_del_cancel_extract_item(void)
646 g_mutex_lock(&extract_item_mutex);
647 __msc_del_extract_item(&cancel_extract_item);
648 g_mutex_unlock(&extract_item_mutex);
651 static void __msc_set_cur_extract_item(const char* cur_path, int pid)
653 g_mutex_lock(&extract_item_mutex);
654 __msc_set_extract_item(&cur_extract_item, cur_path, pid);
655 g_mutex_unlock(&extract_item_mutex);
658 static void __msc_del_cur_extract_item(void)
660 g_mutex_lock(&extract_item_mutex);
661 __msc_del_extract_item(&cur_extract_item);
662 g_mutex_unlock(&extract_item_mutex);
665 void msc_set_extract_blocked_path(const char *blocked_path)
669 g_mutex_lock(&extract_blocked_mutex);
671 if (g_extract_blocked_path != NULL) {
672 MS_DBG_SERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
673 g_free(g_extract_blocked_path);
676 g_extract_blocked_path = g_strdup(blocked_path);
677 MS_DBG_ERR("g_extract_blocked_path is set [%s]", g_extract_blocked_path);
678 g_mutex_unlock(&extract_blocked_mutex);
683 static void __msc_del_extract_blocked_path(const char* blocked_path)
687 g_mutex_lock(&extract_blocked_mutex);
690 if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(g_extract_blocked_path)))) {
691 MS_DBG_ERR("g_extract_blocked_path is deleted [%s]", g_extract_blocked_path);
692 MS_SAFE_FREE(g_extract_blocked_path);
695 if (g_extract_blocked_path != NULL) {
696 MS_DBG_SERR("g_extract_blocked_path is deleted [%s]", g_extract_blocked_path);
697 MS_SAFE_FREE(g_extract_blocked_path);
701 g_mutex_unlock(&extract_blocked_mutex);
706 static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid, bool is_end)
708 int ret = MS_MEDIA_ERR_NONE;
710 /*check poweroff status*/
712 MS_DBG_ERR("Power off");
713 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
716 if (strncmp(start_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) {
718 ms_config_get_int(MS_DISC_STATE, &disc_state);
719 if (disc_state == 0) {
720 MS_DBG_ERR("[DISC IS NOT INSERTED]");
721 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
726 if (scan_type == MS_MSG_DIRECTORY_SCANNING || scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
727 g_mutex_lock(&extract_req_mutex);
728 /* check cancel path */
729 //MS_DBG_ERR("__msc_check_extract_stop_status...");
730 if ((cancel_extract_item != NULL) && (cancel_extract_item->path != NULL)) {
731 MS_DBG_SWARN("check cancel storage [%s][%s]", cancel_extract_item->path, start_path);
732 if ((strncmp(cancel_extract_item->path, start_path, strlen(cancel_extract_item->path)) == 0)
733 && (cancel_extract_item->pid == -1 || cancel_extract_item->pid == pid)) {
734 MS_DBG_SWARN("Receive cancel request [%s][%s]. STOP scan!!", cancel_extract_item->path, start_path);
735 unsigned int path_len = strlen(cancel_extract_item->path);
737 if (strlen(start_path) > path_len) {
738 if (start_path[path_len] == '/') {
739 MS_DBG_ERR("start path is same as cancel path");
740 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
742 MS_DBG_ERR("start path is not same as cancel path");
745 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
750 g_mutex_unlock(&extract_req_mutex);
753 if (scan_type == MS_MSG_STORAGE_ALL || scan_type == MS_MSG_STORAGE_PARTIAL) {
754 if (g_directory_extract_processing == true) {
755 MS_DBG_WARN("Now directory extract is start. So, storage extract is stopped.");
756 __msc_pause_extract();
757 MS_DBG_WARN("Now directory extract is end. So, storage extract is resumed.");
760 g_mutex_lock(&extract_blocked_mutex);
761 /* check block path */
762 if (g_extract_blocked_path != NULL) {
763 //MS_DBG_SWARN("check blocked storage [%s][%s]", g_extract_blocked_path, start_path);
764 if (strncmp(start_path, g_extract_blocked_path, strlen(g_extract_blocked_path)) == 0) {
765 MS_DBG_SERR("Receive blocked message[%s][%s]. STOP extract!!", g_extract_blocked_path, start_path);
766 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
769 MS_DBG("[END REQUEST]");
770 /*MS_SAFE_FREE(g_extract_blocked_path);*/
772 MS_DBG("[NOT END REQUEST]");
776 g_mutex_unlock(&extract_blocked_mutex);
782 static void __msc_set_storage_extract_status(ms_storage_scan_status_e status)
784 stg_extract_status = status;
787 static void __msc_get_storage_extract_status(ms_storage_scan_status_e *status)
789 *status = stg_extract_status;
792 static void __msc_resume_extract(void)
794 g_mutex_lock(&extract_data_mutex);
796 g_cond_signal(&extract_data_cond);
798 g_mutex_unlock(&extract_data_mutex);
801 static void __msc_pause_extract(void)
803 g_mutex_lock(&extract_data_mutex);
805 while (g_directory_extract_processing)
806 g_cond_wait(&extract_data_cond, &extract_data_mutex);
808 g_mutex_unlock(&extract_data_mutex);
811 static int __msc_extract_set_db_status(ms_db_status_type_t status)
813 int res = MS_MEDIA_ERR_NONE;
816 if (!ms_config_set_int(VCONFKEY_PRIVATE_EXTRACTSTATUS, status)) {
817 res = MS_MEDIA_ERR_INTERNAL;
818 MS_DBG_ERR("ms_config_set_int failed");
824 int msc_get_remain_extract_request(ms_extract_type_e scan_type, int *remain_request)
826 int ret = MS_MEDIA_ERR_NONE;
829 case MS_EXTRACT_STORAGE:
830 *remain_request = g_async_queue_length(storage_extract_queue);
832 case MS_EXTRACT_DIRECTORY:
833 *remain_request = g_async_queue_length(folder_extract_queue);
836 MS_DBG_ERR("invalid parameter");
837 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
844 void msc_stop_extract_thread(void)
846 ms_comm_msg_s *data = NULL;
848 if (storage_extract_queue) {
849 /*notify to storage extract thread*/
850 data = g_new0(ms_comm_msg_s, 1);
852 data->pid = POWEROFF;
853 g_async_queue_push(storage_extract_queue, data);
856 if (folder_extract_queue) {
857 /*notify to folder extract thread*/
858 data = g_new0(ms_comm_msg_s, 1);
860 data->pid = POWEROFF;
861 g_async_queue_push(folder_extract_queue, data);
865 int msc_set_extract_cancel_path(const char *cancel_path)
867 if (g_extract_cancel_path != NULL) {
868 MS_DBG_WARN("g_extract_cancel_path is not NULL");
869 g_free(g_extract_cancel_path);
872 g_extract_cancel_path = g_strdup(cancel_path);
874 return MS_MEDIA_ERR_NONE;