src/common/media-common-system.c \
src/common/media-common-external-storage.c \
src/common/media-common-db-svc.c \
- src/scanner/media-scanner-device-block.c \
src/scanner/media-scanner-scan.c \
src/scanner/media-scanner-socket.c \
src/scanner/media-scanner.c
char msg[MAX_MSG_SIZE];
} ms_comm_msg_s;
-typedef enum {
- CLIENT_SOCKET,
- SERVER_SOCKET
-} ms_socket_type_e;
-
typedef struct {
ms_msg_type_e msg_type;
} ms_thumb_server_msg;
typedef struct ms_dir_info_s {
char *dir_path;
int modified_time;
- int item_num;
} ms_dir_info_s;
typedef struct ms_stg_info_s {
typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void *, const char *, int, uid_t, char **);
typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void *, const char *, const char *, bool, uid_t, char**);
typedef int (*COUNT_DELETE_ITEMS_IN_FOLDER)(void *, const char *, const char *, int *, char **);
-typedef int (*GET_FOLDER_LIST)(void *, const char *, char *, char ***, int **, int **, int *, char **);
+typedef int (*GET_FOLDER_LIST)(void *, const char *, char *, char ***, int **, int *, char **);
typedef int (*UPDATE_FOLDER_TIME)(void *, const char *, const char *, uid_t, char **);
typedef int (*GET_STORAGE_ID)(void *, const char *, char *, uid_t uid, char **);
typedef int (*SET_STORAGE_SCAN_STATUS)(void *, const char *, int, uid_t, char **);
bool ms_config_get_int(const char *key, int *value);
bool ms_config_set_int(const char *key, int value);
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);
int ms_get_remain_space(double *free_space);
#ifdef _USE_RECORDED_CONTENT
char **folder_list = NULL;
int *modified_time_list = NULL;
- int *item_num_list = NULL;
int count = 0;
int i = 0;
MS_DBG("start path: %s", start_path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((GET_FOLDER_LIST)func_array[lib_index][eGET_FOLDER_LIST])(handle[lib_index], storage_id, start_path, &folder_list, &modified_time_list, &item_num_list, &count, &err_msg); /*dlopen*/
+ ret = ((GET_FOLDER_LIST)func_array[lib_index][eGET_FOLDER_LIST])(handle[lib_index], storage_id, start_path, &folder_list, &modified_time_list, &count, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
if (dir_info != NULL) {
dir_info->dir_path = strdup(folder_list[i]);
dir_info->modified_time = modified_time_list[i];
- dir_info->item_num = item_num_list[i];
g_array_append_val(*dir_array, dir_info);
} else {
MS_DBG_ERR("malloc failed");
{
int i = 0;
int ret = 0;
- DIR *dp = NULL;
- char *mmc_path = malloc(MS_FILE_NAME_LEN_MAX+1);
-
- if (mmc_path == NULL) {
- MS_DBG_ERR("allocation fail");
- return;
- }
+ char mmc_path[MS_FILE_NAME_LEN_MAX+1] = {0, };
for (i = 0; i < DIR_NUM; ++i) {
- memset(mmc_path, 0, MS_FILE_NAME_LEN_MAX+1);
- snprintf(mmc_path, MS_FILE_NAME_LEN_MAX, "%s/%s", mount_path, default_path[i]);
- dp = opendir(mmc_path);
- if (dp == NULL) {
+ memset(mmc_path, 0, sizeof(mmc_path));
+ snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, default_path[i]);
+ if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
MS_DBG("%s path did not exist", mmc_path);
ret = mkdir(mmc_path, 0770);
if (ret < 0) {
- MS_DBG_ERR("make fail");
+ MS_DBG_ERR("mkdir failed");
}
/*this fuction for emulator*/
/*at the first time, the directroies are made permission 755*/
if (ret != 0) {
MS_DBG_STRERROR("chmod failed");
}
- } else {
- closedir(dp);
}
}
-
- MS_SAFE_FREE(mmc_path);
}
static int __get_contents(const char *filename, char *buf)
#define DEVICE_INFO_FILE ".device_info_"
-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
-
-int __ms_check_mount_path(const char *mount_path)
-{
- DIR *dp = NULL;
-
- /*check mount path*/
- dp = opendir(mount_path);
- if (dp == NULL) {
- MS_DBG_ERR("Mount path is not exist");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- closedir(dp);
-
- return MS_MEDIA_ERR_NONE;
-}
-
int ms_read_device_info(const char *root_path, char **device_uuid)
{
int ret = MS_MEDIA_ERR_NONE;
int len = 0;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ const char *name;
- int fd = -1;
- int nread = 0;
- char buf[BUF_SIZE] = {0,};
- struct linux_dirent *d;
- int bpos = 0;
- bool find_uuid = FALSE;
-
- ret = __ms_check_mount_path(root_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("__ms_check_mount_path falied");
- goto ERROR;
+ if (device_uuid == NULL) {
+ MS_DBG_ERR("device_uuid is NULL");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- fd = open(root_path, O_RDONLY | O_DIRECTORY);
- if (fd == -1) {
- MS_DBG_ERR("open failed [%s]", root_path);
- MS_DBG_STRERROR();
- ret = MS_MEDIA_ERR_INVALID_PATH;
- goto ERROR;
+ if (!g_file_test(root_path, G_FILE_TEST_IS_DIR)) {
+ MS_DBG_ERR("Mount path is not exist");
+ *device_uuid = NULL;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- for ( ; ; ) {
- nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
- if (nread == -1) {
- MS_DBG_ERR("getdents");
- MS_DBG_STRERROR();
- ret = MS_MEDIA_ERR_INTERNAL;
- goto ERROR;
- }
-
- if (nread == 0)
- break;
-
- for (bpos = 0; bpos < nread;) {
- d = (struct linux_dirent *) (buf + bpos);
-
- if (d->d_type == DT_REG && (strncmp(d->d_name, DEVICE_INFO_FILE, strlen(DEVICE_INFO_FILE)) == 0)) {
- MS_DBG_WARN("FIND DEV INFO : %s", d->d_name);
- bpos += d->d_reclen;
- find_uuid = TRUE;
- goto FIND_UUID;
+ dir = g_dir_open(root_path, 0, &error);
+ if (error == NULL && dir != NULL) {
+ *device_uuid = NULL;
+ while ((name = g_dir_read_name(dir))) {
+ if (strncmp(name, DEVICE_INFO_FILE, strlen(DEVICE_INFO_FILE)) == 0) {
+ MS_DBG_WARN("FIND DEV INFO : %s", name);
+ len = strlen(name + strlen(DEVICE_INFO_FILE));
+ if (len > 0) {
+ *device_uuid = strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
+ MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
+ }
+
+ if (*device_uuid == NULL)
+ ret = MS_MEDIA_ERR_INTERNAL;
+
+ break;
}
-
- bpos += d->d_reclen;
- }
- }
-
-FIND_UUID:
- if (find_uuid) {
- len = strlen(d->d_name + strlen(DEVICE_INFO_FILE));
- if (len > 0) {
- *device_uuid = strndup(d->d_name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
- MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
}
} else {
- ret = MS_MEDIA_ERR_FILE_NOT_EXIST;
- MS_DBG_ERR("[%s]DEV INFO NOT EXIST", root_path);
- goto ERROR;
+ MS_DBG_ERR("g_dir_open failed [%s]", root_path);
+ *device_uuid = NULL;
+ return MS_MEDIA_ERR_INVALID_PATH;
}
- if (fd > -1) {
- close(fd);
- fd = -1;
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
}
- return MS_MEDIA_ERR_NONE;
-
-ERROR:
-
- *device_uuid = NULL;
- if (fd > -1) {
- close(fd);
- fd = -1;
- }
return ret;
}
#include "media-common-system.h"
#include "media-common-utils.h"
-/* it's for 32bit file offset */
-struct statvfs_32 {
- unsigned long int f_bsize;
- unsigned long int f_frsize;
- unsigned long int f_blocks;
- unsigned long int f_bfree;
- unsigned long int f_bavail;
- unsigned long int f_files;
- unsigned long int f_ffree;
- unsigned long int f_favail;
- unsigned long int f_fsid;
-#ifdef _STATVFSBUF_F_UNUSED
- int __f_unused;
-#endif
- unsigned long int f_flag;
- unsigned long int f_namemax;
- int __f_spare[6];
-};
-
int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
{
int len = 0;
return false;
}
-bool ms_config_set_str(const char *key, const char *value)
-{
- int err;
-
- if (!key || !value) {
- MS_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- err = vconf_set_str(key, value);
- if (err == 0)
- return true;
- else
- MS_DBG_ERR("fail to vconf_set_str %d", err);
-
- return false;
-}
-
-bool ms_config_get_bool(const char *key, int *value)
-{
- int err;
-
- if (!key || !value) {
- MS_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- err = vconf_get_bool(key, value);
- if (err == 0)
- return true;
- else if (err == -1)
- return false;
- else
- MS_DBG_ERR("Unexpected error code: %d", err);
-
- return false;
-}
-
-static int get_memory_size(const char *path, struct statvfs_32 *buf)
+int ms_get_remain_space(double *free_space)
{
+ int ret = MS_MEDIA_ERR_NONE;
+ const char *path = "/opt";
struct statvfs s;
- int ret;
ret = statvfs(path, &s);
- if (ret) {
+ if (ret != 0) {
MS_DBG_ERR("statvfs failed[%d]", ret);
MS_DBG_STRERROR();
return MS_MEDIA_ERR_INTERNAL;
}
- buf->f_bsize = s.f_bsize;
- buf->f_frsize = s.f_frsize;
- buf->f_blocks = (unsigned long)s.f_blocks;
- buf->f_bfree = (unsigned long)s.f_bfree;
- buf->f_bavail = (unsigned long)s.f_bavail;
- buf->f_files = (unsigned long)s.f_files;
- buf->f_ffree = (unsigned long)s.f_ffree;
- buf->f_favail = (unsigned long)s.f_favail;
- buf->f_fsid = s.f_fsid;
- buf->f_flag = s.f_flag;
- buf->f_namemax = s.f_namemax;
+ /* f_bsize:unsigned long, f_bavail:fsblkcnt_t(unsigned long) */
+ *free_space = (double)(s.f_bsize * s.f_bavail);
return MS_MEDIA_ERR_NONE;
}
-int ms_get_remain_space(double *free_space)
-{
- int ret = MS_MEDIA_ERR_NONE;
- struct statvfs_32 temp;
-
- ret = get_memory_size("/opt", &temp);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("fail to get memory size");
- return ret;
- }
-
-// MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
-
- *free_space = (double)temp.f_bsize*temp.f_bavail;
-
- return ret;
-}
-
#ifdef _USE_RECORDED_CONTENT
bool ms_is_support_pvr(void)
{
int ms_check_file_path(const char *file_path, uid_t uid)
{
- int exist;
- struct stat file_st;
ms_user_storage_type_e storage_type = -1;
int ret = MS_MEDIA_ERR_NONE;
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- /* check location of file */
- /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
ret = ms_user_get_storage_type(uid, file_path, &storage_type);
MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
- /* check the file exits actually */
- exist = open(file_path, O_RDONLY);
- if (exist < 0) {
- MS_DBG_SERR("open file fail [%s]", file_path);
- 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");
+ if (!g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ MS_DBG_SERR("g_file_test fail [%s]", file_path);
return MS_MEDIA_ERR_INVALID_PATH;
}
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;
+ const char *ignore_file = ".scan_ignore";
+ char ignore_path[MS_FILE_PATH_LEN_MAX] = {0, };
if (strstr(path, "/.")) {
MS_DBG_ERR("hidden path");
- ret = MS_MEDIA_ERR_INVALID_PATH;
- goto ERROR;
+ return MS_MEDIA_ERR_INVALID_PATH;
}
- fd = open(path, O_RDONLY | O_DIRECTORY);
- if (fd == -1) {
- MS_DBG_ERR("%s folder opendir fails", path);
+ if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
+ memset(ignore_path, 0, sizeof(ignore_path));
+ snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
+
+ if (g_file_test(ignore_path, G_FILE_TEST_EXISTS)) {
+ MS_DBG_WARN("scan ignore file exist [%s]", ignore_path);
+ return MS_MEDIA_ERR_INVALID_PATH;
+ }
+ } else {
+ MS_DBG_ERR("g_file_test fails[%s]", 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;
+ return ret;
}
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_WARN("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_WARN("scan_ignore exists [%s]", check_ignore_file);
- ret = MS_MEDIA_ERR_INVALID_PATH;
+ /*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);
+ return MS_MEDIA_ERR_USB_UNMOUNTED;
}
-
- 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;
}
int (*svc_delete_storage) (void * handle, const char *storage_id, uid_t uid, char **err_msg);
int (*svc_set_storage_validity) (void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg);
-
-
void callback(media_request_result_s * result, void *user_data)
{
if (result->result != MEDIA_REQUEST_SCAN_PARTIAL) {
printf("=======================================================================================\n");
}
-
static int __get_contents(const char *filename, char *buf)
{
FILE *fp;
return media_directory_scanning_async(path, storage_id, TRUE, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
}
-typedef enum {
- DIRECTORY_OK,
- FILE_OK,
- NOT_OK,
-} check_result;
-
-check_result check_path(char *path)
-{
- struct stat buf;
- DIR *dp = NULL;
-
- /*check the path directory or file*/
- if (stat(path, &buf) == 0) {
- if (S_ISDIR(buf.st_mode)) {
- printf("This is directory\n");
- return DIRECTORY_OK;
- } else {
- dp = opendir(path);
- if (dp == NULL) {
- /*if openning directory is failed, check it exists. */
- if (errno == ENOENT) {
- /* this directory is deleted */
- return DIRECTORY_OK;
- }
- } else {
- closedir(dp);
- }
- print_help();
- return NOT_OK;
- }
- } else {
- printf("stat error");
- }
-
- return NOT_OK;
-}
-
int main(int argc, char **argv)
{
int ret;
exit(0);
}
- if (check_path(argv1) == DIRECTORY_OK) {
+ if (g_file_test(argv1, G_FILE_TEST_IS_DIR)) {
len = strlen(argv1);
if (argv1[len - 1] == '/')
} else if (argc == 3) {
argv2 = strdup(argv[2]);
if (strcmp(argv1, "-r") == 0) {
- if ((argv2 != NULL) && (check_path(argv2) == DIRECTORY_OK)) {
+ if ((argv2 != NULL) && (g_file_test(argv2, G_FILE_TEST_IS_DIR))) {
len = strlen(argv2);
if (argv2[len - 1] == '/')
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * 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_DEVICE_BLOCK_H_
-#define _MEDIA_SCANNER_DEVICE_BLOCK_H_
-
-#include "media-common-system.h"
-
-#ifdef _USE_DEVICED_DBUS
-void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data);
-#else
-void msc_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data);
-#endif
-
-#endif
\ No newline at end of file
ms_db_status_type_t msc_check_scanning_status(void);
int msc_set_cancel_path(const char *cancel_path);
int msc_del_cancel_path(void);
-int msc_set_blocked_path(const char *blocked_path);
-int msc_del_blocked_path(void);
void msc_metadata_update_thread(ms_comm_msg_s *recv_msg);
int msc_init_scanner(void);
int msc_deinit_scanner(void);
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * 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 <vconf.h>
-
-#include "media-util.h"
-
-#include "media-common-utils.h"
-#include "media-common-db-svc.h"
-#include "media-common-external-storage.h"
-
-#include "media-util-err.h"
-#include "media-scanner-dbg.h"
-#include "media-scanner-scan.h"
-#include "media-scanner-device-block.h"
-
-extern GAsyncQueue * storage_queue;
-extern bool g_directory_scan_processing;
-
-#ifdef _USE_DEVICED_DBUS
-static void __msc_usb_remove_event(const char *mount_path)
-{
- return;
-}
-
-int msc_mmc_remove_handler(const char *mount_path)
-{
- return MS_MEDIA_ERR_NONE;
-}
-
-void _msc_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status)
-{
- /* If scanner is not working, media server executes media scanner and sends request. */
- /* If scanner is working, it detects changing status of SD card. */
- if (mount_status == MS_STG_INSERTED) {
- /*DO NOT THING*/
- } else if (mount_status == MS_STG_REMOVED) {
- msc_mmc_remove_handler(mount_path);
- }
-
- return;
-}
-
-
-void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
-{
- if (block_info->block_type == 0) {
- MS_DBG_WARN("GET THE USB EVENT");
- if (block_info->state == MS_STG_INSERTED) {
- /*DO NOT THING*/
- } else {
- __msc_usb_remove_event(block_info->mount_path);
- }
- } else {
- MS_DBG_WARN("GET THE MMC EVENT");
- _msc_mmc_changed_event(block_info->mount_path, block_info->state);
- }
-}
-#else
-void msc_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data)
-{
- char *mount_path = NULL;
-
- if (!usb_device) {
- MS_DBG_ERR("usb_device is NULL");
- return;
- }
-
- if (usb_device_get_class(usb_device) != USB_MASS_STORAGE) {
- free_usb_device_h(usb_device);
- MS_DBG_ERR("usb_device is NOT STORAGE");
- return;
- }
-
- mount_path = usb_device_get_mountpath(usb_device);
-
- if (!strcmp(action, "blocked")) {
- MS_DBG_WARN("===========================================================");
- MS_DBG_WARN("USB BLOCKED, mountpath : %s", mount_path);
- MS_DBG_WARN("===========================================================");
- int status = -1;
-
- if (!ms_config_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &status)) {
- MS_DBG_ERR("ms_config_get_int[VCONFKEY_FILEMANAGER_DB_STATUS]");
- }
- if (!(g_async_queue_length(storage_queue) == 0 && status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
- msc_set_blocked_path(mount_path);
- }
-
- if (g_directory_scan_processing == true) {
- MS_DBG_WARN("Doing directory scanning. Set cancel path");
- msc_set_cancel_path(mount_path);
- }
- }
-
- free_usb_device_h(usb_device);
-
- return;
-}
-#endif
GAsyncQueue *scan_queue;
GAsyncQueue *reg_queue;
GMutex scan_req_mutex;
-GMutex blocked_mutex;
char *g_cancel_path;
-char *g_blocked_path;
-bool g_directory_scan_processing;
-int stg_scan_status;
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_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
static int __msc_clear_file_list(GArray *path_array);
static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status);
static int __msc_check_stop_status(ms_storage_type_t storage_type)
{
}
/* this thread process only the request of media-server */
-static int _check_folder_from_list(char *folder_path, int item_num, GArray *dir_array)
+static int _check_folder_from_list(char *folder_path, GArray *dir_array)
{
int i = 0;
int array_len = dir_array->len;
for (i = 0; i < array_len; i++) {
dir_info = g_array_index(dir_array, ms_dir_info_s*, i);
if (strcmp(folder_path, dir_info->dir_path) == 0) {
- /* if modified time is same, the folder does not need updating */
- if ((mtime == dir_info->modified_time) && (item_num == dir_info->item_num)) {
+ if (mtime == dir_info->modified_time) {
if (mtime == 0)
continue;
char *current_path = NULL;
char path[MS_FILE_PATH_LEN_MAX] = { 0 };
char * start_path = strdup(update_path);
- int item_num = 0;
MS_DBG_FENTER();
/*start db update. the number of element in the array , db update is complete.*/
while (read_dir_array->len != 0) {
- /* get the current path from directory array */
current_path = g_array_index(read_dir_array , char*, 0);
g_array_remove_index(read_dir_array, 0);
/* add new directory to dir_array */
new_path = strdup(path);
g_array_append_val(read_dir_array, new_path);
- } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
- item_num++;
}
}
/* find and compare modified time */
- _check_folder_from_list(current_path, item_num, *dir_array);
- item_num = 0;
+ _check_folder_from_list(current_path, *dir_array);
} else {
MS_DBG_ERR("g_dir_open fails [%s]", current_path);
}
char *storage_id = NULL;
while (1) {
- __msc_set_storage_scan_status(MS_STORAGE_SCAN_PREPARE);
scan_data = g_async_queue_pop(storage_queue);
if (scan_data->pid == POWEROFF) {
MS_DBG_WARN("power off");
goto _POWEROFF;
}
- __msc_set_storage_scan_status(MS_STORAGE_SCAN_PROCESSING);
MS_DBG_WARN("STORAGE SCAN START [%s][%s]", scan_data->msg, scan_data->storage_id);
scan_type = scan_data->msg_type;
goto NEXT;
}
- /*connect to media db, if connecting is failed, db updating is stopped*/
err = ms_connect_db(&handle, scan_data->uid);
if (err != MS_MEDIA_ERR_NONE)
continue;
update_path = strndup(scan_data->msg, scan_data->msg_size);
if (strlen(scan_data->storage_id) > 0) {
- /*MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, scan_data->storage_id);*/
- storage_id = strdup(scan_data->storage_id);
+ storage_id = g_strdup(scan_data->storage_id);
+ if (storage_id == NULL) {
+ MS_DBG_ERR("storage_id NULL");
+ ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ goto NEXT;
+ }
} else {
MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- if (storage_id == NULL) {
- MS_DBG_ERR("storage_id NULL");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- goto NEXT;
- }
-
ret = ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_PROCESSING, scan_data->uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_set_storage_scan_status[%d]", ret);
if (dir_array->len != 0) {
MS_DBG_INFO("DB UPDATING IS NEEDED");
-
ret = _msc_db_update_partial(handle, storage_id, storage_type, dir_array, scan_data->uid);
} else {
MS_DBG_INFO("THERE IS NO UPDATE");
if (!ms_delete_all_items(handle, storage_id, storage_type, scan_data->uid)) {
MS_DBG_ERR("msc_delete_all_record fails");
}
-
- if (storage_type == MS_USER_STORAGE_EXTERNAL) {
- /*storage info updated in media-server*/
- /*ms_update_mmc_info();*/
- }
} else if (scan_type == MS_MSG_STORAGE_PARTIAL) {
ms_validaty_change_all_items(handle, storage_id, storage_type, false, scan_data->uid);
}
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 */
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 */
ms_set_db_status(MS_DB_UPDATED, storage_type);
}
/* get the current path from directory array */
current_path = g_array_index(dir_array , char*, 0);
g_array_remove_index(dir_array, 0);
-// MS_DBG_SLOG("%d", dir_array->len);
if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
g_thread_new("update_thread", (GThreadFunc)msc_metadata_update, recv_msg);
}
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status)
-{
- int res = MS_MEDIA_ERR_NONE;
-#if 0
- if (!ms_config_set_int(MS_SCANNER_STATUS, status)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MS_DBG_ERR("ms_config_set_int failed");
- }
-#else
- stg_scan_status = status;
-#endif
- return res;
-}
-
int msc_init_scanner(void)
{
if (!scan_queue) scan_queue = g_async_queue_new();
return MS_MEDIA_ERR_NONE;
}
-
-int msc_set_blocked_path(const char *blocked_path)
-{
- MS_DBG_FENTER();
- g_mutex_lock(&blocked_mutex);
-
- if (g_blocked_path != NULL) {
- MS_DBG_WARN("g_blocked_path is not NULL [%s]", g_blocked_path);
- free(g_blocked_path);
- g_blocked_path = NULL;
- }
-
- g_blocked_path = strdup(blocked_path);
-
- g_mutex_unlock(&blocked_mutex);
- MS_DBG_FLEAVE();
- return MS_MEDIA_ERR_NONE;
-}
-
-int msc_del_blocked_path(void)
-{
- MS_DBG_FENTER();
- g_mutex_lock(&blocked_mutex);
-
- if (g_blocked_path != NULL) {
- MS_DBG_WARN("g_blocked_path is not NULL [%s]", g_blocked_path);
- free(g_blocked_path);
- g_blocked_path = NULL;
- }
-
- g_mutex_unlock(&blocked_mutex);
- MS_DBG_FLEAVE();
- return MS_MEDIA_ERR_NONE;
-}
-
#include "media-util.h"
#include "media-scanner-dbg.h"
-#include "media-scanner-device-block.h"
#include "media-scanner-scan.h"
#include "media-scanner-socket.h"
{
/*set power off callback function*/
ms_sys_set_poweroff_cb(__msc_power_off_cb, NULL);
- ms_sys_set_device_block_event_cb(msc_device_block_changed_cb, NULL);
}
static void __msc_remove_event_receiver(void)
{
- ms_sys_unset_device_block_event_cb();
ms_sys_unset_poweroff_cb();
}
return;
}
-static int _mkdir(const char *dir, mode_t mode)
-{
- char tmp[256];
- char *p = NULL;
- size_t len;
-
- snprintf(tmp, sizeof(tmp), "%s", dir);
- len = strlen(tmp);
- if (tmp[len - 1] == '/')
- tmp[len - 1] = 0;
- for (p = tmp + 1; *p; p++)
- if (*p == '/') {
- *p = 0;
- mkdir(tmp, mode);
- *p = '/';
- }
-
- return mkdir(tmp, mode);
-}
-
int main(int argc, char **argv)
{
GThread *db_thread = NULL;
/*prepare socket*/
/* create dir socket */
- _mkdir(tzplatform_mkpath(TZ_SYS_RUN, "media-server"), S_IRWXU | S_IRWXG | S_IRWXO);
+ g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "media-server"), S_IRWXU | S_IRWXG | S_IRWXO);
/* Create and bind new UDP socket */
if (ms_ipc_create_server_socket(MS_SCANNER_PORT, &sockfd) != MS_MEDIA_ERR_NONE) {