X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Ffb-mmap.c;h=e3d7ba5311ee6a9b615dd4e6e46ce9240266e13d;hb=34cb2b0143a1df0cde5edeb5e952db30e85ee987;hp=25209721a4039cc06f604e546c6183ae8b64dd34;hpb=a45646a634b71708f5bc4277868c60e80daaa84c;p=libucw.git diff --git a/ucw/fb-mmap.c b/ucw/fb-mmap.c index 25209721..e3d7ba53 100644 --- a/ucw/fb-mmap.c +++ b/ucw/fb-mmap.c @@ -9,24 +9,24 @@ #undef LOCAL_DEBUG -#include "ucw/lib.h" -#include "ucw/fastbuf.h" -#include "ucw/lfs.h" -#include "ucw/conf.h" +#include +#include +#include +#include #include #include #include #include -static uns mmap_window_size = 16*CPU_PAGE_SIZE; -static uns mmap_extend_size = 4*CPU_PAGE_SIZE; +static uint mmap_window_size = 16*CPU_PAGE_SIZE; +static uint mmap_extend_size = 4*CPU_PAGE_SIZE; #ifndef TEST static struct cf_section fbmm_config = { CF_ITEMS { - CF_UNS("WindowSize", &mmap_window_size), - CF_UNS("ExtendSize", &mmap_extend_size), + CF_UINT("WindowSize", &mmap_window_size), + CF_UINT("ExtendSize", &mmap_extend_size), CF_END } }; @@ -44,10 +44,10 @@ struct fb_mmap { ucw_off_t file_size; ucw_off_t file_extend; ucw_off_t window_pos; - uns window_size; + uint 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) @@ -55,7 +55,7 @@ bfmm_map_window(struct fastbuf *f) struct fb_mmap *F = FB_MMAP(f); ucw_off_t pos0 = f->pos & ~(ucw_off_t)(CPU_PAGE_SIZE-1); int l = MIN((ucw_off_t)mmap_window_size, F->file_extend - pos0); - uns ll = ALIGN_TO(l, CPU_PAGE_SIZE); + uint ll = ALIGN_TO(l, CPU_PAGE_SIZE); int prot = ((F->mode & O_ACCMODE) == O_RDONLY) ? PROT_READ : (PROT_READ | PROT_WRITE); DBG(" ... Mapping %x(%x)+%x(%x) len=%x extend=%x", (int)pos0, (int)f->pos, ll, l, (int)F->file_size, (int)F->file_extend); @@ -70,7 +70,10 @@ 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) - die("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); @@ -115,7 +118,7 @@ bfmm_spout(struct fastbuf *f) { 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)) - die("ftruncate(%s): %m", f->name); + bthrow(f, "write", "ftruncate(%s): %m", f->name); } bfmm_map_window(f); f->bstop = f->bptr; @@ -140,18 +143,18 @@ static void 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)) - die("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); } static int -bfmm_config(struct fastbuf *f, uns item, int value) +bfmm_config(struct fastbuf *f, uint item, int value) { int orig; @@ -167,7 +170,7 @@ bfmm_config(struct fastbuf *f, uns item, int value) } struct fastbuf * -bfmmopen_internal(int fd, const char *name, uns mode) +bfmmopen_internal(int fd, const char *name, uint mode) { int namelen = strlen(name) + 1; struct fb_mmap *F = xmalloc(sizeof(struct fb_mmap) + namelen); @@ -179,7 +182,7 @@ bfmmopen_internal(int fd, const char *name, uns mode) 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; @@ -189,7 +192,6 @@ bfmmopen_internal(int fd, const char *name, uns mode) f->seek = bfmm_seek; f->close = bfmm_close; f->config = bfmm_config; - fb_tie(f); return f; }