1 /* $Id: mfile.h,v 1.10 2006-11-14 12:41:19 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
27 #include <yaz/yconfig.h>
28 #include <idzebra/version.h>
29 #include <idzebra/util.h>
33 /* 64-bit access .. */
34 typedef __int64 mfile_off_t;
35 #define mfile_seek _lseeki64
38 #include <sys/types.h>
39 typedef off_t mfile_off_t;
40 #define mfile_seek lseek
44 #include <sys/param.h>
45 #define FILENAME_MAX MAXPATHLEN
48 #include <zebra-lock.h>
52 #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */
53 #define MF_MAX_PARTS 28 /* max # of part-files per metafile */
55 #define mf_blocksize(mf) ((mf)->blocksize)
60 char name[FILENAME_MAX+1];
61 mfile_off_t max_bytes; /* allocated bytes in this dir. */
62 mfile_off_t avail_bytes; /* bytes left */
66 typedef struct part_file
77 struct MFile_area_struct;
78 typedef struct MFile_area_struct *MFile_area;
80 typedef struct meta_file
82 char name[FILENAME_MAX+1];
83 part_file files[MF_MAX_PARTS];
86 int open; /* is this file open? */
88 mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */
93 struct meta_file *next;
96 typedef struct MFile_area_struct
98 char name[FILENAME_MAX+1];
100 struct meta_file *mfiles;
101 struct MFile_area_struct *next; /* global list of active areas */
105 /** \brief creates a metafile area
106 \param name of area (does not show up on disk - purely for notation)
107 \param spec area specification (e.g. "/a:1G dir /b:2000M"
108 \param base base directory (NULL for no base)
109 \returns metafile area handle or NULL if error occurs
111 MFile_area mf_init(const char *name, const char *spec, const char *base)
112 ZEBRA_GCC_ATTR((warn_unused_result));
114 /** \brief destroys metafile area handle
115 \param ma metafile area handle
117 void mf_destroy(MFile_area ma);
119 /** \brief opens metafile
120 \param ma metafile area handle
121 \param name pseudo filename (name*.mf)
122 \param block_size block size for this file
123 \param wflag write flag, 0=read, 1=write&read
124 \returns metafile handle, or NULL for error (could not be opened)
126 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
127 ZEBRA_GCC_ATTR((warn_unused_result));
129 /** \brief closes metafile
130 \param mf metafile handle
133 int mf_close(MFile mf);
135 /** \brief reads block from metafile
136 \param mf metafile handle
137 \param no block position
138 \param offset offset within block
139 \param nbytes no of bytes to read (0 for whole block)
140 \param buf content (filled with data if OK)
141 \retval 0 block partially read
142 \retval 1 block fully read
143 \retval -1 block could not be read due to error
145 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
146 ZEBRA_GCC_ATTR((warn_unused_result));
148 /** \brief writes block to metafile
149 \param mf metafile handle
150 \param no block position
151 \param offset offset within block
152 \param nbytes no of bytes to write (0 for whole block)
153 \param buf content to be written
154 \retval 0 block written
155 \retval -1 error (block not written)
157 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
158 ZEBRA_GCC_ATTR((warn_unused_result));
160 /** \brief reset all files in a metafile area (optionally delete them as well)
161 \param ma metafile area
162 \param unlink_flag if unlink_flag=1 all files are removed from FS
164 void mf_reset(MFile_area ma, int unlink_flag);
166 /* \brief gets statistics about directory in metafile area
168 \param no directory number (0=first, 1=second,...)
169 \param directory holds directory name (if found)
170 \param used_bytes used file bytes in directory (if found)
171 \param max_bytes max usage of bytes (if found)
172 \retval 1 no is within range and directory, used, max are set.
173 \retval 0 no is out of range and directory, used, max are unset
175 We are using double, because off_t may have a different size
176 on same platform depending on whether 64-bit is enabled or not.
177 Note that if an area has unlimited size, that is represented
180 int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
181 double *bytes_used, double *bytes_max);
189 * indent-tabs-mode: nil
191 * vim: shiftwidth=4 tabstop=8 expandtab