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

            try
            {
                informationClass = QueryInformationHelper.ToFileInformationClass(informationLevel);
            }
            catch (UnsupportedInformationLevelException)
            {
                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);
        }
        public static FileNetworkOpenInformation GetNetworkOpenInformation(INTFileStore fileStore, object handle)
        {
            FileInformation fileInfo;
            NTStatus        status = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileNetworkOpenInformation);

            if (status != NTStatus.STATUS_SUCCESS)
            {
                return(null);
            }

            return((FileNetworkOpenInformation)fileInfo);
        }
        public static NTStatus GetFileInformation(out FileInformation result, INTFileStore fileStore, string path, FileInformationClass informationClass, SecurityContext securityContext)
        {
            object     handle;
            FileStatus fileStatus;
            NTStatus   openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);

            if (openStatus != NTStatus.STATUS_SUCCESS)
            {
                result = null;
                return(openStatus);
            }
            NTStatus returnStatus = fileStore.GetFileInformation(out result, handle, informationClass);

            fileStore.CloseFile(handle);
            return(returnStatus);
        }
        public static FileNetworkOpenInformation GetNetworkOpenInformation(INTFileStore fileStore, string path, SecurityContext securityContext)
        {
            object     handle;
            FileStatus fileStatus;
            NTStatus   openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);

            if (openStatus != NTStatus.STATUS_SUCCESS)
            {
                return(null);
            }
            FileInformation fileInfo;
            NTStatus        queryStatus = fileStore.GetFileInformation(out fileInfo, handle, FileInformationClass.FileNetworkOpenInformation);

            fileStore.CloseFile(handle);
            if (queryStatus != NTStatus.STATUS_SUCCESS)
            {
                return(null);
            }
            return((FileNetworkOpenInformation)fileInfo);
        }
        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);
            }
            }
        }