static char *rindex_buffer(lgfs2_rgrps_t rgs, unsigned count) { lgfs2_rgrp_t rg; unsigned i = 0; char *buf; buf = calloc(count, sizeof(struct gfs2_rindex)); if (buf == NULL) { perror(__FUNCTION__); exit(EXIT_FAILURE); } for (rg = lgfs2_rgrp_first(rgs); rg; rg = lgfs2_rgrp_next(rg)) { const struct gfs2_rindex *ri = lgfs2_rgrp_index(rg); gfs2_rindex_out(ri, buf + (sizeof(*ri) * i)); i++; } return buf; }
int build_rindex(struct gfs2_sbd *sdp) { struct gfs2_inode *ip; struct osi_node *n, *next = NULL; struct rgrp_tree *rl; char buf[sizeof(struct gfs2_rindex)]; int count; ip = createi(sdp->master_dir, "rindex", S_IFREG | 0600, GFS2_DIF_SYSTEM | GFS2_DIF_JDATA); if (ip == NULL) { return errno; } ip->i_di.di_payload_format = GFS2_FORMAT_RI; bmodified(ip->i_bh); for (n = osi_first(&sdp->rgtree); n; n = next) { next = osi_next(n); rl = (struct rgrp_tree *)n; gfs2_rindex_out(&rl->ri, buf); count = gfs2_writei(ip, buf, ip->i_di.di_size, sizeof(struct gfs2_rindex)); if (count != sizeof(struct gfs2_rindex)) return -1; } memset(buf, 0, sizeof(struct gfs2_rindex)); count = __gfs2_writei(ip, buf, ip->i_di.di_size, sizeof(struct gfs2_rindex), 0); if (count != sizeof(struct gfs2_rindex)) return -1; if (cfg_debug) { printf("\nResource Index:\n"); gfs2_dinode_print(&ip->i_di); } inode_put(&ip); return 0; }