public static void Write(Partition p, FSBlock b) { Byte[] data = new Byte[p.BlockSize]; int index = 0; if (b.Used) { data[index++] = 0x01; } else { data[index++] = 0x00; } Byte[] x = BitConverter.GetBytes(b.ContentSize); for (int i = 0; i < x.Length; i++) { data[index++] = x[i]; } x = BitConverter.GetBytes(b.TotalSize); for (int i = 0; i < x.Length; i++) { data[index++] = x[i]; } x = BitConverter.GetBytes(b.NextBlock); for (int i = 0; i < x.Length; i++) { data[index++] = x[i]; } x = b.Content; for (int i = 0; i < x.Length; i++) { data[index++] = x[i]; } p.WriteBlock(b.BlockNumber, 1, data); }
public Entry[] GetEntries() { FSBlock curb = _StartBlock; List <Entry> d = new List <Entry>(); while (curb.NextBlock != 0) { int index = 0; curb = FSBlock.Read(_StartBlock.Partition, _StartBlock.NextBlock); while (index < curb.ContentSize) { ulong a = BitConverter.ToUInt64(curb.Content, index); index += 8; uint sep = BitConverter.ToUInt32(curb.Content, index); index += 4; if (sep == 1) { d.Add(new PulsarDirectory(part, a, FileSystem.CombineDir(_Path, Name))); } else if (sep == 2) { d.Add(new File(part, a, FileSystem.CombineDir(_Path, Name))); } } } return(d.ToArray()); }
private FSBlock GetBlockToEdit() { FSBlock ret = _StartBlock; while (ret.NextBlock != 0) { ret = FSBlock.Read(_StartBlock.Partition, _StartBlock.NextBlock); } if (ret.BlockNumber == _StartBlock.BlockNumber) { ret = FSBlock.GetFreeBlock(part); ret.Used = true; ret.ContentSize = 0; ret.NextBlock = 0; _StartBlock.NextBlock = ret.BlockNumber; FSBlock.Write(part, _StartBlock); FSBlock.Write(part, ret); } if (part.NewBlockArray(1).Length - ret.ContentSize < 12) { FSBlock b = FSBlock.GetFreeBlock(part); if (b == null) { return(null); } ret.NextBlock = b.BlockNumber; FSBlock.Write(part, ret); b.Used = true; ret = b; } return(ret); }
public PulsarDirectory(Partition p, ulong bn, String pa) { _Path = pa; part = p; _StartBlock = FSBlock.Read(p, bn); if (bn == 1 && pa == "/" && _StartBlock.Content[0] != '/') { Char[] nm = "/".ToCharArray(); for (int i = 0; i < nm.Length; i++) { _StartBlock.Content[i] = (byte)nm[i]; } _StartBlock.Used = true; _StartBlock.NextBlock = 0; FSBlock.Write(p, _StartBlock); } if (!_StartBlock.Used) { _StartBlock.Used = true; String n = "New Directory"; if (pa == FileSystem.separator) { _Path = ""; n = pa; } CreateEntry(part, _StartBlock, n); } }
public static void ClearBlocks(FSBlock StartBlock) { FSBlock b = StartBlock; while (b.NextBlock != 0) { b = FSBlock.Read(b.Partition, b.NextBlock); b.Used = false; FSBlock.Write(mFS.Partition, b); } }
public File(Partition p, ulong bn, String pa) { _Path = pa; part = p; _StartBlock = FSBlock.Read(p, bn); if (!_StartBlock.Used) { _StartBlock.Used = true; String n = "New File"; CreateEntry(part, _StartBlock, n); } }
public static FSBlock GetFreeBlock(Partition p) { for (ulong i = 1; i < p.BlockCount; i++) { FSBlock b = Read(p, i); if (!b.Used) { return(b); } } return(null); }
private void DeleteBlock(FSBlock FSBlock) { FSBlock curb = _StartBlock; while (curb.NextBlock != 0) { int index = 0; bool found = false; List <Byte> cont = new List <Byte>(); curb = FSBlock.Read(_StartBlock.Partition, _StartBlock.NextBlock); while (index < curb.ContentSize) { ulong a = BitConverter.ToUInt64(curb.Content, index); Byte[] app = BitConverter.GetBytes(a); for (int i = 0; i < app.Length; i++) { cont.Add(app[i]); } index += 8; uint sep = BitConverter.ToUInt32(curb.Content, index); index += 4; if (a == FSBlock.BlockNumber) { app = BitConverter.GetBytes((uint)0); for (int i = 0; i < app.Length; i++) { cont.Add(app[i]); } found = true; } else { app = BitConverter.GetBytes(sep); for (int i = 0; i < app.Length; i++) { cont.Add(app[i]); } } } if (found) { curb.Content = cont.ToArray(); curb.ContentSize = (uint)cont.Count; FSBlock.Write(part, curb); } } }
public Byte[] ReadAllBytes() { if (_StartBlock.NextBlock == 0) { return(new Byte[0]); } FSBlock b = _StartBlock; List <Byte> lret = new List <Byte>(); while (b.NextBlock != 0) { b = FSBlock.Read(b.Partition, b.NextBlock); for (int i = 0; i < b.ContentSize; i++) { lret.Add(b.Content[i]); } } EditEntryInfo(EntryInfoPosition.DateTimeLastAccess, Environment.DateTime.Now.TimeStamp); return(lret.ToArray()); }
public void AddDirectory(String Name) { Entry[] dirs = GetEntries(); for (int i = 0; i < dirs.Length; i++) { if (dirs[i].Name == Name) { Helper.WriteLine("Entry with same Name already exists!"); return; } } FSBlock curb = GetBlockToEdit(); FSBlock newdirb = CreateEntry(part, Name); BitConverter.GetBytes(newdirb.BlockNumber).CopyTo(curb.Content, curb.ContentSize); BitConverter.GetBytes((uint)1).CopyTo(curb.Content, curb.ContentSize + 8); curb.ContentSize += 12; FSBlock.Write(part, curb); EditEntryInfo(EntryInfoPosition.DateTimeModified, Environment.DateTime.Now.TimeStamp); EditEntryInfo(EntryInfoPosition.DateTimeLastAccess, Environment.DateTime.Now.TimeStamp); }
protected static FSBlock CreateEntry(Partition p, FSBlock b, String n) { if (b != null && ((!Utils.StringContains(n, InvalidChars)) || b.BlockNumber == 0)) { b.Used = true; b.NextBlock = 0; b.TotalSize = 0; Char[] nm = n.ToCharArray(); for (int i = 0; i < nm.Length; i++) { b.Content[i] = (byte)nm[i]; } if (b.BlockNumber != 0) { Utils.CopyByteToByte(BitConverter.GetBytes(Environment.DateTime.Now.TimeStamp), 0, b.Content, (int)MaxNameSize + (int)EntryInfoPosition.DateTimeCreated, 8, false); } b.Content[nm.Length] = 0; b.ContentSize = (uint)nm.Length; FSBlock.Write(p, b); return(b); } return(null); }
public void WriteAllBytes(Byte[] Data) { if (_StartBlock.NextBlock != 0) { FileSystem.ClearBlocks(_StartBlock); _StartBlock.NextBlock = 0; FSBlock.Write(FileSystem.mFS.Partition, _StartBlock); } int index = 0; FSBlock curb = FSBlock.GetFreeBlock(FileSystem.mFS.Partition); _StartBlock.NextBlock = curb.BlockNumber; FSBlock.Write(part, _StartBlock); do { Byte[] arr = new Byte[FSBlock.MaxBlockContentSize]; index = Utils.CopyByteToByte(Data, index, arr, 0, arr.Length); curb.Used = true; curb.Content = arr; if (index != Data.Length) { FSBlock b = FSBlock.GetFreeBlock(FileSystem.mFS.Partition); curb.NextBlock = b.BlockNumber; curb.ContentSize = (uint)arr.Length; FSBlock.Write(FileSystem.mFS.Partition, curb); curb = b; } else { curb.ContentSize = (uint)(Data.Length % arr.Length); FSBlock.Write(FileSystem.mFS.Partition, curb); } }while(index != Data.Length); EditEntryInfo(EntryInfoPosition.DateTimeModified, Environment.DateTime.Now.TimeStamp); EditEntryInfo(EntryInfoPosition.DateTimeLastAccess, Environment.DateTime.Now.TimeStamp); }
protected static FSBlock CreateEntry(Partition p, String name) { return(CreateEntry(p, FSBlock.GetFreeBlock(p), name)); }