int init_dpthl(struct dpthl *dpthl, struct asfd *asfd, struct sdirs *sdirs, struct conf *cconf) { char *tmp=NULL; //logp("in init_dpthl\n"); dpthl->looped=0; dpthl->prim=0; dpthl->seco=0; dpthl->tert=0; if((dpthl->prim=get_highest_entry(sdirs->currentdata))<0) { // Could not open directory. Set all zeros. dpthl->prim=0; // mk_dpthl(dpthl, cconf); return 0; } mk_dpthl_prim(dpthl); if(!(tmp=prepend_s(sdirs->currentdata, dpthl->path))) { log_and_send_oom(asfd, __func__); return -1; } if((dpthl->seco=get_highest_entry(tmp))<0) { // Could not open directory. Set zero. dpthl->seco=0; // mk_dpthl(dpthl, cconf); free(tmp); return 0; } free(tmp); mk_dpthl_seco(dpthl); if(!(tmp=prepend_s(sdirs->currentdata, dpthl->path))) { log_and_send_oom(asfd, __func__); return -1; } if((dpthl->tert=get_highest_entry(tmp))<0) { // Could not open directory. Set zero. dpthl->tert=0; // mk_dpthl(dpthl, cconf); free(tmp); return 0; } // At this point, we have the latest data file. Increment to get the // next free one. if(incr_dpthl(dpthl, cconf)) return -1; //logp("init_dpthl: %d/%d/%d\n", dpthl->prim, dpthl->seco, dpthl->tert); //logp("init_dpthl: %s\n", dpthl->path); return 0; }
static int manio_open_last_fpath(struct manio *manio) { int max=-1; if(is_single_file(manio)) return manio_open_next_fpath(manio); if(get_highest_entry(manio->manifest, &max, 8)) return -1; if(max<0) max=0; manio->offset->fcount=(uint64_t)max; return manio_open_next_fpath(manio); }
int dpth_init(struct dpth *dpth) { int max; int ret=0; char *tmp=NULL; if(get_highest_entry(dpth->base_path, &max, NULL)) goto error; if(max<0) max=0; dpth->prim=max; tmp=dpth_mk_prim(dpth); if(!(tmp=prepend_s(dpth->base_path, tmp))) goto error; if(get_highest_entry(tmp, &max, NULL)) goto error; if(max<0) max=0; dpth->seco=max; free(tmp); tmp=dpth_mk_seco(dpth); if(!(tmp=prepend_s(dpth->base_path, tmp))) goto error; if(get_next_entry(tmp, &max, dpth)) goto error; if(max<0) max=0; dpth->tert=max; dpth->sig=0; dpth->need_data_lock=1; goto end; error: ret=-1; end: if(tmp) free(tmp); return ret; }
static int get_next_entry(const char *path, int *max, struct dpth *dpth) { if(get_highest_entry(path, max, dpth)) return -1; (*max)++; return 0; }