/// <summary>
        /// A utility for test supported features in FileFsAttributeInformation
        /// </summary>
        /// <param name="fileType">An Open of a DataFile or DirectoryFile.</param>
        /// <param name="fileSystemAttribute">FileSystemAttribute to test.</param>
        /// <param name="isSupported">Is true, the FileSystemAttribute will be treated as supported.</param>
        private void FsInfo_Query_FileFsAttributeInformation_IsSupported(FileType fileType, FileSystemAttributes_Values fileSystemAttribute, bool isSupported)
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Test case steps:");
            MessageStatus status;

            //Step 1: Create file
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1. Create " + fileType.ToString());
            status = this.fsaAdapter.CreateFile(fileType);

            //Step 2: Query FileFsAttributeInformation
            FileFsAttributeInformation fsAttributeInfo = new FileFsAttributeInformation();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2. Query FileFsAttributeInformation");
            status = this.fsaAdapter.QueryFileFsAttributeInformation(out fsAttributeInfo);
            bool actualResult = (fsAttributeInfo.FileSystemAttributes & fileSystemAttribute) == fileSystemAttribute;

            //Step 3: verify test result
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3. Verify if FileSystemAttributes flag is correctly set.");
            string feature   = fileSystemAttribute.ToString();
            string attribute = string.Format("FileSystemAttributes.{0}", fileSystemAttribute.ToString());

            if (isSupported)
            {
                string comment = string.Format("{0} is supported and {1} MUST be set.", feature, attribute);
                this.fsaAdapter.AssertAreEqual(this.Manager, true, actualResult, comment);
            }
            else
            {
                string comment = string.Format("{0} is NOT supported and {1} MUST NOT be set.", feature, attribute);
                this.fsaAdapter.AssertAreEqual(this.Manager, false, actualResult, comment);
            }
        }
Beispiel #2
0
 public static QueryFSInformation FromFileSystemInformation(FileSystemInformation fsInfo)
 {
     if (fsInfo is FileFsVolumeInformation)
     {
         FileFsVolumeInformation volumeInfo = (FileFsVolumeInformation)fsInfo;
         QueryFSVolumeInfo       result     = new QueryFSVolumeInfo();
         result.VolumeCreationTime = volumeInfo.VolumeCreationTime;
         result.SerialNumber       = volumeInfo.VolumeSerialNumber;
         result.VolumeLabel        = volumeInfo.VolumeLabel;
         return(result);
     }
     else if (fsInfo is FileFsSizeInformation)
     {
         FileFsSizeInformation fsSizeInfo = (FileFsSizeInformation)fsInfo;
         QueryFSSizeInfo       result     = new QueryFSSizeInfo();
         result.TotalAllocationUnits     = fsSizeInfo.TotalAllocationUnits;
         result.TotalFreeAllocationUnits = fsSizeInfo.AvailableAllocationUnits;
         result.BytesPerSector           = fsSizeInfo.BytesPerSector;
         result.SectorsPerAllocationUnit = fsSizeInfo.SectorsPerAllocationUnit;
         return(result);
     }
     else if (fsInfo is FileFsDeviceInformation)
     {
         FileFsDeviceInformation fsDeviceInfo = (FileFsDeviceInformation)fsInfo;
         QueryFSDeviceInfo       result       = new QueryFSDeviceInfo();
         result.DeviceType            = fsDeviceInfo.DeviceType;
         result.DeviceCharacteristics = fsDeviceInfo.Characteristics;
         return(result);
     }
     else if (fsInfo is FileFsAttributeInformation)
     {
         FileFsAttributeInformation fsAttributeInfo = (FileFsAttributeInformation)fsInfo;
         QueryFSAttibuteInfo        result          = new QueryFSAttibuteInfo();
         result.FileSystemAttributes     = fsAttributeInfo.FileSystemAttributes;
         result.MaxFileNameLengthInBytes = fsAttributeInfo.MaximumComponentNameLength;
         result.FileSystemName           = fsAttributeInfo.FileSystemName;
         return(result);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        private bool FSInfo_Query_FileFsAttributeInformation_IsSupported(Smb2FunctionalClient client, uint treeId, FILEID fileId, FileSystemAttributes_Values attribute)
        {
            FileFsAttributeInformation fsAttributeInfo = new FileFsAttributeInformation();

            byte[] buffer;

            client.QueryFSAttributes(
                treeId,
                (byte)FileSystemInformationClasses.FileFsAttributeInformation,
                fileId,
                out buffer,
                checker: (Packet_Header header, QUERY_INFO_Response response) =>
            {
                BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status,
                                             "Query File system should return STATUS_SUCCESS, the server returns with {0}", Smb2Status.GetStatusCode(header.Status));
            }
                );

            fsAttributeInfo = TypeMarshal.ToStruct <FileFsAttributeInformation>(buffer);
            return(fsAttributeInfo.FileSystemAttributes.HasFlag(attribute));
        }
        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);
            }
            }
        }
Beispiel #5
0
        public NTStatus GetFileSystemInformation(out FileSystemInformation result, FileSystemInformationClass informationClass)
        {
            switch (informationClass)
            {
            case FileSystemInformationClass.FileFsVolumeInformation:
            {
                FileFsVolumeInformation information = new FileFsVolumeInformation();
                information.SupportsObjects = false;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsSizeInformation:
            {
                FileFsSizeInformation information = new FileFsSizeInformation();
                information.TotalAllocationUnits     = m_fileSystem.Size / ClusterSize;
                information.AvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
                information.SectorsPerAllocationUnit = ClusterSize / BytesPerSector;
                information.BytesPerSector           = BytesPerSector;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsDeviceInformation:
            {
                FileFsDeviceInformation information = new FileFsDeviceInformation();
                information.DeviceType      = DeviceType.Disk;
                information.Characteristics = DeviceCharacteristics.IsMounted;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsAttributeInformation:
            {
                FileFsAttributeInformation information = new FileFsAttributeInformation();
                information.FileSystemAttributes       = FileSystemAttributes.CasePreservedNamed | FileSystemAttributes.UnicodeOnDisk;
                information.MaximumComponentNameLength = 255;
                information.FileSystemName             = m_fileSystem.Name;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsControlInformation:
            {
                FileFsControlInformation information = new FileFsControlInformation();
                information.FileSystemControlFlags = FileSystemControlFlags.ContentIndexingDisabled;
                information.DefaultQuotaThreshold  = UInt64.MaxValue;
                information.DefaultQuotaLimit      = UInt64.MaxValue;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsFullSizeInformation:
            {
                FileFsFullSizeInformation information = new FileFsFullSizeInformation();
                information.TotalAllocationUnits           = m_fileSystem.Size / ClusterSize;
                information.CallerAvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
                information.ActualAvailableAllocationUnits = m_fileSystem.FreeSpace / ClusterSize;
                information.SectorsPerAllocationUnit       = ClusterSize / BytesPerSector;
                information.BytesPerSector = BytesPerSector;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileSystemInformationClass.FileFsObjectIdInformation:
            {
                result = null;
                // STATUS_INVALID_PARAMETER is returned when the file system does not implement object IDs
                // See: https://msdn.microsoft.com/en-us/library/cc232106.aspx
                return(NTStatus.STATUS_INVALID_PARAMETER);
            }

            case FileSystemInformationClass.FileFsSectorSizeInformation:
            {
                FileFsSectorSizeInformation information = new FileFsSectorSizeInformation();
                information.LogicalBytesPerSector = BytesPerSector;
                information.PhysicalBytesPerSectorForAtomicity   = BytesPerSector;
                information.PhysicalBytesPerSectorForPerformance = BytesPerSector;
                information.FileSystemEffectivePhysicalBytesPerSectorForAtomicity = BytesPerSector;
                information.ByteOffsetForSectorAlignment    = 0;
                information.ByteOffsetForPartitionAlignment = 0;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            default:
            {
                result = null;
                return(NTStatus.STATUS_INVALID_INFO_CLASS);
            }
            }
        }