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