public static DataStreamTestCollaboratorSet CreateCollaboratorsForTestingDataStreamsOneGigabyteDrive() { var stream = new FileStream(@"e:\tests.vhd", FileMode.Create); var formatter = new VirtualDiskFormatter(); VirtualDisk disk = VirtualDisk.CreateFormattingTheStream(stream, 2048, 2048 * 500000); var diskStructuresManager = new FileSystemNodeStorage(disk); formatter.Format(disk, diskStructuresManager); FileSystemHeader header = diskStructuresManager.ReadFileSystemHeader(VirtualDiskFormatter.FileSystemHeaderBlockIndex); var nameValidator = FileSystemArtifactNamesValidator.Default; var pathValidator = PathValidator.Default; var pathBuilder = PathBuilder.Default; var nodeResolver = new NodeResolver(disk, diskStructuresManager, StringComparer.OrdinalIgnoreCase, header.RootBlockOffset, VirtualFileSystem.Root, VirtualFileSystem.DirectorySeparatorChar, pathValidator, pathBuilder); var virtualFileSystem = VirtualFileSystem.CreateFromDisk(disk, StringComparer.OrdinalIgnoreCase, nodeResolver, pathBuilder, nameValidator, pathValidator); var fileNodeFake = virtualFileSystem.CreateFile(@"\hey"); return(new DataStreamTestCollaboratorSet(disk, diskStructuresManager, fileNodeFake, virtualFileSystem)); }
internal static AllCollaborators CreateAllCollaborators(int numberOfBlocks, bool createTestFile) { var stream = new MemoryStream(); // new FileStream(@"e:\" + Guid.NewGuid().ToString("N"), FileMode.Create); var formatter = new VirtualDiskFormatter(); VirtualDisk disk = VirtualDisk.CreateFormattingTheStream(stream, VirtualDisk.OnlySupportedBlockSize, VirtualDisk.OnlySupportedBlockSize * numberOfBlocks); var diskStructuresManager = new FileSystemNodeStorage(disk); formatter.Format(disk, diskStructuresManager); FileSystemHeader header = diskStructuresManager.ReadFileSystemHeader(VirtualDiskFormatter.FileSystemHeaderBlockIndex); var nameValidator = FileSystemArtifactNamesValidator.Default; var pathValidator = PathValidator.Default; var pathBuilder = PathBuilder.Default; var nodeResolver = new NodeResolver(disk, diskStructuresManager, StringComparer.OrdinalIgnoreCase, header.RootBlockOffset, VirtualFileSystem.Root, VirtualFileSystem.DirectorySeparatorChar, pathValidator, pathBuilder); var virtualFileSystem = VirtualFileSystem.CreateFromDisk(disk, StringComparer.OrdinalIgnoreCase, nodeResolver, pathBuilder, nameValidator, pathValidator); FileInfo fileNodeFake = null; if (createTestFile) { fileNodeFake = virtualFileSystem.CreateFile(@"\hey"); } return(new AllCollaborators(disk, diskStructuresManager, nameValidator, pathValidator, nodeResolver, virtualFileSystem, fileNodeFake, stream)); }
public void TryFormattingADiskAndInitializingFileSystemWithIt() { Stream stream = new MemoryStream(); // System.IO.File.Open(@"c:\bs.bin", FileMode.Create); var formatter = new VirtualDiskFormatter(); VirtualDisk disk = VirtualDisk.CreateFormattingTheStream(stream, 2048, 2048 * 5000); var diskStructuresManager = new FileSystemNodeStorage(disk); formatter.Format(disk, diskStructuresManager); FileSystemHeader header = diskStructuresManager.ReadFileSystemHeader(VirtualDiskFormatter.FileSystemHeaderBlockIndex); var nameValidator = new FileSystemArtifactNamesValidator(Constants.IllegalCharactersForNames, Constants.FileAndFolderMaximumNameLength); var pathValidator = new PathValidator(VirtualFileSystem.Root, Constants.IllegalCharactersForPaths, nameValidator, VirtualFileSystem.DirectorySeparatorChar); var pathBuilder = PathBuilder.Default; var nodeResolver = new NodeResolver(disk, diskStructuresManager, StringComparer.OrdinalIgnoreCase, header.RootBlockOffset, VirtualFileSystem.Root, VirtualFileSystem.DirectorySeparatorChar, pathValidator, pathBuilder); VirtualFileSystem fileSystem = VirtualFileSystem.CreateFromDisk(disk, StringComparer.OrdinalIgnoreCase, nodeResolver, pathBuilder, nameValidator, pathValidator); Assert.AreEqual(2048, fileSystem.FileSystemInfo.BlockSizeInBytes); Assert.AreEqual(new Version(1, 0, 0, 0), fileSystem.FileSystemInfo.Version); }
public void MakeSureWriteReadCycleWorksOnFreeSpaceMap() { Stream stream = new FileStream(@"e:\diskTests.tst", FileMode.Create); // new MemoryStream(); var disk = VirtualDisk.CreateFormattingTheStream(stream, 2048, 15000 * 2048); const int numberOfBlocksToMap = 150000; var mapBytes = new byte[numberOfBlocksToMap]; var bitArray = new BitArray(mapBytes); bitArray.Length = numberOfBlocksToMap; var freeBlockManager = new FreeBlockManagerBitArrayBased(bitArray, 22, numberOfBlocksToMap); freeBlockManager.AcquireFreeBlocks(7000); freeBlockManager.AcquireFreeBlocks(24); var bitmapStore = new FreeSpaceBitmapStore(disk, VirtualDiskFormatter.FreeSpaceStartingBlockIndex); var bytes = new byte[SpaceRequirementsCalculator.GetNumberOfChunksNeededToStoreData(numberOfBlocksToMap, Constants.NumberOfBitsInByte)]; bitArray.CopyTo(bytes, 0); bitmapStore.WriteMap(bytes, numberOfBlocksToMap); int bitmapSize; var bytesRead = bitmapStore.ReadMap(out bitmapSize); Assert.AreEqual(numberOfBlocksToMap, bitmapSize); CollectionAssert.AreEqual(bytes, bytesRead); }
public void MakeSureYouCanCreateVirtualDiskOnlyOfSizeAlignedWithDiskBlockSize() { MemoryStream testStream = new MemoryStream(); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(delegate() { VirtualDisk.CreateFormattingTheStream(testStream, 2048, 77777); }); }
public static VirtualDiskWithItsStream ConstructDefaultTestDiskWithStream() { var diskBackingStream = new MemoryStream(); //diskBackingStream = // System.IO.File.Open(Path.Combine(TestContext.TestDeploymentDir, Guid.NewGuid().ToString("N") + ".hdd"), FileMode.CreateNew, FileAccess.ReadWrite); VirtualDisk virtualDisk = VirtualDisk.CreateFormattingTheStream(diskBackingStream, DefaultDiskBlockSize, DefaultDiskSize); return(new VirtualDiskWithItsStream(virtualDisk, diskBackingStream)); }
/// <summary> /// Создает виртуальную файловую систему с настройками по умолчанию, на основе указанного файла. /// </summary> /// <param name="fullPathForFile">Файл, который файловая система должна использовать для хранения своих данных. Принимаются только пути, ведущие к несуществующим файлам.</param> /// <param name="desiredSizeInBytes">Размер нового диска. В текущей версии должен быть кратен 2048 байтам, не больше 1Гб.</param> /// <returns>Экземпляр файловой системы, в качестве хранилища использующей указанный файл.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="FileSystemCreationFailedException"></exception> public static VirtualFileSystem CreateNew(string fullPathForFile, int desiredSizeInBytes) { if (String.IsNullOrEmpty(fullPathForFile)) { throw new ArgumentNullException("fullPathForFile", "Путь к файлу не может быть пустым."); } var stream = CreateStreamWrappingExceptions(fullPathForFile); try { var formatter = new VirtualDiskFormatter(); VirtualDisk disk = VirtualDisk.CreateFormattingTheStream(stream, VirtualDisk.OnlySupportedBlockSize, desiredSizeInBytes); var diskStructuresManager = new FileSystemNodeStorage(disk); formatter.Format(disk, diskStructuresManager); FileSystemHeader header = diskStructuresManager.ReadFileSystemHeader(VirtualDiskFormatter.FileSystemHeaderBlockIndex); var nameValidator = FileSystemArtifactNamesValidator.Default; var pathValidator = PathValidator.Default; var pathBuilder = PathBuilder.Default; var nodeResolver = new NodeResolver(disk, diskStructuresManager, StringComparer.OrdinalIgnoreCase, header.RootBlockOffset, VirtualFileSystem.Root, VirtualFileSystem.DirectorySeparatorChar, pathValidator, pathBuilder); var newVirtualFileSystem = VirtualFileSystem.CreateFromDisk(disk, StringComparer.OrdinalIgnoreCase, nodeResolver, pathBuilder, nameValidator, pathValidator); return(newVirtualFileSystem); } catch (InconsistentDataDetectedException exception) { CleanUpInconsistentFileSystemContainer(fullPathForFile, stream); throw CreateGenericSystemCreationException(exception, fullPathForFile); } catch (VirtualDiskCreationFailedException exception) { CleanUpInconsistentFileSystemContainer(fullPathForFile, stream); throw CreateGenericSystemCreationException(exception, fullPathForFile); } }