]> mj.ucw.cz Git - libucw.git/blob - lib/bucket.h
a9b938bc4d9d6dea9d49906fcc0d0cf9e670327c
[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
17 #define OBUCK_SHIFT 7
18 #define OBUCK_ALIGN (1<<OBUCK_SHIFT)
19 #define OBUCK_MAGIC 0xdeadf00d
20 #define OBUCK_TRAILER 0xfeedcafe
21 #define OBUCK_OID_DELETED (~(oid_t)0)
22
23 struct obuck_header {
24   u32 magic;                    /* OBUCK_MAGIC should dwell here */
25   oid_t oid;                    /* ID of this object or OBUCK_OID_DELETED */
26   u32 length;                   /* Length of compressed data in the bucket */
27   u32 orig_length;              /* Length of uncompressed data */
28   /* Bucket data continue here */
29 };
30
31 struct fastbuf;
32
33 void obuck_init(int writeable);
34 void obuck_cleanup(void);
35 struct fastbuf * obuck_fetch(struct obuck_header *hdrp);
36 void obuck_fetch_abort(struct fastbuf *b);
37 void obuck_fetch_end(struct fastbuf *b);
38 struct fastbuf * obuck_write(void);
39 void obuck_write_end(struct fastbuf *b, struct obuck_header *hdrp);
40 void obuck_delete(oid_t oid);
41 struct fastbuf * obuck_walk_init(void);
42 struct fastbuf * obuck_walk_next(struct fastbuf *b, struct obuck_header *hdrp);
43 void obuck_walk_end(struct fastbuf *b);