mount
blkid
capi-system-info
+ libsyscommon
)
SET(pc_dependents "capi-base-common")
+++ /dev/null
-/*
- * storage
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LIST_H__
-#define __LIST_H__
-
-#include <stdio.h>
-
-#ifdef EINA_LIST
-#include <Eina.h>
-typedef Eina_List dd_list;
-#define DD_LIST_PREPEND(a, b) \
- a = eina_list_prepend(a, b)
-#define DD_LIST_APPEND(a, b) \
- a = eina_list_append(a, b)
-#define DD_LIST_REMOVE(a, b) \
- a = eina_list_remove(a, b)
-#define DD_LIST_LENGTH(a) \
- eina_list_count(a)
-#define DD_LIST_NTH(a, b) \
- eina_list_nth(a, b)
-#define DD_LIST_FREE_LIST(a) \
- a = eina_list_free(a)
-#define DD_LIST_FOREACH(head, elem, node) \
- EINA_LIST_FOREACH(head, elem, node)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
- EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node)
-
-#else
-#include <glib.h>
-typedef GList dd_list;
-#define DD_LIST_PREPEND(a, b) \
- a = g_list_prepend(a, (gpointer)b)
-#define DD_LIST_APPEND(a, b) \
- a = g_list_append(a, (gpointer)b)
-#define DD_LIST_REMOVE(a, b) \
- a = g_list_remove(a, (gpointer)b)
-#define DD_LIST_LENGTH(a) \
- g_list_length(a)
-#define DD_LIST_NTH(a, b) \
- g_list_nth_data(a, b)
-#define DD_LIST_FREE_LIST(a) \
- g_list_free(a)
-#define DD_LIST_FOREACH(head, elem, node) \
- for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
- for (elem = head, elem_next = g_list_next(elem), node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = elem_next, elem_next = g_list_next(elem), node = NULL)
-
-#endif
-
-#endif
BuildRequires: pkgconfig(mount)
BuildRequires: pkgconfig(blkid)
BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(libsyscommon)
%if 0%{?gcov:1}
BuildRequires: lcov
%endif
#include <assert.h>
#include <mntent.h>
#include <tzplatform_config.h>
+#include <libsyscommon/ini-parser.h>
#include "log.h"
#include "common.h"
#define STORAGE_CONF_FILE "/etc/storage/libstorage.conf"
-#define MAX_LINE 128
-#define MAX_SECTION 64
-#define WHITESPACE " \t"
-#define NEWLINE "\n\r"
-#define COMMENT '#'
-
#define MATCH(a, b) (!strncmp(a, b, strlen(a)))
#define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
-struct parse_result {
- char *section;
- char *name;
- char *value;
-};
-
struct storage_config_info {
double total_size;
double check_size;
static struct storage_config_info storage_info;
-static inline char *trim_str(char *s)
-{
- char *t;
- /* left trim */
- s += strspn(s, WHITESPACE);
-
- /* right trim */
- for (t = strchr(s, 0); t > s; t--)
- if (!strchr(WHITESPACE, t[-1]))
- break;
- *t = 0;
- return s;
-}
-
-static int config_parse(const char *file_name, int cb(struct parse_result *result,
- void *user_data), void *user_data)
-{
- FILE *f = NULL;
- struct parse_result result;
- /* use stack for parsing */
- char line[MAX_LINE];
- char section[MAX_SECTION];
- char *start, *end, *name, *value;
- int lineno = 0, ret = 0;
-
- if (!file_name || !cb) {
- ret = -EINVAL;
- goto error;
- }
-
- /* open conf file */
- f = fopen(file_name, "r");
- if (!f) {
- _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE
- ret = -EIO;
- goto error;
- }
-
- /* parsing line by line */
- while (fgets(line, MAX_LINE, f) != NULL) {
- lineno++;
-
- start = line;
- start[strcspn(start, NEWLINE)] = '\0';
- start = trim_str(start);
-
- if (*start == COMMENT) {
- continue;
- } else if (*start == '[') {
- /* parse section */
- end = strchr(start, ']');
- if (!end || *end != ']') {
- ret = -EBADMSG;
- goto error;
- }
-
- *end = '\0';
- strncpy(section, start + 1, sizeof(section) - 1);
- section[MAX_SECTION-1] = '\0';
- } else if (*start) {
- /* parse name & value */
- end = strchr(start, '=');
- if (!end || *end != '=') {
- ret = -EBADMSG;
- goto error;
- }
- *end = '\0';
- name = trim_str(start);
- value = trim_str(end + 1);
- end = strchr(value, COMMENT);
- if (end && *end == COMMENT) {
- *end = '\0';
- value = trim_str(value);
- }
-
- result.section = section;
- result.name = name;
- result.value = value;
- /* callback with parse result */
- ret = cb(&result, user_data);
- if (ret < 0) {
- ret = -EBADMSG;
- goto error;
- }
- }
- }
- _D("Success to load %s", file_name);
- fclose(f);
- return 0;
-
-error:
- if (f)
- fclose(f);
- _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE
- return ret;
-}
-
static int load_config(struct parse_result *result, void *user_data)
{
static int check_size = -1;
#include <stdbool.h>
#include <errno.h>
#include <gio/gio.h>
-#include <glib.h>
#include <assert.h>
#include <limits.h>
+#include <glib.h>
#include <sys/statvfs.h>
#include <tzplatform_config.h>
+#include <libsyscommon/dbus-system.h>
+#include <libsyscommon/list.h>
#include "log.h"
#include "storage-external-dbus.h"
guint block_id;
};
-typedef struct {
- dbus_pending_cb func;
- void *data;
-} pending_call_data;
-
-static dd_list *changed_list;
+static GList *changed_list;
static void storage_ext_release_internal(storage_ext_device *dev)
{
*dev = NULL;
}
-void storage_ext_release_list(dd_list **list)
+void storage_ext_release_list(GList **list)
{
storage_ext_device *dev;
- dd_list *elem;
+ GList *elem;
if (*list == NULL)
return;
- DD_LIST_FOREACH(*list, elem, dev) {
+ SYS_G_LIST_FOREACH(*list, elem, dev) {
storage_ext_release_internal(dev);
free(dev);
}
*list = NULL;
}
-static GDBusConnection *get_dbus_connection(void)
-{
- GError *err = NULL;
- static GDBusConnection *conn;
-
- if (conn)
- return conn;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!conn) {
-//LCOV_EXCL_START System Error
- if (err) {
- _E("fail to get dbus connection : %s", err->message);
- g_clear_error(&err);
- } else
- _E("fail to get dbus connection");
- return NULL;
-//LCOV_EXCL_STOP
- }
- return conn;
-}
-
-static void _cb_pending(GDBusConnection *conn,
- GAsyncResult *res,
- gpointer user_data)
-{
- GVariant *reply = NULL;
- GError *err = NULL;
- pending_call_data *data = (pending_call_data *)user_data;
-
- reply = g_dbus_connection_call_finish(conn, res, &err);
- if (!reply || err) {
- if (!err)
- g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Error during g_dbus_connection_call");
-
- if (data && data->func)
- data->func(NULL, data->data, err);
- goto out;
- }
-
- if (data && data->func)
- data->func(reply, data->data, err);
-out:
- if (err)
- g_error_free(err);
- if (data)
- free(data);
-}
-
-int dbus_method_async_with_reply_var(const char *dest, const char *path,
- const char *iface, const char *method, GVariant *param,
- dbus_pending_cb cb, int timeout, void *data)
-{
- GDBusConnection *conn;
- pending_call_data *pdata = NULL;
- int ret = 0;
-
- if (!dest || !path || !iface || !method)
- return -EINVAL;
-
- if (timeout < -1) {
- _E("wrong timeout %d", timeout);
- return -EINVAL;
- }
-
- conn = get_dbus_connection();
- if (!conn) {
- _E("fail to get dbus connection"); //LCOV_EXCL_LINE
- return -1;
- }
-
- if (cb) {
- pdata = (pending_call_data*)malloc(sizeof(pending_call_data));
- if (!pdata) {
- ret = -ENOMEM;
- goto err;
- }
-
- pdata->func = cb;
- pdata->data = data;
- }
-
- g_dbus_connection_call(conn, dest, path, iface, method,
- param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL,
- (GAsyncReadyCallback)_cb_pending,
- pdata);
-
- return ret;
-err:
- if (param)
- g_variant_unref(param);
- return ret;
-}
-
-GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
- const gchar *iface, const gchar *method, GVariant *param)
-{
- GDBusConnection *conn;
- GError *err = NULL;
- GVariant *ret;
-
- if (!dest || !path || !iface || !method)
- return NULL;
-
- conn = get_dbus_connection();
- if (!conn) {
- _E("fail to get dbus connection"); //LCOV_EXCL_LINE
- return NULL;
- }
-
- ret = g_dbus_connection_call_sync(conn,
- dest, path, iface, method,
- param, NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &err);
- if (!ret) {
-//LCOV_EXCL_START System Error
- if (err) {
- _E("dbus method sync call failed(%s)", err->message);
- g_clear_error(&err);
- } else
- _E("g_dbus_connection_call_sync() failed");
- return NULL;
-//LCOV_EXCL_STOP
- }
-
- return ret;
-}
-
-int storage_ext_get_list(dd_list **list)
+int storage_ext_get_list(GList **list)
{
GVariant *result;
GVariantIter *iter;
if (!list)
return -EINVAL;
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
STORAGE_EXT_GET_LIST,
return -EIO;
}
- g_variant_get(result, "(a(issssssisibii))", &iter);
+ if (!g_variant_get_safe(result, "(a(issssssisibii))", &iter)) {
+ _E("Failed to get params from gvariant.");
+ g_variant_unref(result);
+ return -EIO;
+ }
while (g_variant_iter_loop(iter, "(issssssisibii)",
&info.type, &info.devnode, &info.syspath,
elem->flags = info.flags;
elem->storage_id = info.storage_id;
- DD_LIST_APPEND(*list, elem);
+ SYS_G_LIST_APPEND(*list, elem);
}
- ret = g_list_length(*list);
+ ret = SYS_G_LIST_LENGTH(*list);
out:
if (ret < 0)
memset(buf, 0, sizeof(struct statvfs_32));
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_STORAGE,
STORAGE_EXT_IFACE_STORAGE,
STORAGE_EXT_GET_STATVFS,
return -EIO;
}
- g_variant_get(result, "(ttttttttttt)",
+ if (!g_variant_get_safe(result, "(ttttttttttt)",
&bsize, &frsize, &blocks,
&bfree, &bavail, &files,
&ffree, &favail, &fsid,
- &flag, &namemax);
+ &flag, &namemax)) {
+ _E("Failed to get params from gvariant.");
+ g_variant_unref(result);
+ return -EIO;
+ }
// %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax
buf->f_bsize = (unsigned long)bsize;
memset(buf, 0, sizeof(struct statvfs));
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_STORAGE,
STORAGE_EXT_IFACE_STORAGE,
STORAGE_EXT_GET_STATVFS,
return -EIO;
}
- g_variant_get(result, "(ttttttttttt)",
+ if (!g_variant_get_safe(result, "(ttttttttttt)",
&(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks),
&(buf->f_bfree), &(buf->f_bavail), &(buf->f_files),
&(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid),
- &(buf->f_flag), &(buf->f_namemax));
+ &(buf->f_flag), &(buf->f_namemax))) {
+ _E("Failed to get params from gvariant.");
+ g_variant_unref(result);
+ return -EIO;
+ }
// %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax
// %llu buf->f_blocks, buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, buf->f_favail
return -EINVAL;
}
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_STORAGE,
STORAGE_EXT_IFACE_STORAGE,
STORAGE_EXT_GET_STORAGE_LEVEL,
return -EIO;
}
- g_variant_get(result, "(s)", &tmp);
+ if (!g_variant_get_safe(result, "(s)", &tmp)) {
+ _E("Failed to get params from gvariant.");
+ g_variant_unref(result);
+ return -EIO;
+ }
+
*level = strdup(tmp);
g_free(tmp);
+ g_variant_unref(result);
if (*level == NULL)
return -ENOMEM;
static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data)
{
storage_ext_device *dev;
- dd_list *elem;
+ GList *elem;
struct storage_ext_callback *callback;
int ret;
if (!dev)
return;
- g_variant_get(params, "(issssssisibii)",
+ if (!g_variant_get_safe(params, "(issssssisibii)",
&dev->type,
&dev->devnode,
&dev->syspath,
&dev->state,
&dev->primary,
&dev->flags,
- &dev->storage_id);
+ &dev->storage_id))
+ return;
/* Callback is called when unmount is started(DeviceBlocked signal) */
if (state == STORAGE_EXT_CHANGED && dev->state == STORAGE_EXT_UNMOUNTED) {
return;
}
- DD_LIST_FOREACH(changed_list, elem, callback) {
+ SYS_G_LIST_FOREACH(changed_list, elem, callback) {
if (!callback->func)
continue;
ret = callback->func(dev, state, callback->data);
int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
{
- GDBusConnection *conn;
guint block_id = 0;
struct storage_ext_callback *callback;
- dd_list *elem;
+ GList *elem;
if (!func)
return -EINVAL;
- DD_LIST_FOREACH(changed_list, elem, callback) {
+ SYS_G_LIST_FOREACH(changed_list, elem, callback) {
if (callback->func != func)
continue;
if (callback->block_id == 0)
//LCOV_EXCL_STOP
}
- conn = get_dbus_connection();
- if (!conn) {
- //LCOV_EXCL_START System Error
- free(callback);
- _E("Failed to get dbus connection");
- return -EPERM;
- //LCOV_EXCL_STOP
- }
-
- block_id = g_dbus_connection_signal_subscribe(conn,
- NULL,
+ block_id = subscribe_dbus_signal(NULL, NULL,
STORAGE_EXT_IFACE_MANAGER,
NULL,
- NULL,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
storage_ext_changed,
NULL,
NULL);
callback->data = data;
callback->block_id = block_id;
- DD_LIST_APPEND(changed_list, callback);
+ SYS_G_LIST_APPEND(changed_list, callback);
return 0;
}
void storage_ext_unregister_device_change(storage_ext_changed_cb func)
{
- GDBusConnection *conn;
struct storage_ext_callback *callback;
- dd_list *elem;
- dd_list *elem_n;
+ GList *elem;
+ GList *elem_n;
if (!func)
return;
- conn = get_dbus_connection();
- if (!conn) {
-//LCOV_EXCL_START System Error
- _E("fail to get dbus connection");
- return;
-//LCOV_EXCL_STOP
- }
-
- DD_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) {
+ SYS_G_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) {
if (callback->func != func)
continue;
if (callback->block_id > 0)
- g_dbus_connection_signal_unsubscribe(conn, callback->block_id);
+ unsubscribe_dbus_signal(NULL, callback->block_id);
- DD_LIST_REMOVE(changed_list, callback);
+ SYS_G_LIST_REMOVE(changed_list, callback);
free(callback);
}
}
int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
{
GVariant *result;
+ int ret;
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
"GetDeviceInfo",
return -ENODEV;
}
- if (g_variant_check_format_string(result, "(issssssisibii)", true)) {
- g_variant_get(result, "(issssssisibii)",
+ if (!g_variant_get_safe(result, "(issssssisibii)",
&info->type, &info->devnode, &info->syspath,
&info->fs_usage, &info->fs_type,
&info->fs_version, &info->fs_uuid,
&info->readonly, &info->mount_point,
&info->state, &info->primary,
- &info->flags, &info->storage_id);
- } else {
+ &info->flags, &info->storage_id)) {
_E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
- return -ENODEV;
+ ret = -ENODEV;
+ goto out;
}
if (info->storage_id < 0) {
_E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
- return -ENODEV;
+ ret = -ENODEV;
+ goto out;
}
+ ret = 0;
+out:
g_variant_unref(result);
-
- return 0;
+ return ret;
}
#include <stdbool.h>
#include <glib.h>
#include <gio/gio.h>
-#include "list.h"
#define STORAGE_EXT_BUS_NAME "org.tizen.system.storage"
#define STORAGE_EXT_PATH_MANAGER "/Org/Tizen/System/Storage/Block/Manager"
int storage_ext_is_supported(void);
void storage_ext_release_device(storage_ext_device **dev);
-void storage_ext_release_list(dd_list **list);
-int storage_ext_get_list(dd_list **list);
+void storage_ext_release_list(GList **list);
+int storage_ext_get_list(GList **list);
int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf);
int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf);
int storage_ext_get_device_info(int storage_id, storage_ext_device *info);
int storage_ext_get_storage_level(const char *path, char **level);
-typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err);
-int dbus_method_async_with_reply_var(const char *dest, const char *path,
- const char *iface, const char *method, GVariant *param,
- dbus_pending_cb cb, int timeout, void *data);
-/* storage-internal.c */
-GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
- const gchar *iface, const gchar *method, GVariant *param);
-
#endif /* __STORAGE_EXTERNAL_DBUS_H__ */
#include <sys/statvfs.h>
#include <vconf.h>
#include <tzplatform_config.h>
+#include <libsyscommon/list.h>
#include "common.h"
-#include "list.h"
#include "log.h"
#include "storage-external-dbus.h"
#define LUKS_NAME "crypto_LUKS"
-static dd_list *cb_list[STORAGE_CALLBACK_MAX];
+static GList *cb_list[STORAGE_CALLBACK_MAX];
static int storage_ext_get_dev_state(storage_ext_device *dev,
enum storage_ext_state blk_state,
{
int ret;
bool ret_cb;
- dd_list *list = NULL, *elem;
+ GList *list = NULL, *elem;
storage_ext_device *dev;
storage_state_e state;
return ret;
}
- DD_LIST_FOREACH(list, elem, dev) {
+ SYS_G_LIST_FOREACH(list, elem, dev) {
ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state);
if (ret < 0) {
_E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); //LCOV_EXCL_LINE
{
enum storage_cb_type type = (enum storage_cb_type)data;
struct storage_cb_info *cb_info;
- dd_list *elem;
+ GList *elem;
storage_state_e state;
int ret;
return ret;
}
- DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info)
+ SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info)
cb_info->state_cb(cb_info->id, state, cb_info->user_data);
return 0;
{
enum storage_cb_type type = (enum storage_cb_type)data;
struct storage_cb_info *cb_info;
- dd_list *elem;
+ GList *elem;
storage_state_e state;
int ret;
storage_dev_e strdev;
if (!strncmp(fstype, LUKS_NAME, strlen(LUKS_NAME)))
storage_type = STORAGE_TYPE_EXTENDED_INTERNAL;
- DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) {
+ SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) {
if (cb_info->type != storage_type)
continue;
if (cb_info->type_cb)
struct storage_cb_info *info, struct storage_cb_info **cb_data)
{
struct storage_cb_info *cb_info;
- dd_list *elem;
+ GList *elem;
if (!info)
return false;
if (type == STORAGE_CALLBACK_ID) {
- DD_LIST_FOREACH(cb_list[type], elem, cb_info) {
+ SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) {
if (cb_info->id == info->id &&
cb_info->state_cb == info->state_cb) {
goto out;
}
if (type == STORAGE_CALLBACK_TYPE) {
- DD_LIST_FOREACH(cb_list[type], elem, cb_info) {
+ SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) {
if (cb_info->type == info->type &&
cb_info->type_cb == info->type_cb)
goto out;
return -EINVAL;
}
- n = DD_LIST_LENGTH(cb_list[type]);
+ n = SYS_G_LIST_LENGTH(cb_list[type]);
if (n == 0) {
ret = storage_ext_register_device_change(callback, (void *)type);
if (ret < 0)
return -errno;
memcpy(cb_info, info, sizeof(struct storage_cb_info));
- DD_LIST_APPEND(cb_list[type], cb_info);
+ SYS_G_LIST_APPEND(cb_list[type], cb_info);
return 0;
}
/* remove device callback from list (local) */
if (cb_info) {
- DD_LIST_REMOVE(cb_list[type], cb_info);
+ SYS_G_LIST_REMOVE(cb_list[type], cb_info);
free(cb_info);
}
/* check if this callback is last element */
- n = DD_LIST_LENGTH(cb_list[type]);
+ n = SYS_G_LIST_LENGTH(cb_list[type]);
if (n == 0)
storage_ext_unregister_device_change(callback);
int storage_ext_get_primary_mmc_path(char *path, size_t len)
{
- dd_list *list = NULL, *elem;
+ GList *list = NULL, *elem;
storage_ext_device *dev;
int ret;
return ret;
}
- DD_LIST_FOREACH(list, elem, dev) {
+ SYS_G_LIST_FOREACH(list, elem, dev) {
if (dev->primary) {
snprintf(path, len, "%s", dev->mount_point);
ret = 0;
#include <errno.h>
#include <tzplatform_config.h>
#include <blkid.h>
+#include <libsyscommon/dbus-system.h>
#include "common.h"
-#include "list.h"
#include "log.h"
#include "storage-internal.h"
#include "storage-external-dbus.h"
if (!storage_ext_is_supported())
return STORAGE_ERROR_NOT_SUPPORTED;
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
"GetMmcPrimary",
//LCOV_EXCL_STOP
}
- g_variant_get(result, "(issssssisibii)",
+ if (!g_variant_get_safe(result, "(issssssisibii)",
NULL, NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, &mount_point,
NULL, NULL,
- NULL, &id);
+ NULL, &id)) {
+ g_variant_unref(result);
+ return STORAGE_ERROR_OPERATION_FAILED;
+ }
g_variant_unref(result);
free(path);
//LCOV_EXCL_STOP
- ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+ ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
"Mount",
free(path);
//LCOV_EXCL_STOP
- ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+ ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
"Unmount",
free(path);
//LCOV_EXCL_STOP
- ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+ ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
STORAGE_EXT_PATH_MANAGER,
STORAGE_EXT_IFACE_MANAGER,
"Format",
#include <errno.h>
#include <vconf.h>
#include <tzplatform_config.h>
+#include <libsyscommon/list.h>
#include "common.h"
-#include "list.h"
#include "log.h"
#include "storage-external.h"
[STORAGE_DIRECTORY_OTHERS] = TZ_USER_OTHERS,
};
-static dd_list *st_int_head; /* Internal storage list */
+static GList *st_int_head; /* Internal storage list */
-static dd_list *compat_cb_list;
+static GList *compat_cb_list;
struct compat_cb_info {
storage_state_changed_cb user_cb;
void *user_data;
void add_device(const struct storage_ops *st)
{
- DD_LIST_APPEND(st_int_head, st);
+ SYS_G_LIST_APPEND(st_int_head, st);
}
void remove_device(const struct storage_ops *st)
{
- DD_LIST_REMOVE(st_int_head, st);
+ SYS_G_LIST_REMOVE(st_int_head, st);
}
API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data)
{
const struct storage_ops *st;
- dd_list *elem;
+ GList *elem;
int ret;
bool user = true;
if (getuid() <= USER_UID_START)
user = false;
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (user) {
ret = callback(st->storage_id, st->type, st->get_state(),
st->root(), user_data);
API int storage_get_root_directory(int storage_id, char **path)
{
const struct storage_ops *st;
- dd_list *elem;
+ GList *elem;
char root[PATH_MAX];
int ret;
bool extendedint;
user = false;
/* internal storage */
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (st->storage_id != storage_id)
continue;
if (!user) {
char temp[PATH_MAX];
char *temp2, *end;
int ret;
- dd_list *elem;
+ GList *elem;
bool found;
bool extendedint;
bool user = true;
/* internal storage */
found = false;
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (st->storage_id != storage_id)
continue;
found = true;
API int storage_get_type(int storage_id, storage_type_e *type)
{
const struct storage_ops *st;
- dd_list *elem;
+ GList *elem;
char root[PATH_MAX];
int ret;
bool extendedint;
}
/* internal storage */
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (st->storage_id != storage_id)
continue;
*type = st->type;
{
const struct storage_ops *ops;
storage_state_e st;
- dd_list *elem;
+ GList *elem;
int ret;
if (storage_id < 0)
}
/* internal storage */
- DD_LIST_FOREACH(st_int_head, elem, ops) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, ops) {
if (ops->storage_id != storage_id)
continue;
*state = ops->get_state();
bool primary, int flags, void *user_data)
{
struct compat_cb_info* ccb_info;
- dd_list *elem;
+ GList *elem;
if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD)
- DD_LIST_FOREACH(compat_cb_list, elem, ccb_info)
+ SYS_G_LIST_FOREACH(compat_cb_list, elem, ccb_info)
ccb_info->user_cb(storage_id, state, ccb_info->user_data);
}
//LCOV_EXCL_STOP
const struct storage_ops *st;
struct storage_cb_info info;
int ret;
- dd_list *elem;
+ GList *elem;
struct compat_cb_info* ccb_info;
static int compat_cb_init = 0;
return STORAGE_ERROR_OPERATION_FAILED;
ccb_info->user_cb = callback;
ccb_info->user_data = user_data;
- DD_LIST_APPEND(compat_cb_list, ccb_info);
+ SYS_G_LIST_APPEND(compat_cb_list, ccb_info);
return STORAGE_ERROR_NONE;
}
/* Internal storage does not support registering changed callback */
- DD_LIST_FOREACH(st_int_head, elem, st)
+ SYS_G_LIST_FOREACH(st_int_head, elem, st)
if (st->storage_id == storage_id)
return STORAGE_ERROR_NONE;
const struct storage_ops *st;
struct storage_cb_info info;
int ret;
- dd_list *elem;
+ GList *elem;
if (storage_id < 0)
return STORAGE_ERROR_INVALID_PARAMETER;
return STORAGE_ERROR_NOT_SUPPORTED;
}
- dd_list *elem_n;
+ GList *elem_n;
struct compat_cb_info* ccb_info;
- DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
+ SYS_G_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
if (ccb_info->user_cb == callback) {
- DD_LIST_REMOVE(compat_cb_list, ccb_info);
+ SYS_G_LIST_REMOVE(compat_cb_list, ccb_info);
free(ccb_info);
return STORAGE_ERROR_NONE;
}
}
/* Internal storage does not support registering changed callback */
- DD_LIST_FOREACH(st_int_head, elem, st)
+ SYS_G_LIST_FOREACH(st_int_head, elem, st)
if (st->storage_id == storage_id)
return STORAGE_ERROR_NONE;
const struct storage_ops *st;
unsigned long long total;
int ret;
- dd_list *elem;
+ GList *elem;
if (storage_id < 0)
return STORAGE_ERROR_INVALID_PARAMETER;
}
/* internal storage */
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (st->storage_id != storage_id)
continue;
ret = st->get_space(&total, NULL);
const struct storage_ops *st;
unsigned long long avail;
int ret;
- dd_list *elem;
+ GList *elem;
if (storage_id < 0)
return STORAGE_ERROR_INVALID_PARAMETER;
}
/* internal storage */
- DD_LIST_FOREACH(st_int_head, elem, st) {
+ SYS_G_LIST_FOREACH(st_int_head, elem, st) {
if (st->storage_id != storage_id)
continue;
ret = st->get_space(NULL, &avail);