SMB1FileSystemHelper.QueryFileSystem.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Text;
  10. using SMBLibrary.SMB1;
  11. using Utilities;
  12. namespace SMBLibrary.Server.SMB1
  13. {
  14. public partial class SMB1FileSystemHelper
  15. {
  16. public static NTStatus GetFileSystemInformation(out QueryFSInformation result, QueryFSInformationLevel informationLevel, IFileSystem fileSystem)
  17. {
  18. switch (informationLevel)
  19. {
  20. case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
  21. {
  22. QueryFSVolumeInfo information = new QueryFSVolumeInfo();
  23. information.VolumeCreationTime = DateTime.Now;
  24. result = information;
  25. return NTStatus.STATUS_SUCCESS;
  26. }
  27. case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
  28. {
  29. QueryFSSizeInfo information = new QueryFSSizeInfo();
  30. information.TotalAllocationUnits = (ulong)(fileSystem.Size / NTFileSystemHelper.ClusterSize);
  31. information.TotalFreeAllocationUnits = (ulong)(fileSystem.FreeSpace / NTFileSystemHelper.ClusterSize);
  32. information.BytesPerSector = NTFileSystemHelper.BytesPerSector;
  33. information.SectorsPerAllocationUnit = NTFileSystemHelper.ClusterSize / NTFileSystemHelper.BytesPerSector;
  34. result = information;
  35. return NTStatus.STATUS_SUCCESS;
  36. }
  37. case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
  38. {
  39. QueryFSDeviceInfo information = new QueryFSDeviceInfo();
  40. information.DeviceCharacteristics = DeviceCharacteristics.IsMounted;
  41. information.DeviceType = DeviceType.Disk;
  42. result = information;
  43. return NTStatus.STATUS_SUCCESS;
  44. }
  45. case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
  46. {
  47. QueryFSAttibuteInfo information = new QueryFSAttibuteInfo();
  48. information.FileSystemAttributes = FileSystemAttributes.UnicodeOnDisk;
  49. information.MaxFileNameLengthInBytes = 255;
  50. information.FileSystemName = fileSystem.Name;
  51. result = information;
  52. return NTStatus.STATUS_SUCCESS;
  53. }
  54. default:
  55. {
  56. result = null;
  57. return NTStatus.STATUS_OS2_INVALID_LEVEL;
  58. }
  59. }
  60. }
  61. }
  62. }