Exemple #1
0
 public void AddEntry(int sector, int hash, byte dir)
 {
     byte[] s0 = part.Read(0);
     if (BitConverter.ToInt32(s0, 32) != 0)
         AddEntrySecondary(sector, hash, dir, BitConverter.ToInt32(s0, 32));
     else { if (entries_in_sector > 222) {
         int nb = nextblock();
         inextblock();
         byte[] block = part.Read((int)nb);
         MemBlocks mb = new MemBlocks(block);
         mb.Write(new byte[] { 0 }, 0, 4);
         //Here it writes to the new block
         mb.Write(new byte[] { dir }, 4 + (9 * entries_in_sector), 1);
         mb.Write(BitConverter.GetBytes(hash), 5 + (9 * entries_in_sector), 4);
         mb.Write(BitConverter.GetBytes(sector), 9 + (9 * entries_in_sector), 4);
         entries_in_sector = 0;
         part.Write((int)nb, block);
         block = part.Read(0);
         mb = new MemBlocks(block);
         mb.Write(BitConverter.GetBytes(nb), 32, 4);
         part.Write(0, block);
         entries_in_sector++;
     } else {
         byte[] block = part.Read(0);
         MemBlocks mb = new MemBlocks(block);
         //Here it writes to the new block
         mb.Write(new byte[] { dir }, 46 + (9 * entries_in_sector), 1);
         mb.Write(BitConverter.GetBytes(hash), 47 + (9 * entries_in_sector), 4);
         mb.Write(BitConverter.GetBytes(sector), 51 + (9 * entries_in_sector), 4);
         part.Write(0, block);
         entries_in_sector++;
     } }
 }
Exemple #2
0
 public static void format(Partition p, string label)
 {
     byte[] buffer = new byte[2048];
     var ms = new MemBlocks(buffer);
     ms.Write(Encoding.UTF8.GetBytes(label), 0, 32); //under 32 characters, one word. Used in &Label/
     ms.Write(BitConverter.GetBytes(0x00000000), 32, 4); //next sector
     ms.Write(new byte[] { 0xF0, 0x0F }, 36, 2); //is formatted
     ms.Write(BitConverter.GetBytes(1), 38, 4); //current used sectors
     ms.Write(BitConverter.GetBytes(0), 42, 4); //number of used entrys
     //format for files/directory is byte directory,int hash,int block
     p.Write(0, buffer);
 }
Exemple #3
0
 public void start(int blocks)
 {
     v_cache = new byte[blocks * block_size];
     ms      = new MemBlocks(v_cache);
 }
Exemple #4
0
 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.
 }
Exemple #5
0
 public void close()
 {
     byte[] buffer = part.Read(0);
     var ms = new MemBlocks(buffer);
     ms.Write(BitConverter.GetBytes(entries_in_sector), 42, 4); //number of used entrys
     part.Write(0, buffer);
 }
Exemple #6
0
 private bool doesHaveSecondaryFile(int hash, int file)
 {
     byte[] block0 = part.Read(0);
     MemBlocks mb = new MemBlocks(block0);
     for (int index = 46; index < 2048; index += 9) {
         if (mb.Read(index, 1)[0] == 0xF0 && BitConverter.ToUInt32(block0, index + 5) == hash) {
             return true;
         }
     }
     /*if(BitConverter.ToUInt32(block0, 32) != 0) return doesHaveSecondaryFile(hash, BitConverter.ToInt32(block0, 32);
     else */return false;
 }
Exemple #7
0
 public int sectorOfFile(int hash)
 {
     byte[] block0 = part.Read(0);
     MemBlocks mb = new MemBlocks(block0);
     for (int index = 46; index < 2048; index += 9)
     {
         if (mb.Read(index, 1)[0] == 0xF0 && BitConverter.ToInt32(block0, index + 1) == hash)
         {
             return BitConverter.ToInt32(block0, index + 5);
         }
     }
     /*if(BitConverter.ToUInt32(block0, 32) != 0) return doesHaveSecondaryFile(hash, BitConverter.ToInt32(block0, 32);
     else */
     return 0;
 }
Exemple #8
0
 public void inextblock()
 {
     byte[] block0 = part.Read(0);
     MemBlocks mb = new MemBlocks(block0);
     byte[] nb = BitConverter.GetBytes(nextblock() + 1);
     mb.Write(nb, 38, 4);
     next_block++;
 }
Exemple #9
0
 public void start(int blocks)
 {
     v_cache = new byte[blocks * block_size];
     ms = new MemBlocks(v_cache);
 }