Beispiel #1
0
/** Constructor. Just assigns the ID and determines whether the router is
 * responsive or not based on the presence of a "!" at the start of the ID.
 * See tor-spec.txt for details. */
RouterDescriptor::RouterDescriptor(QStringList descriptor, bool microdesc)
  : _microdesc(microdesc), _observedBandwidth(0), _uptime(0) {
  _status = Online;
  parseDescriptor(descriptor);
}
bool DIVMDKBlockStorage::open(DIBackingStore *backingStore)
{
    close();
    
    DIChar header[VMDK_HEADERSIZE];
    
    if (!backingStore->read(0, header, VMDK_HEADERSIZE))
        return false;
    
    // Check VMDK id
    if (getDIIntLE(&header[0x0]) != 0x564d444b)
        return false;
    
    // Check VMDK version
    DIInt version = getDIIntLE(&header[0x4]);
    if ((version != 1) && (version != 2))
        return false;
    
    // Get VMDK flags
    DIInt flags = getDIIntLE(&header[0x8]);
    
    redundantDirectory = (flags & (1 << 1));
    
    // Get VMDK capacity
    blockNum = (DIInt) getDILongLE(&header[0xc]);
    
    // Get VMDK grain info
    grainSize = (DIInt) getDILongLE(&header[0x14]);
    grainTableSize = getDIIntLE(&header[0x2c]);
    directory1Block = (DIInt) getDILongLE(&header[0x38]);
    directory2Block = (DIInt) getDILongLE(&header[0x30]);
    DIInt dataBlock = (DIInt) getDILongLE(&header[0x40]);
    
    // Get descriptor
    DILong descriptorOffset = getDILongLE(&header[0x1c]);
    DILong descriptorSize = getDILongLE(&header[0x24]);
    
    if (!parseDescriptor(backingStore, descriptorOffset, (DIInt) descriptorSize))
        return false;
    
    // Do not accept compression
    if ((flags & (1 << 16)) && (getDIShortLE(&header[0x4d]) != 0))
        return false;
    
    // Verify clean shutdown
    if (header[0x48])
        return false;
    
    // Read metadata
    DIData data;
    
    data.resize(dataBlock * DI_BLOCKSIZE);
    
    if (!backingStore->read(0, &data.front(), (DIInt) data.size()))
        return false;
    
    metadata.resize(data.size() / sizeof(DIInt));
    for (DIInt i = 0; i < metadata.size(); i++)
        metadata[i] = getDIIntLE(&data[i * sizeof(DIInt)]);
    
    directoryEntrySize = grainTableSize * grainSize;
    
    // Mark in use
    setInUse(true);
    
    this->backingStore = backingStore;
    
    return true;
}