block: When block is disabled, extended internal storage should not be unmounted 82/162182/3
authorpr.jung <pr.jung@samsung.com>
Wed, 29 Nov 2017 11:03:38 +0000 (20:03 +0900)
committerpr.jung <pr.jung@samsung.com>
Thu, 30 Nov 2017 07:12:02 +0000 (16:12 +0900)
- When block control is off,
storaged doesn't deal with mount, format, and unmount operation
storaged doesn't unmount extended internal storage
storaged only handles uevents for extended internal storage
- Mount and Foramt dbus methods for extended internal storage are blocked
- Unmount dbus method for device node is blocked
- FormatwithType dbus method for mapper node is blocked

Change-Id: I723acb5601ad6fd6f53da1dce3f408108f2e676a
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/block/block.c

index 658cf8f..25cb70c 100644 (file)
@@ -2179,6 +2179,15 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m
                return -EPERM;
        }
 
+       if (!block_control) {
+               if (!mapper && strncmp(data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+                       _D("Block module is disabled");
+                       free_block_data(data);
+                       return -EPERM;
+               }
+
+       }
+
        bdev = make_block_device(data);
        if (!bdev) {
                _E("fail to make block device for %s", devnode);
@@ -2608,6 +2617,9 @@ static void remove_whole_block_device(void)
                do {
                        pthread_mutex_lock(&(th_manager[i].mutex));
                        DD_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;
                                if (bdev->removed == false)
                                        break;
                        }
@@ -2646,10 +2658,10 @@ static void booting_done(const char *sender_name,
        if (ret < 0)
                _E("fail to register block uevent : %d", ret);
 
+       block_control = true;
        /* if there is the attached device, try to mount */
        block_init_from_udev_enumerate();
 
-       block_control = true;
        block_boot = true;
 }
 
@@ -2751,6 +2763,12 @@ static DBusMessage *request_mount_block(dbus_method_reply_handle_h reply_handle,
        int id;
        int ret = -EBADMSG;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2767,6 +2785,14 @@ static DBusMessage *request_mount_block(dbus_method_reply_handle_h reply_handle,
                ret = -ENOENT;
                goto out;
        }
+
+       if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
+           !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+               _D("Mount dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (bdev->on_private_op != REQ_NORMAL) {
                ret = -EPERM;
                goto out;
@@ -2838,6 +2864,12 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl
        int id;
        int ret = -EBADMSG;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2855,6 +2887,13 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl
                goto out;
        }
 
+       /* Unmount dbus call is needed when app proceeds extended internal -> portable storage */
+       if (!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+               _D("Unmount dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (onprivate) {
                pid = get_dbus_method_sender_pid(reply_handle);
                if (bdev->on_private_op == REQ_NORMAL || (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid)) {
@@ -2911,6 +2950,12 @@ static DBusMessage *request_format_block(dbus_method_reply_handle_h reply_handle
        int ret = -EBADMSG;
        int prev_state;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2927,6 +2972,13 @@ static DBusMessage *request_format_block(dbus_method_reply_handle_h reply_handle
                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;
+       }
+
        pid = get_dbus_method_sender_pid(reply_handle);
        if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
                _E("Failed to format on private state");
@@ -2986,6 +3038,12 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h
        int ret = -EBADMSG;
        int prev_state;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -3003,6 +3061,13 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h
                goto out;
        }
 
+       /* 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;
+       }
+
        pid = get_dbus_method_sender_pid(reply_handle);
        if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
                _E("Failed to format on private state");
@@ -3746,8 +3811,6 @@ static void block_exit(void *data)
 
 static int block_start(void *data)
 {
-       int ret;
-
        if (!block_boot) {
                _E("Cannot be started. Booting is not ready");
                return -ENODEV;
@@ -3758,15 +3821,10 @@ static int block_start(void *data)
                return 0;
        }
 
-       /* register mmc uevent control routine */
-       ret = register_udev_uevent_control(&uh);
-       if (ret < 0)
-               _E("fail to register block uevent : %d", ret);
+       block_control = true;
 
        block_init_from_udev_enumerate();
 
-       block_control = true;
-
        _I("start");
        return 0;
 }
@@ -3783,9 +3841,6 @@ static int block_stop(void *data)
                return 0;
        }
 
-       /* unregister mmc uevent control routine */
-       unregister_udev_uevent_control(&uh);
-
        /* remove the existing blocks */
        remove_whole_block_device();