- With making this, modify some functions to use new function.
Change-Id: Iadeabf9374f1fbd1d9430527c53524b30714cfb2
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
BuildRequires: pkgconfig(eventsystem)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(storage)
#only for data types
BuildRequires: pkgconfig(tapi)
libsystemd
leveldb
eventsystem
+ storage
)
INCLUDE(FindPkgConfig)
#include "block.h"
#include "proc-common.h"
#include "appinfo-list.h"
+#include "storage-helper.h"
#define BLOCK_CONF_FILE "/etc/resourced/block.conf"
#define BLOCK_CONF_SECTION "MONITOR"
+#define BLOCK_CONF_ACTIVATED "TRUE"
static GSList *block_monitor_list;
static int load_block_config(struct parse_result *result, void *user_data)
{
struct block_monitor_info *bmi;
+ char *monitoring_path;
if (!result)
return RESOURCED_ERROR_NO_DATA;
if (!strstr(result->section, BLOCK_CONF_SECTION))
return RESOURCED_ERROR_NO_DATA;
- if (MATCH(result->name, "path")) {
- bmi = calloc(1, sizeof(struct block_monitor_info));
- if (!bmi) {
- _E("Failed to create monitor info");
- return RESOURCED_ERROR_OUT_OF_MEMORY;
+ if (MATCH(result->name, "activate")) {
+ if (!strncmp(result->value, BLOCK_CONF_ACTIVATED,
+ sizeof(BLOCK_CONF_ACTIVATED))) {
+ bmi = calloc(1, sizeof(struct block_monitor_info));
+ if (!bmi) {
+ _E("Failed to create monitor info");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+ if (get_storage_root_path(INTERNAL, &monitoring_path) != RESOURCED_ERROR_NONE) {
+ _E("Failed to find monitoring path");
+ return RESOURCED_ERROR_FAIL;
+ }
+ _D("Start to monitor %s", monitoring_path);
+ strncpy(bmi->path, monitoring_path, sizeof(bmi->path));
+ free(monitoring_path);
+ block_monitor_list = g_slist_prepend(block_monitor_list, bmi);
}
- strncpy(bmi->path, result->value, MAX_PATH_LENGTH-1);
- block_monitor_list = g_slist_prepend(block_monitor_list, bmi);
-
} else if (MATCH(result->name, "mode")) {
bmi = (struct block_monitor_info *)g_slist_nth_data(block_monitor_list, 0);
SET_CONF(bmi->mode, convert_fanotify_mode(result->value));
+# activate {TRUE, FALSE}
# mode {DISABLE, ACCESS, READ, WRITE}
# logging { DLOG = 0x1, FILE = 0x2, DB = 0x4}
# When adding new monitor, "configend=NULL" should be included for distributing other categories.
-[MONITOR1]
-path=/opt/usr/media
+[MONITOR]
+activate=TRUE
mode=WRITE
include=DOWNLOADABLE
exclude=SLP_debug
#include "storage-helper.h"
#include "trace.h"
#include <mntent.h>
+#include <storage.h>
#define PATH_MAX 256
#define INTERNAL_MEMORY_PATH "/opt/usr"
return ret;
}
-resourced_ret_c storage_get_size(int type, struct statvfs *buf)
+struct rd_storage {
+ int id;
+ int type;
+};
+
+static bool get_storage_id(int sid, storage_type_e type, storage_state_e state,
+ const char *path, void *userData)
{
- int ret;
- char path[PATH_MAX] = "";
- char errbuf[PATH_MAX];
+ struct rd_storage *target = (struct rd_storage*)userData;
+
+ if (type == target->type && state == STORAGE_STATE_MOUNTED) {
+ target->id = sid;
+ return false;
+ }
+ return true;
+}
+
+resourced_ret_c get_storage_root_path(int type, char **path)
+{
+ struct rd_storage target;
if (type == INTERNAL)
- snprintf(path, sizeof(path),"%s", INTERNAL_MEMORY_PATH);
+ target.type = STORAGE_TYPE_INTERNAL;
else if (type == EXTERNAL)
- snprintf(path, sizeof(path), "%s", EXTERNAL_MEMORY_PATH);
+ target.type = STORAGE_TYPE_EXTERNAL;
else {
- _E("Unsupported storage type:%d", type);
+ _E("Invalid storage type");
return RESOURCED_ERROR_INVALID_PARAMETER;
}
+ if (storage_foreach_device_supported(get_storage_id,
+ &target) != STORAGE_ERROR_NONE) {
+ _E("Failed to get storage ID");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ if (storage_get_root_directory(target.id, path)
+ != STORAGE_ERROR_NONE) {
+ _E("Failed to get root path of storage");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
+resourced_ret_c storage_get_size(int type, struct statvfs *buf)
+{
+ int ret;
+ char *path;
+ char errbuf[PATH_MAX];
+
+ if (get_storage_root_path(type, &path) != RESOURCED_ERROR_NONE) {
+ _E("Failed to get storage path");
+ goto fail;
+ }
+
_I("Path:%s", path);
if (type == EXTERNAL) {
- if (!is_mounted(EXTERNAL_MEMORY_PATH)) {
+ if (!is_mounted(path)) {
memset(buf, 0, sizeof(struct statvfs));
- return RESOURCED_ERROR_NONE;
+ goto success;
}
}
ret = statvfs(path, buf);
if (ret) {
_E("statvfs() failed. Path:%s err:%s", path, strerror_r(errno, errbuf, sizeof(errbuf)));
- return RESOURCED_ERROR_FAIL;
+ goto fail;
}
+ goto success;
+
+fail:
+ free(path);
+ return RESOURCED_ERROR_FAIL;
+
+success:
+ free(path);
return RESOURCED_ERROR_NONE;
}
bool is_mounted(const char* path);
+resourced_ret_c get_storage_root_path(int type, char **path);
+
/**
* @desc gets storage details
* @param type-INTERNAL/EXTERNAL, buf-storage details