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