7959b25c5f3c0475907a2daba4ec61e572964eb6
[idzebra-moved-to-github.git] / include / mfile.h
1 /*
2  * Copyright (C) 1994-1997, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: mfile.h,v $
7  * Revision 1.8  1997-09-17 12:19:10  adam
8  * Zebra version corresponds to YAZ version 1.4.
9  * Changed Zebra server so that it doesn't depend on global common_resource.
10  *
11  * Revision 1.7  1997/09/05 15:30:01  adam
12  * Changed prototype for chr_map_input - added const.
13  * Added support for C++, headers uses extern "C" for public definitions.
14  *
15  * Revision 1.6  1996/10/29 13:46:10  adam
16  * Removed obsolete headers alexpath, alexutil. Created zebrautl.h as
17  * a replacement.
18  *
19  * Revision 1.5  1995/12/05 11:15:03  quinn
20  * Fixed FILENAME_MAX for some Sun systems, hopefully.
21  *
22  * Revision 1.4  1995/11/30  08:33:30  adam
23  * Started work on commit facility.
24  *
25  * Revision 1.3  1995/09/04  12:33:35  adam
26  * Various cleanup. YAZ util used instead.
27  *
28  * Revision 1.2  1994/09/14  13:10:36  quinn
29  * Small changes
30  *
31  * Revision 1.1  1994/08/23  14:41:46  quinn
32  * First functional version of mfile.
33  *
34  */
35
36 #ifndef MFILE_H
37 #define MFILE_H
38
39 #include <stdio.h>
40
41 #ifndef FILENAME_MAX
42 #include <sys/param.h>
43 #define FILENAME_MAX MAXPATHLEN
44 #endif
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 #define MF_MIN_BLOCKS_CREAT 1          /* minimum free blocks in new dir */
51 #define MF_MAX_PARTS 28                 /* max # of part-files per metafile */
52
53 #define mf_blocksize(mf) ((mf)->blocksize)
54
55 typedef struct mf_dir
56 {
57     char name[FILENAME_MAX+1];
58     int max_bytes;      /* allocated bytes in this dir. */
59     int avail_bytes;    /* bytes left */
60     struct mf_dir *next;
61 } mf_dir;
62
63 typedef struct part_file
64 {
65     int number;
66     int top;
67     int blocks;
68     int bytes;
69     mf_dir *dir;
70     char *path;
71     int fd;
72 } part_file;
73
74 struct MFile_area_struct;
75 typedef struct MFile_area_struct *MFile_area;
76
77 typedef struct meta_file
78 {
79     char name[FILENAME_MAX+1];
80     part_file files[MF_MAX_PARTS];
81     int no_files;
82     int cur_file;
83     int open;                          /* is this file open? */
84     int blocksize;
85     int min_bytes_creat;  /* minimum bytes required to enter directory */
86     MFile_area ma;
87     int wr;
88
89     struct meta_file *next;
90 } *MFile, meta_file;
91
92 typedef struct MFile_area_struct
93 {
94     char name[FILENAME_MAX+1];
95     mf_dir *dirs;
96     struct meta_file *mfiles;
97     struct MFile_area_struct *next;  /* global list of active areas */
98 } MFile_area_struct;
99
100 /*
101  * Open an area, cotaining metafiles in directories.
102  */
103 MFile_area mf_init(const char *name, const char *spec); 
104
105 /*
106  * Release an area.
107  */
108 int mf_dispose(MFile_area ma);
109
110 /*
111  * Open a metafile.
112  */
113 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
114
115 /*
116  * Close a metafile.
117  */
118 int mf_close(MFile mf);
119
120 /*
121  * Read one block from a metafile. Interface mirrors bfile.
122  */
123 int mf_read(MFile mf, int no, int offset, int num, void *buf);
124
125 /*
126  * Same.
127  */
128 int mf_write(MFile mf, int no, int offset, int num, const void *buf);
129
130 /*
131  * Destroy a metafile, unlinking component files. File must be open.
132  */
133 int mf_unlink(MFile mf);
134
135 /*
136  * Unlink the file by name, rather than MFile-handle.
137  */
138 int mf_unlink_name(MFile_area, const char *name);
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif