From a6249a8696736f7f8c0d497d3056b6679cbd7f87 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Tue, 3 Feb 2009 21:27:16 -0800 Subject: [PATCH] fix partmap_load(size=0), because mmap fails on that since Linux 2.6.12 --- ucw/partmap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ucw/partmap.c b/ucw/partmap.c index 93a7e1ba..a823d3d1 100644 --- a/ucw/partmap.c +++ b/ucw/partmap.c @@ -2,7 +2,7 @@ * UCW Library -- Mapping of File Parts * * (c) 2003--2006 Martin Mares - * (c) 2003--2005 Robert Spalek + * (c) 2003--2009 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -69,13 +69,18 @@ partmap_load(struct partmap *p, ucw_off_t start, uns size) ucw_off_t end = start + size; ucw_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE; size_t win_len = PARTMAP_WINDOW; - if (win_len > p->file_size - win_start) + if (win_len > (size_t) (p->file_size - win_start)) win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE); if ((ucw_off_t) (win_start+win_len) < end) die("partmap_map: Window is too small for mapping %d bytes", size); - p->start_map = ucw_mmap(NULL, win_len, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, win_start); - if (p->start_map == MAP_FAILED) - die("mmap failed at position %lld: %m", (long long)win_start); + if (win_len) + { + p->start_map = ucw_mmap(NULL, win_len, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, win_start); + if (p->start_map == MAP_FAILED) + die("mmap failed at position %lld: %m", (long long)win_start); + } + else + p->start_map = NULL; p->start_off = win_start; p->end_off = win_start+win_len; madvise(p->start_map, win_len, MADV_SEQUENTIAL); -- 2.39.2