From 1c435bf5c2f4357c8c08eb71195a1042f077f7f9 Mon Sep 17 00:00:00 2001 From: Blake Alexander <[email protected]> Date: Tue, 1 Nov 2022 09:34:06 +0000 Subject: [PATCH 1/1] wic: fix corrupt vfat with rawcopy of sparse files
vfat partitions do not support sparse files. When using the rawcopy plugin to write an image to such a partition the filesystem may become corrupte. Boot systems such as UEFI require the boot partition to be a FAT type and this may therefore result in an un-bootable system due to boot partition corruption. Sparse file copying is advantageous when the images consist of mostly empty or unused space. Systems using sparse file capable filesystems should not have this behaviour taken away from the, however, when using a non-compatible file system, the wic script should not perform sparse file operations. If required, the user shall be able to override this to achieve the behaviour prior to this patch. The wic script will now check the filesystem type of the destination and use non-sparse copying functions if it matches the type 'vfat'. If 'allow-holes' is specified in the plugin parameters, then this will be ignored and sparse_copy shall be used instead. Signed-off-by: Blake Alexander <[email protected]> --- scripts/lib/wic/plugins/source/rawcopy.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/lib/wic/plugins/source/rawcopy.py b/scripts/lib/wic/plugins/source/rawcopy.py index 7c90cd3cf8..1e0ddbac12 100644 --- a/scripts/lib/wic/plugins/source/rawcopy.py +++ b/scripts/lib/wic/plugins/source/rawcopy.py @@ -89,10 +89,17 @@ class RawCopyPlugin(SourcePlugin): if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst)) - if 'skip' in source_params: + # Sparse copy if the file system supports it or allow-holes is set to override + allow_holes = False if part.fstype == "vfat" and source_params.get("allow-holes", True) else True + + if allow_holes and 'skip' in source_params: sparse_copy(src, dst, skip=int(source_params['skip'])) - else: + elif allow_holes and 'skip' not in source_params: sparse_copy(src, dst) + elif not allow_holes and 'skip' in source_params: + exec_cmd(f"dd if={src} of={dst} ibs={source_params['skip']} skip=1 conv=notrunc") + else: + exec_cmd(f"cp --sparse=never {src} {dst}") # get the size in the right units for kickstart (kB) du_cmd = "du -Lbks %s" % dst -- 2.25.1 The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, please notify Airbus immediately and delete this e-mail. Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately. All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#172358): https://lists.openembedded.org/g/openembedded-core/message/172358 Mute This Topic: https://lists.openembedded.org/mt/94706878/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
