/// <summary> /// Creates a new PulsarDirectory Object /// </summary> /// <param name="p">The partition to use</param> /// <param name="bn">The block number we want to use</param> /// <param name="pa">The path of the new directory</param> public PulsarDirectory(Partition p, ulong bn, String pa) { _Path = pa; part = p; _StartBlock = PulsarFSBlock.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; PulsarFSBlock.Write(p, _StartBlock); } if (!_StartBlock.Used) { _StartBlock.Used = true; String n = "New Directory"; if (pa == PulsarFileSystem.separator) { _Path = ""; n = pa; } CreateEntry(part, _StartBlock, n); } }
/// <summary> /// Gets the last PulsarFSBlock of the directory /// </summary> private PulsarFSBlock GetBlockToEdit() { PulsarFSBlock ret = _StartBlock; while (ret.NextBlock != 0) { ret = PulsarFSBlock.Read(_StartBlock.Partition, _StartBlock.NextBlock); } if (ret.BlockNumber == _StartBlock.BlockNumber) { ret = PulsarFSBlock.GetFreeBlock(part); ret.Used = true; ret.ContentSize = 0; ret.NextBlock = 0; _StartBlock.NextBlock = ret.BlockNumber; PulsarFSBlock.Write(part, _StartBlock); PulsarFSBlock.Write(part, ret); } if (part.NewBlockArray(1).Length - ret.ContentSize < 12) { PulsarFSBlock b = PulsarFSBlock.GetFreeBlock(part); if (b == null) { return(null); } ret.NextBlock = b.BlockNumber; PulsarFSBlock.Write(part, ret); b.Used = true; ret = b; } return(ret); }
/// <summary> /// Gets all PulsarEntries contained in this PulsarDirectory /// </summary> public PulsarEntry[] GetEntries() { PulsarFSBlock curb = _StartBlock; List <PulsarEntry> d = new List <PulsarEntry>(); while (curb.NextBlock != 0) { int index = 0; curb = PulsarFSBlock.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, PulsarFileSystem.CombineDir(_Path, Name))); } else if (sep == 2) { d.Add(new PulsarFile(part, a, PulsarFileSystem.CombineDir(_Path, Name))); } } } return(d.ToArray()); }
public static void ClearBlocks(PulsarFSBlock StartBlock) { PulsarFSBlock b = StartBlock; while (b.NextBlock != 0) { b = PulsarFSBlock.Read(b.Partition, b.NextBlock); b.Used = false; PulsarFSBlock.Write(mFS.Partition, b); } }
/// <summary> /// Creates a new PulsarFile Object /// </summary> /// <param name="p">The partition to use</param> /// <param name="bn">The block number we want to use</param> /// <param name="pa">The path of the new directory</param> public PulsarFile(Partition p, ulong bn, String pa) { _Path = pa; part = p; _StartBlock = PulsarFSBlock.Read(p, bn); if (!_StartBlock.Used) { _StartBlock.Used = true; String n = "New File"; CreateEntry(part, _StartBlock, n); } }
/// <summary> /// Permits to remove a PulsarFSBlock by passing it /// </summary> /// <param name="PulsarDirectory">The PulsarFSBlock to remove</param> private void DeleteBlock(PulsarFSBlock PulsarFSBlock) { PulsarFSBlock curb = _StartBlock; while (curb.NextBlock != 0) { int index = 0; bool found = false; List <Byte> cont = new List <Byte>(); curb = PulsarFSBlock.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 == PulsarFSBlock.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; PulsarFSBlock.Write(part, curb); } } }
/// <summary> /// Return's all the bytes contained in the file /// </summary> public Byte[] ReadAllBytes() { if (_StartBlock.NextBlock == 0) { return(new Byte[0]); } PulsarFSBlock b = _StartBlock; List <Byte> lret = new List <Byte>(); while (b.NextBlock != 0) { b = PulsarFSBlock.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()); }