OpenMode.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. namespace SMBLibrary.SMB1
  11. {
  12. public enum CreateFile : byte
  13. {
  14. ReturnErrorIfNotExist = 0x00,
  15. CreateIfNotExist = 0x01,
  16. }
  17. public enum FileExistsOpts : byte
  18. {
  19. ReturnError = 0x00,
  20. Append = 0x01,
  21. TruncateToZero = 0x02,
  22. }
  23. public struct OpenMode // 2 bytes
  24. {
  25. public FileExistsOpts FileExistsOpts;
  26. public CreateFile CreateFile;
  27. public OpenMode(byte[] buffer, int offset)
  28. {
  29. FileExistsOpts = (FileExistsOpts)(buffer[offset] & 0x3);
  30. CreateFile = (CreateFile)((buffer[offset] & 0x10) >> 4);
  31. }
  32. public void WriteBytes(byte[] buffer, int offset)
  33. {
  34. buffer[0] = (byte)FileExistsOpts;
  35. buffer[0] |= (byte)((byte)CreateFile << 4);
  36. }
  37. public static OpenMode Read(byte[] buffer, ref int offset)
  38. {
  39. offset += 2;
  40. return new OpenMode(buffer, offset - 2);
  41. }
  42. }
  43. }