X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=bfile%2Fmfile.c;h=5f0547355e2285b816e58334fa4d559c806209ac;hb=ca8c7208a371bcfb79c846dfec9cd7cb42ecaf92;hp=ecd795d6dd7931e1df8f44854d8f9952ac76a3d3;hpb=c4f5c81c1fef61826e2ca7815d5f427a0a82b8e7;p=idzebra-moved-to-github.git diff --git a/bfile/mfile.c b/bfile/mfile.c index ecd795d..5f05473 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,5 +1,5 @@ -/* $Id: mfile.c,v 1.61 2005-05-17 08:50:48 adam Exp $ - Copyright (C) 1995-2005 +/* $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. @@ -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 -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 #ifdef WIN32 #include -#else +#endif +#if HAVE_UNISTD_H #include #endif #include @@ -251,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->unlink_flag = 0; ma->mfiles = meta_f; strcpy(meta_f->name, metaname); part_f = &meta_f->files[0]; @@ -297,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; - meta_file *meta_f; if (!ma) return; @@ -308,24 +307,11 @@ void mf_destroy(MFile_area ma) dp = dp->next; xfree (d); } - meta_f = ma->mfiles; - while (meta_f) - { - int i; - meta_file *m = meta_f; - - for (i = 0; ino_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); } -void mf_reset(MFile_area ma) +void mf_reset(MFile_area ma, int unlink_flag) { meta_file *meta_f; @@ -337,13 +323,16 @@ void mf_reset(MFile_area ma) int i; meta_file *m = meta_f; + meta_f = meta_f->next; + assert (!m->open); for (i = 0; ino_files; i++) { - unlink (m->files[i].path); + if (unlink_flag) + unlink (m->files[i].path); xfree (m->files[i].path); } - meta_f = meta_f->next; + zebra_mutex_destroy (&m->mutex); xfree (m); } ma->mfiles = 0; @@ -351,7 +340,6 @@ void mf_reset(MFile_area ma) /* * Open a metafile. - * If !ma, Use MF_DEFAULT_AREA. */ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) { @@ -383,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->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); @@ -448,8 +435,6 @@ int mf_close(MFile mf) close(mf->files[i].fd); mf->files[i].fd = -1; } - if (mf->unlink_flag) - unlink(mf->files[i].path); } mf->open = 0; return 0; @@ -597,27 +582,34 @@ int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf) 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 && inext) + ; + if (!d) + return 0; + if (directory) + *directory = d->name; + if (max_bytes) { - int i; - for (i = 0; ino_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; -} +