FileFsAttributeInformation.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 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 Utilities;
  10. namespace SMBLibrary
  11. {
  12. /// <summary>
  13. /// [MS-FSCC] 2.5.1 - FileFsAttributeInformation
  14. /// </summary>
  15. public class FileFsAttributeInformation : FileSystemInformation
  16. {
  17. public const int FixedLength = 12;
  18. public FileSystemAttributes FileSystemAttributes;
  19. /// <summary>
  20. /// Maximum file name component length, in bytes, supported by the specified file system.
  21. /// The value of this field MUST be greater than zero and MUST be no more than 510.
  22. /// </summary>
  23. public uint MaximumComponentNameLength;
  24. private uint FileSystemNameLength;
  25. public string FileSystemName = String.Empty;
  26. public FileFsAttributeInformation()
  27. {
  28. }
  29. public FileFsAttributeInformation(byte[] buffer, int offset)
  30. {
  31. FileSystemAttributes = (FileSystemAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 0);
  32. MaximumComponentNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4);
  33. FileSystemNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 8);
  34. FileSystemName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)FileSystemNameLength / 2);
  35. }
  36. public override void WriteBytes(byte[] buffer, int offset)
  37. {
  38. FileSystemNameLength = (uint)(FileSystemName.Length * 2);
  39. LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)FileSystemAttributes);
  40. LittleEndianWriter.WriteUInt32(buffer, offset + 4, MaximumComponentNameLength);
  41. LittleEndianWriter.WriteUInt32(buffer, offset + 8, FileSystemNameLength);
  42. ByteWriter.WriteUTF16String(buffer, offset + 12, FileSystemName);
  43. }
  44. public override FileSystemInformationClass FileSystemInformationClass
  45. {
  46. get
  47. {
  48. return FileSystemInformationClass.FileFsAttributeInformation;
  49. }
  50. }
  51. public override int Length
  52. {
  53. get
  54. {
  55. return FixedLength + FileSystemName.Length * 2;
  56. }
  57. }
  58. }
  59. }