return request_unmount_block(conn, sender, path, iface, name, param, invocation, user_data, true);
}
-static GVariant *request_format_block(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+static int process_request_format_block(const gchar *sender, GDBusMethodInvocation *invocation,
+ struct block_device *bdev, int option, const char *type)
{
- struct block_device *bdev;
struct format_data *fdata;
pid_t pid;
- int id;
- int option;
- int ret = -EBADMSG;
int prev_state;
-
- if (!block_control) {
- _D("Block module is disabled.");
- ret = -EPERM;
- goto out;
- }
-
- 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;
- }
-
- 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;
- }
+ int ret = -EBADMSG;
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;
+ return -EPERM;
}
- fdata = get_format_data(NULL, option);
+ fdata = get_format_data(type, option);
if (!fdata) {
_E("Failed to get format data.");
- goto out;
+ return ret;
}
prev_state = bdev->data->state;
if (ret < 0) {
_E("Failed to add operation(unmount, %s).", bdev->data->devnode);
release_format_data(fdata);
- goto out;
+ return ret;
}
}
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);
- goto out;
+ return ret;
}
}
+ return 0;
+}
+
+static GVariant *request_format_block(GDBusConnection *conn,
+ const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+ GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ struct block_device *bdev;
+ int id;
+ int option;
+ int ret = -EBADMSG;
+
+ if (!block_control) {
+ _D("Block module is disabled.");
+ ret = -EPERM;
+ goto out;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ ret = process_request_format_block(sender, invocation, bdev, option, NULL);
+ if (ret < 0) {
+ goto out;
+ }
+
return NULL;
out:
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
struct block_device *bdev;
- struct format_data *fdata;
char *type = NULL;
- pid_t pid;
int id;
int option;
int ret = -EBADMSG;
- int prev_state;
if (!block_control) {
_D("Block module is disabled.");
goto out;
}
- 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;
- }
-
- fdata = get_format_data(type, option);
- if (!fdata) {
- _E("Failed to get format data.");
- goto out;
- }
-
- prev_state = bdev->data->state;
- if (prev_state == BLOCK_MOUNT) {
- if (bdev->on_private_op == REQ_PRIVATE) {
- bdev->on_private_op = REQ_PRIVATE_FORMAT;
- _D("Private operation state(%d).", bdev->on_private_op);
- }
- ret = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE);
- if (ret < 0) {
- _E("Failed to add operation(unmount, %s).", bdev->data->devnode);
- release_format_data(fdata);
- goto out;
- }
- }
-
- ret = add_operation(bdev, BLOCK_DEV_FORMAT, invocation, (void *)fdata);
+ ret = process_request_format_block(sender, invocation, bdev, option, type);
if (ret < 0) {
- _E("Failed to add operation(format, %s).", bdev->data->devnode);
- release_format_data(fdata);
- }
-
- /* Maintain previous state of mount/unmount */
- 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);
- goto out;
- }
+ goto out;
}
g_free(type);