123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using SMBLibrary.SMB1;
- using Utilities;
- namespace SMBLibrary.Server.SMB1
- {
- public partial class SMB1FileSystemHelper
- {
- public static NTStatus GetFileInformation(out QueryInformation result, FileSystemEntry entry, bool deletePending, QueryInformationLevel informationLevel)
- {
- switch (informationLevel)
- {
- case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
- {
- QueryFileBasicInfo information = new QueryFileBasicInfo();
- information.CreationDateTime = entry.CreationTime;
- information.LastAccessDateTime = entry.LastAccessTime;
- information.LastWriteDateTime = entry.LastWriteTime;
- information.LastChangeTime = entry.LastWriteTime;
- information.ExtFileAttributes = GetExtendedFileAttributes(entry);
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
- {
- QueryFileStandardInfo information = new QueryFileStandardInfo();
- information.AllocationSize = (long)NTFileSystemHelper.GetAllocationSize(entry.Size);
- information.EndOfFile = (long)entry.Size;
- information.DeletePending = deletePending;
- information.Directory = entry.IsDirectory;
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
- {
- QueryFileExtendedAttributeInfo information = new QueryFileExtendedAttributeInfo();
- information.EASize = 0;
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
- {
- QueryFileNameInfo information = new QueryFileNameInfo();
- information.FileName = entry.Name;
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
- {
- QueryFileAllInfo information = new QueryFileAllInfo();
- information.CreationDateTime = entry.CreationTime;
- information.LastAccessDateTime = entry.LastAccessTime;
- information.LastWriteDateTime = entry.LastWriteTime;
- information.ExtFileAttributes = GetExtendedFileAttributes(entry);
- information.LastChangeTime = entry.LastWriteTime;
- information.AllocationSize = (long)NTFileSystemHelper.GetAllocationSize(entry.Size);
- information.EndOfFile = (long)entry.Size;
- information.DeletePending = deletePending;
- information.Directory = entry.IsDirectory;
- information.EASize = 0;
- information.FileName = entry.Name;
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
- {
- QueryFileAltNameInfo information = new QueryFileAltNameInfo();
- information.FileName = NTFileSystemHelper.GetShortName(entry.Name);
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
- {
- QueryFileStreamInfo information = new QueryFileStreamInfo();
- information.StreamSize = (long)entry.Size;
- information.StreamAllocationSize = (long)NTFileSystemHelper.GetAllocationSize(entry.Size);
- information.StreamName = "::$DATA";
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
- {
- QueryFileCompressionInfo information = new QueryFileCompressionInfo();
- information.CompressionFormat = CompressionFormat.COMPRESSION_FORMAT_NONE;
- result = information;
- return NTStatus.STATUS_SUCCESS;
- }
- default:
- {
- result = null;
- return NTStatus.STATUS_OS2_INVALID_LEVEL;
- }
- }
- }
- 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;
- }
- }
- }
|