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