/// <summary> /// "Инициализирует" файловую систему /// </summary> /// <param name="hardDriverSize">размер диска в байтах</param> public FileSystem(int hardDriverSize) { HardDriverSize = hardDriverSize; ClusterSize = 4096; FAT = new FAT32(HardDriverSize / 4096); directoriesAndFiles = new object[FAT.TableSize]; // // Создаем корневой каталог // int clusterForRoot = FAT.GetNextFreeBlock(); Attributes rootAttributes = new Attributes(false, false, true, false, true, false); RootDirectoryCatalog = new CatalogEntry(rootAttributes, ClusterSize / 32, clusterForRoot, "\\", ""); directoriesAndFiles[clusterForRoot] = new Directory(RootDirectoryCatalog); CurrentDirectory = RootDirectoryCatalog; CreateDotFile dotFile = new CreateDotFile(this, clusterForRoot); dotFile.Execute(); }
/// <summary> /// Создает каталог /// </summary> /// <returns></returns> internal override bool Execute() { Directory currentDirectory; int clusterForDirectory = FileSystem.FAT.GetNextFreeBlock(); if (clusterForDirectory != GlobalConstants.EOC) { if (FileSystem.directoriesAndFiles[FileSystem.CurrentDirectory.FirstBlockNumber] == null) { return(false); } currentDirectory = (Directory)FileSystem.directoriesAndFiles[FileSystem.CurrentDirectory.FirstBlockNumber]; CatalogEntry catalogEntry = new CatalogEntry(attributes, FileSystem.ClusterSize / 32, clusterForDirectory, name, ""); if (!currentDirectory.IsThereFreeSpace(currentDirectory.LastUsedClusterNumber)) { int cluster = FileSystem.FAT.GetNextFreeBlock(currentDirectory.FirstClusterNumber); if (cluster == GlobalConstants.EOC) { return(false); } currentDirectory.Add(FileSystem.ClusterSize / 32, cluster); // потому что размер каталожной записи типо 32 байта } currentDirectory.AddEntry(catalogEntry); // // ниже костыль // Directory directoryToAdd = new Directory(catalogEntry); // // выше костыль // //directoryToAdd.Add(FileSystem.ClusterSize / 32, clusterForDirectory); FileSystem.directoriesAndFiles[clusterForDirectory] = directoryToAdd; CreateDotFile dotFile = new CreateDotFile(FileSystem, clusterForDirectory); CreateDoubleDotFile doubleDotFile = new CreateDoubleDotFile(FileSystem, clusterForDirectory); dotFile.Execute(); doubleDotFile.Execute(); FileSystem.directoriesAndFiles[clusterForDirectory] = directoryToAdd; return(true); } return(false); }