예제 #1
0
/**
 * Read block from backing ciphertext file, decrypt it (normal mode)
 * or
 * Read block from backing plaintext file, then encrypt it (reverse mode)
 */
ssize_t CipherFileIO::readOneBlock(const IORequest &req) const {
  int bs = blockSize();
  off_t blockNum = req.offset / bs;

  ssize_t readSize = 0;
  IORequest tmpReq = req;

  // adjust offset if we have a file header
  if (haveHeader && !fsConfig->reverseEncryption) {
    tmpReq.offset += HEADER_SIZE;
  }
  readSize = base->read(tmpReq);

  bool ok;
  if (readSize > 0) {
    if (haveHeader && fileIV == 0)
      const_cast<CipherFileIO *>(this)->initHeader();

    if (readSize != bs) {
      rDebug("streamRead(data, %d, IV)", (int)readSize);
      ok = streamRead(tmpReq.data, (int)readSize, blockNum ^ fileIV);
    } else {
      ok = blockRead(tmpReq.data, (int)readSize, blockNum ^ fileIV);
    }

    if (!ok) {
      rDebug("decodeBlock failed for block %" PRIi64 ", size %i", blockNum,
             (int)readSize);
      readSize = -1;
    }
  } else
    rDebug("readSize zero for offset %" PRIi64, req.offset);

  return readSize;
}
예제 #2
0
파일: zr_sock.cpp 프로젝트: neorayer/zrlib
bool ZrSocket::blockRecv(char * buf, int wantLen) {
	try {
		blockRead(this->sock, buf, wantLen);
		return true;
	}catch(int) {
		return false;
	}
}
예제 #3
0
파일: llreader.cpp 프로젝트: songhtdo/vespa
void
InputBuf::doAllInput(LLParser &outputvia)
{
    while (blockRead()) {
        while (hasInput()) {
            doInput(outputvia);
        }
    }
    if (_bp != _buf) {
	if (_left < 1) extend();
	*_bp++ = '\n';
	doInput(outputvia);
    }
}
예제 #4
0
bool AD5933_Class::getImpedance(double gainFactor, double &impVal) {
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double magSq = getMag(rComp, iComp);
	impVal = gainFactor / magSq;
	return true;
}
예제 #5
0
/*
 * Hidden Function to get magnitude value of impedance measurement. (It does not wait.)
 * Returns the magnitude of impedance value
 */
double AD5933_Class::getMagValue() {

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double result = getMag(rComp, iComp); // Calculating magnitude.
#if LOGGING3
	printer->print("getMagValue - Resistance Magnitude is ");
	printer->println(result);
#endif
	return result;
}
예제 #6
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::getComplexOnce(double gainFactor, double pShift, double &vReal, double &vComp, double &impVal, double &phase)
{
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double magSq = getMag(rComp, iComp);
	impVal = gainFactor / magSq;
	phase = atan2(iComp, rComp) - pShift;
	vReal = impVal * cos(phase);
	vComp = impVal * sin(phase);

	return true;
}
예제 #7
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::getComplexRawOnce(int &realComp, int &imagComp)
{
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	//double magSq = square((double)rComp) + square((double)iComp);
	//double td1=gainFactor/magSq;
	//realComp = abs(rComp)*td1;
	//imagComp = abs(iComp)*td1;
	realComp = rComp;
	imagComp = iComp;

	return true;
}
예제 #8
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
double AD5933_Class::getMagValue() {
	// Hidden Function to get magnitude value of impedance measurement. (It does not wait.)
	// TODO: Rewrite this function with using block read function.

	int rComp, iComp;
	//rComp = getRealComp(); // Getting Real Component
	//iComp = getImagComp(); // Getting Imaginary Component

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double result = getMag(rComp, iComp); // Calculating magnitude.
#if LOGGING3
	printer->print("getMagValue - Resistance Magnitude is ");
	printer->println(result);
#endif
	return result;
}
예제 #9
0
static u32int
blockAlloc(int type, u32int tag)
{
	static u32int addr;
	Label l;
	int lpb;

	lpb = bsize/LabelSize;

	blockRead(PartLabel, addr/lpb);
	if(!labelUnpack(&l, buf, addr % lpb))
		vtFatal("bad label: %r");
	if(l.state != BsFree)
		vtFatal("want to allocate block already in use");
	l.epoch = 1;
	l.epochClose = ~(u32int)0;
	l.type = type;
	l.state = BsAlloc;
	l.tag = tag;
	labelPack(&l, buf, addr % lpb);
	blockWrite(PartLabel, addr/lpb);
	return addr++;
}
예제 #10
0
void AutoBoot::handleCommand(quint8 command, quint16 aux)
{

    switch (command) {
        case 0x3F:  // Speed poll
            {
                if (!sio->port()->writeCommandAck()) {
                    return;
                }
                sio->port()->writeComplete();
                QByteArray speed(1, 0);
                speed[0] = sio->port()->speedByte();
                sio->port()->writeDataFrame(speed);
                qDebug() << "!n" << tr("[%1] Speed poll.").arg(deviceName());
                break;
            }
        case 0x52:
            {    /* Read sector */
                if (loaded) {
                    passToOldHandler(command, aux);
                    return;
                }
                if (aux >= 1 && aux <= sectorCount) {
                    if (!sio->port()->writeCommandAck()) {
                        return;
                    }
                    if (!started) {
                        emit booterStarted();
                        started = true;
                    }
                    QByteArray data;
                    if (readSector(aux, data)) {
                        sio->port()->writeComplete();
                        sio->port()->writeDataFrame(data);
                        qDebug() << "!n" << tr("[%1] Read sector %2 (%3 bytes).")
                                       .arg(deviceName())
                                       .arg(aux)
                                       .arg(data.size());
                    } else {
                        sio->port()->writeError();
                        qCritical() << "!e" << tr("[%1] Read sector %2 failed.")
                                       .arg(deviceName())
                                       .arg(aux);
                    }
                } else {
                    passToOldHandler(command, aux);
                }
                break;
            }
        case 0x53:
            {    /* Get status */
                if (loaded) {
                    passToOldHandler(command, aux);
                    return;
                }
                if (!sio->port()->writeCommandAck()) {
                    return;
                }

                QByteArray status(4, 0);
                status[0] = 8;
                status[3] = 1;
                sio->port()->writeComplete();
                sio->port()->writeDataFrame(status);
                qDebug() << "!n" << tr("[%1] Get status.")
                               .arg(deviceName());
                break;
            }
        case 0xFD:
            {
                if (!sio->port()->writeCommandAck()) {
                    return;
                }
                qDebug() << "!n" << tr("[%1] Atari is jumping to %2.")
                               .arg(deviceName())
                               .arg(aux);
                emit loaderDone();
                sio->port()->writeComplete();
                break;
            }
        case 0xFE:
            {   /* Get chunk */
                if(aux >= chunks.count()) {
                    qDebug() << "!e" << tr("[%1] Invalid chunk in get chunk: aux = %2")
                                   .arg(deviceName())
                                   .arg(aux);
                    return;
                }

                if (!sio->port()->writeCommandAck()) {
                    return;
                }
                qDebug() << "!n" << tr("[%1] Get chunk %2 (%3 bytes).")
                               .arg(deviceName())
                               .arg(aux)
                               .arg(chunks.at(aux).data.size());
                sio->port()->writeComplete();
                sio->port()->writeDataFrame(chunks.at(aux).data);
                emit blockRead(aux + 1, chunks.count());
                break;
            }
        case 0xFF:
            {   /* Get chunk info */
                if(aux >= chunks.count()) {
                    qDebug() << "!e" << tr("[%1] Invalid chunk in get chunk info: aux = %2")
                                   .arg(deviceName())
                                   .arg(aux);
                    return;
                }

                if (!sio->port()->writeCommandAck()) {
                    return;
                }
                if (!loaded) {
                    loaded = true;
                    emit booterLoaded();
                }
                QByteArray data;
                data[0] = chunks.at(aux).address % 256;
                data[1] = chunks.at(aux).address / 256;
                data[2] = 1;
                data[3] = chunks.size() != aux + 1;
                data[4] = chunks.at(aux).data.size() % 256;
                data[5] = chunks.at(aux).data.size() / 256;
                qDebug() << "!d" << tr("[%1] Get chunk info %2 (%3 bytes at %4).")
                               .arg(deviceName())
                               .arg(aux)
                               .arg(chunks.at(aux).data.size())
                               .arg(chunks.at(aux).address);
                sio->port()->writeComplete();
                sio->port()->writeDataFrame(data);
                break;
            }
        default:
            passToOldHandler(command, aux);
            return;
            break;
    }
}