Exemple #1
0
        private void FsInfo_Query_FileFsSizeInformation_SectorsPerAllocationUnit(FileType fileType)
        {
            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 FileFsSizeInformation
            long byteCount;

            byte[] outputBuffer = new byte[0];
            FileFsSizeInformation fsSizeInfo = new FileFsSizeInformation();

            uint outputBufferSize = (uint)TypeMarshal.ToBytes <FileFsSizeInformation>(fsSizeInfo).Length;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2. Query FileFsSizeInformation");
            status = this.fsaAdapter.QueryFileSystemInformation(FileSystemInfoClass.File_FsSizeInformation, outputBufferSize, out byteCount, out outputBuffer);

            //Step 3: Verify test result
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3. Verify OutputBuffer.SectorsPerAllocationUnit");
            fsSizeInfo = TypeMarshal.ToStruct <FileFsSizeInformation>(outputBuffer);
            uint expectedSectorsPerAllocationUnit = this.fsaAdapter.ClusterSizeInKB * 1024 / fsSizeInfo.BytesPerSector;
            uint actualSectorsPerAllocationUnit   = fsSizeInfo.SectorsPerAllocationUnit;

            BaseTestSite.Log.Add(LogEntryKind.Debug, "ClusterSize is " + this.fsaAdapter.ClusterSizeInKB + " KB.");
            BaseTestSite.Log.Add(LogEntryKind.Debug, "BytesPerSector is " + fsSizeInfo.BytesPerSector + " bytes.");
            this.fsaAdapter.AssertAreEqual(this.Manager, expectedSectorsPerAllocationUnit, actualSectorsPerAllocationUnit, "OutputBuffer.SectorsPerAllocationUnit set to Open.File.Volume.ClusterSize / Open.File.Volume.LogicalBytesPerSector.");
        }
Exemple #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();
     }
 }
        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);
            }
            }
        }
Exemple #4
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);
            }
            }
        }