AccessModeOptions.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2014-2016 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. public enum AccessMode : byte
  14. {
  15. Read = 0x00,
  16. Write = 0x01,
  17. ReadWrite = 0x02,
  18. Execute = 0x03,
  19. }
  20. public enum SharingMode : byte
  21. {
  22. Compatibility = 0x00,
  23. DenyReadWriteExecute = 0x01, // Exclusive use
  24. DenyWrite = 0x02,
  25. DenyReadExecute = 0x03,
  26. DenyNothing = 0x04,
  27. }
  28. public enum ReferenceLocality : byte
  29. {
  30. Unknown = 0x00,
  31. Sequential = 0x01,
  32. Random = 0x02,
  33. RandomWithLocality = 0x03,
  34. }
  35. public enum CachedMode : byte
  36. {
  37. CachingAllowed = 0x00,
  38. DoNotCacheFile = 0x01,
  39. }
  40. public enum WriteThroughMode : byte
  41. {
  42. Disabled = 0x00,
  43. /// <summary>
  44. /// Write-through mode.
  45. /// If this flag is set, then no read ahead or write behind is allowed on this file or device.
  46. /// When the response is returned, data is expected to be on the disk or device.
  47. /// </summary>
  48. WriteThrough = 0x01,
  49. }
  50. public struct AccessModeOptions // 2 bytes
  51. {
  52. public AccessMode AccessMode;
  53. public SharingMode SharingMode;
  54. public ReferenceLocality ReferenceLocality;
  55. public CachedMode CachedMode;
  56. public WriteThroughMode WriteThroughMode;
  57. public AccessModeOptions(byte[] buffer, int offset)
  58. {
  59. AccessMode = (AccessMode)(buffer[offset] & 0x07);
  60. SharingMode = (SharingMode)((buffer[offset] & 0x70) >> 4);
  61. ReferenceLocality = (ReferenceLocality)(buffer[offset + 1] & 0x07);
  62. CachedMode = (CachedMode)((buffer[offset + 1] & 0x10) >> 4);
  63. WriteThroughMode = (WriteThroughMode)((buffer[offset + 1] & 0x40) >> 6);
  64. }
  65. public void WriteBytes(byte[] buffer, int offset)
  66. {
  67. buffer[offset + 0] = (byte)((byte)AccessMode & 0x07);
  68. buffer[offset + 0] |= (byte)(((byte)SharingMode << 4) & 0x70);
  69. buffer[offset + 1] = (byte)((byte)ReferenceLocality & 0x07);
  70. buffer[offset + 1] |= (byte)(((byte)CachedMode << 4) & 0x10);
  71. buffer[offset + 1] |= (byte)(((byte)WriteThroughMode << 6) & 0x40);
  72. }
  73. public static AccessModeOptions Read(byte[] buffer, ref int offset)
  74. {
  75. offset += 2;
  76. return new AccessModeOptions(buffer, offset - 2);
  77. }
  78. }
  79. }