- if (!p->start_map || start < p->start_off || (sh_off_t) (start+size) > p->end_off)
- {
- if (p->start_map)
- munmap(p->start_map, p->end_off - p->start_off);
- sh_off_t end = start + size;
- sh_off_t win_start = start/PAGE_SIZE * PAGE_SIZE;
- uns win_len = PARTMAP_WINDOW;
- if ((sh_off_t) (win_start+win_len) > p->file_size)
- win_len = ALIGN(p->file_size - win_start, PAGE_SIZE);
- if ((sh_off_t) (win_start+win_len) < end)
- die("partmap_map: Window is too small for mapping %d bytes", size);
- p->start_map = sh_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 %Ld: %m", (long long)win_start);
- p->start_off = win_start;
- p->end_off = win_start+win_len;
- }
- return p->start_map + (start - p->start_off);
+ if (p->start_map)
+ munmap(p->start_map, p->end_off - p->start_off);
+ sh_off_t end = start + size;
+ sh_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE;
+ size_t win_len = PARTMAP_WINDOW;
+ if ((sh_off_t) (win_start+win_len) > p->file_size)
+ win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE);
+ if ((sh_off_t) (win_start+win_len) < end)
+ die("partmap_map: Window is too small for mapping %d bytes", size);
+ p->start_map = sh_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);
+ p->start_off = win_start;
+ p->end_off = win_start+win_len;
+ madvise(p->start_map, win_len, MADV_SEQUENTIAL);