コード例 #1
0
ファイル: VHD.cs プロジェクト: AyrA/vhd
 /// <summary>
 /// Creates a new VHD image
 /// </summary>
 /// <param name="Size">Size of the disk (as seen from the VM)</param>
 /// <param name="DiskType">Type of the VHD</param>
 /// <param name="Output">Stream to write the image to</param>
 /// <param name="Quick">
 /// Quick create. Will not write <paramref name="Size"/> bytes but instead just skip.
 /// The contents of the skipped range are undefined and depend on the file system the disk is on.
 /// On FAT, the parameter does nothing and the system writes bytes for us.
 /// On NTFS, the bytes are guaranteed to appear as zero
 /// </param>
 public static void CreateVHD(ulong Size, VhdType DiskType, Stream Output, bool Quick)
 {
     var H = new Footer();
     H.CurrentSize = H.OriginalSize = Size;
     H.DiskGeometry = new CHS(Size);
     if (Quick && !Output.CanSeek)
     {
         throw new ArgumentException($"{nameof(Output)} is not seekable, but {nameof(Quick)} is enabled");
     }
     switch (DiskType)
     {
         case VhdType.None:
             throw new ArgumentException("'None' is not a valid VHD type");
         case VhdType.FixedDisk:
             H.Checksum = H.ComputeChecksum();
             H.Validate();
             SeekOrWrite(Size, Output, Quick);
             Output.Write(H.Export(), 0, Footer.HEADER_LENGTH);
             break;
         case VhdType.DynamicDisk:
         case VhdType.DifferencingDisk:
         default:
             throw new NotImplementedException(nameof(VHD) + "." + nameof(CreateVHD) + $": Disk type {DiskType} is not implemented yet");
     }
 }
コード例 #2
0
ファイル: PowerShellWrapper.cs プロジェクト: Roemer/Cake.VHD
        public static VirtualHardDisk Call_NewVHD(string vhdPath, ulong diskSize, uint blockSize = 0, VhdType vhdType = VhdType.Dynamic, string parentPath = null)
        {
            var parameters = new Dictionary <string, object>
            {
                { "Path", vhdPath },
                { "SizeBytes", diskSize }
            };

            if (blockSize > 0)
            {
                parameters.Add("BlockSizeBytes", blockSize);
            }
            switch (vhdType)
            {
            case VhdType.Differencing:
                parameters.Add("Differencing", true);
                parameters.Add("ParentPath", parentPath);
                break;

            case VhdType.Fixed:
                parameters.Add("Fixed", true);
                break;

            case VhdType.Dynamic:
            default:
                parameters.Add("Dynamic", true);
                break;
            }
            var result   = ExecutePowerShell("New-VHD", parameters);
            var psObject = result[0];
            var vhd      = PsObjectToVhdObject(psObject);

            return(vhd);
        }
コード例 #3
0
        public static VirtualHardDisk VhdCreate(this ICakeContext context, FilePath vhdPath, ulong size, uint blockSize, VhdType vhdType)
        {
            var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath;

            return(PowerShellWrapper.Call_NewVHD(vhdFullPath, size, blockSize, vhdType));
        }