Beispiel #1
0
 public byte[] readFileBytes(File f)
 {
     byte[] o = new byte[f.length];
     int m = 0;
     foreach(Region r in f.regions)
     {
         for (int i = r.a; i < r.b; i ++)
             o[m++] = r.block.get(i);
     }
     return o;
 }
Beispiel #2
0
        public void delete(File f)
        {
            int z = 0;
            ToC.Remove(f);
            HashSet<Block> blocks = new HashSet<Block>();
            foreach (Region r in f.regions)
            {
                r.block.freeRegion(r);
                blocks.Add(r.block);

            }
            foreach (Block b in blocks)
            {
                b.MergeRegions();
            }
        }
Beispiel #3
0
        public File writeFile(string name, byte[] bytes)
        {
            int ii = 0;

            Region currentReg;
            List<Region> regions = new List<Region>();
            while (ii < bytes.Length)
            {
                Loc oldLoc = loc;
                ensureFreeSpace();
                currentReg = findSmallestFreeSpace();
                loc.pos = currentReg.a;
                loc.block = currentReg.block;
                if (ii == 0)
                {

                    // done here after we find an initial writing pos
                    //   loc.block.ToC.Add((File)receipt);
                }
                else
                {
               //     oldLoc.block.FileSystem.addJump(oldLoc, loc);
                }
                int z = 0;
                while (loc.pos < currentReg.b && ii < bytes.Length)
                {
                    loc.block.writeByte(loc.pos++, bytes[ii++]);
                    z++;
                }
                regions.Add((loc.pos < currentReg.b) ? new Region(loc.block, currentReg.a, currentReg.a + z) : currentReg);

            }
            File f = new File(regions, bytes.Length, name);
            ToC.Add(f);
            return f;
        }