src/common/media-common-system.c \
src/common/media-common-external-storage.c \
src/common/media-common-db-svc.c \
+ src/scanner-v2/media-scanner-db-manage-v2.c \
src/scanner-v2/media-scanner-common-v2.c \
src/scanner-v2/media-scanner-device-block-v2.c\
src/scanner-v2/media-scanner-scan-v2.c \
Name: media-server
Summary: A server for media content management
-Version: 0.6.9
+Version: 0.6.10
Release: 0
Group: Multimedia/Service
License: Apache-2.0
#define MS_NON_RECURSIVE 0
#define MS_SERVER_STATUS "memory/private/mediaserver/server_status"
+#define MS_DB_LIMIT "file/private/mediaserver/db_limit"
#define MS_DB_RESET "file/private/mediaserver/db_reset"
#define MS_MM_CONF_PATH SYSCONFDIR"/multimedia/"
#define MS_DUMMY_MEDIA_DB_PATH MS_MM_CONF_PATH".media.db"
#include "media-util.h"
#include "media-common-types.h"
+#ifdef _USE_TVPD_MODE
+#include <inttypes.h>
+#define MEDIA_DB_SIZE_LIMIT_2 20000000
+#define MEDIA_DB_SIZE_LIMIT_1 10000000
+#define MEDIA_DB_SPACE_LIMIT 20971520
+#endif
+
#define MS_SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
bool ms_is_valid_symlink(const char *path);
bool ms_config_get_int(const char *key, int *value);
bool ms_config_set_int(const char *key, int value);
int ms_set_db_status(ms_db_status_type_t status);
+int ms_get_remain_space(uint64_t *free_space);
+int ms_check_size_mediadb(uid_t uid, uint64_t *db_size);
bool ms_storage_mount_status(const char *start_path);
bool ms_is_support_pvr(void);
void ms_prevent_oom_killer(void);
return false;
}
+int ms_get_remain_space(uint64_t *free_space)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ const char *path = "/opt";
+ struct statvfs s;
+
+ ret = statvfs(path, &s);
+ if (ret != 0) {
+ MS_DBG_ERR("statvfs failed[%d]", ret);
+ MS_DBG_STRERROR();
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ /* f_bsize:unsigned long, f_bavail:fsblkcnt_t(unsigned long) */
+ *free_space = (uint64_t)s.f_bsize * (uint64_t)s.f_bavail;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
bool ms_is_support_pvr(void)
{
bool bSupportPVR = false;
return ret;
}
+int ms_check_size_mediadb(uid_t uid, uint64_t *db_size)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *db_path = NULL;
+ struct stat buf;
+
+ ret = ms_user_get_media_db_path(uid, &db_path);
+
+ if (stat(db_path, &buf) == 0) {
+ *db_size = (uint64_t)buf.st_size;
+ } else {
+ MS_DBG_STRERROR("stat failed");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ }
+
+ g_free(db_path);
+
+ return ret;
+}
+
int ms_set_db_status(ms_db_status_type_t status)
{
int ret = MS_MEDIA_ERR_NONE;
--- /dev/null
+/*
+ * Media Server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SCANNER_DB_MANAGER_V2_H_
+#define _MEDIA_SCANNER_DB_MANAGER_V2_H_
+
+#include "media-common-types.h"
+
+int msc_check_db_size(uid_t uid, ms_msg_type_e msg_type);
+
+#endif
--- /dev/null
+/*
+ * Media Server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-util.h"
+#include "media-common-utils.h"
+#include "media-common-system.h"
+#include "media-common-db-svc.h"
+#include "media-scanner-dbg-v2.h"
+#include "media-scanner-db-manage-v2.h"
+
+int msc_check_db_size(uid_t uid, ms_msg_type_e msg_type)
+{
+ uint64_t db_size = 0;
+ uint64_t free_space = 0;
+ int err = MS_MEDIA_ERR_NONE;
+
+ ms_check_size_mediadb(uid, &db_size);
+
+ if (msg_type == MS_MSG_STORAGE_ALL || msg_type == MS_MSG_STORAGE_PARTIAL) {
+ if (db_size >= MEDIA_DB_SIZE_LIMIT_1) {
+ MS_DBG_ERR("DB SIZE [%" PRIu64"] reach the MEDIA_DB_SIZE_LIMIT_1[%d]", db_size, MEDIA_DB_SIZE_LIMIT_1);
+ return MS_MEDIA_ERR_DB_LIMIT_1;
+ }
+ } else if (msg_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE || msg_type == MS_MSG_DIRECTORY_SCANNING) {
+ if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {
+ MS_DBG_ERR("DB SIZE [%" PRIu64"] reach the MEDIA_DB_SIZE_LIMIT_2[%d]", db_size, MEDIA_DB_SIZE_LIMIT_2);
+ ms_config_set_int(MS_DB_LIMIT, 0);
+ MS_DBG_ERR("DB IS FULL. CANNOT UPDATE");
+ return MS_MEDIA_ERR_DB_FULL_FAIL;
+ }
+ }
+
+ /*check remain space*/
+ err = ms_get_remain_space(&free_space);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_get_remain_space failed");
+ } else {
+ if (free_space < MEDIA_DB_SPACE_LIMIT) {
+ MS_DBG_ERR("FREE SPACE [%" PRIu64"] DB SIZE [%" PRIu64"]", free_space, db_size);
+ return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
#include "media-common-db-svc.h"
#include "media-scanner-dbg-v2.h"
#include "media-scanner-common-v2.h"
+#include "media-scanner-db-manage-v2.h"
#include "media-scanner-socket-v2.h"
#include "media-scanner-extract-v2.h"
goto NEXT;
}
+ ret = msc_check_db_size(extract_data->uid, extract_data->msg_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("NOT ENOUGH MEMORY");
+ if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
+ ret = MS_MEDIA_ERR_NONE;
+
+ goto NEXT;
+ }
+
ret = __msc_folder_bulk_extract(handle, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag, extract_data->uid);
NEXT:
ms_set_storage_scan_status(extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, extract_data->uid);
__msc_extract_set_db_status(MS_DB_UPDATING);
+ ret = msc_check_db_size(extract_data->uid, extract_data->msg_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("NOT ENOUGH MEMORY");
+ __msc_extract_set_db_status(MS_DB_STOPPED);
+ goto NEXT;
+ }
+
/*extract meta*/
ret = __msc_folder_bulk_extract(handle, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag, extract_data->uid);
MS_DBG_WARN("extract PAUSE");
#include "media-scanner-socket-v2.h"
#include "media-scanner-scan-v2.h"
#include "media-scanner-extract-v2.h"
+#include "media-scanner-db-manage-v2.h"
#define MAX_SCAN_COUNT 300
static void __msc_set_storage_scan_cur_path(char *scan_path);
static void __msc_set_dir_scan_cur_path(char *scan_path);
static int __msc_dir_and_storage_scan_same_path(char *start_path);
+static int __msc_check_memory_status(uid_t uid);
+static int __msc_check_remain_space(uid_t uid);
static void __msc_del_blocked_path(void);
void msc_init_scan_thread(void)
continue;
}
+ ret = msc_check_db_size(uid, msg_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
+ ret = MS_MEDIA_ERR_NONE;
+
+ if (is_recursive)
+ ms_change_validity_item_batch(new_start_path, 1, 2, uid);
+
+ goto STOP_SCAN;
+ }
+
ms_set_folder_scan_status(storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
sleep_count = 0;
goto STOP_SCAN;
}
+ ret = msc_check_db_size(uid, msg_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
+ ret = MS_MEDIA_ERR_NONE;
+
+ if (is_recursive)
+ ms_change_validity_item_batch(new_start_path, 1, 2, uid);
+
+ goto STOP_SCAN;
+ }
+
if (dir_entry->d_name[0] == '.')
continue;
continue;
}
+ ret = msc_check_db_size(uid, msg_type);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto STOP_SCAN;
+
ms_get_folder_scan_status(handle, current_path, (int *)&scan_status);
if (scan_status == MS_DIR_SCAN_PROCESSING && g_directory_scan_processing2 != DIR_SCAN_NON_SCAN) {
if (ret != MS_MEDIA_ERR_NONE)
goto STOP_SCAN;
+ ret = msc_check_db_size(uid, msg_type);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto STOP_SCAN;
+
if (dir_entry->d_name[0] == '.')
continue;
goto NEXT;
}
+ /*check remain space*/
+ if (__msc_check_remain_space(scan_data->uid) != MS_MEDIA_ERR_NONE)
+ goto SCAN_DONE;
+
g_mutex_lock(&scan_item_mutex);
__msc_set_scan_item(&cur_scan_item, scan_data->msg, scan_data->pid);
g_mutex_unlock(&scan_item_mutex);
goto NEXT;
}
+ ret = __msc_check_memory_status(scan_data->uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ ms_set_storage_scan_status(scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
+ MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
+ msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid, MS_ITEM_UPDATE);
+ goto NEXT;
+ }
+
ms_set_storage_scan_status(scan_data->storage_id, MEDIA_SCAN_PROCESSING, scan_data->uid);
ms_set_db_status(MS_DB_UPDATING);
MS_DBG_FLEAVE();
}
+static int __msc_check_memory_status(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ uint64_t db_size = 0;
+
+ /*check remain space*/
+ ret = __msc_check_remain_space(uid);
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*check db size*/
+ ms_check_size_mediadb(uid, &db_size);
+ if (db_size >= MEDIA_DB_SIZE_LIMIT_1) {
+ MS_DBG_ERR("DB SIZE [%" PRIu64"] REACH THE FIRST LIMIT [%d]", db_size, MEDIA_DB_SIZE_LIMIT_1);
+ return MS_MEDIA_ERR_DB_LIMIT_1;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __msc_check_remain_space(uid_t uid)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ uint64_t free_space = 0;
+ uint64_t db_size = 0;
+
+ err = ms_get_remain_space(&free_space);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_get_remain_space failed");
+ } else {
+ if (free_space < MEDIA_DB_SPACE_LIMIT) {
+ MS_DBG_ERR("NOT ENOUGH SPACE WE DO NOT UPDATE MEDIA DB FREE SPACE [%" PRIu64"]", free_space);
+
+ ms_config_set_int(MS_DB_LIMIT, 0);
+
+ return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
+ }
+ }
+
+ err = ms_check_size_mediadb(uid, &db_size);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("msc_check_dbsize failed");
+ } else {
+ if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {
+ MS_DBG_ERR("REACH LIMIT DB SIZE [%" PRIu64"]", db_size);
+ ms_config_set_int(MS_DB_LIMIT, 0);
+
+ MS_DBG_ERR("DB IS FULL. CANNOT UPDATE[%" PRIu64"]", db_size);
+ return MS_MEDIA_ERR_DB_FULL_FAIL;
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
void msc_init_scanner(void)
{
if (!scan_queue2) scan_queue2 = g_async_queue_new();
#include "media-common-types.h"
int ms_reset_mediadb(uid_t uid);
+int ms_check_mediadb(uid_t uid, bool *is_reset);
int ms_check_corrupt_mediadb(void);
#endif
#endif
return ret;
}
+static int __ms_remake_mediadb(uid_t uid)
+{
+ sqlite3 *handle = NULL;
+
+ MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB.");
+
+ /*write read schema*/
+ ms_config_set_int(MS_DB_RESET, 1);
+ ms_reset_mediadb(uid);
+
+ ms_connect_db(&handle, uid);
+
+ MS_DBG_WARN("START WRITE SCHEMA");
+ if (ms_check_db(handle, uid) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("ms_check_db fail");
+
+ MS_DBG_WARN("END WRITE SCHEMA");
+
+ /*disconnect form media db*/
+ ms_disconnect_db(handle);
+
+ ms_config_set_int(MS_DB_RESET, 0);
+ return MS_MEDIA_ERR_NONE;
+}
+
+int ms_check_mediadb(uid_t uid, bool *is_reset)
+{
+ uint64_t db_size = 0;
+
+ ms_check_size_mediadb(uid, &db_size);
+
+ MS_DBG_WARN("[DB SIZE : %" PRIu64"] [LIMIT1 : %d] [LIMIT2 : %d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2);
+ if (db_size > MEDIA_DB_SIZE_LIMIT_2) {
+ MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB.");
+ MS_DBG_ERR("[DB SIZE : %" PRIu64"] [LIMIT1 : %d] [LIMIT2 : %d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2);
+ __ms_remake_mediadb(uid);
+ *is_reset = true;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
int ms_check_corrupt_mediadb(void)
{
sqlite3 *db_handle = NULL;
}
if (media_db_check_integrity(db_handle) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("check interity failed");
+ MS_DBG_ERR("check integrity failed");
media_db_disconnect(db_handle);
return MS_MEDIA_ERR_DB_CORRUPT;
}
media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_INSERT, mount_path, storage_id, 0, PROD_CUSTOM_MIME_ADDED);
}
} else {
- MS_DBG_ERR("STORAGE ID IS NUILL");
+ MS_DBG_ERR("STORAGE ID IS NULL");
goto ERROR;
}
void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data)
{
char *mount_path = NULL;
+ bool is_reset = false;
+ uid_t uid = ms_sys_get_uid();
MS_DBG_WARN("usb_event_callback BEGIN[%s]", action);
if (!usb_device) {
mount_path = usb_device_get_mountpath(usb_device);
+ ms_check_mediadb(uid, &is_reset);
+
#ifdef _USE_ON_DEMAND
ms_block_info_s block_info = { mount_path, 0, NULL };
ms_on_demand_insert_storage((gpointer)&block_info, NULL);
} else if (!strcmp(action, "blocked")) { /*unmount->blocked stop accessing usb in time*/
MS_DBG_SWARN("USB blocked, mountpath : %s", mount_path);
- ms_on_demand_remove_storage((gpointer)&block_info, NULL);
+ if (!is_reset)
+ ms_on_demand_remove_storage((gpointer)&block_info, NULL);
}
#else
if (!strcmp(action, "mounted")) {
ms_device_handle_usb_added(mount_path);
} else if (!strcmp(action, "blocked")) { /*unmount->blocked stop accessing usb in time*/
MS_DBG_SWARN("USB blocked, mountpath : %s", mount_path);
- ms_device_handle_usb_removed(mount_path);
+ if (!is_reset)
+ ms_device_handle_usb_removed(mount_path);
}
#endif
free_usb_device_h(usb_device);
+ if (is_reset)
+ ms_check_mounted_storage(uid);
+
MS_DBG_WARN("usb_event_callback END[%s]", action);
}
for (i = 0; i < count; i++) {
mounted_path = g_ptr_array_index(added_list, i);
- /* read deive information */
+ /* read device information */
ret = ms_read_device_info(mounted_path, &storage_id);
if (!storage_id) {
}
uid_t uid = ms_sys_get_uid();
+ uint64_t db_size = 0;
+ uint64_t free_space = 0;
__ms_deal_reset_status();
#endif
mainloop = g_main_loop_new(NULL, FALSE);
#ifdef _USE_TVPD_MODE
+ ms_check_size_mediadb(uid, &db_size);
+ ms_get_remain_space(&free_space);
+ MS_DBG_WARN("DB SIZE[%" PRIu64"] LIMIT1[%d] LIMIT2[%d] FREE SPACE[%" PRIu64"] SPACE LIMIT[%d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2, free_space, MEDIA_DB_SPACE_LIMIT);
+
+ if (db_size > MEDIA_DB_SIZE_LIMIT_2) {
+ MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB.");
+ ms_reset_mediadb(uid);
+#ifdef _USE_ON_DEMAND
+ need_checkdb = true;
+ ms_on_demand_reset_storage();
+#endif
+ }
+
if (ms_check_corrupt_mediadb() != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("MEDIA DB IS CORRUPTED. RESET MEDIA DB.");
ms_reset_mediadb(uid);
ms_on_demand_reset_storage();
#endif
- /* auto scan tv interal storage */
+ /* auto scan tv internal storage */
char *internal_path = NULL;
ms_user_get_internal_root_path(uid, &internal_path);
ms_send_storage_scan_request(internal_path, INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);