예제 #1
0
static void queueExtension()
{
	int *newQueue;
	int startPos;

	newQueue = (int*)malloc(sizeof(int)* 2 * capacity);

	if (!newQueue)
		return;

	startPos = (front + 1) % capacity;

	if (startPos < 2)
		copyBlock(queue+startPos,queue+startPos+capacity-1,newQueue);
	else{
		copyBlock(queue + startPos, queue + capacity, newQueue);
		copyBlock(queue, queue + rear + 1, newQueue + capacity - startPos);
	}

	front = 2 * capacity - 1;
	rear = capacity - 2;
	capacity *= 2;
	
	free(queue);
	queue = newQueue;
}
예제 #2
0
void PtexWriterBase::writeFaceData(FILE* fp, const void* data, int stride,
				   Res res, FaceDataHeader& fdh)
{
    // determine whether to break into tiles
    Res tileres = calcTileRes(res);
    int ntilesu = res.ntilesu(tileres);
    int ntilesv = res.ntilesv(tileres);
    int ntiles = ntilesu * ntilesv;
    if (ntiles == 1) {
	// write single block
	writeFaceBlock(fp, data, stride, res, fdh);
    } else {
	// write tiles to tilefp temp file
	rewind(_tilefp);

	// alloc tile header
	std::vector<FaceDataHeader> tileHeader(ntiles);
	int tileures = tileres.u();
	int tilevres = tileres.v();
	int tileustride = tileures*_pixelSize;
	int tilevstride = tilevres*stride;

	// output tiles
	FaceDataHeader* tdh = &tileHeader[0];
	int datasize = 0;
	const char* rowp = (const char*) data;
	const char* rowpend = rowp + ntilesv * tilevstride;
	for (; rowp != rowpend; rowp += tilevstride) {
	    const char* p = rowp;
	    const char* pend = p + ntilesu * tileustride;
	    for (; p != pend; tdh++, p += tileustride) {
		// determine if tile is constant
		if (PtexUtils::isConstant(p, stride, tileures, tilevres, _pixelSize))
		    writeConstFaceBlock(_tilefp, p, *tdh);
		else
		    writeFaceBlock(_tilefp, p, stride, tileres, *tdh);
		datasize += tdh->blocksize();
	    }
	}

	// output compressed tile header
	uint32_t tileheadersize = writeZipBlock(_tilefp, &tileHeader[0],
						int(sizeof(FaceDataHeader)*tileHeader.size()));


	// output tile data pre-header
	int totalsize = 0;
	totalsize += writeBlock(fp, &tileres, sizeof(Res));
	totalsize += writeBlock(fp, &tileheadersize, sizeof(tileheadersize));

	// copy compressed tile header from temp file
	totalsize += copyBlock(fp, _tilefp, datasize, tileheadersize);

	// copy tile data from temp file
	totalsize += copyBlock(fp, _tilefp, 0, datasize);

	fdh.set(totalsize, enc_tiled);
    }
}
예제 #3
0
void copyGeneral(void){
  if (MW_has_mouse_pointer())
    copySelectedMixerObjects();
  else if (SEQUENCER_has_mouse_pointer())
    copySelectedSeqblocks();
  else
    copyBlock(-1);
}
예제 #4
0
QSharedPointer<RBlock> RClipboardOperation::copyEntityBlock(
    REntity& entity,
    RDocument& src,
    RDocument& dest,
    bool overwriteBlocks,
    bool toCurrentBlock,
    const QString& blockName,
    RTransaction& transaction) const {

    return copyBlock(entity.getBlockId(), src, dest, overwriteBlocks, toCurrentBlock, blockName, transaction);
}
예제 #5
0
unsigned int path_to_inum(int fd, std::vector<std::string>& path, int inum, int pathPos) {
	//dout << path << " " << inum << std::endl;
	//Get the first directory name in the path
	char delim = '/';
	std::string dir;
	if(pathPos < path.size()) {
		//Read the inode which represents a directory
		//and look for a file whose name matches dir
		dir = path[pathPos];
		char buffer[BLOCK_SIZE] = {};
		unsigned int block = 0;
		ByteAndBlock* rtnVal;
		rtnVal = copyBlock(fd, inum, block); 
		lseek(fd, rtnVal->block * BLOCK_SIZE, SEEK_SET);
		read(fd, buffer, BLOCK_SIZE);

		while(rtnVal->bytesRead > 0) {
			for(int offset = 0; offset < rtnVal->bytesRead; offset += DIR_SIZE) {
				std::string name(buffer + offset + sizeof(unsigned int), DIR_SIZE - sizeof(unsigned int));
				if(stringEquals(dir, name)) {
					delete rtnVal;
					return path_to_inum(fd, path, read_long(buffer + offset, sizeof(int)), pathPos + 1);
				}

			}
			delete rtnVal;

			rtnVal = copyBlock(fd, inum, block++); 
			lseek(fd, rtnVal->block * BLOCK_SIZE, SEEK_SET);
			read(fd, buffer, BLOCK_SIZE);
		}
		delete rtnVal;
		return -1;
	} else {
		return inum;
	}

}
예제 #6
0
파일: hw2.c 프로젝트: dayomi/Homework-1
void BufRead(int blkno, void* pData)
{
	Buf* pBuf;

	pBuf = BufFind(blkno);
	if( pBuf != NULL )
	{
		removeLru(blkno);
		insertLru(pBuf);
		copyBlock((char*)pBuf->pMem, (char*)pData);
		return;
	}

	pBuf = popFree();
	pBuf->blkno = blkno;
	//pBuf->pMem = (void*)malloc(BLOCK_SIZE);
	DevReadBlock(blkno, (char*)pBuf->pMem);
	insertHash(pBuf);
	insertClean(pBuf);
	removeLru(blkno);
	insertLru(pBuf);

	copyBlock((char*)pBuf->pMem, (char*)pData);
}
예제 #7
0
파일: hw2.c 프로젝트: dayomi/Homework-1
void BufWrite(int blkno, void* pData)
{
	Buf* pBuf;

	pBuf = BufFind(blkno);
	if( pBuf == NULL )
	{
		char ptr_tmp_data[BLOCK_SIZE];
		BufRead(blkno, ptr_tmp_data);
		pBuf = BufFind(blkno);
	}

	removeClean(blkno);
	if( ! existDirty(blkno) )
	{
		insertDirty(pBuf);
	}
	removeLru(blkno);
	insertLru(pBuf);

	copyBlock((char*)pData, (char*)pBuf->pMem);
}
예제 #8
0
void PtexMainWriter::finish()
{
    // do nothing if there's no new data to write
    if (!_hasNewData) return;

    // copy missing faces from _reader
    if (_reader) {
	for (int i = 0, nfaces = _header.nfaces; i < nfaces; i++) {
	    if (_faceinfo[i].flags == uint8_t(-1)) {
		// copy face data
                const Ptex::FaceInfo& info = _reader->getFaceInfo(i);
                int size = _pixelSize * info.res.size();
                if (info.isConstant()) {
                    PtexPtr<PtexFaceData> data ( _reader->getData(i) );
                    if (data) {
                        writeConstantFace(i, info, data->getData());
                    }
                } else {
                    void* data = malloc(size);
                    _reader->getData(i, data, 0);
                    writeFace(i, info, data, 0);
                    free(data);
                }
	    }
	}
    }
    else {
	// just flag missing faces as constant (black)
	for (int i = 0, nfaces = _header.nfaces; i < nfaces; i++) {
	    if (_faceinfo[i].flags == uint8_t(-1))
		_faceinfo[i].flags = FaceInfo::flag_constant;
	}
    }

    // write reductions to tmp file
    if (_genmipmaps)
	generateReductions();

    // flag faces w/ constant neighborhoods
    flagConstantNeighorhoods();

    // update header
    _header.nlevels = uint16_t(_levels.size());
    _header.nfaces = uint32_t(_faceinfo.size());

    // create new file
    FILE* newfp = fopen(_newpath.c_str(), "wb+");
    if (!newfp) {
	setError(fileError("Can't write to ptex file: ", _newpath.c_str()));
	return;
    }

    // write blank header (to fill in later)
    writeBlank(newfp, HeaderSize);
    writeBlank(newfp, ExtHeaderSize);

    // write compressed face info block
    _header.faceinfosize = writeZipBlock(newfp, &_faceinfo[0],
					 sizeof(FaceInfo)*_header.nfaces);

    // write compressed const data block
    _header.constdatasize = writeZipBlock(newfp, &_constdata[0], int(_constdata.size()));

    // write blank level info block (to fill in later)
    FilePos levelInfoPos = ftello(newfp);
    writeBlank(newfp, LevelInfoSize * _header.nlevels);

    // write level data blocks (and record level info)
    std::vector<LevelInfo> levelinfo(_header.nlevels);
    for (int li = 0; li < _header.nlevels; li++)
    {
	LevelInfo& info = levelinfo[li];
	LevelRec& level = _levels[li];
	int nfaces = int(level.fdh.size());
	info.nfaces = nfaces;
	// output compressed level data header
	info.levelheadersize = writeZipBlock(newfp, &level.fdh[0],
					     sizeof(FaceDataHeader)*nfaces);
	info.leveldatasize = info.levelheadersize;
	// copy level data from tmp file
	for (int fi = 0; fi < nfaces; fi++)
	    info.leveldatasize += copyBlock(newfp, _tmpfp, level.pos[fi],
					    level.fdh[fi].blocksize());
	_header.leveldatasize += info.leveldatasize;
    }
    rewind(_tmpfp);

    // write meta data (if any)
    if (!_metadata.empty())
	writeMetaData(newfp);

    // update extheader for edit data position
    _extheader.editdatapos = ftello(newfp);

    // rewrite level info block
    fseeko(newfp, levelInfoPos, SEEK_SET);
    _header.levelinfosize = writeBlock(newfp, &levelinfo[0], LevelInfoSize*_header.nlevels);

    // rewrite header
    fseeko(newfp, 0, SEEK_SET);
    writeBlock(newfp, &_header, HeaderSize);
    writeBlock(newfp, &_extheader, ExtHeaderSize);
    fclose(newfp);
}
예제 #9
0
void PtexMainWriter::writeMetaData(FILE* fp)
{
    std::vector<MetaEntry*> lmdEntries; // large meta data items

    // write small meta data items in a single zip block
    for (int i = 0, n = _metadata.size(); i < n; i++) {
	MetaEntry& e = _metadata[i];
#ifndef PTEX_NO_LARGE_METADATA_BLOCKS
	if (int(e.data.size()) > MetaDataThreshold) {
	    // skip large items, but record for later
	    lmdEntries.push_back(&e);
	}
	else 
#endif
    {
	    // add small item to zip block
	    _header.metadatamemsize += writeMetaDataBlock(fp, e);
	}
    }
    if (_header.metadatamemsize) {
	// finish zip block
	_header.metadatazipsize = writeZipBlock(fp, 0, 0, /*finish*/ true);
    }

    // write compatibility barrier
    writeBlank(fp, sizeof(uint64_t));

    // write large items as separate blocks
    int nLmd = lmdEntries.size();
    if (nLmd > 0) {
	// write data records to tmp file and accumulate zip sizes for lmd header
	std::vector<FilePos> lmdoffset(nLmd);
	std::vector<uint32_t> lmdzipsize(nLmd);
	for (int i = 0; i < nLmd; i++) {
	    MetaEntry* e= lmdEntries[i];
	    lmdoffset[i] = ftello(_tmpfp);
	    lmdzipsize[i] = writeZipBlock(_tmpfp, &e->data[0], e->data.size());
	}

	// write lmd header records as single zip block
	for (int i = 0; i < nLmd; i++) {
	    MetaEntry* e = lmdEntries[i];
	    uint8_t keysize = uint8_t(e->key.size()+1);
	    uint8_t datatype = e->datatype;
	    uint32_t datasize = e->data.size();
	    uint32_t zipsize = lmdzipsize[i];

	    writeZipBlock(fp, &keysize, sizeof(keysize), false);
	    writeZipBlock(fp, e->key.c_str(), keysize, false);
	    writeZipBlock(fp, &datatype, sizeof(datatype), false);
	    writeZipBlock(fp, &datasize, sizeof(datasize), false);
	    writeZipBlock(fp, &zipsize, sizeof(zipsize), false);
	    _extheader.lmdheadermemsize +=
		sizeof(keysize) + keysize + sizeof(datatype) + sizeof(datasize) + sizeof(zipsize);
	}
	_extheader.lmdheaderzipsize = writeZipBlock(fp, 0, 0, /*finish*/ true);

	// copy data records
	for (int i = 0; i < nLmd; i++) {
	    _extheader.lmddatasize +=
		copyBlock(fp, _tmpfp, lmdoffset[i], lmdzipsize[i]);
	}
    }
}
예제 #10
0
bool MsCabinet::Decompressor::decompressFile(byte *&fileBuf, const FileEntry &entry) {
#ifdef USE_ZLIB
	// Ref: http://blogs.kde.org/node/3181
	uint32 cksum, cksum2;
	uint16 uncompressedLen, compressedLen;
	byte hdrS[4];
	byte *buf_tmp, *dict;
	bool decRes;

	//Sanity checks
	if (!_compressedBlock || entry.folder != _curFolder)
		return false;

	_startBlock = entry.folderOffset / kCabBlockSize;
	_inBlockStart = entry.folderOffset % kCabBlockSize;
	_endBlock = (entry.folderOffset + entry.length) / kCabBlockSize;
	_inBlockEnd = (entry.folderOffset + entry.length) % kCabBlockSize;

	//Check if the decompressor should be reinitialized
	if (_curBlock > _startBlock || _curBlock == -1) {
		_data->seek(entry.folder->offset);
		//Check the compression method (only mszip supported)
		if (entry.folder->comp_type != kMszipCompression)
			return false;

		_curBlock = -1;		//No block decompressed
	}

	//Check if the file is contained in the folder
	if ((entry.length + entry.folderOffset) / kCabBlockSize > entry.folder->num_blocks)
		return false;

	_fileBuf = new byte[entry.length];
	if (!_fileBuf)
		return false;

	buf_tmp = _fileBuf;

	//if a part of this file has been decompressed in the last block, make a copy of it
	copyBlock(buf_tmp);

	while((_curBlock + 1) <= _endBlock) {
		// Read the CFDATA header
		cksum = _data->readUint32LE();
		_data->read(hdrS, 4);
		compressedLen = READ_LE_UINT16(hdrS);
		uncompressedLen = READ_LE_UINT16(hdrS + 2);

		if (_data->err())
			return false;

		if (compressedLen > kCabInputmax || uncompressedLen > kCabBlockSize)
			return false;

		//Read the compressed block
		if (_data->read(_compressedBlock, compressedLen) != compressedLen)
			return false;

		//Perform checksum test on the block (if one is stored)
		if (cksum != 0) {
			cksum2 = checksum(_compressedBlock, compressedLen, 0);
			if (checksum(hdrS, 4, cksum2) != cksum)
				return false;
		}

		//Check the CK header
		if (_compressedBlock[0] != 'C' || _compressedBlock[1] != 'K')
			return false;

		//Decompress the block. If it isn't the first, provide the previous block as dictonary
		dict = (_curBlock >= 0) ? _decompressedBlock : 0;
		decRes = Common::inflateZlibHeaderless(_decompressedBlock, uncompressedLen, _compressedBlock + 2, compressedLen - 2, dict, kCabBlockSize);
		if (!decRes)
			return false;

		_curBlock++;

		//Copy the decompressed data, if needed
		copyBlock(buf_tmp);
	}

	fileBuf = _fileBuf;
	_fileBuf = 0;
	return true;
#else
	warning("zlib required to extract MSCAB");
	return false;
#endif
}
예제 #11
0
파일: archive.c 프로젝트: 99years/plan9
static int
archWalk(Param *p, u32int addr, uchar type, u32int tag)
{
	int ret, i, x, psize, dsize;
	uchar *data, score[VtScoreSize];
	Block *b;
	Label l;
	Entry *e;
	WalkPtr w;

	p->nvisit++;

	b = cacheLocalData(p->c, addr, type, tag, OReadWrite,0);
	if(b == nil){
		fprint(2, "archive(%ud, %#ux): cannot find block: %R\n", p->snapEpoch, addr);
		if(strcmp(vtGetError(), ELabelMismatch) == 0){
			/* might as well plod on so we write _something_ to Venti */
			memmove(p->score, vtZeroScore, VtScoreSize);
			return ArchFaked;
		}
		return ArchFailure;
	}

	if(DEBUG) fprint(2, "%*sarchive(%ud, %#ux): block label %L\n",
		p->depth*2, "",  p->snapEpoch, b->addr, &b->l);
	p->depth++;
	if(p->depth > p->maxdepth)
		p->maxdepth = p->depth;

	data = b->data;
	if((b->l.state&BsVenti) == 0){
		initWalk(&w, b, b->l.type==BtDir ? p->dsize : p->psize);
		for(i=0; nextWalk(&w, score, &type, &tag, &e); i++){
			if(e){
				if(!(e->flags&VtEntryActive))
					continue;
				if((e->snap && !e->archive)
				|| (e->flags&VtEntryNoArchive)){
					if(0) fprint(2, "snap; faking %#ux\n", b->addr);
					if(data == b->data){
						data = copyBlock(b, p->blockSize);
						if(data == nil){
							ret = ArchFailure;
							goto Out;
						}
						w.data = data;
					}
					memmove(e->score, vtZeroScore, VtScoreSize);
					e->depth = 0;
					e->size = 0;
					e->tag = 0;
					e->flags &= ~VtEntryLocal;
					entryPack(e, data, w.n-1);
					continue;
				}
			}
			addr = globalToLocal(score);
			if(addr == NilBlock)
				continue;
			dsize = p->dsize;
			psize = p->psize;
			if(e){
				p->dsize= e->dsize;
				p->psize = e->psize;
			}
			vtUnlock(b->lk);
			x = archWalk(p, addr, type, tag);
			vtLock(b->lk);
			if(e){
				p->dsize = dsize;
				p->psize = psize;
			}
			while(b->iostate != BioClean && b->iostate != BioDirty)
				vtSleep(b->ioready);
			switch(x){
			case ArchFailure:
				fprint(2, "archWalk %#ux failed; ptr is in %#ux offset %d\n",
					addr, b->addr, i);
				ret = ArchFailure;
				goto Out;
			case ArchFaked:
				/*
				 * When we're writing the entry for an archive directory
				 * (like /archive/2003/1215) then even if we've faked
				 * any data, record the score unconditionally.
				 * This way, we will always record the Venti score here.
				 * Otherwise, temporary data or corrupted file system
				 * would cause us to keep holding onto the on-disk
				 * copy of the archive.
				 */
				if(e==nil || !e->archive)
				if(data == b->data){
if(0) fprint(2, "faked %#ux, faking %#ux (%V)\n", addr, b->addr, p->score);
					data = copyBlock(b, p->blockSize);
					if(data == nil){
						ret = ArchFailure;
						goto Out;
					}
					w.data = data;
				}
				/* fall through */
if(0) fprint(2, "falling\n");
			case ArchSuccess:
				if(e){
					memmove(e->score, p->score, VtScoreSize);
					e->flags &= ~VtEntryLocal;
					entryPack(e, data, w.n-1);
				}else
					memmove(data+(w.n-1)*VtScoreSize, p->score, VtScoreSize);
				if(data == b->data){
					blockDirty(b);
					/*
					 * If b is in the active tree, then we need to note that we've
					 * just removed addr from the active tree (replacing it with the 
					 * copy we just stored to Venti).  If addr is in other snapshots,
					 * this will close addr but not free it, since it has a non-empty
					 * epoch range.
					 *
					 * If b is in the active tree but has been copied (this can happen
					 * if we get killed at just the right moment), then we will
					 * mistakenly leak its kids.  
					 *
					 * The children of an archive directory (e.g., /archive/2004/0604)
					 * are not treated as in the active tree.
					 */
					if((b->l.state&BsCopied)==0 && (e==nil || e->snap==0))
						blockRemoveLink(b, addr, p->l.type, p->l.tag, 0);
				}
				break;
			}
		}

		if(!ventiSend(p->a, b, data)){
			p->nfailsend++;
			ret = ArchFailure;
			goto Out;
		}
		p->nsend++;
		if(data != b->data)
			p->nfake++;
		if(data == b->data){	/* not faking it, so update state */
			p->nreal++;
			l = b->l;
			l.state |= BsVenti;
			if(!blockSetLabel(b, &l, 0)){
				ret = ArchFailure;
				goto Out;
			}
		}
	}

	shaBlock(p->score, b, data, p->blockSize);
if(0) fprint(2, "ventisend %V %p %p %p\n", p->score, data, b->data, w.data);
	ret = data!=b->data ? ArchFaked : ArchSuccess;
	p->l = b->l;
Out:
	if(data != b->data)
		vtMemFree(data);
	p->depth--;
	blockPut(b);
	return ret;
}
예제 #12
0
void console_start() {
	char **parameters;
	char command[512];
	int exit = 0;

	strcpy(currentDirPrompt, "/");
	strcpy(currentDirId, ROOT_DIR_ID);

	do {
		printf("%s > ", currentDirPrompt);
		readCommand(command);
		// El trim de las commons tira error a veces.. string_trim(&command);

		// Ignore empty enter
		if (command[0] != '\0') {
			parameters = string_split(command, " ");

			if (string_equals_ignore_case(parameters[0], "format")) {
				format();
			} else if (string_equals_ignore_case(parameters[0], "df")) {
				diskFree();
			} else if (string_equals_ignore_case(parameters[0], "rm")) {
				deleteResource(parameters);
			} else if (string_equals_ignore_case(parameters[0], "mv")) {
				moveResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "rename")) {
				renameResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "mkdir")) {
				makeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cd")) {
				changeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "ll")) {
				listResources();
			} else if (string_equals_ignore_case(parameters[0], "md5sum")) {
				md5sum(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cp")) {
				copyFile(parameters);
			} else if (string_equals_ignore_case(parameters[0], "blocks")) {
				printFileBlocks(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "catb")) {
				saveBlockContents(parameters);
			} else if (string_equals_ignore_case(parameters[0], "cpb")) {
				copyBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "rmb")) {
				deleteBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "nodestat")) {
				printNodeStatus(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "enablen")) {
				enableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "disablen")) {
				disableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "help")) {
				help();
			} else if (string_equals_ignore_case(parameters[0], "exit")) {
				exit = 1;
			} else if (string_equals_ignore_case(parameters[0], "\n")) {
				// ignore enter
			} else {
				printf("Invalid command \n");
			}
			freeSplits(parameters);
		}
	} while (!exit);

	printf("bye\n");
}
예제 #13
0
파일: blocks.c 프로젝트: abarisain/dtris
blockDescriptor* randomBlock() {
	blockDescriptor* block = copyBlock(blocks[randInt(0,7)]);
	block->currentRotation = randInt(0, 4);
	return block;
}