Example #1
0
 public string MinimumClientSizeForGridView(int profileId, int hdNumber)
 {
     try
     {
         var profile       = ReadProfile(profileId);
         var fltClientSize = new ServiceClientPartition(profile).HardDrive(hdNumber, 1) / 1024f / 1024f / 1024f;
         return(Math.Abs(fltClientSize) < 0.1f ? "< 100M" : fltClientSize.ToString("#.##") + " GB");
     }
     catch
     {
         return("N/A");
     }
 }
Example #2
0
        public string GeneratePartitionScript()
        {
            imageProfile = new ServiceImageProfile().ReadProfile(profileId);
            ImageSchema  = new ServiceClientPartition(imageProfile).GetImageSchema();

            clientSchema =
                new ServiceClientPartitionSchema(HdNumberToGet, NewHdSize, imageProfile, partitionPrefix)
                .GenerateClientSchema();
            if (clientSchema == null)
            {
                return("failed");
            }

            //Handle moving from / to hard drives with different sector sizes ie 512 / 4096
            var activeCounter = HdNumberToGet;

            //Look for first active hd
            if (!ImageSchema.HardDrives[HdNumberToGet].Active)
            {
                while (activeCounter <= ImageSchema.HardDrives.Count())
                {
                    if (ImageSchema.HardDrives[activeCounter - 1].Active)
                    {
                        HdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }
            var LbsByte = Convert.ToInt32(ImageSchema.HardDrives[HdNumberToGet].Lbs); //logical block size in bytes

            if (LbsByte == 512 && clientBlockSize == 4096)
            {
                //fix calculations from 512 to 4096
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector / 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk /
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    //efi partition on 4k drive cannot be smaller than this, and it is smaller on a 512 drive
                    if (partition.FsId.ToLower() == "ef00")
                    {
                        partition.Size = 66560;
                    }
                    else
                    {
                        partition.Size = partition.Size / 8;
                    }
                    partition.Start = partition.Size / 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size / 8;
                    partition.Start = partition.Size / 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size / 8;
                }
            }
            else if (LbsByte == 4096 && clientBlockSize == 512)
            {
                //fix calculations from 4096 to 512
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector * 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk *
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size * 8;
                }
            }

            //otherwise both the original image block size and the destination hard block size are the same, no changes needed
            //End Handle moving from / to hard drives with different sector sizes

            if (imageProfile.Image.Environment == "linux" || string.IsNullOrEmpty(imageProfile.Image.Environment))
            {
                return(LinuxLayout());
            }

            if (imageProfile.Image.Environment == "winpe")
            {
                return(WinPELayout());
            }
            return("failed");
        }