/// <summary>Snippet for GetAsync</summary>
        public async Task GetAsync()
        {
            // Snippet: GetAsync(string, string, string, CallSettings)
            // Additional: GetAsync(string, string, string, CancellationToken)
            // Create client
            DiskTypesClient diskTypesClient = await DiskTypesClient.CreateAsync();

            // Initialize request argument(s)
            string project  = "";
            string zone     = "";
            string diskType = "";
            // Make the request
            DiskType response = await diskTypesClient.GetAsync(project, zone, diskType);

            // End snippet
        }
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetDiskTypeRequest, CallSettings)
     // Create client
     DiskTypesClient diskTypesClient = DiskTypesClient.Create();
     // Initialize request argument(s)
     GetDiskTypeRequest request = new GetDiskTypeRequest
     {
         Zone     = "",
         DiskType = "",
         Project  = "",
     };
     // Make the request
     DiskType response = diskTypesClient.Get(request);
     // End snippet
 }
Пример #3
0
    public void SetDisk(int index, DiskType type)
    {
        if (index >= disks.Length || index < 0)
        {
            return;
        }

        if (disks[index] == null)
        {
            Place(index, type);
        }
        else
        {
            SwitchDisk(index, type);
        }
    }
Пример #4
0
        public static LogicalEntity CreateDisk(string filename, DiskType diskType, DiskContents contents)
        {
            DiskImage created      = null;
            DiskType  typeToCreate = diskType;

            if (typeToCreate == DiskType.UNSPECIFIED)
            {
                string ext = System.IO.Path.GetExtension(filename).ToUpper();
                if (ext.Length > 1)
                {
                    ext = ext.Substring(1); // remove the dot
                    if (DiskExtensions.ContainsKey(ext))
                    {
                        ext = DiskExtensions[ext];  // convert to standard extension
                    }
                    if (!Enum.TryParse(ext, out typeToCreate))
                    {
                        typeToCreate = DiskType.UNSPECIFIED;
                    }
                }
            }
            switch (typeToCreate)
            {
            case DiskType.DMK:
                created = new DMKImage(filename, contents);
                break;

            case DiskType.DSK:
                created = new DSKImage(filename, contents);
                break;

            case DiskType.HD:
                created = new HDImage(filename, contents);
                break;

            case DiskType.PDI:
                created = new PDIImage(filename, contents);
                break;

            case DiskType.SVI:
                break;
            }
            LogicalEntity entity = new LogicalDisk();

            entity.diskImage = created;
            return(entity);
        }
Пример #5
0
        /// <summary>
        /// Сравнивает информацию о дисках. Возвращает false - если различны
        /// </summary>
        /// <param name="diskInfo"></param>
        /// <param name="filterDiskInfo"></param>
        /// <returns></returns>
        private static bool DiskInfoCompare(DiskType diskInfo, string filterDiskInfo)
        {
            switch (filterDiskInfo)
            {
            case "Купленный":
                return(diskInfo == DiskType.Buy);

            case "Диск DVD-R":
                return(diskInfo == DiskType.OwnR);

            case "Диск DVD-RW":
                return(diskInfo == DiskType.OwnRW);

            default:
                return(true);
            }
        }
Пример #6
0
        /// <summary>
        /// Перевод DiskType в соответствующую тестовую строку
        /// </summary>
        /// <param name="diskType"></param>
        /// <returns></returns>
        private static string DiskTypeToString(DiskType diskType)
        {
            switch (diskType)
            {
            case DiskType.Buy:
                return("Купленный");

            case DiskType.OwnR:
                return("DVD-R");

            case DiskType.OwnRW:
                return("DVD-RW");

            default:
                return("Неизвестный");
            }
        }
 public bool UpdateDiskType(DiskType diskType)
 {
     try
     {
         DiskType diskTypeUpdate = context.DiskTypes.Find(diskType.IdDiskType);
         diskTypeUpdate.LateFee    = diskType.LateFee;
         diskTypeUpdate.Price      = diskType.Price;
         diskTypeUpdate.TimeRented = diskType.TimeRented;
         diskTypeUpdate.TypeName   = diskType.TypeName;
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #8
0
    private void Awake()
    {
        board = new GameBoard();

        ui.Init(board.Grid);
        movesCalculator = new ValidMovesCalculator(board.Grid);

        isAllAnimationsFinished    = false;
        isCompliteCalculatingMoves = false;

        movesCalculator.OnFinishCalculating += CompliteCaluclatingValidMoves;
        ui.OnAllAnimationsDone += CompliteAllUIAnimations;

        PlaceStartingDisks();
        currentAttaker = DiskType.Black;
        movesCalculator.StartCalculate(currentAttaker, board.Board);
        ui.UpdatePlayerScores(counterB, counterW);
    }
Пример #9
0
        public void Refresh()
        {
            string query = "Select * from Win32_LogicalDisk Where Name = \"" + Name + "\"";

            ManagementObjectSearcher   searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection results  = searcher.Get();

            foreach (ManagementObject diskObject in results)
            {
                Name               = (string)diskObject["Name"];
                freespace          = Convert.ToInt64(diskObject["FreeSpace"]);
                size               = Convert.ToInt64(diskObject["Size"]);
                driveType          = (DiskType)Convert.ToInt32(diskObject["DriveType"]);
                volumeName         = (string)diskObject["VolumeName"];
                volumeSerialNumber = (string)diskObject["VolumeSerialNumber"];
                networkPath        = (string)diskObject["ProviderName"]; //network path
                IsEnabled          = (string)diskObject["VolumeSerialNumber"] != null;
            }
        }
Пример #10
0
    public DiskImage(string name)
    {
        TextAsset diskAsset = Resources.Load(name) as TextAsset;

        if (diskAsset != null)
        {
            _name = name;
            _data = diskAsset.bytes;
            _type = _data.Length == 819200 ? DiskType.D81 : DiskType.D64;
        }
        else
        {
            Debug.LogError("Failed to open disk image " + name);
            _data = new byte[174848];
            _type = DiskType.D64;
        }

        MakeSectorTable();
    }
Пример #11
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetRegionDiskTypeRequest, CallSettings)
            // Additional: GetAsync(GetRegionDiskTypeRequest, CancellationToken)
            // Create client
            RegionDiskTypesClient regionDiskTypesClient = await RegionDiskTypesClient.CreateAsync();

            // Initialize request argument(s)
            GetRegionDiskTypeRequest request = new GetRegionDiskTypeRequest
            {
                DiskType = "",
                Region   = "",
                Project  = "",
            };
            // Make the request
            DiskType response = await regionDiskTypesClient.GetAsync(request);

            // End snippet
        }
Пример #12
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            if (stream.Length < DATA_OFFSET)
            {
                return(false);
            }

            comment = new byte[60];
            hdrId   = new byte[13];
            stream.Seek(0, SeekOrigin.Begin);
            dskType = (DiskType)stream.ReadByte();
            stream.Seek(0xAB, SeekOrigin.Begin);
            stream.Read(hdrId, 0, 13);
            stream.Seek(0xC2, SeekOrigin.Begin);
            stream.Read(comment, 0, 60);

            return(headerId.SequenceEqual(hdrId));
        }
Пример #13
0
        public static List <Disk> GetDisks(DiskType type = DiskType.All)
        {
            List <Disk> disks = new List <Disk>();

            string[] filter = new string[] { "manufacturer", "mediatype", "model", "partitions", "serialnumber" };

            foreach (ManagementObject disk in new ManagementObjectSearcher("Select * From Win32_DiskDrive").Get())
            {
                if (type == DiskType.All || disk["MediaType"].ToString().ToLowerInvariant().Contains(type.ToString().ToLowerInvariant()))
                {
                    Disk currentDisk = new Disk(disk["DeviceID"].ToString());

                    foreach (PropertyData property in disk.Properties)
                    {
                        string name = property.Name.ToLowerInvariant();
                        if (name == "deviceid")
                        {
                            continue;
                        }
                        if (name == "size")
                        {
                            currentDisk.Size = (UInt64)property.Value;
                        }
                        else if (filter.Contains(name))
                        {
                            currentDisk.AddProperty(property);
                        }
                    }

                    // add associated disk partitions
                    currentDisk.Partitions = DiskPartition.GetDiskPartitions(currentDisk.DeviceID);

                    disks.Add(currentDisk);
                }
            }

            return(disks);
        }
Пример #14
0
        public void AddDisk(DiskType type, DiskContentType contentType, char letter, string name, string path)
        {
            var number = (byte)(GetMax(from pair in this.disks
                                       let idx = pair.Value.Index
                                                 where idx.Letter == letter
                                                 select idx.Number,
                                       0) + 1);

            var index = new DiskIndex(letter, number);
            var disk  = new Disk(index, type, name)
            {
                ContentType = contentType
            };

            if (path != null)
            {
                disk.AddFileTree(new DirectoryInfo(path));
                disk.State = DiskState.FINALIZED;
            }

            this.disks.Add(index.ToString(), disk);

            return;
        }
Пример #15
0
    private void Neghbour(int cellIndex, NeighbourType type, DiskType attacker)
    {
        int           neghbourIndex = grid.GetCellNeghbourIndex(cellIndex, type);
        HashSet <int> flipPath      = new HashSet <int>();

        while (neghbourIndex >= 0 && tempBoard[neghbourIndex] != attacker && tempBoard[neghbourIndex] != DiskType.Default)
        {
            flipPath.Add(neghbourIndex);
            neghbourIndex = grid.GetCellNeghbourIndex(neghbourIndex, type);
        }
        if (neghbourIndex == -1 || tempBoard[neghbourIndex] == attacker || flipPath.Count < 1)
        {
            return;
        }

        if (ValidMoves.ContainsKey(neghbourIndex))
        {
            ValidMoves[neghbourIndex].UnionWith(flipPath);
        }
        else
        {
            ValidMoves.Add(neghbourIndex, flipPath);
        }
    }
Пример #16
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Cookie != null ? Cookie.GetHashCode() : 0);
         result = (result * 397) ^ Features.GetHashCode();
         result = (result * 397) ^ (FileFormatVersion != null ? FileFormatVersion.GetHashCode() : 0);
         result = (result * 397) ^ HeaderOffset.GetHashCode();
         result = (result * 397) ^ TimeStamp.GetHashCode();
         result = (result * 397) ^ (CreatorApplication != null ? CreatorApplication.GetHashCode() : 0);
         result = (result * 397) ^ (CreatorVersion != null ? CreatorVersion.GetHashCode() : 0);
         result = (result * 397) ^ CreatorHostOsType.GetHashCode();
         result = (result * 397) ^ PhsyicalSize.GetHashCode();
         result = (result * 397) ^ VirtualSize.GetHashCode();
         result = (result * 397) ^ (DiskGeometry != null ? DiskGeometry.GetHashCode() : 0);
         result = (result * 397) ^ DiskType.GetHashCode();
         result = (result * 397) ^ CheckSum.GetHashCode();
         result = (result * 397) ^ UniqueId.GetHashCode();
         result = (result * 397) ^ SavedState.GetHashCode();
         result = (result * 397) ^ (Reserved != null ? Reserved.GetHashCode() : 0);
         result = (result * 397) ^ (RawData != null ? RawData.GetHashCode() : 0);
         return(result);
     }
 }
Пример #17
0
        internal static VirtualDisk CreateDisk(DiskType FileType, Stream File, long Size, int BlockSize = 0)
        {
            VirtualDisk Out;

            BlockSize = (BlockSize < 512*1024) ? 512*1024 : (BlockSize%512 != 0) ? (BlockSize/512)*512 : BlockSize;

            switch (FileType)
            {
                case DiskType.VHD:
                    Out = DiscUtils.Vhd.Disk.InitializeDynamic(File, Ownership.None, Size, BlockSize);
                    ((DiscUtils.Vhd.Disk)Out).AutoCommitFooter = false;
                    break;
                case DiskType.VHDX:
                    Out = DiscUtils.Vhdx.Disk.InitializeDynamic(File, Ownership.None, Size, BlockSize);
                    break;
                default:
                    throw new NotSupportedException("The selected disk type is not supported at this time.",
                                                    new ArgumentException(
                                                        "Selected DiskType not currently supported.", "OutputType"));
            }

            Out.Signature = new Random().Next();
            BiosPartitionTable.Initialize(Out);

            return Out;
        }
Пример #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OldVHD"></param>
        /// <param name="NewVHD"></param>
        /// <param name="Output">Filename to the output file.  Method will fail if this already exists unless Force is passed as 'true'.</param>
        /// <param name="OutputType">A <see cref="DiskType"/> which specifies the output file format.</param>
        /// <param name="Force">If true, will overwrite the Output file if it already exists.  Defaults to 'false'.</param>
        /// <param name="Partition">An int tuple which declares a specific pair of partitions to compare.  The first value in the tuple will be the 0-indexed partition number from OldVHD to compare against.  The second value of the tuple will be the 0-indexed parition from NewVHD to compare with.</param>
        /// <param name="Style">The <see cref="DiffVHD.ComparisonStyle"/> to be used when comparing individual files.</param>
        /// <param name="AsBinary">If true, the resultant diff will contain the complete binary file from the child for each file found to be different.  Default is to only do this for non-text files and record a textual diff instead whenever possible.</param>
        /// <returns></returns>
        public static void CreateDiff(string OldVHD, string NewVHD, string Output, DiskType OutputType = DiskType.VHD, bool Force = false, Tuple<int, int> Partition = null, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, bool AsBinary = false)
        {
            if (File.Exists(Output) && !Force) throw new ArgumentException("Output file already exists.", "Output");
            if (!File.Exists(OldVHD)) throw new ArgumentException("Input file does not exist.", "OldVHD");
            if (!File.Exists(NewVHD)) throw new ArgumentException("Input file does not exist.", "NewVHD");

            // byte[] CopyBuffer = new byte[1024*1024];
            VirtualDisk Old, New, Out;
            Old = VirtualDisk.OpenDisk(OldVHD, FileAccess.Read);
            New = VirtualDisk.OpenDisk(NewVHD, FileAccess.Read);

            using (Old)
            using (New)
            using (var OutFS = new FileStream(Output, Force ? FileMode.Create : FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
            {

                // Check type of filesystems being compared
                if (!Old.IsPartitioned) throw new ArgumentException("Input disk is not partitioned.", "OldVHD");
                if (!New.IsPartitioned) throw new ArgumentException("Input disk is not partitioned.", "NewVHD");

                long CapacityBuffer = 64 * Math.Max(Old.Geometry.BytesPerSector, New.Geometry.BytesPerSector); // starting with 64 sectors as a buffer for partition information in the output file
                long[] OutputCapacities = new long[Partition != null ? 1 : Old.Partitions.Count];

                if (Partition != null)
                {
                    var PartA = Old.Partitions[Partition.Item1];
                    var PartB = New.Partitions[Partition.Item2];
                    if (PartA.BiosType != PartB.BiosType)
                        throw new InvalidFileSystemException(
                            String.Format(
                                "Filesystem of partition {0} in '{1}' does not match filesystem type of partition {2} in '{3}'.",
                                Partition.Item2, NewVHD, Partition.Item1, OldVHD));
                    OutputCapacities[0] += Math.Max(PartA.SectorCount * Old.Geometry.BytesPerSector, PartB.SectorCount * New.Geometry.BytesPerSector);
                }
                else
                {
                    if (Old.Partitions.Count != New.Partitions.Count)
                        throw new ArgumentException(
                            "Input disks do not have the same number of partitions.  To compare specific partitions on mismatched disks, provide the 'Partition' parameter.");
                    for (int i = 0; i < Old.Partitions.Count; i++)
                        if (Old.Partitions[i].BiosType != New.Partitions[i].BiosType)
                            throw new InvalidFileSystemException(String.Format("Filesystem of partition {0} in '{1}' does not match filesystem type of partition {0} in '{2}'.", i, NewVHD, OldVHD));
                        else
                            OutputCapacities[i] = Math.Max(Old.Partitions[i].SectorCount * Old.Geometry.BytesPerSector, New.Partitions[i].SectorCount * New.Geometry.BytesPerSector);
                }

                long OutputCapacity = CapacityBuffer + OutputCapacities.Sum();

                using (Out = VHDBuilder.CreateDisk(OutputType, OutFS, OutputCapacity, New.BlockSize))
                {

                    var OutParts = Out.Partitions;

                    if (Partition != null)
                    {
                        OutParts.Create(VHDBuilder.GetPartitionType(Old.Partitions[Partition.Item1]), false); // there is no need (ever) for a VHD diff to have bootable partitions
                        var OutFileSystem = Out.FormatPartition(0);
                        DiffPart(VHDBuilder.DetectFileSystem(Old.Partitions[Partition.Item1]),
                                 VHDBuilder.DetectFileSystem(New.Partitions[Partition.Item2]),
                                 OutFileSystem,  // As we made the partition spen the entire drive, it should be the only partition
                                 Style, new CopyQueue(AsBinary));
                    }
                    else // Partition == null
                    {
                        for (int i = 0; i < Old.Partitions.Count; i++)
                        {
                            var partIndex = OutParts.Create(Math.Max(Old.Partitions[i].SectorCount * Old.Parameters.BiosGeometry.BytesPerSector,
                                                                     New.Partitions[i].SectorCount * New.Parameters.BiosGeometry.BytesPerSector),
                                                            VHDBuilder.GetPartitionType(Old.Partitions[i]), false);
                            var OutFileSystem = Out.FormatPartition(partIndex);

                            DiffPart(VHDBuilder.DetectFileSystem(Old.Partitions[i]),
                                     VHDBuilder.DetectFileSystem(New.Partitions[i]),
                                     OutFileSystem,
                                     Style, new CopyQueue(AsBinary));
                        }
                    }

                } // using (Out)

            } // using (Old, New, and OutFS)
        }
Пример #19
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="OldVHD"></param>
 /// <param name="NewVHD"></param>
 /// <param name="Output">Filename to the output file.  Method will fail if this already exists unless Force is passed as 'true'.</param>
 /// <param name="OutputType">A <see cref="DiskType"/> which specifies the output file format.</param>
 /// <param name="Force">If true, will overwrite the Output file if it already exists.  Defaults to 'false'.</param>
 /// <param name="Partition">The 0-indexed partition number to compare from each disk file.</param>
 /// <param name="Style">The <see cref="DiffVHD.ComparisonStyle"/> to be used when comparing individual files.</param>
 /// <param name="AsBinary">If true, the resultant diff will contain the complete binary file from the child for each file found to be different.  Default is to only do this for non-text files and record a textual diff instead whenever possible.</param>
 /// <returns></returns>
 public static void CreateDiff(string OldVHD, string NewVHD, string Output, int? Partition, DiskType OutputType = DiskType.VHD, bool Force = false, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, bool AsBinary = false)
 {
     CreateDiff(OldVHD, NewVHD, Output, OutputType, Force, Partition.HasValue ? new Tuple<int, int>(Partition.Value, Partition.Value) : null, Style: Style, AsBinary: AsBinary);
 }
Пример #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="OldVHD"></param>
        /// <param name="NewVHD"></param>
        /// <param name="Output">Filename to the output file.  Method will fail if this already exists unless Force is passed as 'true'.</param>
        /// <param name="OutputType">A <see cref="VMProvisioningAgent.DiffVHD.DiskType"/> which specifies the output file format.</param>
        /// <param name="Force">If true, will overwrite the Output file if it already exists.  Defaults to 'false'.</param>
        /// <param name="Partition">An int tuple which declares a specific pair of partitions to compare.  The first value in the tuple will be the 0-indexed partition number from OldVHD to compare against.  The second value of the tuple will be the 0-indexed parition from NewVHD to compare with.</param>
        /// <param name="Style"></param>
        /// <returns></returns>
        internal static void CreateDiff(string OldVHD, string NewVHD, string Output, DiskType OutputType = DiskType.VHD, bool Force = false, Tuple <int, int> Partition = null, ComparisonStyle Style = ComparisonStyle.DateTimeOnly)
        {
            if (File.Exists(Output) && !Force)
            {
                throw new ArgumentException("Output file already exists.", "Output");
            }
            if (!File.Exists(OldVHD))
            {
                throw new ArgumentException("Input file does not exist.", "OldVHD");
            }
            if (!File.Exists(NewVHD))
            {
                throw new ArgumentException("Input file does not exist.", "NewVHD");
            }

            // byte[] CopyBuffer = new byte[1024*1024];
            VirtualDisk Old, New, Out;

            Old = VirtualDisk.OpenDisk(OldVHD, FileAccess.Read);
            New = VirtualDisk.OpenDisk(NewVHD, FileAccess.Read);

            using (Old)
                using (New)
                    using (var OutFS = new FileStream(Output, Force ? FileMode.Create : FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
                    {
                        // Check type of filesystems being compared
                        if (!Old.IsPartitioned)
                        {
                            throw new ArgumentException("Input disk is not partitioned.", "OldVHD");
                        }
                        if (!New.IsPartitioned)
                        {
                            throw new ArgumentException("Input disk is not partitioned.", "NewVHD");
                        }

                        long   CapacityBuffer   = 64 * Math.Max(Old.Geometry.BytesPerSector, New.Geometry.BytesPerSector); // starting with 64 sectors as a buffer for partition information in the output file
                        long[] OutputCapacities = new long[Partition != null ? 1 : Old.Partitions.Count];

                        if (Partition != null)
                        {
                            var PartA = Old.Partitions[Partition.Item1];
                            var PartB = New.Partitions[Partition.Item2];
                            if (PartA.BiosType != PartB.BiosType)
                            {
                                throw new InvalidFileSystemException(
                                          String.Format(
                                              "Filesystem of partition {0} in '{1}' does not match filesystem type of partition {2} in '{3}'.",
                                              Partition.Item2, NewVHD, Partition.Item1, OldVHD));
                            }
                            OutputCapacities[0] += Math.Max(PartA.SectorCount * Old.Geometry.BytesPerSector, PartB.SectorCount * New.Geometry.BytesPerSector);
                        }
                        else
                        {
                            if (Old.Partitions.Count != New.Partitions.Count)
                            {
                                throw new ArgumentException(
                                          "Input disks do not have the same number of partitions.  To compare specific partitions on mismatched disks, provide the 'Partition' parameter.");
                            }
                            for (int i = 0; i < Old.Partitions.Count; i++)
                            {
                                if (Old.Partitions[i].BiosType != New.Partitions[i].BiosType)
                                {
                                    throw new InvalidFileSystemException(String.Format("Filesystem of partition {0} in '{1}' does not match filesystem type of partition {0} in '{2}'.", i, NewVHD, OldVHD));
                                }
                                else
                                {
                                    OutputCapacities[i] = Math.Max(Old.Partitions[i].SectorCount * Old.Geometry.BytesPerSector, New.Partitions[i].SectorCount * New.Geometry.BytesPerSector);
                                }
                            }
                        }

                        long OutputCapacity = CapacityBuffer + OutputCapacities.Sum();
                        switch (OutputType)
                        {
                        case DiskType.VHD:
                            Out = DiscUtils.Vhd.Disk.InitializeDynamic(OutFS, Ownership.None, OutputCapacity, Math.Max(New.BlockSize, 512 * 1024)); // the Max() is present only because there's currently a bug with blocksize < (8*sectorSize) in DiscUtils
                            break;

                        case DiskType.VHDX:
                            Out = DiscUtils.Vhdx.Disk.InitializeDynamic(OutFS, Ownership.None, OutputCapacity, Math.Max(New.BlockSize, 512 * 1024));
                            break;

                        default:
                            throw new NotSupportedException("The selected disk type is not supported at this time.",
                                                            new ArgumentException(
                                                                "Selected DiskType not currently supported.", "OutputType"));
                        }

                        using (Out)
                        {
                            // set up the output location
                            if (Out is DiscUtils.Vhd.Disk)
                            {
                                ((DiscUtils.Vhd.Disk)Out).AutoCommitFooter = false;
                            }
                            var OutParts = BiosPartitionTable.Initialize(Out);

                            if (Partition != null)
                            {
                                OutParts.Create(GetPartitionType(Old.Partitions[Partition.Item1]), false); // there is no need (ever) for a VHD diff to have bootable partitions
                                var OutFileSystem = Out.FormatPartition(0);
                                DiffPart(DetectFileSystem(Old.Partitions[Partition.Item1]),
                                         DetectFileSystem(New.Partitions[Partition.Item2]),
                                         OutFileSystem, // As we made the partition spen the entire drive, it should be the only partition
                                         Style);
                            }
                            else // Partition == null
                            {
                                for (int i = 0; i < Old.Partitions.Count; i++)
                                {
                                    var partIndex = OutParts.Create(Math.Max(Old.Partitions[i].SectorCount * Old.Parameters.BiosGeometry.BytesPerSector,
                                                                             New.Partitions[i].SectorCount * New.Parameters.BiosGeometry.BytesPerSector),
                                                                    GetPartitionType(Old.Partitions[i]), false);
                                    var OutFileSystem = Out.FormatPartition(partIndex);

                                    DiffPart(DetectFileSystem(Old.Partitions[i]),
                                             DetectFileSystem(New.Partitions[i]),
                                             OutFileSystem,
                                             Style);
                                }
                            }
                        } // using (Out)
                    }// using (Old, New, and OutFS)
        }
Пример #21
0
 public DiskDescription(VDI disk, VBD device)
 {
     Disk   = disk;
     Device = device;
     Type   = DiskType.New;
 }
Пример #22
0
        public bool Open(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            if (stream.Length < DATA_OFFSET)
            {
                return(false);
            }

            long diskSize = stream.Length - DATA_OFFSET;

            comment = new byte[60];
            hdrId   = new byte[13];
            stream.Seek(0, SeekOrigin.Begin);
            dskType = (DiskType)stream.ReadByte();
            stream.Seek(0xAB, SeekOrigin.Begin);
            stream.Read(hdrId, 0, 13);
            stream.Seek(0xC2, SeekOrigin.Begin);
            stream.Read(comment, 0, 60);

            if (!headerId.SequenceEqual(hdrId))
            {
                return(false);
            }

            imageInfo.MediaType = MediaType.Unknown;

            switch (dskType)
            {
            // 8 spt, 1024 bps
            case DiskType.Hd2:
                if (diskSize % (2 * 8 * 1024) != 0)
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 8 * 1024));
                    return(false);
                }

                if (diskSize / (2 * 8 * 1024) == 77)
                {
                    imageInfo.MediaType = MediaType.SHARP_525;
                }
                imageInfo.SectorSize = 1024;
                break;

            // 9 spt, 1024 bps
            case DiskType.Hs2:
                if (diskSize % (2 * 9 * 512) != 0)
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 9 * 512));
                    return(false);
                }

                if (diskSize / (2 * 9 * 512) == 80)
                {
                    imageInfo.MediaType = MediaType.SHARP_525_9;
                }
                imageInfo.SectorSize = 512;
                break;

            // 15 spt, 512 bps
            case DiskType.Hc2:
                if (diskSize % (2 * 15 * 512) != 0)
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 15 * 512));
                    return(false);
                }

                if (diskSize / (2 * 15 * 512) == 80)
                {
                    imageInfo.MediaType = MediaType.DOS_525_HD;
                }
                imageInfo.SectorSize = 512;
                break;

            // 9 spt, 1024 bps
            case DiskType.Hde2:
                if (diskSize % (2 * 9 * 512) != 0)
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 9 * 512));
                    return(false);
                }

                if (diskSize / (2 * 9 * 512) == 80)
                {
                    imageInfo.MediaType = MediaType.SHARP_35_9;
                }
                imageInfo.SectorSize = 512;
                break;

            // 18 spt, 512 bps
            case DiskType.Hq2:
                if (diskSize % (2 * 18 * 512) != 0)
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 18 * 512));
                    return(false);
                }

                if (diskSize / (2 * 18 * 512) == 80)
                {
                    imageInfo.MediaType = MediaType.DOS_35_HD;
                }
                imageInfo.SectorSize = 512;
                break;

            // 26 spt, 256 bps
            case DiskType.N88:
                if (diskSize % (2 * 26 * 256) == 0)
                {
                    if (diskSize % (2 * 26 * 256) == 77)
                    {
                        imageInfo.MediaType = MediaType.NEC_8_DD;
                    }
                    imageInfo.SectorSize = 256;
                }
                else if (diskSize % (2 * 26 * 128) == 0)
                {
                    if (diskSize % (2 * 26 * 128) == 77)
                    {
                        imageInfo.MediaType = MediaType.NEC_8_SD;
                    }
                    imageInfo.SectorSize = 256;
                }
                else
                {
                    DicConsole.ErrorWriteLine("DIM shows unknown image with {0} tracks", diskSize / (2 * 26 * 256));
                    return(false);
                }

                break;

            default: return(false);
            }

            DicConsole.VerboseWriteLine("DIM image contains a disk of type {0}", imageInfo.MediaType);
            if (!string.IsNullOrEmpty(imageInfo.Comments))
            {
                DicConsole.VerboseWriteLine("DIM comments: {0}", imageInfo.Comments);
            }

            dimImageFilter = imageFilter;

            imageInfo.ImageSize            = (ulong)diskSize;
            imageInfo.CreationTime         = imageFilter.GetCreationTime();
            imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
            imageInfo.MediaTitle           = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
            imageInfo.Sectors      = imageInfo.ImageSize / imageInfo.SectorSize;
            imageInfo.Comments     = StringHandlers.CToString(comment, Encoding.GetEncoding(932));
            imageInfo.XmlMediaType = XmlMediaType.BlockMedia;

            switch (imageInfo.MediaType)
            {
            case MediaType.SHARP_525:
                imageInfo.Cylinders       = 77;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 8;
                break;

            case MediaType.SHARP_525_9:
                imageInfo.Cylinders       = 80;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 9;
                break;

            case MediaType.DOS_525_HD:
                imageInfo.Cylinders       = 80;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 15;
                break;

            case MediaType.SHARP_35_9:
                imageInfo.Cylinders       = 80;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 9;
                break;

            case MediaType.DOS_35_HD:
                imageInfo.Cylinders       = 80;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 18;
                break;

            case MediaType.NEC_8_DD:
            case MediaType.NEC_8_SD:
                imageInfo.Cylinders       = 77;
                imageInfo.Heads           = 2;
                imageInfo.SectorsPerTrack = 26;
                break;
            }

            return(true);
        }
Пример #23
0
 public Disk(int size, DiskType typeOfDisk)
 {
     Size       = size;
     TypeOfDisk = typeOfDisk;
 }
Пример #24
0
 public DiskDescription(VDI disk, VBD device)
 {
     Disk = disk;
     Device = device;
     Type = DiskType.New;
 }
Пример #25
0
 public DiskStreamBuilder(SparseStream content, DiskType diskType, long blockSize)
 {
     _content = content;
     _diskType = diskType;
     _blockSize = blockSize;
 }
Пример #26
0
 public static string ToDiskType(DiskType diskType)
 {
     switch (diskType)
     {
         case DiskType.Backup:
             return Converter.DiskTypeBackup;
         case DiskType.Data:
             return Converter.DiskTypeData;
         default:
             throw new InvalidCastException();
     }
 }
Пример #27
0
 public bool AddDidkType(DiskType diskType)
 {
     return(db.AddDiskType(diskType));
 }
Пример #28
0
        public bool Open(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            DiskType type = (DiskType)stream.ReadByte();
            byte     tracks;

            switch (type)
            {
            case DiskType.MD1DD8:
            case DiskType.MD1DD:
            case DiskType.MD2DD8:
            case DiskType.MD2DD:
                tracks = 80;
                break;

            case DiskType.MF2DD:
            case DiskType.MD2HD:
            case DiskType.MF2HD:
                tracks = 160;
                break;

            default: throw new ImageNotSupportedException($"Incorrect disk type {(byte)type}");
            }

            byte[] trackBytes = new byte[tracks];
            stream.Read(trackBytes, 0, tracks);

            Compression cmpr = (Compression)stream.ReadByte();

            if (cmpr != Compression.None)
            {
                throw new FeatureSupportedButNotImplementedImageException("Compressed images are not supported.");
            }

            int tracksize = 0;

            switch (type)
            {
            case DiskType.MD1DD8:
            case DiskType.MD2DD8:
                tracksize = 8 * 512;
                break;

            case DiskType.MD1DD:
            case DiskType.MD2DD:
            case DiskType.MF2DD:
                tracksize = 9 * 512;
                break;

            case DiskType.MD2HD:
                tracksize = 15 * 512;
                break;

            case DiskType.MF2HD:
                tracksize = 18 * 512;
                break;
            }

            int headstep = 1;

            if (type == DiskType.MD1DD || type == DiskType.MD1DD8)
            {
                headstep = 2;
            }

            MemoryStream decodedImage = new MemoryStream();

            for (int i = 0; i < tracks; i += headstep)
            {
                byte[] track = new byte[tracksize];

                if ((TrackType)trackBytes[i] == TrackType.Copied)
                {
                    stream.Read(track, 0, tracksize);
                }
                else
                {
                    ArrayHelpers.ArrayFill(track, (byte)0xF6);
                }

                decodedImage.Write(track, 0, tracksize);
            }

            imageInfo.Application          = "CisCopy";
            imageInfo.CreationTime         = imageFilter.GetCreationTime();
            imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
            imageInfo.MediaTitle           = imageFilter.GetFilename();
            imageInfo.ImageSize            = (ulong)(stream.Length - 2 - trackBytes.Length);
            imageInfo.SectorSize           = 512;

            switch (type)
            {
            case DiskType.MD1DD8:
                imageInfo.MediaType       = MediaType.DOS_525_SS_DD_8;
                imageInfo.Sectors         = 40 * 1 * 8;
                imageInfo.Heads           = 1;
                imageInfo.Cylinders       = 40;
                imageInfo.SectorsPerTrack = 8;
                break;

            case DiskType.MD2DD8:
                imageInfo.MediaType       = MediaType.DOS_525_DS_DD_8;
                imageInfo.Sectors         = 40 * 2 * 8;
                imageInfo.Heads           = 2;
                imageInfo.Cylinders       = 40;
                imageInfo.SectorsPerTrack = 8;
                break;

            case DiskType.MD1DD:
                imageInfo.MediaType       = MediaType.DOS_525_SS_DD_9;
                imageInfo.Sectors         = 40 * 1 * 9;
                imageInfo.Heads           = 1;
                imageInfo.Cylinders       = 40;
                imageInfo.SectorsPerTrack = 9;
                break;

            case DiskType.MD2DD:
                imageInfo.MediaType       = MediaType.DOS_525_DS_DD_9;
                imageInfo.Sectors         = 40 * 2 * 9;
                imageInfo.Heads           = 2;
                imageInfo.Cylinders       = 40;
                imageInfo.SectorsPerTrack = 9;
                break;

            case DiskType.MF2DD:
                imageInfo.MediaType       = MediaType.DOS_35_DS_DD_9;
                imageInfo.Sectors         = 80 * 2 * 9;
                imageInfo.Heads           = 2;
                imageInfo.Cylinders       = 80;
                imageInfo.SectorsPerTrack = 9;
                break;

            case DiskType.MD2HD:
                imageInfo.MediaType       = MediaType.DOS_525_HD;
                imageInfo.Sectors         = 80 * 2 * 15;
                imageInfo.Heads           = 2;
                imageInfo.Cylinders       = 80;
                imageInfo.SectorsPerTrack = 15;
                break;

            case DiskType.MF2HD:
                imageInfo.MediaType       = MediaType.DOS_35_HD;
                imageInfo.Sectors         = 80 * 2 * 18;
                imageInfo.Heads           = 2;
                imageInfo.Cylinders       = 80;
                imageInfo.SectorsPerTrack = 18;
                break;
            }

            imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
            decodedDisk            = decodedImage.ToArray();

            decodedImage.Close();

            DicConsole.VerboseWriteLine("CisCopy image contains a disk of type {0}", imageInfo.MediaType);

            return(true);
        }
Пример #29
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            DiskType type = (DiskType)stream.ReadByte();
            byte     tracks;

            switch (type)
            {
            case DiskType.MD1DD8:
            case DiskType.MD1DD:
            case DiskType.MD2DD8:
            case DiskType.MD2DD:
                tracks = 80;
                break;

            case DiskType.MF2DD:
            case DiskType.MD2HD:
            case DiskType.MF2HD:
                tracks = 160;
                break;

            default: return(false);
            }

            byte[] trackBytes = new byte[tracks];
            stream.Read(trackBytes, 0, tracks);

            for (int i = 0; i < tracks; i++)
            {
                if (trackBytes[i] != (byte)TrackType.Copied && trackBytes[i] != (byte)TrackType.Omitted &&
                    trackBytes[i] != (byte)TrackType.OmittedAlternate)
                {
                    return(false);
                }
            }

            Compression cmpr = (Compression)stream.ReadByte();

            if (cmpr != Compression.None && cmpr != Compression.Normal && cmpr != Compression.High)
            {
                return(false);
            }

            switch (type)
            {
            case DiskType.MD1DD8:
                if (stream.Length > 40 * 1 * 8 * 512 + 82)
                {
                    return(false);
                }

                break;

            case DiskType.MD1DD:
                if (stream.Length > 40 * 1 * 9 * 512 + 82)
                {
                    return(false);
                }

                break;

            case DiskType.MD2DD8:
                if (stream.Length > 40 * 2 * 8 * 512 + 82)
                {
                    return(false);
                }

                break;

            case DiskType.MD2DD:
                if (stream.Length > 40 * 2 * 9 * 512 + 82)
                {
                    return(false);
                }

                break;

            case DiskType.MF2DD:
                if (stream.Length > 80 * 2 * 9 * 512 + 162)
                {
                    return(false);
                }

                break;

            case DiskType.MD2HD:
                if (stream.Length > 80 * 2 * 15 * 512 + 162)
                {
                    return(false);
                }

                break;

            case DiskType.MF2HD:
                if (stream.Length > 80 * 2 * 18 * 512 + 162)
                {
                    return(false);
                }

                break;
            }

            return(true);
        }
Пример #30
0
        public void ParseCatalogue(int sectorNumber = 0, bool strictTrdosFormat = true)
        {
            if (Files == null)
            {
                Files = new MList <FileData>();
            }
            else
            {
                Files.Clear();
            }
            for (int i = 0, adr = sectorNumber * SectorSize; i < 128; i++, adr += 16)
            {
                if (Sectors == null || adr / SectorSize >= Sectors.Length)
                {
                    break;
                }
                if (adr + 16 > Data.Length)
                {
                    break;
                }
                if (Sectors[adr / SectorSize] != SectorProcessResult.Good)
                {
                    continue;
                }
                if (strictTrdosFormat && Data[adr] == 0)
                {
                    break;
                }
                if (AllBytes(Data, adr, 8, 0))
                {
                    continue;
                }
                FileData fileData = new FileData();
                fileData.FileName  = ReplaceZeroInString(Encoding.ASCII.GetString(Data, adr, 9));
                fileData.Extension = fileData.FileName[8];
                fileData.FileName  = fileData.FileName.Substring(0, 8);
                fileData.Start     = Data[adr + 9] + Data[adr + 10] * SectorSize;
                fileData.Length    = Data[adr + 11] + Data[adr + 12] * SectorSize;
                fileData.Size      = Data[adr + 13];
                fileData.Sector    = Data[adr + 14];
                fileData.Track     = Data[adr + 15];
                int diskAddress = fileData.Track * SectorsOnTrack + fileData.Sector;
                int good        = 0;
                int bad         = 0;
                int unprocessed = 0;
                for (int j = diskAddress, last = Math.Min(Sectors.Length, diskAddress + fileData.Size); j < last; j++)
                {
                    switch (Sectors[j])
                    {
                    case SectorProcessResult.Unprocessed:
                        unprocessed++;
                        break;

                    case SectorProcessResult.Good:
                        good++;
                        break;

                    case SectorProcessResult.Bad:
                    case SectorProcessResult.NoHeader:
                        bad++;
                        break;
                    }
                }
                fileData.GoodSectors        = good;
                fileData.BadSectors         = bad;
                fileData.UnprocessedSectors = unprocessed;
                Files.Add(fileData);
            }
            if (Sectors.Length > sectorNumber + 8 && Sectors[sectorNumber + 8] == SectorProcessResult.Good)
            {
                Title               = ReplaceZeroInString(Encoding.ASCII.GetString(Data, (sectorNumber + 8) * SectorSize + 245, 8));
                Free8Sector         = Data[(sectorNumber + 8) * SectorSize + 229] + Data[(sectorNumber + 8) * SectorSize + 230] * SectorSize;
                DeletedFiles8Sector = Data[(sectorNumber + 8) * SectorSize + 244];
                FileCount8Sector    = Data[(sectorNumber + 8) * SectorSize + 228];
                switch (Data[(sectorNumber + 8) * SectorSize + 227])
                {
                case 0x16:
                    DiskType = DiskType.DS80;
                    break;

                case 0x17:
                    DiskType = DiskType.DS40;
                    break;

                case 0x18:
                    DiskType = DiskType.SS80;
                    break;

                case 0x19:
                    DiskType = DiskType.SS40;
                    break;

                default:
                    DiskType = DiskType.Unidentified;
                    break;
                }
            }
            else
            {
                Title               = null;
                Free8Sector         = 0;
                DeletedFiles8Sector = 0;
                FileCount8Sector    = 0;
                DiskType            = DiskType.Unidentified;
            }
            catalogueParsed = true;
        }
Пример #31
0
 public Task ClearAs(DiskType diskType)
 {
     throw new NotImplementedException();
 }
Пример #32
0
 public static LogicalEntity CreateDisk(string filename, DiskType diskType)
 {
     return(CreateDisk(filename, diskType, null));
 }
Пример #33
0
 public Disk (DiskIndex index, DiskType type, string name)
     : this () {
     this.Index = index;
     this.Type = type;
     this.Name = name;
 }
Пример #34
0
 public DiskStreamBuilder(SparseStream content, DiskType diskType, long blockSize)
 {
     _content   = content;
     _diskType  = diskType;
     _blockSize = blockSize;
 }
Пример #35
0
        private static async Task InstancePoolApi(DatabricksClient client)
        {
            Console.WriteLine("Creating Testing Instance Pool");
            var poolAttributes = new InstancePoolAttributes
            {
                PoolName = "TestInstancePool",
                PreloadedSparkVersions             = new[] { RuntimeVersions.Runtime_6_4_ESR },
                MinIdleInstances                   = 2,
                MaxCapacity                        = 100,
                IdleInstanceAutoTerminationMinutes = 15,
                NodeTypeId        = NodeTypes.Standard_D3_v2,
                EnableElasticDisk = true,
                DiskSpec          = new DiskSpec
                {
                    DiskCount = 2, DiskSize = 64, DiskType = DiskType.FromAzureDisk(AzureDiskVolumeType.STANDARD_LRS)
                },
                PreloadedDockerImages = new[]
                {
                    new DockerImage {
                        Url = "databricksruntime/standard:latest"
                    }
                },
                AzureAttributes = new InstancePoolAzureAttributes {
                    Availability = AzureAvailability.SPOT_AZURE, SpotBidMaxPrice = -1
                }
            };

            var poolId = await client.InstancePool.Create(poolAttributes).ConfigureAwait(false);

            Console.WriteLine("Listing pools");
            var pools = await client.InstancePool.List().ConfigureAwait(false);

            foreach (var pool in pools)
            {
                Console.WriteLine($"\t{pool.PoolId}\t{pool.PoolName}\t{pool.State}");
            }

            Console.WriteLine("Getting created pool by poolId");
            var targetPoolInfo = await client.InstancePool.Get(poolId).ConfigureAwait(false);

            Console.WriteLine("Editing pool");
            targetPoolInfo.MinIdleInstances = 3;
            await client.InstancePool.Edit(poolId, targetPoolInfo).ConfigureAwait(false);

            Console.WriteLine("Getting edited pool by poolId");
            targetPoolInfo = await client.InstancePool.Get(poolId).ConfigureAwait(false);

            Console.WriteLine($"MinIdleInstances: {targetPoolInfo.MinIdleInstances}");

            Console.WriteLine("Creating a sample cluster in the pool.");
            var clusterConfig = ClusterInfo.GetNewClusterConfiguration("Sample cluster")
                                .WithRuntimeVersion(RuntimeVersions.Runtime_7_3)
                                .WithAutoScale(3, 7)
                                .WithAutoTermination(30)
                                .WithClusterLogConf("dbfs:/logs/");

            clusterConfig.InstancePoolId = poolId;

            var clusterId = await client.Clusters.Create(clusterConfig);

            var createdCluster = await client.Clusters.Get(clusterId);

            Console.WriteLine($"Created cluster pool Id: {createdCluster.InstancePoolId}");

            Console.WriteLine("Deleting pool");
            await client.InstancePool.Delete(poolId);

            Console.WriteLine("Deleting cluster");
            await client.Clusters.Delete(clusterId);
        }
Пример #36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OldVHD"></param>
        /// <param name="NewVHD"></param>
        /// <param name="Output">Filename to the output file.  Method will fail if this already exists unless Force is passed as 'true'.</param>
        /// <param name="OutputType">A <see cref="VMProvisioningAgent.DiffVHD.DiskType"/> which specifies the output file format.</param>
        /// <param name="Force">If true, will overwrite the Output file if it already exists.  Defaults to 'false'.</param>
        /// <param name="Partition">An int tuple which declares a specific pair of partitions to compare.  The first value in the tuple will be the 0-indexed partition number from OldVHD to compare against.  The second value of the tuple will be the 0-indexed parition from NewVHD to compare with.</param>
        /// <param name="Style"></param>
        /// <returns></returns>
        internal static void CreateDiff(string OldVHD, string NewVHD, string Output, DiskType OutputType = DiskType.VHD, bool Force = false, Tuple<int, int> Partition = null, ComparisonStyle Style = ComparisonStyle.DateTimeOnly)
        {
            if (File.Exists(Output) && !Force) throw new ArgumentException("Output file already exists.", "Output");
            if (!File.Exists(OldVHD)) throw new ArgumentException("Input file does not exist.", "OldVHD");
            if (!File.Exists(NewVHD)) throw new ArgumentException("Input file does not exist.", "NewVHD");

            // byte[] CopyBuffer = new byte[1024*1024];
            VirtualDisk Old, New, Out;
            Old = VirtualDisk.OpenDisk(OldVHD, FileAccess.Read);
            New = VirtualDisk.OpenDisk(NewVHD, FileAccess.Read);

            using (Old)
            using (New)
            using (var OutFS = new FileStream(Output, Force ? FileMode.Create : FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
            {

                // Check type of filesystems being compared
                if (!Old.IsPartitioned) throw new ArgumentException("Input disk is not partitioned.", "OldVHD");
                if (!New.IsPartitioned) throw new ArgumentException("Input disk is not partitioned.", "NewVHD");

                long CapacityBuffer = 64 * Math.Max(Old.Geometry.BytesPerSector, New.Geometry.BytesPerSector); // starting with 64 sectors as a buffer for partition information in the output file
                long[] OutputCapacities = new long[Partition != null ? 1 : Old.Partitions.Count];

                if (Partition != null)
                {
                    var PartA = Old.Partitions[Partition.Item1];
                    var PartB = New.Partitions[Partition.Item2];
                    if (PartA.BiosType != PartB.BiosType)
                        throw new InvalidFileSystemException(
                            String.Format(
                                "Filesystem of partition {0} in '{1}' does not match filesystem type of partition {2} in '{3}'.",
                                Partition.Item2, NewVHD, Partition.Item1, OldVHD));
                    OutputCapacities[0] += Math.Max(PartA.SectorCount * Old.Geometry.BytesPerSector, PartB.SectorCount * New.Geometry.BytesPerSector);
                }
                else
                {
                    if (Old.Partitions.Count != New.Partitions.Count)
                        throw new ArgumentException(
                            "Input disks do not have the same number of partitions.  To compare specific partitions on mismatched disks, provide the 'Partition' parameter.");
                    for (int i = 0; i < Old.Partitions.Count; i++)
                        if (Old.Partitions[i].BiosType != New.Partitions[i].BiosType)
                            throw new InvalidFileSystemException(String.Format("Filesystem of partition {0} in '{1}' does not match filesystem type of partition {0} in '{2}'.", i, NewVHD, OldVHD));
                        else
                            OutputCapacities[i] = Math.Max(Old.Partitions[i].SectorCount * Old.Geometry.BytesPerSector, New.Partitions[i].SectorCount * New.Geometry.BytesPerSector);
                }

                long OutputCapacity = CapacityBuffer + OutputCapacities.Sum();
                switch (OutputType)
                {
                    case DiskType.VHD:
                        Out = DiscUtils.Vhd.Disk.InitializeDynamic(OutFS, Ownership.None, OutputCapacity, Math.Max(New.BlockSize, 512 * 1024)); // the Max() is present only because there's currently a bug with blocksize < (8*sectorSize) in DiscUtils
                        break;
                    case DiskType.VHDX:
                        Out = DiscUtils.Vhdx.Disk.InitializeDynamic(OutFS, Ownership.None, OutputCapacity, Math.Max(New.BlockSize, 512 * 1024));
                        break;
                    default:
                        throw new NotSupportedException("The selected disk type is not supported at this time.",
                                                        new ArgumentException(
                                                            "Selected DiskType not currently supported.", "OutputType"));
                }

                using (Out)
                {

                    // set up the output location
                    if (Out is DiscUtils.Vhd.Disk) ((DiscUtils.Vhd.Disk) Out).AutoCommitFooter = false;
                    var OutParts = BiosPartitionTable.Initialize(Out);

                    if (Partition != null)
                    {
                        OutParts.Create(GetPartitionType(Old.Partitions[Partition.Item1]), false); // there is no need (ever) for a VHD diff to have bootable partitions
                        var OutFileSystem = Out.FormatPartition(0);
                        DiffPart(DetectFileSystem(Old.Partitions[Partition.Item1]),
                                 DetectFileSystem(New.Partitions[Partition.Item2]),
                                 OutFileSystem,  // As we made the partition spen the entire drive, it should be the only partition
                                 Style);
                    }
                    else // Partition == null
                    {
                        for (int i = 0; i < Old.Partitions.Count; i++)
                        {
                            var partIndex = OutParts.Create(Math.Max(Old.Partitions[i].SectorCount * Old.Parameters.BiosGeometry.BytesPerSector,
                                                                     New.Partitions[i].SectorCount * New.Parameters.BiosGeometry.BytesPerSector),
                                                            GetPartitionType(Old.Partitions[i]), false);
                            var OutFileSystem = Out.FormatPartition(partIndex);

                            DiffPart(DetectFileSystem(Old.Partitions[i]),
                                     DetectFileSystem(New.Partitions[i]),
                                     OutFileSystem,
                                     Style);
                        }
                    }

                } // using (Out)

            } // using (Old, New, and OutFS)
        }
Пример #37
0
 public bool UpdateDiskType(DiskType diskType)
 {
     return(db.UpdateDiskType(diskType));
 }
Пример #38
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="OldVHD"></param>
 /// <param name="NewVHD"></param>
 /// <param name="Output">Filename to the output file.  Method will fail if this already exists unless Force is passed as 'true'.</param>
 /// <param name="OutputType">A <see cref="VMProvisioningAgent.DiffVHD.DiskType"/> which specifies the output file format.</param>
 /// <param name="Force">If true, will overwrite the Output file if it already exists.  Defaults to 'false'.</param>
 /// <param name="Partition">The 0-indexed partition number to compare from each disk file.</param>
 /// <param name="Style"></param>
 /// <returns></returns>
 internal static void CreateDiff(string OldVHD, string NewVHD, string Output, int?Partition, DiskType OutputType = DiskType.VHD, bool Force = false, ComparisonStyle Style = ComparisonStyle.DateTimeOnly)
 {
     CreateDiff(OldVHD, NewVHD, Output, OutputType, Force, Partition.HasValue ? new Tuple <int, int>(Partition.Value, Partition.Value) : null, Style: Style);
 }