TOCRegion.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.LogicalDiskManager
  12. {
  13. [Flags]
  14. public enum TOCRegionFlags : ushort
  15. {
  16. NotExist = 0x01, // The present of this flag hide the region from display in DMDiag
  17. New = 0x02, // As reported by DMDiag
  18. Delete = 0x04, // As reported by DMDiag
  19. Disabled = 0x08 // As reported by DMDiag
  20. }
  21. public class TOCRegion
  22. {
  23. public const int Length = 34;
  24. public string Name; // 'config' or 'log' (8 characters max)
  25. public TOCRegionFlags RegionFlags;
  26. public ulong StartLBA; // Sector Offset from PrivateRegionStart
  27. public ulong SizeLBA; // Size of the region
  28. public ushort Unknown; // 00 06 ( other values will make DMDiag to report the database as invalid )
  29. public ushort CopyNumber; // copy number, always 00 01
  30. // 4 zero bytes
  31. public TOCRegion(byte[] buffer, int offset)
  32. {
  33. Name = ByteReader.ReadAnsiString(buffer, offset + 0x00, 8).Trim('\0');
  34. RegionFlags = (TOCRegionFlags)BigEndianConverter.ToUInt16(buffer, offset + 0x08);
  35. StartLBA = BigEndianConverter.ToUInt64(buffer, offset + 0x0A);
  36. SizeLBA = BigEndianConverter.ToUInt64(buffer, offset + 0x12);
  37. Unknown = BigEndianConverter.ToUInt16(buffer, offset + 0x1A);
  38. CopyNumber = BigEndianConverter.ToUInt16(buffer, offset + 0x1C);
  39. }
  40. public void WriteBytes(byte[] buffer, int offset)
  41. {
  42. ByteWriter.WriteAnsiString(buffer, offset + 0x00, Name, 8);
  43. BigEndianWriter.WriteUInt16(buffer, offset + 0x08, (ushort)RegionFlags);
  44. BigEndianWriter.WriteUInt64(buffer, offset + 0x0A, StartLBA);
  45. BigEndianWriter.WriteUInt64(buffer, offset + 0x12, SizeLBA);
  46. BigEndianWriter.WriteUInt16(buffer, offset + 0x1A, Unknown);
  47. BigEndianWriter.WriteUInt16(buffer, offset + 0x1C, CopyNumber);
  48. }
  49. }
  50. }