// don't allow appends larger than maximum record size
if ( len > MAX_RECORD_SIZE )
- return ESIZE;
+ return EINVAL;
// move to next block if current block doesn't have enough space
if ( sizeof( m_header ) + len > bytes_left )
uint8_t calcSector( uint8_t client, stm25p_addr_t addr ) {
uint8_t sector = call Sector.getNumSectors[ client ]();
- return (uint8_t)( addr >> STM25P_SECTOR_SIZE_LOG2 ) % sector;
+ return (uint8_t)(( addr >> STM25P_SECTOR_SIZE_LOG2 ) % sector);
}
stm25p_addr_t calcAddr( uint8_t client, stm25p_addr_t addr ) {
{
// make sure the cookie is still within the range of valid data
uint8_t numSectors = call Sector.getNumSectors[ id ]();
- uint8_t readSector =
+ uint16_t readSector =
(m_log_state[ id ].cookie >> STM25P_SECTOR_SIZE_LOG2);
- uint8_t writeSector =
+ uint16_t writeSector =
((m_log_info[ id ].write_addr-1)>>STM25P_SECTOR_SIZE_LOG2)+1;
// if cookie is overwritten, advance to beginning of log
if ( (writeSector - readSector) > numSectors ) {
m_log_info[ id ].read_addr = m_log_state[ id ].cookie & ~BLOCK_MASK;
m_log_info[ id ].remaining = 0;
m_rw_state = S_SEARCH_SEEK;
- if ( m_log_info[ id ].read_addr != m_log_state[ id ].cookie )
+ if ( m_log_info[ id ].read_addr != m_log_state[ id ].cookie ) {
+ m_log_info[ id ].read_addr += sizeof( m_addr );
call Sector.read[ id ]( calcAddr( id, m_log_info[ id ].read_addr ),
&m_header, sizeof( m_header ) );
+ }
else
signalDone( id, SUCCESS );
}
else {
log_info->write_addr += sizeof( m_addr );
m_rw_state = S_SEARCH_RECORDS;
- call Sector.read[ id ]( log_info->write_addr, &m_header,
+ call Sector.read[ id ]( calcAddr(id, log_info->write_addr), &m_header,
sizeof( m_header ) );
}
}
log_info->read_addr += sizeof( m_header ) + m_header;
// if not yet at cookie, keep searching
if ( log_info->read_addr < m_log_state[ id ].cookie ) {
- call Sector.read[ id ]( log_info->read_addr, &m_header,
+ call Sector.read[ id ]( calcAddr(id, log_info->read_addr), &m_header,
sizeof( m_header ) );
}
// at or passed cookie, stop