}
if (bind_success == false) {
- MSAPI_DBG_STRERROR("bind failed");
+ MSAPI_DBG_ERR("bind failed[%s]", serv_addr.sun_path);
close(sock);
return MS_MEDIA_ERR_SOCKET_CONN;
}
Name: media-server
Summary: A server for media content management
-Version: 0.2.115
+Version: 0.3.0
Release: 0
Group: Multimedia/Service
License: Apache-2.0
int ms_update_one_extract_item(void** handle, const char* storage_id, int storage_type, void* data, int burst);
int ms_query_do_update_list(void** handle);
+void ms_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid);
+void ms_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, uid_t uid);
+
#endif /*_MEDIA_COMMON_DB_SVC_H_*/
#include <tzplatform_config.h>
-#define FMS_PERF
-
#define MS_VALIND 1
#define MS_INVALID 0
#define MS_VALIND_V2 2
bool ms_config_get_str(const char *key, char **value);
bool ms_config_set_str(const char *key, const char *value);
bool ms_config_get_bool(const char *key, int *value);
-#ifdef FMS_PERF
-void ms_check_start_time(struct timeval *start_time);
-void ms_check_end_time(struct timeval *end_time);
-void ms_check_time_diff(struct timeval *start_time, struct timeval *end_time);
-#endif/*FMS_PERF */
int ms_get_remain_space(double *free_space);
#ifdef _USE_RECORDED_CONTENT
bool ms_is_support_senior_mode(void);
#endif
+int ms_check_file_path(const char *file_path, uid_t uid);
+int ms_check_ignore_dir(const char *full_path, uid_t uid);
+int ms_check_scan_ignore(char * path);
+char* ms_get_path(uid_t uid);
+bool ms_storage_mount_status(const char* start_path);
+bool ms_is_valid_path(const char *path, uid_t uid);
+int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
+int ms_set_power_mode(ms_db_status_type_t status);
+void ms_trim_dir_path(char *dir_path);
+bool ms_check_folder_path(const char *folder_path);
+int ms_check_size_mediadb(uid_t uid, double *db_size);
+
+
#endif/*_MEDIA_SERVER_UTILS_H__*/
res = MS_MEDIA_ERR_DB_INSERT_FAIL;
}
}
-
+
return res;
}
+void ms_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid)
+{
+ /*call for bundle commit*/
+ if (ins_status) ms_register_start(handle, noti_enable, pid);
+ if (valid_status) ms_validate_start(handle);
+
+ return;
+}
+
+void ms_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, uid_t uid)
+{
+ /*call for bundle commit*/
+ if (valid_status) ms_validate_end(handle, uid);
+ if (ins_status) ms_register_end(handle, uid);
+
+ return;
+}
*/
#define _GNU_SOURCE
+#include <sys/types.h>
+#include <fcntl.h>
#include <errno.h>
#include <vconf.h>
#include <aul/aul.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <system_info.h>
+#include <dd-display.h>
+
+#ifndef _USE_DEVICED_DBUS
+#include <usb-device.h>
+#endif
#include "media-util.h"
#include "media-server-ipc.h"
#include "media-common-system.h"
#include "media-common-utils.h"
-#ifdef FMS_PERF
-#include <sys/time.h>
-#define MILLION 1000000L
-struct timeval g_mmc_start_time;
-struct timeval g_mmc_end_time;
-#endif
-
#define MS_DRM_CONTENT_TYPE_LENGTH 100
/* it's for 32bit file offset */
int __f_spare[6];
};
-#ifdef FMS_PERF
-void ms_check_start_time(struct timeval *start_time)
-{
- gettimeofday(start_time, NULL);
-}
-
-void ms_check_end_time(struct timeval *end_time)
-{
- gettimeofday(end_time, NULL);
-}
-
-void ms_check_time_diff(struct timeval *start_time, struct timeval *end_time)
-{
- struct timeval time;
- long difftime;
-
- time.tv_sec = end_time->tv_sec - start_time->tv_sec;
- time.tv_usec = end_time->tv_usec - start_time->tv_usec;
- difftime = MILLION * time.tv_sec + time.tv_usec;
- MS_DBG("The function_to_time took %ld microseconds or %f seconds.", difftime, difftime / (double)MILLION);
-}
-#endif
-
bool ms_is_mmc_inserted(void)
{
bool ret = FALSE;
} else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
ret = MS_STORAGE_EXTERNAL_USB;
} else {
+ MS_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
ret = MS_MEDIA_ERR_INVALID_PATH;
}
}
#endif
+int ms_check_file_path(const char *file_path, uid_t uid)
+{
+ int exist;
+ struct stat file_st;
+
+ /* check location of file */
+ /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
+ if (!ms_is_valid_path(file_path, uid)) {
+ MS_DBG_ERR("Invalid path : %s", file_path);
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ /* check the file exits actually */
+ exist = open(file_path, O_RDONLY);
+ if (exist < 0) {
+ MS_DBG_ERR("[%s]open files");
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+ close(exist);
+
+ /* check type of the path */
+ /* It must be a regular file */
+ memset(&file_st, 0, sizeof(struct stat));
+ if (stat(file_path, &file_st) == 0) {
+ if (!S_ISREG(file_st.st_mode)) {
+ /* In this case, it is not a regula file */
+ MS_DBG_ERR("this path is not a file");
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+ } else {
+ MS_DBG_STRERROR("stat failed");
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int ms_check_ignore_dir(const char *full_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *dir_path = NULL;
+ char *leaf_path = NULL;
+ char *usr_path = NULL;
+
+ ret = ms_check_file_path(full_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("invalid path : %s", full_path);
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ dir_path = g_path_get_dirname(full_path);
+ if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
+ MS_DBG_ERR("getting directory path is failed : %s", full_path);
+ MS_SAFE_FREE(dir_path);
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ usr_path = ms_get_path(uid);
+ if (usr_path == NULL) {
+ MS_DBG_ERR("ms_get_path() fail");
+ MS_SAFE_FREE(dir_path);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ while (1) {
+ if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+ break;
+ }
+
+#ifdef _USE_SENIOR_MODE
+ if(ms_is_support_senior_mode()) {
+ if(strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
+ break;
+ }
+#endif
+ if (strcmp(dir_path, usr_path) == 0)
+ break;
+ else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
+ break;
+ else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
+ break;
+
+ leaf_path = strrchr(dir_path, '/');
+ if (leaf_path != NULL) {
+ int seek_len = leaf_path -dir_path;
+ dir_path[seek_len] = '\0';
+ } else {
+ MS_DBG_ERR("Fail to find leaf path");
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+ break;
+ }
+ }
+
+ MS_SAFE_FREE(dir_path);
+ MS_SAFE_FREE(usr_path);
+
+ return ret;
+}
+
+int ms_check_scan_ignore(char * path)
+{
+ int fd = -1;
+ int exist = -1;
+ const char *ignore_path = "/.scan_ignore";
+ char *check_ignore_file = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
+
+ if (strstr(path, "/.")) {
+ MS_DBG_ERR("hidden path");
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+ goto ERROR;
+ }
+
+ fd = open(path, O_RDONLY | O_DIRECTORY);
+ if (fd == -1) {
+ MS_DBG_ERR("%s folder opendir fails", path);
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+
+ if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
+ MS_DBG_ERR("Fail to get USB path");
+ goto ERROR;
+ }
+
+ if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
+ if (errno == ENOENT) {
+ /*if the directory does not exist, check the device is unmounted*/
+ if (!ms_storage_mount_status(path)) {
+ MS_DBG_ERR("Device is unmounted[%s]", path);
+ ret = MS_MEDIA_ERR_USB_UNMOUNTED;
+ goto ERROR;
+ }
+ }
+ }
+
+ struct stat folder_st;
+ if (stat(path, &folder_st) == 0) {
+ MS_DBG_ERR("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
+ (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
+ } else {
+ MS_DBG_ERR("%s folder stat fails", path);
+ }
+
+ goto ERROR;
+ } else {
+ /* check the file exits actually */
+ int path_len = 0;
+
+ path_len = strlen(path) + strlen(ignore_path) + 1;
+ check_ignore_file = malloc(path_len);
+ if (check_ignore_file != NULL) {
+ memset(check_ignore_file, 0x0, path_len);
+ snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
+
+ exist = open(check_ignore_file, O_RDONLY);
+ if (exist >= 0) {
+ MS_DBG_ERR("scan_ignore exists [%s]", check_ignore_file);
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ MS_SAFE_FREE(check_ignore_file);
+ } else {
+ MS_DBG_ERR("malloc failed");
+ ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+ }
+
+ERROR:
+
+ if (fd != -1) {
+ close(fd);
+ fd = -1;
+ }
+
+ if (exist >= 0) close(exist);
+
+ return ret;
+}
+
+char* ms_get_path(uid_t uid)
+{
+ int len = 0;
+ char *result_passwd = NULL;
+ struct group *grpinfo = NULL;
+ if (uid == getuid()) {
+ grpinfo = getgrnam("users");
+ if (grpinfo == NULL) {
+ MS_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
+ result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+ } else {
+ char passwd_str[MAX_FILEPATH_LEN] = {0, };
+ struct passwd *userinfo = getpwuid(uid);
+ if (userinfo == NULL) {
+ MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if (grpinfo == NULL) {
+ MS_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+
+ len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+ if (len > 0)
+ result_passwd = strndup(passwd_str, len);
+ }
+
+ return result_passwd;
+}
+
+bool ms_storage_mount_status(const char* start_path)
+{
+ bool ret = false;
+#ifndef _USE_DEVICED_DBUS
+ int count = 0;
+ int err = 0;
+ usb_device_list_h list;
+ usb_device_h device;
+ char *mount_path = NULL;
+
+ char *storage_path = NULL;
+ char *remain_path = NULL;
+ int remain_len = 0;
+
+ remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
+ if (remain_path != NULL)
+ remain_len = strlen(remain_path);
+
+ storage_path = strndup(start_path, strlen(start_path) - remain_len);
+
+ MS_DBG_ERR("storage_path [%s]", storage_path);
+
+ err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
+ if (err == 0) {
+ count = usb_device_list_get_count(list);
+ if (count > 0) {
+ err = usb_device_list_get_first(list, &device);
+ if(err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
+ mount_path = usb_device_get_mountpath(device);
+ if (mount_path != NULL) {
+ MS_DBG_ERR("mount_path [%s]", mount_path);
+ if (strlen(mount_path) == strlen(storage_path)) {
+ if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
+ MS_DBG_ERR("start path is mounted [%s]", start_path);
+ ret = true;
+ }
+ }
+ }
+ }
+
+ if (ret != true) {
+ while(usb_device_list_get_next(list, &device) == 0) {
+ if(device != NULL) {
+ mount_path = usb_device_get_mountpath(device);
+ if (mount_path != NULL) {
+ MS_DBG_ERR("mount_path [%s]", mount_path);
+ if (strlen(mount_path) == strlen(storage_path)) {
+ if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
+ MS_DBG_ERR("start path is mounted [%s]", start_path);
+ ret = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ usb_device_free_device_list(list);
+ } else {
+ MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
+ }
+
+ MS_SAFE_FREE(storage_path);
+#endif
+ return ret;
+}
+
+bool ms_is_valid_path(const char *path, uid_t uid)
+{
+ bool ret = false;
+ char *usr_path = NULL;
+
+ if (path == NULL)
+ return false;
+
+ usr_path = ms_get_path(uid);
+ if (usr_path == NULL)
+ return false;
+
+#ifdef _USE_SENIOR_MODE
+ if(ms_is_support_senior_mode()) {
+ if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
+ return true;
+ }
+#endif
+
+ if (strncmp(path, usr_path, strlen(usr_path)) == 0)
+ ret = true;
+ else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
+ ret = true;
+ else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
+ ret = true;
+ else
+ ret = false;
+
+ MS_SAFE_FREE(usr_path);
+
+ return ret;
+}
+
+int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
+{
+ int res = MS_MEDIA_ERR_NONE;
+ int err = 0;
+
+ if (status == MS_DB_UPDATING) {
+ if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MS_DBG_ERR("ms_config_set_int failed");
+ }
+
+ if (storage_type == MS_STORAGE_EXTERNAL) {
+ if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MS_DBG_ERR("ms_config_set_int failed");
+ }
+ }
+ } else {
+ if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MS_DBG_ERR("ms_config_set_int failed");
+ }
+
+ if (storage_type == MS_STORAGE_EXTERNAL) {
+ if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MS_DBG_ERR("ms_config_set_int failed");
+ }
+ }
+ }
+
+ err = ms_set_power_mode(status);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_set_power_mode fail");
+ res = err;
+ }
+
+ return res;
+}
+
+int ms_set_power_mode(ms_db_status_type_t status)
+{
+ int res = MS_MEDIA_ERR_NONE;
+ int err;
+
+ switch (status) {
+ case MS_DB_UPDATING:
+ err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+ if (err != 0)
+ res = MS_MEDIA_ERR_INTERNAL;
+ break;
+ case MS_DB_UPDATED:
+ err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
+ if (err != 0)
+ res = MS_MEDIA_ERR_INTERNAL;
+ break;
+ default:
+ MS_DBG_ERR("Unacceptable type : %d", status);
+ break;
+ }
+
+ return res;
+}
+
+void ms_trim_dir_path(char *dir_path)
+{
+ /* need implementation */
+ /* if dir_path is not NULL terminated, this function will occure crash */
+ int len = strlen(dir_path);
+
+ if (dir_path[len -1] == '/')
+ dir_path[len -1] = '\0';
+}
+
+bool ms_check_folder_path(const char *folder_path)
+{
+ DIR *dp = NULL;
+
+ dp = opendir(folder_path);
+ if (dp == NULL) {
+ MS_DBG_ERR("Deleted folder path");
+ return false;
+ }
+ closedir(dp);
+
+ return true;
+}
+
+int ms_check_size_mediadb(uid_t uid, double *db_size)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *db_path = NULL;
+ struct stat buf;
+
+ ret = media_db_get_media_db_path(uid, &db_path);
+
+ if(stat(db_path, &buf) == 0) {
+ *db_size = buf.st_size;
+ } else {
+ MS_DBG_STRERROR("stat failed");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ }
+
+ MS_SAFE_FREE(db_path);
+
+ return ret;
+}
+
+
\r
#include "media-common-types.h"\r
\r
-int msc_check_size_mediadb(uid_t uid, double *db_size);\r
int msc_check_db_size(uid_t uid, int scan_type);\r
int msc_cleanup_invalid_values(uid_t uid);\r
\r
#include "media-scanner-common-v2.h"
int mmc_state2 = 0;
-bool msc_power_off2;
+bool power_off2;
int msc_set_mmc_status(ms_stg_status_e status)
{
int msc_set_power_status(bool status)
{
- msc_power_off2 = status;
+ power_off2 = status;
return MS_MEDIA_ERR_NONE;
}
int msc_get_power_status(bool *status)
{
- *status = msc_power_off2;
+ *status = power_off2;
return MS_MEDIA_ERR_NONE;
}
#include "media-scanner-dbg-v2.h"\r
#include "media-scanner-db-manage-v2.h"\r
\r
-int msc_check_size_mediadb(uid_t uid, double *db_size)\r
-{\r
- int ret = MS_MEDIA_ERR_NONE;\r
- char *db_path = NULL;\r
- struct stat buf;\r
-\r
- ret = media_db_get_media_db_path(uid, &db_path);\r
-\r
- if(stat(db_path, &buf) == 0) {\r
- *db_size = buf.st_size;\r
- } else {\r
- MS_DBG_STRERROR("stat failed");\r
- ret = MS_MEDIA_ERR_INTERNAL;\r
- }\r
-\r
- MS_SAFE_FREE(db_path);\r
-\r
- return ret;\r
-}\r
-\r
int msc_check_db_size(uid_t uid, int scan_type)\r
{\r
double db_size = 0.0;\r
double free_space = 0.0;\r
int err = MS_MEDIA_ERR_NONE;\r
\r
- msc_check_size_mediadb(uid, &db_size);\r
+ ms_check_size_mediadb(uid, &db_size);\r
\r
if (scan_type == MS_MSG_STORAGE_ALL\r
|| scan_type == MS_MSG_STORAGE_PARTIAL) {\r
msc_cleanup_invalid_values(uid);\r
MS_DBG_ERR("END REMOVE INVALID DATA");\r
\r
- msc_check_size_mediadb(uid, &db_size);\r
+ ms_check_size_mediadb(uid, &db_size);\r
if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {\r
ms_config_set_int(MS_DB_LIMIT, 0);\r
MS_DBG_ERR("DB IS FULL. CANNOT UPDATE");\r
\r
media_db_disconnect(handle);\r
\r
- msc_check_size_mediadb(uid, &db_size);\r
+ ms_check_size_mediadb(uid, &db_size);\r
MS_DBG_ERR("END CLEANUP MEDIA DB[%lf]", db_size);\r
\r
for (i = 0; i < count; i ++) {\r
#define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
#define LAST_EVENT 1
#define NORMAL_EVENT 0
-#ifdef FMS_PERF
-extern struct timeval g_mmc_start_time;
-extern struct timeval g_mmc_end_time;
-#endif
static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid);
static int __msc_set_storage_extract_status(ms_storage_scan_status_e status);
/*call for bundle commit*/
if (extract_data.msg_type != MS_MSG_STORAGE_INVALID)
- __msc_bacth_commit_disable(handle, TRUE, valid_status, scan_data->storage_id, ret);
+ ms_bacth_commit_disable(handle, TRUE, valid_status, scan_data->storage_id, ret);
if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
int del_count = 0;
#include <dirent.h>
#include <errno.h>
#include <malloc.h>
-#include <dd-display.h>
#include <vconf.h>
#ifndef _USE_DEVICED_DBUS
#include <usb-device.h>
GMutex blocked_mutex2;
GMutex storage_scan_mutex2;
GMutex dir_scan_mutex2;
+GCond data_cond2; /* Must be initialized somewhere */
+GMutex data_mutex2; /* Must be initialized somewhere */
+gpointer current_data2 = NULL;
+GMutex scan_item_mutex;
char *g_cancel_path2;
char *g_blocked_path2;
-GMutex scan_item_mutex;
s_scan_item* cancel_scan_item = NULL;
s_scan_item* cur_scan_item = NULL;
unsigned int io_err_folder;
unsigned int io_err_storage;
-
typedef int (*DIR_SCAN_CB)();
DIR_SCAN_CB g_dir_scan_cb;
-#ifdef FMS_PERF
-extern struct timeval g_mmc_start_time;
-extern struct timeval g_mmc_end_time;
-#endif
+struct linux_dirent {
+ ino64_t d_ino; /* 64-bit inode number */
+ off64_t d_off; /* 64-bit offset to next structure */
+ unsigned short d_reclen; /* Size of this dirent */
+ unsigned char d_type; /* File type */
+ char d_name[]; /* Filename (null-terminated) */
+};
+
+#define BUF_SIZE 1024
-static int __msc_set_power_mode(ms_db_status_type_t status);
-static int __msc_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
static int __msc_check_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid);
static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_msg_s * scan_data);
-static int __msc_check_file_path(const char *file_path, uid_t uid);
static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid);
static int __msc_batch_insert(ms_msg_type_e current_msg, int pid, GArray *path_array, uid_t uid);
static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
static int __msc_clear_file_list(GArray *path_array);
-static int __msc_check_scan_ignore(char * path);
-static bool __msc_is_valid_path(const char *path, uid_t uid);
-static void __msc_trim_dir_path(char *dir_path);
static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
-static void __msc_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid);
-static void __msc_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, const char *path, int result, uid_t uid);
static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid);
static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid);
-
-static bool __msc_storage_mount_status(const char* start_path);
-static char* __msc_get_path(uid_t uid);
-
static int __msc_get_null_scan_folder_list(void **handle, const char *stroage_id, char *path, GArray *dir_array);
static int __msc_dir_scan_cb();
static int __msc_check_scan_same_path(char *scan_path);
static int __msc_dir_and_storage_scan_same_path();
static int __msc_check_memory_status(uid_t uid);
static int __msc_check_remain_space(uid_t uid);
-static bool __msc_check_folder_path(const char *folder_path);
static int __msc_set_dir_scan_cb(DIR_SCAN_CB cb)
{
return MS_MEDIA_ERR_NONE;
}
-static char* __msc_get_path(uid_t uid)
-{
- int len = 0;
- char *result_passwd = NULL;
- struct group *grpinfo = NULL;
- if (uid == getuid()) {
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- MS_DBG_ERR("getgrnam(users) returns NULL !");
- return NULL;
- }
- if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
- result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
- } else {
- char passwd_str[MAX_FILEPATH_LEN] = {0, };
- struct passwd *userinfo = getpwuid(uid);
- if (userinfo == NULL) {
- MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
- return NULL;
- }
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- MS_DBG_ERR("getgrnam(users) returns NULL !");
- return NULL;
- }
- // Compare git_t type and not group name
- if (grpinfo->gr_gid != userinfo->pw_gid) {
- MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
- return NULL;
- }
-
- len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
- if (len > 0)
- result_passwd = strndup(passwd_str, len);
- }
-
- return result_passwd;
-}
-
-static int __msc_set_power_mode(ms_db_status_type_t status)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err;
-
- switch (status) {
- case MS_DB_UPDATING:
- err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- case MS_DB_UPDATED:
- err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- default:
- MS_DBG_ERR("Unacceptable type : %d", status);
- break;
- }
-
- return res;
-}
-
-static int __msc_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err = 0;
-
- if (status == MS_DB_UPDATING) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
- if (storage_type == MS_STORAGE_EXTERNAL) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
- } else if (status == MS_DB_UPDATED) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
- if (storage_type == MS_STORAGE_EXTERNAL) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
- } else {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
- if (storage_type == MS_STORAGE_EXTERNAL) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
- }
-
- err = __msc_set_power_mode(status);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("__msc_set_power_mode fail");
- res = err;
- }
-
- return res;
-}
-
-static int __msc_check_scan_ignore(char * path)
-{
- int fd = -1;
- int exist = -1;
- const char *ignore_path = "/.scan_ignore";
- char *check_ignore_file = NULL;
- int ret = MS_MEDIA_ERR_NONE;
-
- if (strstr(path, "/.")) {
- MS_DBG_ERR("hidden path");
- ret = MS_MEDIA_ERR_INVALID_PATH;
- goto ERROR;
- }
-
- fd = open(path, O_RDONLY | O_DIRECTORY);
- if (fd == -1) {
- MS_DBG_ERR("%s folder opendir fails", path);
- ret = MS_MEDIA_ERR_INVALID_PATH;
-
- if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
- MS_DBG_ERR("Fail to get USB path");
- goto ERROR;
- }
-
- if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
- if (errno == ENOENT) {
- /*if the directory does not exist, check the device is unmounted*/
- if (!__msc_storage_mount_status(path)) {
- MS_DBG_ERR("Device is unmounted[%s]", path);
- ret = MS_MEDIA_ERR_USB_UNMOUNTED;
- goto ERROR;
- }
- }
- }
-
- struct stat folder_st;
- if (stat(path, &folder_st) == 0) {
- MS_DBG_ERR("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
- (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
- } else {
- MS_DBG_ERR("%s folder stat fails", path);
- }
-
- goto ERROR;
- } else {
- /* check the file exits actually */
- int path_len = 0;
-
- path_len = strlen(path) + strlen(ignore_path) + 1;
- check_ignore_file = malloc(path_len);
- if (check_ignore_file != NULL) {
- memset(check_ignore_file, 0x0, path_len);
- snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
-
- exist = open(check_ignore_file, O_RDONLY);
- if (exist >= 0) {
- MS_DBG_ERR("scan_ignore exists [%s]", check_ignore_file);
- ret = MS_MEDIA_ERR_INVALID_PATH;
- }
-
- MS_SAFE_FREE(check_ignore_file);
- } else {
- MS_DBG_ERR("malloc failed");
- ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- }
-
-ERROR:
-
- if (fd != -1) {
- close(fd);
- fd = -1;
- }
-
- if (exist >= 0) close(exist);
-
- return ret;
-}
-
-GCond data_cond2; /* Must be initialized somewhere */
-GMutex data_mutex2; /* Must be initialized somewhere */
-gpointer current_data2 = NULL;
-
int msc_init_scan_thread()
{
g_mutex_init(&data_mutex2);
return ret;
}
-static void __msc_trim_dir_path(char *dir_path)
-{
- /* need implementation */
- /* if dir_path is not NULL terminated, this function will occure crash */
- int len = strlen(dir_path);
-
- if (dir_path[len -1] == '/')
- dir_path[len -1] = '\0';
-}
-
-struct linux_dirent {
- ino64_t d_ino; /* 64-bit inode number */
- off64_t d_off; /* 64-bit offset to next structure */
- unsigned short d_reclen; /* Size of this dirent */
- unsigned char d_type; /* File type */
- char d_name[]; /* Filename (null-terminated) */
-};
-
-#define BUF_SIZE 1024
-
static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid)
{
GArray *dir_array = NULL;
MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);
}
- if (__msc_check_folder_path(new_start_path) == TRUE) {
+ if (ms_check_folder_path(new_start_path) == TRUE) {
if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("insert folder failed");
}
__msc_set_dir_scan_cur_path(current_path);
- ret = __msc_check_scan_ignore(current_path);
+ ret = ms_check_scan_ignore(current_path);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
__msc_set_storage_scan_cur_path(current_path);
- ret = __msc_check_scan_ignore(current_path);
+ ret = ms_check_scan_ignore(current_path);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
}
/*remove invalid folder in folder table.*/
- if (__msc_storage_mount_status(new_start_path)) {
+ if (ms_storage_mount_status(new_start_path)) {
if ((g_directory_scan_processing2 != DIR_SCAN_NON_SCAN)
&& (__msc_dir_and_storage_scan_same_path(new_start_path) == MS_MEDIA_ERR_NONE)) {
__msc_set_dir_scan_cb(__msc_dir_scan_cb);
return MS_MEDIA_ERR_NONE;
}
-static bool __msc_check_folder_path(const char *folder_path)
-{
- DIR *dp = NULL;
-
- dp = opendir(folder_path);
- if (dp == NULL) {
- MS_DBG_ERR("Deleted folder path");
- return false;
- }
- closedir(dp);
-
- return true;
-}
-
gboolean msc_directory_scan_thread(void *data)
{
ms_comm_msg_s *scan_data = NULL;
goto NEXT;
}
- __msc_trim_dir_path(scan_data->msg);
+ ms_trim_dir_path(scan_data->msg);
- if (__msc_check_folder_path(scan_data->msg)) {
+ if (ms_check_folder_path(scan_data->msg)) {
is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("error : %d", err);
/*call for bundle commit*/
- __msc_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
+ ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
/*insert data into media db */
ret = __msc_db_update(handle, storage_id, scan_data);
/*call for bundle commit*/
- __msc_bacth_commit_disable(handle, TRUE, TRUE, scan_data->msg, ret, uid);
+ ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
MS_DBG_ERR("folder scan done, sent cb event path = [%s]", scan_data->msg);
__msc_call_dir_scan_cb();
g_array_remove_index(read_dir_array, 0);
// MS_DBG_ERR("%s", current_path);
- if (__msc_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
+ if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
continue;
MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
msc_insert_exactor_request(scan_type, TRUE, scan_data->storage_id, scan_data->msg, scan_data->pid, uid);
goto NEXT;
- }
+ }
ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_PROCESSING, uid);
/*start db updating */
- __msc_set_db_status(MS_DB_UPDATING, storage_type);
+ ms_set_db_status(MS_DB_UPDATING, storage_type);
valid_status = (scan_type == MS_MSG_STORAGE_PARTIAL || MS_MSG_STORAGE_ALL == scan_type) ? TRUE : FALSE;
if (scan_type != MS_MSG_STORAGE_INVALID)
- __msc_bacth_commit_enable(handle, TRUE, valid_status, MS_NOTI_SWITCH_OFF, 0);
+ ms_bacth_commit_enable(handle, TRUE, valid_status, MS_NOTI_SWITCH_OFF, 0);
if (scan_type == MS_MSG_STORAGE_PARTIAL && storage_type == MS_STORAGE_INTERNAL) {
ms_validaty_change_all_items(handle, scan_data->storage_id, storage_type, true, uid);
/*call for bundle commit*/
if (scan_type != MS_MSG_STORAGE_INVALID) {
- __msc_bacth_commit_disable(handle, TRUE, valid_status, scan_data->msg, ret, uid);
+ ms_bacth_commit_disable(handle, TRUE, valid_status, uid);
}
if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, uid);
/*set vconf key mmc loading for indicator */
- __msc_set_db_status(MS_DB_STOPPED, storage_type);
+ ms_set_db_status(MS_DB_STOPPED, storage_type);
} else {
ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_COMPLETE, uid);
/*set vconf key mmc loading for indicator */
- __msc_set_db_status(MS_DB_UPDATED, storage_type);
+ ms_set_db_status(MS_DB_UPDATED, storage_type);
}
MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
}
}
-static bool __msc_is_valid_path(const char *path, uid_t uid)
-{
- bool ret = false;
- char *usr_path = NULL;
-
- if (path == NULL)
- return false;
-
- usr_path = __msc_get_path(uid);
- if (usr_path == NULL)
- return false;
-
-#ifdef _USE_SENIOR_MODE
- if(ms_is_support_senior_mode()) {
- if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
- return true;
- }
-#endif
-
- if (strncmp(path, usr_path, strlen(usr_path)) == 0)
- ret = true;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
- ret = true;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
- ret = true;
- else
- ret = false;
-
- MS_SAFE_FREE(usr_path);
-
- return ret;
-}
-
-static int __msc_check_file_path(const char *file_path, uid_t uid)
-{
- int exist;
- struct stat file_st;
-
- /* check location of file */
- /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
- if (!__msc_is_valid_path(file_path, uid)) {
- MS_DBG_ERR("Invalid path : %s", file_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- /* check the file exits actually */
- exist = open(file_path, O_RDONLY);
- if (exist < 0) {
- MS_DBG_ERR("[%s]open files");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- close(exist);
-
- /* check type of the path */
- /* It must be a regular file */
- memset(&file_st, 0, sizeof(struct stat));
- if (stat(file_path, &file_st) == 0) {
- if (!S_ISREG(file_st.st_mode)) {
- /* In this case, it is not a regula file */
- MS_DBG_ERR("this path is not a file");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- } else {
- MS_DBG_STRERROR("stat failed");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
static int __msc_clear_file_list(GArray *path_array)
{
if (path_array) {
return MS_MEDIA_ERR_NONE;
}
-static int __msc_check_ignore_dir(const char *full_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *dir_path = NULL;
- char *leaf_path = NULL;
- char *user_path = NULL;
-
- ret = __msc_check_file_path(full_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("invalid path : %s", full_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- dir_path = g_path_get_dirname(full_path);
- if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
- MS_DBG_ERR("getting directory path is failed : %s", full_path);
- MS_SAFE_FREE(dir_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- while (1) {
- if (__msc_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
- ret = MS_MEDIA_ERR_INVALID_PATH;
- break;
- }
-
-#ifdef _USE_SENIOR_MODE
- if(ms_is_support_senior_mode()) {
- if(strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
- break;
- }
-#endif
-
- /*If root path, Stop Scanning*/
- user_path = __msc_get_path(uid);
- if (user_path == NULL) {
- ret = MS_MEDIA_ERR_INTERNAL;
- break;
- }
-
- if (strcmp(dir_path, user_path) == 0)
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
- break;
-
- leaf_path = strrchr(dir_path, '/');
- if (leaf_path != NULL) {
- int seek_len = leaf_path -dir_path;
- dir_path[seek_len] = '\0';
- } else {
- MS_DBG_ERR("Fail to find leaf path");
- ret = MS_MEDIA_ERR_INVALID_PATH;
- break;
- }
- }
-
- MS_SAFE_FREE(dir_path);
- MS_SAFE_FREE(user_path);
-
- return ret;
-}
-
static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
{
FILE *fp = NULL;
path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
/* check valid path */
- ret = __msc_check_ignore_dir(path, uid);
+ ret = ms_check_ignore_dir(path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("invalide path : %s", path);
MS_SAFE_FREE(path);
/*start db updating */
/*call for bundle commit*/
- __msc_bacth_commit_enable(handle, TRUE, FALSE, MS_NOTI_SWITCH_ON, pid);
+ ms_bacth_commit_enable(handle, TRUE, FALSE, MS_NOTI_SWITCH_ON, pid);
MS_DBG_ERR("BULK REGISTER START");
}
/*call for bundle commit*/
- __msc_bacth_commit_disable(handle, TRUE, FALSE, NULL, MS_MEDIA_ERR_NONE, uid);
+ ms_bacth_commit_disable(handle, TRUE, FALSE, uid);
/*disconnect form media db*/
if (handle) ms_disconnect_db(&handle);
return false;
}
-static void __msc_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid)
-{
- /*call for bundle commit*/
- if (ins_status) ms_register_start(handle, noti_enable, pid);
- if (valid_status) ms_validate_start(handle);
-
- return;
-}
-
-static void __msc_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, const char *path, int result, uid_t uid)
-{
- /*call for bundle commit*/
- if (valid_status) ms_validate_end(handle, uid);
- if (ins_status) ms_register_end(handle, uid);
-
- return;
-}
-
int _msc_set_scan_item(s_scan_item** item, const char* path, int pid)
{
s_scan_item* scan_item = *item;
return ret;
}
-static bool __msc_storage_mount_status(const char* start_path)
-{
- bool ret = false;
-#ifndef _USE_DEVICED_DBUS
- int count = 0;
- int err = 0;
- usb_device_list_h list;
- usb_device_h device;
- char *mount_path = NULL;
-
- char *storage_path = NULL;
- char *remain_path = NULL;
- int remain_len = 0;
-
- remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
- if (remain_path != NULL)
- remain_len = strlen(remain_path);
-
- storage_path = strndup(start_path, strlen(start_path) - remain_len);
-
- MS_DBG_ERR("storage_path [%s]", storage_path);
-
- err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
- if (err == 0) {
- count = usb_device_list_get_count(list);
- if (count > 0) {
- err = usb_device_list_get_first(list, &device);
- if(err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
- mount_path = usb_device_get_mountpath(device);
- if (mount_path != NULL) {
- MS_DBG_ERR("mount_path [%s]", mount_path);
- if (strlen(mount_path) == strlen(storage_path)) {
- if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
- MS_DBG_ERR("start path is mounted [%s]", start_path);
- ret = true;
- }
- }
- }
- }
-
- if (ret != true) {
- while(usb_device_list_get_next(list, &device) == 0) {
- if(device != NULL) {
- mount_path = usb_device_get_mountpath(device);
- if (mount_path != NULL) {
- MS_DBG_ERR("mount_path [%s]", mount_path);
- if (strlen(mount_path) == strlen(storage_path)) {
- if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
- MS_DBG_ERR("start path is mounted [%s]", start_path);
- ret = true;
- break;
- }
- }
- }
- }
- }
- }
- }
-
- usb_device_free_device_list(list);
- } else {
- MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
- }
-
- MS_SAFE_FREE(storage_path);
-#endif
- return ret;
-}
-
int msc_set_blocked_path(const char *blocked_path)
{
MS_DBG_FENTER();
|| err == MS_MEDIA_ERR_DB_FULL_FAIL){
return err;
}
-
+
/*check db size*/
- msc_check_size_mediadb(uid, &db_size);
+ ms_check_size_mediadb(uid, &db_size);
if (db_size >= MEDIA_DB_SIZE_LIMIT_1) {
MS_DBG_ERR("DB SIZE [%lf] REACH THE FIRST LIMIT [%lf]", db_size, MEDIA_DB_SIZE_LIMIT_1);
return MS_MEDIA_ERR_DB_LIMIT_1;
}
}
- err = msc_check_size_mediadb(uid, &db_size);
+ err = ms_check_size_mediadb(uid, &db_size);
if (err != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("msc_check_dbsize failed");
} else {
msc_cleanup_invalid_values(uid);
MS_DBG_ERR("END REMOVE INVALID DATA");
- msc_check_size_mediadb(uid, &db_size);
+ ms_check_size_mediadb(uid, &db_size);
if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {
ms_config_set_int(MS_DB_LIMIT, 0);
MS_DBG_ERR("DB IS FULL. CANNOT UPDATE[%lf]", db_size);
int stg_scan_status;
-#ifdef FMS_PERF
-extern struct timeval g_mmc_start_time;
-extern struct timeval g_mmc_end_time;
-#endif
-
-static int __msc_set_power_mode(ms_db_status_type_t status);
-static int __msc_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
static int __msc_check_stop_status(ms_storage_type_t storage_type);
static int __msc_stg_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid);
static int __msc_dir_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, bool is_recursive, uid_t uid);
static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_msg_s * scan_data);
-static int __msc_check_file_path(const char *file_path, uid_t uid);
-static bool __msc_check_folder_path(const char *folder_path);
static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid);
static int __msc_batch_insert(ms_msg_type_e current_msg, int pid, GArray *path_array, uid_t uid);
static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
static int __msc_clear_file_list(GArray *path_array);
-static bool __msc_check_scan_ignore(char * path);
-static bool __msc_is_valid_path(const char *path, uid_t uid);
-static void __msc_trim_dir_path(char *dir_path);
static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
-static void __msc_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid);
-static void __msc_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, uid_t uid);
static int __msc_set_storage_scan_status(ms_storage_scan_status_e status);
//static int __msc_get_storage_scan_status(ms_storage_scan_status_e *status, uid_t uid);
-//static bool __msc_storage_mount_status(const char* start_path);
-static char* __msc_get_path(uid_t uid);
-
-static char* __msc_get_path(uid_t uid)
-{
- int len = 0;
- char *result_passwd = NULL;
- struct group *grpinfo = NULL;
- if (uid == getuid()) {
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- MS_DBG_ERR("getgrnam(users) returns NULL !");
- return NULL;
- }
- if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
- result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
- } else {
- char passwd_str[MAX_FILEPATH_LEN] = {0, };
- struct passwd *userinfo = getpwuid(uid);
- if (userinfo == NULL) {
- MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
- return NULL;
- }
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- MS_DBG_ERR("getgrnam(users) returns NULL !");
- return NULL;
- }
- // Compare git_t type and not group name
- if (grpinfo->gr_gid != userinfo->pw_gid) {
- MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
- return NULL;
- }
-
- len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
- if (len > 0)
- result_passwd = strndup(passwd_str, len);
- }
-
- return result_passwd;
-}
-
-static int __msc_set_power_mode(ms_db_status_type_t status)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err;
-
- switch (status) {
- case MS_DB_UPDATING:
- err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- case MS_DB_UPDATED:
- err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- default:
- MS_DBG_ERR("Unacceptable type : %d", status);
- break;
- }
-
- return res;
-}
-
-static int __msc_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err = 0;
-
- if (status == MS_DB_UPDATING) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
- if (storage_type == MS_STORAGE_EXTERNAL) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
- } else if (status == MS_DB_UPDATED) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
- if (storage_type == MS_STORAGE_EXTERNAL) {
- if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
- }
-
- err = __msc_set_power_mode(status);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("__msc_set_power_mode fail");
- res = err;
- }
-
- return res;
-}
-
-static bool __msc_check_scan_ignore(char * path)
-{
- DIR *dp = NULL;
- struct dirent entry;
- struct dirent *result;
- const char *ignore_path = ".scan_ignore";
-
- if (strstr(path, "/.")) {
- MS_DBG_ERR("hidden path");
- return true;
- }
-
- dp = opendir(path);
- if (dp == NULL) {
- MS_DBG_ERR("%s folder opendir fails", path);
- return true;
- }
-
- while (!readdir_r(dp, &entry, &result)) {
- if (result == NULL)
- break;
-
- if (strcmp(entry.d_name, ignore_path) == 0) {
- closedir(dp);
- return true;
- }
- }
-
- closedir(dp);
- return false;
-}
#if 0
GCond data_cond;
return ret;
}
-static void __msc_trim_dir_path(char *dir_path)
-{
- /* need implementation */
- /* if dir_path is not NULL terminated, this function will occure crash */
- int len = strlen(dir_path);
-
- if (dir_path[len -1] == '/')
- dir_path[len -1] = '\0';
-}
-
static bool __msc_check_mount_storage(const char* start_path)
{
bool ret = FALSE;
g_array_remove_index(dir_array, 0);
MS_DBG_SLOG("%d", dir_array->len);
- if (__msc_check_scan_ignore(current_path)) {
+ if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
continue;
int ret = MS_MEDIA_ERR_NONE;
/*call for bundle commit*/
- __msc_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
+ ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
__msc_read_dir(handle, dir_array, start_path, storage_id, storage_type, scan_type, uid);
/*call for bundle commit*/
- __msc_bacth_commit_disable(handle, TRUE, TRUE, uid);
+ ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
MS_DBG_INFO("ret : %d", ret);
}
}
- if (__msc_check_folder_path(new_start_path)) {
+ if (ms_check_folder_path(new_start_path)) {
ms_insert_folder(handle, storage_id, new_start_path, uid);
}
g_array_remove_index(dir_array, 0);
// MS_DBG_SLOG("%d", dir_array->len);
- if (__msc_check_scan_ignore(current_path)) {
+ if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
continue;
goto NEXT;
}
- __msc_trim_dir_path(scan_data->msg);
+ ms_trim_dir_path(scan_data->msg);
- if (__msc_check_folder_path(scan_data->msg)) {
+ if (ms_check_folder_path(scan_data->msg)) {
is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
g_array_remove_index(read_dir_array, 0);
// MS_DBG_ERR("%s", current_path);
- if (__msc_check_scan_ignore(current_path)) {
+ if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
continue;
}
/*start db updating */
- __msc_set_db_status(MS_DB_UPDATING, storage_type);
+ ms_set_db_status(MS_DB_UPDATING, storage_type);
valid_status = (scan_type == MS_MSG_STORAGE_PARTIAL) ? TRUE : FALSE;
- __msc_bacth_commit_enable(handle, TRUE, valid_status, MS_NOTI_SWITCH_OFF, 0);
-
-#ifdef FMS_PERF
- ms_check_start_time(&g_mmc_start_time);
-#endif
+ ms_bacth_commit_enable(handle, TRUE, valid_status, MS_NOTI_SWITCH_OFF, 0);
if (scan_type == MS_MSG_STORAGE_PARTIAL && storage_type == MS_STORAGE_INTERNAL) {
ms_validaty_change_all_items(handle, storage_id, storage_type, true, scan_data->uid);
}
/*call for bundle commit*/
- __msc_bacth_commit_disable(handle, TRUE, valid_status, scan_data->uid);
+ ms_bacth_commit_disable(handle, TRUE, valid_status, scan_data->uid);
if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
int del_count = 0;
/* send notification */
ms_send_dir_update_noti(handle, storage_id, update_path, NULL, MS_ITEM_UPDATE, scan_data->pid);
-#ifdef FMS_PERF
- ms_check_end_time(&g_mmc_end_time);
- ms_check_time_diff(&g_mmc_start_time, &g_mmc_end_time);
-#endif
-
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_STOP, scan_data->uid);
__msc_set_storage_scan_status(MS_STORAGE_SCAN_STOP);
/*set vconf key mmc loading for indicator */
- __msc_set_db_status(MS_DB_STOPPED, storage_type);
+ ms_set_db_status(MS_DB_STOPPED, storage_type);
} else {
ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_COMPLETE, scan_data->uid);
__msc_set_storage_scan_status(MS_STORAGE_SCAN_COMPLETE);
/*set vconf key mmc loading for indicator */
- __msc_set_db_status(MS_DB_UPDATED, storage_type);
+ ms_set_db_status(MS_DB_UPDATED, storage_type);
}
NEXT:
}
}
-static bool __msc_is_valid_path(const char *path, uid_t uid)
-{
- bool ret = false;
- char *usr_path = NULL;
-
- if (path == NULL)
- return false;
-
- usr_path = __msc_get_path(uid);
- if (usr_path == NULL)
- return false;
-
- if (strncmp(path, usr_path, strlen(usr_path)) == 0) {
- ret = true;
- } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
- ret = true;
- } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
- ret = true;
- } else {
- ret = false;
- }
-
- MS_SAFE_FREE(usr_path);
-
- return ret;
-}
-
-static int __msc_check_file_path(const char *file_path, uid_t uid)
-{
- int exist;
- struct stat file_st;
-
- /* check location of file */
- /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
- if (!__msc_is_valid_path(file_path, uid)) {
- MS_DBG_ERR("Invalid path : %s", file_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- /* check the file exits actually */
- exist = open(file_path, O_RDONLY);
- if (exist < 0) {
- MS_DBG_ERR("[%s]open files");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- close(exist);
-
- /* check type of the path */
- /* It must be a regular file */
- memset(&file_st, 0, sizeof(struct stat));
- if (stat(file_path, &file_st) == 0) {
- if (!S_ISREG(file_st.st_mode)) {
- /* In this case, it is not a regula file */
- MS_DBG_ERR("this path is not a file");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- } else {
- MS_DBG_STRERROR("stat failed");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static bool __msc_check_folder_path(const char *folder_path)
-{
- DIR *dp = NULL;
-
- dp = opendir(folder_path);
- if (dp == NULL) {
- MS_DBG_ERR("Deleted folder path");
- return false;
- }
- closedir(dp);
-
- return true;
-}
-
static int __msc_clear_file_list(GArray *path_array)
{
if (path_array) {
return MS_MEDIA_ERR_NONE;
}
-static int __msc_check_ignore_dir(const char *full_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *dir_path = NULL;
- char *leaf_path = NULL;
- char *usr_path = NULL;
-
- ret = __msc_check_file_path(full_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("invalid path : %s", full_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- dir_path = g_path_get_dirname(full_path);
- if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
- MS_DBG_ERR("getting directory path is failed : %s", full_path);
- MS_SAFE_FREE(dir_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- usr_path = __msc_get_path(uid);
- if (usr_path == NULL) {
- MS_DBG_ERR("__msc_get_path() fail");
- MS_SAFE_FREE(dir_path);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- while (1) {
- if (__msc_check_scan_ignore(dir_path)) {
- ret = MS_MEDIA_ERR_INVALID_PATH;
- break;
- }
-
- /*If root path, Stop Scanning*/
- if (strcmp(dir_path, usr_path) == 0)
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
- break;
-
- leaf_path = strrchr(dir_path, '/');
- if (leaf_path != NULL) {
- int seek_len = leaf_path -dir_path;
- dir_path[seek_len] = '\0';
- } else {
- MS_DBG_ERR("Fail to find leaf path");
- ret = MS_MEDIA_ERR_INVALID_PATH;
- break;
- }
- }
-
- MS_SAFE_FREE(dir_path);
- MS_SAFE_FREE(usr_path);
-
- return ret;
-}
-
static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
{
FILE *fp = NULL;
path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
/* check valid path */
- ret = __msc_check_ignore_dir(path, uid);
+ ret = ms_check_ignore_dir(path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("invalide path : %s", path);
MS_SAFE_FREE(path);
/*start db updating */
/*call for bundle commit*/
- __msc_bacth_commit_enable(handle, TRUE, FALSE, MS_NOTI_SWITCH_ON, pid);
+ ms_bacth_commit_enable(handle, TRUE, FALSE, MS_NOTI_SWITCH_ON, pid);
MS_DBG_ERR("BULK REGISTER START[%d]", pid);
}
/*call for bundle commit*/
- __msc_bacth_commit_disable(handle, TRUE, FALSE, uid);
+ ms_bacth_commit_disable(handle, TRUE, FALSE, uid);
/*disconnect form media db*/
if (handle) ms_disconnect_db(&handle);
return false;
}
-static void __msc_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid)
-{
- /*call for bundle commit*/
- if (ins_status) ms_register_start(handle, noti_enable, pid);
- if (valid_status) ms_validate_start(handle);
-
- return;
-}
-
-static void __msc_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, uid_t uid)
-{
- /*call for bundle commit*/
- if (ins_status) ms_register_end(handle, uid);
- if (valid_status) ms_validate_end(handle, uid);
-
- return;
-}
-
int msc_set_cancel_path(const char *cancel_path)
{
if (g_cancel_path != NULL) {
g_array_remove_index(dir_array, 0);
// MS_DBG_SLOG("%d", dir_array->len);
- if (__msc_check_scan_ignore(current_path)) {
+ if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
MS_SAFE_FREE(current_path);
continue;
ms_update_start(handle);
/*insert data into media db */
- char *usr_path = __msc_get_path(scan_data->uid);
+ char *usr_path = ms_get_path(scan_data->uid);
if (usr_path == NULL) {
- MS_DBG_ERR("__msc_get_path() fail");
+ MS_DBG_ERR("ms_get_path() fail");
if (handle) ms_disconnect_db(&handle);
return MS_MEDIA_ERR_INTERNAL;
}
\r
#include "media-common-types.h"\r
\r
-int ms_check_size_mediadb(uid_t uid, double *db_size);\r
int ms_reset_mediadb(uid_t uid);\r
int ms_check_mediadb(uid_t uid, bool *is_reset);\r
int ms_check_corrupt_mediadb(void);\r
#include "media-server-thumb.h"\r
#include "media-server-db-manage.h"\r
\r
-int ms_check_size_mediadb(uid_t uid, double *db_size)\r
-{\r
- int ret = MS_MEDIA_ERR_NONE;\r
- char *db_path = NULL;\r
- struct stat buf;\r
-\r
- ret = media_db_get_media_db_path(uid, &db_path);\r
-\r
- if(stat(db_path, &buf) == 0) {\r
- *db_size = buf.st_size;\r
- } else {\r
- MS_DBG_STRERROR("stat failed");\r
- ret = MS_MEDIA_ERR_INTERNAL;\r
- }\r
-\r
- MS_SAFE_FREE(db_path);\r
-\r
- return ret;\r
-}\r
-\r
int ms_reset_mediadb(uid_t uid)\r
{\r
MS_DBG_ERR("[MEDIA DB RESET START]");\r