64-bit offsets for register files on Windows
[idzebra-moved-to-github.git] / include / mfile.h
1 /* $Id: mfile.h,v 1.19 2003-02-28 15:28:36 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
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
31 #ifdef WIN32
32
33 /* 32-bit access .. */
34 #if 0
35 typedef long mfile_off_t;
36 #define mfile_seek lseek
37 #endif
38
39 /* 64-but access .. */
40 typedef __int64 mfile_off_t;
41 #define mfile_seek _lseeki64
42
43 #else
44 #include <sys/types.h>
45 typedef off_t mfile_off_t;
46 #define mfile_seek lseek
47 #endif
48
49 #ifndef FILENAME_MAX
50 #include <sys/param.h>
51 #define FILENAME_MAX MAXPATHLEN
52 #endif
53
54 #include <zebra-lock.h>
55
56 YAZ_BEGIN_CDECL
57
58 #define MF_MIN_BLOCKS_CREAT 1          /* minimum free blocks in new dir */
59 #define MF_MAX_PARTS 28                 /* max # of part-files per metafile */
60
61 #define mf_blocksize(mf) ((mf)->blocksize)
62
63
64 typedef struct mf_dir
65 {
66     char name[FILENAME_MAX+1];
67     mfile_off_t max_bytes;      /* allocated bytes in this dir. */
68     mfile_off_t avail_bytes;    /* bytes left */
69     struct mf_dir *next;
70 } mf_dir;
71
72 typedef struct part_file
73 {
74     int number;
75     int top;
76     int blocks;
77     mfile_off_t bytes;
78     mf_dir *dir;
79     char *path;
80     int fd;
81 } part_file;
82
83 struct MFile_area_struct;
84 typedef struct MFile_area_struct *MFile_area;
85
86 typedef struct meta_file
87 {
88     char name[FILENAME_MAX+1];
89     part_file files[MF_MAX_PARTS];
90     int no_files;
91     int cur_file;
92     int open;                          /* is this file open? */
93     int blocksize;
94     mfile_off_t min_bytes_creat;  /* minimum bytes required to enter directory */
95     MFile_area ma;
96     int wr;
97     Zebra_mutex mutex;
98
99     struct meta_file *next;
100 } *MFile, meta_file;
101
102 typedef struct MFile_area_struct
103 {
104     char name[FILENAME_MAX+1];
105     mf_dir *dirs;
106     struct meta_file *mfiles;
107     struct MFile_area_struct *next;  /* global list of active areas */
108     Zebra_mutex mutex;
109 } MFile_area_struct;
110
111 /*
112  * Open an area, cotaining metafiles in directories.
113  */
114 MFile_area mf_init(const char *name, const char *spec, const char *base); 
115
116 /*
117  * Release an area.
118  */
119 void mf_destroy(MFile_area ma);
120
121 /*
122  * Open a metafile.
123  */
124 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
125
126 /*
127  * Close a metafile.
128  */
129 int mf_close(MFile mf);
130
131 /*
132  * Read one block from a metafile. Interface mirrors bfile.
133  */
134 int mf_read(MFile mf, int no, int offset, int nbytes, void *buf);
135
136 /*
137  * Same.
138  */
139 int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf);
140
141 /*
142  * Destroy a metafile, unlinking component files. File must be open.
143  */
144 int mf_unlink(MFile mf);
145
146
147 /*
148  * Destroy all metafiles. No files may be opened.
149  */
150 void mf_reset(MFile_area ma);
151
152 /*
153  * Unlink the file by name, rather than MFile-handle.
154  */
155 int mf_unlink_name(MFile_area, const char *name);
156
157 YAZ_END_CDECL
158
159 #endif