Remove mf_unlink_name
[idzebra-moved-to-github.git] / bfile / mfile.h
1 /* $Id: mfile.h,v 1.3 2006-04-05 02:02:37 adam Exp $
2    Copyright (C) 1995-2005
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 Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
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 unlink_flag;
89     int blocksize;
90     mfile_off_t min_bytes_creat;  /* minimum bytes required to enter directory */
91     MFile_area ma;
92     int wr;
93     Zebra_mutex mutex;
94
95     struct meta_file *next;
96 } *MFile, meta_file;
97
98 typedef struct MFile_area_struct
99 {
100     char name[FILENAME_MAX+1];
101     mf_dir *dirs;
102     struct meta_file *mfiles;
103     struct MFile_area_struct *next;  /* global list of active areas */
104     Zebra_mutex mutex;
105 } MFile_area_struct;
106
107 /*
108  * Open an area, cotaining metafiles in directories.
109  */
110 MFile_area mf_init(const char *name, const char *spec, const char *base); 
111
112 /*
113  * Release an area.
114  */
115 void mf_destroy(MFile_area ma);
116
117 /*
118  * Open a metafile.
119  */
120 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
121
122 /*
123  * Close a metafile.
124  */
125 int mf_close(MFile mf);
126
127 /*
128  * Read one block from a metafile. Interface mirrors bfile.
129  */
130 int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf);
131
132 /*
133  * Same.
134  */
135 int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf);
136
137 /*
138  * Destroy a metafile, unlinking component files. File must be open.
139  */
140 int mf_unlink(MFile mf);
141
142
143 /*
144  * Destroy all metafiles. No files may be opened.
145  */
146 void mf_reset(MFile_area ma);
147
148 YAZ_END_CDECL
149
150 #endif