Ejemplo n.º 1
0
        private void Load()
        {
            if (TheStore.TheFile.Length >= BitmapToPos(Ix + 1))
            {
                TheStore.TheFile.Position = BitmapToPos(Ix);

                if (StreamUtils.ReadInt8(TheStore.TheFile) != (byte)Store.SectorTypes.Bitmap)
                {
                    InitializeBitmapSector();
                    return;
                }

                var nextix = StreamUtils.ReadInt32(TheStore.TheFile);
                SectorData = StreamUtils.Read(TheStore.TheFile, (int)TheStore.SectorDataSize);

                if (nextix != Store.LAST_SECTOR_IN_CHAIN)
                {
                    NextBitmap = new BitmapSector(TheStore, nextix, SectorSize);
                }
                else
                {
                    NextBitmap = null;
                }
            }
            else
            {
                InitializeBitmapSector();
            }
        }
Ejemplo n.º 2
0
        internal int ExtendBitmapSpace()
        {
            var ix = TotalBitCount;

            TheStore.TheFile.Position = BitmapToPos(ix);
            TheStore.TheFile.WriteByte((byte)Store.SectorTypes.Unallocated);

            var next = new BitmapSector(TheStore, ix, SectorSize);

#if STORE_DETAILED_TRACE_LOGS
            System.Diagnostics.Debug.WriteLine("ExtendBitmapSpace: " + ix.ToString());
#endif

            // Its now reserving space for itself
            next[0] = true;

            var lastbitmapsector = TheStore.Bits;
            while (lastbitmapsector.NextBitmap != null)
            {
                lastbitmapsector = lastbitmapsector.NextBitmap;
            }
            lastbitmapsector.NextBitmap = next;
            TheStore.TheFile.Position   = BitmapToPos(lastbitmapsector.Ix) + 1;
            StreamUtils.WriteInt32(TheStore.TheFile, next.Ix);

            return(ix);
        }
Ejemplo n.º 3
0
        private void InitializeBitmapSector()
        {
            TheStore.TheFile.Position = BitmapToPos(Ix);

            StreamUtils.WriteUInt8(TheStore.TheFile, (byte)Store.SectorTypes.Bitmap);
            StreamUtils.WriteInt32(TheStore.TheFile, Store.LAST_SECTOR_IN_CHAIN);
            NextBitmap = null;

            SectorData = new byte[(int)TheStore.SectorDataSize];
            StreamUtils.Write(TheStore.TheFile, SectorData);
        }
Ejemplo n.º 4
0
        private void Initialize(Stream dest, int defaultsectorsize)
        {
            if (defaultsectorsize > 0 && defaultsectorsize < 16)
            {
                throw new Exception("Minimum chunk size: 16 bytes.");
            }

            Chunksize = defaultsectorsize <= 0 ? 1024 : defaultsectorsize;

            TheFile = dest;

            InitializeChunksize();
            Bits = new BitmapSector(this, BITMAP_START_SECTOR, Chunksize);
            FreeSectorSearchStartIndex = RESERVED_SECTORS;

            InitializeReservedSectors();
        }
Ejemplo n.º 5
0
 long PosToBitmap(int bit)
 {
     return(BitmapSector.PosToBitmap(bit, Chunksize));
 }
Ejemplo n.º 6
0
 long BitmapToPos(int bit)
 {
     return(BitmapSector.BitmapToPos(bit, Chunksize));
 }