1 /* $Id: bfile.h,v 1.11 2006-11-08 22:08:26 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
24 \brief Zebra Block File Layer
26 Providers an interface to a file system , AKA persistent storage.
27 The interface allows safe updates - using a shadow file facility.
33 #include <yaz/yconfig.h>
34 #include <idzebra/util.h>
39 \brief A collection of BFile(s).
41 typedef struct BFiles_struct *BFiles;
46 typedef struct BFile_struct *BFile;
48 /** \brief creates a Block files collection
49 \param spec register specification , e.g. "d1:100M d2:1G"
50 \param base base directory for register spec (if that is relative path)
51 \return block files handle
53 BFiles bfs_create (const char *spec, const char *base);
55 /** \brief destroys a block files handle
56 \param bfiles block files handle
58 The files in the block files collection are not deleted. Only the
61 void bfs_destroy (BFiles bfiles);
63 /** \brief closes a Block file
67 int bf_close (BFile bf);
69 /** \brief closes an extended Block file handle..
70 \param bf extended block file opened with bf_xopen
71 \param version version to be put in a file
72 \param more_info more information to be stored in file (header)
74 \retval -1 failure (can never happen as the code is now)
77 int bf_xclose (BFile bf, int version, const char *more_info);
79 /** \brief opens and returns a Block file handle
80 \param bfs block files
82 \param block_size block size in bytes
83 \param wflag 1=opened for read&write, 0=read only
85 \retval -1 failure (can never happen as the code is now)
88 BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag);
90 /** \brief opens and returns an extended Block file handle
91 \param bfs block files
93 \param block_size block size in bytes
94 \param wflag 1=opened for read&write, 0=read only
95 \param magic magic string to be used for file
96 \param read_version holds after completion of bf_xopen the version
97 \param more_info holds more_info as read from file (header)
100 BFile bf_xopen(BFiles bfs, const char *name, int block_size, int wflag,
101 const char *magic, int *read_version,
102 const char **more_info);
104 /** \brief read from block file (may call exit)
105 \param bf block file handle
106 \param no block no (first block is 0, second is 1..)
107 \param offset offset within block to be read
108 \param nbytes number of bytes to read (0 for whole block)
109 \param buf raw bytes with content (at least nbytes of size)
110 \retval 1 whole block could be read
111 \retval 0 whole block could not be read
114 int bf_read(BFile bf, zint no, int offset, int nbytes, void *buf);
116 /** \brief read from block file
117 \param bf block file handle
118 \param no block no (first block is 0, second is 1..)
119 \param offset offset within block to be read
120 \param nbytes number of bytes to read (0 for whole block)
121 \param buf raw bytes with content (at least nbytes of size)
122 \retval 1 whole block could be read
123 \retval 0 whole block could not be read
127 int bf_read2(BFile bf, zint no, int offset, int nbytes, void *buf);
130 /** \brief writes block of bytes to file (may call exit)
131 \param bf block file handle
133 \param offset within block
134 \param nbytes number of bytes to write
135 \param buf buffer to write
136 \retval 0 success (block could be written)
138 This function can not return a failure. System calls exit(1)
142 int bf_write(BFile bf, zint no, int offset, int nbytes, const void *buf);
145 /** \brief writes block of bytes to file
146 \param bf block file handle
148 \param offset within block
149 \param nbytes number of bytes to write
150 \param buf buffer to write
151 \retval 0 success (block written)
154 This function can not return a failure. System calls exit(1)
158 int bf_write2(BFile bf, zint no, int offset, int nbytes, const void *buf);
161 /** \brief enables or disables shadow for block files
162 \param bfs block files
163 \param spec such as "shadow:100M /other:200M"; or NULL to disable
164 \retval ZEBRA_OK successful. spec is OK
165 \retval ZEBRA_FAIL failure.
168 ZEBRA_RES bf_cache (BFiles bfs, const char *spec);
170 /** \brief Check if there is content in shadow area (to be committed).
171 \param bfs block files
172 \retval 1 there is content in shadow area
173 \retval 0 no content in shadow area
176 int bf_commitExists (BFiles bfs);
178 /** \brief Executes commit operation
179 \param bfs block files
182 void bf_commitExec (BFiles bfs);
184 /** \brief Cleans shadow files (remove them)
185 \param bfs block files
186 \param spec shadow specification
189 void bf_commitClean (BFiles bfs, const char *spec);
191 /** \brief Removes register and shadow completely
192 \param bfs block files
195 void bf_reset (BFiles bfs);
197 /** \brief Allocates one or more blocks in an extended block file
198 \param bf extended block file
199 \param no number of blocks to allocate
200 \param blocks output array of size no with block offsets
203 int bf_alloc(BFile bf, int no, zint *blocks);
205 /** \brief Releases one or more blocks in an extended block file
206 \param bf extended block file
207 \param no numer of blocks to release
208 \param blocks input array with block offsets (IDs) to release
211 int bf_free(BFile bf, int no, const zint *blocks);
214 /* \brief gets statistics about directory in register area
215 \param bfs block files
216 \param no directory number (0=first, 1=second,...)
217 \param directory holds directory name (if found)
218 \param used_bytes used file bytes in directory (if found)
219 \param max_bytes max usage of bytes (if found)
220 \retval 1 no is within range and directory, used, max are set.
221 \retval 0 no is out of range and directory, used, max are unset
223 We are using double, because off_t may have a different size
224 on same platform depending on whether 64-bit is enabled or not.
225 Note that if a register area has unlimited size, that is represented
230 int bfs_register_directory_stat(BFiles bfs, int no, const char **directory,
231 double *used_bytes, double *max_bytes);
233 /* \brief gets statistics about directory in shadow area
234 \param bfs block files
235 \param no directory number (0=first, 1=second,...)
236 \param directory holds directory name (if found)
237 \param used_bytes used file bytes in directory (if found)
238 \param max_bytes max usage of bytes (if found)
239 \retval 1 no is within range and directory, used, max are set.
240 \retval 0 no is out of range and directory, used, max are unset
242 We are using double, because off_t may have a different size
243 on same platform depending on whether 64-bit is enabled or not.
244 Note that if a shadow area has unlimited size, that is represented
248 int bfs_shadow_directory_stat(BFiles bfs, int no, const char **directory,
249 double *used_bytes, double *max_bytes);
257 * indent-tabs-mode: nil
259 * vim: shiftwidth=4 tabstop=8 expandtab