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