SMB1FileStoreHelper.Set.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.IO;
  10. using System.Text;
  11. using SMBLibrary.SMB1;
  12. using Utilities;
  13. namespace SMBLibrary.Server.SMB1
  14. {
  15. internal partial class SMB1FileStoreHelper
  16. {
  17. public static NTStatus SetFileInformation(INTFileStore fileStore, object handle, SetInformation information)
  18. {
  19. if (information is SetFileBasicInfo)
  20. {
  21. SetFileBasicInfo basicInfo = (SetFileBasicInfo)information;
  22. FileBasicInformation fileBasicInfo = new FileBasicInformation();
  23. fileBasicInfo.CreationTime = basicInfo.CreationTime;
  24. fileBasicInfo.LastAccessTime = basicInfo.LastAccessTime;
  25. fileBasicInfo.LastWriteTime = basicInfo.LastWriteTime;
  26. fileBasicInfo.ChangeTime = basicInfo.LastChangeTime;
  27. fileBasicInfo.FileAttributes = (FileAttributes)basicInfo.ExtFileAttributes;
  28. fileBasicInfo.Reserved = basicInfo.Reserved;
  29. return fileStore.SetFileInformation(handle, fileBasicInfo);
  30. }
  31. else if (information is SetFileDispositionInfo)
  32. {
  33. FileDispositionInformation fileDispositionInfo = new FileDispositionInformation();
  34. fileDispositionInfo.DeletePending = ((SetFileDispositionInfo)information).DeletePending;
  35. return fileStore.SetFileInformation(handle, fileDispositionInfo);
  36. }
  37. else if (information is SetFileAllocationInfo)
  38. {
  39. // This information level is used to set the file length in bytes.
  40. // Note: the input will NOT be a multiple of the cluster size / bytes per sector.
  41. FileAllocationInformation fileAllocationInfo = new FileAllocationInformation();
  42. fileAllocationInfo.AllocationSize = ((SetFileAllocationInfo)information).AllocationSize;
  43. return fileStore.SetFileInformation(handle, fileAllocationInfo);
  44. }
  45. else if (information is SetFileEndOfFileInfo)
  46. {
  47. FileEndOfFileInformation fileEndOfFileInfo = new FileEndOfFileInformation();
  48. fileEndOfFileInfo.EndOfFile = ((SetFileEndOfFileInfo)information).EndOfFile;
  49. return fileStore.SetFileInformation(handle, fileEndOfFileInfo);
  50. }
  51. else
  52. {
  53. return NTStatus.STATUS_NOT_IMPLEMENTED;
  54. }
  55. }
  56. }
  57. }