]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Ensure that generated filesystem images retain no stale content
authorMichael Brown <mcb30@ipxe.org>
Tue, 24 Mar 2026 16:41:30 +0000 (16:41 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 24 Mar 2026 16:41:30 +0000 (16:41 +0000)
We use mformat to ensure that the FAT filesystem starts as empty.
However, formatting the filesystem can still leave old data blocks
present (though unreferenced) within the disk image.

Truncate the image to a zero length before extending, to ensure that
no stale content is retained.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/util/genfsimg

index 87581503714eafdce23716a19e17f5e7ead4759f..84deea42b6b9933dbc024b5805321c1d67de2483 100755 (executable)
@@ -312,7 +312,6 @@ fi
 if [ -n "${FATIMG}" ] ; then
     FATSIZE=$(du -s -k "${FATDIR}" | cut -f1)
     FATSIZE=$(( FATSIZE + PAD + 256 ))
-    touch "${FATIMG}"
     if [ "${FATSIZE}" -le "1440" ] ; then
        FATSIZE=1440
        FATARGS="-f 1440"
@@ -325,6 +324,8 @@ if [ -n "${FATIMG}" ] ; then
        FATSERIAL=$(( SOURCE_DATE_EPOCH % 100000000 ))
        FATARGS="${FATARGS} -N ${FATSERIAL}"
     fi
+    touch "${FATIMG}"
+    truncate -s 0 "${FATIMG}"
     truncate -s "${FATSIZE}K" "${FATIMG}"
     mformat -v iPXE -i "${FATIMG}" ${FATARGS} ::
     mcopy -i "${FATIMG}" -s "${FATDIR}"/* ::