diff --git a/src/pu-emmc.c b/src/pu-emmc.c index 13f2f57..1100c17 100644 --- a/src/pu-emmc.c +++ b/src/pu-emmc.c @@ -379,13 +379,17 @@ pu_emmc_write_data(PuFlash *flash, return FALSE; if (!pu_umount(part_mount, error)) return FALSE; - } else if (g_regex_match_simple(".ext[234]$", path, 0, 0)) { + } else if (g_regex_match_simple(".ext[234]$", path, 0, 0) || + pu_is_ext234_image(path)) { if (!pu_write_raw(path, part_path, self->device, 0, 0, 0, error)) return FALSE; if (!pu_resize_filesystem(part_path, error)) return FALSE; if (!pu_set_ext_label(part_path, part->label, error)) return FALSE; + } else if (!part->filesystem) { + if (!pu_write_raw(path, part_path, self->device, 0, 0, 0, error)) + return FALSE; } else { if (!pu_mount(part_path, part_mount, NULL, NULL, error)) return FALSE; diff --git a/src/pu-mount.c b/src/pu-mount.c index 3223c24..a041b94 100644 --- a/src/pu-mount.c +++ b/src/pu-mount.c @@ -92,6 +92,7 @@ pu_mount(const gchar *source, GError **error) { gint ret; + gint status; struct libmnt_context *ctx; g_return_val_if_fail(g_strcmp0(source, "") > 0, FALSE); @@ -116,9 +117,11 @@ pu_mount(const gchar *source, mnt_context_append_options(ctx, options); ret = mnt_context_mount(ctx); - if (ret || mnt_context_get_status(ctx) != 1) { + status = mnt_context_get_status(ctx); + if (ret || status != 1) { g_set_error(error, PU_ERROR, PU_ERROR_MOUNT, - "Failed mounting '%s' to '%s'", source, mount_point); + "Failed mounting '%s' to '%s': ret %d, status %d", + source, mount_point, ret, status); mnt_free_context(ctx); return FALSE; } @@ -132,6 +135,7 @@ pu_umount(const gchar *mount_point, GError **error) { gint ret; + gint status; struct libmnt_context *ctx; g_return_val_if_fail(g_strcmp0(mount_point, "") > 0, FALSE); @@ -148,9 +152,11 @@ pu_umount(const gchar *mount_point, } mnt_context_set_target(ctx, mount_point); ret = mnt_context_umount(ctx); - if (ret || mnt_context_get_status(ctx) != 1) { + status = mnt_context_get_status(ctx); + if (ret || status != 1) { g_set_error(error, PU_ERROR, PU_ERROR_MOUNT, - "Failed unmounting '%s'", mount_point); + "Failed unmounting '%s': ret %d, status %d", + mount_point, ret, status); mnt_free_context(ctx); return FALSE; } diff --git a/src/pu-utils.c b/src/pu-utils.c index 78bfab5..863e3a3 100644 --- a/src/pu-utils.c +++ b/src/pu-utils.c @@ -408,6 +408,33 @@ pu_is_drive(const gchar *device) return ret; } +gboolean +pu_is_ext234_image(const gchar *path) +{ + blkid_probe pr; + const gchar *type = NULL; + gboolean ret = FALSE; + + g_return_val_if_fail(g_strcmp0(path, "") > 0, FALSE); + + pr = blkid_new_probe_from_filename(path); + if (!pr) { + return ret; + } + + blkid_probe_enable_superblocks(pr, 1); + blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_TYPE); + + if (blkid_do_safeprobe(pr) == 0) { + if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) { + ret = (type && g_regex_match_simple("^ext[234]$", type, 0, 0)); + } + } + + blkid_free_probe(pr); + return ret; +} + gboolean pu_wait_for_partitions(GError **error) { diff --git a/src/pu-utils.h b/src/pu-utils.h index 72e0958..8b488a9 100644 --- a/src/pu-utils.h +++ b/src/pu-utils.h @@ -47,6 +47,7 @@ gboolean pu_partition_set_partuuid(const gchar *device, const gchar *partuuid, GError **error); gboolean pu_is_drive(const gchar *device); +gboolean pu_is_ext234_image(const gchar *path); gboolean pu_wait_for_partitions(GError **error); gboolean pu_set_hwreset(const gchar *device, const gchar *hwreset, diff --git a/tests/utils.c b/tests/utils.c index bf940e7..3e4431b 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -194,6 +194,17 @@ test_device_get_partition_pattern(void) g_assert_false(g_regex_match_simple(pattern, "/dev/sdb1", 0, 0)); } +static void +test_is_ext234_image(void) +{ + g_assert_true(pu_is_ext234_image("data/root.ext4")); + g_assert_false(pu_is_ext234_image("data/random.bin")); + g_assert_false(pu_is_ext234_image("data/file-zero.txt")); + g_assert_false(pu_is_ext234_image("data/file-integer.txt")); + g_assert_false(pu_is_ext234_image("data/lorem.tar")); + g_assert_false(pu_is_ext234_image("data/lorem.txt")); +} + int main(int argc, char *argv[]) @@ -223,6 +234,7 @@ main(int argc, test_device_get_partition_path_fail); g_test_add_func("/utils/str_pre_remove", test_str_pre_remove); g_test_add_func("/utils/device_get_partition_pattern", test_device_get_partition_pattern); + g_test_add_func("/utils/is_ext234_image", test_is_ext234_image); return g_test_run(); }