/// <summary> /// 根据Gpt分区表项编辑Gpt分区项; /// </summary> /// <param name="gptDeviceInfo"></param> /// <param name="devieStoken"></param> private static void EditGptPartEntries(GPTDeviceInfo gptDeviceInfo, DeviceStoken deviceStoken) { if (gptDeviceInfo == null) { throw new ArgumentNullException(nameof(gptDeviceInfo)); } if (deviceStoken == null) { throw new ArgumentNullException(nameof(deviceStoken)); } gptDeviceInfo.GptPartInfos.ForEach(gptPartInfo => { //若EFIPTable为空,则非分区; if (gptPartInfo.EFIPTable == null) { return; } var efiTable = gptPartInfo.EFIPTable.StructInstance; var entry = PartitionEntryFactory.CreatePartitionEntry(Constants.PartEntryKey_GPT); var entryStoken = entry.GetStoken(Constants.PartEntryKey_GPT); entryStoken.TypeGUID = Constants.PartEntryType_GPT; entryStoken.Name = gptPartInfo.EFIPTable.StructInstance.PartTabName; entryStoken.StartLBA = (long)gptPartInfo.StGptPTable.nOffset; entryStoken.Size = Marshal.SizeOf(typeof(StEFIPTable)); entryStoken.PartStartLBA = (long)efiTable.PartTabStartLBA * deviceStoken.BlockSize; entryStoken.PartSize = (long)(efiTable.PartTabEndLBA - efiTable.PartTabStartLBA) * deviceStoken.BlockSize; deviceStoken.PartitionEntries.Add(entry); }); }
/// <summary> /// 根据Dos分区表项编辑Dos分区项; /// </summary> /// <param name="dosDeviceInfo"></param> private static void EditDosPartEntries(DOSDeviceInfo dosDeviceInfo, DeviceStoken deviceStoken) { if (dosDeviceInfo == null) { throw new ArgumentNullException(nameof(dosDeviceInfo)); } if (deviceStoken == null) { throw new ArgumentNullException(nameof(deviceStoken)); } //拓展分区偏移; long extendPartLBA = 0; dosDeviceInfo.DosPartInfos.ForEach(dosPartInfo => { //确定起始绝对位移; long startLBA = 0; long?partStartLBA = null; long?partSize = dosPartInfo.InfoDisk.StructInstance.AllSector * SECSIZE; switch (dosPartInfo.DosPTable.StDosPTable.DosPartType) { case DosPartType.Error: return; case DosPartType.Main: startLBA = (long)dosPartInfo.DosPTable.StDosPTable.nOffset; partStartLBA = dosPartInfo.InfoDisk.StructInstance.HeadSector * SECSIZE; break; case DosPartType.Extend: extendPartLBA += dosPartInfo.InfoDisk.StructInstance.HeadSector * SECSIZE; startLBA = (long)dosPartInfo.DosPTable.StDosPTable.nOffset; partSize = null; partStartLBA = null; break; case DosPartType.Logic: startLBA = (long)dosPartInfo.DosPTable.StDosPTable.nOffset; partStartLBA = extendPartLBA + dosPartInfo.InfoDisk.StructInstance.HeadSector * SECSIZE; break; default: break; } var entry = PartitionEntryFactory.CreatePartitionEntry(Constants.PartEntryKey_DOS); var entryStoken = entry.GetStoken(Constants.PartEntryKey_DOS); entryStoken.TypeGUID = FromDosPartTypeToCons(dosPartInfo.DosPTable.StDosPTable.DosPartType); entryStoken.StartLBA = startLBA; entryStoken.Size = Marshal.SizeOf(typeof(StInFoDisk)); entryStoken.PartStartLBA = partStartLBA; entryStoken.PartSize = partSize; entryStoken.SetInstance(dosPartInfo, Constants.PartitionEntryStokenTag_DOS); deviceStoken.PartitionEntries.Add(entry); }); }