private void privFlushPages(PageId pageid, int all_pages) throws 
    HashOperationException, 
    PageUnpinnedException,  
    PagePinnedException, 
    PageNotFoundException,
    BufMgrException,
    IOException {
    
    // The current page
    Page curPage;
    
    // The current frame descriptor
    FrameDesc frame;
      
    // Iterate through the Buffer Pool
    for (int i=0; i < numBuffers; i++) {
      
      // If flushAllPages() or pageId specified in flushPage()
      if ( (all_pages == 1) || (frmeTable[i].pageNo.pid == pageid.pid)) {
    
        // If the pin_count isn't 0, the page is still in use and can't be flushed
        if ( frmeTable[i].pin_count() != 0 )
          throw new PagePinnedException (null, "BUFMGR: Page is still pinned.");
    
        // If page is dirty
        if (frmeTable[i].dirty) {
          
          // You cannot write an INVALID_PAGE
          if (frmeTable[i].pageNo.pid == INVALID_PAGE)
            throw new PageNotFoundException( null, "BUFMGR: Page not found");
          
          // Set the current frame and current page
          frame = frmeTable[i];
          curPage = new Page(bufPool[i]);

          pageid.pid = frame.pageNo.pid;
      
          // Write the dirty page
          write_page(pageid, curPage);
      
          // Remove the page from the Page Table
          hashTable.remove(pageid);
      
          // Reset the Buffer Table
          // NOTE: this should be a FrameDesc method
          frmeTable[i].pageNo.pid = INVALID_PAGE; // frame is empty
          frmeTable[i].dirty = false ;
        } // end if
      } // end if
    } // end for
  } // end privFlushPages()