Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Nov 25, 2016
1 parent d2c3799 commit f65d85b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vhdcore/diskstream/diskstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package diskstream

import (
"errors"
"io"

"github.com/Microsoft/azure-vhd-utils-for-go/vhdcore"
"github.com/Microsoft/azure-vhd-utils-for-go/vhdcore/block"
"github.com/Microsoft/azure-vhd-utils-for-go/vhdcore/common"
"github.com/Microsoft/azure-vhd-utils-for-go/vhdcore/footer"
"github.com/Microsoft/azure-vhd-utils-for-go/vhdcore/vhdfile"
"io"
)

// DiskStream provides a logical stream over a VHD file.
Expand Down Expand Up @@ -260,6 +261,15 @@ func (s *DiskStream) readFromFooter(rangeToRead *common.IndexRange, p []byte) (n
vhdFooter.HeaderOffset = vhdcore.VhdNoDataLong
vhdFooter.CreatorApplication = "wa"
}
// As per VHD spec, the size reported by the footer should same as 'header.MaxTableEntries * header.BlockSize'
// But the VHD created by some tool (e.g. qemu) are not honoring this. Azure will reject the VHD if the size
// specified in the footer of VHD not match 'VHD blob size - VHD Footer Size'
//
vhdFooter.PhysicalSize = s.GetSize() - vhdcore.VhdFooterSize
vhdFooter.VirtualSize = s.GetSize() - vhdcore.VhdFooterSize

// Calculate the checksum and serialize the footer
//
vhdFooterBytes := footer.SerializeFooter(vhdFooter)
copyStartIndex := rangeToReadFromFooter.Start - s.vhdFooterRange.Start
writtenCount := copy(p, vhdFooterBytes[copyStartIndex:copyStartIndex+rangeToReadFromFooter.Length()])
Expand Down

0 comments on commit f65d85b

Please sign in to comment.