Exemplo n.º 1
0
void PaletteColor::UpdateBitmaps(){
	Vector col = m_color.Convert(COLOR_SOURCE_DISPLAY).AsVector();
	Float dim = 0.7;
	updateBitmap(m_normalBitmap,        col,m_w,m_h,1.f, 0.f, NULL,            0.0f);
	updateBitmap(m_hoverBitmap,     col*dim,m_w,m_h,0.5f,0.5f,m_refreshIcon,   1.0f);
	updateBitmap(m_leftHoverBitmap, col*dim,m_w,m_h,0.f, 0.5f,m_leftArrowIcon, 1.0f);
	updateBitmap(m_rightHoverBitmap,col*dim,m_w,m_h,1.f, 0.5f,m_rightArrowIcon,1.0f);
    updateBitmap(m_crossHoverBitmap,col*dim,m_w,m_h,0.5f,0.5f,m_crossIcon     ,1.0f);
}
void free_page(vAddr address) {
  sem_wait(memory_lock); // Wait for the semaphore lock
  // Look up for the page table entry
  int ctr = 0; // Loop counter
  for( ; ctr < TOTAL_SYSTEM_MEM_STORAGE; ctr++ ) {
    if( pageTable[ctr].pageNumber == address ) {
      // We found the page
      // Tell the user
      if(DEBUG) printf("Page #%d was freed from the paging simulator.\n", getPageTableNumber(pageTable[ctr].level, pageTable[ctr].index));
      // Clean up now
      if( pageTable[ctr].level == 0 )
        ramStorage[pageTable[ctr].index] = 0;
      else if( pageTable[ctr].level == 1 )
        ssdStorage[pageTable[ctr].index] = 0;
      else if( pageTable[ctr].level == 2 )
        hddStorage[pageTable[ctr].index] = 0;
      // Free this page's bitmap before clearing all its necessary data
      updateBitmap( pageTable[ctr].level, pageTable[ctr].index, 1); // This memory location is now AVAILABLE
      // Clear up the page table entry
      pageTable[ctr].pageNumber = -1; // We don't have a page here no more
      pageTable[ctr].level = -1; // We don't want to point anywhere
      pageTable[ctr].index = -1; // We don't want to point anywhere
      pageTable[ctr].memory = NULL; // No memory location will be stored here
      pageTable[ctr].presentBit = 0; // This page is no longer present in the memory
      // Decrement overallMemoryUsed
      overallMemoryUsed--;
      // Exit the loop
      sem_post(memory_lock); // Release semaphore lock
      return;
    }
  }
  // We didn't find the desired page
  sem_post(memory_lock); // Release semaphore lock
  return; // We still gotta return
}
Exemplo n.º 3
0
/*
 * Deletes a file
 */
static int cs1550_unlink(const char *path)
{

	char dir[MAX_FILENAME + 1];
	char fileName[MAX_FILENAME + 1];
	char ext[MAX_EXTENSION + 1];
	getPath(path, dir, fileName, ext);
	int pathType = getPathType(path, dir, fileName, ext);
	int fileSize = getFileSize(dir, fileName, ext, pathType);

	if (pathType < 2) {
		return -EISDIR;
	}
	else if (fileSize == -1){
		return -ENOENT;
	}
	else {
		cs1550_directory_entry parentDir;
		getDir(&parentDir, dir);
		int i =0;
		for (i = 0; i < parentDir.nFiles; i++) {
			if ((pathType==2 && strcmp(parentDir.files[i].fname, fileName)==0) || (pathType==3 && strcmp(parentDir.files[i].fname, fileName) == 0 && strcmp(parentDir.files[i].fext, ext) == 0)) {
				long startBlock = parentDir.files[i].nStartBlock;
				long seek = startBlock;
				FILE *f = fopen(".disk", "rb");
				while(seek != 0) {
					fseek(f, seek, SEEK_SET);
					cs1550_disk_block curBlock;
					fread(&curBlock, BLOCK_SIZE, 1, f);
					cs1550_disk_block empty;
					memset(&empty, 0, BLOCK_SIZE);
					writeBlock(&empty, seek);
					int index = seek / BLOCK_SIZE;
					updateBitmap(index, 0);
					if (curBlock.magic_number != 0) {
						seek = curBlock.magic_number;
					}
					else {
						seek = 0;
					}
				}
				fclose(f);
				int x =0;
				for (x = 0; x < parentDir.nFiles; x++) {
					if (x >= i && x != parentDir.nFiles-1) {
						strcpy(parentDir.files[x].fname, parentDir.files[x+1].fname);
						strcpy(parentDir.files[x].fext, parentDir.files[x+1].fext);
						parentDir.files[x].fsize = parentDir.files[x+1].fsize;
						parentDir.files[x].nStartBlock = parentDir.files[x+1].nStartBlock;
					}
				}
				parentDir.nFiles--;
				updateDir(&parentDir, dir);
			}
		}
	}
  return 0;
}
Exemplo n.º 4
0
void BMPYUVImage::updateFromRawImage() {
    if (YUVImage::rawImageDimensionsEnlarged()) {
        bitmap = QImage(rawImage->get()->width(),
                        rawImage->get()->height(),
                        QImage::Format_RGB32);
    }
	YUVImage::updateFromRawImage();
	updateBitmap();
}
Exemplo n.º 5
0
/*
 * Does the actual creation of a file. Mode and dev can be ignored.
 *
 */
static int cs1550_mknod(const char *path, mode_t mode, dev_t dev)
{
	(void) mode;
	(void) dev;

	char dir[MAX_FILENAME + 1];
	char fileName[MAX_FILENAME + 1];
	char ext[MAX_EXTENSION + 1];
	getPath(path, dir, fileName, ext);
	int pathType = getPathType(path, dir, fileName, ext);
	int fileSize = getFileSize(dir, fileName, ext, pathType);

	if (pathType < 2) {
		return -EPERM;
	}
	else if (fileSize != -1){
			return -EEXIST;
	}
	else if (strlen(fileName) > MAX_FILENAME || strlen(ext) > MAX_EXTENSION) {
			return -ENAMETOOLONG;
	}
	else {
			cs1550_root_directory r;
			getRoot(&r);
			int i =0;
			for(i = 0; i < r.nDirectories; i++) {
				if (strcmp(r.directories[i].dname, dir) == 0) {
					int blockNum = getNextBlock();
					long startBlock = (long)(BLOCK_SIZE * blockNum);
					updateBitmap(blockNum, 1);
					cs1550_directory_entry parentDir;
					getDir(&parentDir, dir);
					strcpy(parentDir.files[parentDir.nFiles].fname, fileName);
					strcpy(parentDir.files[parentDir.nFiles].fext, ext);
					parentDir.files[parentDir.nFiles].fsize = 0;
					parentDir.files[parentDir.nFiles].nStartBlock = startBlock;
					parentDir.nFiles++;
					int parentDirMagicNum = r.directories[i].nStartBlock;
					FILE *f = fopen(".disk", "rb+");
					if (f != NULL) {
						fseek(f, 0, SEEK_END);
						int diskSize = ftell(f);
						rewind(f);
						char *buffer = (char *)malloc(diskSize);
						fread(buffer, diskSize, 1, f);
						rewind(f);
						memmove(buffer+parentDirMagicNum, &parentDir, BLOCK_SIZE);
						fwrite(buffer, diskSize, 1, f);
						fclose(f);
						free(buffer);
					}
				}
			}
		}
	return 0;
}
Exemplo n.º 6
0
//Creates a new empty directory on .disk
static void createDir(char *dir) {
	int block_number = getNextBlock();
	if (block_number != -1) {
			cs1550_root_directory r;
			getRoot(&r);
			strcpy(r.directories[r.nDirectories].dname, dir);
			r.directories[r.nDirectories].nStartBlock = (long)(BLOCK_SIZE * block_number);
			r.nDirectories = r.nDirectories + 1;
			updateRootOnDisk(&r);
			updateBitmap(block_number, 1);
	}
}
Exemplo n.º 7
0
Arquivo: fuseLib.c Projeto: ferreiro/C
/**
 * @brief Write data on an opened file
 *
 * Help from FUSE
 *
 * Write should return exactly the number of bytes requested except on error.
 * 
 * @param path file path
 * @param buf buffer where we have data to write
 * @param size quantity of bytes to write
 * @param offset offset over the writing
 * @param fi FUSE structure linked to the opened file
 * @return 0 on success and <0 on error
 **/
static int my_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
	char buffer[BLOCK_SIZE_BYTES]; // 1 bloque de caracteres.
	int bytes2Write = size, totalWrite = 0;
	NodeStruct *node = myFileSystem.nodes[fi->fh]; // fh==File handle. May be filled in by filesystem in open().

	fprintf(stderr, "--->>>my_write: path %s, size %zu, offset %jd, fh %"PRIu64"\n", path, size, (intmax_t)offset, fi->fh);

	// Increase the file size if it is needed
	if(resizeNode(fi->fh, size + offset) < 0)
		return -EIO;

	// Write data
	while(bytes2Write) {
		int i;
		int currentBlock, offBloque;
		currentBlock = node->blocks[offset / BLOCK_SIZE_BYTES];
		offBloque = offset % BLOCK_SIZE_BYTES;
	
		// posicionas el cursor del archivo en el bloque + offset.
		// lees un bloque entero empezando en esa posición. SI alguno de los dos falla exit.
		if((lseek(myFileSystem.fdVirtualDisk, currentBlock * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
		        (read(myFileSystem.fdVirtualDisk, &buffer, BLOCK_SIZE_BYTES) == -1)) {
			perror("Failed lseek/read in my_write");
			return -EIO;
		}
		
		// Desde el punto inicial del offset, hasta el final del bloque, escribes la información
		// del buf (texto que nos pasan en la función) en el buffer.
		for(i = offBloque; (i < BLOCK_SIZE_BYTES) && (totalWrite < size); i++) {
			buffer[i] = buf[totalWrite++];
		}
		
		// GUardas el buffer con la información modificada en el archivo indicado en el descriptor físico.
		if((lseek(myFileSystem.fdVirtualDisk, currentBlock * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
		        (write(myFileSystem.fdVirtualDisk, &buffer, BLOCK_SIZE_BYTES) == -1)) {
			perror("Failed lseek/write in my_write");
			return -EIO;
		}

		// Discont the written stuff
		bytes2Write -= (i - offBloque);
		offset += i;
	}
	sync();
	
	node->modificationTime = time(NULL);
	updateSuperBlock(&myFileSystem);
	updateBitmap(&myFileSystem);
	updateNode(&myFileSystem, fi->fh, node);

	return size;
}
Exemplo n.º 8
0
//--------------------------------------------------------------
void IntelFaceScanner::threadedFunction(){
	pxcStatus result;

	while ((scanningFramesRemaining) && (isThreadRunning()))
	{

		pxcStatus status = senseManager->AcquireFrame(true);
		if (checkDeviceConnection(senseManager->IsConnected())) 
		{
			if (status < PXC_STATUS_NO_ERROR)  {				
				ofLogError() << "Error with Sensemanager...! status=" << status;
				return;
			}
			frameCounter++;

		}

		if (scanner->IsScanning())
        {
			if(!bDoScan) {
				bDoScan = true;
				//ofNotifyEvent(scanningStartedEvent,this);
				ofLogNotice("IntelFaceScanner") << "Scanning started... frame:" << frameCounter;
			}
            scanningFramesRemaining--;
		}
		// Get the preview image for this frame
        PXCImage* preview_image = scanner->AcquirePreviewImage();

		senseManager->ReleaseFrame();

		if(preview_image) {
			updateBitmap(preview_image);
			preview_image->Release();
		}

	}


	ofLogNotice("IntelFaceScanner") << "Rendering scan... frame:" << frameCounter;
	ofNotifyEvent(scanningStartedEvent,this);
	renderScan();
	ofLogNotice("IntelFaceScanner") << "Scanning stopped... frame:" << frameCounter;
	curframeCounter = frameCounter;
	ofNotifyEvent(scanningDoneEvent,this);

}
Exemplo n.º 9
0
Arquivo: fuseLib.c Projeto: ferreiro/C
int my_unlink(const char *filename) {
	
	
	// printDirectory(myFileSystem.directory); // DEBUG stuff only for debugging
	
	/***** Copiar filename sin '/' en una nueva variable para 
	 ***** poder pasarla a findFileByNAme (que no admite strings constantes) ****/
	
	int i=0;
	char* fname=(char*)(filename+1); // Convert ffrom const char to char. Y también, quitar el primer character (/) sumando uno al puntero de filename (hace algoritimia de punteros.)
		
	
	/** 1. Buscar si el archivo está en nuestro directorio **/
	/** Si está, liberar el archivo y poner el nombre a empty **/
	/** OJO! NO hay que tocar nodeIdx... **/
	
	int nodeIndexDir = findFileByName(&myFileSystem, fname); // NodeIDx índice que ocupa un nodo en el array de nodos
	 
	if (nodeIndexDir == -1) {
		fprintf(stderr, "File wasn't found on the directory entry\n");  
		return -1; // File is not on the directory.
	}
	
	// FILE to erase is on the directory. Free the directory entry.
	
	myFileSystem.directory.numFiles -= 1; // Decrementar numero de archivos en el directorio.
	myFileSystem.directory.files[nodeIndexDir].freeFile = true; // Put the node in directory as free.
	updateDirectory(&myFileSystem);
	
	int nodeIdx = myFileSystem.directory.files[nodeIndexDir].nodeIdx; // Hacer una copia de nodoIDx del directorio que nos sirve para acceder al array de nodos.
	NodeStruct* inode=myFileSystem.nodes[nodeIdx];
	
	/** 2. Borrar datos y liberar nodo usando el nodeIdx obtenido del directorio **/

	myFileSystem.numFreeNodes += 1; // Increase the number of free nodes by 1 because e erased one.
	
	for (i=0;i<inode->numBlocks;i++)
		myFileSystem.bitMap[inode->blocks[i]] = 0; // Marcar bloques de datos en bitmap como libre
 
	myFileSystem.superBlock.numOfFreeBlocks+=inode->numBlocks;
	updateBitmap(&myFileSystem);
	updateSuperBlock(&myFileSystem);
		
 	/**********************************************
 	 * 	Se podría poner unicamente a NULL? Es peor?
 	 **********************************************/
 	 
	inode->numBlocks=0;
	inode->fileSize=0;
	inode->freeNode=true; // Delete the note from the node's array.

	updateNode(&myFileSystem,nodeIdx,inode);
	
	free(inode);
	myFileSystem.nodes[nodeIdx]=NULL;
	
 	  
 	//printAllNodes(myFileSystem.nodes);
 	//printDirectory(myFileSystem.directory); // DEBUG stuff only for debugging

	fprintf(stderr, "\n Congrats!!! %s file deleted \n", filename);
 	
	return 0;
}
Exemplo n.º 10
0
Arquivo: fuseLib.c Projeto: ferreiro/C
/**
 * @brief Modifies the data size originally reserved by an inode, reserving or removing space if needed.
 *
 * @param idxNode inode number
 * @param newSize new size for the inode
 * @return int
 **/
int resizeNode(uint64_t idxNode, size_t newSize) {
	NodeStruct *node = myFileSystem.nodes[idxNode];
	char block[BLOCK_SIZE_BYTES];
	int i, diff = newSize - node->fileSize;

	if(!diff)
		return 0;

	memset(block, 0, sizeof(char)*BLOCK_SIZE_BYTES);

	/// File size increases
	if(diff > 0) {

		/// Delete the extra conent of the last block if it exists and is not full
		if(node->numBlocks && node->fileSize % BLOCK_SIZE_BYTES) {
			int currentBlock = node->blocks[node->numBlocks - 1];
			if((lseek(myFileSystem.fdVirtualDisk, currentBlock * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
			        (read(myFileSystem.fdVirtualDisk, &block, BLOCK_SIZE_BYTES) == -1)) {
				perror("Failed lseek/read in resizeNode");
				return -EIO;
			}
			int offBlock = node->fileSize % BLOCK_SIZE_BYTES;
			int bytes2Write = (diff > (BLOCK_SIZE_BYTES - offBlock)) ? BLOCK_SIZE_BYTES - offBlock : diff;
			for(i = 0; i < bytes2Write; i++) {
				block[offBlock++] = 0;
			}

			if((lseek(myFileSystem.fdVirtualDisk, currentBlock * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
			        (write(myFileSystem.fdVirtualDisk, &block, BLOCK_SIZE_BYTES) == -1)) {
				perror("Failed lseek/write in resizeNode");
				return -EIO;
			}
		}

		/// File size in blocks after the increment
		int newBlocks = (newSize + BLOCK_SIZE_BYTES - 1) / BLOCK_SIZE_BYTES - node->numBlocks;
		if(newBlocks) {
			memset(block, 0, sizeof(char)*BLOCK_SIZE_BYTES);

			// We check that there is enough space
			if(newBlocks > myFileSystem.superBlock.numOfFreeBlocks)
				return -ENOSPC;

			myFileSystem.superBlock.numOfFreeBlocks -= newBlocks;
			int currentBlock = node->numBlocks;
			node->numBlocks += newBlocks;

			for(i = 0; currentBlock != node->numBlocks; i++) {
				if(myFileSystem.bitMap[i] == 0) {
					myFileSystem.bitMap[i] = 1;
					node->blocks[currentBlock] = i;
					currentBlock++;
					// Clean disk (necessary for truncate)
					if((lseek(myFileSystem.fdVirtualDisk, i * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
					        (write(myFileSystem.fdVirtualDisk, &block, BLOCK_SIZE_BYTES) == -1)) {
						perror("Failed lseek/write in resizeNode");
						return -EIO;
					}
				}
			}
		}
		node->fileSize += diff;

	}
	/// File decreases
	else {
		// File size in blocks after truncation
		int numBlocks = (newSize + BLOCK_SIZE_BYTES - 1) / BLOCK_SIZE_BYTES;
		myFileSystem.superBlock.numOfFreeBlocks += (node->numBlocks - numBlocks);

		for(i = node->numBlocks; i > numBlocks; i--) {
			int nBloque = node->blocks[i - 1];
			myFileSystem.bitMap[nBloque] = 0;
			// Clean disk (it is not really necessary)
			if((lseek(myFileSystem.fdVirtualDisk, nBloque * BLOCK_SIZE_BYTES, SEEK_SET) == (off_t) - 1) ||
			        (write(myFileSystem.fdVirtualDisk, &block, BLOCK_SIZE_BYTES) == -1)) {
				perror("Failed lseek/write in resizeNode");
				return -EIO;
			}
		}
		node->numBlocks = numBlocks;
		node->fileSize += diff;
	}
	node->modificationTime = time(NULL);

	sync();
	
	/// Update all the information in the backup file
	updateSuperBlock(&myFileSystem);
	updateBitmap(&myFileSystem);
	updateNode(&myFileSystem, idxNode, node);

	return 0;
}
Exemplo n.º 11
0
int myMkfs(MyFileSystem *myFileSystem, int diskSize, char *backupFileName) {
	// We create the virtual disk:
	myFileSystem->fdVirtualDisk = open(backupFileName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

	// Some minimal checks:
	assert(sizeof(SuperBlockStruct) <= BLOCK_SIZE_BYTES);
	assert(sizeof(DirectoryStruct) <= BLOCK_SIZE_BYTES);
	int numBlocks = diskSize / BLOCK_SIZE_BYTES;
	int minNumBlocks = 3 + MAX_BLOCKS_WITH_NODES + 1;
	// 3 --> por el superbloque, el raiz y el mapa de bits.
	// 1 --> porque al menos tenemos un bloque para datos.
	int maxNumBlocks = NUM_BITS;
	if(numBlocks < minNumBlocks) {
		return -1;
	}
	if(numBlocks >= maxNumBlocks) {
		return -2;
	}

	/// BITMAP
	// Initialization
	int i;
	for(i = 0; i < NUM_BITS; i++) {
		myFileSystem->bitMap[i] = 0;
	}

	// First three blocks will be superblock, bitmap and directory
	myFileSystem->bitMap[BITMAP_IDX] = 1;
	myFileSystem->bitMap[SUPERBLOCK_IDX] = 1;
	myFileSystem->bitMap[DIRECTORY_IDX] = 1;
	// Next MAX_BLOCKS_WITH_NODES will contain inodes
	for(i = 3; i < 3 + MAX_BLOCKS_WITH_NODES; i++) {
		myFileSystem->bitMap[i] = 1;
	}
	updateBitmap(myFileSystem);

	/// DIRECTORY
	// Initialization
	myFileSystem->directory.numFiles = 0;
	for(i = 0; i < MAX_FILES_PER_DIRECTORY; i++) {
		myFileSystem->directory.files[i].freeFile = 1;
	}
	updateDirectory(myFileSystem);

	/// INODES
	NodeStruct currentNode;
	currentNode.freeNode = 1;
	for(i = 0; i < MAX_NODES; i++) {
		updateNode(myFileSystem, i, &currentNode);
	}

	/// SUPERBLOCK
	initializeSuperBlock(myFileSystem, diskSize);
	updateSuperBlock(myFileSystem);
	sync();

	// At the end we have at least one block
	assert(myQuota(myFileSystem) >= 1);

	if(initializeNodes(myFileSystem)){
		myFree(myFileSystem);
		return -3;
	}

	printf("SF: %s, %d B (%d B/block), %d blocks\n", backupFileName, diskSize, BLOCK_SIZE_BYTES, numBlocks);
	printf("1 block for SUPERBLOCK (%u B)\n", (unsigned int)sizeof(SuperBlockStruct));
	printf("1 block for BITMAP, covering %u blocks, %u B\n", (unsigned int)NUM_BITS, (unsigned int)(NUM_BITS * BLOCK_SIZE_BYTES));
	printf("1 block for DIRECTORY (%u B)\n", (unsigned int)sizeof(DirectoryStruct));
	printf("%d blocks for inodes (%u B/inode, %u inodes)\n", MAX_BLOCKS_WITH_NODES, (unsigned int)sizeof(NodeStruct), (unsigned int)MAX_NODES);
	printf("%d blocks for data (%d B)\n", myFileSystem->superBlock.numOfFreeBlocks, BLOCK_SIZE_BYTES * myFileSystem->superBlock.numOfFreeBlocks);
	printf("Formatting completed!\n");

	return 0;
}
Exemplo n.º 12
0
void BMPYUVImage::updateFromRoboImage() {
	YUVImage::updateFromRoboImage();
	updateBitmap();
}
int *addNewPage(int pageNumber) {
  int *toReturn = (int*)malloc(sizeof(int) * 2);
  // Set some default values
  toReturn[0] = -1; // We couldn't add the page as requested on any level
  toReturn[1] = -1; // The page cannot be accessed at the given level of storage
  // See if we've got space in the RAM
  if( RAMMemoryUsed < RAM_STORAGE_COUNT ) {
    // We've got storage in the RAM
    toReturn[0] = 0; // Level is RAM
    toReturn[1] = findEmptySlotAt(0)[1]; // Index into the first free empty slot got in the RAM
    // Increase memory usage by updating the RAM bitmap
    updateBitmap(0, toReturn[1], 0); // The RAM location is NO longer free
    // Tell the user
    if(DEBUG) printf("A new page with page #%d was directly created in the RAM.\n", pageNumber);
    // Return the requested item
    return toReturn;
  } else if( SSDMemoryUsed < SSD_STORAGE_COUNT ) {
    // We've got no storage in the RAM
    // STEP 1: Find the page to be evicted at RAM level
    int pageIndexToEvictAtRAM = pickAPageToEvict(0)[1];
    // STEP 2: Find a suitable index at level 1 to move it to
    int *levelToMoveTo = findEmptySlotAt(1); 
    // STEP 3: Create levels to execute the swap
    toReturn[0] = 0; // To be evicted from RAM
    toReturn[1] = pageIndexToEvictAtRAM; // Evict index
    // STEP 4: Execute the swap
    switchToMemoryLocation(toReturn, levelToMoveTo);
    // STEP 5: Increase memory usage by updating the RAM and SSD bitmaps
    updateBitmap(0, pageIndexToEvictAtRAM, 0); // The RAM location is NO longer free
    updateBitmap(1, levelToMoveTo[1], 0); // The SSD location is NO longer free
    // STEP 6: Tell the user
    if(DEBUG) printf("A new page with page #%d was added to the RAM causing eviction of a page to the SSD with Page #%d\n", pageNumber, getPageTableNumber(1, levelToMoveTo[1])); 
    // STEP 7: Return the level which was freed up
    return toReturn;
  } else if( HDDMemoryUsed < HDD_STORAGE_COUNT ) {
    // We've got no storage in RAM
    // STEP 1: Find the page to be evicted at the SSD level
    int *pageEvictedFromSSD = pickAPageToEvict(1);
    // STEP 2: Find slot in the HDD level to place the SSD page
    int *destinationInHDD = findEmptySlotAt(2);
    // STEP 3: Perform the swap
    switchToMemoryLocation(pageEvictedFromSSD, destinationInHDD);
    // STEP 4: Find the RAM page to be moved out now
    int *pageEvictedFromRAM = pickAPageToEvict(0);
    // STEP 5: Resolve the location to place this RAM page
    int *destinationInSSD = pageEvictedFromSSD;
    // STEP 6: Perform the swap
    switchToMemoryLocation(pageEvictedFromRAM, destinationInSSD);
    // STEP 7: Resolve the empty spot
    toReturn[0] = 0; // Space freed up in RAM
    toReturn[1] = pageEvictedFromRAM[1]; // Index of free location in the RAM
    // STEP 8: Update the bitmaps
    updateBitmap(0, pageEvictedFromRAM[1], 0); // This RAM location is NO longer free
    updateBitmap(1, destinationInSSD[1], 0); // This SSD location is NO longer free
    updateBitmap(2, destinationInHDD[1], 0); // This location in HDD is NO longer free as well
    // STEP 9: Tell the user
    if(DEBUG) printf("A new page with page #%d was added to the RAM causing eviction of a page from the RAM to the SSD with Page #%d and a page from SSD to the HDD with page #%d\n", pageNumber, getPageTableNumber(1, destinationInSSD[1]), getPageTableNumber(2, destinationInHDD[1])); 
    // STEP 10: Return the level which was freed up
    return toReturn;
  }
  // If nothing matches, return the default values
  return toReturn;
}
Exemplo n.º 14
0
void gfxPreviewWind::Refresh() 
{

	CRect wsize;
	GetWindowRect(wsize);
	Point2I zero(0,0);
	Point2I stretch(wsize.Width() - 1,wsize.Height() - 1);

	pSurface->lock();
	if (m_matType == TS::Material::MatNull) pSurface->clear(0);
	else if (m_matType == TS::Material::MatPalette) pSurface->clear(m_pMaterial->fParams.fIndex);
	else if (m_matType == TS::Material::MatTexture) {

		if (updateBitmap() == false) return;
		
	
	
/*		BOOL found=false;
		CString tempPath = pSearchPath;
		CString onePath;*/
		CString theFile = m_pMaterial->fParams.fMapFile;
/*		CString oneFullPath;
		int foundindex;
		
		while (!found && !tempPath.IsEmpty()) {

			foundindex = tempPath.ReverseFind(';') + 1;
			onePath= tempPath.Mid(foundindex);
			tempPath= tempPath.Left(foundindex);
			
			//look for file here
			oneFullPath+= onePath+theFile;
			if (GetFileAttributes(oneFullPath) != -1) found= 1;
		}

		if (!found) {

		} else {*/

		ResourceObject *obj= rm.load(theFile);
		if (obj && obj->resource) {
     		m_pMaterial->load(rm, 1);
			const GFXBitmap *pBitmap= m_pMaterial->getTextureMap();
			AssertFatal(pBitmap, "gfxPreviewWind::Refresh: get Material TextureMap failed!");
			pSurface->clear(0);

			if (WantStretched) {
				pSurface->drawBitmap2d(pBitmap, &Point2I(0,0), &Point2I(stretch.x, stretch.y));
			} else {
				pSurface->drawBitmap2d(pBitmap, &Point2I(0,0));
			}
		} else 
         pSurface->clear(0);


	
	}
	
	pSurface->unlock();
	pSurface->update();
	

}
Exemplo n.º 15
0
/*
 * Write size bytes from buf into file starting from offset
 *
 */
static int cs1550_write(const char *path, const char *buf, size_t size,
			  off_t offset, struct fuse_file_info *fi)
{
	int ret = 0;
	(void) fi;

	char dir[MAX_FILENAME + 1];
	char fileName[MAX_FILENAME + 1];
	char ext[MAX_EXTENSION + 1];
	getPath(path, dir, fileName, ext);
	int pathType = getPathType(path, dir, fileName, ext);
	int fileSize = getFileSize(dir, fileName, ext, pathType);

	if (dirExists(dir) == 1 && pathType >= 2 && fileSize != -1 && size > 0) {
		cs1550_directory_entry parentDir;
		getDir(&parentDir, dir);
		int i =0;
		for (i = 0; i < parentDir.nFiles; i++) {
			if ((pathType==2 && strcmp(parentDir.files[i].fname, fileName)==0) || (pathType==3 && strcmp(parentDir.files[i].fname, fileName) == 0 && strcmp(parentDir.files[i].fext, ext) == 0)) {
				if (offset > parentDir.files[i].fsize) {
					return -EFBIG;
				}
				else {
					long startBlock = parentDir.files[i].nStartBlock;
					int blockNum = offset / BLOCK_SIZE;

					long seek = startBlock;
					long bStart = 0;
					FILE *f = fopen(".disk", "rb+");
					int j = 0;
					for (j = 0; j <= blockNum; j++) {
						bStart = seek;
						fseek(f, seek, SEEK_SET);
						cs1550_disk_block fileBlock;
						fread(&fileBlock, BLOCK_SIZE, 1, f);
						seek = fileBlock.magic_number;
					}
					rewind(f);
					int off = (int)offset - (blockNum * BLOCK_SIZE);
					int index;
					int count = off;
					seek = bStart;
					fseek(f, seek, SEEK_SET);
					cs1550_disk_block curBlock;
					fread(&curBlock, BLOCK_SIZE, 1, f);
					for (index = 0; index < strlen(buf); index++) {
						if (count < MAX_DATA_IN_BLOCK) {
							curBlock.data[count] = (char)buf[index];
							count++;
						}
						else {
							count = 0;
							if (curBlock.magic_number != 0) {
								writeBlock(&curBlock, seek);
								seek = curBlock.magic_number;
								fseek(f, seek, SEEK_SET);
								fread(&curBlock, BLOCK_SIZE, 1, f);
							}
							else {
								long cSeek = seek;
								int nextBlock = getNextBlock();
								seek = nextBlock * BLOCK_SIZE;
								curBlock.magic_number = seek;
								writeBlock(&curBlock, cSeek);
								fseek(f, seek, SEEK_SET);
								fread(&curBlock, BLOCK_SIZE, 1, f);
								updateBitmap(nextBlock, 1);
							}
						}
						if (index == strlen(buf)-1) {
							writeBlock(&curBlock, seek);
							count = 0;
						}
					}
					fclose(f);
					int old = parentDir.files[i].fsize;
					int newSize =  (size - (old - offset)) + (old - (old - offset));
					parentDir.files[i].fsize = newSize;
					updateDir(&parentDir, dir);
					ret = newSize;
				}
			}
		}
	}
	return ret;
}