done
}
+vtfile_head_zero() {
+ local vsize
+ local voffset
+ local vfile
+ local vzero
+ local vdump
+
+ voffset=0
+ vfile=$1
+ vsize=$(stat -c '%s' ${vfile})
+ vzero=$(hexdump -n 512 -e '512/1 "%02X"' $vfile)
+
+ while [ $voffset -lt $vsize ]; do
+ vdump=$(hexdump -s $voffset -n 512 -e '512/1 "%02X"' $vfile)
+ if [ "$vdump" != "$vzero" ]; then
+ echo $voffset
+ return
+ fi
+ voffset=$($BUSYBOX_PATH/expr $voffset + 512)
+ done
+ echo 0
+}
# This export is for busybox cpio command
export EXTRACT_UNSAFE_SYMLINKS=1
#only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
mv ${vtfile}_tmp $vtfile
+
vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
let vtoffset="(${#vtdump}-${#vtmagic})/2"
if [ -z "$vtmagic" ]; then
- echo "terminate with all zero data file" >> $VTLOG
- break
+ vtHeadZero=$(vtfile_head_zero $vtfile)
+ if [ $vtHeadZero -gt 0 ]; then
+ vtdump=$(hexdump -s $vtHeadZero -n 512 -e '512/1 "%02X"' $vtfile)
+ vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
+ let vtoffset="(${#vtdump}-${#vtmagic})/2+$vtHeadZero"
+ echo "skip head $vtHeadZero zeros with magic ${vtmagic:0:4}" >> $VTLOG
+ else
+ echo "terminate with all zero data file" >> $VTLOG
+ break
+ fi
fi
ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp