- off_t newfile_size = 0;
-
- if (rdwr & RRD_CREAT) {
- /* yes bad inline signaling alert, we are using the
- floatcookie to pass the size in ... only used in resize */
- newfile_size = (off_t) rrd->stat_head->float_cookie;
- free(rrd->stat_head);
+ rrd_simple_file_t *rrd_simple_file = NULL;
+ size_t newfile_size = 0;
+ size_t header_len, value_cnt, data_len;
+
+ /* Are we creating a new file? */
+ if((rdwr & RRD_CREAT) && (rrd->stat_head != NULL))
+ {
+ header_len = \
+ sizeof(stat_head_t) + \
+ sizeof(ds_def_t) * rrd->stat_head->ds_cnt + \
+ sizeof(rra_def_t) * rrd->stat_head->rra_cnt + \
+ sizeof(time_t) + \
+ sizeof(live_head_t) + \
+ sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt + \
+ sizeof(cdp_prep_t) * rrd->stat_head->ds_cnt * rrd->stat_head->rra_cnt + \
+ sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt;
+
+ value_cnt = 0;
+ for (ui = 0; ui < rrd->stat_head->rra_cnt; ui++)
+ value_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[ui].row_cnt;
+
+ data_len = sizeof(rrd_value_t) * value_cnt;
+
+ newfile_size = header_len + data_len;