Author: adrian.chadd
Date: Mon Apr 20 01:21:19 2009
New Revision: 13955

Modified:
    branches/LUSCA_HEAD/src/ufs_utils.c
    branches/LUSCA_HEAD/src/ufs_utils.h

Log:
Start fleshing out the ufs swaplog array thingy a bit more.



Modified: branches/LUSCA_HEAD/src/ufs_utils.c
==============================================================================
--- branches/LUSCA_HEAD/src/ufs_utils.c (original)
+++ branches/LUSCA_HEAD/src/ufs_utils.c Mon Apr 20 01:21:19 2009
@@ -1,7 +1,82 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include "squid.h"
+#include "ufs_utils.h"

-#include "../libcore/varargs.h"
-#include "../libsqdebug/debug.h"
+static int
+ufs_swaplog_grow(ufs_swaplog_t *el, int newsize)
+{
+       storeSwapLogData *b;
+
+       if (newsize < el->size)
+               return 1;
+
+       b = realloc(el->buf, (newsize + 16) * sizeof(storeSwapLogData));
+       if (! b)
+               return -1;
+       el->buf = b;
+       el->size = newsize + 16;
+
+       return 1;
+}
+
+void
+ufs_swaplog_init(ufs_swaplog_t *el)
+{
+       bzero(el, sizeof(*el));
+       (void) ufs_swaplog_grow(el, 128);
+}
+
+void
+ufs_swaplog_done(ufs_swaplog_t *el)
+{
+       safe_free(el->buf);
+}
+
+int
+ufs_swaplog_append(ufs_swaplog_t *el, StoreEntry *e, int op)
+{
+    storeSwapLogData *s;
+
+    if (ufs_swaplog_grow(el, el->count + 1)) {
+       return -1;
+    }
+    assert(el->count < el->size);
+
+    s = &el->buf[el->count++];
+
+    s->op = (char) op;
+    s->swap_filen = e->swap_filen;
+    s->timestamp = e->timestamp;
+    s->lastref = e->lastref;
+    s->expires = e->expires;
+    s->lastmod = e->lastmod;
+    s->swap_file_sz = e->swap_file_sz;
+    s->refcount = e->refcount;
+    s->flags = e->flags;
+    xmemcpy(s->key, e->hash.key, SQUID_MD5_DIGEST_LENGTH);
+
+    return 1;
+}
+
+size_t
+ufs_swaplog_getarray_count(ufs_swaplog_t *el)
+{
+       return el->count;
+}
+
+size_t
+ufs_swaplog_getarray_buf_totalsize(ufs_swaplog_t *el)
+{
+       return el->size;
+}
+
+storeSwapLogData *
+ufs_swaplog_take_buffer(ufs_swaplog_t *el)
+{
+       storeSwapLogData *b;
+
+       b = el->buf;
+       el->buf = NULL;
+       el->count = el->size = 0;
+       return b;
+}


Modified: branches/LUSCA_HEAD/src/ufs_utils.h
==============================================================================
--- branches/LUSCA_HEAD/src/ufs_utils.h (original)
+++ branches/LUSCA_HEAD/src/ufs_utils.h Mon Apr 20 01:21:19 2009
@@ -1,6 +1,22 @@
  #ifndef       __LUSCA_UFS_UTILS_H__
  #define       __LUSCA_UFS_UTILS_H__

+struct _ufsSwapLogEntryList {
+       storeSwapLogData *buf;
+       int count;
+       int size;
+};
+
+typedef struct _ufsSwapLogEntryList ufs_swaplog_t;
+
+extern void ufs_swaplog_init(ufs_swaplog_t *el);
+extern int ufs_swaplog_append(ufs_swaplog_t *el, StoreEntry *e, int op);
+extern void ufs_swaplog_done(ufs_swaplog_t *el);
+
+extern size_t ufs_swaplog_getarray_count(ufs_swaplog_t *el);
+extern size_t ufs_swaplog_getarray_buf_totalsize(ufs_swaplog_t *el);
+extern storeSwapLogData * ufs_swaplog_take_buffer(ufs_swaplog_t *el);
+


  #endif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to