/* Copyright (C) 2014-2017 Tal Aloni . 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 FindInformationList GetFindInformationList(List entries, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys, int maxLength) { FindInformationList result = new FindInformationList(); for (int index = 0; index < entries.Count; index++) { FindInformation infoEntry = GetFindInformation(entries[index], informationLevel, isUnicode, returnResumeKeys); result.Add(infoEntry); if (result.GetLength(isUnicode) > maxLength) { result.RemoveAt(result.Count - 1); break; } } return result; } /// public static FindInformation GetFindInformation(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) { switch (informationLevel) { 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 = (long)entry.Size; result.AllocationSize = (long)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 = (long)entry.Size; result.AllocationSize = (long)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 = (long)entry.Size; result.AllocationSize = (long)NTFileSystemHelper.GetAllocationSize(entry.Size); result.ExtFileAttributes = GetExtendedFileAttributes(entry); result.ShortName = NTFileSystemHelper.GetShortName(entry.Name); result.FileName = entry.Name; return result; } default: { throw new UnsupportedInformationLevelException(); } } } } }