d1b25c17851042cbf6b8fd05e078f923166d7834
[idzebra-moved-to-github.git] / include / idzebra / bfile.h
1 /* $Id: bfile.h,v 1.4 2005-03-30 09:25:23 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23 #ifndef BFILE_H
24 #define BFILE_H
25
26 #include <yaz/yconfig.h>
27 #include <idzebra/util.h>
28
29 YAZ_BEGIN_CDECL
30
31 typedef struct BFiles_struct *BFiles;
32 typedef struct BFile_struct *BFile;
33
34 BFiles bfs_create (const char *spec, const char *base);
35 void bfs_destroy (BFiles bfiles);
36
37 /* bf_close: closes bfile.
38    returns 0 if successful; non-zero otherwise 
39  */
40 YAZ_EXPORT
41 int bf_close (BFile);
42
43 YAZ_EXPORT
44 int bf_xclose (BFile bf, int version, const char *more_info);
45
46 /* bf_open: opens bfile.
47    opens bfile with name 'name' and with 'block_size' as block size.
48    returns bfile handle is successful; NULL otherwise 
49  */
50 YAZ_EXPORT
51 BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag);
52
53 YAZ_EXPORT
54 BFile bf_xopen(BFiles bfs, const char *name, int block_size, int wrflag,
55                const char *magic, int *read_version,
56                const char **more_info);
57
58 /* bf_read: reads bytes from bfile 'bf'.
59    reads 'nbytes' bytes (or whole block if 0) from offset 'offset' from
60    block 'no'. stores contents in buffer 'buf'.
61    returns 1 if whole block could be read; 0 otherwise.
62  */
63 YAZ_EXPORT
64 int bf_read (BFile bf, zint no, int offset, int nbytes, void *buf);
65
66 /* bf_write: writes bytes to bfile 'bf'.
67    writes 'nbytes' bytes (or whole block if 0) at offset 'offset' to
68    block 'no'. retrieves contents from buffer 'buf'.
69    returns 0 if successful; non-zero otherwise.
70  */
71 YAZ_EXPORT
72 int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf);
73
74 /* bf_cache: enables bfile cache if spec is not NULL */
75 YAZ_EXPORT
76 void bf_cache (BFiles bfs, const char *spec);
77
78 /* bf_commitExists: returns 1 if commit is pending; 0 otherwise */
79 YAZ_EXPORT
80 int bf_commitExists (BFiles bfs);
81
82 /* bf_commitExec: executes commit */
83 YAZ_EXPORT
84 void bf_commitExec (BFiles bfs);
85
86 /* bf_commitClean: cleans commit files, etc */
87 YAZ_EXPORT
88 void bf_commitClean (BFiles bfs, const char *spec);
89
90 /* bf_reset: delete register and shadow completely */
91 YAZ_EXPORT
92 void bf_reset (BFiles bfs);
93
94 /* bf_alloc: allocate one or more blocks */
95 YAZ_EXPORT
96 int bf_alloc(BFile bf, int no, zint *blocks);
97
98 /* bf_alloc: allocate one or more blocks */
99 YAZ_EXPORT
100 int bf_free(BFile bf, int no, const zint *blocks);
101
102 YAZ_END_CDECL
103
104 #endif