projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only enable ALVIS if Libxml2 2.6.15 or later is in use.
[idzebra-moved-to-github.git]
/
bfile
/
mfile.c
diff --git
a/bfile/mfile.c
b/bfile/mfile.c
index
bbbc1cf
..
5f05473
100644
(file)
--- a/
bfile/mfile.c
+++ b/
bfile/mfile.c
@@
-1,6
+1,6
@@
-/* $Id: mfile.c,v 1.56 2004-11-19 10:26:53 heikki Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
- Index Data Aps
+/* $Id: mfile.c,v 1.69 2006-10-10 10:19:28 adam Exp $
+ Copyright (C) 1995-2006
+ Index Data ApS
This file is part of the Zebra server.
This file is part of the Zebra server.
@@
-15,9
+15,9
@@
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
*/
@@
-32,7
+32,8
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <fcntl.h>
#ifdef WIN32
#include <io.h>
#include <fcntl.h>
#ifdef WIN32
#include <io.h>
-#else
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <direntz.h>
#include <unistd.h>
#endif
#include <direntz.h>
@@
-43,8
+44,9
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <errno.h>
#include <zebra-lock.h>
#include <errno.h>
#include <zebra-lock.h>
-#include <zebrautl.h>
-#include <mfile.h>
+#include <idzebra/util.h>
+#include <yaz/yaz-util.h>
+#include "mfile.h"
static int scan_areadef(MFile_area ma, const char *ad, const char *base)
{
static int scan_areadef(MFile_area ma, const char *ad, const char *base)
{
@@
-160,7
+162,7
@@
static zint file_position(MFile mf, zint pos, int offset)
if (!mf->wr && errno == ENOENT && off == 0)
return -2;
yaz_log (YLOG_WARN|YLOG_ERRNO, "Failed to open %s", mf->files[c].path);
if (!mf->wr && errno == ENOENT && off == 0)
return -2;
yaz_log (YLOG_WARN|YLOG_ERRNO, "Failed to open %s", mf->files[c].path);
- return -1;
+ return -1;
}
}
ps = pos - off;
}
}
ps = pos - off;
@@
-250,7
+252,6
@@
MFile_area mf_init(const char *name, const char *spec, const char *base)
meta_f->next = ma->mfiles;
meta_f->open = 0;
meta_f->cur_file = -1;
meta_f->next = ma->mfiles;
meta_f->open = 0;
meta_f->cur_file = -1;
- meta_f->unlink_flag = 0;
ma->mfiles = meta_f;
strcpy(meta_f->name, metaname);
part_f = &meta_f->files[0];
ma->mfiles = meta_f;
strcpy(meta_f->name, metaname);
part_f = &meta_f->files[0];
@@
-296,7
+297,6
@@
MFile_area mf_init(const char *name, const char *spec, const char *base)
void mf_destroy(MFile_area ma)
{
mf_dir *dp;
void mf_destroy(MFile_area ma)
{
mf_dir *dp;
- meta_file *meta_f;
if (!ma)
return;
if (!ma)
return;
@@
-307,24
+307,11
@@
void mf_destroy(MFile_area ma)
dp = dp->next;
xfree (d);
}
dp = dp->next;
xfree (d);
}
- meta_f = ma->mfiles;
- while (meta_f)
- {
- int i;
- meta_file *m = meta_f;
-
- for (i = 0; i<m->no_files; i++)
- {
- xfree (m->files[i].path);
- }
- zebra_mutex_destroy (&meta_f->mutex);
- meta_f = meta_f->next;
- xfree (m);
- }
+ mf_reset(ma, 0);
xfree (ma);
}
xfree (ma);
}
-void mf_reset(MFile_area ma)
+void mf_reset(MFile_area ma, int unlink_flag)
{
meta_file *meta_f;
{
meta_file *meta_f;
@@
-336,13
+323,16
@@
void mf_reset(MFile_area ma)
int i;
meta_file *m = meta_f;
int i;
meta_file *m = meta_f;
+ meta_f = meta_f->next;
+
assert (!m->open);
for (i = 0; i<m->no_files; i++)
{
assert (!m->open);
for (i = 0; i<m->no_files; i++)
{
- unlink (m->files[i].path);
+ if (unlink_flag)
+ unlink (m->files[i].path);
xfree (m->files[i].path);
}
xfree (m->files[i].path);
}
- meta_f = meta_f->next;
+ zebra_mutex_destroy (&m->mutex);
xfree (m);
}
ma->mfiles = 0;
xfree (m);
}
ma->mfiles = 0;
@@
-350,7
+340,6
@@
void mf_reset(MFile_area ma)
/*
* Open a metafile.
/*
* Open a metafile.
- * If !ma, Use MF_DEFAULT_AREA.
*/
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
{
*/
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
{
@@
-382,7
+371,6
@@
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
mnew->files[0].top = -1;
mnew->files[0].number = 0;
mnew->files[0].fd = -1;
mnew->files[0].top = -1;
mnew->files[0].number = 0;
mnew->files[0].fd = -1;
- mnew->unlink_flag = 0;
mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size;
for (dp = ma->dirs; dp && dp->max_bytes >= 0 && dp->avail_bytes <
mnew->min_bytes_creat; dp = dp->next);
mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size;
for (dp = ma->dirs; dp && dp->max_bytes >= 0 && dp->avail_bytes <
mnew->min_bytes_creat; dp = dp->next);
@@
-447,8
+435,6
@@
int mf_close(MFile mf)
close(mf->files[i].fd);
mf->files[i].fd = -1;
}
close(mf->files[i].fd);
mf->files[i].fd = -1;
}
- if (mf->unlink_flag)
- unlink(mf->files[i].path);
}
mf->open = 0;
return 0;
}
mf->open = 0;
return 0;
@@
-596,27
+582,34
@@
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
return 0;
}
return 0;
}
-/*
- * Destroy a metafile, unlinking component files. File must be open.
- */
-int mf_unlink(MFile mf)
+int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
+ double *used_bytes, double *max_bytes)
{
{
- if (mf->open)
- mf->unlink_flag = 1;
- else
+ int i;
+ mf_dir *d = ma->dirs;
+ for (i = 0; d && i<no; i++, d = d->next)
+ ;
+ if (!d)
+ return 0;
+ if (directory)
+ *directory = d->name;
+ if (max_bytes)
{
{
- int i;
- for (i = 0; i<mf->no_files; i++)
- unlink(mf->files[i].path);
+ /* possible loss of data. But it's just statistics and lies */
+ *max_bytes = (double) d->max_bytes;
}
}
- return 0;
+ if (used_bytes)
+ {
+ /* possible loss of data. But it's just statistics and lies */
+ *used_bytes = (double) (d->max_bytes - d->avail_bytes);
+ }
+ return 1;
}
}
-
/*
/*
- * Unlink the file by name, rather than MFile-handle. File should be closed.
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
*/
*/
-int mf_unlink_name(MFile_area ma, const char *name)
-{
- abort();
- return 0;
-}
+