DiskGroupRecord.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. public class DiskGroupRecord : DatabaseRecord
  14. {
  15. public Guid DiskGroupGuid;
  16. public Guid DiskSetGuid; // revision 4 only
  17. // 4 zeros (probably reserved for Disk Group Flags)
  18. public ulong CommitTransactionID;
  19. public uint NumberOfConfigCopies; // 0xFFFFFFFF means 'all', 0 means 'default' (DMDiag list this as 'copies: nconfig=x')
  20. public uint NumberOfLogCopies; // 0xFFFFFFFF means 'all', 0 means 'default' (DMDiag list this as 'copies: nlog=x')
  21. public uint MinorsGreaterThanOrEqualTo; // DMDiag reports this as 'minors: >= x', more than 4 bytes are reported as error
  22. public DiskGroupRecord(List<DatabaseRecordFragment> fragments) : base(fragments)
  23. {
  24. // Data begins at 0x10 (VBLK header is at 0x00)
  25. int offset = 0x00; // relative to Data
  26. ReadCommonFields(this.Data, ref offset);
  27. if (RecordRevision == 3)
  28. {
  29. DiskGroupGuid = new Guid(ReadVarString(this.Data, ref offset));
  30. }
  31. else if (RecordRevision == 4)
  32. {
  33. DiskGroupGuid = BigEndianReader.ReadGuidBytes(this.Data, ref offset);
  34. DiskSetGuid = BigEndianReader.ReadGuidBytes(this.Data, ref offset);
  35. }
  36. else
  37. {
  38. throw new NotImplementedException("Unsupported record revision");
  39. }
  40. offset += 4; // 4 Zeros
  41. CommitTransactionID = BigEndianReader.ReadUInt64(this.Data, ref offset);
  42. if (HasNumberOfCopiesFlag)
  43. {
  44. NumberOfConfigCopies = ReadVarUInt(this.Data, ref offset);
  45. NumberOfLogCopies = ReadVarUInt(this.Data, ref offset);
  46. }
  47. if (HasMinorsFlag)
  48. {
  49. MinorsGreaterThanOrEqualTo = ReadVarUInt(this.Data, ref offset);
  50. }
  51. }
  52. public override byte[] GetDataBytes()
  53. {
  54. int dataLength = 8; // header fixed length components
  55. dataLength += VarULongSize(DiskGroupId);
  56. dataLength += Name.Length + 1;
  57. if (RecordRevision == 3)
  58. {
  59. dataLength += 12; // fixed length components
  60. dataLength += DiskGroupGuid.ToString().Length + 1;
  61. }
  62. else // RecordRevision == 4
  63. {
  64. dataLength += 44; // fixed length components
  65. }
  66. if (HasNumberOfCopiesFlag)
  67. {
  68. dataLength += VarUIntSize(NumberOfConfigCopies);
  69. dataLength += VarUIntSize(NumberOfLogCopies);
  70. }
  71. if (HasMinorsFlag)
  72. {
  73. dataLength += VarUIntSize(MinorsGreaterThanOrEqualTo);
  74. }
  75. byte[] data = new byte[dataLength];
  76. int offset = 0x00;
  77. WriteCommonFields(data, ref offset);
  78. if (RecordRevision == 3)
  79. {
  80. WriteVarString(data, ref offset, DiskGroupGuid.ToString());
  81. }
  82. else
  83. {
  84. BigEndianWriter.WriteGuidBytes(data, ref offset, DiskGroupGuid);
  85. BigEndianWriter.WriteGuidBytes(data, ref offset, DiskSetGuid);
  86. }
  87. offset += 4;
  88. BigEndianWriter.WriteUInt64(data, ref offset, CommitTransactionID);
  89. if (HasNumberOfCopiesFlag)
  90. {
  91. WriteVarUInt(data, ref offset, NumberOfConfigCopies);
  92. WriteVarUInt(data, ref offset, NumberOfLogCopies);
  93. }
  94. if (HasMinorsFlag)
  95. {
  96. WriteVarUInt(data, ref offset, MinorsGreaterThanOrEqualTo);
  97. }
  98. return data;
  99. }
  100. public ulong DiskGroupId
  101. {
  102. get
  103. {
  104. return this.Id;
  105. }
  106. }
  107. public string DiskGroupGuidString
  108. {
  109. get
  110. {
  111. return DiskGroupGuid.ToString();
  112. }
  113. }
  114. /// <summary>
  115. /// If this flag is not rpesent, DMDiag will report 'copies: nconfig=default nlog=default'
  116. /// </summary>
  117. public bool HasNumberOfCopiesFlag
  118. {
  119. get
  120. {
  121. return ((Flags & 0x08) != 0);
  122. }
  123. }
  124. public bool HasMinorsFlag
  125. {
  126. get
  127. {
  128. return ((Flags & 0x10) != 0);
  129. }
  130. }
  131. }
  132. }