93871e43acad0d0149d89a4649c525158327fcba
[idzebra-moved-to-github.git] / include / bfile.h
1 /* $Id: bfile.h,v 1.21 2002-08-02 19:26:55 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
24
25 #ifndef BFILE_H
26 #define BFILE_H
27
28 #include <mfile.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #define bf_blocksize(bf) mf_blocksize(bf->mf)
35
36 typedef struct BFiles_struct *BFiles;
37
38 BFiles bfs_create (const char *spec, const char *base);
39 void bfs_destroy (BFiles bfiles);
40
41 typedef struct BFile_struct
42 {
43     MFile mf;
44     Zebra_lock_rdwr rdwr_lock;
45     struct CFile_struct *cf;
46 } *BFile, BFile_struct;
47
48 /* bf_close: closes bfile.
49    returns 0 if successful; non-zero otherwise 
50  */
51 int bf_close (BFile);
52
53 /* bf_open: opens bfile.
54    opens bfile with name 'name' and with 'block_size' as block size.
55    returns bfile handle is successful; NULL otherwise 
56  */
57 BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag);
58
59 /* bf_read: reads bytes from bfile 'bf'.
60    reads 'nbytes' bytes (or whole block if 0) from offset 'offset' from
61    block 'no'. stores contents in buffer 'buf'.
62    returns 1 if whole block could be read; 0 otherwise.
63  */
64 int bf_read (BFile bf, int 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 int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf);
72
73 /* bf_cache: enables bfile cache if spec is not NULL */
74 void bf_cache (BFiles bfs, const char *spec);
75
76 /* bf_commitExists: returns 1 if commit is pending; 0 otherwise */
77 int bf_commitExists (BFiles bfs);
78
79 /* bf_commitExec: executes commit */
80 void bf_commitExec (BFiles bfs);
81
82 /* bf_commitClean: cleans commit files, etc */
83 void bf_commitClean (BFiles bfs, const char *spec);
84
85 /* bf_reset: delete register and shadow completely */
86 void bf_reset (BFiles bfs);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif