* Sherlock Library -- Mapping of File Parts
*
* (c) 2003 Martin Mares <mj@ucw.cz>
+ * (c) 2003 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
+#include <sys/user.h>
struct partmap {
int fd;
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);