From c2ea6ef05797aaf0181c45ed5bcf03741ce76194 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 30 Oct 2017 11:50:05 +0900 Subject: [PATCH 01/16] Support reformatting from internal to external storage Change-Id: Idcf3befbd50de35899545cddf142865cee547cb9 Signed-off-by: Hyotaek Shim --- src/block/block.c | 74 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 0971a5b..e371b6d 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -65,8 +65,6 @@ #define SCSI_PARTITION_LENGTH 9 #define EXTENDEDSD_NODE_PATH "/dev/mapper/extendedsd" -#define FILESYSTEM "filesystem" - #define DEV_PREFIX "/dev/" #define ROOT_DIR "/" @@ -100,6 +98,7 @@ #define EXT4_NAME "ext4" #define LUKS_NAME "crypto_LUKS" #define EXTENDEDSD_NAME "extendedsd" +#define FILESYSTEM_NAME "filesystem" /* Minimum value of block id */ #define BLOCK_ID_MIN 10 @@ -549,7 +548,7 @@ static char *generate_mount_path(struct block_data *data) char *name, node[64]; int ret; - if (!data || !data->devnode || !data->fs_usage || strcmp(data->fs_usage, FILESYSTEM)) + if (!data || !data->devnode || !data->fs_usage || strcmp(data->fs_usage, FILESYSTEM_NAME)) return NULL; name = strrchr(data->devnode, '/'); @@ -711,7 +710,7 @@ static struct block_data *make_block_data(const char *devnode, /* for 2.4 backward compatibility */ // What if storage id 1 is existed? (multi sdcard case) if (data->primary == true && data->block_type == BLOCK_MMC_DEV && - data->fs_usage && !strcmp(data->fs_usage, FILESYSTEM)) + data->fs_usage && !strcmp(data->fs_usage, FILESYSTEM_NAME)) data->id = EXT_PRIMARY_SD_FIXID; else data->id = block_get_new_id(); @@ -869,7 +868,7 @@ static struct block_device *find_block_device_path(const char *mount_point) pthread_mutex_lock(&(th_manager[i].mutex)); DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { if (bdev->data && !bdev->removed && - !strncmp(bdev->data->mount_point, mount_point, len)) { + (bdev->data->mount_point != NULL && !strncmp(bdev->data->mount_point, mount_point, len))) { pthread_mutex_unlock(&(th_manager[i].mutex)); return bdev; } @@ -1169,8 +1168,8 @@ static int block_mount(struct block_data *data) /* check matched file system */ if (!data->fs_usage || - strncmp(data->fs_usage, FILESYSTEM, - sizeof(FILESYSTEM)) != 0) { + strncmp(data->fs_usage, FILESYSTEM_NAME, + sizeof(FILESYSTEM_NAME)) != 0) { r = -ENODEV; goto out; } @@ -2115,7 +2114,7 @@ static bool check_partition(struct udev_device *dev) fs_usage = udev_device_get_property_value(dev, "ID_FS_USAGE"); if (fs_usage && - strncmp(fs_usage, FILESYSTEM, sizeof(FILESYSTEM)) == 0) { + strncmp(fs_usage, FILESYSTEM_NAME, sizeof(FILESYSTEM_NAME)) == 0) { if (!disk_is_partitioned_by_kernel(dev)) goto out; } @@ -2157,11 +2156,11 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m r = rindex(udev_device_get_syspath(dev), '/'); if (!r) return -ENODEV; - sprintf(syspath, "/sys/block%s", r); + snprintf(syspath, sizeof(syspath), "/sys/block%s", r); data = make_block_data(devnode, syspath, - FILESYSTEM, + FILESYSTEM_NAME, EXT4_NAME, "1.0", udev_device_get_property_value(dev, "ID_FS_UUID_ENC"), @@ -2183,7 +2182,7 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m } if (!block_conf[data->block_type].multimount && !data->primary && - data->fs_usage && !strcmp(data->fs_usage, FILESYSTEM)) { + data->fs_usage && !strcmp(data->fs_usage, FILESYSTEM_NAME)) { _D("Not support multi mount by config info"); free_block_data(data); return -EPERM; @@ -2265,7 +2264,7 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m } // Not a regular filesystem -> skip mounting - if (!bdev->data->fs_usage || strcmp(bdev->data->fs_usage, FILESYSTEM)) { + if (!bdev->data->fs_usage || strcmp(bdev->data->fs_usage, FILESYSTEM_NAME)) { _I("Not a filesystem. Not mounting"); return 0; } @@ -3006,6 +3005,7 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h goto out; bdev = find_block_device_by_id(id); + if (!bdev) { _E("Failed to find (%d) in the device list", id); goto out; @@ -3025,11 +3025,59 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h } prev_state = bdev->data->state; - if (prev_state == BLOCK_MOUNT) { + + if (bdev->data->fs_type != NULL && !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) { + struct block_device *bdev_extended; + bdev_extended = find_block_device_path(EXTENDEDSD_MOUNT_PATH); + if (bdev_extended) { + const char *devnode_extended = bdev_extended->data->devnode; + BLOCK_FLAG_SET(bdev_extended->data, UNMOUNT_UNSAFE); + bdev_extended->removed = true; + + if (bdev_extended->on_private_op != REQ_NORMAL) { + bdev_extended->on_private_op = REQ_NORMAL; + _D("Private operation state: %d", bdev_extended->on_private_op); + } + + ret = add_operation(bdev_extended, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE); + if (ret < 0) { + _E("Failed to add operation (unmount %s)", devnode_extended); + goto out; + } + + ret = add_operation(bdev_extended, BLOCK_DEV_REMOVE, NULL, NULL); + if (ret < 0) { + _E("Failed to add operation (remove %s)", devnode_extended); + goto out; + } + + ret = add_operation(bdev_extended, BLOCK_LUKS_CLOSE, NULL, NULL); + if (ret < 0) { + _E("Failed to add operation (luks_close %s)", devnode_extended); + goto out; + } + + //FIXME + sleep(3); + } + + ret = update_block_data(bdev->data, + FILESYSTEM_NAME, + type, + "1.0", + NULL, + 0, + false); + if (ret < 0) + _E("Fail to update block data for %s", bdev->data->devnode); + + prev_state = BLOCK_MOUNT; + } else 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); -- 2.7.4 From 99b57348e01cbcdf929eab433b1f6d365516e3c1 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 30 Oct 2017 16:32:30 +0900 Subject: [PATCH 02/16] Handle exceptional cases in request_check_speed() to avoid divide-by-zero Change-Id: I9ff67572cbe5b866aff2e1f49220c60271aa81b9 Signed-off-by: Hyotaek Shim --- src/block/block.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index e371b6d..1c22a56 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3452,6 +3452,7 @@ static DBusMessage *request_check_speed(dbus_method_reply_handle_h reply_handle, int ret = 0; int id; int fd; + int time_diff; if (!reply_handle || !msg) return NULL; @@ -3477,7 +3478,7 @@ static DBusMessage *request_check_speed(dbus_method_reply_handle_h reply_handle, _D("speed check: %s", data->devnode); fd = open(data->devnode, O_RDWR | O_SYNC); - buf = calloc(1, SPEEDCHECK * 1024 * 1024); + buf = calloc(1, SPEEDCHECK << 20); if (!buf) { _E("calloc() failed"); close(fd); @@ -3486,13 +3487,14 @@ static DBusMessage *request_check_speed(dbus_method_reply_handle_h reply_handle, } clock_gettime(CLOCK_REALTIME, &start_time); _I("start time: %lu.%lu", start_time.tv_sec, start_time.tv_nsec); - ret = write(fd, buf, SPEEDCHECK * 1024 * 1024); + ret = write(fd, buf, SPEEDCHECK << 20); clock_gettime(CLOCK_REALTIME, &end_time); _I("end time %lu.%lu", end_time.tv_sec, end_time.tv_nsec); free(buf); - if (SPEEDCHECK / (end_time.tv_sec - start_time.tv_sec) < 4) { + time_diff = end_time.tv_sec - start_time.tv_sec; + if (time_diff > 0 && (SPEEDCHECK / time_diff < 4)) { ret = -1; close(fd); goto out; -- 2.7.4 From d5e2689744abf0235fe49b8d57e4fa8227100724 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 30 Oct 2017 17:01:49 +0900 Subject: [PATCH 03/16] Check if ode_luke_close is done by using access(EXTENDEDSD_NODE_PATH, F_OK) Change-Id: If135e1e74f478ea8ba2d2e154c5a823f03b5be98 Signed-off-by: Hyotaek Shim --- src/block/block.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 1c22a56..89b553a 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3030,6 +3030,7 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h struct block_device *bdev_extended; bdev_extended = find_block_device_path(EXTENDEDSD_MOUNT_PATH); if (bdev_extended) { + int wait; const char *devnode_extended = bdev_extended->data->devnode; BLOCK_FLAG_SET(bdev_extended->data, UNMOUNT_UNSAFE); bdev_extended->removed = true; @@ -3057,8 +3058,12 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h goto out; } - //FIXME - sleep(3); + for (wait = 0; wait < 5; wait++) { + if (!access(EXTENDEDSD_NODE_PATH, F_OK)) + sleep(1); + else + break; + } } ret = update_block_data(bdev->data, -- 2.7.4 From 901aa8553f31b6f4d278b8d659450fb36cf84be5 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 30 Oct 2017 18:07:14 +0900 Subject: [PATCH 04/16] Avoid crash on storaged UI Change-Id: Ib198495d8e69238fb526f772a9aea835634490c3 Signed-off-by: Hyotaek Shim --- apps/extended-sd/src/es-internal-storage-page.c | 1 + src/block/block.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/extended-sd/src/es-internal-storage-page.c b/apps/extended-sd/src/es-internal-storage-page.c index 9047ce7..65ab94c 100644 --- a/apps/extended-sd/src/es-internal-storage-page.c +++ b/apps/extended-sd/src/es-internal-storage-page.c @@ -67,6 +67,7 @@ mapper_device_cb(int id, storage_dev_e dev, storage_state_e state, if (state == STORAGE_STATE_REMOVED) { DMSG("Storage is removed"); ui_app_exit(); + return; } else if (state == STORAGE_STATE_UNMOUNTABLE) return; diff --git a/src/block/block.c b/src/block/block.c index 89b553a..1bfcc19 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3058,12 +3058,15 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h goto out; } - for (wait = 0; wait < 5; wait++) { + for (wait = 0; wait < 10; wait++) { if (!access(EXTENDEDSD_NODE_PATH, F_OK)) sleep(1); else break; } + + if (wait == 10) + _E("Timeout for checking access(EXTENDEDSD_NODE_PATH, F_OK)"); } ret = update_block_data(bdev->data, -- 2.7.4 From 911218ca02b1f21d726c5c9cdf9cfecc4155eb0e Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 31 Oct 2017 13:58:44 +0900 Subject: [PATCH 05/16] app: Launch setting app when "Move apps now" and "Set Default storage" button touched Change-Id: Id9596a1dcdeb681866bc7d5a45aa7a2884a8ec7c Signed-off-by: pr.jung --- apps/extended-sd/include/extended-sd-main.h | 3 ++ apps/extended-sd/src/es-internal-storage-page.c | 40 +++++++++++++++++++++++++ apps/extended-sd/src/es-portable-storage-page.c | 20 +++++++++++++ 3 files changed, 63 insertions(+) diff --git a/apps/extended-sd/include/extended-sd-main.h b/apps/extended-sd/include/extended-sd-main.h index 3cdbd2b..ba6cc2a 100644 --- a/apps/extended-sd/include/extended-sd-main.h +++ b/apps/extended-sd/include/extended-sd-main.h @@ -20,8 +20,11 @@ #define UNMOUNT_FORCE 1 #define MYFILES_APP_ID "org.tizen.myfile" +#define SETTING_APP_ID "org.tizen.setting-storage" #define SECURITY_APP_ID "org.tizen.ode" #define ENCRYPT_EXTENSION "ENCRYPT_EXTENSION" +#define APPSELECT "appselect" +#define DEFAULT_STORAGE "defstorage" typedef enum { USE_AS_PORTABLE_STORAGE = 0, diff --git a/apps/extended-sd/src/es-internal-storage-page.c b/apps/extended-sd/src/es-internal-storage-page.c index 65ab94c..b9635f2 100644 --- a/apps/extended-sd/src/es-internal-storage-page.c +++ b/apps/extended-sd/src/es-internal-storage-page.c @@ -238,6 +238,26 @@ _move_apps_button_click_cb(void *data, Evas_Object* obj, void *event_info) { FUNC_BEGIN(); + app_control_h app_control = NULL; + int ret; + + ret = app_control_create(&app_control); + if (ret != APP_CONTROL_ERROR_NONE) + return; + + ret = app_control_set_app_id(app_control, SETTING_APP_ID); + if (ret != APP_CONTROL_ERROR_NONE) { + app_control_destroy(app_control); + return; + } + + app_control_add_extra_data(app_control, VIEWTYPE_KEY, APPSELECT); + ret = app_control_send_launch_request(app_control, NULL, NULL); + if (ret != APP_CONTROL_ERROR_NONE) + DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret); + + app_control_destroy(app_control); + FUNC_END(); } @@ -246,6 +266,26 @@ _set_default_button_click_cb(void *data, Evas_Object* obj, void *event_info) { FUNC_BEGIN(); + app_control_h app_control = NULL; + int ret; + + ret = app_control_create(&app_control); + if (ret != APP_CONTROL_ERROR_NONE) + return; + + ret = app_control_set_app_id(app_control, SETTING_APP_ID); + if (ret != APP_CONTROL_ERROR_NONE) { + app_control_destroy(app_control); + return; + } + + app_control_add_extra_data(app_control, VIEWTYPE_KEY, DEFAULT_STORAGE); + ret = app_control_send_launch_request(app_control, NULL, NULL); + if (ret != APP_CONTROL_ERROR_NONE) + DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret); + + app_control_destroy(app_control); + FUNC_END(); } diff --git a/apps/extended-sd/src/es-portable-storage-page.c b/apps/extended-sd/src/es-portable-storage-page.c index 0947fca..97981e1 100644 --- a/apps/extended-sd/src/es-portable-storage-page.c +++ b/apps/extended-sd/src/es-portable-storage-page.c @@ -141,6 +141,26 @@ _set_default_button_click_cb(void *data, Evas_Object* obj, void *event_info) { FUNC_BEGIN(); + app_control_h app_control = NULL; + int ret; + + ret = app_control_create(&app_control); + if (ret != APP_CONTROL_ERROR_NONE) + return; + + ret = app_control_set_app_id(app_control, SETTING_APP_ID); + if (ret != APP_CONTROL_ERROR_NONE) { + app_control_destroy(app_control); + return; + } + + app_control_add_extra_data(app_control, VIEWTYPE_KEY, DEFAULT_STORAGE); + ret = app_control_send_launch_request(app_control, NULL, NULL); + if (ret != APP_CONTROL_ERROR_NONE) + DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret); + + app_control_destroy(app_control); + FUNC_END(); } -- 2.7.4 From e0ace87c896db4e767689500fda6dfc11ddfe1b0 Mon Sep 17 00:00:00 2001 From: Jung Date: Mon, 30 Oct 2017 09:33:29 +0000 Subject: [PATCH 06/16] Revert "Support reformatting from internal to external storage" This reverts commit c2ea6ef05797aaf0181c45ed5bcf03741ce76194. Change-Id: If8fce2a3e84b393952d986b99f71ae7dc1109638 --- src/block/block.c | 62 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 1bfcc19..96293a9 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -65,6 +65,8 @@ #define SCSI_PARTITION_LENGTH 9 #define EXTENDEDSD_NODE_PATH "/dev/mapper/extendedsd" +#define FILESYSTEM_NAME "filesystem" + #define DEV_PREFIX "/dev/" #define ROOT_DIR "/" @@ -98,7 +100,6 @@ #define EXT4_NAME "ext4" #define LUKS_NAME "crypto_LUKS" #define EXTENDEDSD_NAME "extendedsd" -#define FILESYSTEM_NAME "filesystem" /* Minimum value of block id */ #define BLOCK_ID_MIN 10 @@ -3005,7 +3006,6 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h goto out; bdev = find_block_device_by_id(id); - if (!bdev) { _E("Failed to find (%d) in the device list", id); goto out; @@ -3025,67 +3025,11 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h } prev_state = bdev->data->state; - - if (bdev->data->fs_type != NULL && !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) { - struct block_device *bdev_extended; - bdev_extended = find_block_device_path(EXTENDEDSD_MOUNT_PATH); - if (bdev_extended) { - int wait; - const char *devnode_extended = bdev_extended->data->devnode; - BLOCK_FLAG_SET(bdev_extended->data, UNMOUNT_UNSAFE); - bdev_extended->removed = true; - - if (bdev_extended->on_private_op != REQ_NORMAL) { - bdev_extended->on_private_op = REQ_NORMAL; - _D("Private operation state: %d", bdev_extended->on_private_op); - } - - ret = add_operation(bdev_extended, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE); - if (ret < 0) { - _E("Failed to add operation (unmount %s)", devnode_extended); - goto out; - } - - ret = add_operation(bdev_extended, BLOCK_DEV_REMOVE, NULL, NULL); - if (ret < 0) { - _E("Failed to add operation (remove %s)", devnode_extended); - goto out; - } - - ret = add_operation(bdev_extended, BLOCK_LUKS_CLOSE, NULL, NULL); - if (ret < 0) { - _E("Failed to add operation (luks_close %s)", devnode_extended); - goto out; - } - - for (wait = 0; wait < 10; wait++) { - if (!access(EXTENDEDSD_NODE_PATH, F_OK)) - sleep(1); - else - break; - } - - if (wait == 10) - _E("Timeout for checking access(EXTENDEDSD_NODE_PATH, F_OK)"); - } - - ret = update_block_data(bdev->data, - FILESYSTEM_NAME, - type, - "1.0", - NULL, - 0, - false); - if (ret < 0) - _E("Fail to update block data for %s", bdev->data->devnode); - - prev_state = BLOCK_MOUNT; - } else if (prev_state == BLOCK_MOUNT) { + 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); -- 2.7.4 From 84ddf0472888c5823047db19adf538b6b8f5d4a7 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 31 Oct 2017 17:13:14 +0900 Subject: [PATCH 07/16] block,app: Support extended internal storage -> portable storage setting - Only block type of mapper node(/dev/mapper/extendedsd) is BLOCK_EXTENDEDSD_DEV - Not handle unformatted storage is setting on external storage using extended-sd app. - Remove mount operation as extended internal storage when "ExtendedInternalSD" is sent as mount path (Mount dbus method) - Support unmount operation for extended internal storage - Add BLOCK_LUKS_CLOSE operation. - Need to close luks when unmounting mapper node - Register storage callback for removed signal for external storage(ex. /dev/mmcblk1p1) - Register storage callback for mapper node - internal -> portable setting: Get mapper node removed signal to progress format operation for external storage. - portable -> internal setting: Get mapper node mounted signal to progress app ui Change-Id: Iba8206e6e50ff2ed7df18931cd63c5c88109d049 Signed-off-by: pr.jung Signed-off-by: Hyotaek Shim --- apps/extended-sd/include/extended-sd-main.h | 1 - apps/extended-sd/src/es-internal-storage-page.c | 13 +-- apps/extended-sd/src/es-portable-storage-page.c | 118 ++++++++++++++++++++++-- apps/extended-sd/src/extended-sd-main.c | 29 +++--- src/block/block.c | 52 +++++------ 5 files changed, 161 insertions(+), 52 deletions(-) diff --git a/apps/extended-sd/include/extended-sd-main.h b/apps/extended-sd/include/extended-sd-main.h index ba6cc2a..b8cc0a1 100644 --- a/apps/extended-sd/include/extended-sd-main.h +++ b/apps/extended-sd/include/extended-sd-main.h @@ -90,6 +90,5 @@ void apply_theme_extension(); Evas_Object* create_image(Evas_Object* parent, char* image_path); void load_font_color_table(); -void mapper_device_cb(int id, storage_dev_e dev, storage_state_e state, const char *fstype, const char *fsuuid, const char *mount_point, bool primary, int flags, void *user_data); #endif /* __EXTENDED_SD_MAIN_H__ */ diff --git a/apps/extended-sd/src/es-internal-storage-page.c b/apps/extended-sd/src/es-internal-storage-page.c index b9635f2..17d53c3 100644 --- a/apps/extended-sd/src/es-internal-storage-page.c +++ b/apps/extended-sd/src/es-internal-storage-page.c @@ -45,7 +45,7 @@ static Evas_Object* create_page_3(appdata_s* ad); static Evas_Object* create_page_4(appdata_s* ad); static Evas_Object* create_page_5(appdata_s* ad); -void +static void mapper_device_cb(int id, storage_dev_e dev, storage_state_e state, const char *fstype, const char *fsuuide, const char *mount_point, bool primary, int flags, void *user_data) @@ -64,11 +64,7 @@ mapper_device_cb(int id, storage_dev_e dev, storage_state_e state, } // Do not deal with STORAGE_STATE_UNMOUNTABLE. Because of Format operation also emits signals with STORAGE_STATE_UNMOUNTABLE. - if (state == STORAGE_STATE_REMOVED) { - DMSG("Storage is removed"); - ui_app_exit(); - return; - } else if (state == STORAGE_STATE_UNMOUNTABLE) + if (state == STORAGE_STATE_UNMOUNTABLE || state == STORAGE_STATE_REMOVED) return; Evas_Object* page_content = elm_object_part_content_unset(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content"); @@ -833,6 +829,11 @@ void create_internal_storage_page_base_layout(appdata_s *ad) FUNC_BEGIN(); Evas_Object *page_content = NULL; char *str_setup; + int ret; + + ret = storage_set_changed_cb(STORAGE_TYPE_EXTENDED_INTERNAL, mapper_device_cb, ad); + if (ret != STORAGE_ERROR_NONE) + DMSG_ERR("Failed to register signal handler for extended internal storage"); if (ad->internal_storage_page_data) { ELM_OBJECT_ITEM_DEL(ad->internal_storage_page_data->internal_storage_page_navi_it); diff --git a/apps/extended-sd/src/es-portable-storage-page.c b/apps/extended-sd/src/es-portable-storage-page.c index 97981e1..509bfa6 100644 --- a/apps/extended-sd/src/es-portable-storage-page.c +++ b/apps/extended-sd/src/es-portable-storage-page.c @@ -5,6 +5,8 @@ //#include "dbus-macro.h" #include "log-util.h" +#define LUKS_NAME "crypto_LUKS" + typedef enum { PORTABLE_STORAGE_ITEM_PAGE_1_HEADING = 0, PORTABLE_STORAGE_ITEM_PAGE_1_PARA_1, @@ -70,14 +72,114 @@ format_done(void *data, GVariant *result, GError *err) } static void -_format_click_cb(void *data, Evas_Object* obj, void *event_info) +mapper_device_cb(int mapper_id, storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuide, const char *mount_point, + bool primary, int flags, void *user_data) { FUNC_BEGIN(); + appdata_s* ad = (appdata_s*)user_data; + GVariant *output; + GVariantIter *iter; char str_id[32]; char str_option[32]; char *arr[3]; + char *new_fstype; + bool new_primary; int ret; + int id; + + ret_if(ad == NULL); + + //TODO This supports only one extended internal storage and one sdcard slot. + // What if sdcard #1 is setting on extended internal storage, + // and another sdcard #2 is inserted and then #1 is removed? + if (dev != STORAGE_DEV_EXTENDED_INTERNAL) { + DMSG("Not mapper device"); + return; + } + + if (mapper_id != ad->storage_id) + return; + + // After mapper node is removed, app need to format sdcard + if (state != STORAGE_STATE_REMOVED) + return; + + arr[0] = "mmc"; + ret = dbus_method_sync_with_reply(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "GetDeviceList", "s", arr, &output); + if (ret < 0) { + DMSG("Failed to get storage information: %d", ret); + return; + } + + g_variant_get(output, "(a(issssssisibii))", &iter); + + while (g_variant_iter_loop(iter, "(issssssisibii)", + NULL, NULL, NULL, + NULL, &new_fstype, + NULL, NULL, + NULL, NULL, + NULL, &new_primary, + NULL, &id)) { + if (!primary) + continue; + if (strncmp(new_fstype, LUKS_NAME, strlen(LUKS_NAME) + 1)) + continue; + + DMSG("Get Primary MMC: %d", id); + ad->storage_id = id; + break; + } + + snprintf(str_id, sizeof(str_id), "%d", ad->storage_id); + arr[0] = str_id; + snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE); + arr[1] = str_option; + arr[2] = "vfat"; + ret = dbus_method_async_with_reply(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, + STORAGED_INTERFACE_BLOCK_MANAGER, + "FormatwithType", + "iis", + arr, + format_done, + 120000, + ad); + if (ret < 0) + DMSG("Failed to format", ret); + + FUNC_END(); +} + +static void +unmount_done(void *data, GVariant *result, GError *err) +{ + appdata_s* ad = (appdata_s*)data; + int ret; + + FUNC_BEGIN(); + ret_if(ad == NULL); + ret_if(result == NULL); + + g_variant_get(result, "(i)", &ret); + if (ret < 0) { + DMSG("Failed to format sd card as portable storage: %d", ret); + return; + } + + FUNC_END(); +} + +static void +_format_click_cb(void *data, Evas_Object* obj, void *event_info) +{ + FUNC_BEGIN(); + char str_id[32]; + char str_option[32]; + char *arr[2]; + int ret; appdata_s* ad = (appdata_s*)data; ret_if(ad == NULL); @@ -92,15 +194,14 @@ _format_click_cb(void *data, Evas_Object* obj, void *event_info) arr[0] = str_id; snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE); arr[1] = str_option; - arr[2] = "vfat"; ret = dbus_method_async_with_reply(STORAGED_BUS_NAME, STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, - "FormatwithType", - "iis", + "Unmount", + "ii", arr, - format_done, - 120000, + unmount_done, + DBUS_REPLY_TIMEOUT, ad); if (ret < 0) DMSG("Failed to format", ret); @@ -527,6 +628,11 @@ void create_portable_storage_page_base_layout(appdata_s *ad) FUNC_BEGIN(); Evas_Object* page_content = NULL; char *str_portable; + int ret; + + ret = storage_set_changed_cb(STORAGE_TYPE_EXTENDED_INTERNAL, mapper_device_cb, ad); + if (ret != STORAGE_ERROR_NONE) + DMSG_ERR("Failed to register signal handler for extended internal storage"); if (ad->portable_storage_page_data) { ELM_OBJECT_ITEM_DEL(ad->portable_storage_page_data->portable_storage_page_navi_it); diff --git a/apps/extended-sd/src/extended-sd-main.c b/apps/extended-sd/src/extended-sd-main.c index b59073f..625f62f 100644 --- a/apps/extended-sd/src/extended-sd-main.c +++ b/apps/extended-sd/src/extended-sd-main.c @@ -72,7 +72,9 @@ app_create(void *data) } static void -storage_removed_cb(int id, storage_state_e state, void *user_data) +storage_removed_cb(int id, storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuide, const char *mount_point, + bool primary, int flags, void *user_data) { FUNC_BEGIN(); @@ -80,10 +82,16 @@ storage_removed_cb(int id, storage_state_e state, void *user_data) ret_if(ad == NULL); - if (id == ad->storage_id) { - DMSG("Storage is removed"); - ui_app_exit(); - } + if (dev != STORAGE_DEV_EXT_SDCARD) + return; + + if (state != STORAGE_STATE_REMOVED) + return; + + /* Only one mmc slot is supported + ad->storage_id is mapper node id */ + DMSG("Storage is removed"); + ui_app_exit(); FUNC_END(); } @@ -102,12 +110,9 @@ app_control(app_control_h app_control, void *data) ret_if(ad == NULL); - ret = storage_set_state_changed_cb(ad->storage_id, storage_removed_cb, ad); - if (ret != STORAGE_ERROR_NONE) { - DMSG_ERR("Failed to register signal handler"); - ui_app_exit(); - } - ret = storage_set_changed_cb(STORAGE_TYPE_EXTENDED_INTERNAL, mapper_device_cb, ad); + ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, storage_removed_cb, ad); + if (ret != STORAGE_ERROR_NONE) + DMSG_ERR("Failed to register signal handler for extended internal storage"); len = strlen(SETUP_EXTENDED) + 1; app_control_get_extra_data(app_control, SDCARD_SETUP_TYPE, &type); @@ -159,7 +164,7 @@ app_terminate(void *data) appdata_s* ad = (appdata_s*)data; ret_if(ad == NULL); - storage_unset_state_changed_cb(ad->storage_id, storage_removed_cb); + storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, storage_removed_cb); FUNC_END(); } diff --git a/src/block/block.c b/src/block/block.c index 96293a9..1791473 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -95,7 +95,6 @@ #define PATH_LEN 55 #define EXTENDEDSD_MOUNT_PATH "/opt/extendedsd" -#define EXTENDEDSD_STRING "ExtendedInternalSD" #define EXT4_NAME "ext4" #define LUKS_NAME "crypto_LUKS" @@ -549,7 +548,7 @@ static char *generate_mount_path(struct block_data *data) char *name, node[64]; int ret; - if (!data || !data->devnode || !data->fs_usage || strcmp(data->fs_usage, FILESYSTEM_NAME)) + if (!data || !data->devnode || !data->fs_usage || (strcmp(data->fs_usage, FILESYSTEM_NAME) && strncmp(data->fs_usage, "crypto", strlen("crypto")))) return NULL; name = strrchr(data->devnode, '/'); @@ -929,6 +928,9 @@ static char *get_operation_char(enum block_dev_operation op, case BLOCK_DEV_REMOVE: str = "REMOVE"; break; + case BLOCK_LUKS_CLOSE: + str = "LUKS CLOSE"; + break; default: _E("invalid operation (%d)", op); break; @@ -2230,7 +2232,8 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m free_block_device(bdev); return -EPERM; } else if (!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) { - bdev->data->block_type = BLOCK_EXTENDEDSD_DEV; +// bdev->data->block_type = BLOCK_EXTENDEDSD_DEV; + bdev->data->primary = true; _D("Need to unlock encrypted sdcard"); // ---- ODE UI launch ---- ret = launch_system_app(POPUP_DEFAULT @@ -2246,6 +2249,13 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m if (ret < 0) _E("Failed to launch popup"); + ret = add_operation(bdev, BLOCK_DEV_INSERT, NULL, (void *)data); + if (ret < 0) { + _E("Failed to add operation (insert %s)", devnode); + free_block_device(bdev); + return ret; + } + return 0; } else if (mapper && !strncmp(bdev->data->fs_type, EXT4_NAME, strlen(EXT4_NAME))) { bdev->data->block_type = BLOCK_EXTENDEDSD_DEV; @@ -2731,6 +2741,8 @@ static void uevent_block_handler(struct udev_device *dev) false); if (r < 0) _E("fail to update block data for %s", bdev->data->devnode); + if (!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) + _I("filesystem type is updated: crypto_LUKS"); } } @@ -2782,24 +2794,7 @@ static DBusMessage *request_mount_block(dbus_method_reply_handle_h reply_handle, } /* if requester want to use a specific mount point */ - if (mount_point && - !strncmp(mount_point, EXTENDEDSD_STRING, strlen(EXTENDEDSD_STRING) + 1) != 0) { - if (!block_conf[bdev->data->block_type].extendedinternal || - !bdev->data->primary) { - _E("Not support extended internal storage"); - ret = -EPERM; - goto out; - } else { - bdev->data->block_type = BLOCK_EXTENDEDSD_DEV; - ret = change_mount_point(bdev, EXTENDEDSD_MOUNT_PATH); - if (ret < 0) { - ret = -EPERM; - goto out; - } - - create_file(bdev->data->id, bdev->data->mount_point, true); - } - } else if (mount_point && strncmp(mount_point, "", 1) != 0) { + if (mount_point && strncmp(mount_point, "", 1) != 0) { ret = change_mount_point(bdev, mount_point); if (ret < 0) { ret = -EPERM; @@ -2863,12 +2858,6 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl goto out; } - if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV) { - _I("Impossible to request unmount extended internal sdcard"); - 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)) { @@ -2890,6 +2879,12 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl goto out; } + if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV) { + ret = add_operation(bdev, BLOCK_LUKS_CLOSE, NULL, NULL); + if (ret < 0) + _E("Failed to add operation (luks_close %s)", bdev->data->devnode); + } + return NULL; out: @@ -3372,6 +3367,9 @@ static DBusMessage *request_get_mmc_primary(dbus_method_reply_handle_h reply_han continue; if (!data->primary) continue; + // Return mapper node(/dev/mapper/extendedsd) for primary mmc (not /dev/mmcblk1p1(ex)) + if (!strncmp(data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) + continue; found = true; break; } -- 2.7.4 From 8fe2e88814e5cef6d82e6491140a8b284c5b48e4 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 6 Nov 2017 17:39:50 +0900 Subject: [PATCH 08/16] dbus name cleanup --- src/shared/dbus_macro.h | 60 +++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/shared/dbus_macro.h b/src/shared/dbus_macro.h index edaf1e4..af7ea0c 100755 --- a/src/shared/dbus_macro.h +++ b/src/shared/dbus_macro.h @@ -20,9 +20,13 @@ #ifndef __STORAGED_DBUS_MACRO_H__ #define __STORAGED_DBUS_MACRO_H__ -/* + +/******************************************************************************* + * * Template * + ******************************************************************************/ +/* #define XXX_BUS_NAME "org.tizen.system.XXX" #define XXX_OBJECT_PATH "/Org/Tizen/System/XXX" #define XXX_INTERFACE_NAME XXX_BUS_NAME @@ -32,61 +36,69 @@ #define XXX_METHOD_ZZZ "ZZZ" */ -/* - * DBus daemon - */ -#define DBUS_BUS_NAME "org.freedesktop.DBus" -#define DBUS_OBJECT_PATH "/org/freedesktop/DBus" -#define DBUS_INTERFACE_NAME DBUS_BUS_NAME -/* - * System daemon - */ +/******************************************************************************* + * + * System daemon (systemd) + * + ******************************************************************************/ #define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" #define SYSTEMD_DBUS_DEST "org.freedesktop.systemd1" #define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished" -/* - * Device daemon - */ + +/******************************************************************************* + * + * Device daemon (deviced) + * + ******************************************************************************/ #define DEVICED_BUS_NAME "org.tizen.system.deviced" #define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD" #define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME -/* Core service: get/set device status operations about device */ -#define DEVICED_PATH_CORE DEVICED_OBJECT_PATH"/Core" -#define DEVICED_INTERFACE_CORE DEVICED_INTERFACE_NAME".core" -/* Power service: set resetkey disable operations about power */ -#define DEVICED_PATH_POWER DEVICED_OBJECT_PATH"/Power" -#define DEVICED_INTERFACE_POWER DEVICED_INTERFACE_NAME".power" + /* Poweroff service: get power off status operations about Poweroff */ #define DEVICED_PATH_POWEROFF DEVICED_OBJECT_PATH"/PowerOff" #define DEVICED_INTERFACE_POWEROFF DEVICED_INTERFACE_NAME".PowerOff" -/* Block service: manage block device */ + + +/******************************************************************************* + * + * Storage daemon (storaged) + * + ******************************************************************************/ #define STORAGED_BUS_NAME "org.tizen.system.storage" #define STORAGED_OBJECT_PATH "/Org/Tizen/System/Storage" #define STORAGED_INTERFACE_NAME STORAGED_BUS_NAME + +/* Block service */ #define STORAGED_PATH_BLOCK STORAGED_OBJECT_PATH"/Block" #define STORAGED_PATH_BLOCK_MANAGER STORAGED_PATH_BLOCK"/Manager" #define STORAGED_INTERFACE_BLOCK_MANAGER STORAGED_INTERFACE_NAME".BlockManager" + /* Storage service: get storage size operatioins about storage */ #define STORAGED_PATH_STORAGE STORAGED_OBJECT_PATH"/Storage" #define STORAGED_INTERFACE_STORAGE STORAGED_INTERFACE_NAME".storage" + /* Lowmem service: get critical low status operations about Lowmem */ #define STORAGED_PATH_LOWMEM STORAGED_OBJECT_PATH"/Lowmem" #define STORAGED_INTERFACE_LOWMEM STORAGED_INTERFACE_NAME".lowmem" -/* - * Popup launcher - */ + +/******************************************************************************* + * + * Popup launcher (system-popup) + * + ******************************************************************************/ #define POPUP_BUS_NAME "org.tizen.system.popup" #define POPUP_OBJECT_PATH "/Org/Tizen/System/Popup" #define POPUP_INTERFACE_NAME POPUP_BUS_NAME + /* System */ #define POPUP_PATH_SYSTEM POPUP_OBJECT_PATH"/System" #define POPUP_INTERFACE_SYSTEM POPUP_INTERFACE_NAME".System" - +/* ODE */ #define POPUP_METHOD_LAUNCH "PopupLaunch" #define POPUP_KEY_CONTENT "_SYSPOPUP_CONTENT_" #define POPUP_SDCARD_ID "_SDCARD_NUM_" -- 2.7.4 From 14072cf8deedd41fd852a98dd125eb96d2921a44 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 6 Nov 2017 17:52:39 +0900 Subject: [PATCH 09/16] DPM support Signed-off-by: INSUN PYO Change-Id: I2cfb22bcba36f3b8b3c3a487052a228033fe5769 --- src/block/block.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/block/block.c b/src/block/block.c index 1791473..1e4a626 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -191,6 +191,9 @@ static int dev_internal = -1; static char dev_internal_scsi = '\0'; static char dev_internal_emul = '\0'; +static int block_start(void *data); +static int block_stop(void *data); + static int add_operation(struct block_device *bdev, enum block_dev_operation operation, dbus_method_reply_handle_h reply_handle, void *data); @@ -3464,6 +3467,61 @@ out: return reply; } + +static DBusMessage *request_control_block(dbus_method_reply_handle_h reply_handle, + DBusMessage *msg) +{ + int ret; + int enable; + DBusMessage *reply; + DBusMessageIter iter; + + ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &enable, + DBUS_TYPE_INVALID); + if (!ret) { + ret = -1; + goto out; + } + + if (enable == 1) { + _I("control block Enable"); + block_start(NULL); + } else if (enable == 0) { + _I("control block Disable"); + block_stop(NULL); + } else { + _E("control block : Wrong request by client"); + ret = -1; + goto out; + } + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; +} + +static DBusMessage *request_getcontrol_block(dbus_method_reply_handle_h reply_handle, + DBusMessage *msg) +{ + int is_enabled; + DBusMessage *reply; + DBusMessageIter iter; + + _I("getcontrol block"); + + is_enabled = block_control; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &is_enabled); + + return reply; +} + /* Method name Method call format string Reply format string { "ShowDeviceList", NULL, NULL, request_show_device_list }, @@ -3491,6 +3549,8 @@ static const dbus_method_s manager_methods[] = { { "PrivateMount", "is", request_private_mount_block }, { "PrivateUnmount", "ii", request_private_unmount_block }, { "CheckSpeed", "i", request_check_speed }, + { "Control", "i", request_control_block }, + { "GetControl", "i", request_getcontrol_block }, }; static dbus_interface_s block_interface = { -- 2.7.4 From e81801bc4263d1b552206bb5b1ea80eff3bf3439 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 15 Nov 2017 17:45:49 +0900 Subject: [PATCH 10/16] block: Check booting is done when storaged handles uevent - Uevent for internal storage is handled before booting is done and block_init_from_udev_enumerate() called Change-Id: I61d48551b15707c27a41ff63cb01a8c0f47ec2c5 Signed-off-by: pr.jung --- src/block/block.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/block/block.c b/src/block/block.c index 1e4a626..77d32a7 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2682,6 +2682,10 @@ static void uevent_block_handler(struct udev_device *dev) int r; bool mapper = false; + /* Check booting done */ + if (!block_boot) + return; + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) { const char *devlink = udev_list_entry_get_name(list_entry); if (!fnmatch(MMC_LINK_PATH, devlink, 0)) { -- 2.7.4 From effcb8e284a7033af18ffc6b28074a2d9f0dc52e Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 20 Nov 2017 13:46:53 +0900 Subject: [PATCH 11/16] block: Change unmount option in remove_whole_block_device() - UNMOUNT_NORMAL to UNMOUNT_FORCE Change-Id: Ifa184f174d575060944e66d4dffda5cd0050b0a3 Signed-off-by: pr.jung --- src/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/block/block.c b/src/block/block.c index 77d32a7..59696f5 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2630,7 +2630,7 @@ static void remove_whole_block_device(void) if (bdev && bdev->removed == false) { bdev->removed = true; - r = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_NORMAL); + r = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE); if (r < 0) _E("Failed to add operation (unmount %s)", bdev->data->devnode); -- 2.7.4 From fe495389e665b2fde19b09c9eb382cf5c332a3b4 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 16 Nov 2017 14:54:40 +0900 Subject: [PATCH 12/16] block: register uevent control after block_init_from_udev_enumerate() Change-Id: I1abf743b6c48c0ac706b28e1d6d53ae248340388 Signed-off-by: pr.jung Signed-off-by: Hyotaek Shim --- src/block/block.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 59696f5..a069460 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2649,12 +2649,21 @@ static void booting_done(const char *sender_name, void *data) { static int done = 0; + int ret; + if (done > 0) return; done = 1; _I("Booting done"); + + /* register mmc uevent control routine */ + ret = register_udev_uevent_control(&uh); + if (ret < 0) + _E("fail to register block uevent : %d", ret); + /* if there is the attached device, try to mount */ block_init_from_udev_enumerate(); + block_control = true; block_boot = true; } @@ -2682,10 +2691,6 @@ static void uevent_block_handler(struct udev_device *dev) int r; bool mapper = false; - /* Check booting done */ - if (!block_boot) - return; - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) { const char *devlink = udev_list_entry_get_name(list_entry); if (!fnmatch(MMC_LINK_PATH, devlink, 0)) { @@ -3652,11 +3657,6 @@ static void block_init(void *data) if (ret < 0) _E("fail to init pipe"); - /* register mmc uevent control routine */ - ret = register_udev_uevent_control(&uh); - if (ret < 0) - _E("fail to register block uevent : %d", ret); - /* System Session is loaded completely */ register_dbus_signal(SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_IFACE_MANAGER, -- 2.7.4 From 14cb4ddcf25fdba72c4691fe82c1ee2a030e5c12 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 22 Nov 2017 14:46:57 +0900 Subject: [PATCH 13/16] block: Unref udev device Change-Id: Ibe9df053cfb7f6e0fd0bb37332057154c57ffaf4 Signed-off-by: pr.jung --- src/block/block.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index a069460..79a4af4 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2543,22 +2543,29 @@ static int block_init_from_udev_enumerate(void) if (!devnode) { devnode = udev_device_get_devnode(dev); - if (!devnode) + if (!devnode) { + udev_device_unref(dev); continue; + } if (fnmatch(MMC_PATH, devnode, 0) && fnmatch(SCSI_PATH, devnode, 0) && - fnmatch(EXTENDEDSD_NODE_PATH, devnode, 0)) + fnmatch(EXTENDEDSD_NODE_PATH, devnode, 0)) { + udev_device_unref(dev); continue; + } } r = check_external_storage(devnode); - if (r <= 0) + if (r <= 0) { + udev_device_unref(dev); continue; + } r = check_already_handled(devnode); if (r < 0) { _I("%s is already handled", devnode); + udev_device_unref(dev); continue; } -- 2.7.4 From 8d6f4e312d1f328a5aeacc6f929e95070aadab7b Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 21 Nov 2017 16:14:43 +0900 Subject: [PATCH 14/16] block: Rearrange block_init and block_exit sequence. - Get internal storage number on block_init(). - Call pipe_exit() after threads stop. Change-Id: I2bbcc296448a907052d96a2486700be37a92087f Signed-off-by: pr.jung (cherry picked from commit bb0d0846aecf8c021fd704d79f577a2d20d890b6) --- src/block/block.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 79a4af4..4df4812 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2505,13 +2505,6 @@ static int block_init_from_udev_enumerate(void) return -EPERM; } - if ((dev_internal < 0 && !is_emulator() && dev_internal_scsi == '\0') || - (is_emulator() && dev_internal_emul == '\0')) { - r = get_internal_storage_number(); - if (r < 0) - return -EPERM; - } - udev_enumerate_add_match_subsystem(enumerate, BLOCK_SUBSYSTEM); udev_enumerate_add_match_property(enumerate, UDEV_DEVTYPE, BLOCK_DEVTYPE_DISK); @@ -3719,6 +3712,10 @@ static void block_init(void *data) if (ret < 0) _E("Fail to change permissions of a file"); } + + ret = get_internal_storage_number(); + if (ret < 0) + _E("Failed to get internal storage number"); } static void block_exit(void *data) @@ -3739,9 +3736,6 @@ static void block_exit(void *data) DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, block_poweroff); - /* exit pipe */ - pipe_exit(); - /* unregister mmc uevent control routine */ ret = unregister_udev_uevent_control(&uh); if (ret < 0) @@ -3759,6 +3753,9 @@ static void block_exit(void *data) } } + /* exit pipe */ + pipe_exit(); + block_control = false; } -- 2.7.4 From 99675bf459ff204ce429ade2648d328104df6737 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 30 Nov 2017 14:58:40 +0900 Subject: [PATCH 15/16] refactoring : remove unused parameter. Signed-off-by: INSUN PYO Change-Id: I655750c0fde5cf606ca3195e49656891a4510980 --- src/block/block.c | 57 ++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 4df4812..658cf8f 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -907,40 +907,30 @@ static struct block_device *find_block_device_by_id(int id) return NULL; } -static char *get_operation_char(enum block_dev_operation op, - char *name, unsigned int len) +static const char *get_operation_char(enum block_dev_operation op) { - char *str = "unknown"; - - if (!name) - return NULL; - switch (op) { case BLOCK_DEV_MOUNT: - str = "MOUNT"; - break; + return "MOUNT"; + case BLOCK_DEV_UNMOUNT: - str = "UNMOUNT"; - break; + return "UNMOUNT"; + case BLOCK_DEV_FORMAT: - str = "FORMAT"; - break; + return "FORMAT"; + case BLOCK_DEV_INSERT: - str = "INSERT"; - break; + return "INSERT"; + case BLOCK_DEV_REMOVE: - str = "REMOVE"; - break; + return "REMOVE"; + case BLOCK_LUKS_CLOSE: - str = "LUKS CLOSE"; - break; - default: - _E("invalid operation (%d)", op); - break; + return "LUKS CLOSE"; } - snprintf(name, len, "%s", str); - return name; + _E("invalid operation (%d)", op); + return "unknown"; } static void create_external_apps_directory(void) @@ -959,10 +949,9 @@ static int pipe_trigger(enum block_dev_operation op, { struct pipe_data pdata = { op, bdev, result }; int n; - char name[16]; _D("op : %s, bdev : %p, result : %d", - get_operation_char(pdata.op, name, sizeof(name)), + get_operation_char(pdata.op), pdata.bdev, pdata.result); // Multi thread should not write at the same time @@ -979,7 +968,6 @@ static bool pipe_cb(int fd, void *data) int n; int thread_id; int ret; - char name[16]; n = read(fd, &pdata, sizeof(pdata)); if (n != sizeof(pdata) || !pdata.bdev) { @@ -988,7 +976,7 @@ static bool pipe_cb(int fd, void *data) } _I("op : %s, bdev : %p, result : %d", - get_operation_char(pdata.op, name, sizeof(name)), + get_operation_char(pdata.op), pdata.bdev, pdata.result); if (pdata.op == BLOCK_DEV_MOUNT && pdata.result < 0) { @@ -1651,7 +1639,6 @@ static void remove_operation(struct block_device *bdev) { struct operation_queue *op; dd_list *l, *next; - char name[16]; int thread_id; assert(bdev); @@ -1663,7 +1650,7 @@ static void remove_operation(struct block_device *bdev) DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) { if (op->done) { _D("Remove operation (%s, %s)", - get_operation_char(op->op, name, sizeof(name)), + get_operation_char(op->op), bdev->data->devnode); DD_LIST_REMOVE(bdev->op_queue, op); @@ -1777,7 +1764,6 @@ static void trigger_operation(struct block_device *bdev, dd_list *queue, struct int ret = 0; int thread_id; char devnode[PATH_MAX]; - char name[16]; enum block_dev_operation operation; bool unmounted = false; @@ -1801,21 +1787,21 @@ static void trigger_operation(struct block_device *bdev, dd_list *queue, struct operation = op->op; _D("Thread id %d Trigger operation (%s, %s)", thread_id, - get_operation_char(operation, name, sizeof(name)), devnode); + get_operation_char(operation), devnode); unmounted = false; if (operation == BLOCK_DEV_INSERT && bdev->removed) { check_removed(bdev, &queue, &op); operation = op->op; _D("Trigger operation again (%s, %s)", - get_operation_char(operation, name, sizeof(name)), devnode); + get_operation_char(operation), devnode); } if (operation == BLOCK_DEV_MOUNT) { unmounted = check_unmount(bdev, &queue, &op); if (unmounted) { operation = op->op; _D("Trigger operation again (%s, %s)", - get_operation_char(operation, name, sizeof(name)), devnode); + get_operation_char(operation), devnode); } } @@ -1998,14 +1984,13 @@ static int add_operation(struct block_device *bdev, int ret; int thread_id; bool start_th; - char name[16]; if (!bdev) return -EINVAL; _I("Add operation (%s, %s)", - get_operation_char(operation, name, sizeof(name)), + get_operation_char(operation), bdev->data->devnode); thread_id = bdev->thread_id; -- 2.7.4 From 573d40d25aaddee381124897521edd5a952e8f3b Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 12 Jan 2018 13:29:21 +0900 Subject: [PATCH 16/16] DPM: fix bug. wrong dbus return value. Signed-off-by: INSUN PYO Change-Id: I9e9f505976560457aeb3ee799394e51e8abde86e --- src/block/block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/block/block.c b/src/block/block.c index 658cf8f..3df0de5 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3478,6 +3478,7 @@ static DBusMessage *request_control_block(dbus_method_reply_handle_h reply_handl goto out; } + ret = 0; if (enable == 1) { _I("control block Enable"); block_start(NULL); -- 2.7.4