Example #1
0
        public void GetFileSystemInformation(out QueryFSInformation result, QueryFSInformationLevel informationLevel)
        {
            int maxOutputLength = 4096;
            Transaction2QueryFSInformationRequest subcommand = new Transaction2QueryFSInformationRequest
            {
                QueryFSInformationLevel = informationLevel
            };

            Transaction2Request request = new Transaction2Request
            {
                Setup           = subcommand.GetSetup(),
                TransParameters = subcommand.GetParameters(m_client.Unicode),
                TransData       = subcommand.GetData(m_client.Unicode)
            };

            request.TotalDataCount      = (ushort)request.TransData.Length;
            request.TotalParameterCount = (ushort)request.TransParameters.Length;
            request.MaxParameterCount   = Transaction2QueryFSInformationResponse.ParametersLength;
            request.MaxDataCount        = (ushort)maxOutputLength;

            TrySendMessage(request);
            SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);

            if (reply.Header.Status != NTStatus.STATUS_SUCCESS || !(reply.Commands[0] is Transaction2Response))
            {
                throw new NtStatusException(reply.Header.Status);
            }

            Transaction2Response response = (Transaction2Response)reply.Commands[0];
            Transaction2QueryFSInformationResponse subcommandResponse = new Transaction2QueryFSInformationResponse(response.TransData);

            result = subcommandResponse.GetQueryFSInformation(informationLevel);
        }
        public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel, bool isUnicode)
        {
            switch (informationLevel)
            {
            case QueryFSInformationLevel.SMB_INFO_ALLOCATION:
                return(new QueryFSInfoAllocation(buffer, 0));

            case QueryFSInformationLevel.SMB_INFO_VOLUME:
                return(new QueryFSInfoVolume(isUnicode, buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
                return(new QueryFSVolumeInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
                return(new QueryFSSizeInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
                return(new QueryFSDeviceInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
                return(new QueryFSAttibuteInfo(buffer, 0));

            default:
                throw new InvalidRequestException();
            }
        }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationFinalResponsePacket(SmbTrans2QueryFsInformationFinalResponsePacket packet)
     : base(packet)
 {
     this.InitDefaultValue();
     this.trans2Data.Data  = packet.trans2Data.Data;
     this.informationLevel = packet.informationLevel;
 }
Example #4
0
        public NTStatus GetFileSystemInformation(out QueryFSInformation result, QueryFSInformationLevel informationLevel)
        {
            result = null;
            int maxOutputLength = 4096;
            Transaction2QueryFSInformationRequest subcommand = new Transaction2QueryFSInformationRequest();

            subcommand.QueryFSInformationLevel = informationLevel;

            Transaction2Request request = new Transaction2Request();

            request.Setup               = subcommand.GetSetup();
            request.TransParameters     = subcommand.GetParameters(m_client.Unicode);
            request.TransData           = subcommand.GetData(m_client.Unicode);
            request.TotalDataCount      = (ushort)request.TransData.Length;
            request.TotalParameterCount = (ushort)request.TransParameters.Length;
            request.MaxParameterCount   = Transaction2QueryFSInformationResponse.ParametersLength;
            request.MaxDataCount        = (ushort)maxOutputLength;

            TrySendMessage(request);
            SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);

            if (reply != null)
            {
                if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
                {
                    Transaction2Response response = (Transaction2Response)reply.Commands[0];
                    Transaction2QueryFSInformationResponse subcommandResponse = new Transaction2QueryFSInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
                    result = subcommandResponse.GetQueryFSInformation(informationLevel, reply.Header.UnicodeFlag);
                }
                return(reply.Header.Status);
            }
            return(NTStatus.STATUS_INVALID_SMB);
        }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationFinalResponsePacket(SmbTrans2QueryFsInformationFinalResponsePacket packet)
     : base(packet)
 {
     this.InitDefaultValue();
     this.trans2Data.Data = packet.trans2Data.Data;
     this.informationLevel = packet.informationLevel;
 }
Example #6
0
 public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel)
 {
     return(informationLevel switch
     {
         QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO => new QueryFSVolumeInfo(buffer, 0),
         QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO => new QueryFSSizeInfo(buffer),
         QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO => new QueryFSDeviceInfo(buffer, 0),
         QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO => new QueryFSAttibuteInfo(buffer, 0),
         _ => throw new UnsupportedInformationLevelException()
     });
Example #7
0
 /// <exception cref="UnsupportedInformationLevelException"></exception>
 public static FileSystemInformationClass ToFileSystemInformationClass(QueryFSInformationLevel informationLevel)
 {
     return(informationLevel switch
     {
         QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO => FileSystemInformationClass.FileFsVolumeInformation,
         QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO => FileSystemInformationClass.FileFsSizeInformation,
         QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO => FileSystemInformationClass.FileFsDeviceInformation,
         QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO => FileSystemInformationClass
         .FileFsAttributeInformation,
         _ => throw new UnsupportedInformationLevelException()
     });
Example #8
0
        public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel, bool isUnicode)
        {
            switch (informationLevel)
            {
            case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
                return(new QueryFSVolumeInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
                return(new QueryFSSizeInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
                return(new QueryFSDeviceInfo(buffer, 0));

            case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
                return(new QueryFSAttibuteInfo(buffer, 0));

            default:
                throw new UnsupportedInformationLevelException();
            }
        }
Example #9
0
        /// <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();
            }
        }
 /// <summary>
 /// Create Trans2SetFileSystemInformation requestor client to set the file system information on server. 
 /// </summary>
 /// <param name = "fileId">the valid file id to operation on, response by server. </param>
 /// <param name = "transactOptions">
 /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
 /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
 /// client MAY set either or both of the following bit flags 
 /// </param>
 /// <param name = "informationLevel">
 /// Indicates that client specifies the information it is requesting. Server return different data based on 
 /// the client's request. 
 /// </param>
 /// <param name = "data">the information data to be set. </param>
 /// <returns>a set file information request packet </returns>
 public virtual SmbTrans2SetFsInformationRequestPacket CreateTrans2SetFileSystemInformationRequest(
     ushort fileId,
     Trans2SmbParametersFlags transactOptions,
     QueryFSInformationLevel informationLevel,
     byte[] data)
 {
     return CreateTrans2SetFileSystemInformationRequest(
         this.MessageId,
         this.GetSessionIdByFileId(fileId), this.GetTreeIdByFileId(fileId), this.capability.Flag,
         this.capability.Flags2, fileId, transactOptions, this.capability.Timeout,
         this.capability.IsUsePathThrough,
         informationLevel, data);
 }
 /// <summary>
 /// Create Trans2QueryFileSystemInformation request for client to query the file system information on server. 
 /// </summary>
 /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param>
 /// <param name = "maxDataCount">
 /// The maximum number of data bytes that the client will accept in the transaction reply. The server MUST NOT 
 /// return more than this number of data bytes. 
 /// </param>
 /// <param name = "transactOptions">
 /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
 /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
 /// client MAY set either or both of the following bit flags 
 /// </param>
 /// <param name = "informationLevel">
 /// Indicates that client specifies the information it is requesting. Server return different data based on 
 /// the client's request. 
 /// </param>
 /// <returns>a query file system information request packet </returns>
 public virtual SmbTrans2QueryFsInformationRequestPacket CreateTrans2QueryFileSystemInformationRequest(
     ushort treeId,
     ushort maxDataCount,
     Trans2SmbParametersFlags transactOptions,
     QueryFSInformationLevel informationLevel)
 {
     return CreateTrans2QueryFileSystemInformationRequest(
         this.MessageId, this.GetSessionIdByTreeId(treeId), treeId, this.capability.Flag,
         this.capability.Flags2, this.capability.IsUsePathThrough,
         maxDataCount, transactOptions, this.capability.Timeout, informationLevel);
 }
Example #12
0
 public Transaction2QueryFSInformationResponse(byte[] parameters, byte[] data, QueryFSInformationLevel informationLevel, bool isUnicode) : base()
 {
     QueryFSInfo = QueryFSInformation.GetQueryFSInformation(data, informationLevel, isUnicode);
 }
 public QueryFSInformation GetQueryFSInformation(QueryFSInformationLevel informationLevel, bool isUnicode)
 {
     return(QueryFSInformation.GetQueryFSInformation(InformationBytes, informationLevel, isUnicode));
 }
Example #14
0
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationResponsePacket(QueryFSInformationLevel informationLevel)
     : base((QueryFSInformationLevel)informationLevel)
 {
 }
Example #15
0
        internal static QueryFSInformation GetFSInformation(QueryFSInformationLevel informationLevel, IFileSystem fileSystem)
        {
            switch (informationLevel)
            {
            case QueryFSInformationLevel.SMB_INFO_ALLOCATION:
            {
                QueryFSInfoAllocation result = new QueryFSInfoAllocation();
                result.FileSystemID   = 0;
                result.SectorUnit     = ClusterSize / BytesPerSector;
                result.UnitsTotal     = (uint)Math.Min(fileSystem.Size / ClusterSize, UInt32.MaxValue);
                result.UnitsAvailable = (uint)Math.Min(fileSystem.FreeSpace / ClusterSize, UInt32.MaxValue);
                result.Sector         = BytesPerSector;
                return(result);
            }

            case QueryFSInformationLevel.SMB_INFO_VOLUME:
            {
                QueryFSInfoVolume result = new QueryFSInfoVolume();
                result.VolumeLabel        = String.Empty;
                result.VolumeSerialNumber = 0;
                return(result);
            }

            case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
            {
                QueryFSVolumeInfo result = new QueryFSVolumeInfo();
                result.VolumeCreationTime = DateTime.Now;
                return(result);
            }

            case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
            {
                QueryFSSizeInfo result = new QueryFSSizeInfo();
                result.TotalAllocationUnits     = (ulong)(fileSystem.Size / ClusterSize);
                result.TotalFreeAllocationUnits = (ulong)(fileSystem.FreeSpace / ClusterSize);
                result.BytesPerSector           = BytesPerSector;
                result.SectorsPerAllocationUnit = ClusterSize / BytesPerSector;
                return(result);
            }

            case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
            {
                QueryFSDeviceInfo result = new QueryFSDeviceInfo();
                result.DeviceCharacteristics = DeviceCharacteristics.FILE_DEVICE_IS_MOUNTED;
                result.DeviceType            = DeviceType.FILE_DEVICE_DISK;
                return(result);
            }

            case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
            {
                QueryFSAttibuteInfo result = new QueryFSAttibuteInfo();
                result.FileSystemAttributes     = FileSystemAttributes.FILE_UNICODE_ON_DISK;
                result.MaxFileNameLengthInBytes = 255;
                result.FileSystemName           = fileSystem.Name;
                return(result);
            }

            default:
            {
                throw new UnsupportedInformationLevelException();
            }
            }
        }
        public static NTStatus GetFileSystemInformation(out QueryFSInformation result, INTFileStore fileStore, QueryFSInformationLevel informationLevel)
        {
            result = null;

            FileSystemInformation fsInfo;

            switch (informationLevel)
            {
            case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
            {
                NTStatus status = fileStore.GetFileSystemInformation(out fsInfo, FileSystemInformationClass.FileFsVolumeInformation);
                if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(status);
                }

                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);
            }
            }
        }
Example #17
0
 public QueryFSInformation GetQueryFSInformation(QueryFSInformationLevel informationLevel)
 {
     return(QueryFSInformation.GetQueryFSInformation(InformationBytes, informationLevel));
 }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationResponsePacket(QueryFSInformationLevel informationLevel)
     : base((QueryFSInformationLevel)informationLevel)
 {
 }
 /// <summary>
 /// to create a Trans2QueryFsInformation request packet.
 /// </summary>
 /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
 /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
 /// accessing.</param>
 /// <param name="name">This field is present but not used in SMB_COM_TRANSACTION2 requests. If Unicode support
 /// has been negotiated, then this field MUST be aligned to a 16-bit boundary and MUST consist of two null bytes
 /// (a null-terminator). If Unicode support has not been negotiated this field will contain only one null
 /// byte.</param>
 /// <param name="informationLevel">This field contains an information level code, which determines the
 /// information contained in the response.</param>
 /// <returns>a Trans2QueryFsInformation request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbTrans2QueryFsInformationRequestPacket CreateTrans2QueryFsInformationRequest(
     ushort uid,
     ushort treeId,
     string name,
     QueryFSInformationLevel informationLevel)
 {
     return this.CreateTrans2QueryFsInformationRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, this.defaultParameters.MaxParameterCount,
         this.defaultParameters.MaxDataCount, this.defaultParameters.MaxSetupCount, this.defaultParameters.Trans2SmbParametersFlags,
         this.defaultParameters.Timeout, name, informationLevel);
 }
        /// <summary>
        /// to create a Trans2QueryFsInformation request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="maxParameterCount">The maximum number of parameter bytes that the client will accept in the
        /// transaction reply. The server MUST NOT return more than this number of parameter bytes.</param>
        /// <param name="maxDataCount">The maximum number of data bytes that the client will accept in the transaction
        /// reply. The server MUST NOT return more than this number of data bytes.</param>
        /// <param name="maxSetupCount">Maximum number of setup bytes that the client will accept in the transaction
        /// reply. The server MUST NOT return more than this number of setup bytes</param>
        /// <param name="smbParametersFlags">A set of bit flags that alter the behavior of the requested operation.
        /// Unused bit fields MUST be set to zero by the client sending the request, and MUST be ignored by the server
        /// receiving the request. The client MAY set either or both of the following bit flags</param>
        /// <param name="timeout">The number of milliseconds the server SHOULD wait for completion of the transaction
        /// before generating a timeout. A value of zero indicates that the operation MUST NOT block.</param>
        /// <param name="informationLevel">This field contains an information level code, which determines the
        /// information contained in the response.</param>
        /// <param name="name">This field is present but not used in SMB_COM_TRANSACTION2 requests. If Unicode support
        /// has been negotiated, then this field MUST be aligned to a 16-bit boundary and MUST consist of two null bytes
        /// (a null-terminator). If Unicode support has not been negotiated this field will contain only one null
        /// byte.</param>
        /// <returns>a Trans2QueryFsInformation request packet</returns>
        public SmbTrans2QueryFsInformationRequestPacket CreateTrans2QueryFsInformationRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort maxParameterCount,
            ushort maxDataCount,
            byte maxSetupCount,
            Trans2SmbParametersFlags smbParametersFlags,
            uint timeout,
            string name,
            QueryFSInformationLevel informationLevel)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            SmbTrans2QueryFsInformationRequestPacket packet = new SmbTrans2QueryFsInformationRequestPacket();
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION2,
                messageId, uid, treeId, flags, flags2);

            // Set Smb_Parameters
            SMB_COM_TRANSACTION2_Request_SMB_Parameters smbParameters =
                new SMB_COM_TRANSACTION2_Request_SMB_Parameters();
            smbParameters.MaxParameterCount = maxParameterCount;
            smbParameters.MaxDataCount = maxDataCount;
            smbParameters.MaxSetupCount = maxSetupCount;
            smbParameters.Flags = (ushort)smbParametersFlags;
            smbParameters.Timeout = timeout;
            smbParameters.SetupCount = 1; // the correct count in word of the Setup is always 1.
            smbParameters.Setup = new ushort[] { (ushort)Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION };
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION2_Request_SMB_Parameters>(
                smbParameters) / NumBytesOfWord);

            // Set Smb_Data
            SMB_COM_TRANSACTION2_Request_SMB_Data smbData = new SMB_COM_TRANSACTION2_Request_SMB_Data();
            smbData.Name = CifsMessageUtils.ToSmbStringBytes(name,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);

            // Set Trans2_Parameters
            TRANS2_QUERY_FS_INFORMATION_Request_Trans2_Parameters trans2Parameters =
                new TRANS2_QUERY_FS_INFORMATION_Request_Trans2_Parameters();
            trans2Parameters.InformationLevel = informationLevel;

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;
            packet.Trans2Parameters = trans2Parameters;
            packet.UpdateCountAndOffset();

            return packet;
        }
 /// <summary>
 /// Check if the information level matches the information structure.
 /// </summary>
 /// <param name="level">information level</param>
 /// <param name="queryFsInformationLevel">information level structure</param>
 /// <returns>true if the level matches the structure, false if not.</returns>
 private bool CheckInformationLevel(QueryFSInformationLevel level, object queryFsInformationLevel)
 {
     bool ret = false;
     switch (level)
     {
         case QueryFSInformationLevel.SMB_INFO_ALLOCATION:
             ret = queryFsInformationLevel is SMB_INFO_ALLOCATION;
             break;
         case QueryFSInformationLevel.SMB_INFO_VOLUME:
             ret = queryFsInformationLevel is SMB_INFO_VOLUME;
             break;
         case QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO:
             ret = queryFsInformationLevel is SMB_QUERY_FS_VOLUME_INFO;
             break;
         case QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO:
             ret = queryFsInformationLevel is SMB_QUERY_FS_SIZE_INFO;
             break;
         case QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO:
             ret = queryFsInformationLevel is SMB_QUERY_FS_DEVICE_INFO;
             break;
         case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
             ret = queryFsInformationLevel is SMB_QUERY_FS_ATTRIBUTE_INFO;
             break;
         default:
             break;
     }
     return ret;
 }
        /// <summary>
        /// Create Trans2QueryFileSystemInformation request for client to query the file system information on server. 
        /// </summary>
        /// <param name = "messageId">the id of message, used to identity the request and the server response. </param>
        /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param>
        /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param>
        /// <param name = "flags">
        /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. 
        /// </param>
        /// <param name = "flags2">
        /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate   
        /// various client and server capabilities. 
        /// </param>
        /// <param name = "isUsePathThrough">
        /// Indicates that the client is requesting a native Microsoft Windows® NT operating system information level, 
        /// as specified in section 3.2.4.7 and in [MS-FSCC] section 2.4. 
        /// </param>
        /// <param name = "maxDataCount">
        /// The maximum number of data bytes that the client will accept in the transaction reply. The server MUST NOT 
        /// return more than this number of data bytes. 
        /// </param>
        /// <param name = "transactOptions">
        /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
        /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
        /// client MAY set either or both of the following bit flags 
        /// </param>
        /// <param name = "timeOut">
        /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set  
        /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified  
        /// time, the server MAY abort the request and send a failure response. 
        /// </param>
        /// <param name = "informationLevel">
        /// Indicates that client specifies the information it is requesting. Server return different data based on 
        /// the client's request. 
        /// </param>
        /// <returns>a query file system information request packet </returns>
        private SmbTrans2QueryFsInformationRequestPacket CreateTrans2QueryFileSystemInformationRequest(
            ushort messageId,
            ushort sessionUid,
            ushort treeId,
            SmbHeader_Flags_Values flags,
            SmbHeader_Flags2_Values flags2,
            bool isUsePathThrough,
            ushort maxDataCount,
            Trans2SmbParametersFlags transactOptions,
            uint timeOut,
            QueryFSInformationLevel informationLevel)
        {
            if (isUsePathThrough)
            {
                informationLevel = (QueryFSInformationLevel)
                    (informationLevel + SmbCapability.CONST_SMB_INFO_PASSTHROUGH);
            }

            return new SmbTrans2QueryFsInformationRequestPacket(
                this.cifsClient.CreateTrans2QueryFsInformationRequest(
                messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2,
                this.capability.MaxParameterCount, maxDataCount, this.capability.MaxSetupCount,
                transactOptions, timeOut, "", informationLevel));
        }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationFinalResponsePacket(QueryFSInformationLevel informationLevel)
 {
     this.InitDefaultValue();
     this.informationLevel = informationLevel;
 }
        /// <summary>
        /// Create Trans2SetFileSystemInformation requestfor client to set the file system information on server. 
        /// </summary>
        /// <param name = "messageId">the id of message, used to identity the request and the server response. </param>
        /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param>
        /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param>
        /// <param name = "flags">
        /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. 
        /// </param>
        /// <param name = "flags2">
        /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate   
        /// various client and server capabilities. 
        /// </param>
        /// <param name = "fileId">the valid file id to operation on, response by server. </param>
        /// <param name = "transactOptions">
        /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
        /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
        /// client MAY set either or both of the following bit flags 
        /// </param>
        /// <param name = "timeOut">
        /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set  
        /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified  
        /// time, the server MAY abort the request and send a failure response. 
        /// </param>
        /// <param name = "isUsePathThrough">
        /// Indicates that the client is requesting a native Microsoft Windows® NT operating system information level, 
        /// as specified in section 3.2.4.7 and in [MS-FSCC] section 2.4. 
        /// </param>
        /// <param name = "informationLevel">
        /// Indicates that client specifies the information it is requesting. Server return different data based on 
        /// the client's request. 
        /// </param>
        /// <param name = "data">the information data to be set. </param>
        /// <returns>a set file information request packet </returns>
        private SmbTrans2SetFsInformationRequestPacket CreateTrans2SetFileSystemInformationRequest(
            ushort messageId,
            ushort sessionUid,
            ushort treeId,
            SmbHeader_Flags_Values flags,
            SmbHeader_Flags2_Values flags2,
            ushort fileId,
            Trans2SmbParametersFlags transactOptions,
            uint timeOut,
            bool isUsePathThrough,
            QueryFSInformationLevel informationLevel,
            byte[] data)
        {
            if (isUsePathThrough)
            {
                informationLevel = (QueryFSInformationLevel)
                    (informationLevel + SmbCapability.CONST_SMB_INFO_PASSTHROUGH);
            }

            SmbTrans2SetFsInformationRequestPacket packet =
                new SmbTrans2SetFsInformationRequestPacket(
                this.cifsClient.CreateTrans2SetFsInformationRequest(
                messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2,
                this.capability.MaxParameterCount, this.capability.MaxDataCount, this.capability.MaxSetupCount,
                transactOptions, timeOut, ""));

            // Set Trans2_Parameters
            TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Parameters trans2Parameters =
                new TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Parameters();
            trans2Parameters.FID = fileId;
            trans2Parameters.InformationLevel = informationLevel;

            // Set Trans2_Data
            TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Data trans2Data =
                new TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Data();
            trans2Data.Data = data;

            packet.Trans2Parameters = trans2Parameters;
            packet.Trans2Data = trans2Data;

            packet.UpdateCountAndOffset();

            return packet;
        }
        public static NTStatus GetFileSystemInformation(out QueryFSInformation result, INTFileStore fileStore, QueryFSInformationLevel informationLevel)
        {
            result = null;
            FileSystemInformationClass informationClass;

            try
            {
                informationClass = QueryFSInformationHelper.ToFileSystemInformationClass(informationLevel);
            }
            catch (UnsupportedInformationLevelException)
            {
                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);
        }
 public Transaction2QueryFSInformationRequest(byte[] parameters, byte[] data, bool isUnicode) : base()
 {
     InformationLevel = (QueryFSInformationLevel)LittleEndianConverter.ToUInt16(parameters, 0);
 }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbTrans2QueryFsInformationFinalResponsePacket(QueryFSInformationLevel informationLevel)
 {
     this.InitDefaultValue();
     this.informationLevel = informationLevel;
 }