X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fpartmap.c;h=9108353a0e972c04607e033f2395cd20b50ab95b;hb=033a59facff290e2e0f6ed2f97cee5b07cf99e12;hp=93a7e1ba02689b5c3bd4a0f0c5e6c43b81b45db1;hpb=72730c8119f088f39e6ad8c5b0dde446a3940578;p=libucw.git diff --git a/ucw/partmap.c b/ucw/partmap.c index 93a7e1ba..9108353a 100644 --- a/ucw/partmap.c +++ b/ucw/partmap.c @@ -2,15 +2,15 @@ * UCW Library -- Mapping of File Parts * * (c) 2003--2006 Martin Mares - * (c) 2003--2005 Robert Spalek + * (c) 2003--2009 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/lfs.h" -#include "ucw/partmap.h" +#include +#include +#include #include #include @@ -62,20 +62,25 @@ partmap_close(struct partmap *p) } void -partmap_load(struct partmap *p, ucw_off_t start, uns size) +partmap_load(struct partmap *p, ucw_off_t start, uint size) { if (p->start_map) munmap(p->start_map, p->end_off - p->start_off); ucw_off_t end = start + size; ucw_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE; size_t win_len = PARTMAP_WINDOW; - if (win_len > p->file_size - win_start) + if (win_len > (size_t) (p->file_size - win_start)) win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE); if ((ucw_off_t) (win_start+win_len) < end) die("partmap_map: Window is too small for mapping %d bytes", size); - p->start_map = ucw_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); + if (win_len) + { + p->start_map = ucw_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); + } + else + p->start_map = NULL; p->start_off = win_start; p->end_off = win_start+win_len; madvise(p->start_map, win_len, MADV_SEQUENTIAL); @@ -85,8 +90,8 @@ partmap_load(struct partmap *p, ucw_off_t start, uns size) int main(int argc, char **argv) { struct partmap *p = partmap_open(argv[1], 0); - uns l = partmap_size(p); - uns i; + uint l = partmap_size(p); + uint i; for (i=0; i