Browse Source

Splitted InfoHelper to SMB1FileSystemHelper.Find / SMB1FileSystemHelper.Query / SMB1FileSystemHelper.QueryFileSystem

Tal Aloni 8 years ago
parent
commit
841a267cdf

+ 3 - 1
SMBLibrary/SMBLibrary.csproj

@@ -128,7 +128,6 @@
     <Compile Include="Server\Shares\NamedPipeShare.cs" />
     <Compile Include="Server\Shares\ShareCollection.cs" />
     <Compile Include="Server\SMB1\FileSystemResponseHelper.cs" />
-    <Compile Include="Server\SMB1\InfoHelper.cs" />
     <Compile Include="Server\SMB1\NegotiateHelper.cs" />
     <Compile Include="Server\SMB1\NTCreateHelper.cs" />
     <Compile Include="Server\SMB1\NTTransactHelper.cs" />
@@ -136,6 +135,9 @@
     <Compile Include="Server\SMB1\ReadWriteResponseHelper.cs" />
     <Compile Include="Server\SMB1\ServerResponseHelper.cs" />
     <Compile Include="Server\SMB1\SessionSetupHelper.cs" />
+    <Compile Include="Server\SMB1\SMB1FileSystemHelper.Find.cs" />
+    <Compile Include="Server\SMB1\SMB1FileSystemHelper.Query.cs" />
+    <Compile Include="Server\SMB1\SMB1FileSystemHelper.QueryFileSystem.cs" />
     <Compile Include="Server\SMB1\Transaction2SubcommandHelper.cs" />
     <Compile Include="Server\SMB1\TransactionHelper.cs" />
     <Compile Include="Server\SMB1\TransactionSubcommandHelper.cs" />

+ 1 - 1
SMBLibrary/Server/SMB1/FileSystemResponseHelper.cs

@@ -200,7 +200,7 @@ namespace SMBLibrary.Server.SMB1
             }
 
             QueryInformationResponse response = new QueryInformationResponse();
-            response.FileAttributes = InfoHelper.GetFileAttributes(entry);
+            response.FileAttributes = SMB1FileSystemHelper.GetFileAttributes(entry);
             response.LastWriteTime = entry.LastWriteTime;
             response.FileSize = (uint)Math.Min(UInt32.MaxValue, entry.Size);
 

+ 0 - 332
SMBLibrary/Server/SMB1/InfoHelper.cs

@@ -1,332 +0,0 @@
-/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- * 
- * You can redistribute this program and/or modify it under the terms of
- * the GNU Lesser Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using SMBLibrary.SMB1;
-using Utilities;
-
-namespace SMBLibrary.Server.SMB1
-{
-    public class InfoHelper
-    {
-        internal static FindInformation FromFileSystemEntry(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
-        {
-            switch (informationLevel)
-            {
-                case FindInformationLevel.SMB_INFO_STANDARD:
-                    {
-                        FindInfoStandard result = new FindInfoStandard(returnResumeKeys);
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
-                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
-                        result.Attributes = GetFileAttributes(entry);
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
-                    {
-                        FindInfoQueryEASize result = new FindInfoQueryEASize(returnResumeKeys);
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
-                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
-                        result.Attributes = GetFileAttributes(entry);
-                        result.EASize = 0;
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
-                    {
-                        FindInfoQueryExtendedAttributesFromList result = new FindInfoQueryExtendedAttributesFromList(returnResumeKeys);
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
-                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
-                        result.Attributes = GetFileAttributes(entry);
-                        result.ExtendedAttributeList = new FullExtendedAttributeList();
-                        return result;
-                    }
-                case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
-                    {
-                        FindFileDirectoryInfo result = new FindFileDirectoryInfo();
-                        result.CreationTime = entry.CreationTime;
-                        result.LastAccessTime = entry.LastAccessTime;
-                        result.LastWriteTime = entry.LastWriteTime;
-                        result.LastAttrChangeTime = entry.LastWriteTime;
-                        result.EndOfFile = entry.Size;
-                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
-                    {
-                        FindFileFullDirectoryInfo result = new FindFileFullDirectoryInfo();
-                        result.CreationTime = entry.CreationTime;
-                        result.LastAccessTime = entry.LastAccessTime;
-                        result.LastWriteTime = entry.LastWriteTime;
-                        result.LastAttrChangeTime = entry.LastWriteTime;
-                        result.EndOfFile = entry.Size;
-                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
-                    {
-                        FindFileNamesInfo result = new FindFileNamesInfo();
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
-                    {
-                        FindFileBothDirectoryInfo result = new FindFileBothDirectoryInfo();
-                        result.CreationTime = entry.CreationTime;
-                        result.LastAccessTime = entry.LastAccessTime;
-                        result.LastWriteTime = entry.LastWriteTime;
-                        result.LastChangeTime = entry.LastWriteTime;
-                        result.EndOfFile = entry.Size;
-                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
-                        result.ShortName = NTFileSystemHelper.GetShortName(entry.Name);
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                default:
-                    {
-                        throw new UnsupportedInformationLevelException();
-                    }
-            }
-        }
-
-        internal static QueryInformation FromFileSystemEntry(FileSystemEntry entry, bool deletePending, QueryInformationLevel informationLevel)
-        {
-            switch (informationLevel)
-            {
-                case QueryInformationLevel.SMB_INFO_STANDARD:
-                    {
-                        QueryInfoStandard result = new QueryInfoStandard();
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
-                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_INFO_QUERY_EA_SIZE:
-                    {
-                        QueryEASize result = new QueryEASize();
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
-                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
-                        result.Attributes = GetFileAttributes(entry);
-                        result.EASize = 0;
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
-                    {
-                        throw new NotImplementedException();
-                    }
-                case QueryInformationLevel.SMB_INFO_QUERY_ALL_EAS:
-                    {
-                        throw new NotImplementedException();
-                    }
-                case QueryInformationLevel.SMB_INFO_IS_NAME_VALID:
-                    {
-                        throw new NotImplementedException();
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
-                    {
-                        QueryFileBasicInfo result = new QueryFileBasicInfo();
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.LastChangeTime = entry.LastWriteTime;
-                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
-                    {
-                        QueryFileStandardInfo result = new QueryFileStandardInfo();
-                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.EndOfFile = entry.Size;
-                        result.DeletePending = deletePending;
-                        result.Directory = entry.IsDirectory;
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
-                    {
-                        QueryFileExtendedAttributeInfo result = new QueryFileExtendedAttributeInfo();
-                        result.EASize = 0;
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
-                    {
-                        QueryFileNameInfo result = new QueryFileNameInfo();
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
-                    {
-                        QueryFileAllInfo result = new QueryFileAllInfo();
-                        result.CreationDateTime = entry.CreationTime;
-                        result.LastAccessDateTime = entry.LastAccessTime;
-                        result.LastWriteDateTime = entry.LastWriteTime;
-                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
-                        result.LastChangeTime = entry.LastWriteTime;
-                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.EndOfFile = entry.Size;
-                        result.DeletePending = deletePending;
-                        result.Directory = entry.IsDirectory;
-                        result.EASize = 0;
-                        result.FileName = entry.Name;
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
-                    {
-                        QueryFileAltNameInfo result = new QueryFileAltNameInfo();
-                        result.FileName = NTFileSystemHelper.GetShortName(entry.Name);
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
-                    {
-                        QueryFileStreamInfo result = new QueryFileStreamInfo();
-                        result.StreamSize = entry.Size;
-                        result.StreamAllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
-                        result.StreamName = "::$DATA";
-                        return result;
-                    }
-                case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
-                    {
-                        QueryFileCompressionInfo result = new QueryFileCompressionInfo();
-                        result.CompressionFormat = CompressionFormat.COMPRESSION_FORMAT_NONE;
-                        return result;
-                    }
-                default:
-                    {
-                        throw new UnsupportedInformationLevelException();
-                    }
-            }
-        }
-
-        internal static QueryFSInformation GetFSInformation(QueryFSInformationLevel informationLevel, IFileSystem fileSystem)
-        {
-            switch (informationLevel)
-            {
-                case QueryFSInformationLevel.SMB_INFO_ALLOCATION:
-                    {
-                        QueryFSInfoAllocation result = new QueryFSInfoAllocation();
-                        result.FileSystemID = 0;
-                        result.SectorUnit = NTFileSystemHelper.ClusterSize / NTFileSystemHelper.BytesPerSector;
-                        result.UnitsTotal = (uint)Math.Min(fileSystem.Size / NTFileSystemHelper.ClusterSize, UInt32.MaxValue);
-                        result.UnitsAvailable = (uint)Math.Min(fileSystem.FreeSpace / NTFileSystemHelper.ClusterSize, UInt32.MaxValue);
-                        result.Sector = NTFileSystemHelper.BytesPerSector;
-                        return result;
-                    }
-                case QueryFSInformationLevel.SMB_INFO_VOLUME:
-                    {
-                        QueryFSInfoVolume result = new QueryFSInfoVolume();
-                        result.VolumeLabel = String.Empty;
-                        result.VolumeSerialNumber = 0;
-                        return result;
-                    }
-                case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
-                    {
-                        QueryFSVolumeInfo result = new QueryFSVolumeInfo();
-                        result.VolumeCreationTime = DateTime.Now;
-                        return result;
-                    }
-                case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
-                    {
-                        QueryFSSizeInfo result = new QueryFSSizeInfo();
-                        result.TotalAllocationUnits = (ulong)(fileSystem.Size / NTFileSystemHelper.ClusterSize);
-                        result.TotalFreeAllocationUnits = (ulong)(fileSystem.FreeSpace / NTFileSystemHelper.ClusterSize);
-                        result.BytesPerSector = NTFileSystemHelper.BytesPerSector;
-                        result.SectorsPerAllocationUnit = NTFileSystemHelper.ClusterSize / NTFileSystemHelper.BytesPerSector;
-                        return result;
-                    }
-                case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
-                    {
-                        QueryFSDeviceInfo result = new QueryFSDeviceInfo();
-                        result.DeviceCharacteristics = DeviceCharacteristics.IsMounted;
-                        result.DeviceType = DeviceType.Disk;
-                        return result;
-                    }
-                case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
-                    {
-                        QueryFSAttibuteInfo result = new QueryFSAttibuteInfo();
-                        result.FileSystemAttributes = FileSystemAttributes.UnicodeOnDisk;
-                        result.MaxFileNameLengthInBytes = 255;
-                        result.FileSystemName = fileSystem.Name;
-                        return result;
-                    }
-                default:
-                    {
-                        throw new UnsupportedInformationLevelException();
-                    }
-            }
-        }
-
-        public static SMBFileAttributes GetFileAttributes(FileSystemEntry entry)
-        {
-            SMBFileAttributes attributes = SMBFileAttributes.Normal;
-            if (entry.IsHidden)
-            {
-                attributes |= SMBFileAttributes.Hidden;
-            }
-            if (entry.IsReadonly)
-            {
-                attributes |= SMBFileAttributes.ReadOnly;
-            }
-            if (entry.IsArchived)
-            {
-                attributes |= SMBFileAttributes.Archive;
-            }
-            if (entry.IsDirectory)
-            {
-                attributes |= SMBFileAttributes.Directory;
-            }
-
-            return attributes;
-        }
-
-        public static ExtendedFileAttributes GetExtendedFileAttributes(FileSystemEntry entry)
-        {
-            ExtendedFileAttributes attributes = 0;
-            if (entry.IsHidden)
-            {
-                attributes |= ExtendedFileAttributes.Hidden;
-            }
-            if (entry.IsReadonly)
-            {
-                attributes |= ExtendedFileAttributes.Readonly;
-            }
-            if (entry.IsArchived)
-            {
-                attributes |= ExtendedFileAttributes.Archive;
-            }
-            if (entry.IsDirectory)
-            {
-                attributes |= ExtendedFileAttributes.Directory;
-            }
-
-            if ((uint)attributes == 0)
-            {
-                attributes = ExtendedFileAttributes.Normal;
-            }
-
-            return attributes;
-        }
-    }
-}

+ 111 - 0
SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Find.cs

@@ -0,0 +1,111 @@
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using SMBLibrary.SMB1;
+using Utilities;
+
+namespace SMBLibrary.Server.SMB1
+{
+    public partial class SMB1FileSystemHelper
+    {
+        public static FindInformation GetFindInformation(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
+        {
+            switch (informationLevel)
+            {
+                case FindInformationLevel.SMB_INFO_STANDARD:
+                    {
+                        FindInfoStandard result = new FindInfoStandard(returnResumeKeys);
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
+                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
+                        result.Attributes = GetFileAttributes(entry);
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
+                    {
+                        FindInfoQueryEASize result = new FindInfoQueryEASize(returnResumeKeys);
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
+                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
+                        result.Attributes = GetFileAttributes(entry);
+                        result.EASize = 0;
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
+                    {
+                        FindInfoQueryExtendedAttributesFromList result = new FindInfoQueryExtendedAttributesFromList(returnResumeKeys);
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
+                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
+                        result.Attributes = GetFileAttributes(entry);
+                        result.ExtendedAttributeList = new FullExtendedAttributeList();
+                        return result;
+                    }
+                case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
+                    {
+                        FindFileDirectoryInfo result = new FindFileDirectoryInfo();
+                        result.CreationTime = entry.CreationTime;
+                        result.LastAccessTime = entry.LastAccessTime;
+                        result.LastWriteTime = entry.LastWriteTime;
+                        result.LastAttrChangeTime = entry.LastWriteTime;
+                        result.EndOfFile = entry.Size;
+                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
+                    {
+                        FindFileFullDirectoryInfo result = new FindFileFullDirectoryInfo();
+                        result.CreationTime = entry.CreationTime;
+                        result.LastAccessTime = entry.LastAccessTime;
+                        result.LastWriteTime = entry.LastWriteTime;
+                        result.LastAttrChangeTime = entry.LastWriteTime;
+                        result.EndOfFile = entry.Size;
+                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
+                    {
+                        FindFileNamesInfo result = new FindFileNamesInfo();
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
+                    {
+                        FindFileBothDirectoryInfo result = new FindFileBothDirectoryInfo();
+                        result.CreationTime = entry.CreationTime;
+                        result.LastAccessTime = entry.LastAccessTime;
+                        result.LastWriteTime = entry.LastWriteTime;
+                        result.LastChangeTime = entry.LastWriteTime;
+                        result.EndOfFile = entry.Size;
+                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
+                        result.ShortName = NTFileSystemHelper.GetShortName(entry.Name);
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                default:
+                    {
+                        throw new UnsupportedInformationLevelException();
+                    }
+            }
+        }
+    }
+}

+ 180 - 0
SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Query.cs

@@ -0,0 +1,180 @@
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using SMBLibrary.SMB1;
+using Utilities;
+
+namespace SMBLibrary.Server.SMB1
+{
+    public partial class SMB1FileSystemHelper
+    {
+        public static QueryInformation GetFileInformation(FileSystemEntry entry, bool deletePending, QueryInformationLevel informationLevel)
+        {
+            switch (informationLevel)
+            {
+                case QueryInformationLevel.SMB_INFO_STANDARD:
+                    {
+                        QueryInfoStandard result = new QueryInfoStandard();
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
+                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_INFO_QUERY_EA_SIZE:
+                    {
+                        QueryEASize result = new QueryEASize();
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.FileDataSize = (uint)Math.Min(entry.Size, UInt32.MaxValue);
+                        result.AllocationSize = (uint)Math.Min(NTFileSystemHelper.GetAllocationSize(entry.Size), UInt32.MaxValue);
+                        result.Attributes = GetFileAttributes(entry);
+                        result.EASize = 0;
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
+                    {
+                        throw new NotImplementedException();
+                    }
+                case QueryInformationLevel.SMB_INFO_QUERY_ALL_EAS:
+                    {
+                        throw new NotImplementedException();
+                    }
+                case QueryInformationLevel.SMB_INFO_IS_NAME_VALID:
+                    {
+                        throw new NotImplementedException();
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
+                    {
+                        QueryFileBasicInfo result = new QueryFileBasicInfo();
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.LastChangeTime = entry.LastWriteTime;
+                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
+                    {
+                        QueryFileStandardInfo result = new QueryFileStandardInfo();
+                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.EndOfFile = entry.Size;
+                        result.DeletePending = deletePending;
+                        result.Directory = entry.IsDirectory;
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
+                    {
+                        QueryFileExtendedAttributeInfo result = new QueryFileExtendedAttributeInfo();
+                        result.EASize = 0;
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
+                    {
+                        QueryFileNameInfo result = new QueryFileNameInfo();
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
+                    {
+                        QueryFileAllInfo result = new QueryFileAllInfo();
+                        result.CreationDateTime = entry.CreationTime;
+                        result.LastAccessDateTime = entry.LastAccessTime;
+                        result.LastWriteDateTime = entry.LastWriteTime;
+                        result.ExtFileAttributes = GetExtendedFileAttributes(entry);
+                        result.LastChangeTime = entry.LastWriteTime;
+                        result.AllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.EndOfFile = entry.Size;
+                        result.DeletePending = deletePending;
+                        result.Directory = entry.IsDirectory;
+                        result.EASize = 0;
+                        result.FileName = entry.Name;
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
+                    {
+                        QueryFileAltNameInfo result = new QueryFileAltNameInfo();
+                        result.FileName = NTFileSystemHelper.GetShortName(entry.Name);
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
+                    {
+                        QueryFileStreamInfo result = new QueryFileStreamInfo();
+                        result.StreamSize = entry.Size;
+                        result.StreamAllocationSize = NTFileSystemHelper.GetAllocationSize(entry.Size);
+                        result.StreamName = "::$DATA";
+                        return result;
+                    }
+                case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
+                    {
+                        QueryFileCompressionInfo result = new QueryFileCompressionInfo();
+                        result.CompressionFormat = CompressionFormat.COMPRESSION_FORMAT_NONE;
+                        return result;
+                    }
+                default:
+                    {
+                        throw new UnsupportedInformationLevelException();
+                    }
+            }
+        }
+
+        public static SMBFileAttributes GetFileAttributes(FileSystemEntry entry)
+        {
+            SMBFileAttributes attributes = SMBFileAttributes.Normal;
+            if (entry.IsHidden)
+            {
+                attributes |= SMBFileAttributes.Hidden;
+            }
+            if (entry.IsReadonly)
+            {
+                attributes |= SMBFileAttributes.ReadOnly;
+            }
+            if (entry.IsArchived)
+            {
+                attributes |= SMBFileAttributes.Archive;
+            }
+            if (entry.IsDirectory)
+            {
+                attributes |= SMBFileAttributes.Directory;
+            }
+
+            return attributes;
+        }
+
+        public static ExtendedFileAttributes GetExtendedFileAttributes(FileSystemEntry entry)
+        {
+            ExtendedFileAttributes attributes = 0;
+            if (entry.IsHidden)
+            {
+                attributes |= ExtendedFileAttributes.Hidden;
+            }
+            if (entry.IsReadonly)
+            {
+                attributes |= ExtendedFileAttributes.Readonly;
+            }
+            if (entry.IsArchived)
+            {
+                attributes |= ExtendedFileAttributes.Archive;
+            }
+            if (entry.IsDirectory)
+            {
+                attributes |= ExtendedFileAttributes.Directory;
+            }
+
+            if ((uint)attributes == 0)
+            {
+                attributes = ExtendedFileAttributes.Normal;
+            }
+
+            return attributes;
+        }
+    }
+}

+ 75 - 0
SMBLibrary/Server/SMB1/SMB1FileSystemHelper.QueryFileSystem.cs

@@ -0,0 +1,75 @@
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using SMBLibrary.SMB1;
+using Utilities;
+
+namespace SMBLibrary.Server.SMB1
+{
+    public partial class SMB1FileSystemHelper
+    {
+        public static QueryFSInformation GetFileSystemInformation(QueryFSInformationLevel informationLevel, IFileSystem fileSystem)
+        {
+            switch (informationLevel)
+            {
+                case QueryFSInformationLevel.SMB_INFO_ALLOCATION:
+                    {
+                        QueryFSInfoAllocation result = new QueryFSInfoAllocation();
+                        result.FileSystemID = 0;
+                        result.SectorUnit = NTFileSystemHelper.ClusterSize / NTFileSystemHelper.BytesPerSector;
+                        result.UnitsTotal = (uint)Math.Min(fileSystem.Size / NTFileSystemHelper.ClusterSize, UInt32.MaxValue);
+                        result.UnitsAvailable = (uint)Math.Min(fileSystem.FreeSpace / NTFileSystemHelper.ClusterSize, UInt32.MaxValue);
+                        result.Sector = NTFileSystemHelper.BytesPerSector;
+                        return result;
+                    }
+                case QueryFSInformationLevel.SMB_INFO_VOLUME:
+                    {
+                        QueryFSInfoVolume result = new QueryFSInfoVolume();
+                        result.VolumeLabel = String.Empty;
+                        result.VolumeSerialNumber = 0;
+                        return result;
+                    }
+                case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
+                    {
+                        QueryFSVolumeInfo result = new QueryFSVolumeInfo();
+                        result.VolumeCreationTime = DateTime.Now;
+                        return result;
+                    }
+                case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
+                    {
+                        QueryFSSizeInfo result = new QueryFSSizeInfo();
+                        result.TotalAllocationUnits = (ulong)(fileSystem.Size / NTFileSystemHelper.ClusterSize);
+                        result.TotalFreeAllocationUnits = (ulong)(fileSystem.FreeSpace / NTFileSystemHelper.ClusterSize);
+                        result.BytesPerSector = NTFileSystemHelper.BytesPerSector;
+                        result.SectorsPerAllocationUnit = NTFileSystemHelper.ClusterSize / NTFileSystemHelper.BytesPerSector;
+                        return result;
+                    }
+                case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
+                    {
+                        QueryFSDeviceInfo result = new QueryFSDeviceInfo();
+                        result.DeviceCharacteristics = DeviceCharacteristics.IsMounted;
+                        result.DeviceType = DeviceType.Disk;
+                        return result;
+                    }
+                case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
+                    {
+                        QueryFSAttibuteInfo result = new QueryFSAttibuteInfo();
+                        result.FileSystemAttributes = FileSystemAttributes.UnicodeOnDisk;
+                        result.MaxFileNameLengthInBytes = 255;
+                        result.FileSystemName = fileSystem.Name;
+                        return result;
+                    }
+                default:
+                    {
+                        throw new UnsupportedInformationLevelException();
+                    }
+            }
+        }
+    }
+}

+ 5 - 5
SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs

@@ -44,7 +44,7 @@ namespace SMBLibrary.Server.SMB1
             FindInformationList findInformationList = new FindInformationList();
             for (int index = 0; index < entriesToReturn; index++)
             {
-                FindInformation infoEntry = InfoHelper.FromFileSystemEntry(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
+                FindInformation infoEntry = SMB1FileSystemHelper.GetFindInformation(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
                 findInformationList.Add(infoEntry);
                 if (findInformationList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
                 {
@@ -91,7 +91,7 @@ namespace SMBLibrary.Server.SMB1
             FindInformationList findInformationList = new FindInformationList();
             for (int index = openSearch.EnumerationLocation; index < openSearch.Entries.Count; index++)
             {
-                FindInformation infoEntry = InfoHelper.FromFileSystemEntry(openSearch.Entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
+                FindInformation infoEntry = SMB1FileSystemHelper.GetFindInformation(openSearch.Entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
                 findInformationList.Add(infoEntry);
                 if (findInformationList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
                 {
@@ -119,7 +119,7 @@ namespace SMBLibrary.Server.SMB1
         internal static Transaction2QueryFSInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFSInformationRequest subcommand, FileSystemShare share)
         {
             Transaction2QueryFSInformationResponse response = new Transaction2QueryFSInformationResponse();
-            QueryFSInformation queryFSInformation = InfoHelper.GetFSInformation(subcommand.InformationLevel, share.FileSystem);
+            QueryFSInformation queryFSInformation = SMB1FileSystemHelper.GetFileSystemInformation(subcommand.InformationLevel, share.FileSystem);
             response.SetQueryFSInformation(queryFSInformation, header.UnicodeFlag);
             return response;
         }
@@ -138,7 +138,7 @@ namespace SMBLibrary.Server.SMB1
                 return null;
             }
             Transaction2QueryPathInformationResponse response = new Transaction2QueryPathInformationResponse();
-            QueryInformation queryInformation = InfoHelper.FromFileSystemEntry(entry, false, subcommand.InformationLevel);
+            QueryInformation queryInformation = SMB1FileSystemHelper.GetFileInformation(entry, false, subcommand.InformationLevel);
             response.SetQueryInformation(queryInformation);
 
             return response;
@@ -162,7 +162,7 @@ namespace SMBLibrary.Server.SMB1
                 return null;
             }
             Transaction2QueryFileInformationResponse response = new Transaction2QueryFileInformationResponse();
-            QueryInformation queryInformation = InfoHelper.FromFileSystemEntry(entry, openFile.DeleteOnClose, subcommand.InformationLevel);
+            QueryInformation queryInformation = SMB1FileSystemHelper.GetFileInformation(entry, openFile.DeleteOnClose, subcommand.InformationLevel);
             response.SetQueryInformation(queryInformation);
 
             return response;