本文整理汇总了C++中ReadBlock函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadBlock函数的具体用法?C++ ReadBlock怎么用?C++ ReadBlock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadBlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decrease_link_count
void decrease_link_count(ino iNode) {
char iNodeDataBlock[BLOCK_SIZE];
iNodeEntry *iNodes;
if (iNode < 16) {
ReadBlock(4, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
// Decrease the number of link
--iNodes[iNode].iNodeStat.st_nlink;
if (iNodes[iNode].iNodeStat.st_nlink <= 0) {
reset_inode_entry(&iNodes[iNode]);
}
WriteBlock(4, iNodeDataBlock);
} else {
ReadBlock(5, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
// Decrease the number of links
--iNodes[iNode - 16].iNodeStat.st_nlink;
if (iNodes[iNode - 16].iNodeStat.st_nlink <= 0) {
reset_inode_entry(&iNodes[iNode - 16]);
}
WriteBlock(5, iNodeDataBlock);
}
}
示例2: LoadLCD
void LoadLCD(SAVESTATE_t* save, LCD_t* lcd) {
CHUNK_t* chunk = FindChunk(save,LCD_tag);
chunk->pnt = 0;
lcd->active = ReadInt(chunk);
lcd->word_len = ReadInt(chunk);
lcd->x = ReadInt(chunk);
lcd->y = ReadInt(chunk);
lcd->z = ReadInt(chunk);
lcd->cursor_mode = (LCD_CURSOR_MODE) ReadInt(chunk);
lcd->contrast = ReadInt(chunk);
lcd->base_level = ReadInt(chunk);
ReadBlock(chunk, lcd->display, DISPLAY_SIZE);
lcd->front = ReadInt(chunk);
ReadBlock(chunk, (unsigned char *) lcd->queue, LCD_MAX_SHADES * DISPLAY_SIZE);
lcd->shades = ReadInt(chunk);
lcd->mode = (LCD_MODE) ReadInt(chunk);
lcd->time = ReadDouble(chunk);
lcd->ufps = ReadDouble(chunk);
lcd->ufps_last = ReadDouble(chunk);
lcd->lastgifframe= ReadDouble(chunk);
lcd->write_avg = ReadDouble(chunk);
lcd->write_last = ReadDouble(chunk);
}
示例3: create_new_file_inode
void create_new_file_inode(ino fileiNode) {
char iNodeDataBlock[BLOCK_SIZE];
iNodeEntry *iNodes;
if (fileiNode < 16) {
ReadBlock(4, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
iNodes[fileiNode].iNodeStat.st_ino = fileiNode;
iNodes[fileiNode].iNodeStat.st_mode &= 0;
iNodes[fileiNode].iNodeStat.st_mode |= G_IFREG | G_IRWXU | G_IRWXG;
iNodes[fileiNode].iNodeStat.st_nlink = 1;
iNodes[fileiNode].iNodeStat.st_size = 0;
iNodes[fileiNode].iNodeStat.st_blocks = 0;
WriteBlock(4, iNodeDataBlock);
} else {
ReadBlock(5, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
iNodes[fileiNode - 16].iNodeStat.st_ino = fileiNode;
iNodes[fileiNode - 16].iNodeStat.st_mode &= 0;
iNodes[fileiNode - 16].iNodeStat.st_mode |= G_IFREG | G_IRWXU | G_IRWXG;
iNodes[fileiNode - 16].iNodeStat.st_nlink = 1;
iNodes[fileiNode - 16].iNodeStat.st_size = 0;
iNodes[fileiNode - 16].iNodeStat.st_blocks = 0;
WriteBlock(5, iNodeDataBlock);
}
}
示例4: ReadKeyValuePair
void GdbMIThreadInfoParser::Parse(const wxString& info)
{
m_threads.clear();
// an example for -thread-info output
// ^done,threads=[{id="30",target-id="Thread5060.0x1174",frame={level="0",addr="0x77a1000d",func="foo",args=[],from="C:\path\to\file"},state="stopped"},{..}],current-thread-id="30"
wxString buffer = info;
wxString threadsInfo;
wxString threadBlock;
if ( !ReadBlock(buffer, "[]", threadsInfo) )
return;
wxString activeThreadId;
ReadKeyValuePair(buffer, "current-thread-id=", activeThreadId);
while ( ReadBlock(threadsInfo, "{}", threadBlock) ) {
GdbMIThreadInfo ti;
ReadKeyValuePair(threadBlock, "id=", ti.threadId);
ReadKeyValuePair(threadBlock, "target-id=", ti.extendedName);
ReadKeyValuePair(threadBlock, "func=", ti.function);
ReadKeyValuePair(threadBlock, "file=", ti.file);
ReadKeyValuePair(threadBlock, "line=", ti.line);
ti.active = activeThreadId == ti.threadId ? "Yes" : "No";
m_threads.push_back( ti );
}
}
示例5: allocate_directory
int allocate_directory(ino iNode, DirEntry **ppListeFichiers) {
char iNodeDataBlock[BLOCK_SIZE];
char directoryDataBlock[BLOCK_SIZE];
ReadBlock(6 + iNode - 1, directoryDataBlock);
DirEntry *directory = (DirEntry *)directoryDataBlock;
if (iNode < 16) {
ReadBlock(4, iNodeDataBlock);
iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
// If it isn't a directory
if (!(iNodes[iNode].iNodeStat.st_mode & G_IFDIR)) {
return -1;
}
int directorySizeNumber = iNodes[iNode].iNodeStat.st_size;
(*ppListeFichiers) = (DirEntry *)malloc(directorySizeNumber);
memcpy((*ppListeFichiers), directory, directorySizeNumber);
return NumberofDirEntry(directorySizeNumber);
} else {
ReadBlock(5, iNodeDataBlock);
iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
// If it isn't a directory
if (!(iNodes[iNode].iNodeStat.st_mode & G_IFDIR)) {
return -1;
}
int directorySizeNumber = iNodes[iNode - 16].iNodeStat.st_size;
(*ppListeFichiers) = (DirEntry *)malloc(directorySizeNumber);
memcpy((*ppListeFichiers), directory, directorySizeNumber);
return NumberofDirEntry(directorySizeNumber);
}
return -1;
}
示例6: FreeInode
int FreeInode(int dev, int ino)
{
char buf[BLKSIZE * 2];
ReadBlock(dev,SUP_BLK_STARTS_AT,buf);
ReadBlock( dev,SUP_BLK_STARTS_AT+1,buf+BLKSIZE);
struct SupBlock* sptr= (struct SupBlock*) buf;
sptr->sb_nfreeino++;
if (sptr->sb_freeinoindex !=0 ) // if inode list is not full
{
sptr->sb_freeinoindex--;
sptr->sb_freeinos[sptr->sb_freeinoindex]= ino;
}
writeSuper(dev,sptr);
struct INode inode;
ReadInode(dev,ino,&inode);
inode.i_lnk=0;
WriteInode(dev,ino,&inode);
//return success
return 0;
}
示例7: Display
void Display(int mode,int fid)
{
if (fid==-1)
{
printf("目录下没有该文件。\n");
return;
}
FileNode fn=*fileIndex[fid].node;
int nowFDB=fn.FDBBlock;
int size=fn.filesize;
if (nowFDB==0||size==0)
{
return;
}
int BlockNum=(size+4092)/4093;
char data[4096];
if (mode==1) //直接显示
{
for (int i=0;i<BlockNum-1;i++)
{
ReadBlock(nowFDB,data,4096);
int nextBlock=ThreeToInt(&data[4093]);
for (int j=0;j<4093;j++)
{
if (data[j]!='\r')
{
putchar(data[j]);
}
}
nowFDB=nextBlock;
}
int remainSize=size%4093;
if (remainSize==0)
{
remainSize=4093;
}
ReadBlock(nowFDB,data,4096);
for (int i=0;i<remainSize;i++)
{
if (data[i]!='\r')
{
putchar(data[i]);
}
}
}
else
{
}
printf("\n");
}
示例8: readSuper
int readSuper (int dev, struct SupBlock* sb) {
if (sb==NULL)
return -1;//error
char* ptr = (char*) sb;
ReadBlock(dev,SUP_BLK_STARTS_AT+0,ptr);
ReadBlock(dev,SUP_BLK_STARTS_AT+1,ptr+BLKSIZE);
return 0;//success
}
示例9: EncodeFixed64
// Convert an index iterator value (i.e., an encoded BlockHandle)
// into an iterator over the contents of the corresponding block.
Iterator* Table::BlockReader(void* arg,
const ReadOptions& options,
const Slice& index_value) {
Table* table = reinterpret_cast<Table*>(arg);
Cache* block_cache = table->rep_->options.block_cache;
Block* block = NULL;
Cache::Handle* cache_handle = NULL;
BlockHandle handle;
Slice input = index_value;
Status s = handle.DecodeFrom(&input);
// We intentionally allow extra stuff in index_value so that we
// can add more features in the future.
if (s.ok()) {
BlockContents contents;
if (block_cache != NULL) {
char cache_key_buffer[16];
EncodeFixed64(cache_key_buffer, table->rep_->cache_id);
EncodeFixed64(cache_key_buffer+8, handle.offset());
Slice key(cache_key_buffer, sizeof(cache_key_buffer));
cache_handle = block_cache->Lookup(key);
if (cache_handle != NULL) {
block = reinterpret_cast<Block*>(block_cache->Value(cache_handle));
} else {
s = ReadBlock(table->rep_->file, options, handle, &contents);
if (s.ok()) {
block = new Block(contents);
if (contents.cachable && options.fill_cache) {
cache_handle = block_cache->Insert(
key, block, block->size(), &DeleteCachedBlock);
}
}
}
} else {
s = ReadBlock(table->rep_->file, options, handle, &contents);
if (s.ok()) {
block = new Block(contents);
}
}
}
Iterator* iter;
if (block != NULL) {
iter = block->NewIterator(table->rep_->options.comparator);
if (cache_handle == NULL) {
iter->RegisterCleanup(&DeleteBlock, block, NULL);
} else {
iter->RegisterCleanup(&ReleaseBlock, block_cache, cache_handle);
}
} else {
iter = NewErrorIterator(s);
}
return iter;
}
示例10: WriteSkylanderToPortal
bool WriteSkylanderToPortal(unsigned char *encrypted_new_data, unsigned char *encrypted_old_data)
{
bool bResult;
bool bNewSkylander = false;
unsigned char data[0x10];
ConnectToPortal();
// must start with a read of block zero
bResult = ReadBlock(g_hPortalHandle, 0, data, bNewSkylander);
if(!bResult) {
bNewSkylander = !bNewSkylander;
bResult = ReadBlock(g_hPortalHandle, 0, data, bNewSkylander);
if(!bResult) {
fprintf(stderr, "Abort before write. Could not read data from Skylander portal.\n");
return false;
}
}
if(encrypted_old_data == NULL) {
encrypted_old_data = ReadSkylanderFromPortal();
}
printf("\nWriting Skylander to portal.\n");
for(int i=0; i<2; i++) {
// two pass write
// write the access control blocks first
bool selectAccessControlBlock;
if(i == 0) {
selectAccessControlBlock = 1;
} else {
selectAccessControlBlock = 0;
}
for(int block=0; block < 0x40; ++block) {
bool changed, OK;
int offset = block * 0x10;
changed = (memcmp(encrypted_old_data+offset, encrypted_new_data+offset, 0x10) != 0);
if(changed) {
if(IsAccessControlBlock(block) == selectAccessControlBlock) {
OK = WriteBlock(g_hPortalHandle, block, encrypted_new_data+offset, bNewSkylander);
if(!OK) {
fprintf(stderr, "Failed to write block %d. Aborting.\n", block);
return false;
}
}
}
}
}
return true;
}
示例11: DB_DEBUG
void
CVarDataFile::UpdateRecord(DatabaseRec *inRecP) {
SInt32 recSize = inRecP->recSize;
SInt32 recPos = itsMasterIndex->UpdateEntry(inRecP->recID, recSize); // find index entry
inRecP->recPos = recPos;
#if DB_DEBUG_MODE || DB_INTEGRITY_CHECKING
if (inRecP->recID > mLastRecID) {
DB_DEBUG("ERROR: Invalid Record ID "<<inRecP->recID<<" updated. Last ID is "<<mLastRecID, DEBUG_ERROR);
Throw_( dbInvalidID );
}
if (recSize < (SInt32)sizeof(DatabaseRec)) {
DB_DEBUG("ERROR: Trying to update Rec "<<inRecP->recID<<" with size of "<<recSize<<" bytes, smaller than the record header alone.", DEBUG_ERROR);
Throw_( dbDataCorrupt );
}
ASSERT(mBytesUsed <= mAllocatedBytes); // can't use more than we've allocated
ASSERT((mAllocatedBytes+mFirstItemPos) == GetLength()); // LFileStream needs to be in synch
if (GetLength() < recPos) {
DB_DEBUG("ERROR: Index returned offset "<<recPos<<" for Rec "<<inRecP->recID<<", but datafile is only "<<GetLength()<<" bytes long.", DEBUG_ERROR);
mFileIsDamaged = true;
Throw_( dbIndexCorrupt );
}
// DB_DEBUG("in UpdateRecord("<< inRecP->recID <<"); size: "<<recSize<<" pos: "<<recPos, DEBUG_TRIVIA);
RecIDT oldID;
SInt32 slotSize;
SetMarker(recPos + kVarDBFileSlotSizeOffset, streamFrom_Start); // debugging, check old ID
ReadBlock(&slotSize, kSizeOfSlotSize);
ReadBlock(&oldID, kSizeOfRecID);
#if PLATFORM_LITTLE_ENDIAN
slotSize = BigEndian32_ToNative(slotSize);
oldID = BigEndian32_ToNative(oldID);
#endif // PLATFORM_LITTLE_ENDIAN
if ( (oldID != 0) && (oldID != inRecP->recID) ) {
DB_LOG("ERROR: Update Rec " << inRecP->recID << " " << recSize << "B pos: "<<recPos<<" FAILED, overwriting Rec "<<oldID);
DB_DEBUG("ERROR: Updating "<< inRecP->recID << " into wrong place [" << recPos << "] , overwriting Rec "<<oldID, DEBUG_ERROR);
mFileIsDamaged = true;
Throw_( dbIndexCorrupt );
}
if (slotSize < RecSizeToSlotSize(recSize)) {
DB_LOG("ERROR: Update Rec " << inRecP->recID << " " << recSize << "B pos: "<<recPos<<" FAILED, slot too small "<<slotSize<<"B");
DB_DEBUG("ERROR: Writing "<< inRecP->recID <<" of "<<RecSizeToSlotSize(recSize)<<" bytes into a "<<slotSize<<" byte slot at "<< recPos, DEBUG_ERROR);
mFileIsDamaged = true;
Throw_( dbDataCorrupt );
}
#endif
SetMarker(recPos + kVarDBFileRecIDOffset, streamFrom_Start); // move to start of slot's data, skipping size
inRecP->recID = Native_ToBigEndian32(inRecP->recID);
WriteBlock(&inRecP->recID, RecSizeToIOSize(recSize)); // write the new record data into the slot
inRecP->recID = BigEndian32_ToNative(inRecP->recID);
DB_LOG("Updated Rec " << inRecP->recID << " " << recSize << "B pos: "<<recPos);
DB_DEBUG("UpdateRecord("<< inRecP->recID <<"); size: "<<recSize<<" pos: "<<recPos, DEBUG_TRIVIA);
}
示例12: d
TInt YModem::ReadPacket(TDes8& aDest)
{
TUint8* pD = (TUint8*)aDest.Ptr();
TInt r;
TPtr8 d(pD, 0, 1);
r = ReadBlock(d);
if (r != KErrNone)
return r;
if (d.Length()==0)
return KErrZeroLengthPacket;
TUint8 b0 = *pD;
if (b0==CAN)
return KErrAbort;
if (b0==EOT)
return KErrEof;
if (b0==SOH)
iBlockSize=128;
else if (b0==STX)
iBlockSize=1024;
else
return KErrBadPacketType;
iTimeout=5000000;
iPacketSize = iBlockSize+5;
d.Set(pD+1, 0, iPacketSize-1);
r = ReadBlock(d);
if (r!=KErrNone && r!=KErrTimedOut)
return r;
if (d.Length() < iPacketSize-1)
return KErrPacketTooShort;
TUint8 seq = pD[1];
TUint8 seqbar = pD[2];
seqbar^=seq;
if (seqbar != 0xff)
return KErrCorruptSequenceNumber;
if (seq==iSeqNum)
return KErrAlreadyExists;
else
{
TUint8 nextseq=(TUint8)(iSeqNum+1);
if (seq!=nextseq)
return KErrWrongSequenceNumber;
}
iCrc=0;
UpdateCrc(pD+3, iBlockSize);
aDest.SetLength(iPacketSize);
TUint16 rx_crc = (TUint16)((pD[iPacketSize-2]<<8) | pD[iPacketSize-1]);
if (rx_crc != iCrc)
return KErrBadCrc;
++iSeqNum;
return KErrNone;
}
示例13: sizeof
static char *ReadFileBlock(InodePtr fileInode, long blockNum, long blockOffset,
long length, char *buffer, long cache)
{
long diskBlockNum, indBlockNum, indBlockOff, refsPerBlock;
char *indBlock;
if (blockNum >= fileInode->e2di_nblock) return 0;
refsPerBlock = gBlockSize / sizeof(u_int32_t);
// Get Direct Block Number.
if (blockNum < NDADDR) {
diskBlockNum = bswap32(fileInode->e2di_blocks[blockNum]);
} else {
blockNum -= NDADDR;
// Get Single Indirect Block Number.
if (blockNum < refsPerBlock) {
indBlockNum = bswap32(fileInode->e2di_blocks[NDADDR]);
} else {
blockNum -= refsPerBlock;
// Get Double Indirect Block Number.
if (blockNum < (refsPerBlock * refsPerBlock)) {
indBlockNum = fileInode->e2di_blocks[NDADDR + 1];
} else {
blockNum -= refsPerBlock * refsPerBlock;
// Get Triple Indirect Block Number.
indBlockNum = fileInode->e2di_blocks[NDADDR + 2];
indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
blockNum %= (refsPerBlock * refsPerBlock);
indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / refsPerBlock;
blockNum %= refsPerBlock;
indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
diskBlockNum = bswap32(((u_int32_t *)indBlock)[blockNum]);
}
buffer = ReadBlock(diskBlockNum, blockOffset, length, buffer, cache);
return buffer;
}
示例14: print_iNode
void print_iNode(ino pathiNode) {
char iNodeDataBlock[BLOCK_SIZE];
iNodeEntry *iNodes;
if (pathiNode < 16) {
ReadBlock(4, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
printiNode(iNodes[pathiNode]);
} else {
ReadBlock(5, iNodeDataBlock);
iNodes = (iNodeEntry *)iNodeDataBlock;
printiNode(iNodes[pathiNode - 16]);
}
}
示例15: set_stats
void set_stats(const ino iNode, gstat *pStat) {
if (iNode < 16) {
char iNodeDataBlock[BLOCK_SIZE];
ReadBlock(4, iNodeDataBlock);
iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
assign_stats(iNodes[iNode], pStat);
} else {
char iNodeDataBlock[BLOCK_SIZE];
ReadBlock(5, iNodeDataBlock);
iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
// We remove 16 from the iNode to get back to the beginning of the array
assign_stats(iNodes[iNode - 16], pStat);
}
}