Пример #1
0
        public async Task Execute(string partitionDescriptor, string gptTypeString)
        {
            var partition = await fileSystem.GetPartitionFromDescriptor(partitionDescriptor);

            var gptType = GptType.FromString(gptTypeString);
            await partition.SetGptType(gptType);
        }
Пример #2
0
        public async Task <string> Execute(int diskNumber, string partitionType, string label = "")
        {
            var disk = await fileSystem.GetDisk(diskNumber);

            var partition = await disk.CreatePartition(GptType.FromString(partitionType), label);

            var descriptor = FileSystemMixin.GetDescriptor(partition);

            return(await descriptor);
        }
        public async Task <string> Execute(int diskNumber, string partitionType, string sizeString = null)
        {
            var size = sizeString != null?ByteSize.Parse(sizeString) : default;

            var disk = await fileSystem.GetDisk(diskNumber);

            var partition = await disk.CreateGptPartition(GptType.FromString(partitionType), size);

            var descriptor = FileSystemMixin.GetDescriptor(partition);

            return(await descriptor);
        }
Пример #4
0
        internal Table(byte[] gptBuffer, uint bytesPerSector)
        {
            this.gptBuffer = gptBuffer;
            var tempHeaderOffset = ByteOperations.FindAscii(gptBuffer, "EFI PART");

            if (tempHeaderOffset == null)
            {
                throw new Exception("Bad GPT");
            }

            headerOffset      = (uint)tempHeaderOffset;
            headerSize        = ByteOperations.ReadUInt32(gptBuffer, headerOffset + 0x0C);
            tableOffset       = headerOffset + 0x200;
            FirstUsableSector = ByteOperations.ReadUInt64(gptBuffer, headerOffset + 0x28);
            LastUsableSector  = ByteOperations.ReadUInt64(gptBuffer, headerOffset + 0x30);
            var maxPartitions = ByteOperations.ReadUInt32(gptBuffer, headerOffset + 0x50);

            partitionEntrySize = ByteOperations.ReadUInt32(gptBuffer, headerOffset + 0x54);
            tableSize          = maxPartitions * partitionEntrySize;
            if (tableOffset + tableSize > gptBuffer.Length)
            {
                throw new Exception("Bad GPT");
            }

            var partitionOffset = tableOffset;

            uint number = 1;

            while (partitionOffset < tableOffset + tableSize)
            {
                var name = ByteOperations.ReadUnicodeString(gptBuffer, partitionOffset + 0x38, 0x48)
                           .TrimEnd((char)0, ' ');
                if (name.Length == 0)
                {
                    break;
                }

                var partitionTypeGuid = ByteOperations.ReadGuid(gptBuffer, partitionOffset + 0x00);
                var partitionType     = GptType.FromGuid(partitionTypeGuid);

                var currentPartition = new Partition(name, partitionType, bytesPerSector)
                {
                    FirstSector = ByteOperations.ReadUInt64(gptBuffer, partitionOffset + 0x20),
                    LastSector  = ByteOperations.ReadUInt64(gptBuffer, partitionOffset + 0x28),
                    Guid        = ByteOperations.ReadGuid(gptBuffer, partitionOffset + 0x10),
                    Attributes  = ByteOperations.ReadUInt64(gptBuffer, partitionOffset + 0x30)
                };
                Partitions.Add(currentPartition);
                partitionOffset += partitionEntrySize;
                number++;
            }
        }
Пример #5
0
        private static WmiPartition ToWmiPartition(object partition)
        {
            var gptType       = (string)partition.GetPropertyValue("GptType");
            var partitionType = gptType != null?GptType.FromGuid(Guid.Parse(gptType)) : null;

            var driveLetter = (char)partition.GetPropertyValue("DriveLetter");

            return(new WmiPartition
            {
                Number = (uint)partition.GetPropertyValue("PartitionNumber"),
                UniqueId = (string)partition.GetPropertyValue("UniqueId"),
                Guid = Guid.TryParse((string)partition.GetPropertyValue("Guid"), out var guid) ? guid : (Guid?)null,
                Root = driveLetter != 0 ? PathExtensions.GetRootPath(driveLetter) : null,
                GptType = partitionType,
                Size = new ByteSize(Convert.ToUInt64(partition.GetPropertyValue("Size"))),
            });
Пример #6
0
        public async Task SetGptType(GptType gptType)
        {
            Log.Verbose("Setting new GPT partition type {Type} to {Partition}", gptType, this);

            if (Equals(GptType, gptType))
            {
                return;
            }

            var part = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Set-Partition",
                                                 ("InputObject", part),
                                                 ("GptType", $"{{{gptType.Guid}}}")
                                                 );

            await Disk.Refresh();

            Log.Verbose("New GPT type set correctly", gptType, this);
        }
Пример #7
0
 public Task <IPartition> CreateGptPartition(GptType gptType, ByteSize desiredSize)
 {
     throw new NotImplementedException();
 }
Пример #8
0
 public Partition(string name, GptType gptType, uint bytesPerSector)
 {
     GptType             = gptType;
     Name                = name;
     this.bytesPerSector = bytesPerSector;
 }
Пример #9
0
        public async Task Execute(string partitionDescriptor, string gptTypeString)
        {
            var partition = await fileSystem.TryGetPartitionFromDescriptor(partitionDescriptor);

            await partition.DoAsync((p, ct) => p.SetGptType(GptType.FromString(gptTypeString)));
        }
Пример #10
0
 public EntryBuilder(string name, ByteSize size, GptType gptType)
 {
     this.name    = name ?? throw new ArgumentNullException(nameof(name));
     this.size    = size;
     this.gptType = gptType;
 }
Пример #11
0
 protected bool Equals(GptType other)
 {
     return(Code.Equals(other.Code));
 }
Пример #12
0
 public Task <IPartition> CreatePartition(ByteSize desiredSize, GptType gptType, string name)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 public Entry(string name, ByteSize size, GptType gptType)
 {
     Name    = name;
     Size    = size;
     GptType = gptType;
 }
Пример #14
0
 public Task SetGptType(GptType gptType)
 {
     throw new NotImplementedException();
 }