Exemplo n.º 1
0
        /// <summary>
        /// Creates the VHD footer.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="diskGeometry">The disk geometry.</param>
        /// <returns></returns>
        public static byte[] CreateFooter(ulong blocks, uint timeStamp, byte[] guid, DiskGeometry diskGeometry)
        {
            var binaryFooter = new Mosa.ClassLib.BinaryFormat(512);

            binaryFooter.SetString(VHDFooterOffset.Cookie, "conectix", 8);
            binaryFooter.SetUIntReversed(VHDFooterOffset.Features, 0x00000002);
            binaryFooter.SetUIntReversed(VHDFooterOffset.FileFormatVersion, 0x00010000);
            binaryFooter.SetULong(VHDFooterOffset.DataOffset, ~(ulong)0);
            binaryFooter.SetUIntReversed(VHDFooterOffset.TimeStamp, timeStamp);
            binaryFooter.SetString(VHDFooterOffset.CreatorApplication, "MOSA", 4);
            binaryFooter.SetUIntReversed(VHDFooterOffset.CreatorVersion, 0x00050000);
            binaryFooter.SetUIntReversed(VHDFooterOffset.CreatorHostOS, 0x5769326B); // Windows
            binaryFooter.SetULongReversed(VHDFooterOffset.OriginalSize, blocks * 512);
            binaryFooter.SetULongReversed(VHDFooterOffset.CurrentSize, blocks * 512);
            binaryFooter.SetUShortReversed(VHDFooterOffset.DiskGeometryCylinders, diskGeometry.Cylinders);
            binaryFooter.SetByte(VHDFooterOffset.DiskGeometryHeads, diskGeometry.Heads);
            binaryFooter.SetByte(VHDFooterOffset.DiskGeometrySectors, (byte)diskGeometry.SectorsPerTrack);

            binaryFooter.SetUIntReversed(VHDFooterOffset.DiskType, 0x02); // Fixed disk
            binaryFooter.SetUIntReversed(VHDFooterOffset.Checksum, 0x00);
            binaryFooter.SetBytes(VHDFooterOffset.UniqueId, guid, 0, 16);
            binaryFooter.SetByte(VHDFooterOffset.SavedState, 0x00); // No saved state

            uint checksum = 0;
            for (uint index = 0; index < 512; index++)
                checksum += binaryFooter.Data[index];

            binaryFooter.SetUIntReversed(VHDFooterOffset.Checksum, ~checksum);

            return binaryFooter.Data;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the VHD footer.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="diskGeometry">The disk geometry.</param>
        /// <returns></returns>
        static public byte[] CreateFooter(ulong blocks, uint timeStamp, byte[] guid, DiskGeometry diskGeometry)
        {
            Mosa.ClassLib.BinaryFormat binaryFooter = new Mosa.ClassLib.BinaryFormat(512);

            binaryFooter.SetString(VHDFooterOffset.Cookie, "conectix", 8);
            binaryFooter.SetUIntReversed(VHDFooterOffset.Features, 0x00000002);
            binaryFooter.SetUIntReversed(VHDFooterOffset.FileFormatVersion, 0x00010000);
            binaryFooter.SetULong(VHDFooterOffset.DataOffset, ~(ulong)0);
            binaryFooter.SetUIntReversed(VHDFooterOffset.TimeStamp, timeStamp);
            binaryFooter.SetString(VHDFooterOffset.CreatorApplication, "MOSA", 4);
            binaryFooter.SetUIntReversed(VHDFooterOffset.CreatorVersion, 0x00050000);
            binaryFooter.SetUIntReversed(VHDFooterOffset.CreatorHostOS, 0x5769326B);             // Windows
            binaryFooter.SetULongReversed(VHDFooterOffset.OriginalSize, blocks * 512);
            binaryFooter.SetULongReversed(VHDFooterOffset.CurrentSize, blocks * 512);
            binaryFooter.SetUShortReversed(VHDFooterOffset.DiskGeometryCylinders, diskGeometry.Cylinders);
            binaryFooter.SetByte(VHDFooterOffset.DiskGeometryHeads, diskGeometry.Heads);
            binaryFooter.SetByte(VHDFooterOffset.DiskGeometrySectors, (byte)diskGeometry.SectorsPerTrack);

            binaryFooter.SetUIntReversed(VHDFooterOffset.DiskType, 0x02);             // Fixed disk
            binaryFooter.SetUIntReversed(VHDFooterOffset.Checksum, 0x00);
            binaryFooter.SetBytes(VHDFooterOffset.UniqueId, guid, 0, 16);
            binaryFooter.SetByte(VHDFooterOffset.SavedState, 0x00);             // No saved state

            uint checksum = 0;

            for (uint index = 0; index < 512; index++)
            {
                checksum += binaryFooter.Data[index];
            }

            binaryFooter.SetUIntReversed(VHDFooterOffset.Checksum, ~checksum);

            return(binaryFooter.Data);
        }
Exemplo n.º 3
0
Arquivo: VDI.cs Projeto: hj1980/Mosa
        /// <summary>
        /// Creates the header.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="lastSnapGuid">The last snap GUID.</param>
        /// <param name="diskGeometry">The disk geometry.</param>
        /// <returns></returns>
        public static byte[] CreateHeader(uint blocks, byte[] guid, byte[] lastSnapGuid, DiskGeometry diskGeometry)
        {
            Mosa.ClassLib.BinaryFormat binaryHeader = new Mosa.ClassLib.BinaryFormat(512);

            binaryHeader.SetString(VHIHeaderOffset.HeaderText, HeaderText, (uint)HeaderText.Length);
            binaryHeader.SetByte(VHIHeaderOffset.HeaderText + 0x25, 0x0A);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageSignature, 0xBEda107F);
            binaryHeader.SetUInt(VHIHeaderOffset.Version, 0x00010001);
            binaryHeader.SetUInt(VHIHeaderOffset.HeaderSize, 0x180);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageType, 0x02);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageFlags, 0x00);
            binaryHeader.SetUInt(VHIHeaderOffset.OffsetBlocks, 0x200);
            binaryHeader.SetUInt(VHIHeaderOffset.OffsetData, 0x400);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometryCylinders, 0); // diskGeometry.Cylinders);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometryHeads, 0); // diskGeometry.Heads);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometrySectors, 0); // diskGeometry.SectorsPerTrack);
            binaryHeader.SetUInt(VHIHeaderOffset.SectorSize, 512);
            binaryHeader.SetULong(VHIHeaderOffset.DiskSize, blocks * 512);
            binaryHeader.SetUInt(VHIHeaderOffset.BlockSize, 0x100000);
            binaryHeader.SetUInt(VHIHeaderOffset.BlockExtraData, 0);
            binaryHeader.SetUInt(VHIHeaderOffset.BlocksInHDD, (uint)((blocks * 512) / 0x100000));
            binaryHeader.SetUInt(VHIHeaderOffset.BlocksAllocated, (uint)((blocks * 512) / 0x100000));
            binaryHeader.SetBytes(VHIHeaderOffset.UUID, guid, 0, 16);
            binaryHeader.SetBytes(VHIHeaderOffset.UUIDLastSnap, lastSnapGuid, 0, 16);

            return binaryHeader.Data;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the header.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="lastSnapGuid">The last snap GUID.</param>
        /// <param name="diskGeometry">The disk geometry.</param>
        /// <returns></returns>
        static public byte[] CreateHeader(uint blocks, byte[] guid, byte[] lastSnapGuid, DiskGeometry diskGeometry)
        {
            Mosa.ClassLib.BinaryFormat binaryHeader = new Mosa.ClassLib.BinaryFormat(512);

            binaryHeader.SetString(VHIHeaderOffset.HeaderText, HeaderText, (uint)HeaderText.Length);
            binaryHeader.SetByte(VHIHeaderOffset.HeaderText + 0x25, 0x0A);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageSignature, 0xBEda107F);
            binaryHeader.SetUInt(VHIHeaderOffset.Version, 0x00010001);
            binaryHeader.SetUInt(VHIHeaderOffset.HeaderSize, 0x180);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageType, 0x02);
            binaryHeader.SetUInt(VHIHeaderOffset.ImageFlags, 0x00);
            binaryHeader.SetUInt(VHIHeaderOffset.OffsetBlocks, 0x200);
            binaryHeader.SetUInt(VHIHeaderOffset.OffsetData, 0x400);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometryCylinders, 0);         // diskGeometry.Cylinders);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometryHeads, 0);             // diskGeometry.Heads);
            binaryHeader.SetUInt(VHIHeaderOffset.DiskGeometrySectors, 0);           // diskGeometry.SectorsPerTrack);
            binaryHeader.SetUInt(VHIHeaderOffset.SectorSize, 512);
            binaryHeader.SetULong(VHIHeaderOffset.DiskSize, blocks * 512);
            binaryHeader.SetUInt(VHIHeaderOffset.BlockSize, 0x100000);
            binaryHeader.SetUInt(VHIHeaderOffset.BlockExtraData, 0);
            binaryHeader.SetUInt(VHIHeaderOffset.BlocksInHDD, (uint)((blocks * 512) / 0x100000));
            binaryHeader.SetUInt(VHIHeaderOffset.BlocksAllocated, (uint)((blocks * 512) / 0x100000));
            binaryHeader.SetBytes(VHIHeaderOffset.UUID, guid, 0, 16);
            binaryHeader.SetBytes(VHIHeaderOffset.UUIDLastSnap, lastSnapGuid, 0, 16);

            return(binaryHeader.Data);
        }