/// <summary> /// Read page into buffer: n - page number; nbuf - buffer number /// !!! NOT APPLICABLE TO IMO /// </summary> /// <param name="n"></param> /// <param name="nbuf"></param> private void page_read(long n, int sg, int pg, int nbuf) { for (int i = 0; i < pd.Length; i++) { if ((n >= pd[i].start_page) & (n <= pd[i].end_page)) { // Absolute address (beginning of system area long addr = (long)((n - pd[i].start_page) * (DESCRIPTOR.PageSize + DEFS.SYSTEM_USED_PAGE_SPACE)); uint encr = pd[i].fs.ReadUInt(addr); // Encryption uint old_crc = pd[i].fs.ReadUInt(addr + 4); // Crc32 if (encr == DEFS.DATA_ENCRYPTED) { e_buf = pd[i].fs.ReadBytes(addr + DEFS.SYSTEM_USED_PAGE_SPACE, (int)page_size); VSCrypto.Decrypt(ref e_buf, ref segment_table[0].cache[nbuf].buf, e_key, 0); } else { segment_table[0].cache[nbuf].buf = pd[i].fs.ReadBytes(addr + DEFS.SYSTEM_USED_PAGE_SPACE, (int)page_size); } if (old_crc != 0) { uint new_crc = VSCRC32.CountCrc(segment_table[0].cache[nbuf].buf); if (old_crc != new_crc) { throw new VSException(DEFS.E0033_INVALID_CRC_CODE, "Space: " + DESCRIPTOR.name + ", Page#: " + n.ToString()); } } PGRead++; // Update page table entry by but# ans sett 'read' state segment_table[sg].page_table[pg].page_state = DEFS.PAGE_READ; segment_table[sg].page_table[pg].bufno = nbuf; // Update cache entry by page# segment_table[0].cache[nbuf].page_no = n; } } }
//////////////////////////////////////////////////////////////////// //////////////// READ METHODS ////////////////////////////////////// //////////////////////////////////////////////////////////////////// /// <summary> /// Read bytes /// </summary> /// <returns></returns> public byte[] ReadBytes(long offset, int len) { if (offset >= 0) { fs.Seek(offset, SeekOrigin.Begin); } byte[] b = new byte[len]; long pos = fs.Position; fs.Read(b, 0, len); if (!_encrypt) { return(b); } byte[] b_ret = new byte[len]; VSCrypto.Decrypt(ref b, ref b_ret, xkey_b, pos); return(b_ret); }