int rc759_nvm_set_fname (rc759_nvm_t *nvm, const char *fname) { if (nvm->fname != NULL) { free (nvm->fname); nvm->fname = NULL; } if (fname == NULL) { return (0); } nvm->fname = str_copy_alloc (fname); if (nvm->fname == NULL) { return (1); } return (0); }
// add information about physical segment to global variable pv_segments void add_segment(char *pv_name, char *vg_name, char *vg_format, char *vg_attr, char *lv_name, char *pv_type, uint64_t pv_start, uint64_t pv_length, uint64_t lv_start) { if(pv_segments_num==0) pv_segments = calloc(sizeof(struct pv_allocations), 1); if(!pv_segments) goto segment_failure; #define str_copy_alloc(N, X) pv_segments[(N)].X = malloc(strlen(X)+1); \ if(!pv_segments[(N)].X) \ goto segment_failure; \ strcpy(pv_segments[(N)].X, X); if (pv_segments_num==0) { str_copy_alloc(0, pv_name); str_copy_alloc(0, vg_name); str_copy_alloc(0, vg_format); str_copy_alloc(0, vg_attr); str_copy_alloc(0, lv_name); str_copy_alloc(0, pv_type); pv_segments[0].pv_start = pv_start; pv_segments[0].pv_length = pv_length; pv_segments[0].lv_start = lv_start; pv_segments_num=1; return; } pv_segments = realloc(pv_segments, sizeof(struct pv_allocations)*(pv_segments_num+1)); if (!pv_segments) goto segment_failure; str_copy_alloc(pv_segments_num, pv_name); str_copy_alloc(pv_segments_num, vg_name); str_copy_alloc(pv_segments_num, vg_format); str_copy_alloc(pv_segments_num, vg_attr); str_copy_alloc(pv_segments_num, lv_name); str_copy_alloc(pv_segments_num, pv_type); pv_segments[pv_segments_num].pv_start = pv_start; pv_segments[pv_segments_num].pv_length = pv_length; pv_segments[pv_segments_num].lv_start = lv_start; pv_segments_num+=1; return; segment_failure: fprintf(stderr, "Out of memory\n"); exit(1); #undef str_copy_alloc }