simplily repopage handling quite a bit
[platform/upstream/libsolv.git] / src / repopage.h
1 /*
2  * Copyright (c) 2007-2011, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 #ifndef LIBSOLV_REPOPAGE_H
9 #define LIBSOLV_REPOPAGE_H
10
11 #define REPOPAGE_BLOBBITS 15
12 #define REPOPAGE_BLOBSIZE (1 << REPOPAGE_BLOBBITS)
13
14 typedef struct _Attrblobpage
15 {
16   /* mapped_at == -1  --> not loaded, otherwise offset into
17      store->blob_store.  The size of the mapping is REPOPAGE_BLOBSIZE
18      except for the last page.  */
19   unsigned int mapped_at;
20
21   /* page_size == 0 means the page is not backed by some file storage.
22      Otherwise it is L*2+(compressed ? 1 : 0), with L being the data
23      length.  */
24   unsigned int page_offset;
25   unsigned int page_size;
26 } Attrblobpage;
27
28 typedef struct _Repopagestore {
29   int pagefd;           /* file descriptor we're paging from */
30   long file_offset;     /* pages in file start here */
31
32   unsigned char *blob_store;
33   Attrblobpage *pages;
34   unsigned int num_pages;
35
36   /* mapped[i] is zero if nothing is mapped at logical page I,
37    otherwise it contains the pagenumber plus one (of the mapped page).  */
38   unsigned int *mapped;
39   unsigned int nmapped;
40   unsigned int rr_counter;
41 } Repopagestore;
42
43 void repopagestore_init(Repopagestore *store);
44 void repopagestore_free(Repopagestore *store);
45
46 /* load pages pstart..pend into consecutive memory, return address */
47 unsigned char *repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigned int pend);
48
49 /* compress a page, return compressed len */
50 unsigned int repopagestore_compress_page(unsigned char *page, unsigned int len, unsigned char *cpage, unsigned int max);
51
52 /* setup page data for repodata_load_page_range */
53 int repopagestore_read_or_setup_pages(Repopagestore *store, FILE *fp, unsigned int pagesz, unsigned int blobsz);
54
55 void repopagestore_disable_paging(Repopagestore *store);
56
57 #endif  /* LIBSOLV_REPOPAGE_H */