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