diff mbox series

wic: fix corrupt vfat with rawcopy of sparse files

Message ID CAE=baehdk3a9xYOG3za_aG4VZy7GAem=5iiZPVm0ZuSYmrWXug@mail.gmail.com
State New
Headers show
Series wic: fix corrupt vfat with rawcopy of sparse files | expand

Commit Message

Blake Alexander Nov. 1, 2022, 11:42 a.m. UTC
From 1c435bf5c2f4357c8c08eb71195a1042f077f7f9 Mon Sep 17 00:00:00 2001
From: Blake Alexander <blake.alexander@airbus.com>
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 <blake.alexander@airbus.com>
---
 scripts/lib/wic/plugins/source/rawcopy.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)


         # get the size in the right units for kickstart (kB)
         du_cmd = "du -Lbks %s" % dst

Comments

Ross Burton Nov. 1, 2022, 4:57 p.m. UTC | #1
Hi

Can you send the patch using git-send-email?  Your mailer is either sending the patch as plain&html attachments or reformatting the plain text, so git am can’t apply it.

Ross

> On 1 Nov 2022, at 11:42, Blake Alexander via lists.openembedded.org <blake.alexander=airbus.com@lists.openembedded.org> wrote:
> 
> [Edited Message Follows]
> [Reason: remove unneeded automatic footer and raw smtp headers]
> 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 <blake.alexander@airbus.com>
> ---
>  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
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> 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/6875888
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ross.burton@arm.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

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}")