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