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 s_Attrblobpage
15 {
16   /* page_size == 0 means the page is not backed by some file storage.
17      Otherwise it is L*2+(compressed ? 1 : 0), with L being the data
18      length.  */
19   unsigned int page_offset;
20   unsigned int page_size;
21 } Attrblobpage;
22 
23 typedef struct s_Repopagestore {
24   int pagefd;		/* file descriptor we're paging from */
25   long file_offset;	/* pages in file start here */
26 
27   unsigned char *blob_store;
28   unsigned int num_pages;
29 
30   /* mapped_at[page] == -1  --> not loaded, otherwise offset into
31      store->blob_store.  The size of the mapping is REPOPAGE_BLOBSIZE
32      except for the last page.  */
33   unsigned int *mapped_at;
34 
35   Attrblobpage *file_pages;
36 
37   /* mapped[i] is -1 if nothing is mapped at logical page I,
38    otherwise it contains the page number (of the mapped page).  */
39   unsigned int *mapped;
40   unsigned int nmapped;
41   unsigned int rr_counter;
42 } Repopagestore;
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 void repopagestore_init(Repopagestore *store);
49 void repopagestore_free(Repopagestore *store);
50 
51 /* load pages pstart..pend into consecutive memory, return address */
52 unsigned char *repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigned int pend);
53 
54 /* compress a page, return compressed len */
55 unsigned int repopagestore_compress_page(unsigned char *page, unsigned int len, unsigned char *cpage, unsigned int max);
56 
57 /* setup page data for repodata_load_page_range */
58 int repopagestore_read_or_setup_pages(Repopagestore *store, FILE *fp, unsigned int pagesz, unsigned int blobsz);
59 
60 void repopagestore_disable_paging(Repopagestore *store);
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif	/* LIBSOLV_REPOPAGE_H */
67