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); } } }
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); } } }