mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-15 03:33:47 +02:00
Moved SMB1FileStore helper methods to separate classes
This commit is contained in:
parent
cf8857d438
commit
84668b13db
10 changed files with 467 additions and 427 deletions
164
SMBLibrary/SMB1FileStore/Helpers/FindInformationHelper.cs
Normal file
164
SMBLibrary/SMB1FileStore/Helpers/FindInformationHelper.cs
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
/* 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 SMBLibrary.SMB1;
|
||||||
|
using Utilities;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB1
|
||||||
|
{
|
||||||
|
public class FindInformationHelper
|
||||||
|
{
|
||||||
|
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
||||||
|
public static FileInformationClass ToFileInformationClass(FindInformationLevel informationLevel)
|
||||||
|
{
|
||||||
|
switch (informationLevel)
|
||||||
|
{
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
|
||||||
|
return FileInformationClass.FileDirectoryInformation;
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
|
||||||
|
return FileInformationClass.FileFullDirectoryInformation;
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
|
||||||
|
return FileInformationClass.FileNamesInformation;
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
|
||||||
|
return FileInformationClass.FileBothDirectoryInformation;
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO:
|
||||||
|
return FileInformationClass.FileIdFullDirectoryInformation;
|
||||||
|
case FindInformationLevel.SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO:
|
||||||
|
return FileInformationClass.FileIdBothDirectoryInformation;
|
||||||
|
default:
|
||||||
|
throw new UnsupportedInformationLevelException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
||||||
|
public static FindInformationList GetFindInformationList(List<QueryDirectoryFileInformation> entries, bool isUnicode, int maxLength)
|
||||||
|
{
|
||||||
|
FindInformationList result = new FindInformationList();
|
||||||
|
int pageLength = 0;
|
||||||
|
for (int index = 0; index < entries.Count; index++)
|
||||||
|
{
|
||||||
|
FindInformation infoEntry = GetFindInformation(entries[index]);
|
||||||
|
int entryLength = infoEntry.GetLength(isUnicode);
|
||||||
|
if (pageLength + entryLength <= maxLength)
|
||||||
|
{
|
||||||
|
result.Add(infoEntry);
|
||||||
|
pageLength += entryLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
||||||
|
public static FindInformation GetFindInformation(QueryDirectoryFileInformation fileInformation)
|
||||||
|
{
|
||||||
|
if (fileInformation is FileDirectoryInformation)
|
||||||
|
{
|
||||||
|
FileDirectoryInformation fileDirectoryInfo = (FileDirectoryInformation)fileInformation;
|
||||||
|
FindFileDirectoryInfo result = new FindFileDirectoryInfo();
|
||||||
|
result.FileIndex = fileDirectoryInfo.FileIndex;
|
||||||
|
result.CreationTime = fileDirectoryInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileDirectoryInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileDirectoryInfo.LastWriteTime;
|
||||||
|
result.LastAttrChangeTime = fileDirectoryInfo.LastWriteTime;
|
||||||
|
result.EndOfFile = fileDirectoryInfo.EndOfFile;
|
||||||
|
result.AllocationSize = fileDirectoryInfo.AllocationSize;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileDirectoryInfo.FileAttributes;
|
||||||
|
result.FileName = fileDirectoryInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileFullDirectoryInformation)
|
||||||
|
{
|
||||||
|
FileFullDirectoryInformation fileFullDirectoryInfo = (FileFullDirectoryInformation)fileInformation;
|
||||||
|
FindFileFullDirectoryInfo result = new FindFileFullDirectoryInfo();
|
||||||
|
result.FileIndex = fileFullDirectoryInfo.FileIndex;
|
||||||
|
result.CreationTime = fileFullDirectoryInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileFullDirectoryInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileFullDirectoryInfo.LastWriteTime;
|
||||||
|
result.LastAttrChangeTime = fileFullDirectoryInfo.LastWriteTime;
|
||||||
|
result.EndOfFile = fileFullDirectoryInfo.EndOfFile;
|
||||||
|
result.AllocationSize = fileFullDirectoryInfo.AllocationSize;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileFullDirectoryInfo.FileAttributes;
|
||||||
|
result.EASize = fileFullDirectoryInfo.EaSize;
|
||||||
|
result.FileName = fileFullDirectoryInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileNamesInformation)
|
||||||
|
{
|
||||||
|
FileNamesInformation fileNamesInfo = (FileNamesInformation)fileInformation;
|
||||||
|
FindFileNamesInfo result = new FindFileNamesInfo();
|
||||||
|
result.FileIndex = fileNamesInfo.FileIndex;
|
||||||
|
result.FileName = fileNamesInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileBothDirectoryInformation)
|
||||||
|
{
|
||||||
|
FileBothDirectoryInformation fileBothDirectoryInfo = (FileBothDirectoryInformation)fileInformation;
|
||||||
|
FindFileBothDirectoryInfo result = new FindFileBothDirectoryInfo();
|
||||||
|
result.FileIndex = fileBothDirectoryInfo.FileIndex;
|
||||||
|
result.CreationTime = fileBothDirectoryInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileBothDirectoryInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileBothDirectoryInfo.LastWriteTime;
|
||||||
|
result.LastChangeTime = fileBothDirectoryInfo.LastWriteTime;
|
||||||
|
result.EndOfFile = fileBothDirectoryInfo.EndOfFile;
|
||||||
|
result.AllocationSize = fileBothDirectoryInfo.AllocationSize;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileBothDirectoryInfo.FileAttributes;
|
||||||
|
result.EASize = fileBothDirectoryInfo.EaSize;
|
||||||
|
result.Reserved = fileBothDirectoryInfo.Reserved;
|
||||||
|
result.ShortName = fileBothDirectoryInfo.ShortName;
|
||||||
|
result.FileName = fileBothDirectoryInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileIdFullDirectoryInformation)
|
||||||
|
{
|
||||||
|
FileIdFullDirectoryInformation fileIDFullDirectoryInfo = (FileIdFullDirectoryInformation)fileInformation;
|
||||||
|
FindFileIDFullDirectoryInfo result = new FindFileIDFullDirectoryInfo();
|
||||||
|
result.FileIndex = fileIDFullDirectoryInfo.FileIndex;
|
||||||
|
result.CreationTime = fileIDFullDirectoryInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileIDFullDirectoryInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileIDFullDirectoryInfo.LastWriteTime;
|
||||||
|
result.LastAttrChangeTime = fileIDFullDirectoryInfo.LastWriteTime;
|
||||||
|
result.EndOfFile = fileIDFullDirectoryInfo.EndOfFile;
|
||||||
|
result.AllocationSize = fileIDFullDirectoryInfo.AllocationSize;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileIDFullDirectoryInfo.FileAttributes;
|
||||||
|
result.EASize = fileIDFullDirectoryInfo.EaSize;
|
||||||
|
result.Reserved = fileIDFullDirectoryInfo.Reserved;
|
||||||
|
result.FileID = fileIDFullDirectoryInfo.FileId;
|
||||||
|
result.FileName = fileIDFullDirectoryInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileIdBothDirectoryInformation)
|
||||||
|
{
|
||||||
|
FileIdBothDirectoryInformation fileIDBothDirectoryInfo = (FileIdBothDirectoryInformation)fileInformation;
|
||||||
|
FindFileIDBothDirectoryInfo result = new FindFileIDBothDirectoryInfo();
|
||||||
|
result.FileIndex = fileIDBothDirectoryInfo.FileIndex;
|
||||||
|
result.CreationTime = fileIDBothDirectoryInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileIDBothDirectoryInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileIDBothDirectoryInfo.LastWriteTime;
|
||||||
|
result.LastChangeTime = fileIDBothDirectoryInfo.LastWriteTime;
|
||||||
|
result.EndOfFile = fileIDBothDirectoryInfo.EndOfFile;
|
||||||
|
result.AllocationSize = fileIDBothDirectoryInfo.AllocationSize;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileIDBothDirectoryInfo.FileAttributes;
|
||||||
|
result.EASize = fileIDBothDirectoryInfo.EaSize;
|
||||||
|
result.Reserved = fileIDBothDirectoryInfo.Reserved1;
|
||||||
|
result.ShortName = fileIDBothDirectoryInfo.ShortName;
|
||||||
|
result.Reserved2 = fileIDBothDirectoryInfo.Reserved2;
|
||||||
|
result.FileID = fileIDBothDirectoryInfo.FileId;
|
||||||
|
result.FileName = fileIDBothDirectoryInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
SMBLibrary/SMB1FileStore/Helpers/QueryFSInformationHelper.cs
Normal file
78
SMBLibrary/SMB1FileStore/Helpers/QueryFSInformationHelper.cs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* 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 SMBLibrary.SMB1;
|
||||||
|
using Utilities;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB1
|
||||||
|
{
|
||||||
|
public class QueryFSInformationHelper
|
||||||
|
{
|
||||||
|
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
||||||
|
public static FileSystemInformationClass ToFileSystemInformationClass(QueryFSInformationLevel informationLevel)
|
||||||
|
{
|
||||||
|
switch (informationLevel)
|
||||||
|
{
|
||||||
|
case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
|
||||||
|
return FileSystemInformationClass.FileFsVolumeInformation;
|
||||||
|
case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
|
||||||
|
return FileSystemInformationClass.FileFsSizeInformation;
|
||||||
|
case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
|
||||||
|
return FileSystemInformationClass.FileFsDeviceInformation;
|
||||||
|
case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
|
||||||
|
return FileSystemInformationClass.FileFsAttributeInformation;
|
||||||
|
default:
|
||||||
|
throw new UnsupportedInformationLevelException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QueryFSInformation FromFileSystemInformation(FileSystemInformation fsInfo)
|
||||||
|
{
|
||||||
|
if (fsInfo is FileFsVolumeInformation)
|
||||||
|
{
|
||||||
|
FileFsVolumeInformation volumeInfo = (FileFsVolumeInformation)fsInfo;
|
||||||
|
QueryFSVolumeInfo result = new QueryFSVolumeInfo();
|
||||||
|
result.VolumeCreationTime = volumeInfo.VolumeCreationTime;
|
||||||
|
result.SerialNumber = volumeInfo.VolumeSerialNumber;
|
||||||
|
result.VolumeLabel = volumeInfo.VolumeLabel;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fsInfo is FileFsSizeInformation)
|
||||||
|
{
|
||||||
|
FileFsSizeInformation fsSizeInfo = (FileFsSizeInformation)fsInfo;
|
||||||
|
QueryFSSizeInfo result = new QueryFSSizeInfo();
|
||||||
|
result.TotalAllocationUnits = fsSizeInfo.TotalAllocationUnits;
|
||||||
|
result.TotalFreeAllocationUnits = fsSizeInfo.AvailableAllocationUnits;
|
||||||
|
result.BytesPerSector = fsSizeInfo.BytesPerSector;
|
||||||
|
result.SectorsPerAllocationUnit = fsSizeInfo.SectorsPerAllocationUnit;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fsInfo is FileFsDeviceInformation)
|
||||||
|
{
|
||||||
|
FileFsDeviceInformation fsDeviceInfo = (FileFsDeviceInformation)fsInfo;
|
||||||
|
QueryFSDeviceInfo result = new QueryFSDeviceInfo();
|
||||||
|
result.DeviceType = fsDeviceInfo.DeviceType;
|
||||||
|
result.DeviceCharacteristics = fsDeviceInfo.Characteristics;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fsInfo is FileFsAttributeInformation)
|
||||||
|
{
|
||||||
|
FileFsAttributeInformation fsAttributeInfo = (FileFsAttributeInformation)fsInfo;
|
||||||
|
QueryFSAttibuteInfo result = new QueryFSAttibuteInfo();
|
||||||
|
result.FileSystemAttributes = fsAttributeInfo.FileSystemAttributes;
|
||||||
|
result.MaxFileNameLengthInBytes = fsAttributeInfo.MaximumComponentNameLength;
|
||||||
|
result.FileSystemName = fsAttributeInfo.FileSystemName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
128
SMBLibrary/SMB1FileStore/Helpers/QueryInformationHelper.cs
Normal file
128
SMBLibrary/SMB1FileStore/Helpers/QueryInformationHelper.cs
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/* 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 SMBLibrary.SMB1;
|
||||||
|
using Utilities;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB1
|
||||||
|
{
|
||||||
|
public class QueryInformationHelper
|
||||||
|
{
|
||||||
|
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
||||||
|
public static FileInformationClass ToFileInformationClass(QueryInformationLevel informationLevel)
|
||||||
|
{
|
||||||
|
switch (informationLevel)
|
||||||
|
{
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
|
||||||
|
return FileInformationClass.FileBasicInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
|
||||||
|
return FileInformationClass.FileStandardInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
|
||||||
|
return FileInformationClass.FileEaInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
|
||||||
|
return FileInformationClass.FileNameInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
|
||||||
|
return FileInformationClass.FileAllInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
|
||||||
|
return FileInformationClass.FileAlternateNameInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
|
||||||
|
return FileInformationClass.FileStreamInformation;
|
||||||
|
case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
|
||||||
|
return FileInformationClass.FileCompressionInformation;
|
||||||
|
default:
|
||||||
|
throw new UnsupportedInformationLevelException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QueryInformation FromFileInformation(FileInformation fileInformation)
|
||||||
|
{
|
||||||
|
if (fileInformation is FileBasicInformation)
|
||||||
|
{
|
||||||
|
FileBasicInformation fileBasicInfo = (FileBasicInformation)fileInformation;
|
||||||
|
QueryFileBasicInfo result = new QueryFileBasicInfo();
|
||||||
|
result.CreationTime = fileBasicInfo.CreationTime;
|
||||||
|
result.LastAccessTime = fileBasicInfo.LastAccessTime;
|
||||||
|
result.LastWriteTime = fileBasicInfo.LastWriteTime;
|
||||||
|
result.LastChangeTime = fileBasicInfo.LastWriteTime;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileBasicInfo.FileAttributes;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileStandardInformation)
|
||||||
|
{
|
||||||
|
FileStandardInformation fileStandardInfo = (FileStandardInformation)fileInformation;
|
||||||
|
QueryFileStandardInfo result = new QueryFileStandardInfo();
|
||||||
|
result.AllocationSize = fileStandardInfo.AllocationSize;
|
||||||
|
result.EndOfFile = fileStandardInfo.EndOfFile;
|
||||||
|
result.DeletePending = fileStandardInfo.DeletePending;
|
||||||
|
result.Directory = fileStandardInfo.Directory;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileEaInformation)
|
||||||
|
{
|
||||||
|
FileEaInformation fileEAInfo = (FileEaInformation)fileInformation;
|
||||||
|
QueryFileExtendedAttributeInfo result = new QueryFileExtendedAttributeInfo();
|
||||||
|
result.EASize = fileEAInfo.EaSize;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileNameInformation)
|
||||||
|
{
|
||||||
|
FileNameInformation fileNameInfo = (FileNameInformation)fileInformation;
|
||||||
|
QueryFileNameInfo result = new QueryFileNameInfo();
|
||||||
|
result.FileName = fileNameInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileAllInformation)
|
||||||
|
{
|
||||||
|
FileAllInformation fileAllInfo = (FileAllInformation)fileInformation;
|
||||||
|
QueryFileAllInfo result = new QueryFileAllInfo();
|
||||||
|
result.CreationDateTime = fileAllInfo.BasicInformation.CreationTime;
|
||||||
|
result.LastAccessDateTime = fileAllInfo.BasicInformation.LastAccessTime;
|
||||||
|
result.LastWriteDateTime = fileAllInfo.BasicInformation.LastWriteTime;
|
||||||
|
result.LastChangeTime = fileAllInfo.BasicInformation.LastWriteTime;
|
||||||
|
result.ExtFileAttributes = (ExtendedFileAttributes)fileAllInfo.BasicInformation.FileAttributes;
|
||||||
|
result.AllocationSize = fileAllInfo.StandardInformation.AllocationSize;
|
||||||
|
result.EndOfFile = fileAllInfo.StandardInformation.EndOfFile;
|
||||||
|
result.DeletePending = fileAllInfo.StandardInformation.DeletePending;
|
||||||
|
result.Directory = fileAllInfo.StandardInformation.Directory;
|
||||||
|
result.EASize = fileAllInfo.EaInformation.EaSize;
|
||||||
|
result.FileName = fileAllInfo.NameInformation.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileAlternateNameInformation)
|
||||||
|
{
|
||||||
|
FileAlternateNameInformation fileAltNameInfo = (FileAlternateNameInformation)fileInformation;
|
||||||
|
QueryFileAltNameInfo result = new QueryFileAltNameInfo();
|
||||||
|
result.FileName = fileAltNameInfo.FileName;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileStreamInformation)
|
||||||
|
{
|
||||||
|
FileStreamInformation fileStreamInfo = (FileStreamInformation)fileInformation;
|
||||||
|
QueryFileStreamInfo result = new QueryFileStreamInfo();
|
||||||
|
result.Entries.AddRange(fileStreamInfo.Entries);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (fileInformation is FileCompressionInformation)
|
||||||
|
{
|
||||||
|
FileCompressionInformation fileCompressionInfo = (FileCompressionInformation)fileInformation;
|
||||||
|
QueryFileCompressionInfo result = new QueryFileCompressionInfo();
|
||||||
|
result.CompressedFileSize = fileCompressionInfo.CompressedFileSize;
|
||||||
|
result.CompressionFormat = fileCompressionInfo.CompressionFormat;
|
||||||
|
result.CompressionUnitShift = fileCompressionInfo.CompressionUnitShift;
|
||||||
|
result.ChunkShift = fileCompressionInfo.ChunkShift;
|
||||||
|
result.ClusterShift = fileCompressionInfo.ClusterShift;
|
||||||
|
result.Reserved = fileCompressionInfo.Reserved;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
SMBLibrary/SMB1FileStore/Helpers/SetInformationHelper.cs
Normal file
56
SMBLibrary/SMB1FileStore/Helpers/SetInformationHelper.cs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* 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 SMBLibrary.SMB1;
|
||||||
|
using Utilities;
|
||||||
|
|
||||||
|
namespace SMBLibrary.SMB1
|
||||||
|
{
|
||||||
|
public class SetInformationHelper
|
||||||
|
{
|
||||||
|
public static FileInformation ToFileInformation(SetInformation information)
|
||||||
|
{
|
||||||
|
if (information is SetFileBasicInfo)
|
||||||
|
{
|
||||||
|
SetFileBasicInfo basicInfo = (SetFileBasicInfo)information;
|
||||||
|
FileBasicInformation fileBasicInfo = new FileBasicInformation();
|
||||||
|
fileBasicInfo.CreationTime = basicInfo.CreationTime;
|
||||||
|
fileBasicInfo.LastAccessTime = basicInfo.LastAccessTime;
|
||||||
|
fileBasicInfo.LastWriteTime = basicInfo.LastWriteTime;
|
||||||
|
fileBasicInfo.ChangeTime = basicInfo.LastChangeTime;
|
||||||
|
fileBasicInfo.FileAttributes = (FileAttributes)basicInfo.ExtFileAttributes;
|
||||||
|
fileBasicInfo.Reserved = basicInfo.Reserved;
|
||||||
|
return fileBasicInfo;
|
||||||
|
}
|
||||||
|
else if (information is SetFileDispositionInfo)
|
||||||
|
{
|
||||||
|
FileDispositionInformation fileDispositionInfo = new FileDispositionInformation();
|
||||||
|
fileDispositionInfo.DeletePending = ((SetFileDispositionInfo)information).DeletePending;
|
||||||
|
return fileDispositionInfo;
|
||||||
|
}
|
||||||
|
else if (information is SetFileAllocationInfo)
|
||||||
|
{
|
||||||
|
// This information level is used to set the file length in bytes.
|
||||||
|
// Note: the input will NOT be a multiple of the cluster size / bytes per sector.
|
||||||
|
FileAllocationInformation fileAllocationInfo = new FileAllocationInformation();
|
||||||
|
fileAllocationInfo.AllocationSize = ((SetFileAllocationInfo)information).AllocationSize;
|
||||||
|
return fileAllocationInfo;
|
||||||
|
}
|
||||||
|
else if (information is SetFileEndOfFileInfo)
|
||||||
|
{
|
||||||
|
FileEndOfFileInformation fileEndOfFileInfo = new FileEndOfFileInformation();
|
||||||
|
fileEndOfFileInfo.EndOfFile = ((SetFileEndOfFileInfo)information).EndOfFile;
|
||||||
|
return fileEndOfFileInfo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -292,6 +292,10 @@
|
||||||
<Compile Include="Services\WorkstationService\Structures\WorkstationInfo101.cs" />
|
<Compile Include="Services\WorkstationService\Structures\WorkstationInfo101.cs" />
|
||||||
<Compile Include="Services\WorkstationService\Structures\WorkstationInfoLevel.cs" />
|
<Compile Include="Services\WorkstationService\Structures\WorkstationInfoLevel.cs" />
|
||||||
<Compile Include="Services\WorkstationService\WorkstationService.cs" />
|
<Compile Include="Services\WorkstationService\WorkstationService.cs" />
|
||||||
|
<Compile Include="SMB1FileStore\Helpers\FindInformationHelper.cs" />
|
||||||
|
<Compile Include="SMB1FileStore\Helpers\QueryFSInformationHelper.cs" />
|
||||||
|
<Compile Include="SMB1FileStore\Helpers\QueryInformationHelper.cs" />
|
||||||
|
<Compile Include="SMB1FileStore\Helpers\SetInformationHelper.cs" />
|
||||||
<Compile Include="SMB1FileStore\Structures\FindInformation\FindFileIDBothDirectoryInfo.cs" />
|
<Compile Include="SMB1FileStore\Structures\FindInformation\FindFileIDBothDirectoryInfo.cs" />
|
||||||
<Compile Include="SMB1FileStore\Structures\FindInformation\FindFileIDFullDirectoryInfo.cs" />
|
<Compile Include="SMB1FileStore\Structures\FindInformation\FindFileIDFullDirectoryInfo.cs" />
|
||||||
<Compile Include="SMB1\Commands\CheckDirectoryRequest.cs" />
|
<Compile Include="SMB1\Commands\CheckDirectoryRequest.cs" />
|
||||||
|
|
|
@ -32,167 +32,25 @@ namespace SMBLibrary.Server.SMB1
|
||||||
public static NTStatus GetFileInformation(out QueryInformation result, INTFileStore fileStore, object handle, QueryInformationLevel informationLevel)
|
public static NTStatus GetFileInformation(out QueryInformation result, INTFileStore fileStore, object handle, QueryInformationLevel informationLevel)
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
FileInformation fileInfo;
|
FileInformationClass informationClass;
|
||||||
switch (informationLevel)
|
try
|
||||||
{
|
{
|
||||||
case QueryInformationLevel.SMB_INFO_QUERY_ALL_EAS:
|
informationClass = QueryInformationHelper.ToFileInformationClass(informationLevel);
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
return NTStatus.STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
}
|
||||||
case QueryInformationLevel.SMB_INFO_IS_NAME_VALID:
|
catch (UnsupportedInformationLevelException)
|
||||||
{
|
{
|
||||||
result = null;
|
|
||||||
return NTStatus.STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileBasicInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileBasicInformation fileBasicInfo = (FileBasicInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileBasicInfo information = new QueryFileBasicInfo();
|
|
||||||
information.CreationTime = fileBasicInfo.CreationTime;
|
|
||||||
information.LastAccessTime = fileBasicInfo.LastAccessTime;
|
|
||||||
information.LastWriteTime = fileBasicInfo.LastWriteTime;
|
|
||||||
information.LastChangeTime = fileBasicInfo.LastWriteTime;
|
|
||||||
information.ExtFileAttributes = (ExtendedFileAttributes)fileBasicInfo.FileAttributes;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileStandardInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileStandardInformation fileStandardInfo = (FileStandardInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileStandardInfo information = new QueryFileStandardInfo();
|
|
||||||
information.AllocationSize = fileStandardInfo.AllocationSize;
|
|
||||||
information.EndOfFile = fileStandardInfo.EndOfFile;
|
|
||||||
information.DeletePending = fileStandardInfo.DeletePending;
|
|
||||||
information.Directory = fileStandardInfo.Directory;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileEaInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileEaInformation fileEAInfo = (FileEaInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileExtendedAttributeInfo information = new QueryFileExtendedAttributeInfo();
|
|
||||||
information.EASize = fileEAInfo.EaSize;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileNameInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileNameInformation fileNameInfo = (FileNameInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileNameInfo information = new QueryFileNameInfo();
|
|
||||||
information.FileName = fileNameInfo.FileName;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileAllInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileAllInformation fileAllInfo = (FileAllInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileAllInfo information = new QueryFileAllInfo();
|
|
||||||
information.CreationDateTime = fileAllInfo.BasicInformation.CreationTime;
|
|
||||||
information.LastAccessDateTime = fileAllInfo.BasicInformation.LastAccessTime;
|
|
||||||
information.LastWriteDateTime = fileAllInfo.BasicInformation.LastWriteTime;
|
|
||||||
information.LastChangeTime = fileAllInfo.BasicInformation.LastWriteTime;
|
|
||||||
information.ExtFileAttributes = (ExtendedFileAttributes)fileAllInfo.BasicInformation.FileAttributes;
|
|
||||||
information.AllocationSize = fileAllInfo.StandardInformation.AllocationSize;
|
|
||||||
information.EndOfFile = fileAllInfo.StandardInformation.EndOfFile;
|
|
||||||
information.DeletePending = fileAllInfo.StandardInformation.DeletePending;
|
|
||||||
information.Directory = fileAllInfo.StandardInformation.Directory;
|
|
||||||
information.EASize = fileAllInfo.EaInformation.EaSize;
|
|
||||||
information.FileName = fileAllInfo.NameInformation.FileName;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileAlternateNameInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileAlternateNameInformation fileAltNameInfo = (FileAlternateNameInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileAltNameInfo information = new QueryFileAltNameInfo();
|
|
||||||
information.FileName = fileAltNameInfo.FileName;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileStreamInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileStreamInformation fileStreamInfo = (FileStreamInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileStreamInfo information = new QueryFileStreamInfo();
|
|
||||||
information.Entries.AddRange(fileStreamInfo.Entries);
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileCompressionInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileCompressionInformation fileCompressionInfo = (FileCompressionInformation)fileInfo;
|
|
||||||
|
|
||||||
QueryFileCompressionInfo information = new QueryFileCompressionInfo();
|
|
||||||
information.CompressedFileSize = fileCompressionInfo.CompressedFileSize;
|
|
||||||
information.CompressionFormat = fileCompressionInfo.CompressionFormat;
|
|
||||||
information.CompressionUnitShift = fileCompressionInfo.CompressionUnitShift;
|
|
||||||
information.ChunkShift = fileCompressionInfo.ChunkShift;
|
|
||||||
information.ClusterShift = fileCompressionInfo.ClusterShift;
|
|
||||||
information.Reserved = fileCompressionInfo.Reserved;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
return NTStatus.STATUS_OS2_INVALID_LEVEL;
|
return NTStatus.STATUS_OS2_INVALID_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileInformation fileInformation;
|
||||||
|
NTStatus status = fileStore.GetFileInformation(out fileInformation, handle, informationClass);
|
||||||
|
if (status != NTStatus.STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = QueryInformationHelper.FromFileInformation(fileInformation);
|
||||||
|
return NTStatus.STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,140 +49,5 @@ namespace SMBLibrary.Server.SMB1
|
||||||
return NTStatus.STATUS_INVALID_PARAMETER;
|
return NTStatus.STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
|
||||||
public static FindInformationList GetFindInformationList(List<QueryDirectoryFileInformation> entries, FindInformationLevel informationLevel, bool isUnicode, int maxLength)
|
|
||||||
{
|
|
||||||
FindInformationList result = new FindInformationList();
|
|
||||||
int pageLength = 0;
|
|
||||||
for (int index = 0; index < entries.Count; index++)
|
|
||||||
{
|
|
||||||
FindInformation infoEntry = GetFindInformation(entries[index], informationLevel);
|
|
||||||
int entryLength = infoEntry.GetLength(isUnicode);
|
|
||||||
if (pageLength + entryLength <= maxLength)
|
|
||||||
{
|
|
||||||
result.Add(infoEntry);
|
|
||||||
pageLength += entryLength;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
|
|
||||||
public static FindInformation GetFindInformation(QueryDirectoryFileInformation entry, FindInformationLevel informationLevel)
|
|
||||||
{
|
|
||||||
switch (informationLevel)
|
|
||||||
{
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
|
|
||||||
{
|
|
||||||
FileDirectoryInformation fileDirectoryInfo = (FileDirectoryInformation)entry;
|
|
||||||
|
|
||||||
FindFileDirectoryInfo result = new FindFileDirectoryInfo();
|
|
||||||
result.FileIndex = fileDirectoryInfo.FileIndex;
|
|
||||||
result.CreationTime = fileDirectoryInfo.CreationTime;
|
|
||||||
result.LastAccessTime = fileDirectoryInfo.LastAccessTime;
|
|
||||||
result.LastWriteTime = fileDirectoryInfo.LastWriteTime;
|
|
||||||
result.LastAttrChangeTime = fileDirectoryInfo.LastWriteTime;
|
|
||||||
result.EndOfFile = fileDirectoryInfo.EndOfFile;
|
|
||||||
result.AllocationSize = fileDirectoryInfo.AllocationSize;
|
|
||||||
result.ExtFileAttributes = (ExtendedFileAttributes)fileDirectoryInfo.FileAttributes;
|
|
||||||
result.FileName = fileDirectoryInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
|
|
||||||
{
|
|
||||||
FileFullDirectoryInformation fileFullDirectoryInfo = (FileFullDirectoryInformation)entry;
|
|
||||||
|
|
||||||
FindFileFullDirectoryInfo result = new FindFileFullDirectoryInfo();
|
|
||||||
result.FileIndex = fileFullDirectoryInfo.FileIndex;
|
|
||||||
result.CreationTime = fileFullDirectoryInfo.CreationTime;
|
|
||||||
result.LastAccessTime = fileFullDirectoryInfo.LastAccessTime;
|
|
||||||
result.LastWriteTime = fileFullDirectoryInfo.LastWriteTime;
|
|
||||||
result.LastAttrChangeTime = fileFullDirectoryInfo.LastWriteTime;
|
|
||||||
result.EndOfFile = fileFullDirectoryInfo.EndOfFile;
|
|
||||||
result.AllocationSize = fileFullDirectoryInfo.AllocationSize;
|
|
||||||
result.ExtFileAttributes = (ExtendedFileAttributes)fileFullDirectoryInfo.FileAttributes;
|
|
||||||
result.EASize = fileFullDirectoryInfo.EaSize;
|
|
||||||
result.FileName = fileFullDirectoryInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
|
|
||||||
{
|
|
||||||
FileNamesInformation fileNamesInfo = (FileNamesInformation)entry;
|
|
||||||
|
|
||||||
FindFileNamesInfo result = new FindFileNamesInfo();
|
|
||||||
result.FileIndex = fileNamesInfo.FileIndex;
|
|
||||||
result.FileName = fileNamesInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
|
|
||||||
{
|
|
||||||
FileBothDirectoryInformation fileBothDirectoryInfo = (FileBothDirectoryInformation)entry;
|
|
||||||
|
|
||||||
FindFileBothDirectoryInfo result = new FindFileBothDirectoryInfo();
|
|
||||||
result.FileIndex = fileBothDirectoryInfo.FileIndex;
|
|
||||||
result.CreationTime = fileBothDirectoryInfo.CreationTime;
|
|
||||||
result.LastAccessTime = fileBothDirectoryInfo.LastAccessTime;
|
|
||||||
result.LastWriteTime = fileBothDirectoryInfo.LastWriteTime;
|
|
||||||
result.LastChangeTime = fileBothDirectoryInfo.LastWriteTime;
|
|
||||||
result.EndOfFile = fileBothDirectoryInfo.EndOfFile;
|
|
||||||
result.AllocationSize = fileBothDirectoryInfo.AllocationSize;
|
|
||||||
result.ExtFileAttributes = (ExtendedFileAttributes)fileBothDirectoryInfo.FileAttributes;
|
|
||||||
result.EASize = fileBothDirectoryInfo.EaSize;
|
|
||||||
result.Reserved = fileBothDirectoryInfo.Reserved;
|
|
||||||
result.ShortName = fileBothDirectoryInfo.ShortName;
|
|
||||||
result.FileName = fileBothDirectoryInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO:
|
|
||||||
{
|
|
||||||
FileIdFullDirectoryInformation fileIDFullDirectoryInfo = (FileIdFullDirectoryInformation)entry;
|
|
||||||
|
|
||||||
FindFileIDFullDirectoryInfo result = new FindFileIDFullDirectoryInfo();
|
|
||||||
result.FileIndex = fileIDFullDirectoryInfo.FileIndex;
|
|
||||||
result.CreationTime = fileIDFullDirectoryInfo.CreationTime;
|
|
||||||
result.LastAccessTime = fileIDFullDirectoryInfo.LastAccessTime;
|
|
||||||
result.LastWriteTime = fileIDFullDirectoryInfo.LastWriteTime;
|
|
||||||
result.LastAttrChangeTime = fileIDFullDirectoryInfo.LastWriteTime;
|
|
||||||
result.EndOfFile = fileIDFullDirectoryInfo.EndOfFile;
|
|
||||||
result.AllocationSize = fileIDFullDirectoryInfo.AllocationSize;
|
|
||||||
result.ExtFileAttributes = (ExtendedFileAttributes)fileIDFullDirectoryInfo.FileAttributes;
|
|
||||||
result.EASize = fileIDFullDirectoryInfo.EaSize;
|
|
||||||
result.Reserved = fileIDFullDirectoryInfo.Reserved;
|
|
||||||
result.FileID = fileIDFullDirectoryInfo.FileId;
|
|
||||||
result.FileName = fileIDFullDirectoryInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO:
|
|
||||||
{
|
|
||||||
FileIdBothDirectoryInformation fileIDBothDirectoryInfo = (FileIdBothDirectoryInformation)entry;
|
|
||||||
|
|
||||||
FindFileIDBothDirectoryInfo result = new FindFileIDBothDirectoryInfo();
|
|
||||||
result.FileIndex = fileIDBothDirectoryInfo.FileIndex;
|
|
||||||
result.CreationTime = fileIDBothDirectoryInfo.CreationTime;
|
|
||||||
result.LastAccessTime = fileIDBothDirectoryInfo.LastAccessTime;
|
|
||||||
result.LastWriteTime = fileIDBothDirectoryInfo.LastWriteTime;
|
|
||||||
result.LastChangeTime = fileIDBothDirectoryInfo.LastWriteTime;
|
|
||||||
result.EndOfFile = fileIDBothDirectoryInfo.EndOfFile;
|
|
||||||
result.AllocationSize = fileIDBothDirectoryInfo.AllocationSize;
|
|
||||||
result.ExtFileAttributes = (ExtendedFileAttributes)fileIDBothDirectoryInfo.FileAttributes;
|
|
||||||
result.EASize = fileIDBothDirectoryInfo.EaSize;
|
|
||||||
result.Reserved = fileIDBothDirectoryInfo.Reserved1;
|
|
||||||
result.ShortName = fileIDBothDirectoryInfo.ShortName;
|
|
||||||
result.Reserved2 = fileIDBothDirectoryInfo.Reserved2;
|
|
||||||
result.FileID = fileIDBothDirectoryInfo.FileId;
|
|
||||||
result.FileName = fileIDBothDirectoryInfo.FileName;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new UnsupportedInformationLevelException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,83 +17,25 @@ namespace SMBLibrary.Server.SMB1
|
||||||
public static NTStatus GetFileSystemInformation(out QueryFSInformation result, INTFileStore fileStore, QueryFSInformationLevel informationLevel)
|
public static NTStatus GetFileSystemInformation(out QueryFSInformation result, INTFileStore fileStore, QueryFSInformationLevel informationLevel)
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
|
FileSystemInformationClass informationClass;
|
||||||
FileSystemInformation fsInfo;
|
try
|
||||||
switch (informationLevel)
|
|
||||||
{
|
{
|
||||||
case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
|
informationClass = QueryFSInformationHelper.ToFileSystemInformationClass(informationLevel);
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, FileSystemInformationClass.FileFsVolumeInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedInformationLevelException)
|
||||||
FileFsVolumeInformation volumeInfo = (FileFsVolumeInformation)fsInfo;
|
|
||||||
|
|
||||||
QueryFSVolumeInfo information = new QueryFSVolumeInfo();
|
|
||||||
information.VolumeCreationTime = volumeInfo.VolumeCreationTime;
|
|
||||||
information.SerialNumber = volumeInfo.VolumeSerialNumber;
|
|
||||||
information.VolumeLabel = volumeInfo.VolumeLabel;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, FileSystemInformationClass.FileFsSizeInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileFsSizeInformation fsSizeInfo = (FileFsSizeInformation)fsInfo;
|
|
||||||
|
|
||||||
QueryFSSizeInfo information = new QueryFSSizeInfo();
|
|
||||||
information.TotalAllocationUnits = fsSizeInfo.TotalAllocationUnits;
|
|
||||||
information.TotalFreeAllocationUnits = fsSizeInfo.AvailableAllocationUnits;
|
|
||||||
information.BytesPerSector = fsSizeInfo.BytesPerSector;
|
|
||||||
information.SectorsPerAllocationUnit = fsSizeInfo.SectorsPerAllocationUnit;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, FileSystemInformationClass.FileFsDeviceInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileFsDeviceInformation fsDeviceInfo = (FileFsDeviceInformation)fsInfo;
|
|
||||||
|
|
||||||
QueryFSDeviceInfo information = new QueryFSDeviceInfo();
|
|
||||||
information.DeviceType = fsDeviceInfo.DeviceType;
|
|
||||||
information.DeviceCharacteristics = fsDeviceInfo.Characteristics;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
|
|
||||||
{
|
|
||||||
NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, FileSystemInformationClass.FileFsAttributeInformation);
|
|
||||||
if (status != NTStatus.STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileFsAttributeInformation fsAttributeInfo = (FileFsAttributeInformation)fsInfo;
|
|
||||||
|
|
||||||
QueryFSAttibuteInfo information = new QueryFSAttibuteInfo();
|
|
||||||
information.FileSystemAttributes = fsAttributeInfo.FileSystemAttributes;
|
|
||||||
information.MaxFileNameLengthInBytes = fsAttributeInfo.MaximumComponentNameLength;
|
|
||||||
information.FileSystemName = fsAttributeInfo.FileSystemName;
|
|
||||||
result = information;
|
|
||||||
return NTStatus.STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
{
|
||||||
return NTStatus.STATUS_OS2_INVALID_LEVEL;
|
return NTStatus.STATUS_OS2_INVALID_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSystemInformation fsInfo;
|
||||||
|
NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, informationClass);
|
||||||
|
if (status != NTStatus.STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = QueryFSInformationHelper.FromFileSystemInformation(fsInfo);
|
||||||
|
return NTStatus.STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,42 +17,8 @@ namespace SMBLibrary.Server.SMB1
|
||||||
{
|
{
|
||||||
public static NTStatus SetFileInformation(INTFileStore fileStore, object handle, SetInformation information)
|
public static NTStatus SetFileInformation(INTFileStore fileStore, object handle, SetInformation information)
|
||||||
{
|
{
|
||||||
if (information is SetFileBasicInfo)
|
FileInformation fileInformation = SetInformationHelper.ToFileInformation(information);
|
||||||
{
|
return fileStore.SetFileInformation(handle, fileInformation);
|
||||||
SetFileBasicInfo basicInfo = (SetFileBasicInfo)information;
|
|
||||||
FileBasicInformation fileBasicInfo = new FileBasicInformation();
|
|
||||||
fileBasicInfo.CreationTime = basicInfo.CreationTime;
|
|
||||||
fileBasicInfo.LastAccessTime = basicInfo.LastAccessTime;
|
|
||||||
fileBasicInfo.LastWriteTime = basicInfo.LastWriteTime;
|
|
||||||
fileBasicInfo.ChangeTime = basicInfo.LastChangeTime;
|
|
||||||
fileBasicInfo.FileAttributes = (FileAttributes)basicInfo.ExtFileAttributes;
|
|
||||||
fileBasicInfo.Reserved = basicInfo.Reserved;
|
|
||||||
return fileStore.SetFileInformation(handle, fileBasicInfo);
|
|
||||||
}
|
|
||||||
else if (information is SetFileDispositionInfo)
|
|
||||||
{
|
|
||||||
FileDispositionInformation fileDispositionInfo = new FileDispositionInformation();
|
|
||||||
fileDispositionInfo.DeletePending = ((SetFileDispositionInfo)information).DeletePending;
|
|
||||||
return fileStore.SetFileInformation(handle, fileDispositionInfo);
|
|
||||||
}
|
|
||||||
else if (information is SetFileAllocationInfo)
|
|
||||||
{
|
|
||||||
// This information level is used to set the file length in bytes.
|
|
||||||
// Note: the input will NOT be a multiple of the cluster size / bytes per sector.
|
|
||||||
FileAllocationInformation fileAllocationInfo = new FileAllocationInformation();
|
|
||||||
fileAllocationInfo.AllocationSize = ((SetFileAllocationInfo)information).AllocationSize;
|
|
||||||
return fileStore.SetFileInformation(handle, fileAllocationInfo);
|
|
||||||
}
|
|
||||||
else if (information is SetFileEndOfFileInfo)
|
|
||||||
{
|
|
||||||
FileEndOfFileInformation fileEndOfFileInfo = new FileEndOfFileInformation();
|
|
||||||
fileEndOfFileInfo.EndOfFile = ((SetFileEndOfFileInfo)information).EndOfFile;
|
|
||||||
return fileStore.SetFileInformation(handle, fileEndOfFileInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return NTStatus.STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace SMBLibrary.Server.SMB1
|
||||||
FileInformationClass informationClass;
|
FileInformationClass informationClass;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
informationClass = GetFileInformationClass(subcommand.InformationLevel);
|
informationClass = FindInformationHelper.ToFileInformationClass(subcommand.InformationLevel);
|
||||||
}
|
}
|
||||||
catch (UnsupportedInformationLevelException)
|
catch (UnsupportedInformationLevelException)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,7 @@ namespace SMBLibrary.Server.SMB1
|
||||||
FindInformationList findInformationList;
|
FindInformationList findInformationList;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
findInformationList = SMB1FileStoreHelper.GetFindInformationList(segment, subcommand.InformationLevel, header.UnicodeFlag, maxLength);
|
findInformationList = FindInformationHelper.GetFindInformationList(segment, header.UnicodeFlag, maxLength);
|
||||||
}
|
}
|
||||||
catch (UnsupportedInformationLevelException)
|
catch (UnsupportedInformationLevelException)
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,7 @@ namespace SMBLibrary.Server.SMB1
|
||||||
FindInformationList findInformationList;
|
FindInformationList findInformationList;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
findInformationList = SMB1FileStoreHelper.GetFindInformationList(segment, subcommand.InformationLevel, header.UnicodeFlag, maxLength);
|
findInformationList = FindInformationHelper.GetFindInformationList(segment, header.UnicodeFlag, maxLength);
|
||||||
}
|
}
|
||||||
catch (UnsupportedInformationLevelException)
|
catch (UnsupportedInformationLevelException)
|
||||||
{
|
{
|
||||||
|
@ -277,26 +277,5 @@ namespace SMBLibrary.Server.SMB1
|
||||||
Transaction2SetFileInformationResponse response = new Transaction2SetFileInformationResponse();
|
Transaction2SetFileInformationResponse response = new Transaction2SetFileInformationResponse();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileInformationClass GetFileInformationClass(FindInformationLevel informationLevel)
|
|
||||||
{
|
|
||||||
switch (informationLevel)
|
|
||||||
{
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
|
|
||||||
return FileInformationClass.FileDirectoryInformation;
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
|
|
||||||
return FileInformationClass.FileFullDirectoryInformation;
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
|
|
||||||
return FileInformationClass.FileNamesInformation;
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
|
|
||||||
return FileInformationClass.FileBothDirectoryInformation;
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO:
|
|
||||||
return FileInformationClass.FileIdFullDirectoryInformation;
|
|
||||||
case FindInformationLevel.SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO:
|
|
||||||
return FileInformationClass.FileIdBothDirectoryInformation;
|
|
||||||
default:
|
|
||||||
throw new UnsupportedInformationLevelException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue