[build] Ensure that generated filesystem images retain no stale content

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>
This commit is contained in:
Michael Brown 2026-03-24 16:41:30 +00:00
parent a0bf3f1cc8
commit 0d30ee7b49

View File

@ -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}"/* ::