1 /* $Id: mfile.h,v 1.7 2006-10-09 22:10:00 adam Exp $
2 Copyright (C) 1995-2006
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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? */
89 mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */
94 struct meta_file *next;
97 typedef struct MFile_area_struct
99 char name[FILENAME_MAX+1];
101 struct meta_file *mfiles;
102 struct MFile_area_struct *next; /* global list of active areas */
107 * Open an area, cotaining metafiles in directories.
109 MFile_area mf_init(const char *name, const char *spec, const char *base);
114 void mf_destroy(MFile_area ma);
119 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
124 int mf_close(MFile mf);
127 * Read one block from a metafile. Interface mirrors bfile.
129 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf);
134 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf);
137 * Destroy all metafiles. No files may be opened.
139 void mf_reset(MFile_area ma, int unlink_flag);
141 /* \brief gets statistics about directory in metafile area
143 \param no directory number (0=first, 1=second,...)
144 \param directory holds directory name (if found)
145 \param used_bytes used file bytes in directory (if found)
146 \param max_bytes max usage of bytes (if found)
147 \retval 1 no is within range and directory, used, max are set.
148 \retval 0 no is out of range and directory, used, max are unset
150 We are using double, because off_t may have a different size
151 on same platform depending on whether 64-bit is enabled or not.
152 Note that if an area has unlimited size, that is represented
155 int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
156 double *bytes_used, double *bytes_max);
164 * indent-tabs-mode: nil
166 * vim: shiftwidth=4 tabstop=8 expandtab