File: dse_shift.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (163 lines) | stat: -rw-r--r-- 4,394 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/****************************************************************
 *								*
 *	Copyright 2001, 2014 Fidelity Information Services, Inc	*
 *								*
 *	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 "min_max.h"		/* needed for gdsblkops.h */
#include "gdsblkops.h"
#include "gdscc.h"
#include "dse.h"
#include "cli.h"
#include "filestruct.h"
#include "jnl.h"
#include "util.h"

/* Include prototypes */
#include "t_qread.h"
#include "t_write.h"
#include "t_end.h"
#include "t_begin_crit.h"
#include "gvcst_blk_build.h"
#include "t_abort.h"
#include "gtmmsg.h"

GBLREF char		*update_array, *update_array_ptr;
GBLREF cw_set_element   cw_set[];
GBLREF gd_region        *gv_cur_region;
GBLREF sgmnt_addrs	*cs_addrs;
GBLREF sgmnt_data_ptr_t cs_data;
GBLREF srch_hist	dummy_hist;
GBLREF uint4		update_array_size;

error_def(ERR_AIMGBLKFAIL);
error_def(ERR_DBRDONLY);
error_def(ERR_DSEBLKRDFAIL);
error_def(ERR_DSEFAIL);

void dse_shift(void)
{
	blk_segment	*bs1, *bs_ptr;
	block_id	blk;
	boolean_t	forward;
	int4		blk_seg_cnt, blk_size, size;
	sm_uc_ptr_t	bp;
	srch_blk_status	blkhist;
	uchar_ptr_t	lbp;
	uint4		offset, shift;

        if (gv_cur_region->read_only)
                rts_error_csa(CSA_ARG(cs_addrs) VARLSTCNT(4) ERR_DBRDONLY, 2, DB_LEN_STR(gv_cur_region));
	CHECK_AND_RESET_UPDATE_ARRAY;	/* reset update_array_ptr to update_array */
	if (BADDSEBLK == (blk = dse_getblk("BLOCK", DSENOBML, DSEBLKCUR)))		/* WARNING: assignment */
		return;
	if (CLI_PRESENT != cli_present("OFFSET"))
	{
		util_out_print("Error:  offset must be specified.", TRUE);
		return;
	}
	if (!cli_get_hex("OFFSET", &offset))
		return;
	shift = 0;
	if (CLI_PRESENT == cli_present("FORWARD"))
	{
		if (!cli_get_hex("FORWARD", &shift))
			return;
		forward = TRUE;
		lbp = (unsigned char *)malloc((size_t)shift);
	} else if (CLI_PRESENT == cli_present("BACKWARD"))
	{
		if (!cli_get_hex("BACKWARD", &shift))
			return;
                if (shift > offset)
		{
		  	util_out_print("Error: shift greater than offset not allowed.", TRUE);
			return;
                }
		forward = FALSE;
		lbp = (unsigned char *)0;
	}
	if (!shift)
	{
		util_out_print("Error:  must specify amount to shift.", TRUE);
		if (lbp)
			free(lbp);
		return;
	}
	blk_size = cs_addrs->hdr->blk_size;
	t_begin_crit(ERR_DSEFAIL);
	blkhist.blk_num = blk;
	if (!(blkhist.buffaddr = t_qread(blkhist.blk_num, &blkhist.cycle, &blkhist.cr)))
	{
		if (lbp)
			free(lbp);
		rts_error_csa(CSA_ARG(cs_addrs) VARLSTCNT(1) ERR_DSEBLKRDFAIL);
	}
	bp = blkhist.buffaddr;
	size = ((blk_hdr *)bp)->bsiz;
	if (size < 0)
		size = 0;
	else if (size > cs_addrs->hdr->blk_size)
		size = cs_addrs->hdr->blk_size;
	if (offset < SIZEOF(blk_hdr) || offset > size)
	{
		util_out_print("Error:  offset not in range of block.", TRUE);
		t_abort(gv_cur_region, cs_addrs);
		if (lbp)
			free(lbp);
		return;
	}
	BLK_INIT(bs_ptr, bs1);
	if (forward)
	{
		if (shift + size >= cs_addrs->hdr->blk_size)
		{
			util_out_print("Error:  block not large enough to accommodate shift.", TRUE);
			t_abort(gv_cur_region, cs_addrs);
			if (lbp)
				free(lbp);
			return;
		}
		memset(lbp, 0, shift);
		BLK_SEG(bs_ptr, bp + SIZEOF(blk_hdr), offset - SIZEOF(blk_hdr));
		BLK_SEG(bs_ptr, lbp, shift);
		if (size - offset)
			BLK_SEG(bs_ptr, bp + offset, size - offset);
	} else
	{
		if (shift > offset)
			shift = offset - SIZEOF(blk_hdr);
		if (offset - shift > SIZEOF(blk_hdr))
			BLK_SEG(bs_ptr, bp + SIZEOF(blk_hdr), offset - shift - SIZEOF(blk_hdr));
		if (size - offset)
			BLK_SEG(bs_ptr, bp + offset, size - offset);
	}
	if (!BLK_FINI(bs_ptr, bs1))
	{
		gtm_putmsg_csa(CSA_ARG(cs_addrs) VARLSTCNT(5) ERR_AIMGBLKFAIL, 3, blk, DB_LEN_STR(gv_cur_region));
		t_abort(gv_cur_region, cs_addrs);
		if (lbp)
			free(lbp);
		return;
	}
	t_write(&blkhist, (unsigned char *)bs1, 0, 0, ((blk_hdr_ptr_t)bp)->levl, TRUE, FALSE, GDS_WRITE_KILLTN);
	BUILD_AIMG_IF_JNL_ENABLED(cs_data, cs_addrs->ti->curr_tn);
	t_end(&dummy_hist, NULL, TN_NOT_SPECIFIED);
	return;
}