2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2012-10-29 18:54:31 -04:00
|
|
|
* Copyright 2001, 2012 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
|
|
|
|
#include "gtm_string.h"
|
|
|
|
|
|
|
|
#include "gdsroot.h"
|
|
|
|
#include "gtm_facility.h"
|
|
|
|
#include "fileinfo.h"
|
|
|
|
#include "gdsbt.h"
|
|
|
|
#include "gdsfhead.h"
|
|
|
|
#include "gdsblk.h"
|
|
|
|
#include "copy.h"
|
|
|
|
#include "dse.h"
|
|
|
|
|
|
|
|
/* Include prototypes */
|
|
|
|
#include "t_qread.h"
|
|
|
|
#include "mmemory.h"
|
|
|
|
|
|
|
|
GBLREF char patch_comp_key[MAX_KEY_SZ + 1];
|
2012-03-24 14:06:46 -04:00
|
|
|
GBLREF block_id patch_find_blk, patch_left_sib, patch_right_sib;
|
|
|
|
GBLREF block_id patch_path[MAX_BT_DEPTH + 1], patch_path1[MAX_BT_DEPTH + 1];
|
2012-02-05 11:35:58 -05:00
|
|
|
GBLREF bool patch_find_root_search;
|
2012-03-24 14:06:46 -04:00
|
|
|
GBLREF sgmnt_addrs *cs_addrs;
|
|
|
|
GBLREF short int patch_path_count;
|
2012-10-29 18:54:31 -04:00
|
|
|
GBLREF unsigned short patch_comp_count;
|
2012-03-24 14:06:46 -04:00
|
|
|
|
|
|
|
error_def(ERR_DSEBLKRDFAIL);
|
2012-02-05 11:35:58 -05:00
|
|
|
|
|
|
|
int dse_order(block_id srch,
|
|
|
|
block_id_ptr_t pp,
|
|
|
|
int4 *op,
|
|
|
|
char *targ_key,
|
|
|
|
short int targ_len,
|
|
|
|
bool dir_data_blk)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
sm_uc_ptr_t bp, b_top, key_top, ptr, rp, r_top;
|
2012-10-29 18:54:31 -04:00
|
|
|
unsigned short cc;
|
|
|
|
int tmp_cmpc;
|
2012-02-05 11:35:58 -05:00
|
|
|
block_id last;
|
2012-03-24 14:06:46 -04:00
|
|
|
short int rsize, size;
|
2012-02-05 11:35:58 -05:00
|
|
|
int4 dummy_int;
|
|
|
|
cache_rec_ptr_t dummy_cr;
|
|
|
|
|
|
|
|
last = 0;
|
|
|
|
patch_path_count++;
|
2012-03-24 14:06:46 -04:00
|
|
|
if (!(bp = t_qread(srch, &dummy_int, &dummy_cr)))
|
2012-02-05 11:35:58 -05:00
|
|
|
rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL);
|
2012-03-24 14:06:46 -04:00
|
|
|
if (((blk_hdr_ptr_t)bp)->bsiz > cs_addrs->hdr->blk_size)
|
2012-02-05 11:35:58 -05:00
|
|
|
b_top = bp + cs_addrs->hdr->blk_size;
|
2012-03-24 14:06:46 -04:00
|
|
|
else if (SIZEOF(blk_hdr) > ((blk_hdr_ptr_t)bp)->bsiz)
|
2012-02-05 11:35:58 -05:00
|
|
|
b_top = bp + SIZEOF(blk_hdr);
|
|
|
|
else
|
2012-03-24 14:06:46 -04:00
|
|
|
b_top = bp + ((blk_hdr_ptr_t)bp)->bsiz;
|
2012-02-05 11:35:58 -05:00
|
|
|
patch_comp_count = 0;
|
|
|
|
patch_comp_key[0] = patch_comp_key[1] = 0;
|
|
|
|
for (rp = bp + SIZEOF(blk_hdr); rp < b_top ;rp = r_top, last = *pp)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
GET_SHORT(rsize, &((rec_hdr_ptr_t)rp)->rsiz);
|
|
|
|
if (SIZEOF(rec_hdr) > rsize)
|
2012-02-05 11:35:58 -05:00
|
|
|
r_top = rp + SIZEOF(rec_hdr);
|
|
|
|
else
|
|
|
|
r_top = rp + rsize;
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((r_top > b_top) || (r_top == b_top && ((blk_hdr*)bp)->levl))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
2012-10-29 18:54:31 -04:00
|
|
|
if ((SIZEOF(rec_hdr) + SIZEOF(block_id) != (b_top - rp)) || EVAL_CMPC((rec_hdr *)rp))
|
2012-02-05 11:35:58 -05:00
|
|
|
return FALSE;
|
|
|
|
if (dir_data_blk && !((blk_hdr_ptr_t)bp)->levl)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
for (ptr = rp + SIZEOF(rec_hdr); (*ptr++ || *ptr++) && (ptr <= b_top);)
|
|
|
|
;
|
|
|
|
GET_LONGP(pp, ptr);
|
2012-02-05 11:35:58 -05:00
|
|
|
} else
|
2012-03-24 14:06:46 -04:00
|
|
|
GET_LONGP(pp, b_top - SIZEOF(block_id));
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
} else
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((SIZEOF(block_id) + SIZEOF(rec_hdr)) > (r_top - rp))
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
if (dir_data_blk && !((blk_hdr_ptr_t)bp)->levl)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
for (ptr = rp + SIZEOF(rec_hdr); (*ptr++ || *ptr++) && (ptr <= r_top);)
|
|
|
|
;
|
2012-02-05 11:35:58 -05:00
|
|
|
key_top = ptr;
|
|
|
|
} else
|
|
|
|
key_top = r_top - SIZEOF(block_id);
|
2012-10-29 18:54:31 -04:00
|
|
|
if (EVAL_CMPC((rec_hdr_ptr_t)rp) > patch_comp_count)
|
2012-02-05 11:35:58 -05:00
|
|
|
cc = patch_comp_count;
|
|
|
|
else
|
2012-10-29 18:54:31 -04:00
|
|
|
cc = EVAL_CMPC((rec_hdr_ptr_t)rp);
|
2012-02-05 11:35:58 -05:00
|
|
|
size = key_top - rp - SIZEOF(rec_hdr);
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((SIZEOF(patch_comp_key) - 2 - cc) < size)
|
2012-02-05 11:35:58 -05:00
|
|
|
size = SIZEOF(patch_comp_key) - 2 - cc;
|
2012-03-24 14:06:46 -04:00
|
|
|
if (0 > size)
|
2012-02-05 11:35:58 -05:00
|
|
|
size = 0;
|
|
|
|
memcpy(&patch_comp_key[cc], rp + SIZEOF(rec_hdr), size);
|
|
|
|
patch_comp_count = cc + size;
|
2012-03-24 14:06:46 -04:00
|
|
|
GET_LONGP(pp, key_top);
|
|
|
|
if (0 >= memvcmp(targ_key, targ_len, patch_comp_key, patch_comp_count))
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*op = (int4)(rp - bp);
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((*pp == patch_find_blk) && !dir_data_blk)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
patch_left_sib = last;
|
|
|
|
if (r_top < b_top)
|
|
|
|
{
|
|
|
|
rp = r_top;
|
2012-03-24 14:06:46 -04:00
|
|
|
GET_SHORT(rsize, &((rec_hdr_ptr_t)r_top)->rsiz);
|
2012-02-05 11:35:58 -05:00
|
|
|
r_top = rp + rsize;
|
|
|
|
if (r_top > b_top)
|
|
|
|
r_top = b_top;
|
2012-03-24 14:06:46 -04:00
|
|
|
if (SIZEOF(block_id) <= (r_top - rp))
|
|
|
|
GET_LONG(patch_right_sib, r_top - SIZEOF(block_id));
|
2012-02-05 11:35:58 -05:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((*pp > 0) && (*pp < cs_addrs->ti->total_blks) && (*pp % cs_addrs->hdr->bplmap))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((1 < ((blk_hdr_ptr_t)bp)->levl) && dse_order(*pp, pp + 1, op + 1, targ_key, targ_len, 0))
|
2012-02-05 11:35:58 -05:00
|
|
|
return TRUE;
|
2012-03-24 14:06:46 -04:00
|
|
|
else if ((1 == ((blk_hdr_ptr_t)bp)->levl) && patch_find_root_search)
|
|
|
|
return dse_order(*pp, pp + 1, op + 1, targ_key, targ_len, 1);
|
|
|
|
else if ((0 == ((blk_hdr_ptr_t)bp)->levl) && patch_find_root_search)
|
|
|
|
{
|
|
|
|
patch_find_root_search = FALSE;
|
2012-02-05 11:35:58 -05:00
|
|
|
return TRUE;
|
2012-03-24 14:06:46 -04:00
|
|
|
}
|
2012-02-05 11:35:58 -05:00
|
|
|
}
|
|
|
|
patch_path_count--;
|
|
|
|
return FALSE;
|
|
|
|
}
|