From 22d2bb38fbca404d5f53a962591f1ce1574b8c04 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Mon, 3 Nov 2003 14:15:11 +0000 Subject: [PATCH] this could never have worked --- lib/partmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/partmap.c b/lib/partmap.c index 2947bedf..756fdb63 100644 --- a/lib/partmap.c +++ b/lib/partmap.c @@ -2,6 +2,7 @@ * Sherlock Library -- Mapping of File Parts * * (c) 2003 Martin Mares + * (c) 2003 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -31,9 +32,14 @@ struct partmap { #define PARTMAP_WINDOW 16777216 #endif +static uns page_size; + struct partmap * partmap_open(byte *name, int writeable) { + if (!page_size) + page_size = getpagesize(); + struct partmap *p = xmalloc_zero(sizeof(struct partmap)); p->fd = sh_open(name, writeable ? O_RDWR : O_RDONLY); @@ -69,8 +75,12 @@ partmap_map(struct partmap *p, sh_off_t start, uns size) munmap(p->start_map, p->end_off - p->start_off); uns win = PARTMAP_WINDOW; ASSERT(win >= size); + sh_off_t end = start + size; + start = start/page_size * page_size; if (start+win > p->file_size) win = p->file_size - start; + if (start+win < end) + die("cannot mmap, the window is too small"); p->start_map = sh_mmap(NULL, win, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, start); if (p->start_map == MAP_FAILED) die("mmap failed at position %Ld: %m", (long long)start); -- 2.39.2