#include <glib/gstdio.h>
#include <gio/gio.h>
#include <libsyscommon/dbus-system.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"
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;
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);
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;
{
struct block_fs_ops *fs;
blkid_probe probe;
- dd_list *elem;
+ GList *elem;
const char *filesystem = NULL;
char *temp;
char str[PATH_MAX];
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)
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;
}
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;
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;
}
// 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 thread_id;
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;
}
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)
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) {
{
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;
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;
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;
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;
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;
{
struct block_device *bdev;
struct block_data *data = NULL, nodata = {0,};
- dd_list *elem;
+ 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;
}
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);
}
}