filehash/ffdb_page.c
static void
_ffdb_swap_page_metainfo_out (void *p)
{
  unsigned int i, next;
  unsigned int type = TYPE(p);
  unsigned int num = NUM_ENT(p);
  ffdb_data_header_t* header;

#ifdef _FFDB_DEBUG
  fprintf (stderr, "SWAP Header Write page %d \n", CURR_PGNO(p));
  fprintf (stderr, "Page Information: PGNO %d PREV PGNO %d NEXT PGNO %d PAGE SIGN 0x%x\n",
	   CURR_PGNO(p), PREV_PGNO(p),NEXT_PGNO(p), PAGE_SIGN(p));
  fprintf (stderr, "Page TYPE 0x%x OFFSET %d\n", TYPE(p), OFFSET(p));
#endif     

  M_32_SWAP(CURR_PGNO(p));
  M_32_SWAP(PREV_PGNO(p));
  M_32_SWAP(NEXT_PGNO(p));
  M_32_SWAP(PAGE_SIGN(p));
  M_16_SWAP(NUM_ENT(p));
  M_16_SWAP(TYPE(p));
  M_32_SWAP(CHKSUM(p));
  M_32_SWAP(OFFSET(p));

  switch (type) {
  case HASH_BUCKET_PAGE:
    for (i = 0; i < num; i++) {
      M_DATAP_SWAP(DATAP(p,i));
      /* Swap other information */
      M_32_SWAP(KEY_OFF(p, i));
      M_32_SWAP(KEY_LEN(p, i));
      M_32_SWAP(DATAP_OFF(p, i));
    }
    break;
  case HASH_DATA_PAGE:
    /* get next data item header position */
    next = FIRST_DATA_POS(p);
    M_32_SWAP(FIRST_DATA_POS(p));
    for (i = 0; i < num; i++) {
      /* get data header and next item before swapping */
      header = BIG_DATA_HEADER(p, next);

#ifdef _FFDB_DEBUG
      fprintf (stderr, "data header len = %d, status = 0x%x next = %d key_page = %d key_idx = %d\n",
	       header->len, header->status, header->next, header->key_page, header->key_idx);
#endif

      next = header->next;
      M_DATA_HEADER_SWAP(header);
    }
    break;
  case HASH_FREE_PAGE:
    for (i = 0; i < num; i++) 
      /* swap the offset */
      M_32_SWAP(FREE_PAGE(p, i));
    break;
  case HASH_UINFO_PAGE:
    M_32_SWAP(USER_DATA_LEN(p));
    break;
  case HASH_CONFIG_PAGE:
    for (i = 0; i < num; i++) 
      M_CONFIG_INFO_SWAP(CONFIG_INFO(p, i));
    break;
  default:
    break;
  }
}
/**
 * Swap page meta information out before this page is written to disk
 */
Swap page meta information out before this page is written to disk
Swap page meta information out before this page is written to disk
static void
_ffdb_swap_page_metainfo_out (void *p)
{
  unsigned int i, next;
  unsigned int type = TYPE(p);
  unsigned int num = NUM_ENT(p);
  ffdb_data_header_t* header;
#ifdef _FFDB_DEBUG
  fprintf (stderr, "SWAP Header Write page %d \n", CURR_PGNO(p));
  fprintf (stderr, "Page Information: PGNO %d PREV PGNO %d NEXT PGNO %d PAGE SIGN 0x%x\n",
	   CURR_PGNO(p), PREV_PGNO(p),NEXT_PGNO(p), PAGE_SIGN(p));
  fprintf (stderr, "Page TYPE 0x%x OFFSET %d\n", TYPE(p), OFFSET(p));
#endif     
  M_32_SWAP(CURR_PGNO(p));
  M_32_SWAP(PREV_PGNO(p));
  M_32_SWAP(NEXT_PGNO(p));
  M_32_SWAP(PAGE_SIGN(p));
  M_16_SWAP(NUM_ENT(p));
  M_16_SWAP(TYPE(p));
  M_32_SWAP(CHKSUM(p));
  M_32_SWAP(OFFSET(p));
  switch (type) {
  case HASH_BUCKET_PAGE:
    for (i = 0; i < num; i++) {
      M_DATAP_SWAP(DATAP(p,i));
      M_32_SWAP(KEY_OFF(p, i));
      M_32_SWAP(KEY_LEN(p, i));
      M_32_SWAP(DATAP_OFF(p, i));
    }
    break;
  case HASH_DATA_PAGE:
    next = FIRST_DATA_POS(p);
    M_32_SWAP(FIRST_DATA_POS(p));
    for (i = 0; i < num; i++) {
      header = BIG_DATA_HEADER(p, next);
#ifdef _FFDB_DEBUG
      fprintf (stderr, "data header len = %d, status = 0x%x next = %d key_page = %d key_idx = %d\n",
	       header->len, header->status, header->next, header->key_page, header->key_idx);
#endif
      next = header->next;
      M_DATA_HEADER_SWAP(header);
    }
    break;
  case HASH_FREE_PAGE:
    for (i = 0; i < num; i++) 
      M_32_SWAP(FREE_PAGE(p, i));
    break;
  case HASH_UINFO_PAGE:
    M_32_SWAP(USER_DATA_LEN(p));
    break;
  case HASH_CONFIG_PAGE:
    for (i = 0; i < num; i++) 
      M_CONFIG_INFO_SWAP(CONFIG_INFO(p, i));
    break;
  default:
    break;
  }
}
static void _ffdb_swap_page_metainfo_out ( void * p ) { unsigned int i , next ; unsigned int type = TYPE ( p ) ; unsigned int num = NUM_ENT ( p ) ; ffdb_data_header_t * header ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , CURR_PGNO ( p ) ) ; fprintf ( stderr , " \n " , CURR_PGNO ( p ) , PREV_PGNO ( p ) , NEXT_PGNO ( p ) , PAGE_SIGN ( p ) ) ; fprintf ( stderr , " \n " , TYPE ( p ) , OFFSET ( p ) ) ; #endif M_32_SWAP ( CURR_PGNO ( p ) ) ; M_32_SWAP ( PREV_PGNO ( p ) ) ; M_32_SWAP ( NEXT_PGNO ( p ) ) ; M_32_SWAP ( PAGE_SIGN ( p ) ) ; M_16_SWAP ( NUM_ENT ( p ) ) ; M_16_SWAP ( TYPE ( p ) ) ; M_32_SWAP ( CHKSUM ( p ) ) ; M_32_SWAP ( OFFSET ( p ) ) ; switch ( type ) { case HASH_BUCKET_PAGE : for ( i = 0 ; i < num ; i ++ ) { M_DATAP_SWAP ( DATAP ( p , i ) ) ; M_32_SWAP ( KEY_OFF ( p , i ) ) ; M_32_SWAP ( KEY_LEN ( p , i ) ) ; M_32_SWAP ( DATAP_OFF ( p , i ) ) ; } break ; case HASH_DATA_PAGE : next = FIRST_DATA_POS ( p ) ; M_32_SWAP ( FIRST_DATA_POS ( p ) ) ; for ( i = 0 ; i < num ; i ++ ) { header = BIG_DATA_HEADER ( p , next ) ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , header -> len , header -> status , header -> next , header -> key_page , header -> key_idx ) ; #endif next = header -> next ; M_DATA_HEADER_SWAP ( header ) ; } break ; case HASH_FREE_PAGE : for ( i = 0 ; i < num ; i ++ ) M_32_SWAP ( FREE_PAGE ( p , i ) ) ; break ; case HASH_UINFO_PAGE : M_32_SWAP ( USER_DATA_LEN ( p ) ) ; break ; case HASH_CONFIG_PAGE : for ( i = 0 ; i < num ; i ++ ) M_CONFIG_INFO_SWAP ( CONFIG_INFO ( p , i ) ) ; break ; default : break ; } }
Swap page meta information out before this page is written to disk
Swap page meta information out before this page is written to disk
/* Swap other information */ /* get next data item header position */ /* get data header and next item before swapping */ /* swap the offset */