chiark / gitweb /
writeable wip
authorian <ian>
Sun, 15 Jan 2006 15:42:11 +0000 (15:42 +0000)
committerian <ian>
Sun, 15 Jan 2006 15:42:11 +0000 (15:42 +0000)
cdb/cdb.tct
cdb/writeable.c

index e55e15c6a6d3f067d38deb21b04f93812370c577..fca6ecbcab0e6ddb2605ddcd5a46e8ecadf6a67d 100644 (file)
@@ -26,10 +26,13 @@ Table cdbwr Cdbwr_SubCommand
                pathb   string
                # files:
                #       <pathb>.main
+               #       <pathb>.lock
                #       <pathb>.cdb
                #       <pathb>.log
                #       <pathb>.tmp (might be new .main or new .cdb)
                # invariants:
+               #       .lock is an empty file
+               #         which is locked with fcntl by open
                #       .main is a cdb native text file
                #         and always exists
                #       if .tmp exists it is irrelevant
index 140c1ffeaea4ed583b89997cb3c85998ffe7f94f..15afdf5f5ba287eaeeedfe96f8fe44221f20076b 100644 (file)
@@ -2,8 +2,67 @@
 
 #include "chiark_tcl_cdb.h"
 
+/*---------- Pathbuf ----------*/
+
+typedef struct {
+  char *buf, *sfx;
+} Pathbuf;
+
+#define MAX_SUFFIX 4
+
+static void pathbuf_init(Pathbuf *pb, const char *pathb) {
+  int l= strlen(pathb);
+  pb->buf= TALLOC(l + 4);
+  memcpy(pb->buf, pathb, l);
+  pb->sfx= pb->buf + l;
+  *pb->sfx++= '.';
+}
+static const char *pathbuf_sfx(Pathbuf *pb, const char *suffix) {
+  assert(strlen(suffix) <= MAX_SUFFIX);
+  strcpy(pb->sfx, suffix);
+  return pb->buf;
+}
+static void pathbuf_free(Pathbuf *pb) {
+  TFREE(pb->buf);
+  pb->buf= 0;
+}
+
+/*---------- Rw data structure ----------*/
+
+typedef struct {
+  Pathbuf pbsome, pbtmp;
+} Rw;
+
 static void destroy_cdbrw_idtabcb(Tcl_Interp *ip, void *val) { abort(); }
 
 const IdDataSpec cdbtcl_rwdatabases= {
   "cdb-rwdb", "cdb-openrwdatabases-table", destroy_cdbrw_idtabcb
 };
+
+
+
+/*---------- Misc functionality ----------*/
+
+int cht_do_cdbwr_create_empty(ClientData cd, Tcl_Interp *ip,
+                             const char *pathb) {
+  Pathbuf pb;
+  int lock_fd=-1, fd=-1;
+
+  pathbuf_init(&pb, pathb);
+  rc= acquire_lock(ip, &pb, &lock_fd);  if (rc) goto x_rc;
+  
+  fd= open(pathbuf_sfx(".lock"), O_RDONLY
+  
+
+
+int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb, Tcl_Obj *on_info, void **result);
+
+
+int cht_do_cdbwr_close(ClientData cd, Tcl_Interp *ip, void *db);
+int cht_do_cdbwr_close_quick(ClientData cd, Tcl_Interp *ip, void *db);
+int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *db, Tcl_Obj *key, Tcl_Obj **result);
+int cht_do_cdbwr_lookup_hb(ClientData cd, Tcl_Interp *ip, void *db, HBytes_Value key, HBytes_Value *result);
+int cht_do_cdbwr_update(ClientData cd, Tcl_Interp *ip, void *db, Tcl_Obj *key, Tcl_Obj *value);
+int cht_do_cdbwr_update_hb(ClientData cd, Tcl_Interp *ip, void *db, HBytes_Value key, HBytes_Value value);
+int cht_do_cdbwr_update_quick(ClientData cd, Tcl_Interp *ip, void *db, Tcl_Obj *key, Tcl_Obj *value);
+int cht_do_cdbwr_update_quick_hb(ClientData cd, Tcl_Interp *ip, void *db, HBytes_Value key, HBytes_Value value);