IDZEBRA  2.1.2
Data Structures | Macros | Typedefs | Functions
mfile.h File Reference
#include <stdio.h>
#include <yaz/yconfig.h>
#include <idzebra/version.h>
#include <idzebra/util.h>
#include <sys/types.h>
#include <sys/param.h>
#include <zebra-lock.h>

Go to the source code of this file.

Data Structures

struct  mf_dir
 
struct  part_file
 
struct  meta_file
 
struct  MFile_area_struct
 

Macros

#define mfile_seek   lseek
 
#define FILENAME_MAX   MAXPATHLEN
 
#define MF_MIN_BLOCKS_CREAT   1 /* minimum free blocks in new dir */
 
#define MF_MAX_PARTS   28 /* max # of part-files per metafile */
 
#define mf_blocksize(mf)   ((mf)->blocksize)
 

Typedefs

typedef off_t mfile_off_t
 
typedef struct mf_dir mf_dir
 
typedef struct part_file part_file
 
typedef struct MFile_area_structMFile_area
 
typedef struct meta_fileMFile
 
typedef struct meta_file meta_file
 

Functions

MFile_area mf_init (const char *name, const char *spec, const char *base, int only_shadow_files) ZEBRA_GCC_ATTR((warn_unused_result))
 creates a metafile area More...
 
void mf_destroy (MFile_area ma)
 destroys metafile area handle More...
 
MFile mf_open (MFile_area ma, const char *name, int block_size, int wflag) ZEBRA_GCC_ATTR((warn_unused_result))
 opens metafile More...
 
int mf_close (MFile mf)
 closes metafile More...
 
int mf_read (MFile mf, zint no, int offset, int nbytes, void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
 reads block from metafile More...
 
int mf_write (MFile mf, zint no, int offset, int nbytes, const void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
 writes block to metafile More...
 
void mf_reset (MFile_area ma, int unlink_flag)
 reset all files in a metafile area (optionally delete them as well) More...
 
int mf_area_directory_stat (MFile_area ma, int no, const char **directory, double *bytes_used, double *bytes_max)
 metafile area statistics More...
 

Macro Definition Documentation

#define FILENAME_MAX   MAXPATHLEN
#define mf_blocksize (   mf)    ((mf)->blocksize)

Definition at line 52 of file mfile.h.

#define MF_MAX_PARTS   28 /* max # of part-files per metafile */

Definition at line 50 of file mfile.h.

#define MF_MIN_BLOCKS_CREAT   1 /* minimum free blocks in new dir */

Definition at line 49 of file mfile.h.

Referenced by mf_open().

#define mfile_seek   lseek

Definition at line 37 of file mfile.h.

Referenced by file_position(), and mf_init().

Typedef Documentation

typedef struct meta_file meta_file
typedef struct mf_dir mf_dir
typedef struct meta_file * MFile
typedef struct MFile_area_struct* MFile_area

Definition at line 75 of file mfile.h.

typedef off_t mfile_off_t

Definition at line 36 of file mfile.h.

typedef struct part_file part_file

Function Documentation

int mf_area_directory_stat ( MFile_area  ma,
int  no,
const char **  directory,
double *  used_bytes,
double *  max_bytes 
)

metafile area statistics

Parameters
mametafile area handle
noarea number (0=first, 1=second, ..)
directoryholds directory upon completion (if non-NULL)
used_bytesholds used bytes upon completion (if non-NULL)
max_bytesholds max size bytes upon completion (if non-NULL)
Return values
0area number does not exist
1area number exists (and directory,used_bytes,.. are set)

Definition at line 609 of file mfile.c.

References MFile_area_struct::dirs, mf_dir::name, and mf_dir::next.

Referenced by bfs_register_directory_stat(), and bfs_shadow_directory_stat().

int mf_close ( MFile  mf)

closes metafile

Parameters
mfmetafile handle
Return values
0OK

Definition at line 429 of file mfile.c.

References part_file::fd, meta_file::files, meta_file::name, meta_file::no_files, meta_file::open, and meta_file::wr.

Referenced by bf_close2(), bf_commitExec(), cf_close(), and tst2().

void mf_destroy ( MFile_area  ma)

destroys metafile area handle

Parameters
mametafile area handle

Definition at line 307 of file mfile.c.

References MFile_area_struct::dirs, mf_reset(), and mf_dir::next.

Referenced by bfs_destroy(), mf_init(), tst1(), and tst2().

MFile_area mf_init ( const char *  name,
const char *  spec,
const char *  base,
int  only_shadow_files 
)

creates a metafile area

Parameters
nameof area (does not show up on disk - purely for notation)
specarea specification (e.g. "/a:1G dir /b:2000M"
basebase directory (NULL for no base)
only_shadow_filesonly consider shadow files in area
Returns
metafile area handle or NULL if error occurs

Definition at line 195 of file mfile.c.

References mf_dir::avail_bytes, part_file::bytes, cmp_part_file(), meta_file::cur_file, part_file::dir, MFile_area_struct::dirs, fd, part_file::fd, FILENAME_MAX, meta_file::files, meta_file::ma, mf_dir::max_bytes, mf_destroy(), mfile_seek, MFile_area_struct::mfiles, meta_file::mutex, mf_dir::name, meta_file::name, MFile_area_struct::name, mf_dir::next, meta_file::next, meta_file::no_files, part_file::number, O_BINARY, meta_file::open, part_file::path, scan_areadef(), and zebra_mutex_init().

Referenced by bf_cache(), bfs_create(), tst1(), and tst2().

MFile mf_open ( MFile_area  ma,
const char *  name,
int  block_size,
int  wflag 
)

opens metafile

Parameters
mametafile area handle
namepseudo filename (name*.mf)
block_sizeblock size for this file
wflagwrite flag, 0=read, 1=write&read
Returns
metafile handle, or NULL for error (could not be opened)

Definition at line 351 of file mfile.c.

References mf_dir::avail_bytes, part_file::blocks, meta_file::blocksize, part_file::bytes, meta_file::cur_file, part_file::dir, MFile_area_struct::dirs, part_file::fd, FILENAME_MAX, meta_file::files, meta_file::ma, mf_dir::max_bytes, MF_MIN_BLOCKS_CREAT, MFile_area_struct::mfiles, meta_file::min_bytes_creat, meta_file::mutex, mf_dir::name, meta_file::name, mf_dir::next, meta_file::next, meta_file::no_files, part_file::number, meta_file::open, part_file::path, part_file::top, meta_file::wr, and zebra_mutex_init().

Referenced by bf_commitExec(), bf_open(), cf_open(), and tst2().

int mf_read ( MFile  mf,
zint  no,
int  offset,
int  nbytes,
void *  buf 
)

reads block from metafile

Parameters
mfmetafile handle
noblock position
offsetoffset within block
nbytesno of bytes to read (0 for whole block)
bufcontent (filled with data if OK)
Return values
0block partially read
1block fully read
-1block could not be read due to error

Definition at line 451 of file mfile.c.

References meta_file::blocksize, meta_file::cur_file, part_file::fd, file_position(), meta_file::files, meta_file::mutex, meta_file::name, part_file::path, zebra_mutex_lock(), and zebra_mutex_unlock().

Referenced by bf_read2(), cf_commit_flat(), cf_commit_hash(), cf_lookup_flat(), cf_moveto_flat(), cf_open(), cf_read(), cf_write(), get_bucket(), read_head(), and tst2().

void mf_reset ( MFile_area  ma,
int  unlink_flag 
)

reset all files in a metafile area (optionally delete them as well)

Parameters
mametafile area
unlink_flagif unlink_flag=1 all files are removed from FS

Definition at line 324 of file mfile.c.

References meta_file::files, MFile_area_struct::mfiles, meta_file::mutex, meta_file::next, meta_file::no_files, meta_file::open, part_file::path, and zebra_mutex_destroy().

Referenced by bf_commitClean(), bf_reset(), mf_destroy(), and tst2().

int mf_write ( MFile  mf,
zint  no,
int  offset,
int  nbytes,
const void *  buf 
)

writes block to metafile

Parameters
mfmetafile handle
noblock position
offsetoffset within block
nbytesno of bytes to write (0 for whole block)
bufcontent to be written
Return values
0block written
-1error (block not written)

Definition at line 484 of file mfile.c.

References mf_dir::avail_bytes, part_file::blocks, meta_file::blocksize, part_file::bytes, meta_file::cur_file, part_file::dir, MFile_area_struct::dirs, part_file::fd, file_position(), FILENAME_MAX, meta_file::files, meta_file::ma, mf_dir::max_bytes, meta_file::mutex, mf_dir::name, meta_file::name, mf_dir::next, meta_file::no_files, part_file::number, part_file::path, part_file::top, zebra_mutex_lock(), zebra_mutex_unlock(), and ZINT_FORMAT.

Referenced by bf_write2(), cf_close(), cf_commit_flat(), cf_commit_hash(), cf_open(), cf_write(), cf_write_flat(), flush_bucket(), tst2(), and write_head().