IDZEBRA  2.1.2
mfile.h
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #ifndef MFILE_H
21 #define MFILE_H
22 
23 #include <stdio.h>
24 #include <yaz/yconfig.h>
25 #include <idzebra/version.h>
26 #include <idzebra/util.h>
27 
28 #ifdef WIN32
29 
30 /* 64-bit access .. */
31 typedef __int64 mfile_off_t;
32 #define mfile_seek _lseeki64
33 
34 #else
35 #include <sys/types.h>
36 typedef off_t mfile_off_t;
37 #define mfile_seek lseek
38 #endif
39 
40 #ifndef FILENAME_MAX
41 #include <sys/param.h>
42 #define FILENAME_MAX MAXPATHLEN
43 #endif
44 
45 #include <zebra-lock.h>
46 
47 YAZ_BEGIN_CDECL
48 
49 #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */
50 #define MF_MAX_PARTS 28 /* max # of part-files per metafile */
51 
52 #define mf_blocksize(mf) ((mf)->blocksize)
53 
54 
55 typedef struct mf_dir
56 {
57  char name[FILENAME_MAX+1];
58  mfile_off_t max_bytes; /* allocated bytes in this dir. */
59  mfile_off_t avail_bytes; /* bytes left */
60  struct mf_dir *next;
61 } mf_dir;
62 
63 typedef struct part_file
64 {
70  char *path;
71  int fd;
72 } part_file;
73 
74 struct MFile_area_struct;
75 typedef struct MFile_area_struct *MFile_area;
76 
77 typedef struct meta_file
78 {
79  char name[FILENAME_MAX+1];
81  int no_files;
82  int cur_file;
83  int open; /* is this file open? */
84  int blocksize;
85  mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */
86  MFile_area ma;
87  int wr;
89 
90  struct meta_file *next;
91 } *MFile, meta_file;
92 
94 {
95  char name[FILENAME_MAX+1];
97  struct meta_file *mfiles;
98  struct MFile_area_struct *next; /* global list of active areas */
100 };
101 
109 MFile_area mf_init(const char *name, const char *spec, const char *base,
110  int only_shadow_files)
111  ZEBRA_GCC_ATTR((warn_unused_result));
112 
116 void mf_destroy(MFile_area ma);
117 
125 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
126  ZEBRA_GCC_ATTR((warn_unused_result));
127 
132 int mf_close(MFile mf);
133 
144 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
145  ZEBRA_GCC_ATTR((warn_unused_result));
146 
156 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
157  ZEBRA_GCC_ATTR((warn_unused_result));
158 
163 void mf_reset(MFile_area ma, int unlink_flag);
164 
165 /* \brief gets statistics about directory in metafile area
166  \param ma the area
167  \param no directory number (0=first, 1=second,...)
168  \param directory holds directory name (if found)
169  \param used_bytes used file bytes in directory (if found)
170  \param max_bytes max usage of bytes (if found)
171  \retval 1 no is within range and directory, used, max are set.
172  \retval 0 no is out of range and directory, used, max are unset
173 
174  We are using double, because off_t may have a different size
175  on same platform depending on whether 64-bit is enabled or not.
176  Note that if an area has unlimited size, that is represented
177  as max_bytes = -1.
178 */
179 int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
180  double *bytes_used, double *bytes_max);
181 
182 YAZ_END_CDECL
183 
184 #endif
185 /*
186  * Local variables:
187  * c-basic-offset: 4
188  * c-file-style: "Stroustrup"
189  * indent-tabs-mode: nil
190  * End:
191  * vim: shiftwidth=4 tabstop=8 expandtab
192  */
193 
mfile_off_t max_bytes
Definition: mfile.h:58
struct meta_file * MFile
Zebra_mutex mutex
Definition: mfile.h:99
int mf_close(MFile mf)
closes metafile
Definition: mfile.c:429
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
writes block to metafile
Definition: mfile.c:484
#define ZEBRA_GCC_ATTR(x)
Definition: util.h:41
int mf_area_directory_stat(MFile_area ma, int no, const char **directory, double *bytes_used, double *bytes_max)
metafile area statistics
Definition: mfile.c:609
struct MFile_area_struct * MFile_area
Definition: mfile.h:75
Definition: mfile.h:55
struct mf_dir * next
Definition: mfile.h:60
MFile_area ma
Definition: mfile.h:86
struct meta_file * next
Definition: mfile.h:90
char * path
Definition: mfile.h:70
void mf_destroy(MFile_area ma)
destroys metafile area handle
Definition: mfile.c:307
zint top
Definition: mfile.h:66
int blocksize
Definition: mfile.h:84
zint number
Definition: mfile.h:65
int fd
Definition: mfile.h:71
int wr
Definition: mfile.h:87
mf_dir * dir
Definition: mfile.h:69
#define FILENAME_MAX
Definition: mfile.h:42
struct MFile_area_struct * next
Definition: mfile.h:98
int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf) ZEBRA_GCC_ATTR((warn_unused_result))
reads block from metafile
Definition: mfile.c:451
int no_files
Definition: mfile.h:81
struct part_file part_file
off_t mfile_off_t
Definition: mfile.h:36
#define MF_MAX_PARTS
Definition: mfile.h:50
MFile_area mf_init(const char *name, const char *spec, const char *base, int only_shadow_files) ZEBRA_GCC_ATTR((warn_unused_result))
creates a metafile area
Definition: mfile.c:195
struct meta_file * mfiles
Definition: mfile.h:97
struct meta_file meta_file
struct mf_dir mf_dir
mfile_off_t bytes
Definition: mfile.h:68
long zint
Zebra integer.
Definition: util.h:66
mfile_off_t avail_bytes
Definition: mfile.h:59
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) ZEBRA_GCC_ATTR((warn_unused_result))
opens metafile
Definition: mfile.c:351
int cur_file
Definition: mfile.h:82
zint blocks
Definition: mfile.h:67
Zebra_mutex mutex
Definition: mfile.h:88
int open
Definition: mfile.h:83
void mf_reset(MFile_area ma, int unlink_flag)
reset all files in a metafile area (optionally delete them as well)
Definition: mfile.c:324
mf_dir * dirs
Definition: mfile.h:96
char name[FILENAME_MAX+1]
Definition: mfile.h:57
mfile_off_t min_bytes_creat
Definition: mfile.h:85