Added remote record import using Z39.50 extended services and Segment
[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.14 2000-03-20 19:08:36 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 typedef struct mf_dir
30 {
31     char name[FILENAME_MAX+1];
32     off_t max_bytes;      /* allocated bytes in this dir. */
33     off_t avail_bytes;    /* bytes left */
34     struct mf_dir *next;
35 } mf_dir;
36
37 typedef struct part_file
38 {
39     int number;
40     int top;
41     int blocks;
42     off_t bytes;
43     mf_dir *dir;
44     char *path;
45     int fd;
46 } part_file;
47
48 struct MFile_area_struct;
49 typedef struct MFile_area_struct *MFile_area;
50
51 typedef struct meta_file
52 {
53     char name[FILENAME_MAX+1];
54     part_file files[MF_MAX_PARTS];
55     int no_files;
56     int cur_file;
57     int open;                          /* is this file open? */
58     off_t blocksize;
59     off_t min_bytes_creat;  /* minimum bytes required to enter directory */
60     MFile_area ma;
61     int wr;
62     Zebra_mutex mutex;
63
64     struct meta_file *next;
65 } *MFile, meta_file;
66
67 typedef struct MFile_area_struct
68 {
69     char name[FILENAME_MAX+1];
70     mf_dir *dirs;
71     struct meta_file *mfiles;
72     struct MFile_area_struct *next;  /* global list of active areas */
73     Zebra_mutex mutex;
74 } MFile_area_struct;
75
76 /*
77  * Open an area, cotaining metafiles in directories.
78  */
79 MFile_area mf_init(const char *name, const char *spec); 
80
81 /*
82  * Release an area.
83  */
84 void mf_destroy(MFile_area ma);
85
86 /*
87  * Open a metafile.
88  */
89 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
90
91 /*
92  * Close a metafile.
93  */
94 int mf_close(MFile mf);
95
96 /*
97  * Read one block from a metafile. Interface mirrors bfile.
98  */
99 int mf_read(MFile mf, int no, int offset, int nbytes, void *buf);
100
101 /*
102  * Same.
103  */
104 int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf);
105
106 /*
107  * Destroy a metafile, unlinking component files. File must be open.
108  */
109 int mf_unlink(MFile mf);
110
111
112 /*
113  * Destroy all metafiles. No files may be opened.
114  */
115 void mf_reset(MFile_area ma);
116
117 /*
118  * Unlink the file by name, rather than MFile-handle.
119  */
120 int mf_unlink_name(MFile_area, const char *name);
121
122 YAZ_END_CDECL
123
124 #endif