SetInformationHelper.cs 2.6 KB

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