]> mj.ucw.cz Git - libucw.git/blob - ucw/partmap.h
tableprinter: definition of the table separated from handle
[libucw.git] / ucw / partmap.h
1 /*
2  *      UCW Library -- Mapping of File Parts
3  *
4  *      (c) 2003--2006 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 #ifdef CONFIG_UCW_CLEAN_ABI
15 #define partmap_close ucw_partmap_close
16 #define partmap_load ucw_partmap_load
17 #define partmap_open ucw_partmap_open
18 #define partmap_size ucw_partmap_size
19 #endif
20
21 struct partmap {
22   int fd;
23   ucw_off_t file_size;
24   ucw_off_t start_off, end_off;
25   byte *start_map;
26   int writeable;
27 };
28
29 struct partmap *partmap_open(char *name, int writeable);
30 void partmap_close(struct partmap *p);
31 ucw_off_t partmap_size(struct partmap *p);
32 void partmap_load(struct partmap *p, ucw_off_t start, uint size);
33
34 static inline void *partmap_map(struct partmap *p, ucw_off_t start, uint size UNUSED)
35 {
36 #ifndef CONFIG_UCW_PARTMAP_IS_MMAP
37   if (unlikely(!p->start_map || start < p->start_off || (ucw_off_t) (start+size) > p->end_off))
38     partmap_load(p, start, size);
39 #endif
40   return p->start_map + (start - p->start_off);
41 }
42
43 static inline void *partmap_map_forward(struct partmap *p, ucw_off_t start, uint size UNUSED)
44 {
45 #ifndef CONFIG_UCW_PARTMAP_IS_MMAP
46   if (unlikely((ucw_off_t) (start+size) > p->end_off))
47     partmap_load(p, start, size);
48 #endif
49   return p->start_map + (start - p->start_off);
50 }
51
52 #endif