Ejemplo n.º 1
0
        /// <summary>
        /// Reads a stream into a VHD header
        /// </summary>
        /// <param name="S">Stream</param>
        private void FromStream(Stream S)
        {
            Encoding E = Encoding.Default;

            //The comments indicate the offset from the header start
            using (var BR = new BinaryReader(S, E, true))
            {
                //0
                Cookie = E.GetString(BR.ReadBytes(8));
                //8
                Features = (VhdFeatures)Tools.ToNetwork(BR.ReadUInt32());
                //12
                FileFormatVersion = new Version(Tools.ToNetwork(BR.ReadUInt16()), Tools.ToNetwork(BR.ReadUInt16()));
                //16
                DataOffset = Tools.ToNetwork(BR.ReadUInt64());
                //24
                TimeStamp = VHD.FromDiskTimestamp(Tools.ToNetwork(BR.ReadInt32()));
                //28
                CreatorApplication = E.GetString(BR.ReadBytes(4));
                //32
                CreatorVersion = new Version(Tools.ToNetwork(BR.ReadUInt16()), Tools.ToNetwork(BR.ReadUInt16()));
                //36
                CreatorHostOS = E.GetString(BR.ReadBytes(4));
                //40
                OriginalSize = Tools.ToNetwork(BR.ReadUInt64());
                //48
                CurrentSize = Tools.ToNetwork(BR.ReadUInt64());
                //56
                DiskGeometry = new CHS(
                    Tools.ToNetwork(BR.ReadUInt16()),
                    BR.ReadByte(),
                    BR.ReadByte()
                    );
                //60
                DiskType = (VhdType)Tools.ToNetwork(BR.ReadUInt32());
                //64
                Checksum = Tools.ToNetwork(BR.ReadInt32());
                //68
                DiskId = new Guid(BR.ReadBytes(16));
                //84
                SavedState = BR.ReadByte() == 1;
                //85
                Reserved = BR.ReadBytes(RESERVED_FIELD_SIZE);
                //512
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a VHD Header with most values set to their defaults
 /// </summary>
 public Footer()
 {
     Cookie             = DEFAULT_COOKIE;
     FileFormatVersion  = new Version(V_MAJOR_DEFAULT, V_MINOR_DEFAULT);
     DataOffset         = OFFSET_NONE;
     TimeStamp          = DateTime.Now;
     CreatorApplication = "ayra";
     CreatorVersion     = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
     CreatorHostOS      = VhdCreatorHost.WINDOWS;
     OriginalSize       = 0;
     CurrentSize        = 0;
     DiskGeometry       = new CHS(0, 0, 0);
     DiskType           = VhdType.FixedDisk;
     DiskId             = Guid.NewGuid();
     Features           = VhdFeatures.Reserved;
     Reserved           = new byte[RESERVED_FIELD_SIZE];
     Checksum           = ComputeChecksum();
 }