]> mj.ucw.cz Git - libucw.git/blob - lib/partmap.h
main_get_timer() made public.
[libucw.git] / lib / partmap.h
1 /*
2  *      UCW Library -- Mapping of File Parts
3  *
4  *      (c) 2003 Martin Mares <mj@ucw.cz>
5  *      (c) 2003--2005 Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _UCW_PARTMAP_H
12 #define _UCW_PARTMAP_H
13
14 struct partmap {
15   int fd;
16   sh_off_t file_size;
17   sh_off_t start_off, end_off;
18   byte *start_map;
19   int writeable;
20 };
21
22 struct partmap *partmap_open(byte *name, int writeable);
23 void partmap_close(struct partmap *p);
24 sh_off_t partmap_size(struct partmap *p);
25 void partmap_load(struct partmap *p, sh_off_t start, uns size);
26
27 static inline void *
28 partmap_map(struct partmap *p, sh_off_t start, uns size)
29 {
30   if (unlikely(!p->start_map || start < p->start_off || (sh_off_t) (start+size) > p->end_off))
31     partmap_load(p, start, size);
32   return p->start_map + (start - p->start_off);
33 }
34
35 static inline void *
36 partmap_map_forward(struct partmap *p, sh_off_t start, uns size)
37 {
38   if (unlikely((sh_off_t) (start+size) > p->end_off))
39     partmap_load(p, start, size);
40   return p->start_map + (start - p->start_off);
41 }
42
43 #endif