void PtexIncrWriter::writeMetaDataEdit() { // init headers uint8_t edittype = et_editmetadata; uint32_t editsize; EditMetaDataHeader emdh; emdh.metadatazipsize = 0; emdh.metadatamemsize = 0; // record position and skip headers FilePos pos = ftello(_fp); writeBlank(_fp, sizeof(edittype) + sizeof(editsize) + sizeof(emdh)); // write meta data for (int i = 0, n = _metadata.size(); i < n; i++) { MetaEntry& e = _metadata[i]; emdh.metadatamemsize += writeMetaDataBlock(_fp, e); } // finish zip block emdh.metadatazipsize = writeZipBlock(_fp, 0, 0, /*finish*/ true); // update headers editsize = sizeof(emdh) + emdh.metadatazipsize; // rewind and write headers fseeko(_fp, pos, SEEK_SET); writeBlock(_fp, &edittype, sizeof(edittype)); writeBlock(_fp, &editsize, sizeof(editsize)); writeBlock(_fp, &emdh, sizeof(emdh)); fseeko(_fp, 0, SEEK_END); }
void Decompiler::writeIfControl(Common::WriteStream &out, const ControlStructure &control, size_t indent) { writeIndent(out, indent); const Variable *cond = control.ifCond->instructions.back()->variables[0]; out.writeString("if ("); out.writeString(formatVariableName(cond)); out.writeString(") {\n"); if (control.ifTrue) writeBlock(out, control.ifTrue, indent + 1); writeIndent(out, indent); out.writeString("}"); if (control.ifElse) { out.writeString(" else {\n"); writeBlock(out, control.ifElse, indent + 1); writeIndent(out, indent); out.writeString("}"); } out.writeString("\n"); if (control.ifNext) writeBlock(out, control.ifNext, indent); }
/** * Menuliskan isi buffer ke filesystem * @param position * @param buffer * @param size * @param offset * @return */ int POI::writeBlock(Block position, const char *buffer, int size, int offset) { /* kalau sudah di END_BLOCK, return */ if (position == END_BLOCK) { return 0; } /* kalau offset >= BLOCK_SIZE */ if (offset >= BLOCK_SIZE) { /* kalau nextBlock tidak ada, alokasikan */ if (nextBlock[position] == END_BLOCK) { setNextBlock(position, allocateBlock()); } return writeBlock(nextBlock[position], buffer, size, offset - BLOCK_SIZE); } file.seekp(BLOCK_SIZE * DATA_POOL_OFFSET + position * BLOCK_SIZE + offset); int size_now = size; if (offset + size_now > BLOCK_SIZE) { size_now = BLOCK_SIZE - offset; } file.write(buffer, size_now); /* kalau size > block size, lanjutkan di nextBlock */ if (offset + size > BLOCK_SIZE) { /* kalau nextBlock tidak ada, alokasikan */ if (nextBlock[position] == END_BLOCK) { setNextBlock(position, allocateBlock()); } return size_now + writeBlock(nextBlock[position], buffer + BLOCK_SIZE, offset + size - BLOCK_SIZE); } return size_now; }
void putBytes(const uchar* buf, int count) { uchar* data = (uchar*)buf; CV_Assert(m_f && data && m_current && count >= 0); if( m_current >= m_end ) writeBlock(); while( count ) { int l = (int)(m_end - m_current); if (l > count) l = count; if( l > 0 ) { memcpy(m_current, data, l); m_current += l; data += l; count -= l; } if( m_current >= m_end ) writeBlock(); } }
int tfs_mkfs(char *filename, int nBytes){ int i, diskNum; char* templateBlk = calloc(1, BLOCKSIZE); templateBlk[0] = 4; templateBlk[1] = 0x45; diskNum = openDisk(filename, nBytes); if(diskNum < 0) return ERR_MKDSK; for(i = 0; i < BLOCKSIZE; i++) writeBlock(diskNum, i, templateBlk); /* SUPER BLOCK */ templateBlk[0] = 1; templateBlk[2] = 1; writeBlock(diskNum, 0, templateBlk); if(DEBUG) printf("Made File System with super block\n"); free(templateBlk); close(diskNum); return 1; }
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); } }
PaqDir * paqFile(char *name, Dir *dir) { int fd, n, nn, nb; vlong tot; uchar *block, *pointer; ulong offset; fd = open(name, OREAD); if(fd < 0) { warn("could not open file: %s: %r", name); return nil; } block = emallocz(blocksize); pointer = emallocz(blocksize); nb = 0; n = 0; tot = 0; for(;;) { nn = read(fd, block+n, blocksize-n); if(nn < 0) { warn("read failed: %s: %r", name); goto Err; } tot += nn; if(nn == 0) { if(n == 0) break; /* pad out last block */ memset(block+n, 0, blocksize-n); nn = blocksize - n; } n += nn; if(n < blocksize) continue; if(nb >= blocksize/OffsetSize) { warn("file too big for blocksize: %s", name); goto Err; } offset = writeBlock(block, DataBlock); putl(pointer+nb*OffsetSize, offset); nb++; n = 0; } offset = writeBlock(pointer, PointerBlock); close(fd); free(pointer); free(block); dir->length = tot; return paqDirAlloc(dir, offset); Err: close(fd); free(pointer); free(block); return nil; }
const int MemBlockDevice::SaveFile(const std::string & data, FileHeader& file, int blocknr) { for (int i = 0; i < file.nrofblocks; i++) { FreeMemoryBlock(file.blockPointers[i]); } if (file.nrofblocks > 0) file.blockPointers = 0; file.size = data.size(); file.nrofblocks = (file.size / blocksize) + ((file.size % blocksize) ? 1 : 0); if(file.nrofblocks > 0) file.blockPointers = new int[file.nrofblocks]; for (int i = 0; i < file.nrofblocks; i++) { file.blockPointers[i] = GetNextFreeBlock(); if (file.blockPointers[i] == -1) { return -1; } } int err = writeBlock(blocknr, (char*)&file, sizeof(int)*4, 0 ); if (err != 1) { return -1; } err = writeBlock(blocknr, file.name.c_str(), file.namesize, sizeof(int) * 4); if (err != 1) { return -1; } err = writeBlock(blocknr, (char*)file.blockPointers, sizeof(int)*file.nrofblocks, sizeof(int) * 4 + file.namesize); if (err != 1) { return -1; } int size = file.size; for (int i = 0; i < file.nrofblocks; i++) { int s = (size < blocksize) ? size%blocksize : blocksize; int err = writeBlock(file.blockPointers[i], (data.c_str() + i*blocksize), s, 0); if (err != 1) { return -1; } size -= blocksize; } return 1; }
char testFunctionCallback(float seconds, float frequency) { MMRESULT result; HWAVEOUT waveOut; result = waveOutOpen(&waveOut, WAVE_MAPPER, &waveFormat, (DWORD_PTR)&waveOutCallback, 0, CALLBACK_FUNCTION); if(result != MMSYSERR_NOERROR) { printf("waveOutOpen failed (result=%d)\n", result); return 1; } printf("[tid=%d] Opened Wave Mapper!\n", GetCurrentThreadId()); fflush(stdout); waitForKey("to start rendering sound"); DWORD sampleCount = seconds * waveFormat.nSamplesPerSec; LPSTR block1 = allocateBlock(sampleCount); LPSTR block2 = allocateBlock(sampleCount); fillSinWave(block1, frequency, sampleCount); fillSinWave(block2, frequency * 1.5, sampleCount); printf("Writing block (0x%p)...\n", block1); fflush(stdout); { WAVEHDR header1; WAVEHDR header2; ZeroMemory(&header1, sizeof(WAVEHDR)); header1.dwBufferLength = sampleCount * waveFormat.nBlockAlign; header1.lpData = block1; writeBlock(waveOut, &header1); ZeroMemory(&header2, sizeof(WAVEHDR)); header2.dwBufferLength = sampleCount * waveFormat.nBlockAlign; header2.lpData = block2; writeBlock(waveOut, &header2); } waitForKey("to close"); waveOutClose(waveOut); return 0; }
void format(char * device) { FILE *floppy; unsigned int totalBlocks,FsBegin, fsBlockSize, index; int blockNumber; UnusedBlock lastFreeBlock; DirectoryBlock rootDirectory; SuperBlock superBlock; floppy = fopen(device, "rw+"); if(floppy==0){ printf("floppy.img not found\n"); return; } fseek(floppy, 0, SEEK_END); totalBlocks = ftell(floppy)/BLOCKSIZE; fseek(floppy, BLOCKSIZE*FsStart,SEEK_SET); FsBegin = ftell(floppy)/BLOCKSIZE; fsBlockSize = totalBlocks - FsBegin; index = FsBegin - 1; superBlock.magicNumber = MAGICNUMBER; superBlock.totalBlocksInDisk = totalBlocks; superBlock.totalFreeBlocks = superBlock.totalBlocksInDisk - 3; superBlock.firstFreeBlock = 3; superBlock.lastFreeBlock = superBlock.totalBlocksInDisk -1; for(blockNumber = superBlock.firstFreeBlock; blockNumber < superBlock.lastFreeBlock;blockNumber++) { UnusedBlock freeBlock; freeBlock.nextFreeBlock = blockNumber + 1; writeBlock(floppy, blockNumber, &freeBlock); } lastFreeBlock.nextFreeBlock=0; writeBlock(floppy, superBlock.lastFreeBlock, &lastFreeBlock); rootDirectory = createEmptyDirectory(); writeBlock(floppy, ROOTBLOCK, &rootDirectory); writeBlock(floppy, SUPERBLOCK,&superBlock); }
void VirtualComponent::saveToBuffer(uint8_t **buffer) { uint8_t *old = *buffer; debug(3, " Saving internal state (%d bytes) ...\n", VirtualComponent::stateSize()); // Save internal state of sub components if (subComponents != NULL) { for (unsigned i = 0; subComponents[i] != NULL; i++) subComponents[i]->saveToBuffer(buffer); } // Save own internal state void *data; size_t size; int flags; for (unsigned i = 0; snapshotItems != NULL && snapshotItems[i].data != NULL; i++) { data = snapshotItems[i].data; flags = snapshotItems[i].flags & 0x0F; size = snapshotItems[i].size; if (flags == 0) { // Auto detect size switch (snapshotItems[i].size) { case 1: write8(buffer, *(uint8_t *)data); break; case 2: write16(buffer, *(uint16_t *)data); break; case 4: write32(buffer, *(uint32_t *)data); break; case 8: write64(buffer, *(uint64_t *)data); break; default: writeBlock(buffer, (uint8_t *)data, size); } } else { // Format is specified manually switch (flags) { case BYTE_FORMAT: writeBlock(buffer, (uint8_t *)data, size); break; case WORD_FORMAT: writeBlock16(buffer, (uint16_t *)data, size); break; case DOUBLE_WORD_FORMAT: writeBlock32(buffer, (uint32_t *)data, size); break; case QUAD_WORD_FORMAT: writeBlock64(buffer, (uint64_t *)data, size); break; default: assert(0); } } } if (*buffer - old != VirtualComponent::stateSize()) { panic("saveToBuffer: Snapshot size is wrong."); assert(false); } }
void chunkArchive::writeString(const char *s) { do_tagging(CHUNK_STRING); unsigned long size = strlen(s) + 1; writeLong(size); writeBlock((const char *) s, size); }
int PtexWriterBase::writeZipBlock(FILE* fp, const void* data, int size, bool finish) { if (!_ok) return 0; void* buff = alloca(BlockSize); _zstream.next_in = (Bytef*)data; _zstream.avail_in = size; while (1) { _zstream.next_out = (Bytef*)buff; _zstream.avail_out = BlockSize; int zresult = deflate(&_zstream, finish ? Z_FINISH : Z_NO_FLUSH); int size = BlockSize - _zstream.avail_out; if (size > 0) writeBlock(fp, buff, size); if (zresult == Z_STREAM_END) break; if (zresult != Z_OK) { setError("PtexWriter error: data compression internal error"); break; } if (!finish && _zstream.avail_out != 0) // waiting for more input break; } if (!finish) return 0; int total = _zstream.total_out; deflateReset(&_zstream); return total; }
//FIFO void FIFO(BM_BufferPool *const bm, Structure_Details *node) { int i=0; int prev = n%buffpg_size; sd = (Structure_Details *) bm->mgmtData; while(i<buffpg_size) // checks if the page size is greater than 0 { if(sd[prev].fixedcount == 0) { if(sd[prev].dirtyPage == 1) // checks if dirtypage is present and writes it to the disk { openPageFile (bm->pageFile, &fh); writeBlock (sd[prev].pagenum, &fh, sd[prev].data); writeIO++; } sd[prev].data = node->data; sd[prev].pagenum = node->pagenum; sd[prev].dirtyPage = node->dirtyPage; sd[prev].fixedcount = node->fixedcount; break; } else { prev++; if(prev%buffpg_size == 0) prev=0; } i++; } }
void Buffer::closeFile(string& dbName, string& fileName, int fileType){ FileInfo* tempFile = fileHead->firstFile; FileInfo* oldFile = NULL; while (tempFile){ if ((tempFile->fileName == fileName) && (tempFile->type == fileType)){ BlockInfo* tempBlock = tempFile->firstBlock; BlockInfo* oldBlock = NULL; while (tempBlock){ oldBlock = tempBlock; tempBlock = tempBlock->next; if (oldBlock->dirtyBit) writeBlock(dbName, oldBlock); fileHead->fileNum--; //delete oldBlock; //在哪分配就在哪释放 } if (oldFile) oldFile->next = tempFile->next; else fileHead->firstFile = tempFile->next; delete tempFile; fileHead->fileNum--; break; } else{ oldFile = tempFile; tempFile = tempFile->next; } } }
int QFile::putch( int ch ) { #if defined(CHECK_STATE) if ( !isOpen() ) { // file not open warning( "QFile::putch: File not open" ); return EOF; } if ( !isWritable() ) { // writing not permitted warning( "QFile::putch: Write operation not permitted" ); return EOF; } #endif if ( isRaw() ) { // raw file (inefficient) char buf[1]; buf[0] = ch; ch = writeBlock( buf, 1 ) == 1 ? ch : EOF; } else { // buffered file if ( (ch = putc( ch, fh )) != EOF ) { index++; if ( index > length ) // update file length length = index; } else { setStatus(IO_WriteError); } } return ch; }
int QFile::ungetch( int ch ) { #if defined(CHECK_STATE) if ( !isOpen() ) { // file not open warning( "QFile::ungetch: File not open" ); return EOF; } if ( !isReadable() ) { // reading not permitted warning( "QFile::ungetch: Read operation not permitted" ); return EOF; } #endif if ( ch == EOF ) // cannot unget EOF return ch; if ( isRaw() ) { // raw file (very inefficient) char buf[1]; at( index-1 ); buf[0] = ch; if ( writeBlock(buf, 1) == 1 ) at ( index-1 ); else ch = EOF; } else { // buffered file if ( (ch = ungetc(ch, fh)) != EOF ) index--; else setStatus( IO_ReadError ); } return ch; }
/************************************************************************************** * Function Name: forceFlushPool * * Description: * Clear the data in the buffer pool * * Parameters: * BM_BufferPool *const bm: buffer pool that need to clear the data. * * Return: * RC: return code * * Author: * Chengnan Zhao <*****@*****.**> * * History: * Date Name Content * ---------- -------------------------------------- ------------------------ * 2015-03-14 Chengnan Zhao <*****@*****.**> Initialization * 2015-03-20 Xin Su <*****@*****.**> Modify the PageList queue * Add comments * Add judgment of the rc returned by writeBlock **************************************************************************************/ RC forceFlushPool(BM_BufferPool * const bm) { PageList *queue = (PageList *) bm->mgmtData; RC rc; queue->current = queue->head; // The loop ends when the current pointer points to the next to the tail (NULL) while (queue->current != NULL && queue->current->dirtyFlag == TRUE) { // if the page is dirty, write it back to the disk rc = -99; rc = writeBlock(queue->current->page->pageNum, F_HANDLE, queue->current->page->data); if (rc != RC_OK) { return rc; } // Set the dirtyFlag to FALSE after the write queue->current->dirtyFlag = FALSE; queue->current = queue->current->next; } return RC_OK; }
//display the field with position. (ascii cells) void showField(uint8_t *field, int position) { //calculate x and y location from position. x = position%fieldWidth; if(!(position%fieldWidth)) { y++; if(y>=(fieldHeight)) { y=0; } } //set this location. lcd.setCursor(x,y); //draw a cell if there is a 1 at this position. //else draw a empty block. if(field[position]) { writeCell(); } else { writeBlock(); } }
int pinThispage(BM_BufferPool *const bm, frame *pt, PageNumber pageNum) /*pin page pointed by pt with pageNum-th page. If do not have, create one*/ { buffer *bf = bm->mgmtData; SM_FileHandle fHandle; //cheating: should malloc then free RC rt_value = openPageFile(bm->pageFile, &fHandle); if (rt_value!=RC_OK) return rt_value; rt_value = ensureCapacity(pageNum, &fHandle); //你不说谁知道啊 if (rt_value!=RC_OK) return rt_value; if (pt->dirty) { rt_value = writeBlock(pt->currpage, &fHandle, pt->data); if (rt_value!=RC_OK) return rt_value; pt->dirty = false; bf->numWrite++; } rt_value = readBlock(pageNum, &fHandle, pt->data); if (rt_value!=RC_OK) return rt_value; bf->numRead++; pt->currpage = pageNum; pt->fixCount++; closePageFile(&fHandle); return 0; }
//------------------------------------------------------------------------------ void My3Socket::sendTest(quint32 num) { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out << num; writeBlock(block, block.size()); }
void chunkArchive::do_tagging(enum atoms TAG) { if (!TEST_BIT(status_bits, bTAG)) return; CLEAR_BIT(status_bits, bTAG); writeBlock((const char *) &TAG, 1); }
RC forcePage(BM_BufferPool *const bm, BM_PageHandle *const page) { // Retrieve management data BM_MgmtData *mgmtData= bm->mgmtData; // Check if a frame is already assigned to the page BM_Frame *frame= &mgmtData->framePool[0]; RC result = RC_PAGE_NOT_PINNED; int i; for (i = 0; i < bm->numPages; i++) { if (page->pageNum == frame->pageNum) { // Page exists within the buffer if (frame->isDirty && frame->fixCount == 0) { // Check to see if current page is dirty RC result = writeBlock(frame->pageNum, &mgmtData->fh, frame->memPage); if(result==RC_OK){ frame->isDirty = FALSE; mgmtData->ioWrites++; return result; } return result; } } frame++; } return result; }
qint64 SymmetricCipherStream::writeData(const char* data, qint64 maxSize) { Q_ASSERT(maxSize >= 0); if (m_error) { return -1; } m_dataWritten = true; qint64 bytesRemaining = maxSize; qint64 offset = 0; while (bytesRemaining > 0) { int bytesToCopy = qMin(bytesRemaining, static_cast<qint64>(m_cipher->blockSize() - m_buffer.size())); m_buffer.append(data + offset, bytesToCopy); offset += bytesToCopy; bytesRemaining -= bytesToCopy; if (m_buffer.size() == m_cipher->blockSize()) { if (!writeBlock(false)) { if (m_error) { return -1; } else { return maxSize - bytesRemaining; } } } } return maxSize; }
/* A function to write all the dirty pages with fixed count 0 to the page file in disk. */ RC forceFlushPool(BM_BufferPool *const bm) { // read from buffer and write to disk only dirty pages with fixed count 0 RC rc_code; BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData; SM_FileHandle *fHandle = pi->fh; int i; for (i = 0; i < bm->numPages; i++) { if ( pi->dirtys[i] && (pi->fixCounter[i] == 0) ) { // write page to disk SM_PageHandle memPage = pi->frames[i]; // printf("Writing to disk page %i\n", pi->map[i]); rc_code = writeBlock(pi->map[i], pi->fh, memPage); NumWriteIO++; if (rc_code != RC_OK) return rc_code; pi->dirtys[i] = false; } } return rc_code; }
void Core99NVRAM::sync(void) { Core99NVRAMHeader *header; unsigned char *tmpBuffer; // Don't write the BootROM if nothing has changed. if (!bcmp(nvramShadow, nvramCurrent, kCore99NVRAMSize)) return; header = (Core99NVRAMHeader *)nvramShadow; header->generation = ++generation; header->checksum = chrpCheckSum(nvramShadow); header->adler32 = adler32(nvramShadow + kCore99NVRAMAdlerStart, kCore99NVRAMAdlerSize); if (eraseBlock() != kIOReturnSuccess) return; if (writeBlock(nvramShadow) != kIOReturnSuccess) return; tmpBuffer = (unsigned char *)nvramCurrent; nvramCurrent = nvramNext; nvramNext = tmpBuffer; }
/** Block until all audio has been played */ int sa_stream_drain(sa_stream_t *s) { int status; WAVEHDR* current; ERROR_IF_NO_INIT(s); current = &(s->waveBlocks[s->waveCurrentBlock]); if (current->dwUser) { /* We've got pending audio which hasn't been written, we must write it to the hardware, else it will never be played. */ status = writeBlock(s, current); HANDLE_WAVE_ERROR(status, "writing audio to audio device"); } if (!s->playing) { return SA_ERROR_INVALID; } /* wait for all blocks to complete */ EnterCriticalSection(&(s->waveCriticalSection)); while(s->waveFreeBlockCount < BLOCK_COUNT) { LeaveCriticalSection(&(s->waveCriticalSection)); Sleep(10); EnterCriticalSection(&(s->waveCriticalSection)); } LeaveCriticalSection(&(s->waveCriticalSection)); return SA_SUCCESS; }
void FileSendProgressDialog::sendFile(const FileInfo& info) { QFile f( info.fileID == -1 ? QDir::toNativeSeparators(info.fileName) : fileUtils()->resolveFilePath(info.fileID) ); if (!f.open(QIODevice::ReadOnly)) { qDebug() << "Could not open file for reading" << f.fileName()<<f.errorString(); reject(); return; } m_fileSize = f.size(); f.seek(info.offset); setRange(0, 100); qDebug()<<"sendFile:"<<f.fileName(); // we do the whole splitting thing, since when sending the header // we don't want the whole path FileInfo copy = info; if (info.fileID == -1) { copy.fileName = info.fileName.split('/').last(); qDebug() << "sendFile: " << copy.fileName; writeBlock(fileUtils()->formatFileHeader(copy).toAscii()); } //qDebug() << fileUtils()->formatFileHeader(copy).toAscii(); //if (copy.fileName.contains("elf.h")) // qDebug() << "Elf " << fileUtils()->formatFileHeader(copy).toAscii(); m_writingData = true; qDebug() << "sendFile: Calling writeFile"; writeFile(m_socket, &f); //nextFileRequested(); }
// Escreve bitmap no disco int writeBitMap() { if(writeBlock(getBitmapreg()->dataPtr[0], bitmap) == -1) return -1; else return 0; }
RC forceFlushPool(BM_BufferPool *const bm) { //write all dirty pages (fix count 0) to disk //do pinned check buffer *bf = bm->mgmtData; SM_FileHandle fHandle; RC rt_value = openPageFile(bm->pageFile, &fHandle); if (rt_value!=RC_OK) return rt_value; frame *pt = bf->head; do { if (pt->dirty) { rt_value = writeBlock(pt->currpage, &fHandle, pt->data); if (rt_value!=RC_OK) return rt_value; pt->dirty = false; bf->numWrite++; } pt = pt->next; }while (pt!=bf->head); closePageFile(&fHandle); return RC_OK; }