private int GetPartitionOffset(int index)
        {
            bool found        = false;
            int  entriesSoFar = 0;
            int  position     = 0;

            while (!found && position < _primaryHeader.PartitionEntryCount)
            {
                GptEntry entry = new GptEntry();
                entry.ReadFrom(_entryBuffer, position * _primaryHeader.PartitionEntrySize);
                if (entry.PartitionType != Guid.Empty)
                {
                    if (index == entriesSoFar)
                    {
                        found = true;
                        break;
                    }

                    entriesSoFar++;
                }

                position++;
            }

            if (found)
            {
                return(position * _primaryHeader.PartitionEntrySize);
            }
            else
            {
                throw new IOException(string.Format(CultureInfo.InvariantCulture, "No such partition: {0}", index));
            }
        }
 private IEnumerable <GptEntry> GetAllEntries()
 {
     for (int i = 0; i < _primaryHeader.PartitionEntryCount; ++i)
     {
         GptEntry entry = new GptEntry();
         entry.ReadFrom(_entryBuffer, i * _primaryHeader.PartitionEntrySize);
         if (entry.PartitionType != Guid.Empty)
         {
             yield return(entry);
         }
     }
 }
        private int GetFreeEntryOffset()
        {
            for (int i = 0; i < _primaryHeader.PartitionEntryCount; ++i)
            {
                GptEntry entry = new GptEntry();
                entry.ReadFrom(_entryBuffer, i * _primaryHeader.PartitionEntrySize);

                if (entry.PartitionType == Guid.Empty)
                {
                    return(i * _primaryHeader.PartitionEntrySize);
                }
            }

            throw new IOException("No free partition entries available");
        }
        private int GetEntryIndex(Guid identity)
        {
            int index = 0;

            for (int i = 0; i < _primaryHeader.PartitionEntryCount; ++i)
            {
                GptEntry entry = new GptEntry();
                entry.ReadFrom(_entryBuffer, i * _primaryHeader.PartitionEntrySize);

                if (entry.Identity == identity)
                {
                    return(index);
                }
                else if (entry.PartitionType != Guid.Empty)
                {
                    index++;
                }
            }

            throw new IOException("No such partition");
        }