extern bool WndGetLine( a_window *wnd, int row, int piece, wnd_line_piece *line ) { int virtual_row; bool success; virtual_row = WndVirtualRow( wnd, row ); if( _Is( wnd, WSW_CACHE_LINES ) ) { if( FindCacheLine( wnd, virtual_row, piece, line ) ) return( TRUE ); } line->attr = WndPlainAttr; line->indent = 0; line->static_text = FALSE; line->tabstop = TRUE; line->hot = FALSE; line->extent = WND_NO_EXTEND; line->master_tabstop = FALSE; line->underline = FALSE; line->draw_bar = FALSE; line->vertical_line = FALSE; line->draw_hook = FALSE; line->draw_line_hook = FALSE; line->bitmap = FALSE; line->use_piece0_attr = FALSE; line->use_prev_attr = FALSE; line->use_key = TRUE; line->text = ""; line->hint = ""; if( virtual_row < -wnd->title_size ) return( FALSE ); if( row == wnd->u.button_down.row && piece == wnd->u.button_down.piece ) { _Set( wnd, WSW_ALTERNATE_BIT ); } success = wnd->info->getline( wnd, virtual_row, piece, line ); _Clr( wnd, WSW_ALTERNATE_BIT ); if( success ) { if( !(line->bitmap|line->vertical_line|line->draw_hook|line->draw_line_hook|line->draw_bar) ) { line->length = strlen( line->text ); } if( virtual_row > wnd->max_row ) wnd->max_row = virtual_row; } if( success ) { if( _Is( wnd, WSW_CACHE_LINES ) ) { SetCacheLine( wnd, virtual_row, piece, line ); } } return( success ); }
const SectorReader::Cache* SectorReader::GetCacheLine(u64 block_num) { if (auto entry = FindCacheLine(block_num)) return entry; // Cache miss. Fault in the missing entry. Cache* cache = GetEmptyCacheLine(); // We only read aligned chunks, this avoids duplicate overlapping entries. u64 chunk_idx = block_num / m_chunk_blocks; u32 blocks_read = ReadChunk(cache->data.data(), chunk_idx); if (!blocks_read) return nullptr; cache->Fill(chunk_idx * m_chunk_blocks, blocks_read); // Secondary check for out-of-bounds read. // If we got less than m_chunk_blocks, we may still have missed. // We do this after the cache fill since the cache line itself is // fine, the problem is being asked to read past the end of the disk. return cache->Contains(block_num) ? cache : nullptr; }