public static void ExtendBlocks(VirtualDrive drive, List <VirtualBlock> blocks, int initialFileLength, int finalFileLength) { int initialSectorcount = BlocksNeeded(drive, initialFileLength); int finalSectorcount = BlocksNeeded(drive, finalFileLength); if (finalSectorcount > initialSectorcount) { int[] freeSectors = drive.GetNextFreeSectors(finalSectorcount - initialSectorcount); DATA_SECTOR dataSector = blocks.Last().Sector; foreach (int freeSector in freeSectors) { int currentSector = dataSector.NextSectorAt = freeSector; dataSector = new DATA_SECTOR(drive.Disk.BytesPerSector, 0, null); blocks.Add(new VirtualBlock(drive, currentSector, dataSector, true)); } } }
private VirtualNode CommonMake(string name, bool makeFile = true) { if (mSector.Type != SECTOR.SectorType.DIR_NODE) { throw new Exception($"Cannot create Dir/File under node type " + mSector.Type.ToString()); } LoadChildren(); if (mChildren.ContainsKey(name)) { throw new Exception("Name already in use!"); } int[] nextFreeSectors = mDrive.GetNextFreeSectors(2); int nodeAddr = nextFreeSectors[0]; int dataAddr = nextFreeSectors[1]; NODE newNode = null; if (makeFile) { newNode = new FILE_NODE(mDrive.Disk.BytesPerSector, dataAddr, name, 0); } else { newNode = new DIR_NODE(mDrive.Disk.BytesPerSector, dataAddr, name, 0); } DATA_SECTOR dirdata = new DATA_SECTOR(mDrive.Disk.BytesPerSector, 0, null); mDrive.Disk.WriteSector(nodeAddr, newNode.RawBytes); mDrive.Disk.WriteSector(dataAddr, dirdata.RawBytes); VirtualNode child = new VirtualNode(mDrive, nodeAddr, newNode, this); mChildren[name] = child; CommitChildren(); return(child); }