Restore DB size checker 98/316298/3 accepted/tizen_unified_dev accepted/tizen/unified/20240821.081452 accepted/tizen/unified/dev/20240822.230350 accepted/tizen/unified/x/20240822.014255
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 19 Aug 2024 06:07:26 +0000 (15:07 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 20 Aug 2024 02:07:09 +0000 (11:07 +0900)
TV product policy
- Files in the RW area cannot exceed 20MB.

Change-Id: Ibf724e1a8a1fed261ffcafc812a962cfb5498c8d
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
13 files changed:
Makefile.am
packaging/media-server.spec
src/common/include/media-common-types.h
src/common/include/media-common-utils.h
src/common/media-common-utils-tv.c
src/scanner-v2/include/media-scanner-db-manage-v2.h [new file with mode: 0644]
src/scanner-v2/media-scanner-db-manage-v2.c [new file with mode: 0644]
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/server/include/media-server-db-manage.h
src/server/media-server-db-manage.c
src/server/media-server-device-block.c
src/server/media-server-main.c

index b3459f5..4701cb8 100644 (file)
@@ -173,6 +173,7 @@ media_scanner_v2_SOURCES = src/common/media-common-utils.c \
                        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 \
index fc87ee0..ab146ea 100644 (file)
@@ -1,6 +1,6 @@
 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
index ce05f8e..8853e20 100644 (file)
@@ -42,6 +42,7 @@
 #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"
index 7259e43..01ecdfb 100644 (file)
 #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);
@@ -36,6 +43,8 @@ void ms_trim_dir_path(char *dir_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);
index 00b05b1..491d2be 100644 (file)
@@ -75,6 +75,25 @@ bool ms_config_set_int(const char *key, int value)
        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;
@@ -125,6 +144,26 @@ bool ms_storage_mount_status(const char *start_path)
        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;
diff --git a/src/scanner-v2/include/media-scanner-db-manage-v2.h b/src/scanner-v2/include/media-scanner-db-manage-v2.h
new file mode 100644 (file)
index 0000000..de9a5dc
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  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
diff --git a/src/scanner-v2/media-scanner-db-manage-v2.c b/src/scanner-v2/media-scanner-db-manage-v2.c
new file mode 100644 (file)
index 0000000..680da94
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  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;
+}
index 97dd0ac..0e690a8 100644 (file)
@@ -24,6 +24,7 @@
 #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"
 
@@ -206,6 +207,15 @@ gpointer msc_folder_extract_thread(gpointer data)
                        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:
@@ -329,6 +339,13 @@ gpointer msc_storage_extract_thread(gpointer data)
                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");
index 0675c3c..51869dc 100644 (file)
@@ -29,6 +29,7 @@
 #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
 
@@ -66,6 +67,8 @@ static int __msc_check_scan_same_path(char *scan_path);
 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)
@@ -235,6 +238,17 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
                        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;
 
@@ -261,6 +275,17 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
                                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;
 
@@ -411,6 +436,10 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
                        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) {
@@ -457,6 +486,10 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
                        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;
 
@@ -797,6 +830,10 @@ gpointer msc_directory_scan_thread(gpointer data)
                        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);
@@ -1004,6 +1041,14 @@ gpointer msc_storage_scan_thread(gpointer data)
                        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);
@@ -1227,6 +1272,60 @@ static void __msc_del_blocked_path(void)
        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();
index 23c09ad..56c2adc 100644 (file)
@@ -24,6 +24,7 @@
 #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
index ae3e27d..b9031a6 100644 (file)
@@ -69,6 +69,48 @@ int ms_reset_mediadb(uid_t uid)
        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;
@@ -80,7 +122,7 @@ int ms_check_corrupt_mediadb(void)
        }
 
        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;
        }
index def1604..ea870f5 100644 (file)
@@ -175,7 +175,7 @@ void ms_device_handle_usb_added(const char *mount_path)
                                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;
                }
 
@@ -241,6 +241,8 @@ void ms_device_handle_usb_removed(const char *mount_path)
 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) {
@@ -256,6 +258,8 @@ void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *use
 
        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 };
 
@@ -264,7 +268,8 @@ void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *use
                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")) {
@@ -272,12 +277,16 @@ void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *use
                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);
 }
 
@@ -314,7 +323,7 @@ int ms_check_mounted_storage(uid_t uid)
 
        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) {
index 95e971a..9386ff1 100644 (file)
@@ -190,6 +190,8 @@ int main(int argc, char **argv)
        }
 
        uid_t uid = ms_sys_get_uid();
+       uint64_t db_size = 0;
+       uint64_t free_space = 0;
 
        __ms_deal_reset_status();
 #endif
@@ -200,6 +202,19 @@ int main(int argc, char **argv)
        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);
@@ -398,7 +413,7 @@ static void __ms_check_mediadb(void)
        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);