#include <app2ext_interface.h>
#include <libmount.h>
#include <blkid/blkid.h>
-#include <ode/luks.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
-#include <libsyscommon/dbus-system.h>
+#include <libsyscommon/libgdbus.h>
+#include <libsyscommon/ini-parser.h>
+#include <libsyscommon/list.h>
+#ifdef EXTENDED_STORAGE
+#include <ode/luks.h>
+#endif
#include "log.h"
-#include "config-parser.h"
#include "module-intf.h"
#include "udev.h"
-#include "list.h"
#include "block.h"
#include "fd_handler.h"
#include "utils.h"
#define TIMEOUT_MAKE_OBJECT 500 /* milliseconds */
#define SIGNAL_POWEROFF_STATE "ChangeState"
+#define METHOD_ADD_POWEROFF_WAIT "AddPowerOffWait"
+#define METHOD_REMOVE_POWEROFF_WAIT "RemovePowerOffWait"
#define BLOCK_DEVICE_ADDED "DeviceAdded"
#define BLOCK_DEVICE_REMOVED "DeviceRemoved"
#define BLOCK_DEVICE_BLOCKED "DeviceBlocked"
#define BLOCK_DEVICE_CHANGED "DeviceChanged"
-#define BLOCK_DEVICE_CHANGED_2 "DeviceChanged2"
#define BLOCK_TYPE_MMC "mmc"
#define BLOCK_TYPE_SCSI "scsi"
#define EXTENDEDSD_MOUNT_PATH "/opt/extendedsd"
#define VFAT_NAME "vfat"
+#define EXFAT_NAME "exfat"
#define EXT4_NAME "ext4"
#define LUKS_NAME "crypto_LUKS"
-#define EXTENDEDSD_NAME "extendedsd"
+#define EXTENDEDSD_NAME "extendedsd"
/* Minimum value of block id */
#define BLOCK_ID_MIN 10
struct block_device {
struct block_data *data;
- dd_list *op_queue;
+ GList *op_queue;
int thread_id; /* Current thread ID */
bool removed; /* True when device is physically removed but operation is not precessed yet */
enum private_operation_state on_private_op;
} block_conf[BLOCK_EXTENDEDSD_DEV + 1];
static struct manage_thread {
- dd_list *th_node_list; /* List of devnode which thread dealt with. Only main thread access */
- dd_list *block_dev_list; /* Use thread mutex */
+ GList *th_node_list; /* List of devnode which thread dealt with. Only main thread access */
+ GList *block_dev_list; /* Use thread mutex */
pthread_t th;
pthread_mutex_t mutex;
pthread_cond_t cond;
#define DIR_NUM ((int)(sizeof(mmc_default_path)/sizeof(mmc_default_path[0])))
-static dd_list *fs_head;
-static dd_list *block_ops_list;
+static GList *fs_head;
+static GList *block_ops_list;
static bool smack;
static int pfds[2];
static fd_handler_h phandler;
static bool block_control = false;
static bool block_boot = false;
static pthread_mutex_t pipe_mutex = PTHREAD_MUTEX_INITIALIZER;
+static bool add_poweroff_wait = false;
/* Assume there is only one physical internal storage */
static int dev_internal = -1;
enum block_dev_operation operation,
GDBusMethodInvocation *invocation, void *data);
static void remove_operation(struct block_device *bdev);
-static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op);
-static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op);
+static void check_removed(struct block_device *bdev, GList **queue, struct operation_queue **op);
+static bool check_unmount(struct block_device *bdev, GList **queue, struct operation_queue **op);
static int change_mount_point(struct block_device *bdev, const char *mount_point);
+static void terminate_threads(void);
#define nullstr(x) (x ? x : "")
static GVariant *block_data_to_gvariant(struct block_data *data, int flags);
-static GVariant *block_data_to_gvariant2(struct block_data *data, int flags);
#define block_send_dbus_reply(invocation, result) if (invocation) {g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", result)); }
void add_fs(const struct block_fs_ops *fs)
{
- DD_LIST_APPEND(fs_head, (void *)fs);
+ SYS_G_LIST_APPEND(fs_head, (void *)fs);
}
void remove_fs(const struct block_fs_ops *fs)
{
- DD_LIST_REMOVE(fs_head, (void *)fs);
+ SYS_G_LIST_REMOVE(fs_head, (void *)fs);
}
const struct block_fs_ops *find_fs(enum block_fs_type type)
{
struct block_fs_ops *fs;
- dd_list *elem;
+ GList *elem;
- DD_LIST_FOREACH(fs_head, elem, fs) {
+ SYS_G_LIST_FOREACH(fs_head, elem, fs) {
if (fs->type == type)
return fs;
}
void add_block_dev(const struct block_dev_ops *ops)
{
- DD_LIST_APPEND(block_ops_list, (void *)ops);
+ SYS_G_LIST_APPEND(block_ops_list, (void *)ops);
}
void remove_block_dev(const struct block_dev_ops *ops)
{
- DD_LIST_REMOVE(block_ops_list, (void *)ops);
+ SYS_G_LIST_REMOVE(block_ops_list, (void *)ops);
}
static void broadcast_block_info(enum block_dev_operation op,
struct block_data *data, int result)
{
struct block_dev_ops *ops;
- dd_list *elem;
+ GList *elem;
if (data->primary != true)
return;
- DD_LIST_FOREACH(block_ops_list, elem, ops) {
+ SYS_G_LIST_FOREACH(block_ops_list, elem, ops) {
int data_block_type = (data->block_type == BLOCK_EXTENDEDSD_DEV)
? BLOCK_MMC_DEV : data->block_type;
{
static int id = BLOCK_ID_MIN;
struct block_device *bdev;
- dd_list *elem;
+ GList *elem;
bool found;
int i, j;
found = false;
for (j = 0; j < THREAD_MAX; j++) {
pthread_mutex_lock(&(th_manager[j].mutex));
- DD_LIST_FOREACH(th_manager[j].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[j].block_dev_list, elem, bdev) {
if (bdev->data->id == id) {
found = true;
break;
static void remove_file(int id, bool extendedsd)
{
char file_name[PATH_LEN];
- int ret;
+ int ret_val;
if (id < 0)
return;
else
snprintf(file_name, sizeof(file_name), EXTERNAL_STORAGE_PATH"/%d", id);
- ret = remove(file_name);
- if (ret < 0)
+ ret_val = remove(file_name);
+ if (ret_val < 0)
_E("Failed to remove '%s': %d", file_name, errno);
}
_E("Failed to open '%s'.", file_name);
}
-static void signal_device_blocked(struct block_device *bdev)
+static void broadcast_device_blocked(struct block_device *bdev)
{
struct block_data *data;
+ int ret_dbus;
if (!bdev || !bdev->data)
return;
data = bdev->data;
- dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_BLOCK_MANAGER,
+ ret_dbus = gdbus_signal_emit(NULL,
+ STORAGED_PATH_BLOCK_MANAGER,
STORAGED_INTERFACE_BLOCK_MANAGER,
BLOCK_DEVICE_BLOCKED,
block_data_to_gvariant(data, 0));
+ if (ret_dbus < 0)
+ _E("Failed to send dbus signal");
}
-static void signal_device_changed(struct block_device *bdev,
+static void broadcast_device_changed(struct block_device *bdev,
enum block_dev_operation op)
{
struct block_data *data;
- GVariant *var = NULL;
- int flags;
+ GVariant *param = NULL;
+ const char *signal_name = NULL;
+ int flags = 0;
+ int ret_dbus;
- if (!bdev || !bdev->data)
+ if (!bdev || !bdev->data) {
+ _E("Failed to broadcast device changed signal. op(%d)", op);
return;
+ }
data = bdev->data;
+ /* set flags and signal name */
switch (op) {
case BLOCK_DEV_MOUNT:
BLOCK_GET_MOUNT_FLAGS(data, flags);
+ signal_name = BLOCK_DEVICE_CHANGED;
break;
case BLOCK_DEV_UNMOUNT:
BLOCK_GET_UNMOUNT_FLAGS(data, flags);
+ signal_name = BLOCK_DEVICE_CHANGED;
break;
case BLOCK_DEV_FORMAT:
BLOCK_GET_FORMAT_FLAGS(data, flags);
+ signal_name = BLOCK_DEVICE_CHANGED;
break;
- default:
+ case BLOCK_DEV_INSERT:
flags = 0;
+ signal_name = BLOCK_DEVICE_ADDED;
break;
+ case BLOCK_DEV_REMOVE:
+ flags = 0;
+ signal_name = BLOCK_DEVICE_REMOVED;
+ break;
+ default:
+ /* unknown op */
+ _E("Failed to broadcast device changed signal. op(%d)", op);
+ return;
}
/* Broadcast outside with BlockManager iface */
- var = block_data_to_gvariant(data, flags);
+ param = block_data_to_gvariant(data, flags);
- if (op == BLOCK_DEV_INSERT)
- dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- BLOCK_DEVICE_ADDED,
- var);
- else if (op == BLOCK_DEV_REMOVE)
- dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_BLOCK_MANAGER,
+ ret_dbus = gdbus_signal_emit(NULL,
+ STORAGED_PATH_BLOCK_MANAGER,
STORAGED_INTERFACE_BLOCK_MANAGER,
- BLOCK_DEVICE_REMOVED,
- var);
- else {
- dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- BLOCK_DEVICE_CHANGED,
- var);
- dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- BLOCK_DEVICE_CHANGED_2,
- block_data_to_gvariant2(data, flags));
- }
+ signal_name,
+ param);
+ if (ret_dbus < 0)
+ _E("Failed to broadcast device changed signal. op(%d)", op);
}
static int get_mmc_mount_node(char *devnode, char *node, size_t len)
{
const char *str;
char *name, node[64];
- int ret;
+ int ret_val;
if (!data || !data->devnode || !data->fs_usage || (strcmp(data->fs_usage, FILESYSTEM_NAME) && strncmp(data->fs_usage, "crypto", strlen("crypto"))))
return NULL;
switch (data->block_type) {
case BLOCK_MMC_DEV:
- ret = get_mmc_mount_node(name, node, sizeof(node));
+ ret_val = get_mmc_mount_node(name, node, sizeof(node));
break;
case BLOCK_SCSI_DEV:
- ret = get_scsi_mount_node(name, node, sizeof(node));
+ ret_val = get_scsi_mount_node(name, node, sizeof(node));
break;
case BLOCK_EXTENDEDSD_DEV:
return strdup(EXTENDEDSD_MOUNT_PATH);
_E("Invalid block type(%d).", data->block_type);
return NULL;
}
- if (ret < 0)
+ if (ret_val < 0)
goto out;
str = tzplatform_mkpath(TZ_SYS_MEDIA, node);
{
struct block_fs_ops *fs;
blkid_probe probe;
- dd_list *elem;
+ GList *elem;
const char *filesystem = NULL;
char *temp;
char str[PATH_MAX];
char str2[PATH_MAX];
size_t fs_len;
int len;
- int ret;
+ int ret_val;
int i;
bool found = false;
str[len - 1] = '\0';
for (i = 1; i <= 9; ++i) {
- snprintf(str2, sizeof(str2), "%s%d", str, i);
+ if ((ret_val = snprintf(str2, sizeof(str2), "%s%d", str, i)) > sizeof(str2) - 1) {
+ _E("Filename is longer than buffer. Need %d size of buffer.", ret_val + 1);
+ continue;
+ }
+
if (access(str2, R_OK) != 0)
continue;
if (blkid_do_probe(probe) != 0)
continue;
- ret = blkid_probe_lookup_value(probe, "TYPE", &filesystem, &fs_len);
- if (ret < 0) {
+ ret_val = blkid_probe_lookup_value(probe, "TYPE", &filesystem, &fs_len);
+ if (ret_val < 0) {
blkid_free_probe(probe);
continue;
}
- DD_LIST_FOREACH(fs_head, elem, fs) {
+ SYS_G_LIST_FOREACH(fs_head, elem, fs) {
if (!strncmp(fs->name, filesystem, fs_len)) {
found = true;
break;
// Called by MainThread - Remove DevNode
static void free_block_device(struct block_device *bdev)
{
- dd_list *l, *next;
+ GList *l, *next;
struct operation_queue *op;
int thread_id;
pthread_mutex_lock(&(th_manager[thread_id].mutex));
th_manager[thread_id].num_dev--;
- DD_LIST_REMOVE(th_manager[thread_id].block_dev_list, bdev);
+ SYS_G_LIST_REMOVE(th_manager[thread_id].block_dev_list, bdev);
free_block_data(bdev->data);
- DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
+ SYS_G_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
if (!op->done)
th_manager[thread_id].op_len--;
- DD_LIST_REMOVE(bdev->op_queue, op);
+ SYS_G_LIST_REMOVE(bdev->op_queue, op);
free(op);
}
pthread_mutex_unlock(&(th_manager[thread_id].mutex));
static struct block_device *find_block_device(const char *devnode)
{
struct block_device *bdev;
- dd_list *elem;
+ GList *elem;
int len;
int i;
len = strlen(devnode) + 1;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
if (bdev->data && !bdev->removed &&
!strncmp(bdev->data->devnode, devnode, len)) {
pthread_mutex_unlock(&(th_manager[i].mutex));
static struct block_device *find_block_device_path(const char *mount_point)
{
struct block_device *bdev;
- dd_list *elem;
+ GList *elem;
int len;
int i;
len = strlen(mount_point) + 1;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
if (bdev->data && !bdev->removed &&
(bdev->data->mount_point != NULL && !strncmp(bdev->data->mount_point, mount_point, len))) {
pthread_mutex_unlock(&(th_manager[i].mutex));
static struct block_device *find_block_device_by_id(int id)
{
struct block_device *bdev;
- dd_list *elem;
+ GList *elem;
int i;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
if (!bdev->data)
continue;
if (bdev->removed)
void mmc_make_default_path(const char *mount_path)
{
int i = 0;
- int ret = 0;
+ int ret_val = 0;
char mmc_path[FILE_NAME_LEN_MAX + 1] = {0, };
for (i = 0; i < DIR_NUM; ++i) {
- snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i]);
+ if ((ret_val = snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i])) > sizeof(mmc_path) - 1) {
+ _E("Path is longer than buffer. Need %d size of buffer.", ret_val + 1);
+ continue;
+ }
+
if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
_D("Path(%s) did not exist.", mmc_path);
- ret = mkdir(mmc_path, 0777);
- if (ret != 0)
+ ret_val = mkdir(mmc_path, 0777);
+ if (ret_val != 0)
_E("Failed to mkdir: %d", errno);
/*this fuction for emulator*/
/*at the first time, the directroies are made permission 755*/
- ret = chmod(mmc_path, 0777);
- if (ret != 0)
+ ret_val = chmod(mmc_path, 0777);
+ if (ret_val != 0)
_E("Failed to chmod: %d", errno);
- ret = chown(mmc_path, 0, 10001);
- if (ret != 0)
+ ret_val = chown(mmc_path, 0, 10001);
+ if (ret_val != 0)
_E("Failed to chown: %d", errno);
}
}
static void create_external_apps_directory(void)
{
- int ret;
+ int ret_dbus;
- ret = dbus_handle_method_async(PKGDIR_BUS_NAME, PKGDIR_PATH,
- PKGDIR_INTERFACE, "CreateExternalDirsForAllPkgs", NULL, NULL);
- if (ret)
+ ret_dbus = gdbus_call_async(PKGDIR_BUS_NAME, PKGDIR_PATH,
+ PKGDIR_INTERFACE, "CreateExternalDirsForAllPkgs", NULL);
+ if (ret_dbus)
_E("Failed to create external directory.");
}
struct pipe_data pdata = {0,};
int n;
int thread_id;
- int ret;
+ int ret_val;
n = read(fd, &pdata, sizeof(pdata));
if (n != sizeof(pdata) || !pdata.bdev) {
if (pdata.op == BLOCK_DEV_MOUNT && pdata.result < 0) {
if (pdata.bdev->data->state == BLOCK_UNMOUNT) {
- ret = change_mount_point(pdata.bdev, "");
+ ret_val = change_mount_point(pdata.bdev, "");
/* Modify /run/external-storage/id file */
- if (ret == 0) {
+ if (ret_val == 0) {
if (pdata.bdev->data->block_type == BLOCK_EXTENDEDSD_DEV)
create_file(pdata.bdev->data->id, pdata.bdev->data->mount_point, true);
else
}
goto out;
}
+
+ if (pdata.op == BLOCK_DEV_MOUNT && (pdata.result == 0)) {
+ /* Create file for block device /run/external-storage/id */
+ create_file(pdata.bdev->data->id, pdata.bdev->data->mount_point, pdata.bdev->data->block_type == BLOCK_EXTENDEDSD_DEV);
+ }
+
if (pdata.op == BLOCK_DEV_MOUNT &&
pdata.bdev->data->state == BLOCK_MOUNT &&
pdata.bdev->data->block_type == BLOCK_MMC_DEV &&
create_external_apps_directory();
mmc_make_default_path(pdata.bdev->data->mount_point);
- ret = dbus_handle_method_sync_var(POPUP_BUS_NAME,
+ ret_val = gdbus_call_sync_with_reply_int(POPUP_BUS_NAME,
POPUP_PATH_NOTI,
POPUP_INTERFACE_NOTI,
MMC_POPUP_NOTI,
- g_variant_new("(s)", MMC_INSERTED));
- if (ret != 0)
- _E("Failed to popup: %d", ret);
+ g_variant_new("(s)", MMC_INSERTED),
+ NULL);
+ if (ret_val != 0)
+ _E("Failed to popup: %d", ret_val);
}
+
if (pdata.op == BLOCK_DEV_UNMOUNT) {
/* Remove file for block device /run/xxxxxx/id */
remove_file(pdata.bdev->data->id, pdata.bdev->data->block_type == BLOCK_EXTENDEDSD_DEV);
pdata.bdev->data->primary &&
BLOCK_IS_FLAG_SET(pdata.bdev->data, UNMOUNT_UNSAFE)) {
- ret = dbus_handle_method_sync_var(POPUP_BUS_NAME,
+ ret_val = gdbus_call_sync_with_reply_int(POPUP_BUS_NAME,
POPUP_PATH_NOTI,
POPUP_INTERFACE_NOTI,
MMC_POPUP_NOTI,
- g_variant_new("(s)", MMC_REMOVED));
- if (ret != 0)
- _E("Failed to popup: %d", ret);
+ g_variant_new("(s)", MMC_REMOVED),
+ NULL);
+ if (ret_val != 0)
+ _E("Failed to popup: %d", ret_val);
}
}
/* Broadcast outside with Block iface */
if (pdata.bdev->on_private_op == REQ_NORMAL)
- signal_device_changed(pdata.bdev, pdata.op);
+ broadcast_device_changed(pdata.bdev, pdata.op);
else if (pdata.bdev->on_private_op == REQ_PRIVATE) {
if (pdata.op == BLOCK_DEV_UNMOUNT) {
pdata.bdev->on_private_op = REQ_NORMAL;
static int pipe_init(void)
{
- int ret;
+ int ret_val;
- ret = pipe2(pfds, O_CLOEXEC);
- if (ret == -1)
+ ret_val = pipe2(pfds, O_CLOEXEC);
+ if (ret_val == -1)
return -errno;
- ret = add_fd_read_handler(pfds[0], pipe_cb,
+ ret_val = add_fd_read_handler(pfds[0], pipe_cb,
NULL, NULL, &phandler);
- if (ret < 0) {
- _E("Failed to add pipe handler: %d", ret);
- return ret;
+ if (ret_val < 0) {
+ _E("Failed to add pipe handler: %d", ret_val);
+ return ret_val;
}
return 0;
static int block_mount(struct block_data *data)
{
struct block_fs_ops *fs;
- dd_list *elem;
+ GList *elem;
int r;
int len;
fs = NULL;
len = strlen(data->fs_type) + 1;
- DD_LIST_FOREACH(fs_head, elem, fs) {
+ SYS_G_LIST_FOREACH(fs_head, elem, fs) {
if (!strncmp(fs->name, data->fs_type, len))
break;
}
static int mount_start(struct block_device *bdev)
{
struct block_data *data;
- int ret;
+ int ret_val;
int r;
assert(bdev);
if (data->block_type == BLOCK_MMC_DEV) {
/* app2ext_migrate_legacy_all has dbus method call to deviced */
- ret = app2ext_migrate_legacy_all();
- if (ret < 0)
+ ret_val = app2ext_migrate_legacy_all();
+ if (ret_val < 0)
_E("Failed to app2ext.");
}
{
struct block_data *data;
int r, retry = 0;
- struct timespec time = {0,};
if (!bdev || !bdev->data || !bdev->data->mount_point)
return -EINVAL;
data = bdev->data;
if (bdev->on_private_op == REQ_NORMAL)
- signal_device_blocked(bdev);
+ broadcast_device_blocked(bdev);
/* it must called before unmounting mmc */
r = mmc_check_and_unmount(data->mount_point);
_I("Execute force unmount.");
/* Force Unmount Scenario */
- while (1) {
- switch (retry++) {
- case 0:
- /* Mobile specific:
- * should unmount the below vconf key. */
- if ((data->block_type == BLOCK_MMC_DEV ||
- data->block_type == BLOCK_EXTENDEDSD_DEV) &&
- data->primary) {
- /* At first, notify to other app
- * who already access sdcard */
- _I("Notify to other app who already access sdcard.");
- vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS,
- VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED);
- }
- break;
- case 1:
- /* Second, kill app with SIGTERM */
- _I("Kill app with SIGTERM.");
- terminate_process(data->mount_point, false);
- break;
- case 2:
- /* Last time, kill app with SIGKILL */
- _I("Kill app with SIGKILL.");
- terminate_process(data->mount_point, true);
- break;
- default:
- if (umount2(data->mount_point, MNT_DETACH) != 0) {
- _I("Failed to unmount with lazy option: %d",
- errno);
- return -errno;
- }
- goto out;
- }
- /* it takes some seconds til other app completely clean up */
- time.tv_nsec = 500 * NANO_SECOND_MULTIPLIER;
- nanosleep(&time, NULL);
+ /* Mobile specific:
+ * should unmount the below vconf key. */
+ if ((data->block_type == BLOCK_MMC_DEV ||
+ data->block_type == BLOCK_EXTENDEDSD_DEV) &&
+ data->primary) {
+ /* At first, notify to other app who already access sdcard */
+ _I("Notify to other app who already access sdcard.");
+ vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS,
+ VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED);
- print_open_files(data->mount_point);
+ /* Wait for 700 msec to release open files */
+ usleep(700 * 1000);
+ }
- r = mmc_check_and_unmount(data->mount_point);
- if (!r) {
- _D("Success to unmount '%s'.", data->mount_point);
+ sync();
+
+ if (umount2(data->mount_point, MNT_DETACH) != 0) {
+ _I("Failed to unmount with lazy option: %m");
+ return -errno;
+ }
+
+ while (retry++ < UNMOUNT_RETRY) {
+ _I("Kill app with SIGTERM.");
+ terminate_process(data->devnode, false);
+ usleep(500 * 1000);
+
+ if (!is_in_use_partition(data->devnode))
+ break;
+
+ _I("Kill app with SIGKILL.");
+ terminate_process(data->devnode, true);
+ usleep(500 * 1000);
+
+ if (!is_in_use_partition(data->devnode))
break;
- }
}
+ sync();
+
out:
data->state = BLOCK_UNMOUNT;
const char *fs_type, bool mount_point_updated)
{
const struct block_fs_ops *fs;
- dd_list *elem;
+ GList *elem;
const char *fstype;
int len;
int r;
} else
fstype = fs_type;
}
+ if (!strcmp(fstype, EXFAT_NAME))
+ fstype = VFAT_NAME;
fs = NULL;
len = strlen(fstype);
- DD_LIST_FOREACH(fs_head, elem, fs) {
+ SYS_G_LIST_FOREACH(fs_head, elem, fs) {
if (!strncmp(fs->name, fstype, len))
break;
}
- if (!fs) {
+ if (!fs || !fs->format) {
BLOCK_FLAG_SET(data, FS_NOT_SUPPORTED);
_E("Not supported file system(%s).", fstype);
return -ENOTSUP;
}
_I("Format path=%s", data->devnode);
- fs->check(data->devnode);
r = fs->format(data->devnode);
if (r < 0) {
_E("Failed to format block data for %s.", data->devnode);
// Called by BlockThread - Real Mount Op
static int block_mount_device(struct block_device *bdev, void *data)
{
- dd_list *l;
+ GList *l;
int ret;
int thread_id;
if (thread_id < 0 || thread_id >= THREAD_MAX)
return -EINVAL;
pthread_mutex_lock(&(th_manager[thread_id].mutex));
- l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
+ l = SYS_G_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
pthread_mutex_unlock(&(th_manager[thread_id].mutex));
if (!l) {
_E("'%s' does not exist in the device list.", bdev->data->devnode);
// Called by BlockThread - Real Format Op
static int block_format_device(struct block_device *bdev, void *data)
{
- dd_list *l;
+ GList *l;
int ret;
int thread_id;
struct format_data *fdata = (struct format_data *)data;
if (thread_id < 0 || thread_id >= THREAD_MAX)
return -EINVAL;
pthread_mutex_lock(&(th_manager[thread_id].mutex));
- l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
+ l = SYS_G_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
pthread_mutex_unlock(&(th_manager[thread_id].mutex));
if (!l) {
_E("'%s' does not exist in the device list.", bdev->data->devnode);
static void remove_operation(struct block_device *bdev)
{
struct operation_queue *op;
- dd_list *l, *next;
+ GList *l, *next;
int thread_id;
assert(bdev);
if (thread_id < 0 || thread_id >= THREAD_MAX)
return;
- DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
+ SYS_G_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
if (op->done) {
_D("Remove operation(%s, %s).",
get_operation_char(op->op),
bdev->data->devnode);
- DD_LIST_REMOVE(bdev->op_queue, op);
+ SYS_G_LIST_REMOVE(bdev->op_queue, op);
free(op);
}
}
}
// Called by BlockThread
-static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op)
+static void check_removed(struct block_device *bdev, GList **queue, struct operation_queue **op)
{
struct operation_queue *temp;
- dd_list *l;
+ GList *l;
int thread_id;
if (!bdev)
pthread_mutex_lock(&(th_manager[thread_id].mutex));
- DD_LIST_FOREACH(*queue, l, temp) {
+ SYS_G_LIST_FOREACH(*queue, l, temp) {
if (temp->op == BLOCK_DEV_REMOVE) {
*op = temp;
break;
}
// Called by BlockThread
-static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op)
+static bool check_unmount(struct block_device *bdev, GList **queue, struct operation_queue **op)
{
struct operation_queue *temp;
- dd_list *l;
+ GList *l;
int thread_id;
bool unmounted = false;
return false;
pthread_mutex_lock(&(th_manager[thread_id].mutex));
- DD_LIST_FOREACH(*queue, l, temp) {
+ SYS_G_LIST_FOREACH(*queue, l, temp) {
if (temp->op == BLOCK_DEV_UNMOUNT) {
unmounted = true;
_D("Operation queue has unmount operation.");
pthread_mutex_lock(&(th_manager[thread_id].mutex));
- DD_LIST_FOREACH(*queue, l, temp) {
+ SYS_G_LIST_FOREACH(*queue, l, temp) {
if (temp->op == BLOCK_DEV_UNMOUNT) {
*op = temp;
break;
}
// Called by BlockThread
-static void trigger_operation(struct block_device *bdev, dd_list *queue, struct operation_queue *op)
+static void trigger_operation(struct block_device *bdev, GList *queue, struct operation_queue *op)
{
- int ret = 0;
+ int ret_val = 0;
int thread_id;
char devnode[PATH_MAX];
enum block_dev_operation operation;
case BLOCK_DEV_INSERT:
break;
case BLOCK_DEV_MOUNT:
- ret = block_mount_device(bdev, op->data);
- _D("Mount '%s': %d", devnode, ret);
+ ret_val = block_mount_device(bdev, op->data);
+ _D("Mount '%s': %d", devnode, ret_val);
break;
case BLOCK_DEV_FORMAT:
- ret = block_format_device(bdev, op->data);
- _D("Format '%s': %d", devnode, ret);
+ ret_val = block_format_device(bdev, op->data);
+ _D("Format '%s': %d", devnode, ret_val);
break;
case BLOCK_DEV_UNMOUNT:
- ret = block_unmount_device(bdev, op->data);
- _D("Unmount '%s': %d", devnode, ret);
+ ret_val = block_unmount_device(bdev, op->data);
+ _D("Unmount '%s': %d", devnode, ret_val);
break;
case BLOCK_DEV_REMOVE:
/* Do nothing */
break;
case BLOCK_LUKS_CLOSE:
- ret = ode_luks_close_sync(EXTENDEDSD_NAME);
- if (ret < 0)
+#ifdef EXTENDED_STORAGE
+ ret_val = ode_luks_close_sync(EXTENDEDSD_NAME);
+ if (ret_val < 0)
_E("Failed on ode_luks_close(%s).", EXTENDEDSD_NAME);
+#endif
break;
default:
_E("Operation type(%d) is invalid.", op->op);
- ret = -EINVAL;
+ ret_val = -EINVAL;
break;
}
op->done = true;
th_manager[thread_id].op_len--;
- block_send_dbus_reply(op->invocation, ret);
+ block_send_dbus_reply(op->invocation, ret_val);
queue = bdev->op_queue;
if (queue != NULL) {
- queue = DD_LIST_NEXT(queue);
+ queue = SYS_G_LIST_NEXT(queue);
if (queue != NULL)
- op = DD_LIST_NTH(queue, 0);
+ op = SYS_G_LIST_NTH(queue, 0);
else
op = NULL;
} else
struct block_device *temp;
struct manage_thread *th = (struct manage_thread *)arg;
struct operation_queue *op = NULL;
- dd_list *elem;
- dd_list *queue = NULL;
+ GList *elem;
+ GList *queue = NULL;
int thread_id;
assert(th);
_D("Wake up thread=%d.", thread_id);
}
- DD_LIST_FOREACH(th_manager[thread_id].block_dev_list, elem, temp) {
+ SYS_G_LIST_FOREACH(th_manager[thread_id].block_dev_list, elem, temp) {
queue = temp->op_queue;
do {
- op = DD_LIST_NTH(queue, 0);
+ op = SYS_G_LIST_NTH(queue, 0);
if (!op) {
_D("Operation queue for device %s is Empty.", temp->data->devnode);
break;
}
if (op->done) {
- queue = DD_LIST_NEXT(queue);
+ queue = SYS_G_LIST_NEXT(queue);
continue;
}
break;
// Especially, we don't need to keep th_node_list.
static int find_thread(char *devnode)
{
- dd_list *elem;
+ GList *elem;
char str[PATH_MAX];
char *th_node;
char *temp;
min_num = 1000;
min = -1;
for (i = 0; i < THREAD_MAX; i++) {
- DD_LIST_FOREACH(th_manager[i].th_node_list, elem, temp) {
+ SYS_G_LIST_FOREACH(th_manager[i].th_node_list, elem, temp) {
if (!strncmp(temp, th_node, len)) {
free(th_node);
return i;
}
if (min >= 0 && min < THREAD_MAX) {
- DD_LIST_APPEND(th_manager[min].th_node_list, th_node);
+ SYS_G_LIST_APPEND(th_manager[min].th_node_list, th_node);
return min;
}
_E("Failed to find thread.");
- DD_LIST_APPEND(th_manager[0].th_node_list, th_node);
+ SYS_G_LIST_APPEND(th_manager[0].th_node_list, th_node);
return 0;
}
GDBusMethodInvocation *invocation, void *data)
{
struct operation_queue *op;
- int ret;
+ int ret_val;
int thread_id;
bool start_th;
op->done = false;
start_th = th_manager[thread_id].start_th;
- DD_LIST_APPEND(bdev->op_queue, op);
+ SYS_G_LIST_APPEND(bdev->op_queue, op);
th_manager[thread_id].op_len++;
if (th_manager[thread_id].op_len == 1 && start_th)
if (!start_th) {
_D("Start new thread for block device.");
th_manager[thread_id].start_th = true;
- ret = pthread_create(&(th_manager[thread_id].th), NULL, block_th_start, &th_manager[thread_id]);
- if (ret != 0) {
+ ret_val = pthread_create(&(th_manager[thread_id].th), NULL, block_th_start, &th_manager[thread_id]);
+ if (ret_val != 0) {
_E("Failed to create thread for %s.", bdev->data->devnode);
return -EPERM;
}
pthread_mutex_lock(&(th_manager[thread_id].mutex));
th_manager[thread_id].num_dev++;
- DD_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev);
+ SYS_G_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev);
pthread_mutex_unlock(&(th_manager[thread_id].mutex));
if (need_format) {
return 0;
}
- /* Create file for block device /run/external-storage/id */
- create_file(bdev->data->id, bdev->data->mount_point, bdev->data->block_type == BLOCK_EXTENDEDSD_DEV);
ret = add_operation(bdev, BLOCK_DEV_MOUNT, NULL, NULL);
if (ret < 0) {
_E("Failed to add operation(mount, %s).", devnode);
return -EPERM;
}
temp = mnt_fs_get_srcpath(fs);
- if (!temp)
+ if (!temp) {
+ mnt_free_table(t);
return -EPERM;
+ }
name = strrchr(temp, '/');
- if (!name)
+ if (!name) {
+ mnt_free_table(t);
return -EPERM;
+ }
name++;
+
/* Boot from USB is not handled */
if (!is_emulator()) {
if (!fnmatch(MMC_PATH, temp, 0))
{
struct block_device *bdev;
struct block_data *data;
- dd_list *elem;
+ GList *elem;
int i;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
data = bdev->data;
if (!data)
continue;
{
struct block_device *bdev;
struct block_data *data;
- dd_list *elem;
+ GList *elem;
int i;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
data = bdev->data;
if (!data)
continue;
static void remove_whole_block_device(void)
{
struct block_device *bdev;
- dd_list *elem;
- dd_list *next;
+ GList *elem;
+ GList *next;
int r;
int i;
for (i = 0; i < THREAD_MAX; i++) {
do {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) {
+ SYS_G_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) {
if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME)))
continue;
}
}
+static void add_poweroff_wait_cb(GVariant *var, void *user_data, GError *err)
+{
+ int ret_val = -ENOMSG;
+
+ if (!var)
+ return ;
+
+ if (!g_variant_get_safe(var, "(i)", &ret_val))
+ _E("Failed to get(%s): no message", g_variant_get_type_string(var));
+
+ if (ret_val >= 0)
+ add_poweroff_wait = true;
+
+ g_variant_unref(var);
+}
+
static void booting_done(void)
{
static int done = 0;
- int ret;
+ int ret_val;
if (done > 0)
return;
_I("Booting done.");
/* register mmc uevent control routine */
- ret = register_udev_uevent_control(&uh);
- if (ret < 0)
- _E("Failed to register block uevent: %d", ret);
+ ret_val = register_udev_uevent_control(&uh);
+ if (ret_val < 0)
+ _E("Failed to register block uevent: %d", ret_val);
block_control = true;
/* if there is the attached device, try to mount */
block_init_from_udev_enumerate();
+ ret_val = gdbus_call_async_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_POWEROFF,
+ DEVICED_INTERFACE_POWEROFF,
+ METHOD_ADD_POWEROFF_WAIT,
+ NULL,
+ add_poweroff_wait_cb,
+ -1, NULL);
+ if (ret_val < 0)
+ _E("Failed to call "METHOD_ADD_POWEROFF_WAIT" method.");
+
block_boot = true;
}
gpointer data)
{
static int status = 0;
+ int ret_dbus;
+
if (status > 0)
return;
status = 1;
/* unregister mmc uevent control routine */
unregister_udev_uevent_control(&uh);
remove_whole_block_device();
+ terminate_threads();
+
+ if (add_poweroff_wait) {
+ ret_dbus = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
+ DEVICED_PATH_POWEROFF,
+ DEVICED_INTERFACE_POWEROFF,
+ METHOD_REMOVE_POWEROFF_WAIT,
+ NULL, NULL);
+ if (ret_dbus < 0)
+ _E("Failed to call "METHOD_REMOVE_POWEROFF_WAIT" method.");
+ else
+ add_poweroff_wait = false;
+ }
}
static void uevent_block_handler(struct udev_device *dev)
if (onprivate) {
bdev->on_private_op = REQ_PRIVATE;
- bdev->private_pid = dbus_handle_get_sender_pid(NULL, sender);
+ bdev->private_pid = gdbus_connection_get_sender_pid(NULL, sender);
_D("Private operation state(%d). pid=%d.", bdev->on_private_op, bdev->private_pid);
- } else {
- if (bdev->on_private_op != REQ_NORMAL) {
- _E("Failed to process mount operation.");
- ret = -EPERM;
- goto out;
- }
}
/* if requester want to use a specific mount point */
ret = -EPERM;
goto out;
}
-
- /* Create /run/external-storage/id file */
- create_file(bdev->data->id, bdev->data->mount_point, false);
- } else {
- /* Create file for block device /run/external-storage/id */
- create_file(bdev->data->id, bdev->data->mount_point, false);
}
ret = add_operation(bdev, BLOCK_DEV_MOUNT, invocation, NULL);
}
if (onprivate) {
- pid = dbus_handle_get_sender_pid(NULL, sender);
+ pid = gdbus_connection_get_sender_pid(NULL, sender);
if (bdev->on_private_op == REQ_NORMAL || (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid)) {
_E("Failed to process private unmount operation pid=%d private_pid=%d.", pid, bdev->private_pid);
ret = -EPERM;
goto out;
}
- pid = dbus_handle_get_sender_pid(NULL, sender);
+ pid = gdbus_connection_get_sender_pid(NULL, sender);
if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
_E("Failed to format on private state.");
ret = -EPERM;
goto out;
}
- pid = dbus_handle_get_sender_pid(NULL, sender);
+ pid = gdbus_connection_get_sender_pid(NULL, sender);
if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
_E("Failed to format on private state.");
ret = -EPERM;
static GVariant *block_data_to_gvariant(struct block_data *data, int flags)
{
if (!data)
- return dbus_handle_new_g_variant_tuple();
+ return gdbus_new_g_variant_tuple();
return g_variant_new("(issssssisibii)",
data->block_type,
data->id);
}
-static GVariant *block_data_to_gvariant2(struct block_data *data, int flags)
-{
- if (!data)
- return dbus_handle_new_g_variant_tuple();
-
- return g_variant_new("(issssssisibi)",
- data->block_type,
- nullstr(data->devnode),
- nullstr(data->syspath),
- nullstr(data->fs_usage),
- nullstr(data->fs_type),
- nullstr(data->fs_version),
- nullstr(data->fs_uuid_enc),
- data->readonly,
- nullstr(data->mount_point),
- data->state,
- data->primary,
- flags >= 0 ? flags : data->flags);
-}
-
-
//static int add_device_to_struct_iter(struct block_data *data, DBusMessageIter *iter)
//{
// //DBusMessageIter piter;
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
show_block_device_list();
- return dbus_handle_new_g_variant_tuple();
+ return gdbus_new_g_variant_tuple();
}
static enum block_device_type get_bdev_type_from_type_string(const char *type_str)
GVariant *reply = NULL;
struct block_device *bdev;
struct block_data *data;
- dd_list *elem;
+ GList *elem;
char *type = NULL;
enum block_device_type block_type;
int i;
GVariantBuilder *builder = NULL;
+ const char *error = NULL;
g_variant_get(param, "(s)", &type);
- if (!type) {
- _E("Delivered type is NULL.");
- goto out;
- }
-
_D("Block (%s) device list is requested.", type);
block_type = get_bdev_type_from_type_string(type);
if (block_type == BLOCK_UNKNOWN_DEV) {
_E("Invalid type (%s) is requested.", type);
+ error = "Invalid type is requested";
goto out;
}
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
if (!bdev->data || bdev->removed)
continue;
}
pthread_mutex_unlock(&(th_manager[i].mutex));
}
+
reply = g_variant_new("(a(issssssisibii))", builder);
+
g_variant_builder_unref(builder);
out:
g_free(type);
+
if (!reply)
- reply = dbus_handle_new_g_variant_tuple();
+ g_dbus_method_invocation_return_error(invocation,
+ G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "%s", error);
return reply;
}
GVariant *reply = NULL;
struct block_device *bdev;
struct block_data *data;
- dd_list *elem;
+ GList *elem;
char *type = NULL;
enum block_device_type block_type;
int i;
GVariantBuilder *builder = NULL;
+ const char *error = NULL;
g_variant_get(param, "(s)", &type);
if (!type) {
_E("Delivered type is NULL.");
+ error = "Delivered type is NULL";
goto out;
}
block_type = get_bdev_type_from_type_string(type);
if (block_type == BLOCK_UNKNOWN_DEV) {
_E("Invalid type (%s) is requested.", type);
+ error = "Invalid type is requested";
goto out;
}
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
if (!bdev->data || bdev->removed)
continue;
}
pthread_mutex_unlock(&(th_manager[i].mutex));
}
+
reply = g_variant_new("(a(issssssisibi))", builder);
+
g_variant_builder_unref(builder);
out:
g_free(type);
+
+ if (!reply)
+ g_dbus_method_invocation_return_error(invocation,
+ G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "%s", error);
return reply;
}
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
struct block_device *bdev;
- struct block_data *data, nodata = {0,};
- dd_list *elem;
+ struct block_data *data = NULL, nodata = {0,};
+ GList *elem;
bool found = false;
int i;
for (i = 0; i < THREAD_MAX; i++) {
pthread_mutex_lock(&(th_manager[i].mutex));
- DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+ SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
data = bdev->data;
if (!data)
continue;
struct block_device *bdev;
struct block_data *data;
char *buf = NULL;
- int ret;
+ int ret_val;
int result = 0;
int id;
int fd;
result = -1;
goto out;
}
- ret = posix_memalign((void**)&buf, 4096, SPEEDCHECK_SIZE << 20);
- if (ret) {
+ ret_val = posix_memalign((void**)&buf, 4096, SPEEDCHECK_SIZE << 20);
+ if (ret_val) {
_E("Failed to posix_memalign().");
result = -1;
goto out_close;
clock_gettime(CLOCK_REALTIME, &start_time);
_I("Start time=%lu.%lu", start_time.tv_sec, start_time.tv_nsec);
- ret = read(fd, buf, SPEEDCHECK_SIZE << 20);
+ ret_val = read(fd, buf, SPEEDCHECK_SIZE << 20);
clock_gettime(CLOCK_REALTIME, &end_time);
_I("End time=%lu.%lu", end_time.tv_sec, end_time.tv_nsec);
free(buf);
- if (ret < 0) {
+ if (ret_val < 0) {
_E("Failed to read(): %d", errno);
result = -1;
goto out_close;
#ifdef BLOCK_TMPFS
static int mount_root_path_tmpfs(void)
{
- int ret;
+ int ret_val;
const char *root;
root = tzplatform_getenv(TZ_SYS_MEDIA);
if (mount_check(root))
return 0;
- ret = mount("tmpfs", root, "tmpfs", 0, "smackfsroot=System::Shared");
- if (ret < 0) {
- ret = -errno;
- _E("Failed to mount tmpfs: %d", ret);
- return ret;
+ ret_val = mount("tmpfs", root, "tmpfs", 0, "smackfsroot=System::Shared");
+ if (ret_val < 0) {
+ ret_val = -errno;
+ _E("Failed to mount tmpfs: %d", ret_val);
+ return ret_val;
}
return 0;
static void block_init(void *data)
{
- int ret;
+ int ret_val;
int i;
udev_init(NULL);
/* load config */
- ret = config_parse(BLOCK_CONF_FILE, load_config, NULL);
- if (ret < 0)
+ ret_val = config_parse(BLOCK_CONF_FILE, load_config, NULL);
+ if (ret_val < 0)
_E("Failed to load '%s'. Use default value.", BLOCK_CONF_FILE);
- ret = mount_root_path_tmpfs();
- if (ret < 0)
- _E("Failed to mount tmpfs to root mount path: %d", ret);
+ ret_val = mount_root_path_tmpfs();
+ if (ret_val < 0)
+ _E("Failed to mount tmpfs to root mount path: %d", ret_val);
/* register block manager object and interface */
- ret = dbus_handle_register_dbus_object(NULL, STORAGED_PATH_BLOCK_MANAGER, &block_interface);
- if (ret < 0)
- _E("Failed to register block interface and methods: %d", ret);
+ ret_val = gdbus_register_object(NULL, STORAGED_PATH_BLOCK_MANAGER, &block_interface);
+ if (ret_val < 0)
+ _E("Failed to register block interface and methods: %d", ret_val);
/* init pipe */
- ret = pipe_init();
- if (ret < 0)
+ ret_val = pipe_init();
+ if (ret_val < 0)
_E("Failed to init pipe.");
for (i = 0; i < THREAD_MAX; i++) {
pthread_cond_init(&(th_manager[i].cond), NULL);
}
- ret = remove_directory(EXTERNAL_STORAGE_PATH);
- if (ret < 0)
+ ret_val = remove_directory(EXTERNAL_STORAGE_PATH);
+ if (ret_val < 0)
_E("Failed to remove directory.");
- ret = mkdir(EXTERNAL_STORAGE_PATH, 0755);
- if (ret < 0)
+ ret_val = mkdir(EXTERNAL_STORAGE_PATH, 0755);
+ if (ret_val < 0)
_E("Failed to make directory: %d", errno);
- ret = remove_directory(EXTENDED_INTERNAL_PATH);
- if (ret < 0)
+ ret_val = remove_directory(EXTENDED_INTERNAL_PATH);
+ if (ret_val < 0)
_E("Failed to remove directory.");
- ret = mkdir(EXTENDED_INTERNAL_PATH, 0755);
- if (ret < 0)
+ ret_val = mkdir(EXTENDED_INTERNAL_PATH, 0755);
+ if (ret_val < 0)
_E("Failed to make directory: %d", errno);
- ret = get_internal_storage_number();
- if (ret < 0)
+ ret_val = get_internal_storage_number();
+ if (ret_val < 0)
_E("Failed to get internal storage number.");
- id_block_poweroff = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF,
+ id_block_poweroff = gdbus_signal_subscribe(NULL, DEVICED_PATH_POWEROFF,
DEVICED_INTERFACE_POWEROFF,
SIGNAL_POWEROFF_STATE,
block_poweroff, NULL, NULL);
}
static void terminate_threads(void)
{
- dd_list *elem, *elem_next;
+ GList *elem, *elem_next;
char *temp;
int i, count;
const int WAIT_TIME = 10;
pthread_cancel(th_manager[i].th);
pthread_join(th_manager[i].th, NULL);
}
- DD_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) {
- DD_LIST_REMOVE(th_manager[i].th_node_list, temp);
+ SYS_G_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) {
+ SYS_G_LIST_REMOVE(th_manager[i].th_node_list, temp);
free(temp);
}
}
static void block_exit(void *data)
{
- int ret;
+ int ret_val;
udev_exit(NULL);
/* unregister notifier for below each event */
- unsubscribe_dbus_signal(NULL, id_block_poweroff);
+ gdbus_signal_unsubscribe(NULL, id_block_poweroff);
/* unregister mmc uevent control routine */
- ret = unregister_udev_uevent_control(&uh);
- if (ret < 0)
- _E("Failed to unregister block uevent: %d", ret);
+ ret_val = unregister_udev_uevent_control(&uh);
+ if (ret_val < 0)
+ _E("Failed to unregister block uevent: %d", ret_val);
/* remove remaining blocks */
remove_whole_block_device();
/* exit pipe */
pipe_exit();
+ if (add_poweroff_wait) {
+ ret_val = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
+ DEVICED_PATH_POWEROFF,
+ DEVICED_INTERFACE_POWEROFF,
+ METHOD_REMOVE_POWEROFF_WAIT,
+ NULL, NULL);
+ if (ret_val < 0)
+ _E("Failed to call "METHOD_REMOVE_POWEROFF_WAIT" method.");
+ else
+ add_poweroff_wait = false;
+ }
+
block_control = false;
}