static void Main(string[] args) { //starts VDisk vd = VDisk.Create(1024); pt = new PartitionTable(vd); //initializes partition part = Partitioner.Create(pt, 1024); PraxisFormatter.format(part, "system"); //formats praxpart = new PraxisPartition(part); PraxisPartitionTable.Add(praxpart); //creates file Praxis.IO.File.Create("/system/test1.txt", Encoding.UTF8.GetBytes("Hello, World. This is test 1.".PadLeft(1976, 'x'))); Praxis.IO.File.Create("/system/test2.txt", Encoding.UTF8.GetBytes("Hello, World. This is test 2.")); Praxis.IO.File.Create("/system/test3.txt", Encoding.UTF8.GetBytes("Hello, World. This is test 3.")); //writes contents to console Console.Write(Encoding.UTF8.GetString(Praxis.IO.File.Read("/system/test1.txt")));//Encoding.UTF8.GetString(Praxis.IO.File.get("system", 0)).Replace(((char)0).ToString(), "")); Console.ReadKey(); }
private static byte[] ReadFile(string name, Int32 block, PraxisPartition prp) { byte[] sec0 = prp.part.Read(block); int length = BitConverter.ToInt32(sec0, 64); int num_of_sectors = 0, tmp_len = length - 1976; while (tmp_len > 0) { tmp_len -= 2044; num_of_sectors++; } byte[][] blocks = new byte[num_of_sectors + 1][]; byte[] lasttime = new byte[2048]; new MemBlocks(lasttime).Write(BitConverter.GetBytes(block), 68, 4); for (int i = 0; i < blocks.Length; i++) { blocks[i] = prp.part.Read(BitConverter.ToInt32(lasttime, 68)); lasttime = blocks[i]; } byte[] returns = new byte[length]; int x = 0; for (int i = 72; i < blocks[0].Length; i++) { returns[x] = blocks[0][i]; x++; if (x >= length) break; } if (num_of_sectors > 0) for (int i = 1; i < blocks.Length; i++) { for (int j = 4; j < blocks[i].Length; j++) { returns[x] = blocks[i][j]; x++; if (x >= length) break; } if (x >= length) break; } return returns; }
private static void WriteFile(string name, Int32 block, byte[] content, PraxisPartition prp) { int num_of_sectors = 0, tmp_len = content.Length - 1976; while (tmp_len > 0) { tmp_len -= 2044; num_of_sectors++; } byte[][] blocks = new byte[num_of_sectors + 1][]; int[] sectors = new int[num_of_sectors + 1]; for(int i = 0; i < blocks.Length; i++) blocks[i] = new byte[2048]; int x = 0; //first block sectors[0] = prp.nextblock(); var mb = new MemBlocks(blocks[0]); mb.Write(Encoding.UTF8.GetBytes(name), 0, 64); mb.Write(BitConverter.GetBytes(content.Length), 64, 4); mb.Write(BitConverter.GetBytes(sectors[0]), 68, 4); prp.inextblock(); for (int i = 72; i < 2048; i++) { blocks[0][i] = content[x]; if (x >= content.Length - 1) break; x++; } if (num_of_sectors > 0) for (int i = 1; i < blocks.Length; i = Math.Min(blocks.Length - 1, i + 1)) { sectors[i] = prp.nextblock(); mb = new MemBlocks(blocks[i]); mb.Write(BitConverter.GetBytes(sectors[i]), 0, 4); for (int j = 4; j < blocks[i].Length; j++) { blocks[i][j] = content[x]; x++; if (x >= content.Length - 1) break; } if (x >= content.Length - 1) break; prp.inextblock(); } for (int i = 0; i < blocks.Length; i++ ) if(sectors[i] != 0) prp.part.Write(sectors[i], blocks[i]); #region garbagecode /*byte[][] blocks = new byte[num_of_sectors + 2][]; for (int i = 0; i < blocks.Length; i++) blocks[i] = new byte[2048] ; var ms = new MemBlocks(blocks[0]); ms.Write(Encoding.UTF8.GetBytes(name), 0, 64); ms.Write(BitConverter.GetBytes(content.Length), 64, 4); if (num_of_sectors == 0) ms.Write(BitConverter.GetBytes(0), 68, 4); else { prp.inextblock(); ms.Write(BitConverter.GetBytes(prp.nextblock()), 68, 4); } byte[] temp = new byte[1976]; for (int i = 0; i < Math.Min(1976, content.Length); i++) temp[i] = content[i]; ms.Write(temp, 72, 1976); prp.part.Write(block, blocks[0]); prp.inextblock(); for (int i = 0; i <= num_of_sectors; i++) { ms = new MemBlocks(blocks[i + 1]); int old_next = (int)prp.nextblock(); byte[] tmp = new byte[2044]; for (int j = 0; j < Math.Min(1976, content.Length); j++) tmp[j] = content[j + (i * 2044)]; ms.Write(tmp, 4, 2044); prp.inextblock(); if (i == num_of_sectors - 1) ms.Write(BitConverter.GetBytes(0), 0, 4); else ms.Write(BitConverter.GetBytes(prp.nextblock()), 0, 4); prp.part.Write(old_next, tmp); }*/ #endregion //1976 is the bytes in the first sector. 2044 in the later ones. }
public static void Add(PraxisPartition part) { table[index] = part; //hashes[index] = Quicksilver.Impl.String.GetHashCode(part.Label()); index++; }
public static void Add(PraxisPartition part) { table[index] = part; hashes[index] = Quicksilver2013.Impl.String.GetHashCode(part.Label()); index++; }
public static void Add(PraxisPartition part) { table[index] = part; hashes[index] = part.Label().GetHashCode(); index++; }