Small changes
[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.2  1994-09-14 13:10:36  quinn
8  * Small changes
9  *
10  * Revision 1.1  1994/08/23  14:41:46  quinn
11  * First functional version of mfile.
12  *
13  */
14
15 #ifndef MFILE_H
16 #define MFILE_H
17
18 #include <stdio.h>
19
20 #include <util.h>
21
22 #define MF_MIN_BLOCKS_CREAT 1          /* minimum free blocks in new dir */
23 #define MF_DEFAULT_AREA "register"      /* Use if no mf_init */
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); 
77
78 /*
79  * Release an area.
80  */
81 int mf_dispose(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 num, void *buf);
97
98 /*
99  * Same.
100  */
101 int mf_write(MFile mf, int no, int offset, int num, 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  * Unlink the file by name, rather than MFile-handle.
110  */
111 int mf_unlink_name(MFile_area, const char *name);
112
113 #endif