/*
- * $Id: ufscommon.cc,v 1.6 2003/01/09 11:49:35 hno Exp $
+ * $Id: ufscommon.cc,v 1.7 2003/01/23 00:37:27 robertc Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
#include "ufscommon.h"
#include "Store.h"
+#include "fde.h"
+#include "StoreMeta.h"
+#include "Generic.h"
+#include "StoreMetaUnpacker.h"
#include "RefCount.h"
CBDATA_CLASS_INIT(RebuildState);
rb->rebuildFromDirectory();
}
+struct InitStoreEntry : public unary_function<StoreMeta, void>
+{
+ InitStoreEntry(StoreEntry *anEntry, cache_key *aKey):what(anEntry),index(aKey){}
+ void operator()(StoreMeta const &x) {
+ switch (x.getType()) {
+ case STORE_META_KEY:
+ assert(x.length == MD5_DIGEST_CHARS);
+ xmemcpy(index, x.value, MD5_DIGEST_CHARS);
+ break;
+ case STORE_META_STD:
+ assert(x.length == STORE_HDR_METASIZE);
+ xmemcpy(&what->timestamp, x.value, STORE_HDR_METASIZE);
+ break;
+ default:
+ break;
+ }
+ }
+ StoreEntry *what;
+ cache_key *index;
+};
+
void
RebuildState::rebuildFromDirectory()
{
struct stat sb;
int swap_hdr_len;
int fd = -1;
- tlv *tlv_list;
- tlv *t;
+ StoreMeta *tlv_list;
assert(this != NULL);
debug(47, 3) ("commonUfsDirRebuildFromDirectory: DIR #%d\n", sd->index);
for (int count = 0; count < speed; count++) {
sd->path, counts.scancount);
debug(47, 9) ("file_in: fd=%d %08X\n", fd, filn);
statCounter.syscalls.disk.reads++;
- if (FD_READ_METHOD(fd, hdr_buf, SM_PAGE_SIZE) < 0) {
+ int len;
+ if ((len = FD_READ_METHOD(fd, hdr_buf, SM_PAGE_SIZE)) < 0) {
debug(47, 1) ("commonUfsDirRebuildFromDirectory: read(FD %d): %s\n",
fd, xstrerror());
file_close(fd);
if (sb.st_size == 0)
continue;
#endif
- tlv_list = storeSwapMetaUnpack(hdr_buf, &swap_hdr_len);
+ StoreMetaUnpacker aBuilder(hdr_buf, len, &swap_hdr_len);
+ if (!aBuilder.isBufferSane()) {
+ debug(47, 1) ("commonUfsDirRebuildFromDirectory: Swap data buffer length is not sane.\n");
+ /* XXX shouldn't this be a call to commonUfsUnlink ? */
+ sd->unlinkFile ( filn);
+ continue;
+ }
+ tlv_list = aBuilder.createStoreMeta ();
if (tlv_list == NULL) {
debug(47, 1) ("commonUfsDirRebuildFromDirectory: failed to get meta data\n");
/* XXX shouldn't this be a call to commonUfsUnlink ? */
debug(47, 3) ("commonUfsDirRebuildFromDirectory: successful swap meta unpacking\n");
memset(key, '\0', MD5_DIGEST_CHARS);
memset(&tmpe, '\0', sizeof(StoreEntry));
- for (t = tlv_list; t; t = t->next) {
- switch (t->type) {
- case STORE_META_KEY:
- assert(t->length == MD5_DIGEST_CHARS);
- xmemcpy(key, t->value, MD5_DIGEST_CHARS);
- break;
- case STORE_META_STD:
- assert(t->length == STORE_HDR_METASIZE);
- xmemcpy(&tmpe.timestamp, t->value, STORE_HDR_METASIZE);
- break;
- default:
- break;
- }
- }
+ InitStoreEntry visitor(&tmpe, key);
+ for_each(*tlv_list, visitor);
storeSwapTLVFree(tlv_list);
tlv_list = NULL;
if (storeKeyNull(key)) {
*filn_p = fn;
return fd;
}
+
+#ifndef _USE_INLINE_
+#include "ufscommon.cci"
+#endif