Exemple #1
0
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);
    }
}
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);
}
Exemple #3
0
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);
    }
}
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 );
    }
}
Exemple #5
0
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;
}
Exemple #6
0
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;
}
Exemple #7
0
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");
	
}
Exemple #8
0
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
}
Exemple #9
0
static char * ReadFileBlock( InodePtr fileInode, long fragNum, long blockOffset,
                             long length, char * buffer, long cache )
{
    long fragCount, blockNum;
    long diskFragNum, indFragNum, indBlockOff, refsPerBlock;
    char *indBlock;

    fragCount = (fileInode->di_size + gFragSize - 1) / gFragSize;
    if (fragNum >= fragCount) return 0;

    refsPerBlock = gBlockSize / sizeof(ufs_daddr_t);

    blockNum = fragNum / gFragsPerBlock;
    fragNum -= blockNum * gFragsPerBlock;
    
    // Get Direct Block Number.
    if (blockNum < NDADDR) {
        diskFragNum = fileInode->di_db[blockNum];
    } else {
        blockNum -= NDADDR;

        // Get Single Indirect Fragment Number.
        if (blockNum < refsPerBlock) {
            indFragNum = fileInode->di_ib[0];
        } else {
            blockNum -= refsPerBlock;

            // Get Double Indirect Fragment Number.
            if (blockNum < (refsPerBlock * refsPerBlock)) {
                indFragNum = fileInode->di_ib[1];
            } else {
                blockNum -= refsPerBlock * refsPerBlock;

                // Get Triple Indirect Fragment Number.
                indFragNum = fileInode->di_ib[2];

                indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
                indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
                blockNum %= (refsPerBlock * refsPerBlock);
                indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
            }

            indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
            indBlockOff = blockNum / refsPerBlock;
            blockNum %= refsPerBlock;
            indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
        }

        indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
        diskFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[blockNum]);
    }

    buffer = ReadBlock(diskFragNum+fragNum, blockOffset, length, buffer, cache);

    return buffer;
}
Exemple #10
0
// 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;
}
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;
}
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);
}
Exemple #13
0
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;
	}
Exemple #14
0
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;
}
Exemple #15
0
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]);
    }
}
Exemple #16
0
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);
    }
}
Exemple #17
0
int has_allowed_block(ino iNode) {
    char iNodeDataBlock[BLOCK_SIZE];
    iNodeEntry *iNodes;

    if (iNode < 16) {
        ReadBlock(4, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        return iNodes[iNode].iNodeStat.st_blocks;
    } else {
        ReadBlock(5, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        return iNodes[iNode - 16].iNodeStat.st_blocks;
    }
}
bool FirewirePort::ReadAllBoards(void)
{
    if (Protocol_ == FirewirePort::PROTOCOL_BC_QRW) {
        return ReadAllBoardsBroadcast();
    }

    if (!handle) {
        outStr << "ReadAllBoards: handle for port " << PortNum << " is NULL" << std::endl;
        return false;
    }
    bool allOK = true;
    bool noneRead = true;
    for (int board = 0; board < max_board; board++) {
        if (BoardList[board]) {
            bool ret = ReadBlock(board, 0, BoardList[board]->GetReadBuffer(),
                                 BoardList[board]->GetReadNumBytes());
            if (ret) {
                noneRead = false;
            } else {
                allOK = false;
            }
            BoardList[board]->SetReadValid(ret);

            if (!ret) {
                outStr << "ReadAllBoards: read failed on port " << PortNum << ", board " << board << std::endl;
            }
        }
    }
    if (noneRead) {
        PollEvents();
    }
    return allOK;
}
Exemple #19
0
static int RemoveINodeFromINode(const char* filename, const iNodeEntry *pSrcInode, iNodeEntry *pDstInode) {
  
  if (!(pDstInode->iNodeStat.st_mode & G_IFDIR))
    return -1;

  char dataBlock[BLOCK_SIZE];
  if (ReadBlock(pDstInode->Block[0], dataBlock) == -1)
    return -1;

  DirEntry *pDirEntry = (DirEntry*)dataBlock;
  if (pDirEntry == NULL)
    return -1;
  
  const ino inode = pSrcInode->iNodeStat.st_ino;
  const size_t nDir = NumberofDirEntry(pDstInode->iNodeStat.st_size);
  size_t i;
  for (i = 0; i < nDir; ++i) {
    if ((pDirEntry[i].iNode == inode) 
	&& (strcmp(pDirEntry[i].Filename, filename) == 0))
      break;
  }
  for (; i< nDir; ++i) {
    pDirEntry[i] = pDirEntry[i + 1];
  }
  pDstInode->iNodeStat.st_size -= sizeof(DirEntry);
  if (WriteBlock(pDstInode->Block[0], dataBlock) == -1)
    return -1;
  return WriteINodeToDisk(pDstInode);
}
Exemple #20
0
void Table::ReadMeta(const Footer& footer) {
  if (rep_->options.filter_policy == NULL) {
    return;  // Do not need any metadata
  }

  // TODO(sanjay): Skip this if footer.metaindex_handle() size indicates
  // it is an empty block.
  ReadOptions opt;
  if (rep_->options.paranoid_checks) {
    opt.verify_checksums = true;
  }
  BlockContents contents;
  if (!ReadBlock(rep_->file, opt, footer.metaindex_handle(), &contents).ok()) {
    // Do not propagate errors since meta info is not needed for operation
    return;
  }
  Block* meta = new Block(contents);

  Iterator* iter = meta->NewIterator(BytewiseComparator());
  std::string key = "filter.";
  key.append(rep_->options.filter_policy->Name());
  iter->Seek(key);
  if (iter->Valid() && iter->key() == Slice(key)) {
    ReadFilter(iter->value());
  }
  delete iter;
  delete meta;
}
Exemple #21
0
static long ReadInode( long inodeNum, InodePtr inode, long * flags, long * time )
{
    long fragNum = ino_to_fsba(gFS, inodeNum);
    long blockOffset = ino_to_fsbo(gFS, inodeNum) * sizeof(Inode);

    ReadBlock(fragNum, blockOffset, sizeof(Inode), (char *)inode, 1);
    byte_swap_dinode_in(inode);

    if (time != 0) *time = inode->di_mtime;

    if (flags != 0) {
        switch (inode->di_mode & IFMT) {
            case IFREG: *flags = kFileTypeFlat; break;
            case IFDIR: *flags = kFileTypeDirectory; break;
            case IFLNK: *flags = kFileTypeLink; break;
            default :   *flags = kFileTypeUnknown; break;
        }

        *flags |= inode->di_mode & kPermMask;

        if (inode->di_uid != 0) *flags |= kOwnerNotRoot;
    }

    return 0;
}
Exemple #22
0
void free_data_block_bitmap(UINT16 blockNumber) {
    printf("GLOFS: Relache bloc %u\n", blockNumber);
    char blockFreeBitmap[BLOCK_SIZE];
    ReadBlock(FREE_BLOCK_BITMAP, blockFreeBitmap);
    blockFreeBitmap[blockNumber] = 1;
    WriteBlock(FREE_BLOCK_BITMAP, blockFreeBitmap);
}
Exemple #23
0
    FileRead( FILE* f )
        : m_stream( LZ4_createStreamDecode() )
        , m_file( f )
        , m_buf( m_bufData[1] )
        , m_second( m_bufData[0] )
        , m_offset( 0 )
        , m_lastBlock( 0 )
        , m_signalSwitch( false )
        , m_signalAvailable( false )
        , m_exit( false )
    {
        char hdr[4];
        if( fread( hdr, 1, sizeof( hdr ), m_file ) != sizeof( hdr ) ) throw NotTracyDump();
        if( memcmp( hdr, Lz4Header, sizeof( hdr ) ) != 0 )
        {
            fseek( m_file, 0, SEEK_SET );
            uint32_t sz;
            static_assert( sizeof( sz ) == sizeof( hdr ), "Size mismatch" );
            memcpy( &sz, hdr, sizeof( sz ) );
            if( sz > LZ4Size ) throw NotTracyDump();
        }

        ReadBlock();
        std::swap( m_buf, m_second );
        m_decThread = std::thread( [this] { Worker(); } );
    }
Exemple #24
0
void increase_link_count(ino iNode) {
    char iNodeDataBlock[BLOCK_SIZE];
    iNodeEntry *iNodes;

    if (iNode < 16) {
        ReadBlock(4, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        ++iNodes[iNode].iNodeStat.st_nlink;
        WriteBlock(4, iNodeDataBlock);
    } else {
        ReadBlock(5, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        ++iNodes[iNode - 16].iNodeStat.st_nlink;
        WriteBlock(5, iNodeDataBlock);
    }
}
Exemple #25
0
void remove_file_from_directory(ino pathiNode, ino iNode,
                                const char *filename) {
    char directoryDataBlock[BLOCK_SIZE];
    ReadBlock(6 + pathiNode - 1, directoryDataBlock);
    DirEntry *directory = (DirEntry *)directoryDataBlock;

    int filesNumber = numberOfFilesInDirectory(directory);
    // For the non-empty files
    int fileSize = get_file_size(iNode);

    int index;
    for (index = 0; index < filesNumber; ++index) {
        if (strcmp(filename, directory[index].Filename) == 0) {
            // If the file is empty, removing by its content won't work. We have
            // to take the size of the file itself

            fileSize = sizeof(directory[index]);

            strcpy(directory[index].Filename, "");
            directory[index].iNode = 0;
            // Remove from the size of the directory
            remove_from_inode_size(pathiNode, fileSize);

            // If the file is not at the end of the directory
            if (index < filesNumber - 1) {
                move_at_the_end(directory, index, filesNumber);
            }
        }
    }

    WriteBlock(6 + pathiNode - 1, directoryDataBlock);
}
Exemple #26
0
void free_inode_bitmap(ino iNode) {
    printf("GLOFS: Relache i-node %u\n", iNode);
    char freeiNodeBitmap[BLOCK_SIZE];
    ReadBlock(FREE_INODE_BITMAP, freeiNodeBitmap);
    freeiNodeBitmap[iNode] = 1;
    WriteBlock(FREE_INODE_BITMAP, freeiNodeBitmap);
}
Exemple #27
0
long MPEG_File::previousFrameOffset(long position)
{
	// TODO: This will miss syncs spanning buffer read boundaries.

	while(int(position - BufferSize()) > int(BufferSize()))
	{
		position -= BufferSize();
		Seek(position);
		SjByteVector buffer = ReadBlock(BufferSize());

		// If the amount of data is smaller than an MPEG header (4 bytes) there's no
		// chance of this being valid.

		if(buffer.size() < 4)
		{
			return -1;
		}

		for(int i = buffer.size() - 2; i >= 0; i--)
		{
			if((unsigned char)(buffer[i]) == 0xff && secondSynchByte(buffer[i + 1]))
			{
				return position + i;
			}
		}
	}

	return -1;
}
Exemple #28
0
void VCTCOL::ReadColumn(PGLOBAL g)
  {
  PTXF txfp = ((PTDBVCT)To_Tdb)->Txfp;

#if defined(_DEBUG)
  assert (!To_Kcol);
#endif

  if (trace > 1)
    htrc("VCT ReadColumn: col %s R%d coluse=%.4X status=%.4X buf_type=%d\n",
         Name, To_Tdb->GetTdb_No(), ColUse, Status, Buf_Type);

  if (ColBlk != txfp->CurBlk)
    ReadBlock(g);
  else if (ColPos == txfp->CurNum)
    return;            // Value is already there

//ColBlk = txfp->CurBlk;        done in ReadBlock
  ColPos = txfp->CurNum;
  Value->SetValue_pvblk(Blk, ColPos);

  // Set null when applicable
  if (Nullable)
    Value->SetNull(Value->IsZero());

  } // end of ReadColumn
Exemple #29
0
void remove_from_inode_size(ino iNode, UINT16 size) {
    char iNodeDataBlock[BLOCK_SIZE];
    iNodeEntry *iNodes;

    if (iNode < 16) {
        ReadBlock(4, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        iNodes[iNode].iNodeStat.st_size -= size;
        WriteBlock(4, iNodeDataBlock);
    } else {
        ReadBlock(5, iNodeDataBlock);
        iNodes = (iNodeEntry *)iNodeDataBlock;
        iNodes[iNode - 16].iNodeStat.st_size -= size;
        WriteBlock(5, iNodeDataBlock);
    }
}
Exemple #30
0
int create_hardlink_file(iNodeEntry *existingFileiNode, ino newLinkPathiNode,
                         char *linkName, iNodeEntry *iNodes) {
    char directoryDataBlock[BLOCK_SIZE];

    ReadBlock(6 + newLinkPathiNode - 1, directoryDataBlock);
    DirEntry *directory = (DirEntry *)directoryDataBlock;

    int numberOfFiles = numberOfFilesInDirectory(directory);

    // We create the new link
    strcpy(directory[numberOfFiles].Filename, linkName);
    directory[numberOfFiles].iNode = existingFileiNode->iNodeStat.st_ino;

    // We increase the number of links
    ++existingFileiNode->iNodeStat.st_nlink;

    // We write the updated directory back to the block
    WriteBlock(6 + newLinkPathiNode - 1, directoryDataBlock);

    // We increase the size of the directory
    if (newLinkPathiNode < 16) {
        iNodes[newLinkPathiNode].iNodeStat.st_size +=
            sizeof(directory[numberOfFiles]);
    } else {
        iNodes[newLinkPathiNode - 16].iNodeStat.st_size +=
            sizeof(directory[numberOfFiles]);
    }

    return 0;
}