virtual void grow(std::size_t by) { //L_(info) << "growing store by " << by << " bytes"; sync(); filesize_ += by; bip::shared_memory_object::remove(filename_.c_str()); base_t::grow(filename_.c_str(), filesize_); base_t newstore(bip::open_only, filename_.c_str()); base_t::swap(newstore); }
struct store *newfstore(char *dir) { struct store *st; struct fstore *fst; char tbuf[1024]; struct loghdr lh; struct idxhdr ih; struct stat64 sb; fst = calloc(1, sizeof(*fst)); fst->logfd = -1; fst->idxfd = -1; snprintf(tbuf, sizeof(tbuf), "%s/log", dir); if((fst->logfd = open(tbuf, O_RDWR | O_LARGEFILE)) < 0) { flog(LOG_ERR, "could not open log %s: %s", tbuf, strerror(errno)); release(fst); return(NULL); } if(fstat64(fst->logfd, &sb)) { flog(LOG_ERR, "could not stat log: %s", strerror(errno)); release(fst); return(NULL); } fst->logsize = sb.st_size; if(readall(fst->logfd, &lh, sizeof(lh), 0)) { flog(LOG_ERR, "could not read log header: %s", strerror(errno)); release(fst); return(NULL); } if(memcmp(lh.magic, LOGMAGIC, sizeof(LOGMAGIC))) { flog(LOG_ERR, "invalid log magic"); release(fst); return(NULL); } snprintf(tbuf, sizeof(tbuf), "%s/index", dir); if((fst->idxfd = open(tbuf, O_RDWR | O_LARGEFILE)) < 0) { flog(LOG_ERR, "could not open index %s: %s", tbuf, strerror(errno)); release(fst); return(NULL); } if(fstat64(fst->idxfd, &sb)) { flog(LOG_ERR, "could not stat index: %s", strerror(errno)); release(fst); return(NULL); } if(readall(fst->idxfd, &ih, sizeof(ih), 0)) { flog(LOG_ERR, "could not read index header: %s", strerror(errno)); release(fst); return(NULL); } if(memcmp(ih.magic, IDXMAGIC, sizeof(IDXMAGIC))) { flog(LOG_ERR, "invalid index magic"); release(fst); return(NULL); } if(sb.st_size != (sizeof(struct idxhdr) + ih.size * sizeof(struct idxent))) { flog(LOG_ERR, "invalid index size"); release(fst); return(NULL); } fst->idxsize = ih.size; st = newstore(&fstops); st->pdata = fst; return(st); }