1 /* $Id: mfile.h,v 1.5 2006-05-10 08:13:17 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include <yaz/yconfig.h>
30 #include <idzebra/version.h>
34 /* 64-bit access .. */
35 typedef __int64 mfile_off_t;
36 #define mfile_seek _lseeki64
39 #include <sys/types.h>
40 typedef off_t mfile_off_t;
41 #define mfile_seek lseek
45 #include <sys/param.h>
46 #define FILENAME_MAX MAXPATHLEN
49 #include <zebra-lock.h>
53 #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */
54 #define MF_MAX_PARTS 28 /* max # of part-files per metafile */
56 #define mf_blocksize(mf) ((mf)->blocksize)
61 char name[FILENAME_MAX+1];
62 mfile_off_t max_bytes; /* allocated bytes in this dir. */
63 mfile_off_t avail_bytes; /* bytes left */
67 typedef struct part_file
78 struct MFile_area_struct;
79 typedef struct MFile_area_struct *MFile_area;
81 typedef struct meta_file
83 char name[FILENAME_MAX+1];
84 part_file files[MF_MAX_PARTS];
87 int open; /* is this file open? */
90 mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */
95 struct meta_file *next;
98 typedef struct MFile_area_struct
100 char name[FILENAME_MAX+1];
102 struct meta_file *mfiles;
103 struct MFile_area_struct *next; /* global list of active areas */
108 * Open an area, cotaining metafiles in directories.
110 MFile_area mf_init(const char *name, const char *spec, const char *base);
115 void mf_destroy(MFile_area ma);
120 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
125 int mf_close(MFile mf);
128 * Read one block from a metafile. Interface mirrors bfile.
130 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf);
135 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf);
138 * Destroy a metafile, unlinking component files. File must be open.
140 int mf_unlink(MFile mf);
144 * Destroy all metafiles. No files may be opened.
146 void mf_reset(MFile_area ma);
148 /* \brief gets statistics about directory in metafile area
150 \param no directory number (0=first, 1=second,...)
151 \param directory holds directory name (if found)
152 \param used_bytes used file bytes in directory (if found)
153 \param max_bytes max usage of bytes (if found)
154 \retval 1 no is within range and directory, used, max are set.
155 \retval 0 no is out of range and directory, used, max are unset
157 We are using double, because off_t may have a different size
158 on same platform depending on whether 64-bit is enabled or not.
159 Note that if an area has unlimited size, that is represented
162 int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
163 double *bytes_used, double *bytes_max);
171 * indent-tabs-mode: nil
173 * vim: shiftwidth=4 tabstop=8 expandtab