public FileSystem(uint sectors, uint minIndexNodes) { //Ensure index nodes use whole sectors minIndexNodes += 8 - minIndexNodes % 8; Header = new Header() { Sectors = sectors, IndexNodes = minIndexNodes, VersionMajor = 1, VersionMinor = 0 }; IndexNodes = new IndexNode[minIndexNodes]; var dataSectors = Header.Sectors - Header.IndexSectors - 1; var bitmapSectors = 0U; while (bitmapSectors * (512 * 8) < dataSectors) { bitmapSectors++; dataSectors--; } Bitmap = new SectorBitmap(dataSectors); Header.BitmapLength = (uint)Bitmap.Bitmap.LongLength; Header.BitmapSectors = Bitmap.BitmapSectors; DataSectors = new DataSector[dataSectors]; }
public void InsertIndexNode(IndexNode node) { var index = Array.FindIndex( IndexNodes, x => x == null || !x.Flags.HasFlag(IndexFlags.Valid) ); if (index == -1) { throw new InvalidOperationException("Exausted index nodes"); } IndexNodes[index] = node; }
public IndexNode GetIndexByPath(string filePath) { var path = ("/" + (filePath.TrimStart('/'))).Split('/'); IndexNode node = null; for (var i = 0; i < path.Length; i++) { var parentId = node == null ? 0 : node.ID; node = IndexNodes.FirstOrDefault(x => x != null && x.ParentID == parentId && x.Name == path[i]); if (node == null) { return(null); } } return(node); }