]> mj.ucw.cz Git - libucw.git/blobdiff - lib/bucket.h
If have GET_O and GET_P, we should have PUT_O and PUT_P as well.
[libucw.git] / lib / bucket.h
index a9b938bc4d9d6dea9d49906fcc0d0cf9e670327c..759ef0e4761e4b035d8242a7bc57339bdb4f1280 100644 (file)
  * Locking: Each operation on the pool is protected by a flock.
  *
  * The buckets emulate non-seekable fastbuf streams.
  * Locking: Each operation on the pool is protected by a flock.
  *
  * The buckets emulate non-seekable fastbuf streams.
+ *
+ * fork()'ing if you don't have any bucket open is safe.
  */
 
  */
 
+extern byte *obuck_name;       /* Internal, for use by buckettool only! */
+
 #define OBUCK_SHIFT 7
 #define OBUCK_ALIGN (1<<OBUCK_SHIFT)
 #define OBUCK_MAGIC 0xdeadf00d
 #define OBUCK_SHIFT 7
 #define OBUCK_ALIGN (1<<OBUCK_SHIFT)
 #define OBUCK_MAGIC 0xdeadf00d
+#define OBUCK_INCOMPLETE_MAGIC 0xdeadfeel
 #define OBUCK_TRAILER 0xfeedcafe
 #define OBUCK_OID_DELETED (~(oid_t)0)
 #define OBUCK_TRAILER 0xfeedcafe
 #define OBUCK_OID_DELETED (~(oid_t)0)
+#define OBUCK_OID_FIRST_SPECIAL (~(oid_t)0xffff)
 
 struct obuck_header {
   u32 magic;                   /* OBUCK_MAGIC should dwell here */
 
 struct obuck_header {
   u32 magic;                   /* OBUCK_MAGIC should dwell here */
@@ -30,14 +36,32 @@ struct obuck_header {
 
 struct fastbuf;
 
 
 struct fastbuf;
 
-void obuck_init(int writeable);
-void obuck_cleanup(void);
-struct fastbuf * obuck_fetch(struct obuck_header *hdrp);
-void obuck_fetch_abort(struct fastbuf *b);
+void obuck_init(int writeable);        /* Initialize the bucket module */
+void obuck_cleanup(void);      /* Clean up the bucket module */
+void obuck_sync(void);         /* Flush all buffers to disk */
+
+/* Searching for buckets */
+void obuck_find_by_oid(struct obuck_header *hdrp);
+int obuck_find_first(struct obuck_header *hdrp, int full);
+int obuck_find_next(struct obuck_header *hdrp, int full);
+
+/* Reading current bucket */
+struct fastbuf *obuck_fetch(void);
 void obuck_fetch_end(struct fastbuf *b);
 void obuck_fetch_end(struct fastbuf *b);
-struct fastbuf * obuck_write(void);
-void obuck_write_end(struct fastbuf *b, struct obuck_header *hdrp);
+
+/* Creating buckets */
+struct fastbuf *obuck_create(void);
+void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
+
+/* Deleting buckets */
 void obuck_delete(oid_t oid);
 void obuck_delete(oid_t oid);
-struct fastbuf * obuck_walk_init(void);
-struct fastbuf * obuck_walk_next(struct fastbuf *b, struct obuck_header *hdrp);
-void obuck_walk_end(struct fastbuf *b);
+
+/* Convert bucket ID to file position (for size limitations etc.) */
+
+static inline sh_off_t obuck_get_pos(oid_t oid)
+{
+  return ((sh_off_t) oid) << OBUCK_SHIFT;
+}
+
+/* Shaking down bucket file */
+void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));