Exemplo n.º 1
0
        public string GeneratePartitionScript()
        {
            imageProfile = BLL.ImageProfile.ReadProfile(profileId);
            ImageSchema = new ClientPartitionHelper(imageProfile).GetImageSchema();

            clientSchema = new ClientPartition(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();
            }
            else if(imageProfile.Image.Environment == "macOS")
            {
                return OsxNbiLayout();
            }
            else if (imageProfile.Image.Environment == "winpe")
            {
                return WinPELayout();
            }
            else
            {
                return "failed";
            }
        }
        public string GeneratePartitionScript()
        {
            imageProfile = BLL.ImageProfile.ReadProfile(profileId);
            ImageSchema  = new ClientPartitionHelper(imageProfile).GetImageSchema();


            clientSchema = new ClientPartition(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());
            }
            else if (imageProfile.Image.Environment == "macOS")
            {
                return(OsxNbiLayout());
            }
            else if (imageProfile.Image.Environment == "winpe")
            {
                return(WinPELayout());
            }
            else
            {
                return("failed");
            }
        }