Exemple #1
0
 private byte[] ReadSectorCached(int lba)
 {
     //read it if we dont have it cached
     //we wont be caching very much here, it's no big deal
     //identification is not something we want to take a long time
     byte[] data;
     if (!_sectorCache.TryGetValue(lba, out data))
     {
         data = new byte[2048];
         int read = _dsr.ReadLBA_2048(lba, data, 0);
         if (read != 2048)
         {
             return(null);
         }
         _sectorCache[lba] = data;
     }
     return(data);
 }
Exemple #2
0
        //TODO - I'm not sure everything in here makes sense right now..
        public override int Read(byte[] buffer, int offset, int count)
        {
            long remainInDisc = Length - currPosition;

            if (count > remainInDisc)
            {
                count = (int)Math.Min(remainInDisc, int.MaxValue);
            }

            int remain = count;
            int readed = 0;

            while (remain > 0)
            {
                int lba            = (int)(currPosition / SectorSize);
                int lba_within     = (int)(currPosition % SectorSize);
                int todo           = remain;
                int remains_in_lba = SectorSize - lba_within;
                if (remains_in_lba < todo)
                {
                    todo = remains_in_lba;
                }
                if (cachedSector != lba)
                {
                    dsr.ReadLBA_2048(lba, cachedSectorBuffer, 0);
                    cachedSector = lba;
                }
                Array.Copy(cachedSectorBuffer, lba_within, buffer, offset, todo);
                offset       += todo;
                remain       -= todo;
                currPosition += todo;
                readed       += todo;
            }

            return(readed);
        }