X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fpartmap.c;h=d3892ff58ffd56816fd4a1ca40d17060e939306d;hb=e29c6b7097c92fb1ee0587d167e1c434db198056;hp=2947bedffa62ae1e10e3fbbc14cf60349648c503;hpb=bc6049e67fb8de5774b7f6d3160bc89f952f9428;p=libucw.git diff --git a/lib/partmap.c b/lib/partmap.c index 2947bedf..d3892ff5 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. @@ -16,6 +17,7 @@ #include #include #include +#include struct partmap { int fd; @@ -69,8 +71,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);