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