MftSegmentReference.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.FileSystems.NTFS
  12. {
  13. public class MftSegmentReference
  14. {
  15. public const int Length = 8;
  16. public long SegmentNumber; // 6 bytes
  17. public ushort SequenceNumber;
  18. public MftSegmentReference(byte[] buffer, int offset)
  19. {
  20. SegmentNumber = (long)(LittleEndianConverter.ToUInt64(buffer, offset + 0x00) & 0xFFFFFFFFFFFF);
  21. SequenceNumber = LittleEndianConverter.ToUInt16(buffer, offset + 0x06);
  22. }
  23. public void WriteBytes(byte[] buffer, int offset)
  24. {
  25. LittleEndianWriter.WriteInt64(buffer, offset + 0x00, SegmentNumber & 0xFFFFFFFFFFFF);
  26. LittleEndianWriter.WriteUInt16(buffer, offset + 0x06, SequenceNumber);
  27. }
  28. public static int IndexOfSegmentNumber(List<MftSegmentReference> list, long segmentNumber)
  29. {
  30. for(int index = 0; index < list.Count; index++)
  31. {
  32. if (list[index].SegmentNumber == segmentNumber)
  33. {
  34. return index;
  35. }
  36. }
  37. return -1;
  38. }
  39. public static bool ContainsSegmentNumber(List<MftSegmentReference> list, long segmentNumber)
  40. {
  41. return (IndexOfSegmentNumber(list, segmentNumber) >= 0);
  42. }
  43. }
  44. }