Removed a few redundant comments.
[idzebra-moved-to-github.git] / bfile / mfile.h
1 /* $Id: mfile.h,v 1.8 2006-11-08 22:06:50 adam Exp $
2    Copyright (C) 1995-2006
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23
24
25 #ifndef MFILE_H
26 #define MFILE_H
27
28 #include <stdio.h>
29 #include <yaz/yconfig.h>
30 #include <idzebra/version.h>
31
32 #ifdef WIN32
33
34 /* 64-bit access .. */
35 typedef __int64 mfile_off_t;
36 #define mfile_seek _lseeki64
37
38 #else
39 #include <sys/types.h>
40 typedef off_t mfile_off_t;
41 #define mfile_seek lseek
42 #endif
43
44 #ifndef FILENAME_MAX
45 #include <sys/param.h>
46 #define FILENAME_MAX MAXPATHLEN
47 #endif
48
49 #include <zebra-lock.h>
50
51 YAZ_BEGIN_CDECL
52
53 #define MF_MIN_BLOCKS_CREAT 1          /* minimum free blocks in new dir */
54 #define MF_MAX_PARTS 28                 /* max # of part-files per metafile */
55
56 #define mf_blocksize(mf) ((mf)->blocksize)
57
58
59 typedef struct mf_dir
60 {
61     char name[FILENAME_MAX+1];
62     mfile_off_t max_bytes;      /* allocated bytes in this dir. */
63     mfile_off_t avail_bytes;    /* bytes left */
64     struct mf_dir *next;
65 } mf_dir;
66
67 typedef struct part_file
68 {
69     zint number;
70     zint top;
71     zint blocks;
72     mfile_off_t bytes;
73     mf_dir *dir;
74     char *path;
75     int fd;
76 } part_file;
77
78 struct MFile_area_struct;
79 typedef struct MFile_area_struct *MFile_area;
80
81 typedef struct meta_file
82 {
83     char name[FILENAME_MAX+1];
84     part_file files[MF_MAX_PARTS];
85     int no_files;
86     int cur_file;
87     int open;                          /* is this file open? */
88     int blocksize;
89     mfile_off_t min_bytes_creat;  /* minimum bytes required to enter directory */
90     MFile_area ma;
91     int wr;
92     Zebra_mutex mutex;
93
94     struct meta_file *next;
95 } *MFile, meta_file;
96
97 typedef struct MFile_area_struct
98 {
99     char name[FILENAME_MAX+1];
100     mf_dir *dirs;
101     struct meta_file *mfiles;
102     struct MFile_area_struct *next;  /* global list of active areas */
103     Zebra_mutex mutex;
104 } MFile_area_struct;
105
106 /*
107  * Open an area, cotaining metafiles in directories.
108  */
109 MFile_area mf_init(const char *name, const char *spec, const char *base); 
110
111 /*
112  * Release an area.
113  */
114 void mf_destroy(MFile_area ma);
115
116 /*
117  * Open a metafile.
118  */
119 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
120
121 /*
122  * Close a metafile.
123  */
124 int mf_close(MFile mf);
125
126 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf);
127
128 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf);
129
130 /*
131  * Destroy all metafiles. No files may be opened.
132  */
133 void mf_reset(MFile_area ma, int unlink_flag);
134
135 /* \brief gets statistics about directory in metafile area
136    \param ma the area
137    \param no directory number (0=first, 1=second,...)
138    \param directory holds directory name (if found)
139    \param used_bytes used file bytes in directory (if found)
140    \param max_bytes max usage of bytes (if found)
141    \retval 1 no is within range and directory, used, max are set.
142    \retval 0 no is out of range and directory, used, max are unset
143
144    We are using double, because off_t may have a different size
145    on same platform depending on whether 64-bit is enabled or not.
146    Note that if an area has unlimited size, that is represented
147    as max_bytes = -1.
148 */ 
149 int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
150                            double *bytes_used, double *bytes_max);
151     
152 YAZ_END_CDECL
153
154 #endif
155 /*
156  * Local variables:
157  * c-basic-offset: 4
158  * indent-tabs-mode: nil
159  * End:
160  * vim: shiftwidth=4 tabstop=8 expandtab
161  */
162