コード例 #1
0
        public static HeaderRecord Initialized(ImageType type, ImageFlags flags, long size, int blockSize, int blockExtra)
        {
            HeaderRecord result = new HeaderRecord();

            result._fileVersion = new FileVersion(0x00010001);
            result.HeaderSize = 400;
            result.ImageType = type;
            result.Flags = flags;
            result.Comment = "Created by .NET DiscUtils";
            result.LegacyGeometry = new GeometryRecord();
            result.DiskSize = size;
            result.BlockSize = blockSize;
            result.BlockExtraSize = blockExtra;
            result.BlockCount = (int)((size + blockSize - 1) / blockSize);
            result.BlocksAllocated = 0;

            result.BlocksOffset = ((PreHeaderRecord.Size + result.HeaderSize + 511) / 512) * 512;
            result.DataOffset = (uint)(((result.BlocksOffset + result.BlockCount * 4 + 511) / 512) * 512);

            result.UniqueId = Guid.NewGuid();
            result.ModificationId = Guid.NewGuid();

            result.LChsGeometry = new GeometryRecord();

            return result;
        }
コード例 #2
0
ファイル: DiskStream.cs プロジェクト: joconno4/MediaPortal-2
        public DiskStream(Stream fileStream, Ownership ownsStream, HeaderRecord fileHeader)
        {
            _fileStream = fileStream;
            _fileHeader = fileHeader;

            _ownsStream = ownsStream;

            ReadBlockTable();
        }
コード例 #3
0
        /// <summary>
        /// Initializes a stream as a dynamically-sized VDI file.
        /// </summary>
        /// <param name="stream">The stream to initialize.</param>
        /// <param name="ownsStream">Indicates if the new instance controls the lifetime of the stream.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <returns>An object that accesses the stream as a VDI file</returns>
        public static DiskImageFile InitializeDynamic(Stream stream, Ownership ownsStream, long capacity)
        {
            PreHeaderRecord preHeader = PreHeaderRecord.Initialized();
            HeaderRecord    header    = HeaderRecord.Initialized(ImageType.Dynamic, ImageFlags.None, capacity, 1024 * 1024, 0);

            byte[] blockTable = new byte[header.BlockCount * 4];
            for (int i = 0; i < blockTable.Length; ++i)
            {
                blockTable[i] = 0xFF;
            }
            header.BlocksAllocated = 0;

            stream.Position = 0;
            preHeader.Write(stream);
            header.Write(stream);

            stream.Position = header.BlocksOffset;
            stream.Write(blockTable, 0, blockTable.Length);

            return(new DiskImageFile(stream, ownsStream));
        }
コード例 #4
0
 private void ReadHeader()
 {
     _stream.Position = 0;
     _preHeader = new PreHeaderRecord();
     _preHeader.Read(_stream);
     _header = new HeaderRecord();
     _header.Read(_preHeader.Version, _stream);
 }