1 /* $Id: mfile.h,v 1.21 2003-03-25 23:47:24 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
5 This file is part of the Zebra server.
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
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
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
29 #include <yaz/yconfig.h>
34 /* 32-bit access .. */
35 typedef long mfile_off_t;
36 #define mfile_seek lseek
39 /* 64-bit access .. */
40 typedef __int64 mfile_off_t;
41 #define mfile_seek _lseeki64
45 #include <sys/types.h>
46 typedef off_t mfile_off_t;
47 #define mfile_seek lseek
51 #include <sys/param.h>
52 #define FILENAME_MAX MAXPATHLEN
55 #include <zebra-lock.h>
59 #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */
60 #define MF_MAX_PARTS 28 /* max # of part-files per metafile */
62 #define mf_blocksize(mf) ((mf)->blocksize)
67 char name[FILENAME_MAX+1];
68 mfile_off_t max_bytes; /* allocated bytes in this dir. */
69 mfile_off_t avail_bytes; /* bytes left */
73 typedef struct part_file
84 struct MFile_area_struct;
85 typedef struct MFile_area_struct *MFile_area;
87 typedef struct meta_file
89 char name[FILENAME_MAX+1];
90 part_file files[MF_MAX_PARTS];
93 int open; /* is this file open? */
96 mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */
101 struct meta_file *next;
104 typedef struct MFile_area_struct
106 char name[FILENAME_MAX+1];
108 struct meta_file *mfiles;
109 struct MFile_area_struct *next; /* global list of active areas */
114 * Open an area, cotaining metafiles in directories.
116 MFile_area mf_init(const char *name, const char *spec, const char *base);
121 void mf_destroy(MFile_area ma);
126 MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag);
131 int mf_close(MFile mf);
134 * Read one block from a metafile. Interface mirrors bfile.
136 int mf_read(MFile mf, int no, int offset, int nbytes, void *buf);
141 int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf);
144 * Destroy a metafile, unlinking component files. File must be open.
146 int mf_unlink(MFile mf);
150 * Destroy all metafiles. No files may be opened.
152 void mf_reset(MFile_area ma);
155 * Unlink the file by name, rather than MFile-handle.
157 int mf_unlink_name(MFile_area, const char *name);