1
1
/*****************************************************************************
2
* RRDtool 1.3.8 Copyright by Tobi Oetiker, 1997-2009
2
* RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
3
3
*****************************************************************************
4
4
* rrd_resize.c Alters size of an RRA
5
5
*****************************************************************************
6
6
* Initial version by Alex van den Bogaerdt
7
7
*****************************************************************************/
9
11
#include "rrd_tool.h"
87
86
rrd_close(rrd_file);
90
/* the size of the new file */
91
/* yes we are abusing the float cookie for this, aargh */
91
/* These need to be initialised before calling rrd_open() with
92
the RRD_CREATE flag */
92
94
if ((rrdnew.stat_head = (stat_head_t*)calloc(1, sizeof(stat_head_t))) == NULL) {
93
95
rrd_set_error("allocating stat_head for new RRD");
95
97
rrd_close(rrd_file);
98
rrdnew.stat_head->float_cookie = rrd_file->file_len +
99
(rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify);
100
memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t));
102
if ((rrdnew.rra_def = (rra_def_t *)malloc(sizeof(rra_def_t) * rrdold.stat_head->rra_cnt)) == NULL) {
103
rrd_set_error("allocating rra_def for new RRD");
109
memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);
111
/* Set this so that the file will be created with the correct size */
112
rrdnew.rra_def[target_rra].row_cnt += modify;
100
114
rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT);
101
115
if (rrd_out_file == NULL) {
102
116
rrd_set_error("Can't create '%s': %s", outfilename,
118
132
/*XXX: do one write for those parts of header that are unchanged */
119
if ((rrdnew.stat_head = (stat_head_t*)malloc(sizeof(stat_head_t))) == NULL) {
120
rrd_set_error("allocating stat_head for new RRD");
124
rrd_close(rrd_out_file);
128
if ((rrdnew.rra_ptr = (rra_ptr_t*)malloc(sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt)) == NULL) {
133
if ((rrdnew.rra_ptr = (rra_ptr_t *)malloc(sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt)) == NULL) {
129
134
rrd_set_error("allocating rra_ptr for new RRD");
130
135
rrd_free(&rrdnew);
131
136
rrd_free(&rrdold);
137
if ((rrdnew.rra_def = (rra_def_t*)malloc(sizeof(rra_def_t) * rrdold.stat_head->rra_cnt)) == NULL) {
138
rrd_set_error("allocating rra_def for new RRD");
142
rrd_close(rrd_out_file);
147
memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t));
142
/* Put this back the way it was so that the rest of the algorithm
143
below remains unchanged, it will be corrected later */
144
rrdnew.rra_def[target_rra].row_cnt -= modify;
148
146
rrdnew.ds_def = rrdold.ds_def;
149
memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);
150
147
rrdnew.live_head = rrdold.live_head;
151
148
rrdnew.pdp_prep = rrdold.pdp_prep;
152
149
rrdnew.cdp_prep = rrdold.cdp_prep;
153
150
memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt);
156
* For windows Other fields also should be allocated. Crashes otherwise
159
if ((rrdnew.ds_def = (ds_def_t*)malloc(sizeof(ds_def_t) * rrdold.stat_head->ds_cnt)) == NULL) {
160
rrd_set_error("allocating ds_def for new RRD");
164
rrd_close(rrd_out_file);
168
if ((rrdnew.live_head = (live_head_t*)malloc(sizeof(live_head_t))) == NULL) {
169
rrd_set_error("allocating live_head for new RRD");
173
rrd_close(rrd_out_file);
177
if ((rrdnew.pdp_prep = (pdp_prep_t*)malloc(sizeof(pdp_prep_t))) == NULL) {
178
rrd_set_error("allocating pdp_prep for new RRD");
182
rrd_close(rrd_out_file);
186
if ((rrdnew.cdp_prep = (cdp_prep_t*)malloc(sizeof(cdp_prep_t))) == NULL) {
187
rrd_set_error("allocating cdp_prep for new RRD");
191
rrd_close(rrd_out_file);
194
memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t));
195
memcpy(rrdnew.ds_def,rrdold.ds_def,sizeof(ds_def_t) * rrdold.stat_head->ds_cnt);
196
memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);
197
memcpy(rrdnew.live_head,rrdold.live_head,sizeof(live_head_t));
198
memcpy(rrdnew.pdp_prep,rrdold.pdp_prep,sizeof(pdp_prep_t));
199
memcpy(rrdnew.cdp_prep,rrdold.cdp_prep,sizeof(cdp_prep_t));
200
memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt);
203
153
version = atoi(rrdold.stat_head->version);
204
154
switch (version) {