public MiniDB(String dbName){
    this.dbName = dbName;
    this.bufMgr = new BufMgr(this);

    try{
      
      if( MiniDB_Util.fileOrDirectoryExists( osFilename() ) ){
	// load DB from file
	restoreDBFromOSFile();
	
	MiniDB_Block catHeadBlock = bufMgr.pin_block( MiniDB_Constants.CATALOG_BLOCK_ID );
	this.catalog = MiniDB_Catalog.createFromExisting( catHeadBlock, this );
      }
      else{
	// create DB from scratch
	this.dbBlocks = new byte[ MiniDB_Constants.DB_MAX_BLOCKS ][ MiniDB_Constants.BLOCK_SIZE ];
	this.dbBlockUsed = new boolean[ MiniDB_Constants.DB_MAX_BLOCKS ];

	for (int i=0; i<MiniDB_Constants.DB_MAX_BLOCKS; i++){
	  for (int j=0; j< MiniDB_Constants.BLOCK_SIZE ; j++){
	    this.dbBlocks[i][j] = (byte)0xaa;
	  }
	}
	
	// create the catalog
	int blockID = addBlockToDB();
	assert( blockID == MiniDB_Constants.CATALOG_BLOCK_ID );
	MiniDB_Block catHeadBlock = bufMgr.pin_block( MiniDB_Constants.CATALOG_BLOCK_ID );
	this.catalog = MiniDB_Catalog.createNewCatalog(catHeadBlock, this);
	bufMgr.markDirty( catHeadBlock.blockID );
      }
      
    }
    catch(MiniDB_Exception ex){
      // bad news
      System.out.println( "Exception " + ex );
      ex.printStackTrace();
      System.exit(0);
    }

  }