Exemplo n.º 1
0
        public Partition Add(Entry entry)
        {
            var desiredSize = new GptSegment(currentSector, ToSectors(entry.Size.Bytes));
            var size        = calculator.Constraint(desiredSize);

            Log.Verbose("PartitionEntry to add: {@Entry}, Desired Size={DesiredSize}, Final Size={FinalSize}", desiredSize, size);

            var partition = new Partition(entry.Name, entry.GptType, bytesPerSector)
            {
                Attributes  = entry.Attributes,
                FirstSector = size.Start,
                LastSector  = size.End,
                Guid        = Guid.NewGuid(),
            };

            Log.Verbose("Adding pending partition to the context: {@Partition}", partition);
            handler.Partitions.Add(partition);

            EnsureValidLayout(handler.Partitions, SizeInSectors);

            availableSectorSize -= size.Length;
            currentSector       += size.Length + chunkSize;

            return(partition);
        }
Exemplo n.º 2
0
        public GptSegment Constraint(GptSegment desired)
        {
            var size = SmallerDivisible(desired.Length, chunkSize);

            var rightLimit = totalSectors - 1 * chunkSize;

            var finalFirst  = Math.Min(SmallerDivisible(desired.Start, chunkSize), rightLimit);
            var finalLast   = Math.Min(finalFirst + size, rightLimit);
            var finalLength = finalLast - finalFirst;

            return(new GptSegment(finalFirst, finalLength));
        }