X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Ffb-mmap.c;h=b6a61248cf42a7ed15fa2da2b70aaff1f1a3fc3e;hb=623185a65b8870abb82cd0dd8547a1aa4fc1f535;hp=25209721a4039cc06f604e546c6183ae8b64dd34;hpb=a45646a634b71708f5bc4277868c60e80daaa84c;p=libucw.git diff --git a/ucw/fb-mmap.c b/ucw/fb-mmap.c index 25209721..b6a61248 100644 --- a/ucw/fb-mmap.c +++ b/ucw/fb-mmap.c @@ -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, "fb.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, "fb.write", "ftruncate(%s): %m", f->name); } bfmm_map_window(f); f->bstop = f->bptr; @@ -140,12 +143,12 @@ 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, "fb.write", "ftruncate(%s): %m", f->name); bclose_file_helper(f, F->fd, F->is_temp_file); xfree(f); } @@ -189,8 +192,7 @@ 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; + return fb_tie(f); } #ifdef TEST