#undef LOCAL_DEBUG
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
-#include "ucw/lfs.h"
-#include "ucw/conf.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
+#include <ucw/io.h>
+#include <ucw/conf.h>
#include <string.h>
#include <fcntl.h>
uns window_size;
int mode;
};
-#define FB_MMAP(f) ((struct fb_mmap *)(f)->is_fastbuf)
+#define FB_MMAP(f) ((struct fb_mmap *)(f))
static void
bfmm_map_window(struct fastbuf *f)
else
f->buffer = ucw_mmap(f->buffer, ll, prot, MAP_SHARED | MAP_FIXED, F->fd, pos0);
if (f->buffer == (byte *) MAP_FAILED)
- bthrow(f, "fb.mmap", "mmap(%s): %m", f->name);
+ {
+ f->buffer = NULL;
+ bthrow(f, "mmap", "mmap(%s): %m", f->name);
+ }
#ifdef MADV_SEQUENTIAL
if (ll > CPU_PAGE_SIZE)
madvise(f->buffer, ll, MADV_SEQUENTIAL);
{
F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (ucw_off_t)CPU_PAGE_SIZE);
if (ucw_ftruncate(F->fd, F->file_extend))
- bthrow(f, "fb.write", "ftruncate(%s): %m", f->name);
+ bthrow(f, "write", "ftruncate(%s): %m", f->name);
}
bfmm_map_window(f);
f->bstop = f->bptr;
bfmm_close(struct fastbuf *f)
{
struct fb_mmap *F = FB_MMAP(f);
-
if (f->buffer)
munmap(f->buffer, F->window_size);
- if (F->file_extend > F->file_size &&
+ if (!(f->flags & FB_DEAD) &&
+ F->file_extend > F->file_size &&
ucw_ftruncate(F->fd, F->file_size))
- bthrow(f, "fb.write", "ftruncate(%s): %m", f->name);
+ bthrow(f, "write", "ftruncate(%s): %m", f->name);
bclose_file_helper(f, F->fd, F->is_temp_file);
xfree(f);
}
F->fd = fd;
F->file_extend = F->file_size = ucw_seek(fd, 0, SEEK_END);
if (F->file_size < 0)
- die("seek(%s): %m", name);
+ bthrow(f, "open", "fb-mmap: Cannot detect size of %s -- is it seekable?", name);
if (mode & O_APPEND)
f->pos = F->file_size;
F->mode = mode;
f->seek = bfmm_seek;
f->close = bfmm_close;
f->config = bfmm_config;
- fb_tie(f);
return f;
}