4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
30 #include <dbus/dbus-glib.h>
31 #include <dbus/dbus.h>
32 #include <dbus/dbus-glib-lowlevel.h>
33 #include <sys/statvfs.h>
35 #ifdef _SET_VIP_PROCESS
36 #include <sys/prctl.h>
38 #include <system_info.h>
39 #include <dd-display.h>
41 #ifndef _USE_DEVICED_DBUS
42 #include <usb-device.h>
45 #include "media-util.h"
46 #include "media-server-ipc.h"
47 #include "media-common-dbg.h"
48 #include "media-common-system.h"
49 #include "media-common-utils.h"
51 #define MS_DRM_CONTENT_TYPE_LENGTH 100
53 /* it's for 32bit file offset */
55 unsigned long int f_bsize;
56 unsigned long int f_frsize;
57 unsigned long int f_blocks;
58 unsigned long int f_bfree;
59 unsigned long int f_bavail;
60 unsigned long int f_files;
61 unsigned long int f_ffree;
62 unsigned long int f_favail;
63 unsigned long int f_fsid;
64 #ifdef _STATVFSBUF_F_UNUSED
67 unsigned long int f_flag;
68 unsigned long int f_namemax;
72 bool ms_is_mmc_inserted(void)
75 ms_stg_type_e stg_type = MS_STG_TYPE_MMC;
76 GArray *dev_list = NULL;
78 ret = ms_sys_get_device_list(stg_type, &dev_list);
79 if (ret == MS_MEDIA_ERR_NONE) {
80 if (dev_list != NULL) {
81 MS_DBG_WARN("MMC FOUND[%d]", dev_list->len);
82 ms_sys_release_device_list(&dev_list);
85 MS_DBG_ERR("MMC NOT FOUND");
88 MS_DBG_ERR("ms_sys_get_device_list failed");
94 static char* __media_get_path(uid_t uid)
98 char *result_passwd = NULL;
100 struct group *grpresult = NULL;
103 grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
104 if (grpbufsize == -1) /* Value was indeterminate */
105 grpbufsize = 16384; /* Should be more than enough (16*1024) */
107 grpbuf = malloc(grpbufsize);
108 if (grpbuf == NULL) {
109 MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
113 ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
114 if ((ret == 0) && (grpresult != NULL)) {
115 // MS_DBG("getgrnam_r users success...\n");
117 MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
121 if (uid == getuid()) {
122 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
123 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
125 struct passwd pwdinfo;
126 struct passwd *pwdresult = NULL;
130 pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
131 if (pwdbufsize == -1) /* Value was indeterminate */
132 pwdbufsize = 16384; /* Should be more than enough (16*1024) */
134 pwdbuf = malloc(pwdbufsize);
135 if (pwdbuf == NULL) {
136 MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
140 ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
141 if ((ret == 0) && (pwdresult != NULL)) {
142 // MS_DBG("getpwuid uid[%d] success\n", uid);
144 MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
145 MS_SAFE_FREE(pwdbuf);
149 // Compare git_t type and not group name
150 if (grpinfo.gr_gid != pwdinfo.pw_gid) {
151 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
152 MS_SAFE_FREE(pwdbuf);
155 result_passwd = strndup(pwdinfo.pw_dir, strlen(pwdinfo.pw_dir));
157 MS_SAFE_FREE(pwdbuf);
161 MS_SAFE_FREE(grpbuf);
163 return result_passwd;
167 ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid)
170 int ret = MS_MEDIA_ERR_NONE;
171 char * user_path = NULL;
174 return MS_MEDIA_ERR_INVALID_PATH;
176 #ifdef _USE_SENIOR_MODE
177 if (ms_is_support_senior_mode()) {
178 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0) {
179 return MS_STORAGE_EXTERNAL;
184 user_path = __media_get_path(uid);
185 if (user_path == NULL)
186 return MS_MEDIA_ERR_OUT_OF_MEMORY;
188 length_path = strlen(user_path);
190 if (strncmp(path, user_path, length_path) == 0) {
191 ret = MS_STORAGE_INTERNAL;
192 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
193 ret = MS_STORAGE_EXTERNAL;
194 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
195 ret = MS_STORAGE_EXTERNAL_USB;
196 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)) {
197 ret = MS_STORAGE_EXTERNAL_USB;
199 MS_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
200 ret = MS_MEDIA_ERR_INVALID_PATH;
203 MS_SAFE_FREE(user_path);
208 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
211 int real_size = size - 1;
213 if (!res || !pattern || !str1 || !str2)
214 return MS_MEDIA_ERR_INVALID_PARAMETER;
216 if (real_size < (int)(strlen(str1) + strlen(str2)))
217 return MS_MEDIA_ERR_INVALID_PARAMETER;
219 len = snprintf(res, real_size, pattern, str1, str2);
221 return MS_MEDIA_ERR_INVALID_PARAMETER;
226 return MS_MEDIA_ERR_NONE;
229 int ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
232 int real_size = size;
234 if (!res || !pattern || !str1) {
235 MS_DBG_ERR("parameta is invalid");
236 return MS_MEDIA_ERR_INVALID_PARAMETER;
239 if (real_size < (int)(strlen(str1))) {
240 MS_DBG_ERR("size is wrong");
241 return MS_MEDIA_ERR_INVALID_PARAMETER;
244 len = snprintf(res, real_size, pattern, str1);
246 MS_DBG_ERR("snprintf failed");
247 return MS_MEDIA_ERR_INVALID_PARAMETER;
252 return MS_MEDIA_ERR_NONE;
255 bool ms_config_get_int(const char *key, int *value)
259 if (!key || !value) {
260 MS_DBG_ERR("Arguments key or value is NULL");
264 err = vconf_get_int(key, value);
270 MS_DBG_ERR("Unexpected error code: %d", err);
275 bool ms_config_set_int(const char *key, int value)
280 MS_DBG_ERR("Arguments key is NULL");
284 err = vconf_set_int(key, value);
290 MS_DBG_ERR("Unexpected error code: %d", err);
295 bool ms_config_get_str(const char *key, char **value)
299 if (key == NULL || value == NULL) {
300 MS_DBG_ERR("Arguments key or value is NULL");
304 res = vconf_get_str(key);
305 if (MS_STRING_VALID(res)) {
306 *value = strdup(res);
314 bool ms_config_set_str(const char *key, const char *value)
318 if (!key || !value) {
319 MS_DBG_ERR("Arguments key or value is NULL");
323 err = vconf_set_str(key, value);
327 MS_DBG_ERR("fail to vconf_set_str %d", err);
332 bool ms_config_get_bool(const char *key, int *value)
336 if (!key || !value) {
337 MS_DBG_ERR("Arguments key or value is NULL");
341 err = vconf_get_bool(key, value);
347 MS_DBG_ERR("Unexpected error code: %d", err);
352 static int get_memory_size(const char *path, struct statvfs_32 *buf)
357 ret = statvfs(path, &s);
359 MS_DBG_ERR("statvfs failed[%d]", ret);
361 return MS_MEDIA_ERR_INTERNAL;
364 buf->f_bsize = s.f_bsize;
365 buf->f_frsize = s.f_frsize;
366 buf->f_blocks = (unsigned long)s.f_blocks;
367 buf->f_bfree = (unsigned long)s.f_bfree;
368 buf->f_bavail = (unsigned long)s.f_bavail;
369 buf->f_files = (unsigned long)s.f_files;
370 buf->f_ffree = (unsigned long)s.f_ffree;
371 buf->f_favail = (unsigned long)s.f_favail;
372 buf->f_fsid = s.f_fsid;
373 buf->f_flag = s.f_flag;
374 buf->f_namemax = s.f_namemax;
376 return MS_MEDIA_ERR_NONE;
379 int ms_get_remain_space(double *free_space)
381 int ret = MS_MEDIA_ERR_NONE;
382 struct statvfs_32 temp;
384 ret = get_memory_size("/opt", &temp);
385 if (ret != MS_MEDIA_ERR_NONE) {
386 MS_DBG_ERR("fail to get memory size");
390 // MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
392 *free_space = (double)temp.f_bsize*temp.f_bavail;
397 #ifdef _USE_RECORDED_CONTENT
398 bool ms_is_support_pvr(void)
402 if (system_info_get_value_int(SYSTEM_INFO_KEY_PVR_SUPPORTED, &nSupportPVR) != SYSTEM_INFO_ERROR_NONE) {
403 MS_DBG_ERR("Get PVR Support failed");
407 MS_DBG("PVR Support : [%d]", nSupportPVR);
409 return (nSupportPVR != 0);
413 #ifdef _USE_SENIOR_MODE
414 bool ms_is_support_senior_mode()
416 bool bSupportSeniorMode = false;
418 if (system_info_get_value_bool(SYSTEM_INFO_KEY_GET_SENIOR_MODE_SUPPORTED, &bSupportSeniorMode) != SYSTEM_INFO_ERROR_NONE) {
419 MS_DBG_ERR("Get senior mode support failed");
423 MS_DBG("Senior mode support : [%d]", bSupportSeniorMode);
425 return bSupportSeniorMode;
429 int ms_check_file_path(const char *file_path, uid_t uid)
434 /* check location of file */
435 /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
436 if (!ms_is_valid_path(file_path, uid)) {
437 MS_DBG_ERR("Invalid path : %s", file_path);
438 return MS_MEDIA_ERR_INVALID_PATH;
441 /* check the file exits actually */
442 exist = open(file_path, O_RDONLY);
444 MS_DBG_ERR("[%s]open files");
445 return MS_MEDIA_ERR_INVALID_PATH;
449 /* check type of the path */
450 /* It must be a regular file */
451 memset(&file_st, 0, sizeof(struct stat));
452 if (stat(file_path, &file_st) == 0) {
453 if (!S_ISREG(file_st.st_mode)) {
454 /* In this case, it is not a regula file */
455 MS_DBG_ERR("this path is not a file");
456 return MS_MEDIA_ERR_INVALID_PATH;
459 MS_DBG_STRERROR("stat failed");
460 return MS_MEDIA_ERR_INVALID_PATH;
463 return MS_MEDIA_ERR_NONE;
466 int ms_check_ignore_dir(const char *full_path, uid_t uid)
468 int ret = MS_MEDIA_ERR_NONE;
469 char *dir_path = NULL;
470 char *leaf_path = NULL;
471 char *usr_path = NULL;
473 ret = ms_check_file_path(full_path, uid);
474 if (ret != MS_MEDIA_ERR_NONE) {
475 MS_DBG_ERR("invalid path : %s", full_path);
476 return MS_MEDIA_ERR_INVALID_PATH;
479 dir_path = g_path_get_dirname(full_path);
480 if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
481 MS_DBG_ERR("getting directory path is failed : %s", full_path);
482 MS_SAFE_FREE(dir_path);
483 return MS_MEDIA_ERR_INVALID_PATH;
486 usr_path = ms_get_path(uid);
487 if (usr_path == NULL) {
488 MS_DBG_ERR("ms_get_path() fail");
489 MS_SAFE_FREE(dir_path);
490 return MS_MEDIA_ERR_INTERNAL;
494 if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
495 ret = MS_MEDIA_ERR_INVALID_PATH;
499 #ifdef _USE_SENIOR_MODE
500 if (ms_is_support_senior_mode()) {
501 if (strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
505 if (strcmp(dir_path, usr_path) == 0)
507 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
509 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
511 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(dir_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0))
514 leaf_path = strrchr(dir_path, '/');
515 if (leaf_path != NULL) {
516 int seek_len = leaf_path -dir_path;
517 dir_path[seek_len] = '\0';
519 MS_DBG_ERR("Fail to find leaf path");
520 ret = MS_MEDIA_ERR_INVALID_PATH;
525 MS_SAFE_FREE(dir_path);
526 MS_SAFE_FREE(usr_path);
531 int ms_check_scan_ignore(char * path)
535 const char *ignore_path = "/.scan_ignore";
536 char *check_ignore_file = NULL;
537 int ret = MS_MEDIA_ERR_NONE;
539 if (strstr(path, "/.")) {
540 MS_DBG_ERR("hidden path");
541 ret = MS_MEDIA_ERR_INVALID_PATH;
545 fd = open(path, O_RDONLY | O_DIRECTORY);
547 MS_DBG_ERR("%s folder opendir fails", path);
548 ret = MS_MEDIA_ERR_INVALID_PATH;
550 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
551 MS_DBG_ERR("Fail to get USB path");
555 if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
556 if (errno == ENOENT) {
557 /*if the directory does not exist, check the device is unmounted*/
558 if (!ms_storage_mount_status(path)) {
559 MS_DBG_ERR("Device is unmounted[%s]", path);
560 ret = MS_MEDIA_ERR_USB_UNMOUNTED;
566 struct stat folder_st;
567 if (stat(path, &folder_st) == 0) {
568 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,
569 (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
571 MS_DBG_ERR("%s folder stat fails", path);
576 /* check the file exits actually */
579 path_len = strlen(path) + strlen(ignore_path) + 1;
580 check_ignore_file = malloc(path_len);
581 if (check_ignore_file != NULL) {
582 memset(check_ignore_file, 0x0, path_len);
583 snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
585 exist = open(check_ignore_file, O_RDONLY);
587 MS_DBG_WARN("scan_ignore exists [%s]", check_ignore_file);
588 ret = MS_MEDIA_ERR_INVALID_PATH;
591 MS_SAFE_FREE(check_ignore_file);
593 MS_DBG_ERR("malloc failed");
594 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
605 if (exist >= 0) close(exist);
610 char* ms_get_path(uid_t uid)
613 char *result_passwd = NULL;
616 struct group grpinfo;
617 struct group* grpresult = NULL;
620 grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
621 if (grpbufsize == -1) /* Value was indeterminate */
622 grpbufsize = 16384; /* Should be more than enough (16*1024) */
624 grpbuf = malloc(grpbufsize);
625 if (grpbuf == NULL) {
626 MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
630 ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
631 if ((ret == 0) && (grpresult != NULL)) {
632 // MS_DBG("getgrnam_r users success...\n");
634 MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
638 if (uid == getuid()) {
639 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
640 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
642 char passwd_str[MAX_FILEPATH_LEN] = {0, };
643 struct passwd pwdinfo;
644 struct passwd* pwdresult = NULL;
648 pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
649 if (pwdbufsize == -1) /* Value was indeterminate */
650 pwdbufsize = 16384; /* Should be more than enough (16*1024) */
652 pwdbuf = malloc(pwdbufsize);
653 if (pwdbuf == NULL) {
654 MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
658 ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
659 if ((ret == 0) && (pwdresult != NULL)) {
660 // MS_DBG("getpwuid uid[%d] success\n", uid);
662 MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
663 MS_SAFE_FREE(pwdbuf);
667 // Compare git_t type and not group name
668 if (grpinfo.gr_gid != pwdinfo.pw_gid) {
669 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
670 MS_SAFE_FREE(pwdbuf);
674 len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", pwdinfo.pw_dir, MEDIA_CONTENT_PATH);
676 result_passwd = strndup(passwd_str, len);
678 MS_SAFE_FREE(pwdbuf);
682 MS_SAFE_FREE(grpbuf);
684 return result_passwd;
687 bool ms_storage_mount_status(const char* start_path)
690 #ifndef _USE_DEVICED_DBUS
693 usb_device_list_h list;
695 char *mount_path = NULL;
697 char *storage_path = NULL;
698 char *remain_path = NULL;
701 remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
702 if (remain_path != NULL)
703 remain_len = strlen(remain_path);
705 storage_path = strndup(start_path, strlen(start_path) - remain_len);
707 MS_DBG_WARN("storage_path [%s]", storage_path);
709 err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
711 count = usb_device_list_get_count(list);
713 err = usb_device_list_get_first(list, &device);
714 if (err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
715 mount_path = usb_device_get_mountpath(device);
716 if (mount_path != NULL) {
717 MS_DBG_WARN("mount_path [%s]", mount_path);
718 if (strlen(mount_path) == strlen(storage_path)) {
719 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
720 MS_DBG_WARN("start path is mounted [%s]", start_path);
728 while (usb_device_list_get_next(list, &device) == 0) {
729 if (device != NULL) {
730 mount_path = usb_device_get_mountpath(device);
731 if (mount_path != NULL) {
732 MS_DBG_WARN("mount_path [%s]", mount_path);
733 if (strlen(mount_path) == strlen(storage_path)) {
734 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
735 MS_DBG_WARN("start path is mounted [%s]", start_path);
746 usb_device_free_device_list(list);
748 MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
751 MS_SAFE_FREE(storage_path);
756 bool ms_is_valid_path(const char *path, uid_t uid)
759 char *usr_path = NULL;
764 usr_path = ms_get_path(uid);
765 if (usr_path == NULL)
768 #ifdef _USE_SENIOR_MODE
769 if (ms_is_support_senior_mode()) {
770 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
775 if (strncmp(path, usr_path, strlen(usr_path)) == 0)
777 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
779 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
781 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0))
786 MS_SAFE_FREE(usr_path);
791 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
793 int res = MS_MEDIA_ERR_NONE;
796 if (status == MS_DB_UPDATING) {
797 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
798 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
799 MS_DBG_ERR("ms_config_set_int failed");
802 if (storage_type == MS_STORAGE_EXTERNAL) {
803 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
804 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
805 MS_DBG_ERR("ms_config_set_int failed");
809 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
810 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
811 MS_DBG_ERR("ms_config_set_int failed");
814 if (storage_type == MS_STORAGE_EXTERNAL) {
815 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
816 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
817 MS_DBG_ERR("ms_config_set_int failed");
822 err = ms_set_power_mode(status);
823 if (err != MS_MEDIA_ERR_NONE) {
824 MS_DBG_ERR("ms_set_power_mode fail");
831 int ms_set_power_mode(ms_db_status_type_t status)
833 int res = MS_MEDIA_ERR_NONE;
838 err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
840 res = MS_MEDIA_ERR_INTERNAL;
843 err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
845 res = MS_MEDIA_ERR_INTERNAL;
848 MS_DBG_ERR("Unacceptable type : %d", status);
855 void ms_trim_dir_path(char *dir_path)
857 /* need implementation */
858 /* if dir_path is not NULL terminated, this function will occure crash */
859 int len = strlen(dir_path);
861 if (dir_path[len -1] == '/')
862 dir_path[len -1] = '\0';
865 bool ms_check_folder_path(const char *folder_path)
869 dp = opendir(folder_path);
871 MS_DBG_ERR("Deleted folder path");
879 int ms_check_size_mediadb(uid_t uid, double *db_size)
881 int ret = MS_MEDIA_ERR_NONE;
882 char *db_path = NULL;
885 ret = media_db_get_media_db_path(uid, &db_path);
887 if (stat(db_path, &buf) == 0) {
888 *db_size = buf.st_size;
890 MS_DBG_STRERROR("stat failed");
891 ret = MS_MEDIA_ERR_INTERNAL;
894 MS_SAFE_FREE(db_path);
899 #ifdef _SET_VIP_PROCESS
900 #define PROC_OOM_SCORE_ADJ_PATH "/proc/%d/oom_score_adj"
901 #define VIP_OOM_SCORE_ADJ (-1000)
902 #define PROC_NAME_MAX 1024
903 #define PROC_BUF_MAX 64
905 static int ms_get_cmdline_from_proc(pid_t pid, char *cmdline)
907 char buf[PROC_BUF_MAX];
908 char cmdline_buf[PROC_NAME_MAX];
912 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
913 fp = fopen(buf, "r");
915 return MS_MEDIA_ERR_INTERNAL;
917 if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) {
919 return MS_MEDIA_ERR_INTERNAL;
923 filename = strrchr(cmdline_buf, '/');
924 if (filename == NULL)
925 filename = cmdline_buf;
927 filename = filename + 1;
929 strncpy(cmdline, filename, PROC_NAME_MAX-1);
931 return MS_MEDIA_ERR_NONE;
934 int ms_set_vip_process(void)
938 static pid_t pid = 0;
939 static char process_name[PROC_NAME_MAX] = {0};
940 static char *appid = NULL;
944 if (ms_get_cmdline_from_proc(pid, process_name)) {
945 MS_DBG_ERR("%s: Read process name failed pid[%d]\n", __func__, pid);
946 return MS_MEDIA_ERR_INTERNAL;
948 appid = process_name;
950 MS_DBG("Process name[%s]:Pid[%d]", appid, pid);
952 if (prctl(PR_GET_DUMPABLE) == 0)
953 prctl(PR_SET_DUMPABLE, 1);
955 snprintf(buf, sizeof(buf), PROC_OOM_SCORE_ADJ_PATH, pid);
956 id = open(buf, O_WRONLY, 0777);
958 MS_DBG_ERR("fopen %s failed errno:%d", buf, errno);
959 return MS_MEDIA_ERR_INTERNAL;
961 snprintf(buf, sizeof(buf), "%d", VIP_OOM_SCORE_ADJ);
962 if (write(id, buf, strlen(buf)) < 0) {
963 MS_DBG_ERR("write() failed errno=%d", errno);
965 return MS_MEDIA_ERR_INTERNAL;
968 return MS_MEDIA_ERR_NONE;