QueryFSVolumeInfo.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_QUERY_FS_VOLUME_INFO
  15. /// </summary>
  16. public class QueryFSVolumeInfo : QueryFSInformation
  17. {
  18. public const int FixedLength = 18;
  19. public DateTime VolumeCreationTime;
  20. public uint SerialNumber;
  21. //uint VolumeLabelSize;
  22. public ushort Reserved;
  23. public string VolumeLabel; // Unicode
  24. public QueryFSVolumeInfo()
  25. {
  26. VolumeLabel = String.Empty;
  27. }
  28. public QueryFSVolumeInfo(byte[] buffer, int offset)
  29. {
  30. VolumeCreationTime = SMBHelper.ReadFileTime(buffer, offset + 0);
  31. SerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
  32. uint volumeLabelSize = LittleEndianConverter.ToUInt32(buffer, offset + 12);
  33. Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 16);
  34. VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)volumeLabelSize);
  35. }
  36. public override byte[] GetBytes(bool isUnicode)
  37. {
  38. uint volumeLabelSize = (uint)(VolumeLabel.Length * 2);
  39. byte[] buffer = new byte[FixedLength + volumeLabelSize];
  40. SMBHelper.WriteFileTime(buffer, 0, VolumeCreationTime);
  41. LittleEndianWriter.WriteUInt32(buffer, 8, SerialNumber);
  42. LittleEndianWriter.WriteUInt32(buffer, 12, volumeLabelSize);
  43. LittleEndianWriter.WriteUInt16(buffer, 16, Reserved);
  44. ByteWriter.WriteUTF16String(buffer, 18, VolumeLabel);
  45. return buffer;
  46. }
  47. }
  48. }