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 */
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);
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);
54 /* Reading current bucket */
55 struct fastbuf *obuck_fetch(void);
56 void obuck_fetch_end(struct fastbuf *b);
58 /* Creating buckets */
59 struct fastbuf *obuck_create(void);
60 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
62 /* Deleting buckets */
63 void obuck_delete(oid_t oid);
65 /* Fast reading of the whole pool */
66 struct fastbuf *obuck_slurp_pool(struct obuck_header *hdrp);
68 /* Convert bucket ID to file position (for size limitations etc.) */
70 static inline sh_off_t obuck_get_pos(oid_t oid)
72 return ((sh_off_t) oid) << OBUCK_SHIFT;
75 /* Shaking down bucket file */
76 void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));