GuidPartitionEntryCollection.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace DiskAccessLibrary
  12. {
  13. public class GuidPartitionEntryCollection
  14. {
  15. public static int GetIndexOfPartitionGuid(List<GuidPartitionEntry> entries, Guid partitionGuid)
  16. {
  17. for (int index = 0; index < entries.Count; index++)
  18. {
  19. if (entries[index].PartitionGuid.Equals(partitionGuid))
  20. {
  21. return index;
  22. }
  23. }
  24. return -1;
  25. }
  26. public static bool ContainsPartitionTypeGuid(List<GuidPartitionEntry> entries, Guid typeGuid)
  27. {
  28. int index = GetIndexOfPartitionTypeGuid(entries, typeGuid);
  29. return (index >= 0);
  30. }
  31. public static int GetIndexOfPartitionTypeGuid(List<GuidPartitionEntry> entries, Guid typeGuid)
  32. {
  33. for (int index = 0; index < entries.Count; index++)
  34. {
  35. if (entries[index].PartitionTypeGuid.Equals(typeGuid))
  36. {
  37. return index;
  38. }
  39. }
  40. return -1;
  41. }
  42. public static byte[] GetBytes(GuidPartitionTableHeader header, List<GuidPartitionEntry> entries)
  43. {
  44. byte[] buffer = new byte[header.NumberOfPartitionEntries * header.SizeOfPartitionEntry];
  45. int count = (int)Math.Min(header.NumberOfPartitionEntries, entries.Count);
  46. for (int index = 0; index < count; index++)
  47. {
  48. entries[index].WriteBytes(buffer, index * (int)header.SizeOfPartitionEntry);
  49. }
  50. return buffer;
  51. }
  52. }
  53. }