Пример #1
0
 /// <summary>
 /// Create a GUID Partition Table entry
 /// </summary>
 /// <param name="typeId">A unique identifier indicating the type of the partition</param>
 /// <param name="entryId">A unique identifier for the partition</param>
 /// <param name="flags">The flags to set on the partition</param>
 /// <param name="name">The name of the partition</param>
 /// <param name="offset">The offset of the partition in it's container file</param>
 /// <param name="length">The length of the partition</param>
 /// <param name="stream">The stream containing the partition data</param>
 public GptPartitionEntry(Guid typeId, Guid entryId, GptPartitionFlags flags, string name, long offset, long length, Stream stream) : base(offset, length, stream)
 {
     TypeId  = typeId;
     EntryId = entryId;
     Flags   = flags;
     Name    = name;
 }
Пример #2
0
        /// <inheritdoc />
        protected override IEnumerable <PartitionEntry> LoadPartitions()
        {
            using BinaryReader br = new BinaryReader(_container.Content, Encoding.ASCII, true);
            br.BaseStream.Seek(_sectorSize, SeekOrigin.Begin);

            _header = new GptHeader(br);

            if (_header.Signature != "EFI PART")
            {
                throw new InvalidDataException("Not a GPT Protective Partition");
            }

            br.BaseStream.Seek((long)(_sectorSize * _header.TableLBA), SeekOrigin.Begin);

            var entries = ImmutableList.CreateBuilder <PartitionEntry>();

            for (int i = 0; i < _header.PartitionEntries; i++)
            {
                Guid              typeId   = new Guid(br.ReadBytes(16));
                Guid              entryId  = new Guid(br.ReadBytes(16));
                ulong             firstLba = br.ReadUInt64();
                ulong             lastLba  = br.ReadUInt64();
                GptPartitionFlags flags    = (GptPartitionFlags)br.ReadUInt64();
                string            name     = Encoding.Unicode.GetString(br.ReadBytes(72));

                long offset = (long)(firstLba * _sectorSize);
                long length = (long)((lastLba - firstLba + 1) * _sectorSize);

                long additionalBytes = _header.SizeOfPartitionEntry - 0x80;
                if (additionalBytes > 0)
                {
                    br.BaseStream.Seek(additionalBytes, SeekOrigin.Current);
                }

                if (typeId != Guid.Empty)
                {
                    entries.Add(new GptPartitionEntry(typeId, entryId, flags, name, offset, length, new PartialStream(_container.Content, offset, length)));
                }
            }

            return(entries.ToImmutableList());
        }