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