QueryFSVolumeInfo.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Copyright (C) 2014-2017 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. private 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 = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
  31. SerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
  32. 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. VolumeLabelSize = (uint)(VolumeLabel.Length * 2);
  39. byte[] buffer = new byte[this.Length];
  40. FileTimeHelper.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. public override int Length
  48. {
  49. get
  50. {
  51. return FixedLength + VolumeLabel.Length * 2;
  52. }
  53. }
  54. public override QueryFSInformationLevel InformationLevel
  55. {
  56. get
  57. {
  58. return QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO;
  59. }
  60. }
  61. }
  62. }