X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fpartmap.c;h=8dba8f8fcffe6ec891978d919db7430acf934cbd;hb=36313f6350b823895c65111fe577083cbc58e088;hp=e0832fcd798d1b5b0e679adcc8145cd04c5941fd;hpb=e046e98358467bc0b8a3e6bdb7685311aea462e4;p=libucw.git diff --git a/lib/partmap.c b/lib/partmap.c index e0832fcd..8dba8f8f 100644 --- a/lib/partmap.c +++ b/lib/partmap.c @@ -1,7 +1,7 @@ /* * UCW Library -- Mapping of File Parts * - * (c) 2003 Martin Mares + * (c) 2003--2006 Martin Mares * (c) 2003--2005 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -10,6 +10,7 @@ #include "lib/lib.h" #include "lib/lfs.h" +#include "lib/partmap.h" #include #include @@ -19,11 +20,15 @@ #include #include +#ifdef CONFIG_PARTMAP_IS_MMAP +#define PARTMAP_WINDOW ~(size_t)0 +#else #ifdef TEST #define PARTMAP_WINDOW 4096 #else #define PARTMAP_WINDOW 16777216 #endif +#endif struct partmap * partmap_open(byte *name, int writeable) @@ -36,6 +41,9 @@ partmap_open(byte *name, int writeable) if ((p->file_size = sh_seek(p->fd, 0, SEEK_END)) < 0) die("lseek(%s): %m", name); p->writeable = writeable; +#ifdef CONFIG_PARTMAP_IS_MMAP + partmap_load(p, 0, p->file_size); +#endif return p; } @@ -61,9 +69,9 @@ partmap_load(struct partmap *p, sh_off_t start, uns size) 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; + size_t 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); + win_len = ALIGN_TO(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); @@ -71,6 +79,7 @@ partmap_load(struct partmap *p, sh_off_t start, uns size) die("mmap failed at position %Ld: %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); } #ifdef TEST