IDZEBRA
2.2.7
|
#include <sys/types.h>
#include <fcntl.h>
#include <direntz.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <zebra-lock.h>
#include <idzebra/util.h>
#include <yaz/yaz-util.h>
#include <yaz/snprintf.h>
#include "mfile.h"
Go to the source code of this file.
Functions | |
static int | scan_areadef (MFile_area ma, const char *ad, const char *base) |
static zint | file_position (MFile mf, zint pos, int offset) |
position within metafile (perform seek) More... | |
static int | cmp_part_file (const void *p1, const void *p2) |
MFile_area | mf_init (const char *name, const char *spec, const char *base, int only_shadow_files) |
creates a metafile area More... | |
void | mf_destroy (MFile_area ma) |
destroys metafile area handle More... | |
void | mf_reset (MFile_area ma, int unlink_flag) |
reset all files in a metafile area (optionally delete them as well) More... | |
MFile | mf_open (MFile_area ma, const char *name, int block_size, int wflag) |
opens metafile More... | |
int | mf_close (MFile mf) |
closes metafile More... | |
int | mf_read (MFile mf, zint no, int offset, int nbytes, void *buf) |
reads block from metafile More... | |
int | mf_write (MFile mf, zint no, int offset, int nbytes, const void *buf) |
writes block to metafile More... | |
int | mf_area_directory_stat (MFile_area ma, int no, const char **directory, double *used_bytes, double *max_bytes) |
metafile area statistics More... | |
|
static |
position within metafile (perform seek)
mf | metafile handle |
pos | block position |
offset | offset within block |
0 | OK |
-1 | ERROR |
-2 | OK, but file does not created (read-only) |
Definition at line 139 of file mfile.c.
References part_file::blocks, meta_file::blocksize, meta_file::cur_file, part_file::fd, meta_file::files, mfile_seek, meta_file::no_files, O_BINARY, part_file::path, part_file::top, meta_file::wr, and ZINT_FORMAT.
Referenced by mf_read(), and mf_write().
int mf_area_directory_stat | ( | MFile_area | ma, |
int | no, | ||
const char ** | directory, | ||
double * | used_bytes, | ||
double * | max_bytes | ||
) |
metafile area statistics
ma | metafile area handle |
no | area number (0=first, 1=second, ..) |
directory | holds directory upon completion (if non-NULL) |
used_bytes | holds used bytes upon completion (if non-NULL) |
max_bytes | holds max size bytes upon completion (if non-NULL) |
0 | area number does not exist |
1 | area number exists (and directory,used_bytes,.. are set) |
Definition at line 612 of file mfile.c.
References mf_dir::avail_bytes, MFile_area_struct::dirs, mf_dir::max_bytes, 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
mf | metafile handle |
0 | OK |
Definition at line 431 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
ma | metafile area handle |
Definition at line 309 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
name | of area (does not show up on disk - purely for notation) |
spec | area specification (e.g. "/a:1G dir /b:2000M" |
base | base directory (NULL for no base) |
only_shadow_files | only consider shadow files in area |
Definition at line 196 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, part_file::fd, 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
ma | metafile area handle |
name | pseudo filename (name*.mf) |
block_size | block size for this file |
wflag | write flag, 0=read, 1=write&read |
Definition at line 353 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().
reads block from metafile
mf | metafile handle |
no | block position |
offset | offset within block |
nbytes | no of bytes to read (0 for whole block) |
buf | content (filled with data if OK) |
0 | block partially read |
1 | block fully read |
-1 | block could not be read due to error |
Definition at line 453 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)
ma | metafile area |
unlink_flag | if unlink_flag=1 all files are removed from FS |
Definition at line 326 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().
writes block to metafile
mf | metafile handle |
no | block position |
offset | offset within block |
nbytes | no of bytes to write (0 for whole block) |
buf | content to be written |
0 | block written |
-1 | error (block not written) |
Definition at line 486 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().
|
static |
Definition at line 44 of file mfile.c.
References MFile_area_struct::dirs, FILENAME_MAX, and mf_dir::next.
Referenced by mf_init().