return request_unmount_block(conn, sender, path, iface, name, param, invocation, user_data, true);
}
-static int process_request_format_block(const gchar *sender, GDBusMethodInvocation *invocation,
+static GVariant *process_request_format_block(const gchar *sender, GDBusMethodInvocation *invocation,
struct block_device *bdev, int option, const char *type)
{
struct format_data *fdata;
pid_t pid;
int prev_state;
- int ret = -EBADMSG;
+ int ret;
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.");
- return -EPERM;
+ return g_variant_new("(i)", -EPERM);
}
fdata = get_format_data(type, option);
if (!fdata) {
_E("Failed to get format data.");
- return ret;
+ return g_variant_new("(i)", -EBADMSG);
}
prev_state = bdev->data->state;
+ /* unmount if mounted */
if (prev_state == BLOCK_MOUNT) {
if (bdev->on_private_op == REQ_PRIVATE) {
bdev->on_private_op = REQ_PRIVATE_FORMAT;
if (ret < 0) {
_E("Failed to add operation(unmount, %s).", bdev->data->devnode);
release_format_data(fdata);
- return ret;
+ return g_variant_new("(i)", ret);
}
}
+ /* do format */
ret = add_operation(bdev, BLOCK_DEV_FORMAT, invocation, (void *)fdata);
if (ret < 0) {
_E("Failed to add operation(format, %s).", bdev->data->devnode);
if (prev_state == BLOCK_MOUNT) {
if (add_operation(bdev, BLOCK_DEV_MOUNT, NULL, NULL) < 0) {
_E("Failed to add operation(mount, %s).", bdev->data->devnode);
- return ret;
+ /* mount was failed, but returns ret */
+ return g_variant_new("(i)", ret);
}
}
- return 0;
+ /* everything was successful */
+ return NULL;
}
static GVariant *request_format_block(GDBusConnection *conn,
struct block_device *bdev;
int id;
int option;
- int ret = -EBADMSG;
if (!block_control) {
_D("Block module is disabled.");
- ret = -EPERM;
- goto out;
+ return g_variant_new("(i)", -EPERM);
}
g_variant_get(param, "(ii)", &id, &option);
bdev = find_block_device_by_id(id);
if (!bdev) {
_E("Failed to find (%d) in the device list.", id);
- goto out;
+ return g_variant_new("(i)", -EBADMSG);
}
if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
_D("Format dbus request for extended internal storage is blocked.");
- ret = -EPERM;
- goto out;
+ return g_variant_new("(i)", -EPERM);
}
- ret = process_request_format_block(sender, invocation, bdev, option, NULL);
- if (ret < 0) {
- goto out;
- }
-
- return NULL;
-
-out:
- return g_variant_new("(i)", ret);
+ return process_request_format_block(sender, invocation, bdev, option, NULL);
}
static GVariant *request_format_block_type(GDBusConnection *conn,
char *type = NULL;
int id;
int option;
- int ret = -EBADMSG;
+ GVariant *ret = NULL;
if (!block_control) {
_D("Block module is disabled.");
- ret = -EPERM;
- goto out;
+ return g_variant_new("(i)", -EPERM);
}
g_variant_get(param, "(iis)", &id, &option, &type);
bdev = find_block_device_by_id(id);
if (!bdev) {
_E("Failed to find (%d) in the device list.", id);
- goto out;
+ g_free(type);
+ return g_variant_new("(i)", -EBADMSG);
}
/* FormatwithType dbus call is needed when app proceeds extended internal -> portable storage */
if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV) {
_D("FormatwithType dbus request for extended internal storage is blocked.");
- ret = -EPERM;
- goto out;
+ g_free(type);
+ return g_variant_new("(i)", -EPERM);
}
ret = process_request_format_block(sender, invocation, bdev, option, type);
- if (ret < 0) {
- goto out;
- }
g_free(type);
- return NULL;
-
-out:
- g_free(type);
- return g_variant_new("(i)", ret);
+ return ret;
}
static GVariant *block_data_to_gvariant(struct block_data *data, int flags)