Esempio n. 1
0
Launcher::Launcher(QStringList const & args)
{
  setObjectName("Launcher");
  
  initializeArguments(args);
  
  if( QFile::exists(arguments["settings"]) )
  { // try loading the settings XML file into a C++ representation
//     try
//     {
      xmlSettings = XML::SAI::configuration(arguments["settings"].toStdString());
//     }
//     catch(const xml_schema::Exception& e)
//     {
//       Q_CHECK_PTR( e.what() );
//       std::cerr << "error in Launcher(QStringList const &)"<< std::endl;
//       std::cerr << e.what() << std::endl;
//     }
    
    initializeFrames();
    loadBoundary();
    loadObstacles();
    initializeNodes();
    
    qDebug() << objectName() << ": Enjoy the show.\n\n\n";
    
  }
  else
  { // error handling
    //NOTE: qFatal() will _abort_ on a UNIX system!
    qFatal("%s: Cannot load settings from %s. (File does not seem to exist.)"
      ,objectName().toStdString().c_str()
      ,arguments["settings"].toStdString().c_str());
  }
}
Esempio n. 2
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;
}