public static NTStatus GetFileInformation(out QueryInformation result, INTFileStore fileStore, object handle, QueryInformationLevel informationLevel)
        {
            result = null;
            FileInformation fileInfo;

            switch (informationLevel)
            {
            case QueryInformationLevel.SMB_INFO_QUERY_ALL_EAS:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case QueryInformationLevel.SMB_INFO_IS_NAME_VALID:
            {
                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.StreamSize           = fileStreamInfo.StreamSize;
                information.StreamAllocationSize = fileStreamInfo.StreamAllocationSize;
                information.StreamName           = fileStreamInfo.StreamName;
                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);
            }
            }
        }
Exemple #2
0
 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.ChangeTime;
         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;
         QueryFileEaInfo   result     = new QueryFileEaInfo();
         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.CreationTime      = fileAllInfo.BasicInformation.CreationTime;
         result.LastAccessTime    = fileAllInfo.BasicInformation.LastAccessTime;
         result.LastWriteTime     = fileAllInfo.BasicInformation.LastWriteTime;
         result.LastChangeTime    = fileAllInfo.BasicInformation.ChangeTime;
         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();
     }
 }