X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=bfile%2Fmfile.c;h=06d4781c3198b123b553cec76161069e89e57da7;hb=3946190aece0417a4ad4e40946dfcb9f1bca4755;hp=ce4279afc966159ca3bed910e565041b6a055a3f;hpb=47eeb5384a8fae8bcac8afb8a84782ca094683f9;p=idzebra-moved-to-github.git diff --git a/bfile/mfile.c b/bfile/mfile.c index ce4279a..06d4781 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,5 +1,5 @@ -/* $Id: mfile.c,v 1.62 2005-06-14 20:28:53 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: mfile.c,v 1.68 2006-10-09 22:10:00 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 + */ @@ -252,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]; @@ -309,24 +308,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; @@ -338,13 +324,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; @@ -352,7 +341,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) { @@ -384,7 +372,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); @@ -449,8 +436,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; @@ -598,27 +583,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; -} +