NTFileSystemAdapter.QueryFileSystem.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Utilities;
  11. namespace SMBLibrary
  12. {
  13. public partial class NTFileSystemAdapter
  14. {
  15. public NTStatus GetFileSystemInformation(out FileSystemInformation result, FileSystemInformationClass informationClass)
  16. {
  17. switch (informationClass)
  18. {
  19. case FileSystemInformationClass.FileFsVolumeInformation:
  20. {
  21. FileFsVolumeInformation information = new FileFsVolumeInformation();
  22. information.SupportsObjects = false;
  23. result = information;
  24. return NTStatus.STATUS_SUCCESS;
  25. }
  26. case FileSystemInformationClass.FileFsSizeInformation:
  27. {
  28. FileFsSizeInformation information = new FileFsSizeInformation();
  29. information.TotalAllocationUnits = m_fileSystem.Size / ClusterSize;
  30. information.AvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
  31. information.SectorsPerAllocationUnit = ClusterSize / BytesPerSector;
  32. information.BytesPerSector = BytesPerSector;
  33. result = information;
  34. return NTStatus.STATUS_SUCCESS;
  35. }
  36. case FileSystemInformationClass.FileFsDeviceInformation:
  37. {
  38. FileFsDeviceInformation information = new FileFsDeviceInformation();
  39. information.DeviceType = DeviceType.Disk;
  40. information.Characteristics = DeviceCharacteristics.IsMounted;
  41. result = information;
  42. return NTStatus.STATUS_SUCCESS;
  43. }
  44. case FileSystemInformationClass.FileFsAttributeInformation:
  45. {
  46. FileFsAttributeInformation information = new FileFsAttributeInformation();
  47. information.FileSystemAttributes = FileSystemAttributes.CasePreservedNamed | FileSystemAttributes.UnicodeOnDisk;
  48. information.MaximumComponentNameLength = 255;
  49. information.FileSystemName = m_fileSystem.Name;
  50. result = information;
  51. return NTStatus.STATUS_SUCCESS;
  52. }
  53. case FileSystemInformationClass.FileFsControlInformation:
  54. {
  55. FileFsControlInformation information = new FileFsControlInformation();
  56. information.FileSystemControlFlags = FileSystemControlFlags.ContentIndexingDisabled;
  57. information.DefaultQuotaThreshold = UInt64.MaxValue;
  58. information.DefaultQuotaLimit = UInt64.MaxValue;
  59. result = information;
  60. return NTStatus.STATUS_SUCCESS;
  61. }
  62. case FileSystemInformationClass.FileFsFullSizeInformation:
  63. {
  64. FileFsFullSizeInformation information = new FileFsFullSizeInformation();
  65. information.TotalAllocationUnits = m_fileSystem.Size / ClusterSize;
  66. information.CallerAvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
  67. information.ActualAvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
  68. information.SectorsPerAllocationUnit = ClusterSize / BytesPerSector;
  69. information.BytesPerSector = BytesPerSector;
  70. result = information;
  71. return NTStatus.STATUS_SUCCESS;
  72. }
  73. case FileSystemInformationClass.FileFsObjectIdInformation:
  74. {
  75. result = null;
  76. // STATUS_INVALID_PARAMETER is returned when the file system does not implement object IDs
  77. // See: https://msdn.microsoft.com/en-us/library/cc232106.aspx
  78. return NTStatus.STATUS_INVALID_PARAMETER;
  79. }
  80. case FileSystemInformationClass.FileFsSectorSizeInformation:
  81. {
  82. FileFsSectorSizeInformation information = new FileFsSectorSizeInformation();
  83. information.LogicalBytesPerSector = BytesPerSector;
  84. information.PhysicalBytesPerSectorForAtomicity = BytesPerSector;
  85. information.PhysicalBytesPerSectorForPerformance = BytesPerSector;
  86. information.FileSystemEffectivePhysicalBytesPerSectorForAtomicity = BytesPerSector;
  87. information.ByteOffsetForSectorAlignment = 0;
  88. information.ByteOffsetForPartitionAlignment = 0;
  89. result = information;
  90. return NTStatus.STATUS_SUCCESS;
  91. }
  92. default:
  93. {
  94. result = null;
  95. return NTStatus.STATUS_INVALID_INFO_CLASS;
  96. }
  97. }
  98. }
  99. public NTStatus SetFileSystemInformation(FileSystemInformation information)
  100. {
  101. return NTStatus.STATUS_NOT_SUPPORTED;
  102. }
  103. }
  104. }