void fp_EmbedRun::mapXYToPosition(UT_sint32 x, UT_sint32 /*y*/, PT_DocPosition& pos, bool& bBOL, bool& bEOL, bool & /*isTOC*/)
{
	if (x > getWidth())
		pos = getBlock()->getPosition() + getBlockOffset() + getLength();
	else
		pos = getBlock()->getPosition() + getBlockOffset();

	bBOL = false;
	bEOL = false;
}
Esempio n. 2
0
//Note: il faut traduire une vraie adresse en offset
int oslVramMgrFreeBlock(void *blockAddress, int blockSize)		{
	int i, j, updateNeeded;
	int blockOffset = (u32)blockAddress - (u32)osl_vramBase;

	//Sans le manager, c'est plus simple...
	if (!osl_useVramManager)		{
		osl_currentVramPtr -= blockSize;
		//Pas vraiment utile, juste là pour s'assurer qu'on ne dépassera jamais de l'espace alloué
		if (osl_currentVramPtr < osl_vramBase)
			osl_currentVramPtr = osl_vramBase;
		return 1;
	}

	//Trouvons le bloc qui va bien
	for (i=0;i<osl_vramBlocksNb;i++)		{
		if (getBlockOffset(i) == blockOffset)
			break;
	}

	//Impossible de trouver le bloc
	if (i >= osl_vramBlocksNb)
		return 0;

	//Le bloc est maintenant libre ^^
	setBlockFree(i, 1);

	//Bon maintenant reste à "assembler" les blocs libres adjacents
	do		{
		updateNeeded = 0;
		for (j=0;j<osl_vramBlocksNb-1;j++)			{
			//Cherchons deux blocs adjacents
			if ((isBlockFree(j) && isBlockFree(j + 1))
				|| (isBlockFree(j) && getBlockSize(j) == 0))			{
				//Assemblons ces blocs maintenant
				int newSize = getBlockSize(j) + getBlockSize(j + 1), newAdd = getBlockOffset(j);
				memmove(osl_vramBlocks + j, osl_vramBlocks + j + 1, sizeof(OSL_VRAMBLOCK) * (osl_vramBlocksNb - j - 1));
				setBlockOffset(j, newAdd);
				setBlockSize(j, newSize);
				//Le bloc entre deux est supprimé
				osl_vramBlocksNb--;
				//ATT: On devra refaire un tour pour vérifier si de nouveaux blocs n'ont pas été créés
				updateNeeded = 1;
			}
		}

	} while (updateNeeded);

	return 1;
}
Esempio n. 3
0
File: block.cpp Progetto: xzblh/fs
void writeBlock(BLOCK * blockP, void * mem)
{
	if(NULL == mem){
		return ;
	}
	fseek(dataFp, getBlockOffset(blockP->blockNumber), SEEK_SET);
	Fwrite(mem, superBlockPointer->blockSize, 1, dataFp);
}
Esempio n. 4
0
bool Log::BlockBuffer::writeBack() {
  if (!ready || !dirty) return true;

  off_t offset = getBlockOffset(id);
  if (!Disk::diskWrite(offset, block, BLOCK_SIZE))
    return false;

  dirty = false;

  return true;
}
Esempio n. 5
0
void BufferManager::pageIn(int index, int pageNum) {
	// Read page data from disk into buffer
	char buffer[4096] = {};
	int blockOffset = getBlockOffset(pageNum);
	fm->read(dbName, blockOffset, 8, buffer);

	// Create page
	pages[index] = Page(buffer);

	// Set page status
	pageNums[index] = pageNum;
	dirtied[index] = 0;
	pinned[index] = 0;
}
Esempio n. 6
0
RingBufferBlock* RingBuffer::getNextBlock(RingBufferBlock *block)
{
	if (NULL == block) {
		return NULL;
	}

	int alignLength = ALIGN(block->m_length);
	int offset = getBlockOffset(block);

	int nextOffset = offset + sizeof(RingBufferBlock) + alignLength;
	if (nextOffset >= m_size) {
		return NULL;
	}

	return (RingBufferBlock*)(m_data + nextOffset);
}
Esempio n. 7
0
void BufferManager::pageOut(int index) {
	// If page is dirty, write it to disk
	if (dirtied[index] == 1) {
		char buffer[4096] = {};
		char* pageBytes = (char*) &pages[index];
		for (int i = 0; i < 4096; i++) { buffer[i] = pageBytes[i]; }
		int blockOffset = getBlockOffset(pageNums[index]);
		fm->write(dbName, blockOffset, 8, buffer);
	}

	// Evict page
	pages[index] = Page();

	// Reset page status
	pageNums[index] = 0;
	dirtied[index] = 0;
	pinned[index] = 0;
}
Esempio n. 8
0
bool Log::BlockBuffer::prepareBlock(uint32_t blockId) {
  // Check valid id.
  if (!isValidBlockId(blockId)) return false;

  // If the block is dirty, write it back.
  if (!writeBack()) return false;

  // If the block is already loaded, just return.
  if (id == blockId && ready) return true;

  // Read in block.
  if (!Disk::diskRead(getBlockOffset(blockId), block, BLOCK_SIZE))
    return false;

  id = blockId;
  ready = true;

  return true;
}
Esempio n. 9
0
File: inode.cpp Progetto: xzblh/fs
INODE * getINODE(int inodeNumber)
{
	INODE * inodeP = (INODE *)Malloc(sizeof(INODE));
	inodeP->mem = Malloc(superBlockPointer->blockSize);
	int time_tmp = 0;
	fseek(dataFp, getInodeAreaOffset(superBlockPointer) + inodeNumber * superBlockPointer->inodeSize, SEEK_SET);
	fread(&time_tmp, 4, 1, dataFp);
	inodeP->aTime = time_tmp;
	fread(&time_tmp, 4, 1, dataFp);
	inodeP->cTime = time_tmp;
	fread(&time_tmp, 4, 1, dataFp);
	inodeP->mTime = time_tmp;
	fread(&inodeP->GID, 4, 1, dataFp);
	fread(&inodeP->UID, 4, 1, dataFp);
	fread(&inodeP->authority, 4, 1, dataFp);
	fread(&inodeP->inodeNumber, 4, 1, dataFp);
	fread(&inodeP->blockNumber, 4, 1, dataFp);
	fread(&inodeP->length, 4, 1, dataFp);
	fseek(dataFp, getBlockOffset(inodeP->blockNumber), SEEK_SET);
	fread(inodeP->mem, superBlockPointer->blockSize, 1, dataFp);
	return inodeP;
}
Esempio n. 10
0
/**
 * Transfer the block form the remote rank, that holds it,
 * or if it´s the same rank, copy it by using memcpy.
 */
void grid::NumaDistStaticGrid::getBlock(unsigned long block,
        long oldBlock,
        unsigned long cacheIndex,
        unsigned char *cache) {
    unsigned long blockSize = getTotalBlockSize();
    int remoteRank = getBlockRank(block);
    incCounter(perf::Counter::MPI);
    int mpiResult;
     
    if (remoteRank == getMPIRank()) {
        //The block is located in the same NUMA Domain, but in the memspace of another thread.
        pthread_t remoteId = getThreadId(block);
        size_t offset = getType().getSize()*blockSize*getBlockThreadOffset(block);
        //copy the block
     //   std::cout << "Memcpy Thread: " << remoteId << " Pointer: " << &(m_threadHandle.getStaticPtr(remoteId, m_id));
        memcpy(cache, m_threadHandle.getStaticPtr(remoteId, m_id) + offset, getType().getSize()*blockSize);
    } 
    else {
        
        //This section is critical. Only one Thread is allowed to access.
        //TODO: Find a better solution than pthread mutex.
        unsigned long offset = getBlockOffset(block);
        NDBG_UNUSED(mpiResult);
        mpiResult = m_threadHandle.getBlock(cache,
                blockSize,
                getType().getMPIType(),
                remoteRank,
                offset * blockSize,
                blockSize,
                getType().getMPIType(),
                m_threadHandle.mpiWindow);
        assert(mpiResult == MPI_SUCCESS);

    }



}
Esempio n. 11
0
/*!
  Dump fp_TextRun information
  \param fp File where the dump should be written to
*/
void fp_TextRun::__dump(FILE * fp) const
{
	fp_Run::__dump(fp);

	fprintf(fp,"         [");
	if (getLength() != 0)
	{
		UT_uint32 koff=getBlockOffset();
		UT_uint32 klen=getLength();

		PD_StruxIterator text(getBlock()->getStruxDocHandle(),
							  koff + fl_BLOCK_STRUX_OFFSET);

		for(UT_uint32 k = 0; k < klen; k++)
		{
			unsigned char c = static_cast<unsigned char>(text[k+fl_BLOCK_STRUX_OFFSET] & 0x00ff);
			UT_return_if_fail(text.getStatus() == UTIter_OK);
			fprintf(fp,"%c",c);
		}
	}
	fprintf(fp,"]\n");
		
}
Esempio n. 12
0
RingBufferBlock* RingBuffer::splitBlock(int sum, int size)
{
	int alignLength = ALIGN(sizeof(struct RingBufferBlock) + size);

	// 切割出第一个长度为size的block
	struct RingBufferBlock *head = getHead();
	head->m_length = size;
	head->m_skip = 0;
	head->m_next = NULL;
	head->m_link = NULL;

	// 切割出第二个长度为sum - size的block
	struct RingBufferBlock *next = getNextBlock(head);
	if (next) {
		int nextOffset = getBlockOffset(next);

		// 如果第二块位于末尾,判断空间是否足够再构造一个block
		if (m_size - nextOffset > sizeof(RingBufferBlock)) {
			if (alignLength < sum) {
				next->m_length = sum - alignLength - sizeof(RingBufferBlock);
				next->m_link = NULL;
				next->m_next = NULL;
				next->m_skip = 0;

				if (next->m_length <= 0) {
					LOG_ERROR << "next->m_length = " << next->m_length;
					statistic();
				}
			}
		}
	} else {
		// m_head = 0;
	}

	// 返回第一块block
	return head;
}
void fp_EmbedRun::findPointCoords(UT_uint32 iOffset, UT_sint32& x, UT_sint32& y, UT_sint32& x2, UT_sint32& y2, UT_sint32& height, bool& bDirection)
{
	//UT_DEBUGMSG(("fintPointCoords: ImmageRun\n"));
	UT_sint32 xoff;
	UT_sint32 yoff;

	UT_ASSERT(getLine());

	getLine()->getOffsets(this, xoff, yoff);
	if (iOffset == (getBlockOffset() + getLength()))
	{
		x = xoff + getWidth();
		x2 = x;
	}
	else
	{
		x = xoff;
		x2 = x;
	}
	y = yoff + getAscent() - m_iPointHeight;
	height = m_iPointHeight;
	y2 = y;
	bDirection = (getVisDirection() != UT_BIDI_LTR);
}
Esempio n. 14
0
void fp_AnnotationRun::_draw(dg_DrawArgs* pDA)
{
        if(!displayAnnotations())
	  return;
	if(!m_bIsStart)
	  return;

	GR_Graphics * pG = pDA->pG;

	UT_sint32 xoff = 0, yoff = 0;
	GR_Painter painter(pG);

	// need screen locations of this run

	getLine()->getScreenOffsets(this, xoff, yoff);

	UT_sint32 iYdraw =  pDA->yoff - getAscent()-1;

	UT_uint32 iRunBase = getBlock()->getPosition() + getBlockOffset();

//
// Sevior was here
//		UT_sint32 iFillTop = iYdraw;
	UT_sint32 iFillTop = iYdraw+1;
	UT_sint32 iFillHeight = getAscent() + getDescent();

	FV_View* pView = _getView();
	UT_uint32 iSelAnchor = pView->getSelectionAnchor();
	UT_uint32 iPoint = pView->getPoint();

	UT_uint32 iSel1 = UT_MIN(iSelAnchor, iPoint);
	UT_uint32 iSel2 = UT_MAX(iSelAnchor, iPoint);

	UT_ASSERT(iSel1 <= iSel2);
	bool bIsInTOC = getBlock()->isContainedByTOC();
	if (
	    isInSelectedTOC() || (!bIsInTOC && (
						/* pView->getFocus()!=AV_FOCUS_NONE && */
						(iSel1 <= iRunBase)
						&& (iSel2 > iRunBase)))
	    )
	{
	    UT_RGBColor color(_getView()->getColorSelBackground());			
	    pG->setColor(_getView()->getColorAnnotation(this));
	    painter.fillRect(color, pDA->xoff, iFillTop, getWidth(), iFillHeight);

	}
	else
        {
	    Fill(getGraphics(),pDA->xoff, iFillTop, getWidth(), iFillHeight);
	    pG->setColor(_getColorFG());
	}
	pG->setFont(_getFont());
	pG->setColor(_getView()->getColorAnnotation(this));
	UT_DEBUGMSG(("Drawing string m_sValue %s \n",m_sValue.utf8_str()));
	painter.drawChars(m_sValue.ucs4_str().ucs4_str(), 0,m_sValue.ucs4_str().size(), pDA->xoff,iYdraw, NULL);
//
// Draw underline/overline/strikethough
//
	UT_sint32 yTopOfRun = pDA->yoff - getAscent()-1; // Hack to remove
	                                                 //character dirt
	drawDecors( xoff, yTopOfRun,pG);

}
Esempio n. 15
0
void *oslVramMgrAllocBlock(int blockSize)		{
	int i;

	osl_skip = osl_vramBlocks[0].size;
	//Le bloc ne peut pas être de taille nulle ou négative
	if (blockSize <= 0)
		return NULL;

	//La taille est toujours multiple de 16 - arrondir au bloc supérieur
	if (blockSize & 15)
		blockSize += 16;

	//Sans le manager, c'est plus simple...
	if (!osl_useVramManager)		{
		int ptr = osl_currentVramPtr;
		//Dépassement de la mémoire?
		if (osl_currentVramPtr + blockSize >= osl_vramBase + osl_vramSize)
			return NULL;
		osl_currentVramPtr += blockSize;
		return (void*)ptr;
	}

	for (i=0;i<osl_vramBlocksNb;i++)		{
		//Ce bloc est-il suffisant?
		if (isBlockFree(i) && getBlockSize(i) >= blockSize)
			break;
	}

	//Aucun bloc libre
	if (i >= osl_vramBlocksNb)
		return NULL;

	//Pile la mémoire qu'il faut? - pas géré, il faut toujours que le dernier bloc soit marqué comme libre (même s'il reste 0 octet) pour ulSetTexVramParameters
	if (getBlockSize(i) == blockSize && i != osl_vramBlocksNb - 1)			{
		//Il n'est plus libre
		setBlockFree(i, 0);
	}
	else		{
		//On va ajouter un nouveau bloc
		osl_vramBlocksNb++;

		//Plus de mémoire pour le tableau? On l'aggrandit
		if (osl_vramBlocksNb >= osl_vramBlocksMax)			{
			OSL_VRAMBLOCK *oldBlock = osl_vramBlocks;
			osl_vramBlocksMax += DEFAULT_TABLE_SIZE;
			osl_vramBlocks = (OSL_VRAMBLOCK*)realloc(osl_vramBlocks, osl_vramBlocksMax);

			//Vérification que la mémoire a bien pu être allouée
			if (!osl_vramBlocks)		{
				osl_vramBlocks = oldBlock;
				osl_vramBlocksMax -= DEFAULT_TABLE_SIZE;
				//Pas assez de mémoire
				return NULL;
			}
		}

		//Décalage pour insérer notre nouvel élément
		memmove(osl_vramBlocks + i + 1, osl_vramBlocks + i, sizeof(OSL_VRAMBLOCK) * (osl_vramBlocksNb - i - 1));

		//Remplissons notre nouveau bloc
		setBlockSize(i, blockSize);
		//Il a l'adresse du bloc qui était là avant
		setBlockOffset(i, getBlockOffset(i + 1));
		//Il n'est pas libre
		setBlockFree(i, 0);

		//Pour le prochain, sa taille diminue
		setBlockSize(i + 1, getBlockSize(i + 1) - blockSize);
		//ATTENTION: calcul d'offset
		setBlockOffset(i + 1, getBlockOffset(i + 1) + blockSize);
	}

	//Note: il faut traduire l'offset en vraie adresse
	return (void*)(getBlockOffset(i) + osl_vramBase);
}
Esempio n. 16
0
File: block.cpp Progetto: xzblh/fs
void readBlock(BLOCK * blockP, void * mem)
{
	fseek(dataFp, getBlockOffset(blockP->blockNumber), SEEK_SET);
	fread(mem, superBlockPointer->blockSize, 1, dataFp);
}