2 * Sherlock Library -- Object Buckets
4 * (c) 2001 Martin Mares <mj@ucw.cz>
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.
12 * Locking: Each operation on the pool is protected by a flock.
14 * The buckets emulate non-seekable fastbuf streams.
16 * fork()'ing if you don't have any bucket open is safe.
19 extern byte *obuck_name; /* Internal, for use by buckettool only! */
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)
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 */
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 */
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);
48 /* Reading current bucket */
49 struct fastbuf *obuck_fetch(void);
50 void obuck_fetch_end(struct fastbuf *b);
52 /* Creating buckets */
53 struct fastbuf *obuck_create(void);
54 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
56 /* Deleting buckets */
57 void obuck_delete(oid_t oid);
59 /* Convert bucket ID to file position (for size limitations etc.) */
61 static inline sh_off_t obuck_get_pos(oid_t oid)
63 return ((sh_off_t) oid) << OBUCK_SHIFT;
66 /* Shaking down bucket file */
67 void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));