IDZEBRA  2.2.7
Typedefs | Functions
bfile.h File Reference

Zebra Block File Layer. More...

#include <yaz/yconfig.h>
#include <idzebra/util.h>

Go to the source code of this file.

Typedefs

typedef struct BFiles_structBFiles
 A collection of BFile(s). More...
 
typedef struct BFile_structBFile
 A Block File. More...
 

Functions

BFiles bfs_create (const char *spec, const char *base)
 creates a Block files collection More...
 
void bfs_destroy (BFiles bfiles)
 destroys a block files handle More...
 
void bf_close (BFile bf)
 closes a Block file (may call exit) More...
 
int bf_close2 (BFile bf)
 closes a Block file More...
 
BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag)
 opens and returns a Block file handle More...
 
int bf_read (BFile bf, zint no, int offset, int nbytes, void *buf)
 read from block file (may call exit) More...
 
int bf_read2 (BFile bf, zint no, int offset, int nbytes, void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
 read from block file More...
 
int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf)
 writes block of bytes to file (may call exit) More...
 
int bf_write2 (BFile bf, zint no, int offset, int nbytes, const void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
 writes block of bytes to file More...
 
ZEBRA_RES bf_cache (BFiles bfs, const char *spec)
 enables or disables shadow for block files More...
 
int bf_commitExists (BFiles bfs)
 Check if there is content in shadow area (to be committed). More...
 
int bf_commitExec (BFiles bfs) ZEBRA_GCC_ATTR((warn_unused_result))
 Executes commit operation. More...
 
void bf_commitClean (BFiles bfs, const char *spec)
 Cleans shadow files (remove them) More...
 
void bf_reset (BFiles bfs)
 Removes register and shadow completely. More...
 
int bfs_register_directory_stat (BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes)
 
int bfs_shadow_directory_stat (BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes)
 

Detailed Description

Zebra Block File Layer.

Providers an interface to a file system , AKA persistent storage. The interface allows safe updates - using a shadow file facility.

Definition in file bfile.h.

Typedef Documentation

◆ BFile

A Block File.

Definition at line 43 of file bfile.h.

◆ BFiles

A collection of BFile(s).

Definition at line 38 of file bfile.h.

Function Documentation

◆ bf_cache()

ZEBRA_RES bf_cache ( BFiles  bfs,
const char *  spec 
)

enables or disables shadow for block files

Parameters
bfsblock files
specsuch as "shadow:100M /other:200M"; or NULL to disable
Return values
ZEBRA_OKsuccessful. spec is OK
ZEBRA_FAILfailure.

Definition at line 95 of file bfile.c.

References BFiles_struct::base, BFiles_struct::cache_fname, BFiles_struct::commit_area, MFile_area_struct::dirs, mf_init(), mf_dir::name, ZEBRA_FAIL, and ZEBRA_OK.

Referenced by bf_commitClean(), tst(), zebra_commit_ex(), zebra_init(), and zebra_register_open().

◆ bf_close()

void bf_close ( BFile  bf)

closes a Block file (may call exit)

Parameters
bfblock file

Definition at line 139 of file bfile.c.

References bf_close2(), and zebra_exit().

Referenced by bf_open(), dict_bf_close(), isamb_close(), isamc_close(), isams_close(), rec_close(), recindex_close(), tst(), zebra_sort_close(), and zebra_sort_type().

◆ bf_close2()

int bf_close2 ( BFile  bf)

closes a Block file

Parameters
bfblock file
Return values
0success
-1failure

Definition at line 121 of file bfile.c.

References BFile_struct::cf, cf_close(), BFile_struct::mf, mf_close(), BFile_struct::rdwr_lock, and zebra_lock_rdwr_destroy().

Referenced by bf_close().

◆ bf_commitClean()

void bf_commitClean ( BFiles  bfs,
const char *  spec 
)

Cleans shadow files (remove them)

Parameters
bfsblock files
specshadow specification

Definition at line 321 of file bfile.c.

References bf_cache(), BFiles_struct::commit_area, mf_reset(), and unlink_cache().

Referenced by zebra_commit_ex(), and zebra_end_transaction().

◆ bf_commitExec()

int bf_commitExec ( BFiles  bfs)

Executes commit operation.

Parameters
bfsblock files

Definition at line 277 of file bfile.c.

References cf_close(), cf_commit(), cf_open(), BFiles_struct::commit_area, inf, mf_close(), mf_open(), open_cache(), and BFiles_struct::register_area.

Referenced by zebra_commit_ex().

◆ bf_commitExists()

int bf_commitExists ( BFiles  bfs)

Check if there is content in shadow area (to be committed).

Parameters
bfsblock files
Return values
1there is content in shadow area
0no content in shadow area

Definition at line 255 of file bfile.c.

References inf, and open_cache().

Referenced by zebra_commit_ex().

◆ bf_open()

BFile bf_open ( BFiles  bfs,
const char *  name,
int  block_size,
int  wflag 
)

opens and returns a Block file handle

Parameters
bfsblock files
namefilename
block_sizeblock size in bytes
wflag1=opened for read&write, 0=read only
Return values
0success
-1failure (can never happen as the code is now)

Definition at line 150 of file bfile.c.

References bf_close(), BFile_struct::block_size, BFiles_struct::cache_fname, BFile_struct::cf, cf_open(), BFiles_struct::commit_area, BFile_struct::mf, mf_open(), open_cache(), outf, BFile_struct::rdwr_lock, BFiles_struct::register_area, and zebra_lock_rdwr_init().

Referenced by dict_bf_open(), isamb_open2(), isamc_open(), isams_open(), rec_open(), recindex_open(), tst(), and zebra_sort_type().

◆ bf_read()

int bf_read ( BFile  bf,
zint  no,
int  offset,
int  nbytes,
void *  buf 
)

read from block file (may call exit)

Parameters
bfblock file handle
noblock no (first block is 0, second is 1..)
offsetoffset within block to be read
nbytesnumber of bytes to read (0 for whole block)
bufraw bytes with content (at least nbytes of size)
Return values
1whole block could be read
0whole block could not be read

Definition at line 205 of file bfile.c.

References bf_read2(), and zebra_exit().

Referenced by alloc_block(), cache_block(), dict_bf_readp(), isamb_open2(), isamc_open(), isamc_read_block(), isams_open(), isams_pp_open(), isams_read_item(), new_block(), open_block(), rec_get_int(), rec_prstat(), rec_release_blocks(), rec_write_tmp_buf(), recindex_read_head(), recindex_read_indx(), tst(), zebra_sort_read(), and zebra_sort_type().

◆ bf_read2()

int bf_read2 ( BFile  bf,
zint  no,
int  offset,
int  nbytes,
void *  buf 
)

read from block file

Parameters
bfblock file handle
noblock no (first block is 0, second is 1..)
offsetoffset within block to be read
nbytesnumber of bytes to read (0 for whole block)
bufraw bytes with content (at least nbytes of size)
Return values
1whole block could be read
0whole block could not be read
-1error

Definition at line 216 of file bfile.c.

References BFile_struct::cf, cf_read(), BFile_struct::mf, mf_read(), BFile_struct::rdwr_lock, zebra_lock_rdwr_rlock(), and zebra_lock_rdwr_runlock().

Referenced by bf_read().

◆ bf_reset()

void bf_reset ( BFiles  bfs)

Removes register and shadow completely.

Parameters
bfsblock files

Definition at line 268 of file bfile.c.

References BFiles_struct::commit_area, mf_reset(), BFiles_struct::register_area, and unlink_cache().

Referenced by main(), tst(), and zebra_init().

◆ bf_write()

int bf_write ( BFile  bf,
zint  no,
int  offset,
int  nbytes,
const void *  buf 
)

writes block of bytes to file (may call exit)

Parameters
bfblock file handle
noblock no
offsetwithin block
nbytesnumber of bytes to write
bufbuffer to write
Return values
0success (block could be written)

This function can not return a failure. System calls exit(1) if write failed.

Definition at line 232 of file bfile.c.

References bf_write2(), and zebra_exit().

Referenced by cache_block(), close_block(), dict_bf_flush_blocks(), flush_blocks(), isamb_close(), isamc_close(), isamc_merge(), isamc_write_block(), isams_close(), isams_merge(), rec_release_blocks(), rec_write_tmp_buf(), recindex_write_head(), recindex_write_indx(), release_block(), tst(), zebra_sort_add(), and zebra_sort_delete().

◆ bf_write2()

int bf_write2 ( BFile  bf,
zint  no,
int  offset,
int  nbytes,
const void *  buf 
)

writes block of bytes to file

Parameters
bfblock file handle
noblock no
offsetwithin block
nbytesnumber of bytes to write
bufbuffer to write
Return values
0success (block written)
-1error

This function can not return a failure. System calls exit(1) if write failed.

Definition at line 243 of file bfile.c.

References BFile_struct::cf, cf_write(), BFile_struct::mf, mf_write(), BFile_struct::rdwr_lock, zebra_lock_rdwr_wlock(), and zebra_lock_rdwr_wunlock().

Referenced by bf_write().

◆ bfs_create()

BFiles bfs_create ( const char *  spec,
const char *  base 
)

creates a Block files collection

Parameters
specregister specification , e.g. "d1:100M d2:1G"
basebase directory for register spec (if that is relative path)
Returns
block files handle

Definition at line 56 of file bfile.c.

References BFiles_struct::base, bfs_destroy(), BFiles_struct::cache_fname, BFiles_struct::commit_area, mf_init(), and BFiles_struct::register_area.

Referenced by main(), tst(), zebra_commit_ex(), zebra_compact(), zebra_end_transaction(), zebra_init(), and zebra_register_open().

◆ bfs_destroy()

void bfs_destroy ( BFiles  bfiles)

destroys a block files handle

Parameters
bfilesblock files handle

The files in the block files collection are not deleted. Only the handle is freed.

Definition at line 73 of file bfile.c.

References BFiles_struct::base, BFiles_struct::cache_fname, BFiles_struct::commit_area, mf_destroy(), and BFiles_struct::register_area.

Referenced by bfs_create(), main(), tst(), zebra_commit_ex(), zebra_compact(), zebra_end_transaction(), zebra_init(), zebra_register_close(), and zebra_register_open().

◆ bfs_register_directory_stat()

int bfs_register_directory_stat ( BFiles  bfs,
int  no,
const char **  directory,
double *  used_bytes,
double *  max_bytes 
)

Definition at line 338 of file bfile.c.

References mf_area_directory_stat(), and BFiles_struct::register_area.

Referenced by show_bfs_stats().

◆ bfs_shadow_directory_stat()

int bfs_shadow_directory_stat ( BFiles  bfs,
int  no,
const char **  directory,
double *  used_bytes,
double *  max_bytes 
)

Definition at line 346 of file bfile.c.

References BFiles_struct::commit_area, and mf_area_directory_stat().

Referenced by show_bfs_stats().