SparseExtentHeader.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.VMDK
  12. {
  13. public class SparseExtentHeader
  14. {
  15. private const string ValidSignature = "KDMV";
  16. public string Signature; // MagicNumber
  17. public uint Version;
  18. public uint Flags;
  19. public ulong Capacity; // multiple of the grain size
  20. public ulong GrainSize; // Expressed in sectors
  21. public ulong DescriptorOffset; // Expressed in sectors
  22. public ulong DescriptorSize; // Expressed in sectors
  23. public uint NumGTEsPerGT;
  24. public ulong RGDOffset; // Expressed in sectors
  25. public ulong GDOffset; // Expressed in sectors
  26. public ulong OverHead;
  27. public bool UncleanShutdown; // Stored as byte
  28. public char SingleEndLineChar;
  29. public char NonEndLineChar;
  30. public char DoubleEndLineChar1;
  31. public char DoubleEndLineChar2;
  32. public ushort CompressionAlgirithm;
  33. public SparseExtentHeader()
  34. {
  35. }
  36. public SparseExtentHeader(byte[] buffer)
  37. {
  38. Signature = ByteReader.ReadAnsiString(buffer, 0x00, 4);
  39. Version = LittleEndianConverter.ToUInt32(buffer, 0x04);
  40. Flags = LittleEndianConverter.ToUInt32(buffer, 0x08);
  41. Capacity = LittleEndianConverter.ToUInt64(buffer, 0x0C);
  42. GrainSize = LittleEndianConverter.ToUInt64(buffer, 0x14);
  43. DescriptorOffset = LittleEndianConverter.ToUInt64(buffer, 0x1C);
  44. DescriptorSize = LittleEndianConverter.ToUInt64(buffer, 0x24);
  45. NumGTEsPerGT = LittleEndianConverter.ToUInt32(buffer, 0x2C);
  46. RGDOffset = LittleEndianConverter.ToUInt64(buffer, 0x30);
  47. GDOffset = LittleEndianConverter.ToUInt64(buffer, 0x38);
  48. OverHead = LittleEndianConverter.ToUInt64(buffer, 0x40);
  49. UncleanShutdown = ByteReader.ReadByte(buffer, 0x48) == 1;
  50. SingleEndLineChar = (char)ByteReader.ReadByte(buffer, 0x49);
  51. NonEndLineChar = (char)ByteReader.ReadByte(buffer, 0x4A);
  52. DoubleEndLineChar1 = (char)ByteReader.ReadByte(buffer, 0x4B);
  53. DoubleEndLineChar2 = (char)ByteReader.ReadByte(buffer, 0x4C);
  54. CompressionAlgirithm = (char)LittleEndianConverter.ToUInt16(buffer, 0x4D);
  55. }
  56. public bool IsValid
  57. {
  58. get
  59. {
  60. return String.Equals(Signature, ValidSignature);
  61. }
  62. }
  63. public bool IsValidAndSupported
  64. {
  65. get
  66. {
  67. return this.IsValid && (Version == 1) && (CompressionAlgirithm == 0);
  68. }
  69. }
  70. }
  71. }