show_block_device_list();
return dbus_handle_new_g_variant_tuple();
}
+
+static enum block_device_type get_bdev_type_from_type_string(const char *type_str)
+{
+ if (!type_str)
+ return BLOCK_UNKNOWN_DEV;
+
+ if (strcmp(type_str, BLOCK_TYPE_SCSI) == 0)
+ return BLOCK_SCSI_DEV;
+ if (strcmp(type_str, BLOCK_TYPE_MMC) == 0)
+ return BLOCK_MMC_DEV;
+ if (strcmp(type_str, BLOCK_TYPE_ALL) == 0)
+ return BLOCK_ALL_DEV;
+
+ return BLOCK_UNKNOWN_DEV;
+}
+
// Called by MainThread
static GVariant *request_get_device_list(GDBusConnection *conn,
const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
struct block_data *data;
dd_list *elem;
char *type = NULL;
- int block_type;
+ enum block_device_type block_type;
int i;
int item_cnt = 0;
GVariantBuilder *builder = NULL;
_D("Block (%s) device list is requested.", type);
- if (!strncmp(type, BLOCK_TYPE_SCSI, sizeof(BLOCK_TYPE_SCSI)))
- block_type = BLOCK_SCSI_DEV;
- else if (!strncmp(type, BLOCK_TYPE_MMC, sizeof(BLOCK_TYPE_MMC)))
- block_type = BLOCK_MMC_DEV;
- else if (!strncmp(type, BLOCK_TYPE_ALL, sizeof(BLOCK_TYPE_ALL)))
- block_type = -1;
- else {
+ 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) {
- data = bdev->data;
- if (!data)
- continue;
- if (bdev->removed)
+ if (!bdev->data || bdev->removed)
continue;
- switch (block_type) {
- case BLOCK_SCSI_DEV:
- case BLOCK_MMC_DEV:
+ data = bdev->data;
+
+ if (block_type != BLOCK_ALL_DEV) {
if (data->block_type != block_type)
continue;
- break;
- default:
- break;
}
g_variant_builder_add(builder, "(issssssisibii)",
struct block_data *data;
dd_list *elem;
char *type = NULL;
- int block_type;
+ enum block_device_type block_type;
int i;
int item_cnt;
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";
_D("Block (%s) device list is requested.", type);
- if (!strncmp(type, BLOCK_TYPE_SCSI, sizeof(BLOCK_TYPE_SCSI)))
- block_type = BLOCK_SCSI_DEV;
- else if (!strncmp(type, BLOCK_TYPE_MMC, sizeof(BLOCK_TYPE_MMC)))
- block_type = BLOCK_MMC_DEV;
- else if (!strncmp(type, BLOCK_TYPE_ALL, sizeof(BLOCK_TYPE_ALL)))
- block_type = -1;
- else {
+ 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) {
- data = bdev->data;
- if (!data)
- continue;
- if (bdev->removed)
+ if (!bdev->data || bdev->removed)
continue;
- switch (block_type) {
- case BLOCK_SCSI_DEV:
- case BLOCK_MMC_DEV:
+ data = bdev->data;
+
+ if (block_type != BLOCK_ALL_DEV) {
if (data->block_type != block_type)
continue;
- break;
- default:
- break;
}
g_variant_builder_add(builder, "(issssssisibi)",