]> mj.ucw.cz Git - libucw.git/blob - lib/bucket.h
Generate index cards.
[libucw.git] / lib / bucket.h
1 /*
2  *      Sherlock Library -- Object Buckets
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 /*
8  * Format: The object pool is merely a sequence of object buckets.
9  * Each bucket starts with struct obuck_header and it's padded
10  * by zeros to a multiple of OBUCK_ALIGN bytes.
11  *
12  * Locking: Each operation on the pool is protected by a flock.
13  *
14  * The buckets emulate non-seekable fastbuf streams.
15  *
16  * fork()'ing if you don't have any bucket open is safe.
17  */
18
19 extern byte *obuck_name;        /* Internal, for use by buckettool only! */
20
21 #define OBUCK_SHIFT 7
22 #define OBUCK_ALIGN (1<<OBUCK_SHIFT)
23 #define OBUCK_MAGIC 0xdeadf00d
24 #define OBUCK_INCOMPLETE_MAGIC 0xdeadfeel
25 #define OBUCK_TRAILER 0xfeedcafe
26 #define OBUCK_OID_DELETED (~(oid_t)0)
27 #define OBUCK_OID_FIRST_SPECIAL (~(oid_t)0xffff)
28
29 struct obuck_header {
30   u32 magic;                    /* OBUCK_MAGIC should dwell here */
31   oid_t oid;                    /* ID of this object or OBUCK_OID_DELETED */
32   u32 length;                   /* Length of compressed data in the bucket */
33   u32 orig_length;              /* Length of uncompressed data */
34   /* Bucket data continue here */
35 };
36
37 struct fastbuf;
38
39 void obuck_init(int writeable); /* Initialize the bucket module */
40 void obuck_cleanup(void);       /* Clean up the bucket module */
41 void obuck_sync(void);          /* Flush all buffers to disk */
42
43 /* Searching for buckets */
44 void obuck_find_by_oid(struct obuck_header *hdrp);
45 int obuck_find_first(struct obuck_header *hdrp, int full);
46 int obuck_find_next(struct obuck_header *hdrp, int full);
47
48 /* Reading current bucket */
49 struct fastbuf *obuck_fetch(void);
50 void obuck_fetch_end(struct fastbuf *b);
51
52 /* Creating buckets */
53 struct fastbuf *obuck_create(void);
54 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
55
56 /* Deleting buckets */
57 void obuck_delete(oid_t oid);