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