35 #include <yaz/xmalloc.h>
63 bfs->
base = xstrdup(base);
99 yaz_log(YLOG_LOG,
"enabling shadow spec=%s", spec);
108 yaz_log(YLOG_LOG,
"cache_fname = %s", bfs->
cache_fname);
112 yaz_log(YLOG_WARN,
"shadow could not be enabled");
148 #define HEADER_SIZE 256
168 yaz_log(YLOG_FATAL,
"cf_open failed for %s", name);
179 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"open %s", bfs->
cache_fname);
183 fprintf(
outf,
"%s %d\n", name, block_size);
186 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"fclose %s", bfs->
cache_fname);
198 yaz_log(YLOG_FATAL,
"mf_open failed for %s", name);
207 int ret =
bf_read2(bf, no, offset, nbytes, buf);
223 if ((ret =
cf_read(bf->
cf, no, offset, nbytes, buf)) == 0)
224 ret =
mf_read(bf->
mf, no, offset, nbytes, buf);
227 ret =
mf_read(bf->
mf, no, offset, nbytes, buf);
234 int ret =
bf_write2(bf, no, offset, nbytes, buf);
248 r =
cf_write(bf->
cf, no, offset, nbytes, buf);
250 r =
mf_write(bf->
mf, no, offset, nbytes, buf);
290 yaz_log(YLOG_LOG,
"No commit file");
293 while (fscanf(
inf,
"%s %d", path, &block_size) == 2)
339 double *used_bytes,
double *max_bytes)
342 used_bytes, max_bytes);
347 double *used_bytes,
double *max_bytes)
352 used_bytes, max_bytes);
int bf_write2(BFile bf, zint no, int offset, int nbytes, const void *buf)
writes block of bytes to file
int bf_read(BFile bf, zint no, int offset, int nbytes, void *buf)
read from block file (may call exit)
static FILE * open_cache(BFiles bfs, const char *flags)
int bf_read2(BFile bf, zint no, int offset, int nbytes, void *buf)
read from block file
ZEBRA_RES bf_cache(BFiles bfs, const char *spec)
enables or disables shadow for block files
int bfs_register_directory_stat(BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes)
void bf_close(BFile bf)
closes a Block file (may call exit)
BFile bf_open(BFiles bfs, const char *name, int block_size, int wflag)
opens and returns a Block file handle
static void unlink_cache(BFiles bfs)
int bf_write(BFile bf, zint no, int offset, int nbytes, const void *buf)
writes block of bytes to file (may call exit)
void bf_reset(BFiles bfs)
Removes register and shadow completely.
void bfs_destroy(BFiles bfs)
destroys a block files handle
void bf_commitClean(BFiles bfs, const char *spec)
Cleans shadow files (remove them)
int bf_close2(BFile bf)
closes a Block file
int bfs_shadow_directory_stat(BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes)
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
int bf_commitExec(BFiles bfs)
Executes commit operation.
int bf_commitExists(BFiles bfs)
Check if there is content in shadow area (to be committed).
struct BFile_struct * BFile
A Block File.
struct BFiles_struct * BFiles
A collection of BFile(s).
CFile cf_open(MFile mf, MFile_area area, const char *fname, int block_size, int wflag, int *firstp)
int cf_read(CFile cf, zint no, int offset, int nbytes, void *buf)
reads block from commit area
int cf_write(CFile cf, zint no, int offset, int nbytes, const void *buf)
writes block to commit area
int cf_commit(CFile cf) ZEBRA_GCC_ATTR((warn_unused_result))
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
writes block to metafile
int mf_area_directory_stat(MFile_area ma, int no, const char **directory, double *used_bytes, double *max_bytes)
metafile area statistics
int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
reads block from metafile
void mf_reset(MFile_area ma, int unlink_flag)
reset all files in a metafile area (optionally delete them as well)
void mf_destroy(MFile_area ma)
destroys metafile area handle
MFile_area mf_init(const char *name, const char *spec, const char *base, int only_shadow_files)
creates a metafile area
int mf_close(MFile mf)
closes metafile
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
opens metafile
Zebra_lock_rdwr rdwr_lock
All in-memory information per CFile.
char name[FILENAME_MAX+1]
void zebra_exit(const char *msg)
short ZEBRA_RES
Common return type for Zebra API.
int zebra_lock_rdwr_rlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_wlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_destroy(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_wunlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_runlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_init(Zebra_lock_rdwr *p)