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 GMutex extract_req_mutex;
48 GMutex extract_blocked_mutex;
49 char *g_extract_cancel_path;
50 char *g_extract_blocked_path;
51 bool g_directory_extract_processing;
52 int stg_extract_status;
54 GMutex extract_item_mutex;
55 s_extract_item* cancel_extract_item = NULL;
56 s_extract_item* cur_extract_item = NULL;
58 GCond extract_data_cond;
59 GMutex extract_data_mutex;
60 #define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
62 #define NORMAL_EVENT 0
64 static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid, bool is_end);
65 static int __msc_set_storage_extract_status(ms_storage_scan_status_e status);
66 static int __msc_get_storage_extract_status(ms_storage_scan_status_e *status);
67 static int __msc_resume_extract();
68 static int __msc_pause_extract();
69 static int __msc_extract_set_db_status(ms_db_status_type_t status);
76 static int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count, bool is_end);
78 int msc_init_extract_thread()
80 if (!storage_extract_queue) storage_extract_queue = g_async_queue_new();
81 if (!folder_extract_queue) folder_extract_queue = g_async_queue_new();
83 g_mutex_init(&extract_req_mutex);
84 g_mutex_init(&extract_blocked_mutex);
85 g_mutex_init(&extract_data_mutex);
87 g_mutex_init(&extract_item_mutex);
89 g_cond_init(&extract_data_cond);
91 return MS_MEDIA_ERR_NONE;
94 int msc_deinit_extract_thread()
96 if (storage_extract_queue) g_async_queue_unref(storage_extract_queue);
97 if (folder_extract_queue) g_async_queue_unref(folder_extract_queue);
99 g_mutex_clear(&extract_req_mutex);
100 g_mutex_clear(&extract_blocked_mutex);
101 g_mutex_clear(&extract_data_mutex);
103 g_mutex_clear(&extract_item_mutex);
105 g_cond_clear(&extract_data_cond);
107 return MS_MEDIA_ERR_NONE;
110 int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count, bool is_end)
112 MS_DBG_WARN("begin of __msc_folder_bulk_extract");
113 int ret = MS_MEDIA_ERR_NONE;
114 int tmp_ret = MS_MEDIA_ERR_NONE;
115 GArray *data_array = NULL;
116 ms_item_info_s* db_data = NULL;
117 int extract_count = 0;
119 ret = ms_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, (void*)&data_array);
120 if (ret != MS_MEDIA_ERR_NONE) {
121 MS_DBG_ERR("ms_get_extract_list failed!!!");
122 return MS_MEDIA_ERR_NONE;
125 if (data_array == NULL) {
126 MS_DBG_ERR("data_array is NULL!!!");
127 return MS_MEDIA_ERR_NONE;
130 while (data_array->len != 0) {
131 tmp_ret = MS_MEDIA_ERR_NONE;
134 ret = __msc_check_extract_stop_status(scan_type, storage_type, path, pid, is_end);
135 if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
136 MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
140 db_data = g_array_index(data_array, ms_item_info_s*, 0);
141 g_array_remove_index(data_array, 0);
143 tmp_ret = ms_update_one_extract_item(handle, storage_id, storage_type, db_data, burst);
144 if (tmp_ret == MS_MEDIA_ERR_NONE)
146 else if (tmp_ret == MS_MEDIA_ERR_FILE_IO)
150 MS_SAFE_FREE(db_data->path);
151 MS_SAFE_FREE(db_data);
156 if (extract_count > 0)
157 ms_query_do_update_list(handle);
159 while (data_array->len != 0) {
161 db_data = g_array_index(data_array, ms_item_info_s*, 0);
162 g_array_remove_index(data_array, 0);
165 MS_SAFE_FREE(db_data->path);
166 MS_SAFE_FREE(db_data);
170 g_array_free(data_array, FALSE);
173 MS_DBG_WARN("end of __msc_folder_bulk_extract");
177 gboolean msc_folder_extract_thread(void *data)
179 ms_comm_msg_s *extract_data = NULL;
180 int ret = MS_MEDIA_ERR_NONE;
181 void **handle = NULL;
183 ms_user_storage_type_e storage_type;
184 char *storage_id = NULL;
185 char *update_path = NULL;
186 unsigned int io_err_count = 0;
187 uid_t uid = MEDIA_DEFAULT_UID;
189 int end_flag = NORMAL_EVENT;
192 extract_data = g_async_queue_pop(folder_extract_queue);
193 if (extract_data->pid == POWEROFF) {
194 MS_DBG_ERR("power off");
198 MS_DBG_WARN("DIRECTORY EXTRACT START [%s %d]", extract_data->msg, extract_data->msg_type);
202 msc_set_cur_extract_item(extract_data->msg, extract_data->pid);
203 g_directory_extract_processing = true;
204 uid = extract_data->uid;
206 /*connect to media db, if conneting is failed, db updating is stopped*/
207 ret = ms_connect_db(&handle, uid);
208 if (ret != MS_MEDIA_ERR_NONE) {
209 MS_DBG_ERR("ms_connect_db failed");
213 scan_type = extract_data->msg_type;
215 storage_id = strdup(extract_data->storage_id);
216 if (storage_id == NULL) {
217 MS_DBG_ERR("storage_id NULL");
218 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
222 MS_DBG("path : [%s], storage_id : [%s]", extract_data->msg, storage_id);
224 update_path = strndup(extract_data->msg, extract_data->msg_size);
226 if (strlen(storage_id) == 0) {
227 MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", extract_data->msg);
228 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
232 if (scan_type != MS_MSG_DIRECTORY_SCANNING
233 && scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
234 MS_DBG_ERR("Invalid request");
235 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
238 end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
240 ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
241 if (ret != MS_MEDIA_ERR_NONE) {
242 MS_DBG_ERR("ms_user_get_storage_type failed");
246 ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
248 if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
249 MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
253 /*insert data into media db */
254 ret = msc_check_db_size(uid, extract_data->msg_type);
255 if (ret != MS_MEDIA_ERR_NONE) {
256 MS_DBG_ERR("NOT ENOUGH MEMORY");
257 if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
258 ret = MS_MEDIA_ERR_NONE;
263 ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count, end_flag);
266 g_directory_extract_processing = false;
268 MS_DBG_ERR("power off");
275 if (extract_data->result) {
276 /*send notification*/
277 char *folder_uuid = NULL;
278 ms_get_folder_id(handle, storage_id, extract_data->msg, &folder_uuid);
279 ms_send_dir_update_noti(handle, storage_id, update_path, folder_uuid, MS_ITEM_UPDATE, extract_data->pid);
280 extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
281 msc_send_result(ret, extract_data);
284 MS_SAFE_FREE(update_path);
285 MS_SAFE_FREE(extract_data);
286 MS_SAFE_FREE(storage_id);
288 msc_del_cur_extract_item();
289 msc_del_cancel_extract_item();
290 if (msc_get_disc_dir_scan_status()) {
291 MS_DBG("[DISC ACCESS END]");
292 msc_set_disc_dir_scan_status(false);
294 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
295 if (disc_state == MS_DISC_ACCESS) {
296 MS_DBG("[CHANGE DISC STATE]");
297 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
301 MS_DBG_WARN("DIRECTORY EXTRACT END [%d]", ret);
303 ms_storage_scan_status_e storage_scan_status = MS_STORAGE_SCAN_NONE;
304 ret = __msc_get_storage_extract_status(&storage_scan_status);
305 if (ret == MS_MEDIA_ERR_NONE) {
306 /*get storage list and scan status from media db*/
307 if (storage_scan_status != MS_STORAGE_SCAN_COMPLETE) {
308 __msc_resume_extract();
309 MS_DBG_WARN("extract RESUME OK");
313 /*disconnect form media db*/
314 if (handle) ms_disconnect_db(&handle);
318 __msc_resume_extract();
320 MS_SAFE_FREE(update_path);
321 MS_SAFE_FREE(extract_data);
322 MS_SAFE_FREE(storage_id);
324 if (handle) ms_disconnect_db(&handle);
329 gboolean msc_storage_extract_thread(void *data)
331 ms_comm_msg_s *extract_data = NULL;
332 int ret = MS_MEDIA_ERR_NONE;
333 void **handle = NULL;
334 ms_user_storage_type_e storage_type = MS_STORAGE_INTERNAL;
336 char *update_path = NULL;
337 unsigned int io_err_count = 0;
338 uid_t uid = MEDIA_DEFAULT_UID;
340 int end_flag = NORMAL_EVENT;
343 __msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
344 extract_data = g_async_queue_pop(storage_extract_queue);
345 if (extract_data->pid == POWEROFF) {
346 MS_DBG_ERR("power off");
350 __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_PROCESSING);
354 MS_DBG_WARN("STORAGE extract START extract len is %d ", g_async_queue_length(storage_extract_queue));
356 scan_type = extract_data->msg_type;
357 if (scan_type != MS_MSG_STORAGE_ALL
358 && scan_type != MS_MSG_STORAGE_PARTIAL) {
359 MS_DBG_ERR("Invalid request[%d]", scan_type);
360 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
364 uid = extract_data->uid;
366 /*connect to media db, if conneting is failed, db updating is stopped*/
367 ret = ms_connect_db(&handle, uid);
368 if (ret != MS_MEDIA_ERR_NONE) {
369 MS_DBG_ERR("ms_connect_db falied!");
373 end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
374 update_path = g_strndup(extract_data->msg, extract_data->msg_size);
375 if (!MS_STRING_VALID(update_path)) {
376 MS_DBG_ERR("Invalid update_path");
377 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
380 MS_DBG_WARN("extract storage_id is [%s], path [%s]", extract_data->storage_id, update_path);
381 ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
382 if (ret != MS_MEDIA_ERR_NONE) {
383 MS_DBG_ERR("ms_user_get_storage_type failed");
386 if (storage_type == MS_STORAGE_EXTERNAL_USB) {
387 if (!ms_storage_mount_status(update_path)) {
388 MS_DBG_ERR("%s is unmounted", update_path);
389 ret = MS_MEDIA_ERR_USB_UNMOUNTED;
390 msc_remove_extract_request(extract_data);
394 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, uid);
395 __msc_extract_set_db_status(MS_DB_UPDATING);
397 ret = msc_check_db_size(uid, extract_data->msg_type);
398 if (ret != MS_MEDIA_ERR_NONE) {
399 MS_DBG_ERR("NOT ENOUGH MEMORY");
400 __msc_extract_set_db_status(MS_DB_STOPPED);
401 if (strncmp(update_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) {
402 if (msc_get_disc_stg_scan_status()) {
403 MS_DBG("[DISC ACCESS STOP]");
404 msc_set_disc_stg_scan_status(false);
406 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
407 if (disc_state == MS_DISC_ACCESS) {
408 MS_DBG("[CHANGE DISC STATE]");
409 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
418 ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count, end_flag);
419 MS_DBG_WARN("extract PAUSE");
420 __msc_pause_extract();
421 MS_DBG_WARN("extract RESUME");
423 int tem_ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
424 if (tem_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
425 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, uid);
426 __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
427 MS_DBG_WARN("storage scan force stopped");
428 /* set vconf key db extract status */
429 __msc_extract_set_db_status(MS_DB_STOPPED);
430 if (msc_get_disc_stg_scan_status()) {
431 MS_DBG("[DISC ACCESS STOP]");
432 msc_set_disc_stg_scan_status(false);
434 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
435 if (disc_state == MS_DISC_ACCESS) {
436 MS_DBG("[CHANGE DISC STATE]");
437 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
440 msc_del_extract_blocked_path(update_path);
441 msc_remove_extract_request(extract_data);
444 if (extract_data->result == TRUE) {
445 MS_DBG_WARN("extract_data->result == TRUE, MS_STORAGE_SCAN_COMPLETE");
446 ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
447 __msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
449 /* send notification */
450 ms_send_dir_update_noti(handle, extract_data->storage_id, update_path, NULL, MS_ITEM_UPDATE, extract_data->pid);
451 /* set vconf key db extract status */
452 __msc_extract_set_db_status(MS_DB_UPDATED);
453 if (msc_get_disc_stg_scan_status()) {
454 MS_DBG("[DISC ACCESS END]");
455 msc_set_disc_stg_scan_status(false);
457 ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
458 if (disc_state == MS_DISC_ACCESS) {
459 MS_DBG("[CHANGE DISC STATE]");
460 ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
466 MS_SAFE_FREE(update_path);
469 MS_DBG_ERR("power off");
473 /*disconnect form media db*/
474 if (handle) ms_disconnect_db(&handle);
479 if (extract_data->result) {
480 extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
481 msc_send_result(ret, extract_data);
484 MS_SAFE_FREE(extract_data);
486 MS_DBG_WARN("STORAGE EXTRACT END[%d]", ret);
490 MS_SAFE_FREE(extract_data);
491 if (handle) ms_disconnect_db(&handle);
496 void msc_insert_exactor_request(int message_type, bool ins_status, const char *storage_id, const char *path, int pid, uid_t uid)
498 ms_comm_msg_s *extract_data = NULL;
499 MS_MALLOC(extract_data, sizeof(ms_comm_msg_s));
500 if (extract_data == NULL) {
501 MS_DBG_ERR("MS_MALLOC failed");
505 extract_data->msg_type = message_type;
506 extract_data->pid = pid;
507 extract_data->uid = uid;
508 extract_data->result = ins_status;
509 extract_data->msg_size = strlen(path);
510 SAFE_STRLCPY(extract_data->msg, path, sizeof(extract_data->msg));
511 SAFE_STRLCPY(extract_data->storage_id, storage_id, sizeof(extract_data->storage_id));
513 if (message_type == MS_MSG_STORAGE_ALL || message_type == MS_MSG_STORAGE_PARTIAL || message_type == MS_MSG_STORAGE_INVALID) {
514 g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(extract_data));
515 MS_DBG("insert to storage exactor queue. msg_type [%d]", ins_status);
516 } else if (message_type == MS_MSG_DIRECTORY_SCANNING || message_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
517 g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(extract_data));
518 MS_DBG("insert to dir exactor queue. msg_type [%d]", ins_status);
520 MS_DBG_ERR("try to insert to exactor scan with msg_type [%d]", message_type);
521 MS_SAFE_FREE(extract_data);
527 int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
529 if (recv_msg == NULL) {
530 MS_DBG_ERR("recv_msg is null");
531 return MS_MEDIA_ERR_INVALID_PARAMETER;
533 const char *storageid = recv_msg->storage_id;
534 int len = g_async_queue_length(storage_extract_queue);
535 ms_comm_msg_s *msg = NULL;
536 GAsyncQueue *temp_queue = NULL;
538 MS_DBG_WARN("exactor_req_mutex is LOCKED");
539 g_mutex_lock(&extract_req_mutex);
542 MS_DBG_ERR("Request is not stacked");
543 goto END_REMOVE_REQUEST;
546 temp_queue = g_async_queue_new();
548 for (; i < len; i++) {
549 /*create new queue to compare request*/
550 msg = g_async_queue_pop(storage_extract_queue);
551 if ((strcmp(msg->storage_id, storageid) == 0)) {
553 MS_DBG_WARN("force stop storage scan");
554 msg->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
555 msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
559 g_async_queue_push(temp_queue, GINT_TO_POINTER(msg));
562 len = g_async_queue_length(temp_queue);
564 for (; j < len; j++) {
565 msg = g_async_queue_pop(temp_queue);
567 g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(msg));
569 g_async_queue_unref(temp_queue);
572 g_mutex_unlock(&extract_req_mutex);
573 MS_DBG_WARN("exactor_req_mutex is UNLOCKED");
575 return MS_MEDIA_ERR_NONE;
578 int _msc_set_extract_item(s_extract_item** item, const char* path, int pid)
580 s_extract_item* extract_item = *item;
581 if (extract_item != NULL) {
582 MS_SAFE_FREE(extract_item->path);
583 extract_item->pid = -1;
585 extract_item = (s_extract_item*)malloc(sizeof(s_extract_item));
586 if (extract_item == NULL) {
587 MS_DBG_ERR("malloc item failed");
588 return MS_MEDIA_ERR_INTERNAL;
590 memset(extract_item, 0, sizeof(s_extract_item));
593 extract_item->path = strdup(path);
594 extract_item->pid = pid;
595 *item = extract_item;
597 MS_DBG_WARN("_msc_set_extract_item path[%s],pid[%d]", extract_item->path, extract_item->pid);
598 return MS_MEDIA_ERR_NONE;
601 int _msc_del_extract_item(s_extract_item** item)
604 MS_SAFE_FREE((*item)->path);
608 return MS_MEDIA_ERR_NONE;
611 int msc_set_cancel_extract_item(const char* cancel_path, int pid)
614 MS_DBG_WARN("msc_set_cancel_extract_item begin");
615 g_mutex_lock(&extract_item_mutex);
616 if (cancel_path == NULL) {
617 MS_DBG_ERR("cancel_path invalid...");
621 if (cur_extract_item && cur_extract_item->path) {
622 if ((strcmp(cur_extract_item->path, cancel_path) == 0) && (pid == cur_extract_item->pid))
623 ret = _msc_set_extract_item(&cancel_extract_item, cancel_path, pid);
624 else if ((pid == -1) && (strncmp(cur_extract_item->path, cancel_path, strlen(cancel_path)) == 0))
625 ret = _msc_set_extract_item(&cancel_extract_item, cancel_path, pid);
627 g_mutex_unlock(&extract_item_mutex);
629 MS_DBG_WARN("msc_set_cancel_extract_item end");
633 int msc_del_cancel_extract_item()
636 g_mutex_lock(&extract_item_mutex);
637 ret = _msc_del_extract_item(&cancel_extract_item);
638 g_mutex_unlock(&extract_item_mutex);
643 int msc_set_cur_extract_item(const char* cur_path, int pid)
646 g_mutex_lock(&extract_item_mutex);
647 ret = _msc_set_extract_item(&cur_extract_item, cur_path, pid);
648 g_mutex_unlock(&extract_item_mutex);
652 int msc_del_cur_extract_item()
655 g_mutex_lock(&extract_item_mutex);
656 ret = _msc_del_extract_item(&cur_extract_item);
657 g_mutex_unlock(&extract_item_mutex);
662 int msc_set_extract_blocked_path(const char *blocked_path)
666 g_mutex_lock(&extract_blocked_mutex);
668 if (g_extract_blocked_path != NULL) {
669 MS_DBG_ERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
670 MS_SAFE_FREE(g_extract_blocked_path);
673 g_extract_blocked_path = strdup(blocked_path);
675 g_mutex_unlock(&extract_blocked_mutex);
679 return MS_MEDIA_ERR_NONE;
682 int msc_del_extract_blocked_path(const char* blocked_path)
686 g_mutex_lock(&extract_blocked_mutex);
688 if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(blocked_path)))) {
689 MS_DBG_ERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
690 MS_SAFE_FREE(g_extract_blocked_path);
693 if (g_extract_blocked_path != NULL) {
694 MS_DBG_ERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
695 MS_SAFE_FREE(g_extract_blocked_path);
699 g_mutex_unlock(&extract_blocked_mutex);
703 return MS_MEDIA_ERR_NONE;
706 static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_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_WARN("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_WARN("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_WARN("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_ERR("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 int __msc_set_storage_extract_status(ms_storage_scan_status_e status)
784 int res = MS_MEDIA_ERR_NONE;
786 stg_extract_status = status;
791 static int __msc_get_storage_extract_status(ms_storage_scan_status_e *status)
793 int res = MS_MEDIA_ERR_NONE;
795 *status = stg_extract_status;
800 static int __msc_resume_extract()
802 g_mutex_lock(&extract_data_mutex);
804 g_cond_signal(&extract_data_cond);
806 g_mutex_unlock(&extract_data_mutex);
808 return MS_MEDIA_ERR_NONE;
811 static int __msc_pause_extract()
813 g_mutex_lock(&extract_data_mutex);
815 while (g_directory_extract_processing)
816 g_cond_wait(&extract_data_cond, &extract_data_mutex);
818 g_mutex_unlock(&extract_data_mutex);
820 return MS_MEDIA_ERR_NONE;
823 static int __msc_extract_set_db_status(ms_db_status_type_t status)
825 int res = MS_MEDIA_ERR_NONE;
828 if (!ms_config_set_int(VCONFKEY_PRIVATE_EXTRACTSTATUS, status)) {
829 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
830 MS_DBG_ERR("ms_config_set_int failed");
836 int msc_get_remain_extract_request(ms_extract_type_e scan_type, int *remain_request)
838 int ret = MS_MEDIA_ERR_NONE;
841 case MS_EXTRACT_STORAGE:
842 *remain_request = g_async_queue_length(storage_extract_queue);
844 case MS_EXTRACT_DIRECTORY:
845 *remain_request = g_async_queue_length(folder_extract_queue);
848 MS_DBG_ERR("invalid parameter");
849 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
856 int msc_get_dir_extract_status(bool *extract_status)
858 *extract_status = g_directory_extract_processing;
860 return MS_MEDIA_ERR_NONE;
863 int msc_stop_extract_thread(void)
865 ms_comm_msg_s *data = NULL;
867 if (storage_extract_queue) {
868 /*notify to storage extract thread*/
869 MS_MALLOC(data, sizeof(ms_comm_msg_s));
871 data->pid = POWEROFF;
872 g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(data));
876 if (folder_extract_queue) {
877 /*notify to folder extract thread*/
878 MS_MALLOC(data, sizeof(ms_comm_msg_s));
880 data->pid = POWEROFF;
881 g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(data));
885 return MS_MEDIA_ERR_NONE;
888 int msc_set_extract_cancel_path(const char *cancel_path)
890 if (g_extract_cancel_path != NULL) {
891 MS_DBG_WARN("g_extract_cancel_path is not NULL");
892 MS_SAFE_FREE(g_extract_cancel_path);
895 g_extract_cancel_path = strdup(cancel_path);
897 return MS_MEDIA_ERR_NONE;