private void initfromRootBlock(final IRootBlockView rb) throws IOException {
  assert (rb != null);
  m_storeUUID=rb.getUUID();
  if (rb.getNextOffset() == 0) {
    defaultInit();
  }
 else {
    final long nxtOffset=rb.getNextOffset();
    m_nextAllocation=-(int)(nxtOffset >> 32);
    if (m_nextAllocation == 0) {
      m_nextAllocation=-(1 + META_ALLOCATION);
    }
    m_committedNextAllocation=m_nextAllocation;
    m_metaBitsAddr=-(int)nxtOffset;
    if (log.isInfoEnabled()) {
      log.info("MetaBitsAddr: " + m_metaBitsAddr);
    }
{
      final long metaAddr=rb.getMetaStartAddr();
      m_fileSize=(int)-(metaAddr & 0xFFFFFFFF);
      if (log.isInfoEnabled())       log.info("InitFromRootBlock m_fileSize: " + convertAddr(m_fileSize));
    }
    long rawmbaddr=rb.getMetaBitsAddr();
    final int metaBitsStore=(int)(rawmbaddr & 0xFFFF);
    if (metaBitsStore > 0) {
      rawmbaddr>>=16;
      final byte[] buf=new byte[metaBitsStore * 4];
      FileChannelUtility.readAll(m_reopener,ByteBuffer.wrap(buf),rawmbaddr);
      final DataInputStream strBuf=new DataInputStream(new ByteArrayInputStream(buf));
      final int storeVersion=strBuf.readInt();
switch ((storeVersion & 0xFF00)) {
case (cVersion & 0xFF00):
case (cVersionDemispace & 0xFF00):
        break;
default :
      throw new IllegalStateException("Incompatible RWStore header version: storeVersion=" + storeVersion + ", cVersion="+ cVersion+ ", demispace: "+ isUsingDemiSpace());
  }
  m_lastDeferredReleaseTime=strBuf.readLong();
  if (strBuf.readInt() != cDefaultMetaBitsSize) {
    throw new IllegalStateException("Store opened with unsupported metabits size");
  }
  final int allocBlocks=strBuf.readInt();
  m_storageStatsAddr=strBuf.readLong();
  for (int i=0; i < cReservedMetaBits; i++) {
    strBuf.readInt();
  }
  m_allocSizes=new int[allocBlocks];
  for (int i=0; i < allocBlocks; i++) {
    m_allocSizes[i]=strBuf.readInt();
  }
  m_metaBitsSize=metaBitsStore - allocBlocks - cMetaHdrFields;
  m_metaBits=new int[m_metaBitsSize];
  if (log.isInfoEnabled()) {
    log.info("Raw MetaBitsAddr: " + rawmbaddr);
  }
  for (int i=0; i < m_metaBitsSize; i++) {
    m_metaBits[i]=strBuf.readInt();
  }
  syncMetaTransients();
  final int numFixed=m_allocSizes.length;
  m_freeFixed=new ArrayList[numFixed];
  for (int i=0; i < numFixed; i++) {
    m_freeFixed[i]=new ArrayList<FixedAllocator>();
  }
  checkCoreAllocations();
  readAllocationBlocks();
}
if (log.isInfoEnabled()) log.info("restored from RootBlock: " + m_nextAllocation + ", "+ m_metaBitsAddr);
}
}

private void initfromRootBlock ( final IRootBlockView rb ) throws IOException { assert ( rb != null ) ; m_storeUUID = rb . getUUID ( ) ; if ( rb . getNextOffset ( ) == 0 ) { defaultInit ( ) ; } else { final long nxtOffset = rb . getNextOffset ( ) ; m_nextAllocation = - ( int ) ( nxtOffset > > 32 ) ; if ( m_nextAllocation == 0 ) { m_nextAllocation = - ( 1 + META_ALLOCATION ) ; } m_committedNextAllocation = m_nextAllocation ; m_metaBitsAddr = - ( int ) nxtOffset ; if ( log . isInfoEnabled ( ) ) { log . info ( "MetaBitsAddr: " + m_metaBitsAddr ) ; } { final long metaAddr = rb . getMetaStartAddr ( ) ; m_fileSize = ( int ) - ( metaAddr & 0xFFFFFFFF ) ; if ( log . isInfoEnabled ( ) ) log . info ( "InitFromRootBlock m_fileSize: " + convertAddr ( m_fileSize ) ) ; } long rawmbaddr = rb . getMetaBitsAddr ( ) ; final int metaBitsStore = ( int ) ( rawmbaddr & 0xFFFF ) ; if ( metaBitsStore > 0 ) { rawmbaddr >>= 16 ; final byte [ ] buf = new byte [ metaBitsStore * 4 ] ; FileChannelUtility . readAll ( m_reopener , ByteBuffer . wrap ( buf ) , rawmbaddr ) ; final DataInputStream strBuf = new DataInputStream ( new ByteArrayInputStream ( buf ) ) ; final int storeVersion = strBuf . readInt ( ) ; switch ( ( storeVersion & 0xFF00 ) ) { case ( cVersion & 0xFF00 ) : case ( cVersionDemispace & 0xFF00 ) : break ; default : throw new IllegalStateException ( "Incompatible RWStore header version: storeVersion=" + storeVersion + ", cVersion=" + cVersion + ", demispace: " + isUsingDemiSpace ( ) ) ; } m_lastDeferredReleaseTime = strBuf . readLong ( ) ; if ( strBuf . readInt ( ) != cDefaultMetaBitsSize ) { throw new IllegalStateException ( "Store opened with unsupported metabits size" ) ; } final int allocBlocks = strBuf . readInt ( ) ; m_storageStatsAddr = strBuf . readLong ( ) ; for ( int i = 0 ; i < cReservedMetaBits ; i ++ ) { strBuf . readInt ( ) ; } m_allocSizes = new int [ allocBlocks ] ; for ( int i = 0 ; i < allocBlocks ; i ++ ) { m_allocSizes [ i ] = strBuf . readInt ( ) ; } m_metaBitsSize = metaBitsStore - allocBlocks - cMetaHdrFields ; m_metaBits = new int [ m_metaBitsSize ] ; if ( log . isInfoEnabled ( ) ) { log . info ( "Raw MetaBitsAddr: " + rawmbaddr ) ; } for ( int i = 0 ; i < m_metaBitsSize ; i ++ ) { m_metaBits [ i ] = strBuf . readInt ( ) ; } syncMetaTransients ( ) ; final int numFixed = m_allocSizes . length ; m_freeFixed = new ArrayList [ numFixed ] ; for ( int i = 0 ; i < numFixed ; i ++ ) { m_freeFixed [ i ] = new ArrayList < FixedAllocator > ( ) ; } checkCoreAllocations ( ) ; readAllocationBlocks ( ) ; } if ( log . isInfoEnabled ( ) ) log . info ( "restored from RootBlock: " + m_nextAllocation + ", " + m_metaBitsAddr ) ; } }
should be called where previously initfilespec was used . rather than reading from file , instead reads from the current root block . we use the rootblock fields , nextoffset , metastartaddr , metabitsaddr . metabitsaddr indicates where the meta allocation bits are . metastartaddr is the offset in the file where the allocation blocks are allocated the long value also indicates the size of the allocation , such that the address plus the size is the " filesize " . note that metabitsaddr must be an absolute address , with the low order 16 bits used to indicate the size .
