IDZEBRA  2.1.2
Data Structures | Macros | Functions
bfile.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <yaz/xmalloc.h>
#include <idzebra/util.h>
#include <idzebra/bfile.h>
#include "mfile.h"
#include "cfile.h"

Go to the source code of this file.

Data Structures

struct  BFile_struct
 
struct  BFiles_struct
 

Macros

#define HEADER_SIZE   256
 

Functions

BFiles bfs_create (const char *spec, const char *base)
 creates a Block files collection More...
 
void bfs_destroy (BFiles bfs)
 destroys a block files handle More...
 
static FILE * open_cache (BFiles bfs, const char *flags)
 
static void unlink_cache (BFiles bfs)
 
ZEBRA_RES bf_cache (BFiles bfs, const char *spec)
 enables or disables shadow for block files More...
 
int bf_close2 (BFile bf)
 closes a Block file More...
 
void bf_close (BFile bf)
 closes a Block file (may call exit) More...
 
BFile bf_xopen (BFiles bfs, const char *name, int block_size, int wrflag, const char *magic, int *read_version, const char **more_info)
 opens and returns an extended Block file handle More...
 
int bf_xclose (BFile bf, int version, const char *more_info)
 closes an extended Block file handle.. 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)
 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)
 writes block of bytes to file More...
 
int bf_commitExists (BFiles bfs)
 Check if there is content in shadow area (to be committed). More...
 
void bf_reset (BFiles bfs)
 Removes register and shadow completely. More...
 
int bf_commitExec (BFiles bfs)
 Executes commit operation. More...
 
void bf_commitClean (BFiles bfs, const char *spec)
 Cleans shadow files (remove them) More...
 
int bf_alloc (BFile bf, int no, zint *blocks)
 Allocates one or more blocks in an extended block file. More...
 
int bf_free (BFile bf, int no, const zint *blocks)
 Releases one or more blocks in an extended block file. 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)
 

Macro Definition Documentation

#define HEADER_SIZE   256

Definition at line 160 of file bfile.c.

Referenced by bf_xopen().

Function Documentation

int bf_alloc ( BFile  bf,
int  no,
zint blocks 
)

Allocates one or more blocks in an extended block file.

Parameters
bfextended block file
nonumber of blocks to allocate
blocksoutput array of size no with block offsets

Definition at line 452 of file bfile.c.

References BFile_struct::alloc_buf, bf_read(), BFile_struct::free_list, BFile_struct::header_dirty, BFile_struct::last_block, zebra_zint_decode(), and ZINT_FORMAT.

Referenced by tst2(), and tst3().

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 105 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().

void bf_close ( BFile  bf)

closes a Block file (may call exit)

Parameters
bfblock file

Definition at line 151 of file bfile.c.

References bf_close2(), and zebra_exit().

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

int bf_close2 ( BFile  bf)

closes a Block file

Parameters
bfblock file
Return values
0success
-1failure

Definition at line 131 of file bfile.c.

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

Referenced by bf_close(), and bf_xclose().

void bf_commitClean ( BFiles  bfs,
const char *  spec 
)

Cleans shadow files (remove them)

Parameters
bfsblock files
specshadow specification

Definition at line 435 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().

int bf_commitExec ( BFiles  bfs)

Executes commit operation.

Parameters
bfsblock files

Definition at line 391 of file bfile.c.

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

Referenced by zebra_commit_ex().

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 369 of file bfile.c.

References inf, and open_cache().

Referenced by zebra_commit_ex().

int bf_free ( BFile  bf,
int  no,
const zint blocks 
)

Releases one or more blocks in an extended block file.

Parameters
bfextended block file
nonumer of blocks to release
blocksinput array with block offsets (IDs) to release

Definition at line 480 of file bfile.c.

References BFile_struct::alloc_buf, bf_write(), BFile_struct::free_list, BFile_struct::header_dirty, and zebra_zint_encode().

Referenced by tst2(), and tst3().

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 261 of file bfile.c.

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

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

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 319 of file bfile.c.

References bf_read2(), and zebra_exit().

Referenced by alloc_block(), bf_alloc(), bf_xopen(), cache_block(), dict_bf_readp(), isamb_open2(), isamc_open(), isamc_read_block(), isamc_write_dblock(), 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().

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 330 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().

void bf_reset ( BFiles  bfs)

Removes register and shadow completely.

Parameters
bfsblock files

Definition at line 382 of file bfile.c.

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

Referenced by main(), tst(), tst1(), tst2(), tst3(), and zebra_init().

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 346 of file bfile.c.

References bf_write2(), and zebra_exit().

Referenced by bf_free(), bf_xclose(), cache_block(), close_block(), dict_bf_flush_blocks(), flush_blocks(), isamb_close(), isamc_close(), isamc_merge(), isamc_write_block(), isamc_write_dblock(), 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().

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 357 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().

int bf_xclose ( BFile  bf,
int  version,
const char *  more_info 
)

closes an extended Block file handle..

Parameters
bfextended block file opened with bf_xopen
versionversion to be put in a file
more_infomore information to be stored in file (header)
Return values
0success
-1failure (can never happen as the code is now)

Definition at line 239 of file bfile.c.

References BFile_struct::alloc_buf, bf_close2(), bf_write(), BFile_struct::block_size, BFile_struct::free_list, BFile_struct::header_dirty, BFile_struct::last_block, BFile_struct::magic, and ZINT_FORMAT.

Referenced by tst1(), tst2(), and tst3().

BFile bf_xopen ( BFiles  bfs,
const char *  name,
int  block_size,
int  wflag,
const char *  magic,
int *  read_version,
const char **  more_info 
)

opens and returns an extended Block file handle

Parameters
bfsblock files
namefilename
block_sizeblock size in bytes
wflag1=opened for read&write, 0=read only
magicmagic string to be used for file
read_versionholds after completion of bf_xopen the version
more_infoholds more_info as read from file (header)

Definition at line 162 of file bfile.c.

References BFile_struct::alloc_buf, BFile_struct::alloc_buf_size, bf_close(), bf_open(), bf_read(), BFile_struct::block_size, BFile_struct::free_list, BFile_struct::header_dirty, HEADER_SIZE, BFile_struct::last_block, BFile_struct::magic, BFile_struct::root_block, and ZINT_FORMAT.

Referenced by tst1(), tst2(), and tst3().

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 63 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().

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 80 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().

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

Definition at line 497 of file bfile.c.

References mf_area_directory_stat(), and BFiles_struct::register_area.

Referenced by show_bfs_stats().

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

Definition at line 505 of file bfile.c.

References BFiles_struct::commit_area, and mf_area_directory_stat().

Referenced by show_bfs_stats().

static FILE* open_cache ( BFiles  bfs,
const char *  flags 
)
static

Definition at line 91 of file bfile.c.

References BFiles_struct::cache_fname.

Referenced by bf_commitExec(), bf_commitExists(), and bf_open().

static void unlink_cache ( BFiles  bfs)
static

Definition at line 99 of file bfile.c.

References BFiles_struct::cache_fname.

Referenced by bf_commitClean(), and bf_reset().