]> mj.ucw.cz Git - libucw.git/blob - lib/bucket.h
Fix escaping of "+" characters in outgoing parameters. (BTW: when Galeon
[libucw.git] / lib / bucket.h
1 /*
2  *      Sherlock Library -- Object Buckets
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 /*
11  * Format: The object pool is merely a sequence of object buckets.
12  * Each bucket starts with struct obuck_header and it's padded
13  * by zeros to a multiple of OBUCK_ALIGN bytes.
14  *
15  * Locking: Each operation on the pool is protected by a flock.
16  *
17  * The buckets emulate non-seekable fastbuf streams.
18  *
19  * fork()'ing if you don't have any bucket open is safe.
20  */
21
22 extern byte *obuck_name;        /* Internal, for use by buckettool only! */
23
24 #define OBUCK_SHIFT 7
25 #define OBUCK_ALIGN (1<<OBUCK_SHIFT)
26 #define OBUCK_MAGIC 0xdeadf00d
27 #define OBUCK_INCOMPLETE_MAGIC 0xdeadfeel
28 #define OBUCK_TRAILER 0xfeedcafe
29 #define OBUCK_OID_DELETED (~(oid_t)0)
30 #define OBUCK_OID_FIRST_SPECIAL (~(oid_t)0xffff)
31
32 struct obuck_header {
33   u32 magic;                    /* OBUCK_MAGIC should dwell here */
34   oid_t oid;                    /* ID of this object or OBUCK_OID_DELETED */
35   u32 length;                   /* Length of compressed data in the bucket */
36   u32 orig_length;              /* Length of uncompressed data */
37   /* Bucket data continue here */
38 };
39
40 struct fastbuf;
41
42 void obuck_init(int writeable); /* Initialize the bucket module */
43 void obuck_cleanup(void);       /* Clean up the bucket module */
44 void obuck_sync(void);          /* Flush all buffers to disk */
45 void obuck_lock_read(void);     /* Explicit locking to make sure other threads don't touch buckets now */
46 void obuck_lock_write(void);
47 void obuck_unlock(void);
48
49 /* Searching for buckets */
50 void obuck_find_by_oid(struct obuck_header *hdrp);
51 int obuck_find_first(struct obuck_header *hdrp, int full);
52 int obuck_find_next(struct obuck_header *hdrp, int full);
53
54 /* Reading current bucket */
55 struct fastbuf *obuck_fetch(void);
56 void obuck_fetch_end(struct fastbuf *b);
57
58 /* Creating buckets */
59 struct fastbuf *obuck_create(void);
60 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
61
62 /* Deleting buckets */
63 void obuck_delete(oid_t oid);
64
65 /* Convert bucket ID to file position (for size limitations etc.) */
66
67 static inline sh_off_t obuck_get_pos(oid_t oid)
68 {
69   return ((sh_off_t) oid) << OBUCK_SHIFT;
70 }
71
72 /* Shaking down bucket file */
73 void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));