Revision: 14505
Author: adrian.chadd
Date: Sun Mar 28 00:37:53 2010
Log: Add in a basic UFS file info program. It just prints out the metadata
at the moment.


http://code.google.com/p/lusca-cache/source/detail?r=14505

Added:
 /branches/LUSCA_HEAD/tools/ufs_obj_cat.c
Modified:
 /branches/LUSCA_HEAD/tools/Makefile.am

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/tools/ufs_obj_cat.c    Sun Mar 28 00:37:53 2010
@@ -0,0 +1,122 @@
+#include "../include/config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "../libcore/varargs.h"
+#include "../libcore/tools.h"
+#include "../libcore/kb.h"           /* for squid_off_t */
+#include "../libcore/debug.h"
+
+#include "../libsqtlv/tlv.h"
+
+#define SQUID_MD5_DIGEST_LENGTH 16
+
+#include "../libsqstore/store_mgr.h"
+#include "../libsqstore/store_meta.h"
+#include "../libsqstore/store_log.h"
+
+/* XXX temporary! because of linking related stuff! */
+int shutting_down = 0;
+
+
+static const char *
+storeKeyText(const unsigned char *key)
+{
+        static char buf[64];
+        char b2[4];
+
+        buf[0] = '\0';
+
+        int i;
+        for (i = 0; i < 16; i++) {
+                sprintf(b2, "%02X", *(key + i));
+                strcat(buf, b2);
+        }
+        return buf;
+}
+
+#define        META_BUFSIZ             4096
+
+int
+main(int argc, const char *argv[])
+{
+       const char *path = NULL;
+       int fd, r;
+       char buf[META_BUFSIZ];
+       tlv *t, *tl;
+
+       path = argv[1];
+
+       /* open the file */
+       fd = open(path, O_RDONLY);
+       if (fd < 0) {
+               perror("open");
+               exit(1);
+       }
+
+       /* read in the metadata */
+       r = read(fd, buf, META_BUFSIZ);
+       if (r <= 0) {
+               perror("read");
+               exit(1);
+       }
+
+       /* try parsing! */
+       tl = storeSwapMetaUnpack(buf, &r);
+
+       close(fd); fd = -1;
+
+       /* is tl null? no metadata */
+       if (tl == NULL) {
+               printf("ERROR: no valid metadata found\n");
+               exit(1);
+       }
+
+       /* meta data size needs to be <= buffer size */
+       if (r > META_BUFSIZ) {
+               printf("ERROR: metadata size bigger than buffer?!\n");
+               exit(1);
+       }
+
+       printf("metadata header size: %d\n", r);
+
+       for (t = tl ; t; t = t->next) {
+                       switch (t->type) {
+                       case STORE_META_KEY_MD5:
+                               printf("STORE_META_KEY_MD5: len %d: value %s\n", 
t->length,
+                                   storeKeyText(t->value));
+                               break;
+                       case STORE_META_URL:
+                               printf("STORE_META_URL: len %d: value %.*s\n", 
t->length,
+                                   t->length, (const char *)t->value);
+                               break;
+                       case STORE_META_STOREURL:
+                               printf("STORE_META_STOREURL: len %d: value 
%.*s\n", t->length,
+                                   t->length, (const char *)t->value);
+                               break;
+                       case STORE_META_OBJSIZE:
+                               printf("STORE_META_OBJSIZE: len %d: value %d\n", 
t->length,
+                                   * ((squid_off_t *) t->value));
+                               break;
+                       case STORE_META_VARY_HEADERS:
+                               printf("STORE_META_VARY_HEADERS: len %d: value 
%.*s\n", t->length,
+                                   t->length, (const char *)t->value);
+                               break;
+                       case STORE_META_STD_LFS:
+                               /* This is for when size_t != squid_file_sz */
+                               /* XXX why is this size so .. stupidly big for 
the timestamp? */
+                               printf("STORE_META_STD_LFS: len %d: value %d\n", 
t->length,
+                                   * ((squid_file_sz *) t->value));
+                               break;
+                       default:
+                               printf("  unknown type %d; len %d\n", t->type, 
t->length);
+               }
+       }
+
+       exit(0);
+}
+
=======================================
--- /branches/LUSCA_HEAD/tools/Makefile.am      Sun May  3 07:23:23 2009
+++ /branches/LUSCA_HEAD/tools/Makefile.am      Sun Mar 28 00:37:53 2010
@@ -27,6 +27,9 @@
        ufs_log_dump \
        $(COSSDUMP)

+noinst_PROGRAMS = \
+       ufs_obj_cat
+
 libexec_PROGRAMS = \
        ufs_log_build \
        ufs_log_cat \
@@ -37,6 +40,7 @@
 ufs_log_build_SOURCES = ufs_log_build.c
 ufs_log_dump_SOURCES = ufs_log_dump.c
 ufs_log_cat_SOURCES = ufs_log_cat.c
+ufs_obj_cat_SOURCES = ufs_obj_cat.c
 cachemgr__CGIEXT__SOURCES = cachemgr.c
cachemgr__CGIEXT__CFLAGS = -DDEFAULT_CACHEMGR_CONFIG=\"$(DEFAULT_CACHEMGR_CONFIG)\" $(AM_CFLAGS)

--
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