/// <summary>
        ///     Calculates the minimum block size required for a single logical volume, assuming the logical volume cannot have any
        ///     children.
        /// </summary>
        public PartitionHelper LogicalVolume(LogicalVolume lv, int lbsByte, long newHdSize, int hdNumberToGet)
        {
            var logicalVolumeHelper = new PartitionHelper {
                MinSizeBlk = 0
            };

            if (lv.ForceFixedSize)
            {
                logicalVolumeHelper.MinSizeBlk    = lv.Size;
                logicalVolumeHelper.IsDynamicSize = false;
            }
            else if (!string.IsNullOrEmpty(lv.CustomSize) && !string.IsNullOrEmpty(lv.CustomSizeUnit))
            {
                long customSizeBytes = 0;
                switch (lv.CustomSizeUnit)
                {
                case "MB":
                    customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024;
                    break;

                case "GB":
                    customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024 * 1024;
                    break;

                case "%":
                    var hdPercent = Convert.ToDouble(lv.CustomSize) / 100;
                    customSizeBytes = Convert.ToInt64(hdPercent * newHdSize);
                    break;
                }
                logicalVolumeHelper.MinSizeBlk    = customSizeBytes / lbsByte;
                logicalVolumeHelper.IsDynamicSize = false;
            }
            else
            {
                logicalVolumeHelper.IsDynamicSize = true;
                string imageFile = null;
                foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                {
                    imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(_imageProfile.Image.Name,
                                                                                    hdNumberToGet.ToString(), lv.VolumeGroup, lv.Name, ext);

                    if (!string.IsNullOrEmpty(imageFile))
                    {
                        break;
                    }
                }
                if (Path.GetExtension(imageFile) == ".wim")
                {
                    logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte;
                }
                else
                {
                    //fix me - a hack when using core storage with dynamic partitions on macos environment
                    if (lv.FsType.ToLower().Contains("hfs") && newHdSize <= 121332826112)
                    {
                        //assume fusion, set minsize to full size of drive
                        logicalVolumeHelper.MinSizeBlk = Convert.ToInt64(newHdSize * .8) / lbsByte;
                    }
                    else
                    {
                        if (lv.VolumeSize > lv.UsedMb)
                        {
                            logicalVolumeHelper.MinSizeBlk = lv.VolumeSize * 1024 * 1024 / lbsByte;
                        }
                        else
                        {
                            logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte;
                        }
                    }
                }
            }

            return(logicalVolumeHelper);
        }
Пример #2
0
        /// <summary>
        ///     Calculates the minimum block size required for a single logical volume, assuming the logical volume cannot have any
        ///     children.
        /// </summary>
        public PartitionHelper LogicalVolume(LogicalVolume lv, int lbsByte, long newHdSize, int hdNumberToGet)
        {
            var logicalVolumeHelper = new PartitionHelper {
                MinSizeBlk = 0
            };

            if (lv.ForceFixedSize)
            {
                logicalVolumeHelper.MinSizeBlk    = lv.Size;
                logicalVolumeHelper.IsDynamicSize = false;
            }
            else if (!string.IsNullOrEmpty(lv.CustomSize) && !string.IsNullOrEmpty(lv.CustomSizeUnit))
            {
                long customSizeBytes = 0;
                switch (lv.CustomSizeUnit)
                {
                case "MB":
                    customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024;
                    break;

                case "GB":
                    customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024 * 1024;
                    break;

                case "%":
                    var hdPercent = Convert.ToDouble(lv.CustomSize) / 100;
                    customSizeBytes = Convert.ToInt64(hdPercent * newHdSize);
                    break;
                }
                logicalVolumeHelper.MinSizeBlk    = customSizeBytes / lbsByte;
                logicalVolumeHelper.IsDynamicSize = false;
            }
            else
            {
                logicalVolumeHelper.IsDynamicSize = true;
                string imageFile = null;
                foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                {
                    imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(_imageProfile.Image.Name,
                                                                                    hdNumberToGet.ToString(), lv.VolumeGroup, lv.Name, ext);

                    if (!string.IsNullOrEmpty(imageFile))
                    {
                        break;
                    }
                }
                if (Path.GetExtension(imageFile) == ".wim")
                {
                    logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte;
                }
                else
                {
                    if (lv.VolumeSize > lv.UsedMb)
                    {
                        logicalVolumeHelper.MinSizeBlk = lv.VolumeSize * 1024 * 1024 / lbsByte;
                    }
                    else
                    {
                        logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte;
                    }
                }
            }

            return(logicalVolumeHelper);
        }