From patchwork Tue Nov 1 11:42:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blake Alexander X-Patchwork-Id: 14634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C54AC433FE for ; Tue, 1 Nov 2022 11:42:20 +0000 (UTC) Received: from mx1.myeers.net (mx1.myeers.net [87.190.7.230]) by mx.groups.io with SMTP id smtpd.web10.5183.1667302938162369454 for ; Tue, 01 Nov 2022 04:42:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@airbus.com header.s=eers-ng2048 header.b=oCXmh15Z; spf=pass (domain: airbus.com, ip: 87.190.7.230, mailfrom: blake.alexander@airbus.com) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=airbus.com; i=@airbus.com; l=10129; q=dns/txt; s=eers-ng2048; t=1667302938; x=1698838938; h=mime-version:from:date:message-id:subject:to; bh=u215sh+qSf+oyrZGWf6aCXvT2JjVXS6CNuU6L3BCqsg=; b=oCXmh15ZAUWKYgIcQ9jSjgCN3OHORvPFFn89Svqeyzu5+mUvaLWsnrfZ 4aw6qQzhN623MvR89ydC/uIKzH5BbQUhegAV7YyPKQ9Cd6z7FxikiHcV9 wMP0MIthMJmEUFoJDviNObs3Y3XjJBGG2ecPBDyzUNToXy7xTxzyCzIel wmt2vZr+QLPkz7GSVcHshsH9PT+MfLZDb3nOZ9BB4s1KFSs6sNbrn8ZBa 7NmM7wviK4WnJZqkWiCNHJeyEt76pxDSgMkAT27HG7c6CzGqrkflxP/oJ 1nFniIbkc9dGHLvAxlUssTK58D3QUkQG/wULcElDEyNOnaSzIt7rTxthw Q==; Received-SPF: Fail (MX: domain of blake.alexander@airbus.com does not designate 209.85.208.72 as permitted sender) identity=mailfrom; client-ip=209.85.208.72; receiver=MX; envelope-from="blake.alexander@airbus.com"; x-sender="blake.alexander@airbus.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:87.190.7.224/28 ip4:80.242.167.16/28 ip4:217.239.138.48/28 ip4:62.217.58.112/28 include:group1._spf.airbus.com include:group2._spf.airbus.com include:group3._spf.airbus.com include:group4._spf.airbus.com -all" Received-SPF: None (MX: no sender authenticity information available from domain of postmaster@mail-ed1-f72.google.com) identity=helo; client-ip=209.85.208.72; receiver=MX; envelope-from="blake.alexander@airbus.com"; x-sender="postmaster@mail-ed1-f72.google.com"; x-conformance=spf_only Authentication-Results: MX; spf=Fail smtp.mailfrom=blake.alexander@airbus.com; spf=None smtp.helo=postmaster@mail-ed1-f72.google.com; dkim=pass (signature verified) header.i=@airbus.com X-Ironport-Dmarc-Check-Result: validskip IronPort-SDR: H20bpaIGx7hRN+jIAGhx9TdBlrgvgON4Gu0ApZh9igvfgk4xNpFEucvCqAH6d8OMrD4WZJ2mQx XeUTlpVu/UJQ== X-IronPort-AV: E=Sophos;i="5.95,230,1661810400"; d="scan'208,217,223";a="8925862" Received: from mail-ed1-f72.google.com ([209.85.208.72]) by mx1.myeers.net with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 12:42:15 +0100 Received: by mail-ed1-f72.google.com with SMTP id i17-20020a05640242d100b0044f18a5379aso9900720edc.21 for ; Tue, 01 Nov 2022 04:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=airbus.com; s=google; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=wf9ZRmWufW0toVTeeCF89RQ1vI3YQ6nekr3HIJpwlL0=; b=T0EuJDNOzVulbcdSqyufRIdGg6kIPU+aQ+2jUGwk+D0EXc0IfRFKlmdXDelL6JPPoa WLobw83iuMvs5MiZgTErgdMwHvWZzWfG70XvxHNP4iubnnXyZ+dOnUuBxux1D+LonnoI 5y+DLpoXFTobJx5/WsCyWm4Fhk/5+hRhmkuHQlDYU0OAt4cAaD/jBJQ6nugH6z8GEA5l fmBVez7UyaMMe+7Kshpr1LKkiirkkXqo42XwmygXBoFkc8goipMsry36S17Pd5fcP3eW Xut11ybvvtYWJMqeCRfn0JRRAQjwQGCy0TM+B24kk4fxK2ArHpJAsKPNRsUhyeh0hiJV Zi+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wf9ZRmWufW0toVTeeCF89RQ1vI3YQ6nekr3HIJpwlL0=; b=CND9czjwYGYfukx4N4DrjAX2+bdAdcNyURNTfc/I4mFXOCn5op0RjBsZoDREYWUwk0 UQbXXyTgClw842TirCkpjvVBLJA98OLBHwUPFdm3lqeePO/DeN1r1Xqo5Y4f9Qbm8//B 3Z6ZDVCX4S2JQ75mEZPKOH/TFPeK9jYVnq4QMyHOZg2g+YkoZZcU+GyhfokqM9NNnpks Km33eTb1dLQbrD+gaO3F8P4L/uTO4aEiQk7g7A49osI/FTD59Up1Xrc1y5zi44GErXEE Sjy1z94C4k0MmXJL7kxVg8MfhuHR61o/a2wnLsGJquPg85t9BQ5DJ9YJZJPQ2G8Ah9xB rw5Q== X-Gm-Message-State: ACrzQf3i3XvdSMB3ngTPYS0hkwo+pNLyxNLdWJ54KUv8DNxsW2glX2r5 kNmPiy8rDyJtOh1OQeT8xxAs5Fc0HDrLjcDXGcClJQEUDkF3T2lUBZTff4sTtdJJXPhB8M/KtfT KGQhPlRjJQPo8Q5xSxSYmESh54kN1wn7ovKGkYTKcz5ashZ2/Kar7lNM5 X-Received: by 2002:a17:907:6d29:b0:78d:d12d:15af with SMTP id sa41-20020a1709076d2900b0078dd12d15afmr18111431ejc.53.1667302935008; Tue, 01 Nov 2022 04:42:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM50TfdDBElz3D7J/x1zYtU8Q2SmzjCezB5JSy/1M6G7sKcU//J5MQE5ZWa22QBGUfQiD3IGVqECcO5YR6ZBsEA= X-Received: by 2002:a17:907:6d29:b0:78d:d12d:15af with SMTP id sa41-20020a1709076d2900b0078dd12d15afmr18111399ejc.53.1667302934505; Tue, 01 Nov 2022 04:42:14 -0700 (PDT) MIME-Version: 1.0 From: Blake Alexander Date: Tue, 1 Nov 2022 12:42:03 +0100 Message-ID: Subject: [PATCH] wic: fix corrupt vfat with rawcopy of sparse files To: openembedded-core@lists.openembedded.org List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 01 Nov 2022 11:42:20 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/172358 From 1c435bf5c2f4357c8c08eb71195a1042f077f7f9 Mon Sep 17 00:00:00 2001 From: Blake Alexander 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 --- 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 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}")