2 * Sherlock Library -- Object Buckets
4 * (c) 2001 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
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.
15 * Locking: Each operation on the pool is protected by a flock.
17 * The buckets emulate non-seekable fastbuf streams.
19 * fork()'ing if you don't have any bucket open is safe.
22 extern byte *obuck_name; /* Internal, for use by buckettool only! */
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)
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 */
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 */
46 /* Searching for buckets */
47 void obuck_find_by_oid(struct obuck_header *hdrp);
48 int obuck_find_first(struct obuck_header *hdrp, int full);
49 int obuck_find_next(struct obuck_header *hdrp, int full);
51 /* Reading current bucket */
52 struct fastbuf *obuck_fetch(void);
53 void obuck_fetch_end(struct fastbuf *b);
55 /* Creating buckets */
56 struct fastbuf *obuck_create(void);
57 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
59 /* Deleting buckets */
60 void obuck_delete(oid_t oid);
62 /* Convert bucket ID to file position (for size limitations etc.) */
64 static inline sh_off_t obuck_get_pos(oid_t oid)
66 return ((sh_off_t) oid) << OBUCK_SHIFT;
69 /* Shaking down bucket file */
70 void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));